mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-16 14:31:59 +00:00
Convert to be compatible with lli.
Need to eliminate duplicate \n entries git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@883 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
685639df42
commit
4457163bc4
@ -28,9 +28,6 @@
|
|||||||
#include <strstream>
|
#include <strstream>
|
||||||
#include "llvm/Assembly/Writer.h"
|
#include "llvm/Assembly/Writer.h"
|
||||||
|
|
||||||
|
|
||||||
const char* const PRINTF = "printVal";
|
|
||||||
|
|
||||||
static inline GlobalVariable *
|
static inline GlobalVariable *
|
||||||
GetStringRef(Module *M, const string &str)
|
GetStringRef(Module *M, const string &str)
|
||||||
{
|
{
|
||||||
@ -67,84 +64,66 @@ FindValuesToTraceInBB(BasicBlock* bb, vector<Value*>& valuesToTraceInBB)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The invocation should be:
|
// The invocation should be:
|
||||||
// call "printf"(fmt, value).
|
// call "printVal"(value).
|
||||||
//
|
//
|
||||||
static Value *GetPrintMethodForType(Module *Mod, const Type *valueType) {
|
static Value *GetPrintMethodForType(Module *Mod, const Type *VTy) {
|
||||||
vector<const Type*> ArgTys;
|
MethodType *MTy = MethodType::get(Type::VoidTy, vector<const Type*>(1, VTy),
|
||||||
ArgTys.reserve(2);
|
/*isVarArg*/ false);
|
||||||
ArgTys.push_back(PointerType::get(ArrayType::get(Type::UByteTy)));
|
|
||||||
ArgTys.push_back(valueType);
|
|
||||||
|
|
||||||
MethodType *printMethodTy = MethodType::get(Type::VoidTy, ArgTys,
|
|
||||||
/*isVarArg*/ false);
|
|
||||||
|
|
||||||
SymbolTable *ST = Mod->getSymbolTableSure();
|
SymbolTable *ST = Mod->getSymbolTableSure();
|
||||||
if (Value *V = ST->lookup(PointerType::get(printMethodTy), PRINTF))
|
if (Value *V = ST->lookup(PointerType::get(MTy), "printVal"))
|
||||||
return V;
|
return V;
|
||||||
|
|
||||||
// Create a new method and add it to the module
|
// Create a new method and add it to the module
|
||||||
Method *M = new Method(printMethodTy, PRINTF);
|
Method *M = new Method(MTy, "printVal");
|
||||||
Mod->getMethodList().push_back(M);
|
Mod->getMethodList().push_back(M);
|
||||||
return M;
|
return M;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Instruction*
|
static void InsertPrintInsts(Value *Val,
|
||||||
CreatePrintInstr(Value* val,
|
BasicBlock::iterator &BBI,
|
||||||
const BasicBlock* bb,
|
Module *Mod,
|
||||||
Module* module,
|
unsigned int indent,
|
||||||
unsigned int indent,
|
bool isMethodExit) {
|
||||||
bool isMethodExit)
|
const Type* ValTy = Val->getType();
|
||||||
{
|
BasicBlock *BB = (*BBI)->getParent();
|
||||||
strstream scopeNameString;
|
|
||||||
const Type* valueType = val->getType();
|
|
||||||
|
|
||||||
assert(valueType->isPrimitiveType() &&
|
assert(ValTy->isPrimitiveType() &&
|
||||||
valueType->getPrimitiveID() != Type::VoidTyID &&
|
ValTy->getPrimitiveID() != Type::VoidTyID &&
|
||||||
valueType->getPrimitiveID() != Type::TypeTyID &&
|
ValTy->getPrimitiveID() != Type::TypeTyID &&
|
||||||
valueType->getPrimitiveID() != Type::LabelTyID &&
|
ValTy->getPrimitiveID() != Type::LabelTyID &&
|
||||||
"Unsupported type for printing");
|
"Unsupported type for printing");
|
||||||
|
|
||||||
const Value* scopeToUse = (isMethodExit)? (const Value*) bb->getParent()
|
const Value* scopeToUse =
|
||||||
: (const Value*) bb;
|
isMethodExit ? (const Value*)BB->getParent() : (const Value*)BB;
|
||||||
|
|
||||||
|
// Create the marker string...
|
||||||
|
strstream scopeNameString;
|
||||||
WriteAsOperand(scopeNameString, scopeToUse) << " : ";
|
WriteAsOperand(scopeNameString, scopeToUse) << " : ";
|
||||||
WriteAsOperand(scopeNameString, val) << " = "
|
WriteAsOperand(scopeNameString, Val) << " = " << ends;
|
||||||
<< val->getType()->getDescription()
|
|
||||||
<< ends;
|
|
||||||
string fmtString(indent, ' ');
|
string fmtString(indent, ' ');
|
||||||
|
|
||||||
fmtString += " At exit of " + string(isMethodExit ? "Method " : "BB ") +
|
fmtString += string(" At exit of") + scopeNameString.str();
|
||||||
scopeNameString.str();
|
|
||||||
|
|
||||||
switch(valueType->getPrimitiveID()) {
|
|
||||||
case Type::BoolTyID:
|
|
||||||
case Type::UByteTyID: case Type::UShortTyID:
|
|
||||||
case Type::UIntTyID: case Type::ULongTyID:
|
|
||||||
case Type::SByteTyID: case Type::ShortTyID:
|
|
||||||
case Type::IntTyID: case Type::LongTyID:
|
|
||||||
fmtString += " %d\0A";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Type::FloatTyID: case Type::DoubleTyID:
|
|
||||||
fmtString += " %g\0A";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Type::PointerTyID:
|
|
||||||
fmtString += " %p\0A";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
assert(0 && "Should not get here. Check the IF expression above");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
GlobalVariable *fmtVal = GetStringRef(module, fmtString);
|
|
||||||
|
|
||||||
vector<Value*> paramList;
|
|
||||||
paramList.push_back(fmtVal);
|
|
||||||
paramList.push_back(val);
|
|
||||||
|
|
||||||
return new CallInst(GetPrintMethodForType(module, valueType), paramList);
|
// Turn the marker string into a global variable...
|
||||||
|
GlobalVariable *fmtVal = GetStringRef(Mod, fmtString);
|
||||||
|
|
||||||
|
// Insert the first print instruction to print the string flag:
|
||||||
|
Instruction *I = new CallInst(GetPrintMethodForType(Mod, fmtVal->getType()),
|
||||||
|
vector<Value*>(1, fmtVal));
|
||||||
|
BBI = BB->getInstList().insert(BBI, I)+1;
|
||||||
|
|
||||||
|
// Insert the next print instruction to print the value:
|
||||||
|
I = new CallInst(GetPrintMethodForType(Mod, ValTy),
|
||||||
|
vector<Value*>(1, Val));
|
||||||
|
BBI = BB->getInstList().insert(BBI, I)+1;
|
||||||
|
|
||||||
|
// Print out a newline
|
||||||
|
fmtVal = GetStringRef(Mod, "\n");
|
||||||
|
I = new CallInst(GetPrintMethodForType(Mod, fmtVal->getType()),
|
||||||
|
vector<Value*>(1, fmtVal));
|
||||||
|
BBI = BB->getInstList().insert(BBI, I)+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -165,17 +144,13 @@ TraceValuesAtBBExit(const vector<Value*>& valueVec,
|
|||||||
//
|
//
|
||||||
BasicBlock::InstListType& instList = bb->getInstList();
|
BasicBlock::InstListType& instList = bb->getInstList();
|
||||||
TerminatorInst* termInst = bb->getTerminator();
|
TerminatorInst* termInst = bb->getTerminator();
|
||||||
BasicBlock::InstListType::iterator here = instList.end()-1;
|
BasicBlock::iterator here = instList.end()-1;
|
||||||
assert((*here)->isTerminator());
|
assert((*here)->isTerminator());
|
||||||
|
|
||||||
// Insert a print instruction for each value.
|
// Insert a print instruction for each value.
|
||||||
//
|
//
|
||||||
for (unsigned i=0, N=valueVec.size(); i < N; i++)
|
for (unsigned i=0, N=valueVec.size(); i < N; i++)
|
||||||
{
|
InsertPrintInsts(valueVec[i], here, module, indent, isMethodExit);
|
||||||
Instruction* traceInstr =
|
|
||||||
CreatePrintInstr(valueVec[i], bb, module, indent, isMethodExit);
|
|
||||||
here = instList.insert(here, traceInstr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -220,11 +195,14 @@ bool InsertTraceCode::doInsertTraceCode(Method *M, bool traceBasicBlockExits,
|
|||||||
valuesToTraceInBB.end());
|
valuesToTraceInBB.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// Disable this code until we have a proper exit node.
|
||||||
if (traceMethodExits) {
|
if (traceMethodExits) {
|
||||||
TraceValuesAtBBExit(valuesToTraceInMethod, exitBB, module,
|
TraceValuesAtBBExit(valuesToTraceInMethod, exitBB, module,
|
||||||
/*indent*/ 0, /*isMethodExit*/ true);
|
/*indent*/ 0, /*isMethodExit*/ true);
|
||||||
InsertCodeToShowMethodExit(exitBB);
|
InsertCodeToShowMethodExit(exitBB);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user