| author | |
| committer | |
| log | 0ac714f0d6a23ea1810c8a6327dc6048c2df14c5 |
| tree | 65c8a02312b231549d2936f37a5eb4f67810091e |
| parent | 41b95cc2374010f39b903cb4b90d233d2f7d57c4 |
5 files changed, 26 insertions(+), 2 deletions(-)
src/all_types.hpp+1| ... | @@ -1096,6 +1096,7 @@ struct CodeGen { | ... | @@ -1096,6 +1096,7 @@ struct CodeGen { |
| 1096 | 1096 | ||
| 1097 | const char **clang_argv; | 1097 | const char **clang_argv; |
| 1098 | int clang_argv_len; | 1098 | int clang_argv_len; |
| 1099 | ZigList<const char *> lib_dirs; | ||
| 1099 | }; | 1100 | }; |
| 1100 | 1101 | ||
| 1101 | struct VariableTableEntry { | 1102 | struct VariableTableEntry { |
src/analyze.cpp+1-1| ... | @@ -538,7 +538,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId fn_type_id) { | ... | @@ -538,7 +538,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId fn_type_id) { |
| 538 | fn_type->data.fn.raw_type_ref = LLVMFunctionType(gen_return_type->type_ref, | 538 | fn_type->data.fn.raw_type_ref = LLVMFunctionType(gen_return_type->type_ref, |
| 539 | gen_param_types, gen_param_index, fn_type_id.is_var_args); | 539 | gen_param_types, gen_param_index, fn_type_id.is_var_args); |
| 540 | fn_type->type_ref = LLVMPointerType(fn_type->data.fn.raw_type_ref, 0); | 540 | fn_type->type_ref = LLVMPointerType(fn_type->data.fn.raw_type_ref, 0); |
| 541 | LLVMZigDIFile *di_file = nullptr; // TODO if we get a crash maybe this is the culprit | 541 | LLVMZigDIFile *di_file = nullptr; |
| 542 | fn_type->di_type = LLVMZigCreateSubroutineType(g->dbuilder, di_file, | 542 | fn_type->di_type = LLVMZigCreateSubroutineType(g->dbuilder, di_file, |
| 543 | param_di_types, gen_param_index + 1, 0); | 543 | param_di_types, gen_param_index + 1, 0); |
| 544 | 544 |
src/codegen.cpp+15-1| ... | @@ -73,6 +73,10 @@ void codegen_set_libc_path(CodeGen *g, Buf *libc_path) { | ... | @@ -73,6 +73,10 @@ void codegen_set_libc_path(CodeGen *g, Buf *libc_path) { |
| 73 | g->libc_path = libc_path; | 73 | g->libc_path = libc_path; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | void codegen_add_lib_dir(CodeGen *g, const char *dir) { | ||
| 77 | g->lib_dirs.append(dir); | ||
| 78 | } | ||
| 79 | |||
| 76 | static LLVMValueRef gen_expr(CodeGen *g, AstNode *expr_node); | 80 | static LLVMValueRef gen_expr(CodeGen *g, AstNode *expr_node); |
| 77 | static LLVMValueRef gen_lvalue(CodeGen *g, AstNode *expr_node, AstNode *node, TypeTableEntry **out_type_entry); | 81 | static LLVMValueRef gen_lvalue(CodeGen *g, AstNode *expr_node, AstNode *node, TypeTableEntry **out_type_entry); |
| 78 | static LLVMValueRef gen_field_access_expr(CodeGen *g, AstNode *node, bool is_lvalue); | 82 | static LLVMValueRef gen_field_access_expr(CodeGen *g, AstNode *node, bool is_lvalue); |
| ... | @@ -3648,6 +3652,12 @@ void codegen_link(CodeGen *g, const char *out_file) { | ... | @@ -3648,6 +3652,12 @@ void codegen_link(CodeGen *g, const char *out_file) { |
| 3648 | args.append(get_libc_file(g, "crtn.o")); | 3652 | args.append(get_libc_file(g, "crtn.o")); |
| 3649 | } | 3653 | } |
| 3650 | 3654 | ||
| 3655 | for (int i = 0; i < g->lib_dirs.length; i += 1) { | ||
| 3656 | const char *lib_dir = g->lib_dirs.at(i); | ||
| 3657 | args.append("-L"); | ||
| 3658 | args.append(lib_dir); | ||
| 3659 | } | ||
| 3660 | |||
| 3651 | auto it = g->link_table.entry_iterator(); | 3661 | auto it = g->link_table.entry_iterator(); |
| 3652 | for (;;) { | 3662 | for (;;) { |
| 3653 | auto *entry = it.next(); | 3663 | auto *entry = it.next(); |
| ... | @@ -3673,7 +3683,11 @@ void codegen_link(CodeGen *g, const char *out_file) { | ... | @@ -3673,7 +3683,11 @@ void codegen_link(CodeGen *g, const char *out_file) { |
| 3673 | 3683 | ||
| 3674 | if (return_code != 0) { | 3684 | if (return_code != 0) { |
| 3675 | fprintf(stderr, "ld failed with return code %d\n", return_code); | 3685 | fprintf(stderr, "ld failed with return code %d\n", return_code); |
| 3676 | fprintf(stderr, "%s\n", buf_ptr(&ld_stderr)); | 3686 | fprintf(stderr, "ld "); |
| 3687 | for (int i = 0; i < args.length; i += 1) { | ||
| 3688 | fprintf(stderr, "%s ", args.at(i)); | ||
| 3689 | } | ||
| 3690 | fprintf(stderr, "\n%s\n", buf_ptr(&ld_stderr)); | ||
| 3677 | exit(1); | 3691 | exit(1); |
| 3678 | } else if (buf_len(&ld_stderr)) { | 3692 | } else if (buf_len(&ld_stderr)) { |
| 3679 | fprintf(stderr, "%s\n", buf_ptr(&ld_stderr)); | 3693 | fprintf(stderr, "%s\n", buf_ptr(&ld_stderr)); |
src/codegen.hpp+1| ... | @@ -24,6 +24,7 @@ void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color); | ... | @@ -24,6 +24,7 @@ void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color); |
| 24 | void codegen_set_out_type(CodeGen *codegen, OutType out_type); | 24 | void codegen_set_out_type(CodeGen *codegen, OutType out_type); |
| 25 | void codegen_set_out_name(CodeGen *codegen, Buf *out_name); | 25 | void codegen_set_out_name(CodeGen *codegen, Buf *out_name); |
| 26 | void codegen_set_libc_path(CodeGen *codegen, Buf *libc_path); | 26 | void codegen_set_libc_path(CodeGen *codegen, Buf *libc_path); |
| 27 | void codegen_add_lib_dir(CodeGen *codegen, const char *dir); | ||
| 27 | 28 | ||
| 28 | void codegen_add_root_code(CodeGen *g, Buf *source_dir, Buf *source_basename, Buf *source_code); | 29 | void codegen_add_root_code(CodeGen *g, Buf *source_dir, Buf *source_basename, Buf *source_code); |
| 29 | 30 |
src/main.cpp+8| ... | @@ -31,6 +31,7 @@ static int usage(const char *arg0) { | ... | @@ -31,6 +31,7 @@ static int usage(const char *arg0) { |
| 31 | " --libc-path [path] set the C compiler data path\n" | 31 | " --libc-path [path] set the C compiler data path\n" |
| 32 | " -isystem [dir] add additional search path for other .h files\n" | 32 | " -isystem [dir] add additional search path for other .h files\n" |
| 33 | " -dirafter [dir] same as -isystem but do it last\n" | 33 | " -dirafter [dir] same as -isystem but do it last\n" |
| 34 | " --library-path [dir] add a directory to the library search path\n" | ||
| 34 | , arg0); | 35 | , arg0); |
| 35 | return EXIT_FAILURE; | 36 | return EXIT_FAILURE; |
| 36 | } | 37 | } |
| ... | @@ -56,6 +57,7 @@ int main(int argc, char **argv) { | ... | @@ -56,6 +57,7 @@ int main(int argc, char **argv) { |
| 56 | ErrColor color = ErrColorAuto; | 57 | ErrColor color = ErrColorAuto; |
| 57 | const char *libc_path = nullptr; | 58 | const char *libc_path = nullptr; |
| 58 | ZigList<const char *> clang_argv = {0}; | 59 | ZigList<const char *> clang_argv = {0}; |
| 60 | ZigList<const char *> lib_dirs = {0}; | ||
| 59 | int err; | 61 | int err; |
| 60 | 62 | ||
| 61 | for (int i = 1; i < argc; i += 1) { | 63 | for (int i = 1; i < argc; i += 1) { |
| ... | @@ -108,6 +110,8 @@ int main(int argc, char **argv) { | ... | @@ -108,6 +110,8 @@ int main(int argc, char **argv) { |
| 108 | } else if (strcmp(arg, "-dirafter") == 0) { | 110 | } else if (strcmp(arg, "-dirafter") == 0) { |
| 109 | clang_argv.append("-dirafter"); | 111 | clang_argv.append("-dirafter"); |
| 110 | clang_argv.append(argv[i]); | 112 | clang_argv.append(argv[i]); |
| 113 | } else if (strcmp(arg, "--library-path") == 0) { | ||
| 114 | lib_dirs.append(argv[i]); | ||
| 111 | } else { | 115 | } else { |
| 112 | return usage(arg0); | 116 | return usage(arg0); |
| 113 | } | 117 | } |
| ... | @@ -183,6 +187,10 @@ int main(int argc, char **argv) { | ... | @@ -183,6 +187,10 @@ int main(int argc, char **argv) { |
| 183 | codegen_set_verbose(g, verbose); | 187 | codegen_set_verbose(g, verbose); |
| 184 | codegen_set_errmsg_color(g, color); | 188 | codegen_set_errmsg_color(g, color); |
| 185 | 189 | ||
| 190 | for (int i = 0; i < lib_dirs.length; i += 1) { | ||
| 191 | codegen_add_lib_dir(g, lib_dirs.at(i)); | ||
| 192 | } | ||
| 193 | |||
| 186 | if (cmd == CmdBuild) { | 194 | if (cmd == CmdBuild) { |
| 187 | codegen_add_root_code(g, &root_source_dir, &root_source_name, &root_source_code); | 195 | codegen_add_root_code(g, &root_source_dir, &root_source_name, &root_source_code); |
| 188 | codegen_link(g, out_file); | 196 | codegen_link(g, out_file); |