Skip to content

Commit

Permalink
Support additional keys in projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
data-man authored and lerno committed Sep 19, 2023
1 parent 9eef340 commit a06cc76
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 140 deletions.
72 changes: 65 additions & 7 deletions resources/examples/nolibc/project.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,79 @@
{
// Language version of C3.
"langrev": "1",
// Warnings used for all targets.
"warnings": [ "no-unused" ],
// Directories where C3 library files may be found.
"dependency-search-paths": [ ],
// Libraries to use for all targets.
"dependencies": [ ],
// Authors, optionally with email.
"authors": [ "Dmitry Atamanov https://github.com/data-man" ],
// Version using semantic versioning.
"version": "0.0.1 Omega",
// Sources compiled for all targets.
"sources": [ "./**" ],
// C sources if the project also compiles C sources
// relative to the project file.
// "c-sources": [ "csource/**" ],
// Output location, relative to project file.
"output": ".",
// Architecture and OS target.
// You can use 'c3c --list-targets' to list all valid targets.
"target": "linux-x64",
// Targets.
"targets": {
"hello_world": {
"type": "executable",
"opt": "O3",
"nolibc": true,
"nostdlib": true
"debug-info": "none",
"link-libc": false,
"opt": "O0",
"safe": false,
"system-linker": true,
"use-stdlib": false,
},
},
"debug-info": "none",
"target": "linux-x64",
// Global settings.
// C compiler if the project also compiles C sources
// defaults to 'cc'.
"cc": "cc",
// CPU name, used for optimizations in the LLVM backend.
"cpu": "generic",
// Debug information, may be "none", "full" and "line-tables".
"debug-info": "full",
// FP math behaviour: "strict", "relaxed", "fast".
"fp-math": "strict",
// Link libc other default libraries.
"link-libc": true,
// Memory environment: "normal", "small", "tiny", "none".
"memory-env": "normal",
// Optimization: "O0", "O1", "O2", "O3", "O4", "O5", "Os", "Oz".
"opt": "O0",
// Code optimization level: "none", "less", "more", "max".
"optlevel": "none",
// Code size optimization: "none", "small", "tiny".
"optsize": "none",
// Relocation model: "none", "pic", "PIC", "pie", "PIE".
"reloc": "none",
// Trap on signed and unsigned integer wrapping for testing.
"trap-on-wrap": false,
// Turn safety (contracts, runtime bounds checking, null pointer checks etc).
"safe": true,
// Compile all modules together, enables more inlining.
"single-module": true,
// Use / don't use soft float, value is otherwise target default.
"soft-float": false,
// Strip unused code and globals from the output.
"strip-unused": true,
// The size of the symtab, which limits the amount
// of symbols that can be used. Should usually not be changed.
"symtab": 1048576,
// Use the system linker.
"system-linker": false,
// Include the standard library.
"use-stdlib": true,
// Set general level of x64 cpu: "baseline", "ssse3", "sse4", "avx1", "avx2-v1", "avx2-v2", "avx512", "native".
"x86cpu": "native",
// Set max type of vector use: "none", "mmx", "sse", "avx", "avx512", "native".
"x86vec": "sse",
"cpu": "generic",
"output": "."
}
1 change: 1 addition & 0 deletions src/build/build_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ typedef enum
TRUST_INCLUDE,
TRUST_FULL
} TrustLevel;

