From b2c7b713f218c724263b4cc7118f0f4a42d90b4c Mon Sep 17 00:00:00 2001 From: Pierre Curto Date: Sat, 30 Sep 2023 19:52:11 +0200 Subject: [PATCH] add descriptions to the --list-project-properties cli option (#1021) * fix constant name typo * add descriptions to the --list-project-properties cli option * add missing file name for main.c3 --- src/build/build_options.c | 2 +- src/build/project.c | 100 +++++++++++++++++++++++++++++++ src/build/project_creation.c | 6 +- src/compiler/compiler.c | 19 +++++- src/compiler/compiler.h | 1 + src/compiler/compiler_internal.h | 2 + 6 files changed, 124 insertions(+), 6 deletions(-) diff --git a/src/build/build_options.c b/src/build/build_options.c index 45fe89dde..294a2362d 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -145,7 +145,7 @@ static void usage(void) OUTPUT(" --debug-log - Print debug logging to stdout."); #endif OUTPUT(""); - OUTPUT(" --benchmarking - Run builtin benchmarks."); + OUTPUT(" --benchmarking - Run built-in benchmarks."); OUTPUT(" --testing - Run built-in tests."); OUTPUT(""); OUTPUT(" --list-attributes - List all attributes."); diff --git a/src/build/project.c b/src/build/project.c index 97914c95a..c6806bf96 100644 --- a/src/build/project.c +++ b/src/build/project.c @@ -55,6 +55,53 @@ const char *project_default_keys[] = { const int project_default_keys_count = ELEMENTLEN(project_default_keys); +const char *project_default_descriptions[] = { + "Authors, optionally with email.", + "Override the benchmark function name.", + "Override C sources to be compiled.", + "Specify the C compiler.", + "Add flags for the C compiler.", + "CPU name, used for optimizations in the compiler backend.", + "Add debug info.", + "Add dependencies for all targets.", + "Override dependencies for all targets.", +"features", +"fp-math", + "Language version of C3.", + "The external libraries to link for all targets.", + "The path used to search for external libraries.", + "Extra arguments to the linker for all targets.", + "Link libc other default libraries (default: yes).", + "Set the directory for the MacOS SDK for cross compilation.", + "Set the memory environment: normal, small, tiny, none.", + "Do not generate (or require) a main function.", +"opt", + "Code optimization level: none, less, more, max.", + "Code size optimization: none, small, tiny.", + "Output location, relative to project file.", + "Override the panic function name.", + "Relocation model: none, pic, PIC, pie, PIE.", + "Turn safety (contracts, runtime bounds checking, null pointer checks etc) on or off.", + "Compile all modules together, enables more inlining.", +"soft-float", + "Sources compiled for all targets.", + "Strip unused code and globals from the output. (default: yes)", + "Sets the preferred symtab size.", + "Use the system linker (default: no for cross compilation, yes otherwise).", + "Compile for a particular architecture + OS target.", + "Set of targets for the project.", + "Override the test function name.", +"trap-on-wrap", + "Use this directory as the C3 standard library path.", + "Version using semantic versioning.", + "Warnings used for all targets.", + "Windows CRT linking: none, static, dynamic (default).", + "Set the directory for Windows system library files for cross compilation.", + "Set general level of x64 cpu: baseline, ssse3, sse4, avx1, avx2-v1, avx2-v2 (Skylake/Zen1+), avx512 (Icelake/Zen4+), native.", + "Set max type of vector use: none, mmx, sse, avx, avx512, native.", +"x86-stack-struct-return", +}; + const char* project_target_keys[] = { "benchfn", "c-sources-add", @@ -111,6 +158,59 @@ const char* project_target_keys[] = { const int project_target_keys_count = ELEMENTLEN(project_target_keys); +const char* project_target_descriptions[] = { + "Override the benchmark function name.", + "Add C sources to be compiled.", + "Override C sources to be compiled.", + "Specify the C compiler.", + "Add flags for the C compiler.", + "Override flags for the C compiler.", + "CPU name, used for optimizations in the compiler backend.", + "Add debug info.", + "Add dependencies for this target.", + "Override dependencies for this target.", + "Add directories where C3 library files may be found", + "Override directories where C3 library files may be found", +"features", + "FP math behaviour: strict, relaxed, fast.", + "Language version of C3.", + "Additional libraries to be linked.", + "Override libraries to be linked.", + "Add search paths for the linker.", + "Override search paths for the linker.", + "Add arguments for the linker.", + "Override arguments for the linker.", + "Link libc other default libraries (default: yes).", + "Set the directory for the MacOS SDK for cross compilation.", + "Set the memory environment: normal, small, tiny, none.", + "Do not generate (or require) a main function.", +"opt", + "Code optimization level: none, less, more, max.", + "Code size optimization: none, small, tiny.", + "Override the panic function name.", + "Relocation model: none, pic, PIC, pie, PIE.", + "Turn safety (contracts, runtime bounds checking, null pointer checks etc) on or off.", + "Compile all modules together, enables more inlining.", +"soft-float", + "Add sources for the target.", + "Override sources for the target.", + "Strip unused code and globals from the output. (default: yes)", + "Sets the preferred symtab size.", + "Use the system linker (default: no for cross compilation, yes otherwise).", + "Compile for a particular architecture + OS target.", + "Override the test function name.", +"trap-on-wrap", + "Executable or library.", + "Use this directory as the C3 standard library path.", + "Version using semantic versioning.", + "Warnings used for this target.", + "Windows CRT linking: none, static, dynamic (default).", + "Set the directory for Windows system library files for cross compilation.", + "Set general level of x64 cpu: baseline, ssse3, sse4, avx1, avx2-v1, avx2-v2 (Skylake/Zen1+), avx512 (Icelake/Zen4+), native.", + "Set max type of vector use: none, mmx, sse, avx, avx512, native.", +"x86-stack-struct-return", +}; + const char *get_valid_string(JSONObject *table, const char *key, const char *category, bool mandatory) { JSONObject *value = json_obj_get(table, key); diff --git a/src/build/project_creation.c b/src/build/project_creation.c index 023ac181d..472655a3d 100644 --- a/src/build/project_creation.c +++ b/src/build/project_creation.c @@ -131,7 +131,7 @@ const char *MANIFEST_TEMPLATE = " }\n" "}"; -const char *MAINIFEST_TARGET = +const char *MANIFEST_TARGET = " \"%s\" : {\n" " // Extra flags to the linker for this target:\n" " \"linkflags\" : [],\n" @@ -211,7 +211,7 @@ void create_library(BuildOptions *build_options) for (int i = 0; i < sizeof(DEFAULT_TARGETS) / sizeof(char*); i++) { const char *target = DEFAULT_TARGETS[i]; - scratch_buffer_printf(MAINIFEST_TARGET, target); + scratch_buffer_printf(MANIFEST_TARGET, target); mkdir_or_fail(build_options, target); } create_file_or_fail(build_options, "manifest.json", MANIFEST_TEMPLATE, build_options->project_name, scratch_buffer_to_string()); @@ -264,7 +264,7 @@ void create_project(BuildOptions *build_options) mkdir_or_fail(build_options, "src"); chdir_or_fail(build_options, "src"); - create_file_or_fail(build_options, MAIN_TEMPLATE, module_name(build_options)); + create_file_or_fail(build_options, "main.c3", MAIN_TEMPLATE, module_name(build_options)); chdir_or_fail(build_options, ".."); mkdir_or_fail(build_options, "test"); diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 77920cc50..bd40060ba 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -733,18 +733,21 @@ void print_syntax(BuildOptions *options) } if (options->print_project_properties) { + int width; puts("Project properties"); puts("------------------"); + width = find_padding_length(project_default_keys, project_default_keys_count); for (int i = 0; i < project_default_keys_count; i++) { - printf("%2d %s\n", i + 1, project_default_keys[i]); + printf("%2d %-*s%s\n", i + 1, width, project_default_keys[i], project_default_descriptions[i]); } puts(""); puts("Target properties"); puts("-----------------"); + width = find_padding_length(project_target_keys, project_target_keys_count); for (int i = 0; i < project_target_keys_count; i++) { - printf("%2d %s\n", i + 1, project_target_keys[i]); + printf("%2d %-*s%s\n", i + 1, width, project_target_keys[i], project_target_descriptions[i]); } puts(""); } @@ -1026,3 +1029,15 @@ File *compile_and_invoke(const char *file, const char *args) return source_file_text_load(file, out); } +int find_padding_length(const char** arr, const int count) +{ + int width = 0; + for (int i = 0; i < count; i++) + { + const char* str = arr[i]; + int len = strlen(str); + if (width < len) width = len; + } + width += 2; + return width; +} \ No newline at end of file diff --git a/src/compiler/compiler.h b/src/compiler/compiler.h index dc7ac2446..aad794245 100644 --- a/src/compiler/compiler.h +++ b/src/compiler/compiler.h @@ -17,6 +17,7 @@ void symtab_init(uint32_t max_size); void symtab_destroy(); void print_syntax(BuildOptions *options); void vendor_fetch(BuildOptions *options); +int find_padding_length(const char** str, const int count); extern double compiler_init_time; extern double compiler_parsing_time; diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 8e3ff6108..efc506ccf 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -46,8 +46,10 @@ typedef uint16_t SectionId; #define MAX_CLOBBER_FLAGS (64 * CLOBBER_FLAG_ELEMENTS) extern const char *project_default_keys[]; +extern const char *project_default_descriptions[]; extern const int project_default_keys_count; extern const char* project_target_keys[]; +extern const char* project_target_descriptions[]; extern const int project_target_keys_count; typedef struct Ast_ Ast;