Jump to content
etemadi

Linking systemC to legacy C++ code

Recommended Posts

Hi

I am providing a systemC model to another team that uses a non-systemC legacy model. The idea is to include systemC libraries and then replace the legacy main() function with systemC's sc_main() so that sc_start() command could be called. Here is an sketch:

 

 

sc_main () {

 

   // legacy code here

 

  // instantiate/initial systemC modules

 

  // systemC code

  sc_start(sim_time);

  sc_stop();

 

  // process systemC output with the legacy code

 

 

}

 

For various reasons, the other team is not willing to replace the main() function with sc_main(). One obvious way is to make the systemC portion an executable and call it from main(). But this requires file I/O that would slow down the sim.  I was wondering if there is a way to accomplish this without replacing the main() function?

 

Thanks

Farzad

Share this post


Link to post
Share on other sites

It is not really clear what exactly the issue is. SystemC is

basically ANSI C++ library, so one might start with an

include directive as:

 

#include "<my_legacy_code>.h"

 

Then, use standard C++ techniques to get data from

or pass data to the legacy code. However, the legacy

code probably would not support concurrency or the

other SystemC specific features.

 

For example, to read in double numbers from the

command line, one might have:

 

int sc_main(int argc, char **argv)

{

   double d0 = strtod(arggv[1], NULL);

 

   ......

   return 0;

}

 

Hope that helps/

Share this post


Link to post
Share on other sites

You can use the sc_elab_and_sim function (see Section 4.3.2 in 1666-2011):

 

int main(int argc, char* argv[])
{
     // legacy code here
 
     int scresult = sc_core::sc_elab_and_sim( argc, argv );



     // process systemC output with the legacy code
}

 
// still needed for SystemC part:
int sc_main(int argc, char* argv[])

{
  // instantiate/initial SystemC modules
 
  // SystemC code
  sc_start(sim_time);
  sc_stop();
}

 

Passing information between the legacy part and the SystemC part can then be done via a singleton class or by any other C++ means that fits your needs.

 

 

Greetings from Oldenburg,

  Philipp

Share this post


Link to post
Share on other sites

Suppose I have a SystemC model for a 3 bit adder,

and I wish to execute that from pure C++ code as:

 

int main(int argc, char **argv)

{

 

 int scresult = sc_core::sc_elab_and_sim( argc, argv );

.....

return 0;

}

 

So what arguments would I pass to main at execution

time ?


 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...