Add a -c option.
This commit is contained in:
parent
148e6f7b00
commit
f12998e5d7
5 changed files with 46 additions and 11 deletions
|
@ -168,6 +168,8 @@ impure fn main(vec[str] args) {
|
|||
ot = trans.output_type_none;
|
||||
} else if (_str.eq(arg, "-S")) {
|
||||
ot = trans.output_type_assembly;
|
||||
} else if (_str.eq(arg, "-c")) {
|
||||
ot = trans.output_type_object;
|
||||
} else if (_str.eq(arg, "-o")) {
|
||||
if (i+1u < len) {
|
||||
output_file = some(args.(i+1u));
|
||||
|
|
|
@ -815,8 +815,10 @@ native mod llvm = llvm_lib {
|
|||
fn LLVMRustCreateMemoryBufferWithContentsOfFile(sbuf Path) ->
|
||||
MemoryBufferRef;
|
||||
|
||||
fn LLVMRustWriteAssembly(PassManagerRef PM, ModuleRef M,
|
||||
sbuf Triple, sbuf Output);
|
||||
/* FIXME: The FileType is an enum.*/
|
||||
fn LLVMRustWriteOutputFile(PassManagerRef PM, ModuleRef M,
|
||||
sbuf Triple, sbuf Output,
|
||||
int FileType);
|
||||
|
||||
/** Returns a string describing the last error caused by an LLVMRust*
|
||||
call. */
|
||||
|
|
|
@ -6754,6 +6754,17 @@ tag output_type {
|
|||
output_type_none;
|
||||
output_type_bitcode;
|
||||
output_type_assembly;
|
||||
output_type_object;
|
||||
}
|
||||
|
||||
fn is_object_or_assembly(output_type ot) -> bool {
|
||||
if (ot == output_type_assembly) {
|
||||
ret true;
|
||||
}
|
||||
if (ot == output_type_object) {
|
||||
ret true;
|
||||
}
|
||||
ret false;
|
||||
}
|
||||
|
||||
fn run_passes(ModuleRef llmod, bool opt, str output,
|
||||
|
@ -6823,10 +6834,21 @@ fn run_passes(ModuleRef llmod, bool opt, str output,
|
|||
}
|
||||
llvm.LLVMAddVerifierPass(pm.llpm);
|
||||
|
||||
if (ot == output_type_assembly) {
|
||||
llvm.LLVMRustWriteAssembly(pm.llpm, llmod,
|
||||
if (is_object_or_assembly(ot)) {
|
||||
let int LLVMAssemblyFile = 0;
|
||||
let int LLVMObjectFile = 1;
|
||||
let int LLVMNullFile = 2;
|
||||
auto FileType;
|
||||
if (ot == output_type_object) {
|
||||
FileType = LLVMObjectFile;
|
||||
} else {
|
||||
FileType = LLVMAssemblyFile;
|
||||
}
|
||||
|
||||
llvm.LLVMRustWriteOutputFile(pm.llpm, llmod,
|
||||
_str.buf(x86.get_target_triple()),
|
||||
_str.buf(output));
|
||||
_str.buf(output),
|
||||
FileType);
|
||||
ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,8 +42,15 @@ extern "C" void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM);
|
|||
void (*RustHackToFetchPassesO)(LLVMPassManagerRef PM) =
|
||||
LLVMAddBasicAliasAnalysisPass;
|
||||
|
||||
extern "C" void LLVMRustWriteAssembly(LLVMPassManagerRef PMR, LLVMModuleRef M,
|
||||
const char *triple, const char *path) {
|
||||
enum LLVMCodeGenFileType {
|
||||
LLVMAssemblyFile,
|
||||
LLVMObjectFile,
|
||||
LLVMNullFile // Do not emit any output.
|
||||
};
|
||||
|
||||
extern "C" void LLVMRustWriteOutputFile(LLVMPassManagerRef PMR, LLVMModuleRef M,
|
||||
const char *triple, const char *path,
|
||||
LLVMCodeGenFileType FileType) {
|
||||
InitializeAllTargets();
|
||||
InitializeAllAsmPrinters();
|
||||
TargetMachine::setRelocationModel(Reloc::PIC_);
|
||||
|
@ -53,13 +60,15 @@ extern "C" void LLVMRustWriteAssembly(LLVMPassManagerRef PMR, LLVMModuleRef M,
|
|||
TargetMachine &Target = *TheTarget->createTargetMachine(triple, FeaturesStr);
|
||||
bool NoVerify = false;
|
||||
CodeGenOpt::Level OLvl = CodeGenOpt::Default;
|
||||
TargetMachine::CodeGenFileType FileType = TargetMachine::CGFT_AssemblyFile;
|
||||
PassManager *PM = unwrap<PassManager>(PMR);
|
||||
std::string ErrorInfo;
|
||||
raw_fd_ostream OS(path, ErrorInfo,
|
||||
raw_fd_ostream::F_Binary);
|
||||
formatted_raw_ostream FOS(OS);
|
||||
bool foo = Target.addPassesToEmitFile(*PM, FOS, FileType, OLvl, NoVerify);
|
||||
TargetMachine::CodeGenFileType FileType2 =
|
||||
static_cast<TargetMachine::CodeGenFileType>(FileType);
|
||||
|
||||
bool foo = Target.addPassesToEmitFile(*PM, FOS, FileType2, OLvl, NoVerify);
|
||||
assert(!foo);
|
||||
PM->run(*unwrap(M));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
LLVMRustCreateMemoryBufferWithContentsOfFile
|
||||
LLVMRustWriteAssembly
|
||||
LLVMRustWriteOutputFile
|
||||
LLVMRustGetLastError
|
||||
LLVMCreateObjectFile
|
||||
LLVMDisposeObjectFile
|
||||
|
|
Loading…
Reference in a new issue