Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • sac2c sac2c
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 400
    • Issues 400
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • sac-group
  • sac2csac2c
  • Wiki
  • Tutorials
  • add compiler flag

add compiler flag · Changes

Page history
add tutorial about adding a compiler flag authored Apr 07, 2025 by Quinten Cabo's avatar Quinten Cabo
Hide whitespace changes
Inline Side-by-side
tutorials/add-compiler-flag.md 0 → 100644
View page @ b562eac3
This tutorial teaches you how to add a new compiler flag called `-enable-foo` to the compiler.
# Step 1
First add a global variable where your flag will be stored into.
This is done in `src/libsac2c/global/globals.mac`.
Just add a macro like this:
```c
GLOBAL (bool, enable_foo, FALSE, xfree_dummy)
// ^-type ^-name ^-default ^-free-function
```
Just look at what is already there.
For a string argument you need:
```c
GLOBAL (char *, enable_foo, NULL, xfree_char_ptr, )
```
# Step 2
Then you have to add the flag to the `AnalyseCommandlineSac2c` function in `src/libsac2c/global/options.c`.
This function is responsible for parsing the command line arguments and setting the global variables accordingly.
Again just look at what is already there and extend this tutorial if you learned anything noteworthy.
There two simple macros you can use:
- `ARGS_FLAG`
- `ARGS_OPTION`
There is also `ARGS_OPTION_BEGIN` and friends for one option that takes multiple flags like `-check pc`.
Read `getoptions.h` for more information about these or look at the code for `-check`.
## ARGS_FLAG
With `ARGS_FLAG` the compiler option is just a boolean.
The macro takes a name and an expression.
The macro will run the expression if the option is passed.
```c
ARGS_FLAG ("enable-foo", global.enable_foo = TRUE);
```
## ARGS_OPTION
This macro also takes a name and an expression.
But with the expression of `ARGS_OPTION` you also can access the `ARG` variable.
```c
ARGS_OPTION ("enable-foo", global.enable_foo = STRcpy (ARG));
```
Clone repository
  • Styleguide
  • concepts
    • Deprecated Modules
    • Globals
    • Intermediate Code Macros
    • Named Tuples
    • Overloading
    • Preprocessor
    • Primitive functions
    • Runtime Representations
    • input stdin
    • phm xt
    • ref counting methods
    • type famlies
    • type patterns
  • error messages
    • Anthropomorphic error essages
View All Pages