aboutsummaryrefslogtreecommitdiffstats
path: root/qv4codegen.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2012-11-29 14:41:26 +0100
committerLars Knoll <lars.knoll@digia.com>2012-11-29 22:05:49 +0100
commita14e7549c4a3faece3474f059b2d04005cfc7cbf (patch)
tree3ce4903154e98aec5d952e5cdd067a7cb1b33aff /qv4codegen.cpp
parent36356a4b273e19ca599bf2a0cbfb02fda69e6c0a (diff)
Add some debugging infrastructure to the interpreter.
This currently mainly intended to be useful in a C++ debugger. The infrastructure makes it a lot easier to access (parent) contexts, find function names, etc. Change-Id: I0493d3a3bd4bf5c3a03379c1a2b545ed76862cd5 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'qv4codegen.cpp')
-rw-r--r--qv4codegen.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/qv4codegen.cpp b/qv4codegen.cpp
index 0f3cedb55c..1980ed95a4 100644
--- a/qv4codegen.cpp
+++ b/qv4codegen.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "qv4codegen_p.h"
+#include "debugging.h"
#include <QtCore/QStringList>
#include <QtCore/QSet>
@@ -352,7 +353,7 @@ protected:
QStack<Environment *> _envStack;
};
-Codegen::Codegen()
+Codegen::Codegen(Debugging::Debugger *debugger)
: _module(0)
, _function(0)
, _block(0)
@@ -363,6 +364,7 @@ Codegen::Codegen()
, _env(0)
, _loop(0)
, _labelledStatement(0)
+ , _debugger(debugger)
{
}
@@ -377,6 +379,12 @@ IR::Function *Codegen::operator()(Program *node, IR::Module *module, Mode mode)
scan(node);
IR::Function *globalCode = defineFunction(QStringLiteral("%entry"), node, 0, node->elements, mode);
+ if (_debugger) {
+ if (node->elements->element) {
+ SourceLocation loc = node->elements->element->firstSourceLocation();
+ _debugger->setSourceLocation(globalCode, loc.startLine, loc.startColumn);
+ }
+ }
foreach (IR::Function *function, _module->functions) {
linearize(function);
@@ -397,6 +405,8 @@ IR::Function *Codegen::operator()(AST::FunctionExpression *ast, IR::Module *modu
scan(ast);
IR::Function *function = defineFunction(ast->name.toString(), ast, ast->formals, ast->body ? ast->body->elements : 0);
+ if (_debugger)
+ _debugger->setSourceLocation(function, ast->functionToken.startLine, ast->functionToken.startColumn);
foreach (IR::Function *function, _module->functions) {
linearize(function);
@@ -1168,6 +1178,8 @@ bool Codegen::visit(FieldMemberExpression *ast)
bool Codegen::visit(FunctionExpression *ast)
{
IR::Function *function = defineFunction(ast->name.toString(), ast, ast->formals, ast->body ? ast->body->elements : 0);
+ if (_debugger)
+ _debugger->setSourceLocation(function, ast->functionToken.startLine, ast->functionToken.startColumn);
_expr.code = _block->CLOSURE(function);
return false;
}
@@ -1570,6 +1582,8 @@ IR::Function *Codegen::defineFunction(const QString &name, AST::Node *ast,
enterEnvironment(ast);
IR::Function *function = _module->newFunction(name);
+ if (_debugger)
+ _debugger->addFunction(function);
IR::BasicBlock *entryBlock = function->newBasicBlock();
IR::BasicBlock *exitBlock = function->newBasicBlock(IR::Function::DontInsertBlock);
IR::BasicBlock *throwBlock = function->newBasicBlock();
@@ -1626,6 +1640,8 @@ IR::Function *Codegen::defineFunction(const QString &name, AST::Node *ast,
foreach (AST::FunctionDeclaration *f, _env->functions) {
IR::Function *function = defineFunction(f->name.toString(), f, f->formals,
f->body ? f->body->elements : 0);
+ if (_debugger)
+ _debugger->setSourceLocation(function, f->functionToken.startLine, f->functionToken.startColumn);
if (! _env->parent)
move(_block->NAME(f->name.toString(), f->identifierToken.startLine, f->identifierToken.startColumn),
_block->CLOSURE(function));