diff --git a/src/build/build_options.c b/src/build/build_options.c index cac087060..a87d77324 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -104,7 +104,15 @@ static void usage(void) OUTPUT(""); OUTPUT(" -z - Send the as a parameter to the linker."); OUTPUT(""); + OUTPUT(" -mavx - Enable AVX on x64 targets."); + OUTPUT(" -mavx512 - Enable AVX512 on x64 targets."); + OUTPUT(" -mno-avx - Disable AVX on x64 targets."); + OUTPUT(""); OUTPUT(" --debug-stats - Print debug statistics."); + OUTPUT(" --list-keywords - List all keywords."); + OUTPUT(" --list-operators - List all operators."); + OUTPUT(" --list-attributes - List all attributes."); + OUTPUT(" --list-builtins - List all builtins."); #ifndef NDEBUG OUTPUT(" --debug-log - Print debug logging to stdout."); #endif @@ -285,10 +293,18 @@ static void print_version(void) OUTPUT("LLVM default target: %s", llvm_target); } + static void parse_option(BuildOptions *options) { switch (current_arg[1]) { + case '?': + if (match_shortopt("?")) + { + usage(); + exit_compiler(COMPILER_SUCCESS_EXIT); + } + break; case 'V': if (match_shortopt("V")) { @@ -467,6 +483,30 @@ static void parse_option(BuildOptions *options) debug_stats = true; return; } + if (match_longopt("list-keywords")) + { + options->print_keywords = true; + options->command = COMMAND_PRINT_SYNTAX; + return; + } + if (match_longopt("list-attributes")) + { + options->print_attributes = true; + options->command = COMMAND_PRINT_SYNTAX; + return; + } + if (match_longopt("list-builtins")) + { + options->print_builtins = true; + options->command = COMMAND_PRINT_SYNTAX; + return; + } + if (match_longopt("list-operators")) + { + options->print_operators = true; + options->command = COMMAND_PRINT_SYNTAX; + return; + } if (match_longopt("threads")) { if (at_end() || next_is_opt()) error_exit("error: --threads needs a valid integer 1 or higher."); @@ -547,7 +587,8 @@ static void parse_option(BuildOptions *options) } if (match_longopt("help")) { - break; + usage(); + exit_compiler(COMPILER_SUCCESS_EXIT); } break; default: @@ -621,6 +662,10 @@ BuildOptions parse_arguments(int argc, const char *argv[]) } if (build_options.command == COMMAND_MISSING) { + if (build_options.print_operators || build_options.print_builtins || build_options.print_keywords || build_options.print_attributes) + { + return build_options; + } FAIL_WITH_ERR("No command found."); } return build_options; diff --git a/src/build/build_options.h b/src/build/build_options.h index 7ea40d205..8c2a3ead6 100644 --- a/src/build/build_options.h +++ b/src/build/build_options.h @@ -35,6 +35,7 @@ typedef enum COMMAND_DOCS, COMMAND_BENCH, COMMAND_UNIT_TEST, + COMMAND_PRINT_SYNTAX, } CompilerCommand; typedef enum @@ -207,6 +208,10 @@ typedef struct BuildOptions_ bool no_avx; bool avx; bool avx512; + bool print_keywords; + bool print_attributes; + bool print_builtins; + bool print_operators; } BuildOptions; diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 1710e3a1d..b96dd06c5 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -403,6 +403,55 @@ static void setup_bool_define(const char *id, bool value) } } +void print_syntax(BuildOptions *options) +{ + symtab_init(64 * 1024); + + if (options->print_keywords) + { + int index = 1; + for (int i = 1; i < TOKEN_LAST; i++) + { + const char *name = token_type_to_string((TokenType)i); + if (name[0] == '$' || (name[0] >= 'a' && name[0] <= 'z')) + { + if (name[1] == '$' || name[1] == '\0') continue; + printf("%2d %s\n", index++, name); + } + } + } + if (options->print_operators) + { + int index = 1; + for (int i = 1; i < TOKEN_LAST; i++) + { + if (i == TOKEN_DOCS_START || i == TOKEN_DOCS_END) continue; + const char *name = token_type_to_string((TokenType)i); + char first_char = name[0]; + if (first_char == '$' || first_char == '@' + || (first_char >= 'a' && first_char <= 'z') + || (first_char >= 'A' && first_char <= 'Z')) + { + continue; + } + printf("%2d %s\n", index++, name); + } + } + if (options->print_attributes) + { + for (int i = 0; i < NUMBER_OF_ATTRIBUTES; i++) + { + printf("%2d @%s\n", i + 1, attribute_list[i]); + } + } + if (options->print_builtins) + { + for (int i = 0; i < NUMBER_OF_BUILTINS; i++) + { + printf("%2d $$%s\n", i + 1, builtin_list[i]); + } + } +} void compile() { active_target.sources = target_expand_source_names(active_target.source_dirs, ".c3", ".c3t", true); diff --git a/src/compiler/compiler.h b/src/compiler/compiler.h index 524844629..7dc6f6988 100644 --- a/src/compiler/compiler.h +++ b/src/compiler/compiler.h @@ -14,4 +14,4 @@ void init_build_target(BuildTarget *build_target, BuildOptions *build_options); void init_default_build_target(BuildTarget *target, BuildOptions *options); void symtab_init(uint32_t max_size); void symtab_destroy(); - +void print_syntax(BuildOptions *options); diff --git a/src/main.c b/src/main.c index 69330c3bd..c10f93d06 100644 --- a/src/main.c +++ b/src/main.c @@ -43,6 +43,9 @@ int main_real(int argc, const char *argv[]) switch (build_options.command) { + case COMMAND_PRINT_SYNTAX: + print_syntax(&build_options); + break; case COMMAND_INIT: create_project(&build_options); break;