Jump to content
ANKUR SAINI

How exactly sc_main works !!

Recommended Posts

How "sc_main" works in SystemC ?

I mean what I understood from library is that - there is a main function defined in library which calls the sc_elab_and_sim which in turns calls the sc_main function.

But my question is SystemC library is distributed as source which user builds at his end; and links to his application.
And if SystemC has main inside it then it should have got compiled into exe! Am I right ?

Can somebody help me in understanding this flow ?

Share this post


Link to post
Share on other sites

This question in mostly about how the linker works on your platform, and not really specific to SystemC.  Let me try to give a short summary:

  • Yes, the "main" symbol is needed by the final application
  • For every needed symbol, the linker looks in your object files first
    • If the symbol is present there, the linker picks it up
    • If not, the linker looks in the libraries given by the user (order/lookup is platform-specific)
  • Repeat this for all required symbols (including "sc_main")

So, if you define your own "main" in your application, SystemC's "main" will not be picked. This is actually a feature, as you can call "sc_elab_and_sim" manually from your "main" as well, if you want.

Hope that helps,
  Philipp

 

Share this post


Link to post
Share on other sites

Just to add a bit to Philipp's excellent reply:

In part this was done to support EDA tools that support co-simulation of SystemC with other languages (e.g. SystemVerilog and VHDL). The EDA tools themselves implement main and then they can dynamically link in your sc_main as needed.

Of course if you really know how to control the linker, there are other means as well, but we don't need to go there.

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

×