From e89d7d77c6e6d46ff3c5732f66554c14d316433d Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Mon, 16 May 2022 23:11:19 +0200 Subject: [PATCH 1/2] Make pallenec's -O0 flag only affect pallenec Now, the official way to affect the C compiler is to use the CFLAGS environment variable. This is a cleaner separation of duties. It also paves the way for using Luarocks as the compilation backend, because Luarocks only allows setting custom flags via the CFLAGS environment variable. --- README.md | 15 ++++----------- src/pallene/c_compiler.lua | 6 ++---- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6b5c1b12..dbfbc13c 100644 --- a/README.md +++ b/README.md @@ -88,22 +88,15 @@ It is possible to change the compiler optimization level, for the Pallene compil Here are some examples: ```sh -# execute no optimization (Pallene and C compiler) +# disable Pallene optimization passes pallenec test.pln -O0 -# execute Pallene compiler optimizations and C compiler level 3 optimizations -pallenec test.pln -O3 - -# execute no optimizations for Pallene compiler but executes C compiler level 2 optimizations -env CFLAGS="-O2" pallenec test.pln -O0 - -# execute all default optimizations (same as -O2) +# disable C compiler optimization +export CFLAGS='-O0' pallenec test.pln ``` -**Note**: For the C compiler only, the setting set using `CFLAGS` overrides the setting set by flag `-O`. - -For more compiler options, see `pallenec --help` +For more compiler options, see `./pallenec --help` ## Developing Pallene diff --git a/src/pallene/c_compiler.lua b/src/pallene/c_compiler.lua index c80294a8..c8f12091 100644 --- a/src/pallene/c_compiler.lua +++ b/src/pallene/c_compiler.lua @@ -18,7 +18,7 @@ local c_compiler = {} local CC = "cc" local CPPFLAGS = "" -local CFLAGS_BASE = "-std=c99 -g -fPIC" +local CFLAGS_BASE = "-std=c99 -g -fPIC -O2" local CFLAGS_WARN = "-Wall -Wundef -Wpedantic -Wno-unused" local USER_CFlAGS = os.getenv("CFLAGS") or "" @@ -47,13 +47,11 @@ local function run_cc(args) return true, {} end --- The third argument is the mod_name, which is not used by this -function c_compiler.compile_c_to_o(in_filename, out_filename, _, opt_level) +function c_compiler.compile_c_to_o(in_filename, out_filename) return run_cc({ CPPFLAGS, CFLAGS_BASE, CFLAGS_WARN, - opt_level and "-O"..opt_level or "", USER_CFlAGS, "-x c", "-o", util.shell_quote(out_filename), From 44ae7e80724e8df643b4190d26d3ab5c8fd5fc3f Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Fri, 20 May 2022 00:07:35 +0200 Subject: [PATCH 2/2] Move the dev-minded CFLAGS into the run-tests This removes debugging (-g) and warning (-W) flags in a default invocation of pallenec. Again, the main reason is to pave the road for the Luarocks compilation backend, which requires that any custom flags be passed via the CFLAGS environment variable. However, I think it is still a good idea despite that. Removing -g leads to smaller binaries and faster compilation times. As for the warning-related flags, they are not relevant to Pallene end-users, they are only relevant to us who are writing the compiler. --- run-tests | 6 +++--- src/pallene/c_compiler.lua | 13 ++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/run-tests b/run-tests index 125e01d7..e804cbe1 100755 --- a/run-tests +++ b/run-tests @@ -17,9 +17,9 @@ echo "--- Test Suite ---" # need to press Ctrl-C once and busted usually gets to exit gracefully. FLAGS=(--verbose --no-keep-going) -# To speed things up, we tell the C compiler to skip optimizations. -# Don't worry, the continuous integration server still tests with optimizations. -export CFLAGS=-O0 +# To speed things up, we tell the C compiler to skip optimizations. (It's OK, the CI still uses -O2) +# Also, add some compiler flags to verify standard compliance. +export CFLAGS='-O0 -std=c99 -Wall -Werror -Wundef -Wpedantic -Wno-unused' if [ "$#" -eq 0 ]; then if command -v parallel >/dev/null; then diff --git a/src/pallene/c_compiler.lua b/src/pallene/c_compiler.lua index c8f12091..ca204b66 100644 --- a/src/pallene/c_compiler.lua +++ b/src/pallene/c_compiler.lua @@ -16,11 +16,8 @@ local util = require "pallene.util" local c_compiler = {} -local CC = "cc" -local CPPFLAGS = "" -local CFLAGS_BASE = "-std=c99 -g -fPIC -O2" -local CFLAGS_WARN = "-Wall -Wundef -Wpedantic -Wno-unused" -local USER_CFlAGS = os.getenv("CFLAGS") or "" +local CC = os.getenv("CC") or "cc" +local CFLAGS = os.getenv("CFLAGS") or "-O2" local function get_uname() local ok, err, uname = util.outputs_of_execute("uname -s") @@ -49,10 +46,8 @@ end function c_compiler.compile_c_to_o(in_filename, out_filename) return run_cc({ - CPPFLAGS, - CFLAGS_BASE, - CFLAGS_WARN, - USER_CFlAGS, + "-fPIC", + CFLAGS, "-x c", "-o", util.shell_quote(out_filename), "-c", util.shell_quote(in_filename),