| author | |
| committer | |
| log | 855d51840dbb14888b4a727c495e01f96027985a |
| tree | 03b7c52c0bf4c7ca455149261ed960577a7773e4 |
| parent | e5d1f0eea592e6efc4c4665eb473de95ef106e8a |
The llvm C API provided function is adequate.4 files changed, 3 insertions(+), 57 deletions(-)
README.md+2-1| ... | @@ -42,9 +42,10 @@ make | ... | @@ -42,9 +42,10 @@ make |
| 42 | 42 | ||
| 43 | ## Roadmap | 43 | ## Roadmap |
| 44 | 44 | ||
| 45 | * Math expression | 45 | * variables and parameters |
| 46 | * Export .so library | 46 | * Export .so library |
| 47 | * Multiple files | 47 | * Multiple files |
| 48 | * Type checking | ||
| 48 | * inline assembly and syscalls | 49 | * inline assembly and syscalls |
| 49 | * running code at compile time | 50 | * running code at compile time |
| 50 | * print! macro that takes var args | 51 | * print! macro that takes var args |
src/codegen.cpp+1-1| ... | @@ -1313,7 +1313,7 @@ void code_gen_link(CodeGen *g, const char *out_file) { | ... | @@ -1313,7 +1313,7 @@ void code_gen_link(CodeGen *g, const char *out_file) { |
| 1313 | } | 1313 | } |
| 1314 | 1314 | ||
| 1315 | char *err_msg = nullptr; | 1315 | char *err_msg = nullptr; |
| 1316 | if (LLVMZigTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(&out_file_o), | 1316 | if (LLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(&out_file_o), |
| 1317 | LLVMObjectFile, &err_msg)) | 1317 | LLVMObjectFile, &err_msg)) |
| 1318 | { | 1318 | { |
| 1319 | zig_panic("unable to write object file: %s", err_msg); | 1319 | zig_panic("unable to write object file: %s", err_msg); |
src/zig_llvm.cpp-52| ... | @@ -115,58 +115,6 @@ void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef | ... | @@ -115,58 +115,6 @@ void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef |
| 115 | MPM->run(*module); | 115 | MPM->run(*module); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | static LLVMBool LLVMZigTargetMachineEmit(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, | ||
| 119 | raw_pwrite_stream &out_stream, LLVMCodeGenFileType codegen, char **err_msg) | ||
| 120 | { | ||
| 121 | TargetMachine* target_machine = reinterpret_cast<TargetMachine*>(targ_machine_ref); | ||
| 122 | Module* module = unwrap(module_ref); | ||
| 123 | TargetLibraryInfoImpl tlii(Triple(module->getTargetTriple())); | ||
| 124 | |||
| 125 | legacy::PassManager pass; | ||
| 126 | |||
| 127 | pass.add(new TargetLibraryInfoWrapperPass(tlii)); | ||
| 128 | |||
| 129 | const DataLayout *td = target_machine->getDataLayout(); | ||
| 130 | |||
| 131 | if (!td) { | ||
| 132 | *err_msg = strdup("No DataLayout in TargetMachine"); | ||
| 133 | return true; | ||
| 134 | } | ||
| 135 | module->setDataLayout(*td); | ||
| 136 | |||
| 137 | |||
| 138 | TargetMachine::CodeGenFileType ft; | ||
| 139 | switch (codegen) { | ||
| 140 | case LLVMAssemblyFile: | ||
| 141 | ft = TargetMachine::CGFT_AssemblyFile; | ||
| 142 | break; | ||
| 143 | default: | ||
| 144 | ft = TargetMachine::CGFT_ObjectFile; | ||
| 145 | break; | ||
| 146 | } | ||
| 147 | if (target_machine->addPassesToEmitFile(pass, out_stream, ft)) { | ||
| 148 | *err_msg = strdup("TargetMachine can't emit a file of this type"); | ||
| 149 | return true; | ||
| 150 | } | ||
| 151 | |||
| 152 | pass.run(*module); | ||
| 153 | |||
| 154 | out_stream.flush(); | ||
| 155 | return false; | ||
| 156 | } | ||
| 157 | |||
| 158 | LLVMBool LLVMZigTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, | ||
| 159 | const char* filename, LLVMCodeGenFileType codegen, char** err_msg) | ||
| 160 | { | ||
| 161 | std::error_code error_code; | ||
| 162 | raw_fd_ostream dest(filename, error_code, sys::fs::F_None); | ||
| 163 | if (error_code) { | ||
| 164 | *err_msg = strdup(error_code.message().c_str()); | ||
| 165 | return true; | ||
| 166 | } | ||
| 167 | return LLVMZigTargetMachineEmit(targ_machine_ref, module_ref, dest, codegen, err_msg); | ||
| 168 | } | ||
| 169 | |||
| 170 | LLVMValueRef LLVMZigBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, | 118 | LLVMValueRef LLVMZigBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, |
| 171 | unsigned NumArgs, unsigned CC, const char *Name) | 119 | unsigned NumArgs, unsigned CC, const char *Name) |
| 172 | { | 120 | { |
src/zig_llvm.hpp-3| ... | @@ -21,9 +21,6 @@ void LLVMZigInitializeUnreachableBlockElimPass(LLVMPassRegistryRef R); | ... | @@ -21,9 +21,6 @@ void LLVMZigInitializeUnreachableBlockElimPass(LLVMPassRegistryRef R); |
| 21 | char *LLVMZigGetHostCPUName(void); | 21 | char *LLVMZigGetHostCPUName(void); |
| 22 | char *LLVMZigGetNativeFeatures(void); | 22 | char *LLVMZigGetNativeFeatures(void); |
| 23 | 23 | ||
| 24 | LLVMBool LLVMZigTargetMachineEmitToFile(LLVMTargetMachineRef target_machine, LLVMModuleRef module, | ||
| 25 | const char* filename, LLVMCodeGenFileType codegen, char** error_msg); | ||
| 26 | |||
| 27 | void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref); | 24 | void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref); |
| 28 | 25 | ||
| 29 | LLVMValueRef LLVMZigBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, | 26 | LLVMValueRef LLVMZigBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, |