From d49365b4a7371d5a2bef016899955f08a2cf9f95 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sun, 17 Sep 2023 00:23:38 +0200 Subject: [PATCH] Change how -O works and create -optsize / -optlevel. Update --safe / --fast. --- .github/workflows/main.yml | 8 +-- README.md | 2 +- src/build/build_options.c | 97 +++++++++++++++----------- src/build/build_options.h | 42 +++++++++-- src/build/builder.c | 93 +++++++++++++++--------- src/build/project.c | 11 +-- src/compiler/compiler.c | 4 +- src/compiler/llvm_codegen.c | 4 +- src/compiler/llvm_codegen_builtins.c | 2 +- src/compiler/llvm_codegen_debug_info.c | 4 +- src/compiler/llvm_codegen_function.c | 2 +- src/compiler/llvm_codegen_module.c | 2 +- src/compiler/target.c | 2 +- test/src/tester.py | 4 +- 14 files changed, 177 insertions(+), 100 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9b00c37b8..0324676c7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,7 +64,7 @@ jobs: - name: Compile run unit tests run: | cd test - ..\build\${{ matrix.build_type }}\c3c.exe compile-test unit -g1 -O1 --safe + ..\build\${{ matrix.build_type }}\c3c.exe compile-test unit -O1 - name: upload artifacts uses: actions/upload-artifact@v3 @@ -263,7 +263,7 @@ jobs: - name: Compile run unit tests run: | cd test - ../build/c3c compile-test unit -g1 --safe + ../build/c3c compile-test unit - name: Build testproject run: | @@ -368,7 +368,7 @@ jobs: - name: Compile run unit tests run: | cd test - ../build/c3c compile-test unit -g1 --safe + ../build/c3c compile-test unit - name: Build testproject run: | @@ -440,7 +440,7 @@ jobs: - name: Compile run unit tests run: | cd test - ../build/c3c compile-test unit -g1 --safe + ../build/c3c compile-test unit - name: Build testproject run: | diff --git a/README.md b/README.md index 852b6d0b6..41710627d 100644 --- a/README.md +++ b/README.md @@ -320,6 +320,6 @@ Editor plugins can be found at https://github.com/c3lang/editor-plugins. 1. Write the test, either adding to existing test files in `/test/unit/` or add a new file. (If testing the standard library, put it in the `/test/unit/stdlib/` subdirectory). 2. Make sure that the test functions have the `@test` attribute. -3. Run tests and see that they pass. (Recommended settings: `c3c compile-test --safe -g1 -O0 test/unit`. +3. Run tests and see that they pass. (Recommended settings: `c3c compile-test -O0 test/unit`. - in this example `test/unit/` is the relative path to the test directory, so adjust as required) 4. Make a pull request for the new tests. diff --git a/src/build/build_options.c b/src/build/build_options.c index 8f1f8c83b..8d3d07312 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -98,18 +98,20 @@ static void usage(void) OUTPUT(" -C - Only lex, parse and check."); OUTPUT(" - - Read code from standard in."); OUTPUT(" -o - Write output to ."); - OUTPUT(" -O0 - Optimizations off."); - OUTPUT(" -O1 - Simple optimizations only."); - OUTPUT(" -O2 - Default optimization level."); - OUTPUT(" -O3 - Aggressive optimization."); - OUTPUT(" -Os - Optimize for size."); - OUTPUT(" -Oz - Optimize for tiny size."); - OUTPUT(" -O0+ - No optimization, single module."); - OUTPUT(" -O1+ - Simple optimizations, single module."); - OUTPUT(" -O2+ - Default optimization level, single module"); - OUTPUT(" -O3+ - Aggressive optimization, single module."); - OUTPUT(" -Os+ - Optimize for size, single module."); - OUTPUT(" -Oz+ - Optimize for tiny size, single module."); + OUTPUT(" -O0 - Safe, no optimizations, emit debug info."); + OUTPUT(" -O1 - Safe, high optimization, emit debug info."); + OUTPUT(" -O2 - Unsafe, high optimization, emit debug info."); + OUTPUT(" -O3 - Unsafe, highest optimization, relaxed maths, emit debug info."); + OUTPUT(" -O4 - Unsafe, highest optimization, fast maths, emit debug info."); + OUTPUT(" -Os - Unsafe, high optimization, small code, no debug info."); + OUTPUT(" -Oz - Unsafe, high optimization, tiny code, no debug info."); + OUTPUT(" -O0+ - O0, single module."); + OUTPUT(" -O1+ - O1, single module."); + OUTPUT(" -O2+ - O2, single module."); + OUTPUT(" -O3+ - O3, single module."); + OUTPUT(" -O4+ - O4, single module."); + OUTPUT(" -Os+ - Os, single module."); + OUTPUT(" -Oz+ - Oz, single module."); OUTPUT(" -t1 - Trust level 1 - don't allow $include nor $exec (default)."); OUTPUT(" -t2 - Trust level 2 - allow $include but not $exec / exec directives."); OUTPUT(" -t3 - Trust level 3 - full trust, allow both include and exec."); @@ -127,12 +129,12 @@ static void usage(void) OUTPUT(" --no-emit-stdlib - Do not output object files (nor asm or ir) for the standard library."); OUTPUT(" --target - Compile for a particular architecture + OS target."); OUTPUT(" --threads - Set the number of threads to use for compilation."); - OUTPUT(" --safe - Set mode to 'safe', generating runtime traps on overflows and contract violations."); - OUTPUT(" --fast - Set mode to 'fast', removes runtime traps."); + OUTPUT(" --safe= - Turn safety (contracts, runtime bounds checking, null pointer checks etc) on or off."); + OUTPUT(" --optlevel=