Commit 9c3d08f9 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[interpreter] Implement support for the --trace flag.

R=rmcilroy@chromium.org

Review-Url: https://codereview.chromium.org/2387363003
Cr-Commit-Position: refs/heads/master@{#39979}
parent f7307419
......@@ -716,14 +716,6 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::MarkTryEnd(int handler_id) {
return *this;
}
void BytecodeArrayBuilder::EnsureReturn() {
if (!return_seen_in_block_) {
LoadUndefined();
Return();
}
DCHECK(return_seen_in_block_);
}
BytecodeArrayBuilder& BytecodeArrayBuilder::Call(Register callable,
RegisterList args,
int feedback_slot,
......
......@@ -312,7 +312,7 @@ class BytecodeArrayBuilder final : public ZoneObject {
latest_source_info_.MakeStatementPosition(expr->position());
}
void EnsureReturn();
bool RequiresImplicitReturn() const { return !return_seen_in_block_; }
// Accessors
BytecodeRegisterAllocator* register_allocator() {
......
......@@ -217,10 +217,10 @@ class BytecodeGenerator::ControlScopeForTopLevel final
case CMD_CONTINUE:
UNREACHABLE();
case CMD_RETURN:
generator()->builder()->Return();
generator()->BuildReturn();
return true;
case CMD_RETHROW:
generator()->builder()->ReThrow();
generator()->BuildReThrow();
return true;
}
return false;
......@@ -311,7 +311,7 @@ class BytecodeGenerator::ControlScopeForTryCatch final
case CMD_RETURN:
break;
case CMD_RETHROW:
generator()->builder()->ReThrow();
generator()->BuildReThrow();
return true;
}
return false;
......@@ -649,7 +649,13 @@ void BytecodeGenerator::GenerateBytecode(uintptr_t stack_limit) {
if (!label.is_bound()) builder()->Bind(&label);
}
builder()->EnsureReturn();
// Emit an implicit return instruction in case control flow can fall off the
// end of the function without an explicit return being present on all paths.
if (builder()->RequiresImplicitReturn()) {
builder()->LoadUndefined();
BuildReturn();
}
DCHECK(!builder()->RequiresImplicitReturn());
}
void BytecodeGenerator::GenerateBytecodeBody() {
......@@ -666,10 +672,8 @@ void BytecodeGenerator::GenerateBytecodeBody() {
// Build assignment to {new.target} variable if it is used.
VisitNewTargetVariable(scope()->new_target_var());
// TODO(rmcilroy): Emit tracing call if requested to do so.
if (FLAG_trace) {
UNIMPLEMENTED();
}
// Emit tracing call if requested to do so.
if (FLAG_trace) builder()->CallRuntime(Runtime::kTraceEnter);
// Visit declarations within the function scope.
VisitDeclarations(scope()->declarations());
......@@ -1855,6 +1859,19 @@ void BytecodeGenerator::VisitVariableLoadForAccumulatorValue(
VisitVariableLoad(variable, slot, typeof_mode);
}
void BytecodeGenerator::BuildReturn() {
if (FLAG_trace) {
RegisterAllocationScope register_scope(this);
Register result = register_allocator()->NewRegister();
// Runtime returns {result} value, preserving accumulator.
builder()->StoreAccumulatorInRegister(result).CallRuntime(
Runtime::kTraceExit, result);
}
builder()->Return();
}
void BytecodeGenerator::BuildReThrow() { builder()->ReThrow(); }
void BytecodeGenerator::BuildAbort(BailoutReason bailout_reason) {
RegisterAllocationScope register_scope(this);
Register reason = register_allocator()->NewRegister();
......
......@@ -105,6 +105,8 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
void VisitVariableAssignment(Variable* variable, Token::Value op,
FeedbackVectorSlot slot);
void BuildReturn();
void BuildReThrow();
void BuildAbort(BailoutReason bailout_reason);
void BuildThrowIfHole(Handle<String> name);
void BuildThrowIfNotHole(Handle<String> name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment