From 643ab90ace52d6d752a12ece9d6a8655ca2ca596 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 23 Oct 2017 22:33:00 -0400 Subject: add maximum value for @setAlignStack --- src/ir.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 0879942b3e..787d58442e 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -15312,6 +15312,11 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes)) return ira->codegen->builtin_types.entry_invalid; + if (align_bytes > 256) { + ir_add_error(ira, &instruction->base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes)); + return ira->codegen->builtin_types.entry_invalid; + } + FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); if (fn_entry == nullptr) { ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function")); -- cgit v1.2.3 From 5f28a9d23851d94edc2b24e549b7c5abbbf23f68 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 25 Oct 2017 23:10:41 -0400 Subject: cleaner verbose flags and zig build prints failed command --- src/all_types.hpp | 5 +- src/analyze.cpp | 10 +-- src/codegen.cpp | 18 +----- src/codegen.hpp | 1 - src/ir.cpp | 6 +- src/link.cpp | 21 +++---- src/main.cpp | 142 ++++++++++++++++++++++++++----------------- src/parsec.cpp | 2 +- std/build.zig | 39 +++++++++--- std/special/build_runner.zig | 39 +++++++++--- 10 files changed, 171 insertions(+), 112 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index 894deca930..b8966e764a 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1515,9 +1515,12 @@ struct CodeGen { size_t version_major; size_t version_minor; size_t version_patch; - bool verbose; + bool verbose_tokenize; + bool verbose_ast; bool verbose_link; bool verbose_ir; + bool verbose_llvm_ir; + bool verbose_cimport; ErrColor err_color; ImportTableEntry *root_import; ImportTableEntry *bootstrap_import; diff --git a/src/analyze.cpp b/src/analyze.cpp index 292943a6e6..45efa205e3 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2982,7 +2982,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ return; } - if (g->verbose) { + if (g->verbose_ir) { fprintf(stderr, "{ // (analyzed)\n"); ir_print(g, stderr, &fn_table_entry->analyzed_executable, 4); fprintf(stderr, "}\n"); @@ -3015,7 +3015,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) { fn_table_entry->anal_state = FnAnalStateInvalid; return; } - if (g->verbose) { + if (g->verbose_ir) { fprintf(stderr, "\n"); ast_render(g, stderr, fn_table_entry->body_node, 4); fprintf(stderr, "\n{ // (IR)\n"); @@ -3115,7 +3115,7 @@ void preview_use_decl(CodeGen *g, AstNode *node) { } ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code) { - if (g->verbose) { + if (g->verbose_tokenize) { fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(abs_full_path)); fprintf(stderr, "----------------\n"); fprintf(stderr, "%s\n", buf_ptr(source_code)); @@ -3135,7 +3135,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a exit(1); } - if (g->verbose) { + if (g->verbose_tokenize) { print_tokens(source_code, tokenization.tokens); fprintf(stderr, "\nAST:\n"); @@ -3150,7 +3150,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color); assert(import_entry->root); - if (g->verbose) { + if (g->verbose_ast) { ast_print(stderr, import_entry->root, 0); } diff --git a/src/codegen.cpp b/src/codegen.cpp index 6fb8d4b8ef..68fd4159bd 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -196,10 +196,6 @@ void codegen_set_is_static(CodeGen *g, bool is_static) { g->is_static = is_static; } -void codegen_set_verbose(CodeGen *g, bool verbose) { - g->verbose = verbose; -} - void codegen_set_each_lib_rpath(CodeGen *g, bool each_lib_rpath) { g->each_lib_rpath = each_lib_rpath; } @@ -4163,10 +4159,6 @@ static void validate_inline_fns(CodeGen *g) { } static void do_code_gen(CodeGen *g) { - if (g->verbose) { - fprintf(stderr, "\nCode Generation:\n"); - fprintf(stderr, "------------------\n"); - } assert(!g->errors.length); codegen_add_time_event(g, "Code Generation"); @@ -4443,7 +4435,8 @@ static void do_code_gen(CodeGen *g) { ZigLLVMDIBuilderFinalize(g->dbuilder); - if (g->verbose || g->verbose_ir) { + if (g->verbose_llvm_ir) { + fflush(stderr); LLVMDumpModule(g->module); } @@ -5273,10 +5266,6 @@ static void gen_root_source(CodeGen *g) { resolve_top_level_decl(g, panic_tld, false, nullptr); } - if (g->verbose) { - fprintf(stderr, "\nIR Generation and Semantic Analysis:\n"); - fprintf(stderr, "--------------------------------------\n"); - } if (!g->error_during_imports) { semantic_analyze(g); } @@ -5290,9 +5279,6 @@ static void gen_root_source(CodeGen *g) { } report_errors_and_maybe_exit(g); - if (g->verbose) { - fprintf(stderr, "OK\n"); - } } diff --git a/src/codegen.hpp b/src/codegen.hpp index f4c7f6a8c7..cc7721e9f8 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -25,7 +25,6 @@ void codegen_set_each_lib_rpath(CodeGen *codegen, bool each_lib_rpath); void codegen_set_is_static(CodeGen *codegen, bool is_static); void codegen_set_strip(CodeGen *codegen, bool strip); -void codegen_set_verbose(CodeGen *codegen, bool verbose); void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color); void codegen_set_out_name(CodeGen *codegen, Buf *out_name); void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir); diff --git a/src/ir.cpp b/src/ir.cpp index 787d58442e..6c6ce676f6 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -7849,7 +7849,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node if (ir_executable.invalid) return codegen->invalid_instruction; - if (codegen->verbose) { + if (codegen->verbose_ir) { fprintf(stderr, "\nSource: "); ast_render(codegen, stderr, node, 4); fprintf(stderr, "\n{ // (IR)\n"); @@ -7870,7 +7870,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node if (type_is_invalid(result_type)) return codegen->invalid_instruction; - if (codegen->verbose) { + if (codegen->verbose_ir) { fprintf(stderr, "{ // (analyzed)\n"); ir_print(codegen, stderr, &analyzed_executable, 4); fprintf(stderr, "}\n"); @@ -13514,7 +13514,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc return ira->codegen->builtin_types.entry_invalid; } - if (ira->codegen->verbose) { + if (ira->codegen->verbose_cimport) { fprintf(stderr, "\nC imports:\n"); fprintf(stderr, "-----------\n"); ast_render(ira->codegen, stderr, child_import->root, 4); diff --git a/src/link.cpp b/src/link.cpp index 316c7bc761..a4e5b2dd25 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -37,8 +37,12 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) parent_gen->zig_lib_dir); child_gen->want_h_file = false; + child_gen->verbose_tokenize = parent_gen->verbose_tokenize; + child_gen->verbose_ast = parent_gen->verbose_ast; child_gen->verbose_link = parent_gen->verbose_link; child_gen->verbose_ir = parent_gen->verbose_ir; + child_gen->verbose_llvm_ir = parent_gen->verbose_llvm_ir; + child_gen->verbose_cimport = parent_gen->verbose_cimport; codegen_set_cache_dir(child_gen, parent_gen->cache_dir); @@ -47,7 +51,6 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) codegen_set_out_name(child_gen, buf_create_from_str(oname)); - codegen_set_verbose(child_gen, parent_gen->verbose); codegen_set_errmsg_color(child_gen, parent_gen->err_color); codegen_set_mmacosx_version_min(child_gen, parent_gen->mmacosx_version_min); @@ -859,15 +862,12 @@ void codegen_link(CodeGen *g, const char *out_file) { buf_resize(&lj.out_file, 0); } - if (g->verbose || g->verbose_ir) { + if (g->verbose_llvm_ir) { fprintf(stderr, "\nOptimization:\n"); fprintf(stderr, "---------------\n"); + fflush(stderr); LLVMDumpModule(g->module); } - if (g->verbose || g->verbose_link) { - fprintf(stderr, "\nLink:\n"); - fprintf(stderr, "-------\n"); - } bool override_out_file = (buf_len(&lj.out_file) != 0); if (!override_out_file) { @@ -888,9 +888,6 @@ void codegen_link(CodeGen *g, const char *out_file) { zig_panic("unable to rename object file into final output: %s", err_str(err)); } } - if (g->verbose || g->verbose_link) { - fprintf(stderr, "OK\n"); - } return; } @@ -908,7 +905,7 @@ void codegen_link(CodeGen *g, const char *out_file) { construct_linker_job(&lj); - if (g->verbose || g->verbose_link) { + if (g->verbose_link) { for (size_t i = 0; i < lj.args.length; i += 1) { const char *space = (i != 0) ? " " : ""; fprintf(stderr, "%s%s", space, lj.args.at(i)); @@ -925,8 +922,4 @@ void codegen_link(CodeGen *g, const char *out_file) { } codegen_add_time_event(g, "Done"); - - if (g->verbose || g->verbose_link) { - fprintf(stderr, "OK\n"); - } } diff --git a/src/main.cpp b/src/main.cpp index a9a1d5a8da..bee021c6a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,67 +20,70 @@ static int usage(const char *arg0) { fprintf(stderr, "Usage: %s [command] [options]\n" "Commands:\n" " build build project from build.zig\n" - " build-exe [source] create executable from source or object files\n" - " build-lib [source] create library from source or object files\n" - " build-obj [source] create object from source or assembly\n" - " parsec [source] convert c code to zig code\n" + " build-exe $source create executable from source or object files\n" + " build-lib $source create library from source or object files\n" + " build-obj $source create object from source or assembly\n" + " parsec $source convert c code to zig code\n" " targets list available compilation targets\n" - " test [source] create and run a test build\n" + " test $source create and run a test build\n" " version print version number and exit\n" " zen print zen of zig and exit\n" "Compile Options:\n" - " --assembly [source] add assembly file to build\n" - " --cache-dir [path] override the cache directory\n" - " --color [auto|off|on] enable or disable colored error messages\n" + " --assembly $source add assembly file to build\n" + " --cache-dir $path override the cache directory\n" + " --color $auto|off|on enable or disable colored error messages\n" " --enable-timing-info print timing diagnostics\n" - " --libc-include-dir [path] directory where libc stdlib.h resides\n" - " --name [name] override output name\n" - " --output [file] override destination path\n" - " --output-h [file] override generated header file path\n" - " --pkg-begin [name] [path] make package available to import and push current pkg\n" + " --libc-include-dir $path directory where libc stdlib.h resides\n" + " --name $name override output name\n" + " --output $file override destination path\n" + " --output-h $file override generated header file path\n" + " --pkg-begin $name $path make package available to import and push current pkg\n" " --pkg-end pop current pkg\n" " --release-fast build with optimizations on and safety off\n" " --release-safe build with optimizations on and safety on\n" " --static output will be statically linked\n" " --strip exclude debug symbols\n" - " --target-arch [name] specify target architecture\n" - " --target-environ [name] specify target environment\n" - " --target-os [name] specify target operating system\n" - " --verbose turn on compiler debug output\n" - " --verbose-link turn on compiler debug output for linking only\n" - " --verbose-ir turn on compiler debug output for IR only\n" - " --zig-install-prefix [path] override directory where zig thinks it is installed\n" - " -dirafter [dir] same as -isystem but do it last\n" - " -isystem [dir] add additional search path for other .h files\n" - " -mllvm [arg] additional arguments to forward to LLVM's option processing\n" + " --target-arch $name specify target architecture\n" + " --target-environ $name specify target environment\n" + " --target-os $name specify target operating system\n" + " --verbose-tokenize turn on compiler debug output for tokenization\n" + " --verbose-ast turn on compiler debug output for parsing into an AST\n" + " --verbose-link turn on compiler debug output for linking\n" + " --verbose-ir turn on compiler debug output for Zig IR\n" + " --verbose-llvm-ir turn on compiler debug output for LLVM IR\n" + " --verbose-cimport turn on compiler debug output for C imports\n" + " --zig-install-prefix $path override directory where zig thinks it is installed\n" + " -dirafter $dir same as -isystem but do it last\n" + " -isystem $dir add additional search path for other .h files\n" + " -mllvm $arg additional arguments to forward to LLVM's option processing\n" "Link Options:\n" - " --ar-path [path] set the path to ar\n" - " --dynamic-linker [path] set the path to ld.so\n" + " --ar-path $path set the path to ar\n" + " --dynamic-linker $path set the path to ld.so\n" " --each-lib-rpath add rpath for each used dynamic library\n" - " --libc-lib-dir [path] directory where libc crt1.o resides\n" - " --libc-static-lib-dir [path] directory where libc crtbegin.o resides\n" - " --msvc-lib-dir [path] (windows) directory where vcruntime.lib resides\n" - " --kernel32-lib-dir [path] (windows) directory where kernel32.lib resides\n" - " --library [lib] link against lib\n" - " --library-path [dir] add a directory to the library search path\n" - " --linker-script [path] use a custom linker script\n" - " --object [obj] add object file to build\n" - " -L[dir] alias for --library-path\n" + " --libc-lib-dir $path directory where libc crt1.o resides\n" + " --libc-static-lib-dir $path directory where libc crtbegin.o resides\n" + " --msvc-lib-dir $path (windows) directory where vcruntime.lib resides\n" + " --kernel32-lib-dir $path (windows) directory where kernel32.lib resides\n" + " --library $lib link against lib\n" + " --library-path $dir add a directory to the library search path\n" + " --linker-script $path use a custom linker script\n" + " --object $obj add object file to build\n" + " -L$dir alias for --library-path\n" " -rdynamic add all symbols to the dynamic symbol table\n" - " -rpath [path] add directory to the runtime library search path\n" + " -rpath $path add directory to the runtime library search path\n" " -mconsole (windows) --subsystem console to the linker\n" " -mwindows (windows) --subsystem windows to the linker\n" " -municode (windows) link with unicode\n" - " -framework [name] (darwin) link against framework\n" - " -mios-version-min [ver] (darwin) set iOS deployment target\n" - " -mmacosx-version-min [ver] (darwin) set Mac OS X deployment target\n" - " --ver-major [ver] dynamic library semver major version\n" - " --ver-minor [ver] dynamic library semver minor version\n" - " --ver-patch [ver] dynamic library semver patch version\n" + " -framework $name (darwin) link against framework\n" + " -mios-version-min $ver (darwin) set iOS deployment target\n" + " -mmacosx-version-min $ver (darwin) set Mac OS X deployment target\n" + " --ver-major $ver dynamic library semver major version\n" + " --ver-minor $ver dynamic library semver minor version\n" + " --ver-patch $ver dynamic library semver patch version\n" "Test Options:\n" - " --test-filter [text] skip tests that do not match filter\n" - " --test-name-prefix [text] add prefix to all tests\n" - " --test-cmd [arg] specify test execution command one arg at a time\n" + " --test-filter $text skip tests that do not match filter\n" + " --test-name-prefix $text add prefix to all tests\n" + " --test-cmd $arg specify test execution command one arg at a time\n" " --test-cmd-bin appends test binary path to test cmd args\n" , arg0); return EXIT_FAILURE; @@ -274,9 +277,12 @@ int main(int argc, char **argv) { bool is_static = false; OutType out_type = OutTypeUnknown; const char *out_name = nullptr; - bool verbose = false; + bool verbose_tokenize = false; + bool verbose_ast = false; bool verbose_link = false; bool verbose_ir = false; + bool verbose_llvm_ir = false; + bool verbose_cimport = false; ErrColor color = ErrColorAuto; const char *libc_lib_dir = nullptr; const char *libc_static_lib_dir = nullptr; @@ -328,9 +334,7 @@ int main(int argc, char **argv) { args.append(NULL); // placeholder args.append(NULL); // placeholder for (int i = 2; i < argc; i += 1) { - if (strcmp(argv[i], "--debug-build-verbose") == 0) { - verbose = true; - } else if (strcmp(argv[i], "--help") == 0) { + if (strcmp(argv[i], "--help") == 0) { asked_for_help = true; args.append(argv[i]); } else if (i + 1 < argc && strcmp(argv[i], "--build-file") == 0) { @@ -363,7 +367,6 @@ int main(int argc, char **argv) { CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf); codegen_set_out_name(g, buf_create_from_str("build")); - codegen_set_verbose(g, verbose); Buf build_file_abs = BUF_INIT; os_path_resolve(buf_create_from_str("."), buf_create_from_str(build_file), &build_file_abs); @@ -398,14 +401,30 @@ int main(int argc, char **argv) { "\n" "General Options:\n" " --help Print this help and exit\n" - " --build-file [file] Override path to build.zig\n" - " --cache-dir [path] Override path to cache directory\n" + " --build-file $file Override path to build.zig\n" + " --cache-dir $path Override path to cache directory\n" " --verbose Print commands before executing them\n" - " --debug-build-verbose Print verbose debugging information for the build system itself\n" - " --prefix [prefix] Override default install prefix\n" + " --verbose-tokenize Enable compiler debug output for tokenization\n" + " --verbose-ast Enable compiler debug output for parsing into an AST\n" + " --verbose-link Enable compiler debug output for linking\n" + " --verbose-ir Enable compiler debug output for Zig IR\n" + " --verbose-llvm-ir Enable compiler debug output for LLVM IR\n" + " --verbose-cimport Enable compiler debug output for C imports\n" + " --prefix $path Override default install prefix\n" "\n" - "More options become available when the build file is found.\n" + "Project-specific options become available when the build file is found.\n" "Run this command with no options to generate a build.zig template.\n" + "\n" + "Advanced Options:\n" + " --build-file $file Override path to build.zig\n" + " --cache-dir $path Override path to cache directory\n" + " --verbose-tokenize Enable compiler debug output for tokenization\n" + " --verbose-ast Enable compiler debug output for parsing into an AST\n" + " --verbose-link Enable compiler debug output for linking\n" + " --verbose-ir Enable compiler debug output for Zig IR\n" + " --verbose-llvm-ir Enable compiler debug output for LLVM IR\n" + " --verbose-cimport Enable compiler debug output for C imports\n" + "\n" , zig_exe_path); return 0; } @@ -452,12 +471,18 @@ int main(int argc, char **argv) { strip = true; } else if (strcmp(arg, "--static") == 0) { is_static = true; - } else if (strcmp(arg, "--verbose") == 0) { - verbose = true; + } else if (strcmp(arg, "--verbose-tokenize") == 0) { + verbose_tokenize = true; + } else if (strcmp(arg, "--verbose-ast") == 0) { + verbose_ast = true; } else if (strcmp(arg, "--verbose-link") == 0) { verbose_link = true; } else if (strcmp(arg, "--verbose-ir") == 0) { verbose_ir = true; + } else if (strcmp(arg, "--verbose-llvm-ir") == 0) { + verbose_llvm_ir = true; + } else if (strcmp(arg, "--verbose-cimport") == 0) { + verbose_cimport = true; } else if (strcmp(arg, "-mwindows") == 0) { mwindows = true; } else if (strcmp(arg, "-mconsole") == 0) { @@ -742,9 +767,12 @@ int main(int argc, char **argv) { codegen_set_kernel32_lib_dir(g, buf_create_from_str(kernel32_lib_dir)); if (dynamic_linker) codegen_set_dynamic_linker(g, buf_create_from_str(dynamic_linker)); - codegen_set_verbose(g, verbose); + g->verbose_tokenize = verbose_tokenize; + g->verbose_ast = verbose_ast; g->verbose_link = verbose_link; g->verbose_ir = verbose_ir; + g->verbose_llvm_ir = verbose_llvm_ir; + g->verbose_cimport = verbose_cimport; codegen_set_errmsg_color(g, color); for (size_t i = 0; i < lib_dirs.length; i += 1) { diff --git a/src/parsec.cpp b/src/parsec.cpp index d200c0531d..586e95bc75 100644 --- a/src/parsec.cpp +++ b/src/parsec.cpp @@ -3167,7 +3167,7 @@ int parse_h_file(ImportTableEntry *import, ZigList *errors, const ch { Context context = {0}; Context *c = &context; - c->warnings_on = codegen->verbose; + c->warnings_on = codegen->verbose_cimport; c->import = import; c->errors = errors; if (buf_ends_with_str(buf_create_from_str(target_file), ".h")) { diff --git a/std/build.zig b/std/build.zig index 84eba6d33b..7cf2ac5987 100644 --- a/std/build.zig +++ b/std/build.zig @@ -33,6 +33,12 @@ pub const Builder = struct { available_options_map: AvailableOptionsMap, available_options_list: ArrayList(AvailableOption), verbose: bool, + verbose_tokenize: bool, + verbose_ast: bool, + verbose_link: bool, + verbose_ir: bool, + verbose_llvm_ir: bool, + verbose_cimport: bool, invalid_user_input: bool, zig_exe: []const u8, default_step: &Step, @@ -88,6 +94,12 @@ pub const Builder = struct { .build_root = build_root, .cache_root = %%os.path.relative(allocator, build_root, cache_root), .verbose = false, + .verbose_tokenize = false, + .verbose_ast = false, + .verbose_link = false, + .verbose_ir = false, + .verbose_llvm_ir = false, + .verbose_cimport = false, .invalid_user_input = false, .allocator = allocator, .lib_paths = ArrayList([]const u8).init(allocator), @@ -536,15 +548,19 @@ pub const Builder = struct { return self.spawnChildEnvMap(null, &self.env_map, argv); } + fn printCmd(cwd: ?[]const u8, argv: []const []const u8) { + if (cwd) |yes_cwd| %%io.stderr.print("cd {} && ", yes_cwd); + for (argv) |arg| { + %%io.stderr.print("{} ", arg); + } + %%io.stderr.printf("\n"); + } + fn spawnChildEnvMap(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap, argv: []const []const u8) -> %void { if (self.verbose) { - if (cwd) |yes_cwd| %%io.stderr.print("cd {}; ", yes_cwd); - for (argv) |arg| { - %%io.stderr.print("{} ", arg); - } - %%io.stderr.printf("\n"); + printCmd(cwd, argv); } const child = %%os.ChildProcess.init(argv, self.allocator); @@ -561,12 +577,15 @@ pub const Builder = struct { switch (term) { Term.Exited => |code| { if (code != 0) { - %%io.stderr.printf("Process {} exited with error code {}\n", argv[0], code); + %%io.stderr.printf("The following command exited with error code {}:\n", code); + printCmd(cwd, argv); return error.UncleanExit; } }, else => { - %%io.stderr.printf("Process {} terminated unexpectedly\n", argv[0]); + %%io.stderr.printf("The following command terminated unexpectedly:\n"); + printCmd(cwd, argv); + return error.UncleanExit; }, }; @@ -1117,6 +1136,12 @@ pub const LibExeObjStep = struct { if (self.verbose) { %%zig_args.append("--verbose"); } + if (builder.verbose_tokenize) %%zig_args.append("--verbose-tokenize"); + if (builder.verbose_ast) %%zig_args.append("--verbose-ast"); + if (builder.verbose_cimport) %%zig_args.append("--verbose-cimport"); + if (builder.verbose_ir) %%zig_args.append("--verbose-ir"); + if (builder.verbose_llvm_ir) %%zig_args.append("--verbose-llvm-ir"); + if (builder.verbose_link) %%zig_args.append("--verbose-link"); if (self.strip) { %%zig_args.append("--strip"); diff --git a/std/special/build_runner.zig b/std/special/build_runner.zig index b1fbfc6c2b..089137c923 100644 --- a/std/special/build_runner.zig +++ b/std/special/build_runner.zig @@ -69,6 +69,18 @@ pub fn main() -> %void { %%io.stderr.printf("Expected argument after --prefix\n\n"); return usage(&builder, false, &io.stderr); }); + } else if (mem.eql(u8, arg, "--verbose-tokenize")) { + builder.verbose_tokenize = true; + } else if (mem.eql(u8, arg, "--verbose-ast")) { + builder.verbose_ast = true; + } else if (mem.eql(u8, arg, "--verbose-link")) { + builder.verbose_link = true; + } else if (mem.eql(u8, arg, "--verbose-ir")) { + builder.verbose_ir = true; + } else if (mem.eql(u8, arg, "--verbose-llvm-ir")) { + builder.verbose_llvm_ir = true; + } else if (mem.eql(u8, arg, "--verbose-cimport")) { + builder.verbose_cimport = true; } else { %%io.stderr.printf("Unrecognized argument: {}\n\n", arg); return usage(&builder, false, &io.stderr); @@ -116,27 +128,40 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) \\ \\General Options: \\ --help Print this help and exit - \\ --build-file [file] Override path to build.zig - \\ --cache-dir [path] Override path to cache directory \\ --verbose Print commands before executing them - \\ --debug-build-verbose Print verbose debugging information for the build system itself - \\ --prefix [prefix] Override default install prefix + \\ --prefix $path Override default install prefix \\ \\Project-Specific Options: \\ ); if (builder.available_options_list.len == 0) { - %%out_stream.printf(" (none)\n"); + %%out_stream.print(" (none)\n"); } else { for (builder.available_options_list.toSliceConst()) |option| { const name = %%fmt.allocPrint(allocator, - " -D{}=({})", option.name, Builder.typeIdName(option.type_id)); + " -D{}=${}", option.name, Builder.typeIdName(option.type_id)); defer allocator.free(name); - %%out_stream.printf("{s24} {}\n", name, option.description); + %%out_stream.print("{s24} {}\n", name, option.description); } } + %%out_stream.write( + \\ + \\Advanced Options: + \\ --build-file $file Override path to build.zig + \\ --cache-dir $path Override path to zig cache directory + \\ --verbose-tokenize Enable compiler debug output for tokenization + \\ --verbose-ast Enable compiler debug output for parsing into an AST + \\ --verbose-link Enable compiler debug output for linking + \\ --verbose-ir Enable compiler debug output for Zig IR + \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR + \\ --verbose-cimport Enable compiler debug output for C imports + \\ + ); + + %%out_stream.flush(); + if (out_stream == &io.stderr) return error.InvalidArgs; } -- cgit v1.2.3