From 3e06ed0e8cdfba69e28600a2fcf52d795a86f3bb Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 8 Dec 2015 00:27:50 -0700 Subject: [PATCH] codegen: set target triple and data layout --- src/codegen.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 183722d14..fdbffcc8d 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -885,12 +885,17 @@ static void init(CodeGen *g, Buf *source_path) { g->is_native_target = true; char *native_triple = LLVMGetDefaultTargetTriple(); + g->module = LLVMModuleCreateWithName(buf_ptr(source_path)); + + LLVMSetTarget(g->module, native_triple); + LLVMTargetRef target_ref; char *err_msg = nullptr; if (LLVMGetTargetFromTriple(native_triple, &target_ref, &err_msg)) { zig_panic("unable to get target from triple: %s", err_msg); } + char *native_cpu = LLVMZigGetHostCPUName(); char *native_features = LLVMZigGetNativeFeatures(); @@ -904,8 +909,9 @@ static void init(CodeGen *g, Buf *source_path) { g->target_data_ref = LLVMGetTargetMachineData(g->target_machine); + char *layout_str = LLVMCopyStringRepOfTargetData(g->target_data_ref); + LLVMSetDataLayout(g->module, layout_str); - g->module = LLVMModuleCreateWithName("ZigModule"); g->pointer_size_bytes = LLVMPointerSize(g->target_data_ref);