| author | |
| committer | |
| log | c281533638dd08bb84f4f538fd8c5ae85791d034 |
| tree | 94ed711ef254a4b35d729dd944c1da2d0f833e63 |
| parent | 69d4f55fbf816bf417dfab9c0e7525971922f166 |
7 files changed, 29 insertions(+), 9 deletions(-)
src/all_types.hpp+3| ... | ... | @@ -1041,6 +1041,9 @@ struct CodeGen { |
| 1041 | 1041 | uint32_t error_value_count; |
| 1042 | 1042 | TypeTableEntry *err_tag_type; |
| 1043 | 1043 | LLVMValueRef int_overflow_fns[2][3][4]; // [0-signed,1-unsigned][0-add,1-sub,2-mul][0-8,1-16,2-32,3-64] |
| 1044 | ||
| 1045 | const char **clang_argv; | |
| 1046 | int clang_argv_len; | |
| 1044 | 1047 | }; |
| 1045 | 1048 | |
| 1046 | 1049 | struct VariableTableEntry { |
src/analyze.cpp+3-1| ... | ... | @@ -1057,7 +1057,9 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *import, AstNode |
| 1057 | 1057 | find_libc_path(g); |
| 1058 | 1058 | int err; |
| 1059 | 1059 | ParseH parse_h = {{0}}; |
| 1060 | if ((err = parse_h_buf(&parse_h, child_context->c_import_buf, buf_ptr(g->libc_include_path)))) { | |
| 1060 | if ((err = parse_h_buf(&parse_h, child_context->c_import_buf, g->clang_argv, g->clang_argv_len, | |
| 1061 | buf_ptr(g->libc_include_path)))) | |
| 1062 | { | |
| 1061 | 1063 | zig_panic("unable to parse h file: %s\n", err_str(err)); |
| 1062 | 1064 | } |
| 1063 | 1065 |
src/codegen.cpp+5| ... | ... | @@ -32,6 +32,11 @@ CodeGen *codegen_create(Buf *root_source_dir) { |
| 32 | 32 | return g; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | void codegen_set_clang_argv(CodeGen *g, const char **args, int len) { | |
| 36 | g->clang_argv = args; | |
| 37 | g->clang_argv_len = len; | |
| 38 | } | |
| 39 | ||
| 35 | 40 | void codegen_set_build_type(CodeGen *g, CodeGenBuildType build_type) { |
| 36 | 41 | g->build_type = build_type; |
| 37 | 42 | } |
src/codegen.hpp+1| ... | ... | @@ -13,6 +13,7 @@ |
| 13 | 13 | |
| 14 | 14 | CodeGen *codegen_create(Buf *root_source_dir); |
| 15 | 15 | |
| 16 | void codegen_set_clang_argv(CodeGen *codegen, const char **args, int len); | |
| 16 | 17 | void codegen_set_build_type(CodeGen *codegen, CodeGenBuildType build_type); |
| 17 | 18 | void codegen_set_is_static(CodeGen *codegen, bool is_static); |
| 18 | 19 | void codegen_set_strip(CodeGen *codegen, bool strip); |
src/main.cpp+11-6| ... | ... | @@ -20,7 +20,7 @@ static int usage(const char *arg0) { |
| 20 | 20 | " build create executable, object, or library from target\n" |
| 21 | 21 | " version print version number and exit\n" |
| 22 | 22 | " parseh convert a c header file to zig extern declarations\n" |
| 23 | "Command: build target\n" | |
| 23 | "Options:\n" | |
| 24 | 24 | " --release build with optimizations on and debug protection off\n" |
| 25 | 25 | " --static output will be statically linked\n" |
| 26 | 26 | " --strip exclude debug symbols\n" |
| ... | ... | @@ -30,10 +30,8 @@ static int usage(const char *arg0) { |
| 30 | 30 | " --verbose turn on compiler debug output\n" |
| 31 | 31 | " --color [auto|off|on] enable or disable colored error messages\n" |
| 32 | 32 | " --libc-path [path] set the C compiler data path\n" |
| 33 | "Command: parseh target\n" | |
| 34 | 33 | " -isystem [dir] add additional search path for other .h files\n" |
| 35 | 34 | " -dirafter [dir] same as -isystem but do it last\n" |
| 36 | " -B[prefix] set the C compiler data path\n" | |
| 37 | 35 | , arg0); |
| 38 | 36 | return EXIT_FAILURE; |
| 39 | 37 | } |
| ... | ... | @@ -54,6 +52,7 @@ struct Build { |
| 54 | 52 | bool verbose; |
| 55 | 53 | ErrColor color; |
| 56 | 54 | const char *libc_path; |
| 55 | ZigList<const char *> clang_argv; | |
| 57 | 56 | }; |
| 58 | 57 | |
| 59 | 58 | static int build(const char *arg0, int argc, char **argv) { |
| ... | ... | @@ -62,7 +61,7 @@ static int build(const char *arg0, int argc, char **argv) { |
| 62 | 61 | |
| 63 | 62 | for (int i = 0; i < argc; i += 1) { |
| 64 | 63 | char *arg = argv[i]; |
| 65 | if (arg[0] == '-' && arg[1] == '-') { | |
| 64 | if (arg[0] == '-') { | |
| 66 | 65 | if (strcmp(arg, "--release") == 0) { |
| 67 | 66 | b.release = true; |
| 68 | 67 | } else if (strcmp(arg, "--strip") == 0) { |
| ... | ... | @@ -103,6 +102,12 @@ static int build(const char *arg0, int argc, char **argv) { |
| 103 | 102 | b.out_name = argv[i]; |
| 104 | 103 | } else if (strcmp(arg, "--libc-path") == 0) { |
| 105 | 104 | b.libc_path = argv[i]; |
| 105 | } else if (strcmp(arg, "-isystem") == 0) { | |
| 106 | b.clang_argv.append("-isystem"); | |
| 107 | b.clang_argv.append(argv[i]); | |
| 108 | } else if (strcmp(arg, "-dirafter") == 0) { | |
| 109 | b.clang_argv.append("-dirafter"); | |
| 110 | b.clang_argv.append(argv[i]); | |
| 106 | 111 | } else { |
| 107 | 112 | return usage(arg0); |
| 108 | 113 | } |
| ... | ... | @@ -140,6 +145,7 @@ static int build(const char *arg0, int argc, char **argv) { |
| 140 | 145 | |
| 141 | 146 | CodeGen *g = codegen_create(&root_source_dir); |
| 142 | 147 | codegen_set_build_type(g, b.release ? CodeGenBuildTypeRelease : CodeGenBuildTypeDebug); |
| 148 | codegen_set_clang_argv(g, b.clang_argv.items, b.clang_argv.length); | |
| 143 | 149 | codegen_set_strip(g, b.strip); |
| 144 | 150 | codegen_set_is_static(g, b.is_static); |
| 145 | 151 | if (b.out_type != OutTypeUnknown) |
| ... | ... | @@ -202,8 +208,7 @@ static int parseh(const char *arg0, int argc, char **argv) { |
| 202 | 208 | } |
| 203 | 209 | clang_argv.append("-isystem"); |
| 204 | 210 | clang_argv.append(argv[i + 1]); |
| 205 | } else if (arg[1] == 'B') { | |
| 206 | clang_argv.append(arg); | |
| 211 | i += 1; | |
| 207 | 212 | } else { |
| 208 | 213 | fprintf(stderr, "unrecognized argument: %s", arg); |
| 209 | 214 | return usage(arg0); |
src/parseh.cpp+5-1| ... | ... | @@ -345,7 +345,7 @@ static bool decl_visitor(void *context, const Decl *decl) { |
| 345 | 345 | return true; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | int parse_h_buf(ParseH *parse_h, Buf *source, const char *libc_include_path) { | |
| 348 | int parse_h_buf(ParseH *parse_h, Buf *source, const char **args, int args_len, const char *libc_include_path) { | |
| 349 | 349 | int err; |
| 350 | 350 | Buf tmp_file_path = BUF_INIT; |
| 351 | 351 | if ((err = os_buf_to_tmp_file(source, buf_create_from_str(".h"), &tmp_file_path))) { |
| ... | ... | @@ -357,6 +357,10 @@ int parse_h_buf(ParseH *parse_h, Buf *source, const char *libc_include_path) { |
| 357 | 357 | clang_argv.append("-isystem"); |
| 358 | 358 | clang_argv.append(libc_include_path); |
| 359 | 359 | |
| 360 | for (int i = 0; i < args_len; i += 1) { | |
| 361 | clang_argv.append(args[i]); | |
| 362 | } | |
| 363 | ||
| 360 | 364 | err = parse_h_file(parse_h, &clang_argv); |
| 361 | 365 | |
| 362 | 366 | os_delete_file(&tmp_file_path); |
src/parseh.hpp+1-1| ... | ... | @@ -12,6 +12,6 @@ |
| 12 | 12 | #include "all_types.hpp" |
| 13 | 13 | |
| 14 | 14 | int parse_h_file(ParseH *parse_h, ZigList<const char *> *clang_argv); |
| 15 | int parse_h_buf(ParseH *parse_h, Buf *buf, const char *libc_include_path); | |
| 15 | int parse_h_buf(ParseH *parse_h, Buf *source, const char **args, int args_len, const char *libc_include_path); | |
| 16 | 16 | |
| 17 | 17 | #endif |