add -mllvm support
useful for debugging crashes in llvm optimizer
This commit is contained in:
parent
faaaf88327
commit
b8ee3a8143
@ -1524,6 +1524,9 @@ struct CodeGen {
|
||||
size_t clang_argv_len;
|
||||
ZigList<const char *> lib_dirs;
|
||||
|
||||
const char **llvm_argv;
|
||||
size_t llvm_argv_len;
|
||||
|
||||
ZigList<FnTableEntry *> test_fns;
|
||||
TypeTableEntry *test_fn_type;
|
||||
|
||||
|
@ -152,6 +152,11 @@ void codegen_set_clang_argv(CodeGen *g, const char **args, size_t len) {
|
||||
g->clang_argv_len = len;
|
||||
}
|
||||
|
||||
void codegen_set_llvm_argv(CodeGen *g, const char **args, size_t len) {
|
||||
g->llvm_argv = args;
|
||||
g->llvm_argv_len = len;
|
||||
}
|
||||
|
||||
void codegen_set_omit_zigrt(CodeGen *g, bool omit_zigrt) {
|
||||
g->omit_zigrt = omit_zigrt;
|
||||
}
|
||||
@ -4918,6 +4923,17 @@ static void init(CodeGen *g) {
|
||||
if (g->module)
|
||||
return;
|
||||
|
||||
|
||||
if (g->llvm_argv_len > 0) {
|
||||
const char **args = allocate_nonzero<const char *>(g->llvm_argv_len + 2);
|
||||
args[0] = "zig (LLVM option parsing)";
|
||||
for (size_t i = 0; i < g->llvm_argv_len; i += 1) {
|
||||
args[i + 1] = g->llvm_argv[i];
|
||||
}
|
||||
args[g->llvm_argv_len + 1] = nullptr;
|
||||
ZigLLVMParseCommandLineOptions(g->llvm_argv_len + 1, args);
|
||||
}
|
||||
|
||||
if (g->is_test_build) {
|
||||
g->windows_subsystem_windows = false;
|
||||
g->windows_subsystem_console = true;
|
||||
|
@ -17,6 +17,7 @@
|
||||
CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode);
|
||||
|
||||
void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len);
|
||||
void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len);
|
||||
void codegen_set_is_test(CodeGen *codegen, bool is_test);
|
||||
void codegen_set_each_lib_rpath(CodeGen *codegen, bool each_lib_rpath);
|
||||
|
||||
|
@ -50,6 +50,7 @@ static int usage(const char *arg0) {
|
||||
" --zig-std-dir [path] directory where zig standard library resides\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"
|
||||
@ -190,6 +191,7 @@ int main(int argc, char **argv) {
|
||||
const char *zig_std_dir = nullptr;
|
||||
const char *dynamic_linker = nullptr;
|
||||
ZigList<const char *> clang_argv = {0};
|
||||
ZigList<const char *> llvm_argv = {0};
|
||||
ZigList<const char *> lib_dirs = {0};
|
||||
ZigList<const char *> link_libs = {0};
|
||||
ZigList<const char *> frameworks = {0};
|
||||
@ -420,6 +422,11 @@ int main(int argc, char **argv) {
|
||||
} else if (strcmp(arg, "-dirafter") == 0) {
|
||||
clang_argv.append("-dirafter");
|
||||
clang_argv.append(argv[i]);
|
||||
} else if (strcmp(arg, "-mllvm") == 0) {
|
||||
clang_argv.append("-mllvm");
|
||||
clang_argv.append(argv[i]);
|
||||
|
||||
llvm_argv.append(argv[i]);
|
||||
} else if (strcmp(arg, "--library-path") == 0 || strcmp(arg, "-L") == 0) {
|
||||
lib_dirs.append(argv[i]);
|
||||
} else if (strcmp(arg, "--library") == 0) {
|
||||
@ -604,6 +611,7 @@ int main(int argc, char **argv) {
|
||||
codegen_set_each_lib_rpath(g, each_lib_rpath);
|
||||
|
||||
codegen_set_clang_argv(g, clang_argv.items, clang_argv.length);
|
||||
codegen_set_llvm_argv(g, llvm_argv.items, llvm_argv.length);
|
||||
codegen_set_strip(g, strip);
|
||||
codegen_set_is_static(g, is_static);
|
||||
if (libc_lib_dir)
|
||||
|
@ -602,6 +602,10 @@ void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn_ref) {
|
||||
func->setAttributes(new_attr_set);
|
||||
}
|
||||
|
||||
void ZigLLVMParseCommandLineOptions(int argc, const char *const *argv) {
|
||||
llvm::cl::ParseCommandLineOptions(argc, argv);
|
||||
}
|
||||
|
||||
|
||||
static_assert((Triple::ArchType)ZigLLVM_LastArchType == Triple::LastArchType, "");
|
||||
static_assert((Triple::VendorType)ZigLLVM_LastVendorType == Triple::LastVendorType, "");
|
||||
|
@ -164,6 +164,8 @@ void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state);
|
||||
void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value);
|
||||
void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn);
|
||||
|
||||
void ZigLLVMParseCommandLineOptions(int argc, const char *const *argv);
|
||||
|
||||
|
||||
// copied from include/llvm/ADT/Triple.h
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user