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
This commit is contained in:
Pierre Curto
2023-09-30 19:52:11 +02:00
committed by GitHub
parent 99ec44ad78
commit b2c7b713f2
6 changed files with 124 additions and 6 deletions

View File

@@ -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.");

View File

@@ -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);

View File

@@ -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");

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;