Skip to content

How to actually run main #675

Answered by Timmmm
moste00 asked this question in Q&A
Jan 7, 2025 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

So what happens is this:

  1. function main() -> unit = ... gets compiled to a function called zmain in C, something like this:
unit zmain(unit zgsz317645)
{
  1. Sail will also include this hard-coded function in the C:
int model_main(int argc, char *argv[])
{
  model_init();
  if (process_arguments(argc, argv)) exit(EXIT_FAILURE);
  zmain(UNIT);
  model_fini();
  model_pre_exit();
  return EXIT_SUCCESS;
}
  1. By default, Sail will also generate a main():
int main(int argc, char *argv[])
{
  return model_main(argc, argv);
}

That can be disabled via the --c-no-main flag. In the RISC-V model I don't believe we use main() at all, except maybe for make interp? I've never used that though tbh.

If …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@moste00
Comment options

@jrtc27
Comment options

jrtc27 Jan 7, 2025
Collaborator

Comment options

You must be logged in to vote
0 replies
Answer selected by moste00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants