Skip to content

feat: add exit code support to sc_start and sc_stop - #152

Open
janweinstock wants to merge 1 commit into
accellera-official:developfrom
janweinstock:dev-exitcode
Open

feat: add exit code support to sc_start and sc_stop#152
janweinstock wants to merge 1 commit into
accellera-official:developfrom
janweinstock:dev-exitcode

Conversation

@janweinstock

Copy link
Copy Markdown
Contributor

Hi all,

I though it could be useful to have and exit code that could be set using sc_stop which would be returned by sc_start, e.g.:

if (everything_ok)
    sc_stop(EXIT_SUCCESS);
else
    sc_stop(EXIT_FAILURE);

and then

int sc_main(int argc, char** argv) {
    // ...
    return sc_start();
}

Calling sc_stop() without an argument is backward-compatible and equivalent to sc_stop(0). The implementation stores the exit code in sc_simcontext and sc_start returns it on exit.

What do you think?

@janweinstock

Copy link
Copy Markdown
Contributor Author

@markfoodyburton

Copy link
Copy Markdown
Contributor

Looks very good to me.

@maehne maehne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expressed my doubts about this change to the LRM in this comment. Changing the signature of sc_start() may have unexpected effects on legacy code. At least add [[maybe_unused]] to the user-facing sc_start() functions.

@janweinstock

Copy link
Copy Markdown
Contributor Author

I expressed my doubts about this change to the LRM in this comment. Changing the signature of sc_start() may have unexpected effects on legacy code. At least add [[maybe_unused]] to the user-facing sc_start() functions.

The return value is intentionally not marked [[nodiscard]], so it is explicitly allowed to be ignored; [[maybe_unused]] is neither applicable nor necessary.

@janweinstock
janweinstock changed the base branch from main to develop May 18, 2026 14:03
@janweinstock

Copy link
Copy Markdown
Contributor Author

Retargeted to develop branch.

Signed-off-by: Jan Henrik Weinstock <jan@mwa.re>
@janweinstock

Copy link
Copy Markdown
Contributor Author

It was discussed in the LWG to include an update to sc_pause so that it can also specify an exit_code. Since the reference implementation allows to call sc_pause multiple times in the same delta-cycle, we need to decide which exit_code should be reported in such cases.

Example 1 (multiple sc_pause)

sc_pause(val_a);
sc_pause(val_b);
sc_pause(val_c);

Example 2 (mixed with sc_stop):

sc_pause(val_a);
sc_pause(val_b);
sc_stop(val_c);

Which values should be returned in each case? We could say val_c for both cases (exit code gets updated each time, last write wins). This would also simplify the implementation in sc_stop, since one should not call sc_pause after sc_stop anways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants