Jump to content

How exactly sc_main works !!


ANKUR SAINI

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 ?

Link to comment
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

 

Link to comment
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.

Link to comment
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...