diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2015-11-24 22:32:26 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2015-11-24 22:32:26 -0700 |
| commit | 505317a12fd89b144097e4b99e84b619f7ca5ac2 (patch) | |
| tree | dde38d6810e2f0497599b61e5ea0282e83db2052 /src/codegen.cpp | |
| parent | cda10f0577fcf5794f1f583ff159311a1b186082 (diff) | |
| download | zig-505317a12fd89b144097e4b99e84b619f7ca5ac2.tar.gz zig-505317a12fd89b144097e4b99e84b619f7ca5ac2.zip | |
debug/release mode
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index 5a47f68de3..5cd8236260 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -60,6 +60,8 @@ struct CodeGen { LLVMTargetDataRef target_data_ref; unsigned pointer_size_bytes; bool is_static; + bool strip_debug_symbols; + CodeGenBuildType build_type; LLVMTargetMachineRef target_machine; Buf in_file; Buf in_dir; @@ -77,19 +79,33 @@ struct CodeGenNode { } data; }; -CodeGen *create_codegen(AstNode *root, bool is_static, Buf *in_full_path) { +CodeGen *create_codegen(AstNode *root, Buf *in_full_path) { CodeGen *g = allocate<CodeGen>(1); g->root = root; g->fn_defs.init(32); g->fn_table.init(32); g->str_table.init(32); g->type_table.init(32); - g->is_static = is_static; + g->is_static = false; + g->build_type = CodeGenBuildTypeDebug; + g->strip_debug_symbols = false; os_path_split(in_full_path, &g->in_dir, &g->in_file); return g; } +void codegen_set_build_type(CodeGen *g, CodeGenBuildType build_type) { + g->build_type = build_type; +} + +void codegen_set_is_static(CodeGen *g, bool is_static) { + g->is_static = is_static; +} + +void codegen_set_strip(CodeGen *g, bool strip) { + g->strip_debug_symbols = strip; +} + static void add_node_error(CodeGen *g, AstNode *node, Buf *msg) { g->errors.add_one(); ErrorMsg *last_msg = &g->errors.last(); @@ -352,7 +368,8 @@ void semantic_analyze(CodeGen *g) { char *native_cpu = LLVMZigGetHostCPUName(); char *native_features = LLVMZigGetNativeFeatures(); - LLVMCodeGenOptLevel opt_level = LLVMCodeGenLevelNone; + LLVMCodeGenOptLevel opt_level = (g->build_type == CodeGenBuildTypeDebug) ? + LLVMCodeGenLevelNone : LLVMCodeGenLevelAggressive; LLVMRelocMode reloc_mode = g->is_static ? LLVMRelocStatic : LLVMRelocPIC; @@ -522,12 +539,13 @@ static llvm::DISubroutineType *create_di_function_type(CodeGen *g, AstNodeFnProt void code_gen(CodeGen *g) { Buf *producer = buf_sprintf("zig %s", ZIG_VERSION_STRING); - bool is_optimized = false; + bool is_optimized = g->build_type == CodeGenBuildTypeRelease; const char *flags = ""; unsigned runtime_version = 0; g->compile_unit = g->dbuilder->createCompileUnit(llvm::dwarf::DW_LANG_C99, buf_ptr(&g->in_file), buf_ptr(&g->in_dir), - buf_ptr(producer), is_optimized, flags, runtime_version); + buf_ptr(producer), is_optimized, flags, runtime_version, + "", llvm::DIBuilder::FullDebug, 0, !g->strip_debug_symbols); g->block_scopes.append(g->compile_unit); @@ -615,6 +633,9 @@ void code_gen_link(CodeGen *g, const char *out_file) { } ZigList<const char *> args = {0}; + if (g->is_static) { + args.append("-static"); + } args.append("-o"); args.append(out_file); args.append((const char *)buf_ptr(&out_file_o)); |
