| author | |
| committer | |
| log | 783f73c7e3590f05825d66f1f0ccb108be74b5c4 |
| tree | 429e9e06852b06bd6758ab2bd7d53a240a71771c |
| parent | 6695fa4f326e807256b9afc6321e63a90b08e1ba |
| signature |
13 files changed, 122 insertions(+), 90 deletions(-)
src-self-hosted/clang_options_data.zig+5-5| ... | @@ -7,7 +7,7 @@ flagpd1("CC"), | ... | @@ -7,7 +7,7 @@ flagpd1("CC"), |
| 7 | .{ | 7 | .{ |
| 8 | .name = "E", | 8 | .name = "E", |
| 9 | .syntax = .flag, | 9 | .syntax = .flag, |
| 10 | .zig_equivalent = .preprocess, | 10 | .zig_equivalent = .pp_or_asm, |
| 11 | .pd1 = true, | 11 | .pd1 = true, |
| 12 | .pd2 = false, | 12 | .pd2 = false, |
| 13 | .psl = false, | 13 | .psl = false, |
| ... | @@ -53,7 +53,7 @@ flagpd1("Qy"), | ... | @@ -53,7 +53,7 @@ flagpd1("Qy"), |
| 53 | .{ | 53 | .{ |
| 54 | .name = "S", | 54 | .name = "S", |
| 55 | .syntax = .flag, | 55 | .syntax = .flag, |
| 56 | .zig_equivalent = .driver_punt, | 56 | .zig_equivalent = .pp_or_asm, |
| 57 | .pd1 = true, | 57 | .pd1 = true, |
| 58 | .pd2 = false, | 58 | .pd2 = false, |
| 59 | .psl = false, | 59 | .psl = false, |
| ... | @@ -154,7 +154,7 @@ sepd1("Zlinker-input"), | ... | @@ -154,7 +154,7 @@ sepd1("Zlinker-input"), |
| 154 | .{ | 154 | .{ |
| 155 | .name = "E", | 155 | .name = "E", |
| 156 | .syntax = .flag, | 156 | .syntax = .flag, |
| 157 | .zig_equivalent = .preprocess, | 157 | .zig_equivalent = .pp_or_asm, |
| 158 | .pd1 = true, | 158 | .pd1 = true, |
| 159 | .pd2 = false, | 159 | .pd2 = false, |
| 160 | .psl = true, | 160 | .psl = true, |
| ... | @@ -1442,7 +1442,7 @@ sepd1("Zlinker-input"), | ... | @@ -1442,7 +1442,7 @@ sepd1("Zlinker-input"), |
| 1442 | .{ | 1442 | .{ |
| 1443 | .name = "assemble", | 1443 | .name = "assemble", |
| 1444 | .syntax = .flag, | 1444 | .syntax = .flag, |
| 1445 | .zig_equivalent = .driver_punt, | 1445 | .zig_equivalent = .pp_or_asm, |
| 1446 | .pd1 = false, | 1446 | .pd1 = false, |
| 1447 | .pd2 = true, | 1447 | .pd2 = true, |
| 1448 | .psl = false, | 1448 | .psl = false, |
| ... | @@ -1770,7 +1770,7 @@ sepd1("Zlinker-input"), | ... | @@ -1770,7 +1770,7 @@ sepd1("Zlinker-input"), |
| 1770 | .{ | 1770 | .{ |
| 1771 | .name = "preprocess", | 1771 | .name = "preprocess", |
| 1772 | .syntax = .flag, | 1772 | .syntax = .flag, |
| 1773 | .zig_equivalent = .preprocess, | 1773 | .zig_equivalent = .pp_or_asm, |
| 1774 | .pd1 = false, | 1774 | .pd1 = false, |
| 1775 | .pd2 = true, | 1775 | .pd2 = true, |
| 1776 | .psl = false, | 1776 | .psl = false, |
src-self-hosted/stage2.zig+1-1| ... | @@ -1280,7 +1280,7 @@ pub const ClangArgIterator = extern struct { | ... | @@ -1280,7 +1280,7 @@ pub const ClangArgIterator = extern struct { |
| 1280 | shared, | 1280 | shared, |
| 1281 | rdynamic, | 1281 | rdynamic, |
| 1282 | wl, | 1282 | wl, |
| 1283 | preprocess, | 1283 | pp_or_asm, |
| 1284 | optimize, | 1284 | optimize, |
| 1285 | debug, | 1285 | debug, |
| 1286 | sanitize, | 1286 | sanitize, |
src/all_types.hpp+10| ... | @@ -54,6 +54,16 @@ struct ResultLocCast; | ... | @@ -54,6 +54,16 @@ struct ResultLocCast; |
| 54 | struct ResultLocReturn; | 54 | struct ResultLocReturn; |
| 55 | struct IrExecutableGen; | 55 | struct IrExecutableGen; |
| 56 | 56 | ||
| 57 | enum FileExt { | ||
| 58 | FileExtUnknown, | ||
| 59 | FileExtAsm, | ||
| 60 | FileExtC, | ||
| 61 | FileExtCpp, | ||
| 62 | FileExtHeader, | ||
| 63 | FileExtLLVMIr, | ||
| 64 | FileExtLLVMBitCode, | ||
| 65 | }; | ||
| 66 | |||
| 57 | enum PtrLen { | 67 | enum PtrLen { |
| 58 | PtrLenUnknown, | 68 | PtrLenUnknown, |
| 59 | PtrLenSingle, | 69 | PtrLenSingle, |
src/analyze.hpp+1-7| ... | @@ -257,14 +257,8 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose | ... | @@ -257,14 +257,8 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose |
| 257 | LLVMTypeRef get_llvm_type(CodeGen *g, ZigType *type); | 257 | LLVMTypeRef get_llvm_type(CodeGen *g, ZigType *type); |
| 258 | ZigLLVMDIType *get_llvm_di_type(CodeGen *g, ZigType *type); | 258 | ZigLLVMDIType *get_llvm_di_type(CodeGen *g, ZigType *type); |
| 259 | 259 | ||
| 260 | enum CSourceKind { | ||
| 261 | CSourceKindAsm, | ||
| 262 | CSourceKindC, | ||
| 263 | CSourceKindCpp, | ||
| 264 | }; | ||
| 265 | |||
| 266 | void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_path, bool translate_c, | 260 | void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_path, bool translate_c, |
| 267 | CSourceKind source_kind); | 261 | FileExt source_kind); |
| 268 | 262 | ||
| 269 | void src_assert(bool ok, AstNode *source_node); | 263 | void src_assert(bool ok, AstNode *source_node); |
| 270 | bool is_container(ZigType *type_entry); | 264 | bool is_container(ZigType *type_entry); |
src/buffer.hpp+1-4| ... | @@ -178,10 +178,7 @@ static inline bool buf_starts_with_str(Buf *buf, const char *str) { | ... | @@ -178,10 +178,7 @@ static inline bool buf_starts_with_str(Buf *buf, const char *str) { |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | static inline bool buf_ends_with_mem(Buf *buf, const char *mem, size_t mem_len) { | 180 | static inline bool buf_ends_with_mem(Buf *buf, const char *mem, size_t mem_len) { |
| 181 | if (buf_len(buf) < mem_len) { | 181 | return mem_ends_with_mem(buf_ptr(buf), buf_len(buf), mem, mem_len); |
| 182 | return false; | ||
| 183 | } | ||
| 184 | return memcmp(buf_ptr(buf) + buf_len(buf) - mem_len, mem, mem_len) == 0; | ||
| 185 | } | 182 | } |
| 186 | 183 | ||
| 187 | static inline bool buf_ends_with_str(Buf *buf, const char *str) { | 184 | static inline bool buf_ends_with_str(Buf *buf, const char *str) { |
src/codegen.cpp+37-45| ... | @@ -9170,20 +9170,13 @@ static void detect_libc(CodeGen *g) { | ... | @@ -9170,20 +9170,13 @@ static void detect_libc(CodeGen *g) { |
| 9170 | 9170 | ||
| 9171 | // does not add the "cc" arg | 9171 | // does not add the "cc" arg |
| 9172 | void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_path, | 9172 | void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_path, |
| 9173 | bool translate_c, CSourceKind source_kind) | 9173 | bool translate_c, FileExt source_kind) |
| 9174 | { | 9174 | { |
| 9175 | if (translate_c) { | 9175 | if (translate_c) { |
| 9176 | args.append("-x"); | 9176 | args.append("-x"); |
| 9177 | args.append("c"); | 9177 | args.append("c"); |
| 9178 | } | 9178 | } |
| 9179 | 9179 | ||
| 9180 | if (source_kind != CSourceKindAsm && out_dep_path != nullptr) { | ||
| 9181 | args.append("-MD"); | ||
| 9182 | args.append("-MV"); | ||
| 9183 | args.append("-MF"); | ||
| 9184 | args.append(out_dep_path); | ||
| 9185 | } | ||
| 9186 | |||
| 9187 | args.append("-nostdinc"); | 9180 | args.append("-nostdinc"); |
| 9188 | args.append("-fno-spell-checking"); | 9181 | args.append("-fno-spell-checking"); |
| 9189 | 9182 | ||
| ... | @@ -9191,14 +9184,7 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa | ... | @@ -9191,14 +9184,7 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa |
| 9191 | args.append("-ffunction-sections"); | 9184 | args.append("-ffunction-sections"); |
| 9192 | } | 9185 | } |
| 9193 | 9186 | ||
| 9194 | if (translate_c) { | 9187 | if (!translate_c) { |
| 9195 | if (source_kind != CSourceKindAsm) { | ||
| 9196 | // this gives us access to preprocessing entities, presumably at | ||
| 9197 | // the cost of performance | ||
| 9198 | args.append("-Xclang"); | ||
| 9199 | args.append("-detailed-preprocessing-record"); | ||
| 9200 | } | ||
| 9201 | } else { | ||
| 9202 | switch (g->err_color) { | 9188 | switch (g->err_color) { |
| 9203 | case ErrColorAuto: | 9189 | case ErrColorAuto: |
| 9204 | break; | 9190 | break; |
| ... | @@ -9232,24 +9218,25 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa | ... | @@ -9232,24 +9218,25 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa |
| 9232 | args.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS"); | 9218 | args.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS"); |
| 9233 | } | 9219 | } |
| 9234 | 9220 | ||
| 9235 | // According to Rich Felker libc headers are supposed to go before C language headers. | ||
| 9236 | // However as noted by @dimenus, appending libc headers before c_headers breaks intrinsics | ||
| 9237 | // and other compiler specific items. | ||
| 9238 | args.append("-isystem"); | ||
| 9239 | args.append(buf_ptr(g->zig_c_headers_dir)); | ||
| 9240 | |||
| 9241 | for (size_t i = 0; i < g->libc_include_dir_len; i += 1) { | ||
| 9242 | const char *include_dir = g->libc_include_dir_list[i]; | ||
| 9243 | args.append("-isystem"); | ||
| 9244 | args.append(include_dir); | ||
| 9245 | } | ||
| 9246 | |||
| 9247 | args.append("-target"); | 9221 | args.append("-target"); |
| 9248 | args.append(buf_ptr(&g->llvm_triple_str)); | 9222 | args.append(buf_ptr(&g->llvm_triple_str)); |
| 9249 | 9223 | ||
| 9250 | switch (source_kind) { | 9224 | switch (source_kind) { |
| 9251 | case CSourceKindC: | 9225 | case FileExtC: |
| 9252 | case CSourceKindCpp: | 9226 | case FileExtCpp: |
| 9227 | case FileExtHeader: | ||
| 9228 | // According to Rich Felker libc headers are supposed to go before C language headers. | ||
| 9229 | // However as noted by @dimenus, appending libc headers before c_headers breaks intrinsics | ||
| 9230 | // and other compiler specific items. | ||
| 9231 | args.append("-isystem"); | ||
| 9232 | args.append(buf_ptr(g->zig_c_headers_dir)); | ||
| 9233 | |||
| 9234 | for (size_t i = 0; i < g->libc_include_dir_len; i += 1) { | ||
| 9235 | const char *include_dir = g->libc_include_dir_list[i]; | ||
| 9236 | args.append("-isystem"); | ||
| 9237 | args.append(include_dir); | ||
| 9238 | } | ||
| 9239 | |||
| 9253 | if (g->zig_target->llvm_cpu_name != nullptr) { | 9240 | if (g->zig_target->llvm_cpu_name != nullptr) { |
| 9254 | args.append("-Xclang"); | 9241 | args.append("-Xclang"); |
| 9255 | args.append("-target-cpu"); | 9242 | args.append("-target-cpu"); |
| ... | @@ -9262,8 +9249,23 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa | ... | @@ -9262,8 +9249,23 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa |
| 9262 | args.append("-Xclang"); | 9249 | args.append("-Xclang"); |
| 9263 | args.append(g->zig_target->llvm_cpu_features); | 9250 | args.append(g->zig_target->llvm_cpu_features); |
| 9264 | } | 9251 | } |
| 9252 | if (translate_c) { | ||
| 9253 | // this gives us access to preprocessing entities, presumably at | ||
| 9254 | // the cost of performance | ||
| 9255 | args.append("-Xclang"); | ||
| 9256 | args.append("-detailed-preprocessing-record"); | ||
| 9257 | } | ||
| 9258 | if (out_dep_path != nullptr) { | ||
| 9259 | args.append("-MD"); | ||
| 9260 | args.append("-MV"); | ||
| 9261 | args.append("-MF"); | ||
| 9262 | args.append(out_dep_path); | ||
| 9263 | } | ||
| 9265 | break; | 9264 | break; |
| 9266 | case CSourceKindAsm: | 9265 | case FileExtAsm: |
| 9266 | case FileExtLLVMIr: | ||
| 9267 | case FileExtLLVMBitCode: | ||
| 9268 | case FileExtUnknown: | ||
| 9267 | break; | 9269 | break; |
| 9268 | } | 9270 | } |
| 9269 | for (size_t i = 0; i < g->zig_target->llvm_cpu_features_asm_len; i += 1) { | 9271 | for (size_t i = 0; i < g->zig_target->llvm_cpu_features_asm_len; i += 1) { |
| ... | @@ -9413,7 +9415,7 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) { | ... | @@ -9413,7 +9415,7 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) { |
| 9413 | } | 9415 | } |
| 9414 | 9416 | ||
| 9415 | ZigList<const char *> clang_argv = {0}; | 9417 | ZigList<const char *> clang_argv = {0}; |
| 9416 | add_cc_args(g, clang_argv, out_dep_path_cstr, true, CSourceKindC); | 9418 | add_cc_args(g, clang_argv, out_dep_path_cstr, true, FileExtC); |
| 9417 | 9419 | ||
| 9418 | clang_argv.append(buf_ptr(full_path)); | 9420 | clang_argv.append(buf_ptr(full_path)); |
| 9419 | 9421 | ||
| ... | @@ -9751,15 +9753,6 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { | ... | @@ -9751,15 +9753,6 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { |
| 9751 | Buf *c_source_basename = buf_alloc(); | 9753 | Buf *c_source_basename = buf_alloc(); |
| 9752 | os_path_split(c_source_file, nullptr, c_source_basename); | 9754 | os_path_split(c_source_file, nullptr, c_source_basename); |
| 9753 | 9755 | ||
| 9754 | CSourceKind c_source_kind; | ||
| 9755 | if (buf_ends_with_str(c_source_basename, ".s") || | ||
| 9756 | buf_ends_with_str(c_source_basename, ".S")) | ||
| 9757 | { | ||
| 9758 | c_source_kind = CSourceKindAsm; | ||
| 9759 | } else { | ||
| 9760 | c_source_kind = CSourceKindC; | ||
| 9761 | } | ||
| 9762 | |||
| 9763 | Stage2ProgressNode *child_prog_node = stage2_progress_start(g->sub_progress_node, buf_ptr(c_source_basename), | 9756 | Stage2ProgressNode *child_prog_node = stage2_progress_start(g->sub_progress_node, buf_ptr(c_source_basename), |
| 9764 | buf_len(c_source_basename), 0); | 9757 | buf_len(c_source_basename), 0); |
| 9765 | 9758 | ||
| ... | @@ -9825,14 +9818,13 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { | ... | @@ -9825,14 +9818,13 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { |
| 9825 | args.append(buf_ptr(self_exe_path)); | 9818 | args.append(buf_ptr(self_exe_path)); |
| 9826 | args.append("clang"); | 9819 | args.append("clang"); |
| 9827 | 9820 | ||
| 9828 | if (c_file->preprocessor_only_basename != nullptr) { | 9821 | if (c_file->preprocessor_only_basename == nullptr) { |
| 9829 | args.append("-E"); | ||
| 9830 | } else { | ||
| 9831 | args.append("-c"); | 9822 | args.append("-c"); |
| 9832 | } | 9823 | } |
| 9833 | 9824 | ||
| 9834 | Buf *out_dep_path = buf_sprintf("%s.d", buf_ptr(out_obj_path)); | 9825 | Buf *out_dep_path = buf_sprintf("%s.d", buf_ptr(out_obj_path)); |
| 9835 | add_cc_args(g, args, buf_ptr(out_dep_path), false, c_source_kind); | 9826 | FileExt ext = classify_file_ext(buf_ptr(c_source_basename), buf_len(c_source_basename)); |
| 9827 | add_cc_args(g, args, buf_ptr(out_dep_path), false, ext); | ||
| 9836 | 9828 | ||
| 9837 | args.append("-o"); | 9829 | args.append("-o"); |
| 9838 | args.append(buf_ptr(out_obj_path)); | 9830 | args.append(buf_ptr(out_obj_path)); |
src/compiler.cpp+22| ... | @@ -164,3 +164,25 @@ Buf *get_global_cache_dir(void) { | ... | @@ -164,3 +164,25 @@ Buf *get_global_cache_dir(void) { |
| 164 | buf_deinit(&app_data_dir); | 164 | buf_deinit(&app_data_dir); |
| 165 | return &saved_global_cache_dir; | 165 | return &saved_global_cache_dir; |
| 166 | } | 166 | } |
| 167 | |||
| 168 | FileExt classify_file_ext(const char *filename_ptr, size_t filename_len) { | ||
| 169 | if (mem_ends_with_str(filename_ptr, filename_len, ".c")) { | ||
| 170 | return FileExtC; | ||
| 171 | } else if (mem_ends_with_str(filename_ptr, filename_len, ".C") || | ||
| 172 | mem_ends_with_str(filename_ptr, filename_len, ".cc") || | ||
| 173 | mem_ends_with_str(filename_ptr, filename_len, ".cpp") || | ||
| 174 | mem_ends_with_str(filename_ptr, filename_len, ".cxx")) | ||
| 175 | { | ||
| 176 | return FileExtCpp; | ||
| 177 | } else if (mem_ends_with_str(filename_ptr, filename_len, ".ll")) { | ||
| 178 | return FileExtLLVMIr; | ||
| 179 | } else if (mem_ends_with_str(filename_ptr, filename_len, ".bc")) { | ||
| 180 | return FileExtLLVMBitCode; | ||
| 181 | } else if (mem_ends_with_str(filename_ptr, filename_len, ".s") || | ||
| 182 | mem_ends_with_str(filename_ptr, filename_len, ".S")) | ||
| 183 | { | ||
| 184 | return FileExtAsm; | ||
| 185 | } | ||
| 186 | // TODO look for .so, .so.X, .so.X.Y, .so.X.Y.Z | ||
| 187 | return FileExtUnknown; | ||
| 188 | } |
src/compiler.hpp+4-2| ... | @@ -8,8 +8,7 @@ | ... | @@ -8,8 +8,7 @@ |
| 8 | #ifndef ZIG_COMPILER_HPP | 8 | #ifndef ZIG_COMPILER_HPP |
| 9 | #define ZIG_COMPILER_HPP | 9 | #define ZIG_COMPILER_HPP |
| 10 | 10 | ||
| 11 | #include "buffer.hpp" | 11 | #include "all_types.hpp" |
| 12 | #include "error.hpp" | ||
| 13 | 12 | ||
| 14 | Error get_compiler_id(Buf **result); | 13 | Error get_compiler_id(Buf **result); |
| 15 | 14 | ||
| ... | @@ -19,4 +18,7 @@ Buf *get_zig_std_dir(Buf *zig_lib_dir); | ... | @@ -19,4 +18,7 @@ Buf *get_zig_std_dir(Buf *zig_lib_dir); |
| 19 | 18 | ||
| 20 | Buf *get_global_cache_dir(void); | 19 | Buf *get_global_cache_dir(void); |
| 21 | 20 | ||
| 21 | |||
| 22 | FileExt classify_file_ext(const char *filename_ptr, size_t filename_len); | ||
| 23 | |||
| 22 | #endif | 24 | #endif |
src/ir.cpp+1-1| ... | @@ -25171,7 +25171,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo | ... | @@ -25171,7 +25171,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo |
| 25171 | 25171 | ||
| 25172 | ZigList<const char *> clang_argv = {0}; | 25172 | ZigList<const char *> clang_argv = {0}; |
| 25173 | 25173 | ||
| 25174 | add_cc_args(ira->codegen, clang_argv, buf_ptr(tmp_dep_file), true, CSourceKindC); | 25174 | add_cc_args(ira->codegen, clang_argv, buf_ptr(tmp_dep_file), true, FileExtC); |
| 25175 | 25175 | ||
| 25176 | clang_argv.append(buf_ptr(&tmp_c_file_path)); | 25176 | clang_argv.append(buf_ptr(&tmp_c_file_path)); |
| 25177 | 25177 |
src/main.cpp+26-20| ... | @@ -455,7 +455,7 @@ static int main0(int argc, char **argv) { | ... | @@ -455,7 +455,7 @@ static int main0(int argc, char **argv) { |
| 455 | const char *mcpu = nullptr; | 455 | const char *mcpu = nullptr; |
| 456 | CodeModel code_model = CodeModelDefault; | 456 | CodeModel code_model = CodeModelDefault; |
| 457 | const char *override_soname = nullptr; | 457 | const char *override_soname = nullptr; |
| 458 | bool only_preprocess = false; | 458 | bool only_pp_or_asm = false; |
| 459 | bool ensure_libc_on_non_freestanding = false; | 459 | bool ensure_libc_on_non_freestanding = false; |
| 460 | bool ensure_libcpp_on_non_freestanding = false; | 460 | bool ensure_libcpp_on_non_freestanding = false; |
| 461 | 461 | ||
| ... | @@ -615,20 +615,22 @@ static int main0(int argc, char **argv) { | ... | @@ -615,20 +615,22 @@ static int main0(int argc, char **argv) { |
| 615 | } | 615 | } |
| 616 | break; | 616 | break; |
| 617 | case Stage2ClangArgPositional: { | 617 | case Stage2ClangArgPositional: { |
| 618 | Buf *arg_buf = buf_create_from_str(it.only_arg); | 618 | FileExt file_ext = classify_file_ext(it.only_arg, strlen(it.only_arg)); |
| 619 | if (buf_ends_with_str(arg_buf, ".c") || | 619 | switch (file_ext) { |
| 620 | buf_ends_with_str(arg_buf, ".C") || | 620 | case FileExtAsm: |
| 621 | buf_ends_with_str(arg_buf, ".cc") || | 621 | case FileExtC: |
| 622 | buf_ends_with_str(arg_buf, ".cpp") || | 622 | case FileExtCpp: |
| 623 | buf_ends_with_str(arg_buf, ".cxx") || | 623 | case FileExtLLVMIr: |
| 624 | buf_ends_with_str(arg_buf, ".s") || | 624 | case FileExtLLVMBitCode: |
| 625 | buf_ends_with_str(arg_buf, ".S")) | 625 | case FileExtHeader: { |
| 626 | { | 626 | CFile *c_file = heap::c_allocator.create<CFile>(); |
| 627 | CFile *c_file = heap::c_allocator.create<CFile>(); | 627 | c_file->source_path = it.only_arg; |
| 628 | c_file->source_path = it.only_arg; | 628 | c_source_files.append(c_file); |
| 629 | c_source_files.append(c_file); | 629 | break; |
| 630 | } else { | 630 | } |
| 631 | objects.append(it.only_arg); | 631 | case FileExtUnknown: |
| 632 | objects.append(it.only_arg); | ||
| 633 | break; | ||
| 632 | } | 634 | } |
| 633 | break; | 635 | break; |
| 634 | } | 636 | } |
| ... | @@ -674,8 +676,12 @@ static int main0(int argc, char **argv) { | ... | @@ -674,8 +676,12 @@ static int main0(int argc, char **argv) { |
| 674 | } | 676 | } |
| 675 | break; | 677 | break; |
| 676 | } | 678 | } |
| 677 | case Stage2ClangArgPreprocess: | 679 | case Stage2ClangArgPreprocessOrAsm: |
| 678 | only_preprocess = true; | 680 | // this handles both -E and -S |
| 681 | only_pp_or_asm = true; | ||
| 682 | for (size_t i = 0; i < it.other_args_len; i += 1) { | ||
| 683 | clang_argv.append(it.other_args_ptr[i]); | ||
| 684 | } | ||
| 679 | break; | 685 | break; |
| 680 | case Stage2ClangArgOptimize: | 686 | case Stage2ClangArgOptimize: |
| 681 | // alright what release mode do they want? | 687 | // alright what release mode do they want? |
| ... | @@ -799,7 +805,7 @@ static int main0(int argc, char **argv) { | ... | @@ -799,7 +805,7 @@ static int main0(int argc, char **argv) { |
| 799 | build_mode = BuildModeSafeRelease; | 805 | build_mode = BuildModeSafeRelease; |
| 800 | } | 806 | } |
| 801 | 807 | ||
| 802 | if (only_preprocess) { | 808 | if (only_pp_or_asm) { |
| 803 | cmd = CmdBuild; | 809 | cmd = CmdBuild; |
| 804 | out_type = OutTypeObj; | 810 | out_type = OutTypeObj; |
| 805 | emit_bin = false; | 811 | emit_bin = false; |
| ... | @@ -1597,7 +1603,7 @@ static int main0(int argc, char **argv) { | ... | @@ -1597,7 +1603,7 @@ static int main0(int argc, char **argv) { |
| 1597 | #endif | 1603 | #endif |
| 1598 | Buf *dest_path = buf_create_from_str(emit_bin_override_path); | 1604 | Buf *dest_path = buf_create_from_str(emit_bin_override_path); |
| 1599 | Buf *source_path; | 1605 | Buf *source_path; |
| 1600 | if (only_preprocess) { | 1606 | if (only_pp_or_asm) { |
| 1601 | source_path = buf_alloc(); | 1607 | source_path = buf_alloc(); |
| 1602 | Buf *pp_only_basename = buf_create_from_str( | 1608 | Buf *pp_only_basename = buf_create_from_str( |
| 1603 | c_source_files.at(0)->preprocessor_only_basename); | 1609 | c_source_files.at(0)->preprocessor_only_basename); |
| ... | @@ -1611,7 +1617,7 @@ static int main0(int argc, char **argv) { | ... | @@ -1611,7 +1617,7 @@ static int main0(int argc, char **argv) { |
| 1611 | buf_ptr(dest_path), err_str(err)); | 1617 | buf_ptr(dest_path), err_str(err)); |
| 1612 | return main_exit(root_progress_node, EXIT_FAILURE); | 1618 | return main_exit(root_progress_node, EXIT_FAILURE); |
| 1613 | } | 1619 | } |
| 1614 | } else if (only_preprocess) { | 1620 | } else if (only_pp_or_asm) { |
| 1615 | #if defined(ZIG_OS_WINDOWS) | 1621 | #if defined(ZIG_OS_WINDOWS) |
| 1616 | buf_replace(g->c_artifact_dir, '/', '\\'); | 1622 | buf_replace(g->c_artifact_dir, '/', '\\'); |
| 1617 | #endif | 1623 | #endif |
src/stage2.h+1-1| ... | @@ -339,7 +339,7 @@ enum Stage2ClangArg { | ... | @@ -339,7 +339,7 @@ enum Stage2ClangArg { |
| 339 | Stage2ClangArgShared, | 339 | Stage2ClangArgShared, |
| 340 | Stage2ClangArgRDynamic, | 340 | Stage2ClangArgRDynamic, |
| 341 | Stage2ClangArgWL, | 341 | Stage2ClangArgWL, |
| 342 | Stage2ClangArgPreprocess, | 342 | Stage2ClangArgPreprocessOrAsm, |
| 343 | Stage2ClangArgOptimize, | 343 | Stage2ClangArgOptimize, |
| 344 | Stage2ClangArgDebug, | 344 | Stage2ClangArgDebug, |
| 345 | Stage2ClangArgSanitize, | 345 | Stage2ClangArgSanitize, |
src/util.hpp+9| ... | @@ -100,6 +100,15 @@ static inline bool is_power_of_2(uint64_t x) { | ... | @@ -100,6 +100,15 @@ static inline bool is_power_of_2(uint64_t x) { |
| 100 | return x != 0 && ((x & (~x + 1)) == x); | 100 | return x != 0 && ((x & (~x + 1)) == x); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | static inline bool mem_ends_with_mem(const char *mem, size_t mem_len, const char *end, size_t end_len) { | ||
| 104 | if (mem_len < end_len) return false; | ||
| 105 | return memcmp(mem + mem_len - end_len, end, end_len) == 0; | ||
| 106 | } | ||
| 107 | |||
| 108 | static inline bool mem_ends_with_str(const char *mem, size_t mem_len, const char *str) { | ||
| 109 | return mem_ends_with_mem(mem, mem_len, str, strlen(str)); | ||
| 110 | } | ||
| 111 | |||
| 103 | static inline uint64_t round_to_next_power_of_2(uint64_t x) { | 112 | static inline uint64_t round_to_next_power_of_2(uint64_t x) { |
| 104 | --x; | 113 | --x; |
| 105 | x |= x >> 1; | 114 | x |= x >> 1; |
tools/update_clang_options.zig+4-4| ... | @@ -96,19 +96,19 @@ const known_options = [_]KnownOpt{ | ... | @@ -96,19 +96,19 @@ const known_options = [_]KnownOpt{ |
| 96 | }, | 96 | }, |
| 97 | .{ | 97 | .{ |
| 98 | .name = "E", | 98 | .name = "E", |
| 99 | .ident = "preprocess", | 99 | .ident = "pp_or_asm", |
| 100 | }, | 100 | }, |
| 101 | .{ | 101 | .{ |
| 102 | .name = "preprocess", | 102 | .name = "preprocess", |
| 103 | .ident = "preprocess", | 103 | .ident = "pp_or_asm", |
| 104 | }, | 104 | }, |
| 105 | .{ | 105 | .{ |
| 106 | .name = "S", | 106 | .name = "S", |
| 107 | .ident = "driver_punt", | 107 | .ident = "pp_or_asm", |
| 108 | }, | 108 | }, |
| 109 | .{ | 109 | .{ |
| 110 | .name = "assemble", | 110 | .name = "assemble", |
| 111 | .ident = "driver_punt", | 111 | .ident = "pp_or_asm", |
| 112 | }, | 112 | }, |
| 113 | .{ | 113 | .{ |
| 114 | .name = "O1", | 114 | .name = "O1", |