#include "config.h"
#include "DFGGraph.h"
#include "CodeBlock.h"
#if ENABLE(DFG_JIT)
namespace JSC { namespace DFG {
#ifndef NDEBUG
static const char* dfgOpNames[] = {
#define STRINGIZE_DFG_OP_ENUM(opcode, flags) #opcode ,
FOR_EACH_DFG_OP(STRINGIZE_DFG_OP_ENUM)
#undef STRINGIZE_DFG_OP_ENUM
};
void Graph::dump(NodeIndex nodeIndex, CodeBlock* codeBlock)
{
Node& node = at(nodeIndex);
NodeType op = node.op;
unsigned refCount = node.refCount();
if (!refCount)
return;
bool mustGenerate = node.mustGenerate();
if (mustGenerate)
--refCount;
printf("% 4d:\t<%c%u:", (int)nodeIndex, mustGenerate ? '!' : ' ', refCount);
if (node.hasResult())
printf("%u", node.virtualRegister());
else
printf("-");
printf(">\t%s(", dfgOpNames[op & NodeIdMask]);
if (node.child1 != NoNode)
printf("@%u", node.child1);
if (node.child2 != NoNode)
printf(", @%u", node.child2);
if (node.child3 != NoNode)
printf(", @%u", node.child3);
bool hasPrinted = node.child1 != NoNode;
if (node.hasVarNumber()) {
printf("%svar%u", hasPrinted ? ", " : "", node.varNumber());
hasPrinted = true;
}
if (node.hasIdentifier()) {
if (codeBlock)
printf("%sid%u{%s}", hasPrinted ? ", " : "", node.identifierNumber(), codeBlock->identifier(node.identifierNumber()).ustring().utf8().data());
else
printf("%sid%u", hasPrinted ? ", " : "", node.identifierNumber());
hasPrinted = true;
}
if (node.hasLocal()) {
int local = node.local();
if (operandIsArgument(local))
printf("%sarg%u", hasPrinted ? ", " : "", local - codeBlock->thisRegister());
else
printf("%sr%u", hasPrinted ? ", " : "", local);
hasPrinted = true;
}
if (op == Int32Constant) {
printf("%s$%u{%d|0x%08x}", hasPrinted ? ", " : "", node.constantNumber(), node.int32Constant(), node.int32Constant());
hasPrinted = true;
}
if (op == DoubleConstant) {
printf("%s$%u{%f})", hasPrinted ? ", " : "", node.constantNumber(), node.numericConstant());
hasPrinted = true;
}
if (op == JSConstant) {
printf("%s$%u", hasPrinted ? ", " : "", node.constantNumber());
hasPrinted = true;
}
if (node.isBranch() || node.isJump()) {
printf("%sT:#%u", hasPrinted ? ", " : "", blockIndexForBytecodeOffset(node.takenBytecodeOffset()));
hasPrinted = true;
}
if (node.isBranch()) {
printf("%sF:#%u", hasPrinted ? ", " : "", blockIndexForBytecodeOffset(node.notTakenBytecodeOffset()));
hasPrinted = true;
}
printf(")\n");
}
void Graph::dump(CodeBlock* codeBlock)
{
for (size_t b = 0; b < m_blocks.size(); ++b) {
printf("Block #%u:\n", (int)b);
for (size_t i = m_blocks[b]->begin; i < m_blocks[b]->end; ++i)
dump(i, codeBlock);
}
printf("Phi Nodes:\n");
for (size_t i = m_blocks.last()->end; i < size(); ++i)
dump(i, codeBlock);
}
#endif
void Graph::refChildren(NodeIndex op)
{
Node& node = at(op);
if (node.child1 == NoNode) {
ASSERT(node.child2 == NoNode && node.child3 == NoNode);
return;
}
ref(node.child1);
if (node.child2 == NoNode) {
ASSERT(node.child3 == NoNode);
return;
}
ref(node.child2);
if (node.child3 == NoNode)
return;
ref(node.child3);
}
} }
#endif