#include "llvm/Transforms/Scalar.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/CodeGen/Passes.h"
+using namespace MSIL;
namespace {
// TargetMachine for the MSIL
};
}
-/// MSILTargetMachineModule - Note that this is used on hosts that
-/// cannot link in a library unless there are references into the
-/// library. In particular, it seems that it is not possible to get
-/// things to work on Win32 without this. Though it is unused, do not
-/// remove it.
-extern "C" int MSILTargetMachineModule;
-int MSILTargetMachineModule = 0;
-
-extern Target TheMSILTarget;
static RegisterTarget<MSILTarget> X(TheMSILTarget, "msil", "MSIL backend");
// Force static initialization.
std::string MSILWriter::getValueName(const Value* V) {
std::string Name;
- if (const GlobalValue *GV = cast<GlobalValue>(V))
+ if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
Name = Mang->getMangledName(GV);
else {
unsigned &No = AnonValueNumbers[V];
std::string MSILWriter::getLabelName(const Value* V) {
std::string Name;
- if (const GlobalValue *GV = cast<GlobalValue>(V))
+ if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
Name = Mang->getMangledName(GV);
else {
unsigned &No = AnonValueNumbers[V];
else if (const InvokeInst* Invoke = dyn_cast<InvokeInst>(Inst))
Name = getConvModopt(Invoke->getCallingConv());
else {
- cerr << "Instruction = " << Inst->getName() << '\n';
+ errs() << "Instruction = " << Inst->getName() << '\n';
llvm_unreachable("Need \"Invoke\" or \"Call\" instruction only");
}
if (const Function* F = dyn_cast<Function>(FnVal)) {
printSimpleInstruction("cpobj","[mscorlib]System.ArgIterator");
break;
default:
- cerr << "Intrinsic ID = " << Inst->getIntrinsicID() << '\n';
+ errs() << "Intrinsic ID = " << Inst->getIntrinsicID() << '\n';
llvm_unreachable("Invalid intrinsic function");
}
}
printBinaryInstruction("cgt",Left,Right);
break;
default:
- cerr << "Predicate = " << Predicate << '\n';
+ errs() << "Predicate = " << Predicate << '\n';
llvm_unreachable("Invalid icmp predicate");
}
}
printVAArgInstruction(cast<VAArgInst>(Inst));
break;
default:
- cerr << "Instruction = " << Inst->getName() << '\n';
+ errs() << "Instruction = " << Inst->getName() << '\n';
llvm_unreachable("Unsupported instruction");
}
}
printBinaryInstruction("shr",left,right);
break;
default:
- cerr << "Expression = " << *CE << "\n";
+ errs() << "Expression = " << *CE << "\n";
llvm_unreachable("Invalid constant expression");
}
}
postfix = "stind."+postfix;
printSimpleInstruction(postfix.c_str());
} else {
- cerr << "Constant = " << *I->constant << '\n';
+ errs() << "Constant = " << *I->constant << '\n';
llvm_unreachable("Invalid static initializer");
}
}
case 64:
return N;
default:
- cerr << "Bits = " << N << '\n';
+ errs() << "Bits = " << N << '\n';
llvm_unreachable("Unsupported integer width");
}
return 0; // Not reached
}
break;
default:
- cerr << "TypeID = " << Ty->getTypeID() << '\n';
+ errs() << "TypeID = " << Ty->getTypeID() << '\n';
llvm_unreachable("Invalid type in printStaticConstant()");
}
// Increase offset.
Out << getTypeName(C->getType());
break;
default:
- cerr << "Type = " << *C << "\n";
+ errs() << "Type = " << *C << "\n";
llvm_unreachable("Invalid constant type");
}
// Print initializer
const char* MSILWriter::getLibraryName(const Function* F) {
- return getLibraryForSymbol(F->getName().c_str(), true, F->getCallingConv());
+ return getLibraryForSymbol(F->getName(), true, F->getCallingConv());
}
const char* MSILWriter::getLibraryName(const GlobalVariable* GV) {
- return getLibraryForSymbol(Mang->getMangledName(GV).c_str(), false, 0);
+ return getLibraryForSymbol(Mang->getMangledName(GV), false, 0);
}
-const char* MSILWriter::getLibraryForSymbol(const char* Name, bool isFunction,
- unsigned CallingConv) {
+const char* MSILWriter::getLibraryForSymbol(const StringRef &Name,
+ bool isFunction,
+ unsigned CallingConv) {
// TODO: Read *.def file with function and libraries definitions.
return "MSVCRT.DLL";
}