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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×