mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-02 19:24:25 +00:00
Print incoming arguments and return values.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1315 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -28,6 +28,7 @@
|
|||||||
#include "llvm/SymbolTable.h"
|
#include "llvm/SymbolTable.h"
|
||||||
#include "llvm/Assembly/Writer.h"
|
#include "llvm/Assembly/Writer.h"
|
||||||
#include "llvm/Support/HashExtras.h"
|
#include "llvm/Support/HashExtras.h"
|
||||||
|
#include "llvm/Support/StringExtras.h"
|
||||||
#include <hash_set>
|
#include <hash_set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@ -193,8 +194,8 @@ CreatePrintfInstr(Value* val,
|
|||||||
for (unsigned i=0; i < indent; i++)
|
for (unsigned i=0; i < indent; i++)
|
||||||
fmtString << " ";
|
fmtString << " ";
|
||||||
|
|
||||||
fmtString << " At exit of "
|
fmtString << " AT EXIT OF "
|
||||||
<< ((isMethodExit)? "Method " : "BB ")
|
<< ((isMethodExit)? "METHOD " : "BB ")
|
||||||
<< "%s : val %s = %s ";
|
<< "%s : val %s = %s ";
|
||||||
|
|
||||||
GlobalVariable* scopeNameVal = GetStringRef(module, scopeNameString.str());
|
GlobalVariable* scopeNameVal = GetStringRef(module, scopeNameString.str());
|
||||||
@ -265,7 +266,8 @@ InsertPrintInsts(Value *Val,
|
|||||||
BasicBlock::iterator &BBI,
|
BasicBlock::iterator &BBI,
|
||||||
Module *Mod,
|
Module *Mod,
|
||||||
unsigned int indent,
|
unsigned int indent,
|
||||||
bool isMethodExit)
|
bool isMethodExit,
|
||||||
|
bool isMethodEntry = false)
|
||||||
{
|
{
|
||||||
const Type* ValTy = Val->getType();
|
const Type* ValTy = Val->getType();
|
||||||
|
|
||||||
@ -274,15 +276,27 @@ InsertPrintInsts(Value *Val,
|
|||||||
ValTy != Type::LabelTy && "Unsupported type for printing");
|
ValTy != Type::LabelTy && "Unsupported type for printing");
|
||||||
|
|
||||||
const Value* scopeToUse =
|
const Value* scopeToUse =
|
||||||
isMethodExit ? (const Value*)BB->getParent() : (const Value*)BB;
|
(isMethodExit || isMethodEntry)? (const Value*)BB->getParent() : (const Value*)BB;
|
||||||
|
|
||||||
// Create the marker string...
|
// Create the marker string...
|
||||||
ostringstream scopeNameString;
|
ostringstream scopeNameString;
|
||||||
WriteAsOperand(scopeNameString, scopeToUse) << " : ";
|
if (isMethodExit || isMethodEntry)
|
||||||
|
scopeNameString << " METHOD ";
|
||||||
|
else
|
||||||
|
scopeNameString << " BASIC BLOCK ";
|
||||||
|
|
||||||
|
scopeNameString << ((scopeToUse->hasName())
|
||||||
|
? scopeToUse->getName().c_str()
|
||||||
|
: itostr((int) scopeToUse).c_str())
|
||||||
|
<< " : ";
|
||||||
|
|
||||||
WriteAsOperand(scopeNameString, Val) << " = ";
|
WriteAsOperand(scopeNameString, Val) << " = ";
|
||||||
|
|
||||||
string fmtString(indent, ' ');
|
string fmtString(indent, ' ');
|
||||||
fmtString += string(" At exit of") + scopeNameString.str();
|
if (isMethodEntry)
|
||||||
|
fmtString += string(" AT ENTRY OF") + scopeNameString.str();
|
||||||
|
else
|
||||||
|
fmtString += string(" AT EXIT OF") + scopeNameString.str();
|
||||||
|
|
||||||
// Turn the marker string into a global variable...
|
// Turn the marker string into a global variable...
|
||||||
GlobalVariable *fmtVal = GetStringRef(Mod, fmtString);
|
GlobalVariable *fmtVal = GetStringRef(Mod, fmtString);
|
||||||
@ -390,9 +404,13 @@ CreateMethodTraceInst(Method* method,
|
|||||||
const string& msg)
|
const string& msg)
|
||||||
{
|
{
|
||||||
string fmtString(indent, ' ');
|
string fmtString(indent, ' ');
|
||||||
ostringstream methodNameString;
|
// ostringstream methodNameString;
|
||||||
WriteAsOperand(methodNameString, method);
|
// WriteAsOperand(methodNameString, method);
|
||||||
fmtString += msg + methodNameString.str() + '\n';
|
// fmtString += msg + methodNameString.str() + '\n';
|
||||||
|
if (method->hasName())
|
||||||
|
fmtString += msg + method->getName().c_str() + '\n';
|
||||||
|
else
|
||||||
|
fmtString += msg + itostr((int) method) + '\n';
|
||||||
|
|
||||||
GlobalVariable *fmtVal = GetStringRef(method->getParent(), fmtString);
|
GlobalVariable *fmtVal = GetStringRef(method->getParent(), fmtString);
|
||||||
Instruction *printInst =
|
Instruction *printInst =
|
||||||
@ -413,9 +431,17 @@ InsertCodeToShowMethodEntry(Method* method,
|
|||||||
BasicBlock::iterator here = instList.begin();
|
BasicBlock::iterator here = instList.begin();
|
||||||
|
|
||||||
Instruction *printInst = CreateMethodTraceInst(method, indent,
|
Instruction *printInst = CreateMethodTraceInst(method, indent,
|
||||||
"Entering Method");
|
"ENTERING METHOD ");
|
||||||
|
|
||||||
here = entryBB->getInstList().insert(here, printInst) + 1;
|
here = entryBB->getInstList().insert(here, printInst) + 1;
|
||||||
|
|
||||||
|
// Now print all the incoming arguments
|
||||||
|
const Method::ArgumentListType& argList = method->getArgumentList();
|
||||||
|
for (Method::ArgumentListType::const_iterator
|
||||||
|
I=argList.begin(), E=argList.end(); I != E; ++I)
|
||||||
|
{
|
||||||
|
InsertPrintInsts((*I), entryBB, here, method->getParent(),
|
||||||
|
indent, /*isMethodExit*/false, /*isMethodEntry*/true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -428,11 +454,17 @@ InsertCodeToShowMethodExit(Method* method,
|
|||||||
BasicBlock::InstListType& instList = exitBB->getInstList();
|
BasicBlock::InstListType& instList = exitBB->getInstList();
|
||||||
BasicBlock::iterator here = instList.end()-1;
|
BasicBlock::iterator here = instList.end()-1;
|
||||||
assert((*here)->isTerminator());
|
assert((*here)->isTerminator());
|
||||||
|
assert(isa<ReturnInst>(*here));
|
||||||
|
|
||||||
Instruction *printInst = CreateMethodTraceInst(method, indent,
|
Instruction *printInst = CreateMethodTraceInst(method, indent,
|
||||||
"Leaving Method");
|
"LEAVING METHOD ");
|
||||||
|
here = exitBB->getInstList().insert(here, printInst) + 1;
|
||||||
|
|
||||||
exitBB->getInstList().insert(here, printInst) + 1;
|
// print the return value, if any
|
||||||
|
if (method->getReturnType() != Type::VoidTy)
|
||||||
|
InsertPrintInsts(cast<ReturnInst>(exitBB->getTerminator())->getReturnValue(),
|
||||||
|
exitBB, here, method->getParent(),
|
||||||
|
indent, /*isMethodExit*/true, /*isMethodEntry*/false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user