Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save IR to a file and build it to an executable file?

Now I use clang build my .c file to .s file. And I have used the llvm API modify the IR. However, now I can't save my modified IR to a file. I want to use "LLVMWriteBitcodeToFile", but I can't find the struct of "LLVMOpaqueModule"; I want to use "WriteBitcodeToFile", it always show me "type mismatch". And I also want to know how to build an IR file to a executable file.

Next are two methods I use to save a module:

1、First use WriteBitcodeToFile

bool unbuffered = false; 
llvm::raw_ostream ro(unbuffered); 
WriteBitcodeToFile(m, ro); 

2、Second use LLVMWriteBitcodeToFile

const char *Path = "hello2.s"; 
int ans = LLVMWriteBitcodeToFile(m, Path); 

note: m is a point of Module instance

like image 988
Kun Lee Avatar asked Dec 18 '12 07:12

Kun Lee


1 Answers

  1. For saving the IR into a file, see the answer to this question: writing module to .bc bitcode file
  2. For compiling IR to an object file, look at the llc tool and follow what its main function does.
like image 81
Eli Bendersky Avatar answered Oct 30 '22 11:10

Eli Bendersky