supporting LLVM trunk

This commit is contained in:
Ilia Filippov
2014-01-21 14:21:26 +04:00
parent 37e12045fb
commit aa31957d84
3 changed files with 33 additions and 6 deletions

View File

@@ -643,13 +643,21 @@ lSetInternalFunctions(llvm::Module *module) {
void void
AddBitcodeToModule(const unsigned char *bitcode, int length, AddBitcodeToModule(const unsigned char *bitcode, int length,
llvm::Module *module, SymbolTable *symbolTable) { llvm::Module *module, SymbolTable *symbolTable) {
std::string bcErr;
llvm::StringRef sb = llvm::StringRef((char *)bitcode, length); llvm::StringRef sb = llvm::StringRef((char *)bitcode, length);
llvm::MemoryBuffer *bcBuf = llvm::MemoryBuffer::getMemBuffer(sb); llvm::MemoryBuffer *bcBuf = llvm::MemoryBuffer::getMemBuffer(sb);
#if defined(LLVM_3_5)
llvm::ErrorOr<llvm::Module *> ModuleOrErr = llvm::parseBitcodeFile(bcBuf, *g->ctx);
if (llvm::error_code EC = ModuleOrErr.getError())
Error(SourcePos(), "Error parsing stdlib bitcode: %s", EC.message().c_str());
else {
llvm::Module *bcModule = ModuleOrErr.get();
#else
std::string bcErr;
llvm::Module *bcModule = llvm::ParseBitcodeFile(bcBuf, *g->ctx, &bcErr); llvm::Module *bcModule = llvm::ParseBitcodeFile(bcBuf, *g->ctx, &bcErr);
if (!bcModule) if (!bcModule)
Error(SourcePos(), "Error parsing stdlib bitcode: %s", bcErr.c_str()); Error(SourcePos(), "Error parsing stdlib bitcode: %s", bcErr.c_str());
else { else {
#endif
// FIXME: this feels like a bad idea, but the issue is that when we // FIXME: this feels like a bad idea, but the issue is that when we
// set the llvm::Module's target triple in the ispc Module::Module // set the llvm::Module's target triple in the ispc Module::Module
// constructor, we start by calling llvm::sys::getHostTriple() (and // constructor, we start by calling llvm::sys::getHostTriple() (and

View File

@@ -2327,7 +2327,11 @@ bool CWriter::doInitialization(llvm::Module &M) {
if (I->hasExternalLinkage() || I->hasExternalWeakLinkage() || if (I->hasExternalLinkage() || I->hasExternalWeakLinkage() ||
I->hasCommonLinkage()) I->hasCommonLinkage())
Out << "extern "; Out << "extern ";
#if defined (LLVM_3_5)
else if (I->hasDLLImportStorageClass())
#else
else if (I->hasDLLImportLinkage()) else if (I->hasDLLImportLinkage())
#endif
Out << "__declspec(dllimport) "; Out << "__declspec(dllimport) ";
else else
continue; // Internal Global continue; // Internal Global
@@ -2499,11 +2503,13 @@ bool CWriter::doInitialization(llvm::Module &M) {
if (I->hasLocalLinkage()) if (I->hasLocalLinkage())
Out << "static "; Out << "static ";
else if (I->hasDLLImportLinkage()) #if defined(LLVM_3_5)
Out << "__declspec(dllimport) "; else if (I->hasDLLImportStorageClass()) Out << "__declspec(dllimport) ";
else if (I->hasDLLExportLinkage()) else if (I->hasDLLExportStorageClass()) Out << "__declspec(dllexport) ";
Out << "__declspec(dllexport) "; #else
else if (I->hasDLLImportLinkage()) Out << "__declspec(dllimport) ";
else if (I->hasDLLExportLinkage()) Out << "__declspec(dllexport) ";
#endif
// Thread Local Storage // Thread Local Storage
if (I->isThreadLocal()) if (I->isThreadLocal())
Out << "__thread "; Out << "__thread ";
@@ -2782,8 +2788,13 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
bool isStructReturn = F->hasStructRetAttr(); bool isStructReturn = F->hasStructRetAttr();
if (F->hasLocalLinkage()) Out << "static "; if (F->hasLocalLinkage()) Out << "static ";
#if defined(LLVM_3_5)
if (F->hasDLLImportStorageClass()) Out << "__declspec(dllimport) ";
if (F->hasDLLExportStorageClass()) Out << "__declspec(dllexport) ";
#else
if (F->hasDLLImportLinkage()) Out << "__declspec(dllimport) "; if (F->hasDLLImportLinkage()) Out << "__declspec(dllimport) ";
if (F->hasDLLExportLinkage()) Out << "__declspec(dllexport) "; if (F->hasDLLExportLinkage()) Out << "__declspec(dllexport) ";
#endif
switch (F->getCallingConv()) { switch (F->getCallingConv()) {
case llvm::CallingConv::X86_StdCall: case llvm::CallingConv::X86_StdCall:
Out << "__attribute__((stdcall)) "; Out << "__attribute__((stdcall)) ";

View File

@@ -477,7 +477,11 @@ Function::GenerateIR() {
} }
if (m->errorCount == 0) { if (m->errorCount == 0) {
#if defined (LLVM_3_5)
if (llvm::verifyFunction(*function) == true) {
#else
if (llvm::verifyFunction(*function, llvm::ReturnStatusAction) == true) { if (llvm::verifyFunction(*function, llvm::ReturnStatusAction) == true) {
#endif
if (g->debugPrint) if (g->debugPrint)
function->dump(); function->dump();
FATAL("Function verificication failed"); FATAL("Function verificication failed");
@@ -523,8 +527,12 @@ Function::GenerateIR() {
emitCode(&ec, appFunction, firstStmtPos); emitCode(&ec, appFunction, firstStmtPos);
if (m->errorCount == 0) { if (m->errorCount == 0) {
sym->exportedFunction = appFunction; sym->exportedFunction = appFunction;
#if defined(LLVM_3_5)
if (llvm::verifyFunction(*appFunction) == true) {
#else
if (llvm::verifyFunction(*appFunction, if (llvm::verifyFunction(*appFunction,
llvm::ReturnStatusAction) == true) { llvm::ReturnStatusAction) == true) {
#endif
if (g->debugPrint) if (g->debugPrint)
appFunction->dump(); appFunction->dump();
FATAL("Function verificication failed"); FATAL("Function verificication failed");