typedef enum
{
COMPILE_NORMAL,
Expand Down
79 changes: 63 additions & 16 deletions src/build/project.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,40 @@ const char *project_default_keys[] = {
"debug-info",
"dependencies",
"dependency-search-paths",
"features",
"fp-math",
"langrev",
"link-args",
"linked-libraries",
"linker-search-paths",
"link-args",
"link-libc",
"macossdk",
"memory-env",
"no-entry",
"nolibc",
"nostdlib",
"opt",
"optlevel",
"optsize",
"output",
"panicfn",
"reloc",
"safe",
"single-module",
"soft-float",
"sources",
"strip-unused",
"symtab",
"system-linker",
"target",
"targets",
"trap-on-wrap",
"use-stdlib",
"version",
"warnings",
"wincrt",
"winsdk",
"x86-stack-struct-return",
"x86cpu",
"x86vec",
"features"
"x86-stack-struct-return",
};

const int project_default_keys_count = sizeof(project_default_keys) / sizeof(char*);
Expand All @@ -58,36 +66,44 @@ const char* project_target_keys[] = {
"dependencies-override",
"dependency-search-paths-add",
"dependency-search-paths-override",
"features",
"fp-math",
"langrev",
"link-args-add",
"link-args-override",
"linked-libraries-add",
"linked-libraries-override",
"linker-search-paths-add",
"linker-search-paths-override",
"link-args-add",
"link-args-override",
"link-libc",
"macossdk",
"memory-env",
"no-entry",
"nolibc",
"nostdlib",
"opt",
"optlevel",
"optsize",
"output"
"panicfn",
"reloc",
"safe",
"single-module",
"soft-float",
"sources-add",
"sources-override",
"strip-unused",
"symtab",
"system-linker",
"target",
"trap-on-wrap",
"type",
"use-stdlib",
"version",
"warnings",
"wincrt",
"winsdk",
"x86-stack-struct-return",
"x86cpu",
"x86vec",
"features",
"x86-stack-struct-return",
};

const int project_target_keys_count = sizeof(project_target_keys) / sizeof(char*);
Expand Down Expand Up @@ -298,6 +314,25 @@ static void load_into_build_target(JSONObject *json, const char *type, BuildTarg
DebugInfo info = get_valid_string_setting(json, "debug-info", type, debug_infos, 0, 3, "one of 'full' 'line-table' or 'none'.");
if (info > -1) target->debug_info = info;

// Optimization Level
static const char *opt_level_settings[4] = {
[OPTIMIZATION_NONE] = "none",
[OPTIMIZATION_LESS] = "less",
[OPTIMIZATION_MORE] = "more",
[OPTIMIZATION_AGGRESSIVE] = "max",
};
OptimizationLevel optlevel = (OptimizationLevel)get_valid_string_setting(json, "optlevel", type, opt_level_settings, 0, 4, "`none`, `less`, `more`, `max`.");
target->optlevel = optlevel;

// Size optimization Level
static const char *opt_size_settings[3] = {
[SIZE_OPTIMIZATION_NONE] = "none",
[SIZE_OPTIMIZATION_SMALL] = "small",
[SIZE_OPTIMIZATION_TINY] = "tiny",
};
SizeOptimizationLevel optsize = (SizeOptimizationLevel)get_valid_string_setting(json, "optsize", type, opt_size_settings, 0, 4, "`none`, `small`, `tiny`.");
target->optsize = optsize;

static const char *opt_settings[8] = {
[OPT_SETTING_O0] = "O0",
[OPT_SETTING_O1] = "O1",
Expand All @@ -311,6 +346,12 @@ static void load_into_build_target(JSONObject *json, const char *type, BuildTarg
OptimizationSetting opt = (OptimizationSetting)get_valid_string_setting(json, "opt", type, opt_settings, 0, 8, "'O0', 'O1' etc.");
update_build_target_with_opt_level(target, opt);

// Safety level
target->feature.safe_mode = (SafetyLevel)get_valid_bool(json, "safe", type, target->feature.safe_mode);

// Single module
target->single_module = (SingleModule)get_valid_bool(json, "single-module", type, target->single_module);

MemoryEnvironment env = get_valid_string_setting(json, "memory-env", type, memory_environment, 0, 4, "one of 'normal', 'small', 'tiny' or 'none'.");
if (env > -1) target->memory_environment = env;

Expand Down Expand Up @@ -352,7 +393,7 @@ static void load_into_build_target(JSONObject *json, const char *type, BuildTarg
if (wincrt > -1) target->win.crt_linking = (WinCrtLinking)wincrt;

// fp-math
int fpmath = get_valid_string_setting(json, "fp-math", type, fp_math, 0, 3, "strict, relaxed, fast");
int fpmath = get_valid_string_setting(json, "fp-math", type, fp_math, 0, 3, "`strict`, `relaxed` or `fast`.");
if (fpmath > -1) target->feature.fp_math = fpmath;

const char **features = get_valid_array(json, "features", type, false);
Expand All @@ -368,15 +409,15 @@ static void load_into_build_target(JSONObject *json, const char *type, BuildTarg
}

// x86vec
int x86vec = get_valid_string_setting(json, "x86vec", type, x86_vector_capability, 0, 6, "none, native, mmx, sse, avx or avx512");
int x86vec = get_valid_string_setting(json, "x86vec", type, x86_vector_capability, 0, 6, "`none`, `native`, `mmx`, `sse`, `avx` or `avx512`.");
if (x86vec > -1) target->feature.x86_vector_capability = x86vec;

// x86vec
int x86cpu = get_valid_string_setting(json, "x86cpu", type, x86_cpu_set, 0, 8, "baseline, ssse3, sse4, avx1, avx2-v1, avx2-v2, avx512 or native");
int x86cpu = get_valid_string_setting(json, "x86cpu", type, x86_cpu_set, 0, 8, "`baseline`, `ssse3`, `sse4`, `avx1`, `avx2-v1`, `avx2-v2`, `avx512` or `native`.");
if (x86cpu > -1) target->feature.x86_cpu_set = x86cpu;

// riscvfloat
int riscv_float = get_valid_string_setting(json, "riscvfloat", type, riscv_capability, 0, 3, "none, float or double");
int riscv_float = get_valid_string_setting(json, "riscvfloat", type, riscv_capability, 0, 3, "`none`, `float` or `double`.");
if (riscv_float > -1) target->feature.riscv_float_capability = riscv_float;

// winsdk
Expand Down Expand Up @@ -410,7 +451,13 @@ static void load_into_build_target(JSONObject *json, const char *type, BuildTarg
target->panicfn = panicfn;

// link-libc
target->link_libc = (LinkLibc)get_valid_bool(json, "nolibc", type, target->link_libc);
target->link_libc = (LinkLibc)get_valid_bool(json, "link-libc", type, target->link_libc);

// strip-unused
target->strip_unused = (StripUnused)get_valid_bool(json, "strip-unused", type, target->strip_unused);

// system-linker
target->system_linker = (SystemLinker)get_valid_bool(json, "system-linker", type, target->system_linker);

// no-entry
target->no_entry = get_valid_bool(json, "no-entry", type, target->no_entry);
Expand Down
Loading

0 comments on commit a06cc76

Please sign in to comment.