mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-11 21:38:19 +00:00
Get the CPP backend into some semblance of working by updating for numerous LLVMContext changes,
as well as the StringRef change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79006 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -353,7 +353,7 @@ namespace {
|
|||||||
case Type::VoidTyID: return "Type::VoidTy";
|
case Type::VoidTyID: return "Type::VoidTy";
|
||||||
case Type::IntegerTyID: {
|
case Type::IntegerTyID: {
|
||||||
unsigned BitWidth = cast<IntegerType>(Ty)->getBitWidth();
|
unsigned BitWidth = cast<IntegerType>(Ty)->getBitWidth();
|
||||||
return "IntegerType::get(" + utostr(BitWidth) + ")";
|
return "IntegerType::get(getGlobalContext(), " + utostr(BitWidth) + ")";
|
||||||
}
|
}
|
||||||
case Type::X86_FP80TyID: return "Type::X86_FP80Ty";
|
case Type::X86_FP80TyID: return "Type::X86_FP80Ty";
|
||||||
case Type::FloatTyID: return "Type::FloatTy";
|
case Type::FloatTyID: return "Type::FloatTy";
|
||||||
@ -750,9 +750,10 @@ namespace {
|
|||||||
|
|
||||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
||||||
std::string constValue = CI->getValue().toString(10, true);
|
std::string constValue = CI->getValue().toString(10, true);
|
||||||
Out << "ConstantInt* " << constName << " = ConstantInt::get(APInt("
|
Out << "ConstantInt* " << constName
|
||||||
<< cast<IntegerType>(CI->getType())->getBitWidth() << ", \""
|
<< " = ConstantInt::get(getGlobalContext(), APInt("
|
||||||
<< constValue << "\", " << constValue.length() << ", 10));";
|
<< cast<IntegerType>(CI->getType())->getBitWidth()
|
||||||
|
<< ", StringRef(\"" << constValue << "\"), 10));";
|
||||||
} else if (isa<ConstantAggregateZero>(CV)) {
|
} else if (isa<ConstantAggregateZero>(CV)) {
|
||||||
Out << "ConstantAggregateZero* " << constName
|
Out << "ConstantAggregateZero* " << constName
|
||||||
<< " = ConstantAggregateZero::get(" << typeName << ");";
|
<< " = ConstantAggregateZero::get(" << typeName << ");";
|
||||||
@ -767,7 +768,8 @@ namespace {
|
|||||||
if (CA->isString() &&
|
if (CA->isString() &&
|
||||||
CA->getType()->getElementType() ==
|
CA->getType()->getElementType() ==
|
||||||
Type::getInt8Ty(CA->getContext())) {
|
Type::getInt8Ty(CA->getContext())) {
|
||||||
Out << "Constant* " << constName << " = ConstantArray::get(\"";
|
Out << "Constant* " << constName <<
|
||||||
|
" = ConstantArray::get(getGlobalContext(), \"";
|
||||||
std::string tmp = CA->getAsString();
|
std::string tmp = CA->getAsString();
|
||||||
bool nullTerminate = false;
|
bool nullTerminate = false;
|
||||||
if (tmp[tmp.length()-1] == 0) {
|
if (tmp[tmp.length()-1] == 0) {
|
||||||
@ -994,13 +996,13 @@ namespace {
|
|||||||
void CppWriter::printVariableHead(const GlobalVariable *GV) {
|
void CppWriter::printVariableHead(const GlobalVariable *GV) {
|
||||||
nl(Out) << "GlobalVariable* " << getCppName(GV);
|
nl(Out) << "GlobalVariable* " << getCppName(GV);
|
||||||
if (is_inline) {
|
if (is_inline) {
|
||||||
Out << " = mod->getGlobalVariable(";
|
Out << " = mod->getGlobalVariable(getGlobalContext(), ";
|
||||||
printEscapedString(GV->getName());
|
printEscapedString(GV->getName());
|
||||||
Out << ", " << getCppName(GV->getType()->getElementType()) << ",true)";
|
Out << ", " << getCppName(GV->getType()->getElementType()) << ",true)";
|
||||||
nl(Out) << "if (!" << getCppName(GV) << ") {";
|
nl(Out) << "if (!" << getCppName(GV) << ") {";
|
||||||
in(); nl(Out) << getCppName(GV);
|
in(); nl(Out) << getCppName(GV);
|
||||||
}
|
}
|
||||||
Out << " = new GlobalVariable(/*Module=*/*mod";
|
Out << " = new GlobalVariable(/*Module=*/*mod, ";
|
||||||
nl(Out) << "/*Type=*/";
|
nl(Out) << "/*Type=*/";
|
||||||
printCppName(GV->getType()->getElementType());
|
printCppName(GV->getType()->getElementType());
|
||||||
Out << ",";
|
Out << ",";
|
||||||
@ -1093,7 +1095,7 @@ namespace {
|
|||||||
|
|
||||||
case Instruction::Ret: {
|
case Instruction::Ret: {
|
||||||
const ReturnInst* ret = cast<ReturnInst>(I);
|
const ReturnInst* ret = cast<ReturnInst>(I);
|
||||||
Out << "ReturnInst::Create("
|
Out << "ReturnInst::Create(getGlobalContext(), "
|
||||||
<< (ret->getReturnValue() ? opNames[0] + ", " : "") << bbname << ");";
|
<< (ret->getReturnValue() ? opNames[0] + ", " : "") << bbname << ");";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1678,7 +1680,8 @@ namespace {
|
|||||||
for (Function::const_iterator BI = F->begin(), BE = F->end();
|
for (Function::const_iterator BI = F->begin(), BE = F->end();
|
||||||
BI != BE; ++BI) {
|
BI != BE; ++BI) {
|
||||||
std::string bbname(getCppName(BI));
|
std::string bbname(getCppName(BI));
|
||||||
Out << "BasicBlock* " << bbname << " = BasicBlock::Create(\"";
|
Out << "BasicBlock* " << bbname <<
|
||||||
|
" = BasicBlock::Create(getGlobalContext(), \"";
|
||||||
if (BI->hasName())
|
if (BI->hasName())
|
||||||
printEscapedString(BI->getName());
|
printEscapedString(BI->getName());
|
||||||
Out << "\"," << getCppName(BI->getParent()) << ",0);";
|
Out << "\"," << getCppName(BI->getParent()) << ",0);";
|
||||||
@ -1797,6 +1800,7 @@ namespace {
|
|||||||
|
|
||||||
void CppWriter::printProgram(const std::string& fname,
|
void CppWriter::printProgram(const std::string& fname,
|
||||||
const std::string& mName) {
|
const std::string& mName) {
|
||||||
|
Out << "#include <llvm/LLVMContext.h>\n";
|
||||||
Out << "#include <llvm/Module.h>\n";
|
Out << "#include <llvm/Module.h>\n";
|
||||||
Out << "#include <llvm/DerivedTypes.h>\n";
|
Out << "#include <llvm/DerivedTypes.h>\n";
|
||||||
Out << "#include <llvm/Constants.h>\n";
|
Out << "#include <llvm/Constants.h>\n";
|
||||||
@ -1833,7 +1837,7 @@ namespace {
|
|||||||
nl(Out,1) << "// Module Construction";
|
nl(Out,1) << "// Module Construction";
|
||||||
nl(Out) << "Module* mod = new Module(\"";
|
nl(Out) << "Module* mod = new Module(\"";
|
||||||
printEscapedString(mName);
|
printEscapedString(mName);
|
||||||
Out << "\");";
|
Out << "\", getGlobalContext());";
|
||||||
if (!TheModule->getTargetTriple().empty()) {
|
if (!TheModule->getTargetTriple().empty()) {
|
||||||
nl(Out) << "mod->setDataLayout(\"" << TheModule->getDataLayout() << "\");";
|
nl(Out) << "mod->setDataLayout(\"" << TheModule->getDataLayout() << "\");";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user