mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-02-26 00:23:14 +01:00
Use the system assembler on MinGW.
MC does not support writing out the exception handling tables to COFF files yet.
This commit is contained in:
@@ -8,9 +8,11 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "driver/toobj.h"
|
||||
#include "driver/tool.h"
|
||||
#include "gen/irstate.h"
|
||||
#include "gen/logger.h"
|
||||
#include "gen/optimizer.h"
|
||||
#include "gen/programs.h"
|
||||
#include "llvm/Analysis/Verifier.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#include "llvm/PassManager.h"
|
||||
@@ -26,7 +28,6 @@
|
||||
#include <cstddef>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
// based on llc code, University of Illinois Open Source License
|
||||
static void codegenModule(llvm::TargetMachine &Target, llvm::Module& m,
|
||||
llvm::raw_fd_ostream& out, llvm::TargetMachine::CodeGenFileType fileType)
|
||||
@@ -62,6 +63,30 @@ static void codegenModule(llvm::TargetMachine &Target, llvm::Module& m,
|
||||
Passes.doFinalization();
|
||||
}
|
||||
|
||||
static void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
args.push_back("-O3");
|
||||
args.push_back("-c");
|
||||
args.push_back("-xassembler");
|
||||
args.push_back(asmpath.str());
|
||||
args.push_back("-o");
|
||||
args.push_back(objpath.str());
|
||||
|
||||
if (global.params.is64bit)
|
||||
args.push_back("-m64");
|
||||
else
|
||||
args.push_back("-m32");
|
||||
|
||||
// Run the compiler to assembly the program.
|
||||
int R = executeToolAndWait(getGcc(), args, global.params.verbose);
|
||||
if (R)
|
||||
{
|
||||
error("Error while invoking external assembler.");
|
||||
fatal();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void writeModule(llvm::Module* m, std::string filename)
|
||||
@@ -69,6 +94,11 @@ void writeModule(llvm::Module* m, std::string filename)
|
||||
// run optimizer
|
||||
ldc_optimize_module(m);
|
||||
|
||||
// We don't use the integrated assembler with MinGW as it does not support
|
||||
// emitting DW2 exception handling tables.
|
||||
bool const assembleExternally = global.params.output_o &&
|
||||
global.params.targetTriple.getOS() == llvm::Triple::MinGW32;
|
||||
|
||||
// eventually do our own path stuff, dmd's is a bit strange.
|
||||
typedef llvm::sys::Path LLPath;
|
||||
|
||||
@@ -105,10 +135,12 @@ void writeModule(llvm::Module* m, std::string filename)
|
||||
}
|
||||
|
||||
// write native assembly
|
||||
if (global.params.output_s) {
|
||||
if (global.params.output_s || assembleExternally) {
|
||||
LLPath spath = LLPath(filename);
|
||||
spath.eraseSuffix();
|
||||
spath.appendSuffix(std::string(global.s_ext));
|
||||
if (!global.params.output_s) spath.createTemporaryFileOnDisk();
|
||||
|
||||
Logger::println("Writing native asm to: %s\n", spath.c_str());
|
||||
std::string err;
|
||||
{
|
||||
@@ -123,9 +155,17 @@ void writeModule(llvm::Module* m, std::string filename)
|
||||
fatal();
|
||||
}
|
||||
}
|
||||
|
||||
if (assembleExternally)
|
||||
{
|
||||
LLPath objpath(filename);
|
||||
assemble(spath, objpath);
|
||||
}
|
||||
|
||||
if (!global.params.output_s) spath.eraseFromDisk();
|
||||
}
|
||||
|
||||
if (global.params.output_o) {
|
||||
if (global.params.output_o && !assembleExternally) {
|
||||
LLPath objpath = LLPath(filename);
|
||||
Logger::println("Writing object file to: %s\n", objpath.c_str());
|
||||
std::string err;
|
||||
|
||||
Reference in New Issue
Block a user