Commit 43d6dc56 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Interpreter] Move ast printing into interpreter.cc

Moves ast printing out of codegen.cc and into interpreter.cc since this is
the only place which calls it.

BUG=v8:6409

Change-Id: I7b730f6b4da76247f57e3cb4fa7895e638ea0517
Reviewed-on: https://chromium-review.googlesource.com/664888
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47996}
parent cf9386c7
......@@ -10,14 +10,12 @@
#include <memory>
#include "src/ast/prettyprinter.h"
#include "src/bootstrapper.h"
#include "src/compilation-info.h"
#include "src/counters.h"
#include "src/debug/debug.h"
#include "src/eh-frame.h"
#include "src/objects-inl.h"
#include "src/parsing/parse-info.h"
#include "src/runtime/runtime.h"
namespace v8 {
......@@ -69,45 +67,6 @@ UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction)
#undef UNARY_MATH_FUNCTION
void CodeGenerator::MakeCodePrologue(ParseInfo* parse_info,
CompilationInfo* info, const char* kind) {
bool print_ast = false;
const char* ftype;
if (info->isolate()->bootstrapper()->IsActive()) {
print_ast = FLAG_print_builtin_ast;
ftype = "builtin";
} else {
print_ast = FLAG_print_ast;
ftype = "user-defined";
}
if (!FLAG_trace_codegen && !print_ast) return;
// Requires internalizing the AST, so make sure we are on the main thread and
// allow handle dereference and allocations.
// TODO(rmcilroy): Make ast-printer print ast raw strings instead of
// internalized strings to avoid internalizing here.
DCHECK(ThreadId::Current().Equals(info->isolate()->thread_id()));
AllowHandleDereference allow_deref;
AllowHandleAllocation allow_handles;
AllowHeapAllocation allow_gc;
parse_info->ast_value_factory()->Internalize(info->isolate());
if (FLAG_trace_codegen || print_ast) {
std::unique_ptr<char[]> name = info->GetDebugName();
PrintF("[generating %s code for %s function: %s]\n", kind, ftype,
name.get());
}
#ifdef DEBUG
if (!info->IsStub() && print_ast) {
PrintF("--- AST ---\n%s\n",
AstPrinter(info->isolate()).PrintProgram(info->literal()));
}
#endif // DEBUG
}
Handle<Code> CodeGenerator::MakeCodeEpilogue(TurboAssembler* tasm,
EhFrameWriter* eh_frame_writer,
CompilationInfo* info,
......
......@@ -10,10 +10,9 @@
#include "src/runtime/runtime.h"
// Include the declaration of the architecture defined class CodeGenerator.
// The contract to the shared code is that the the CodeGenerator is a subclass
// The contract to the shared code is that the the CodeGenerator is a subclass
// of Visitor and that the following methods are available publicly:
// MakeCode
// MakeCodePrologue
// MakeCodeEpilogue
// masm
// frame
......@@ -68,14 +67,9 @@ namespace internal {
class CompilationInfo;
class EhFrameWriter;
class ParseInfo;
class CodeGenerator {
public:
// Printing of AST, etc. as requested by flags.
static void MakeCodePrologue(ParseInfo* parse_info, CompilationInfo* info,
const char* kind);
// Allocate and install the code.
static Handle<Code> MakeCodeEpilogue(TurboAssembler* tasm,
EhFrameWriter* unwinding,
......
......@@ -7,6 +7,8 @@
#include <fstream>
#include <memory>
#include "src/ast/prettyprinter.h"
#include "src/bootstrapper.h"
#include "src/codegen.h"
#include "src/compilation-info.h"
#include "src/compiler.h"
......@@ -16,6 +18,7 @@
#include "src/log.h"
#include "src/objects-inl.h"
#include "src/objects/shared-function-info.h"
#include "src/parsing/parse-info.h"
#include "src/setup-isolate.h"
#include "src/visitors.h"
......@@ -120,6 +123,32 @@ void Interpreter::IterateDispatchTable(RootVisitor* v) {
namespace {
void MaybePrintAst(ParseInfo* parse_info, CompilationInfo* compilation_info) {
Isolate* isolate = compilation_info->isolate();
bool print_ast = isolate->bootstrapper()->IsActive() ? FLAG_print_builtin_ast
: FLAG_print_ast;
if (!print_ast) return;
// Requires internalizing the AST, so make sure we are on the main thread and
// allow handle dereference and allocations.
// TODO(rmcilroy): Make ast-printer print ast raw strings instead of
// internalized strings to avoid internalizing here.
DCHECK(ThreadId::Current().Equals(isolate->thread_id()));
AllowHandleDereference allow_deref;
AllowHandleAllocation allow_handles;
AllowHeapAllocation allow_gc;
parse_info->ast_value_factory()->Internalize(isolate);
OFStream os(stdout);
std::unique_ptr<char[]> name = compilation_info->GetDebugName();
os << "[generating bytecode for function: "
<< compilation_info->GetDebugName().get() << "]" << std::endl;
#ifdef DEBUG
os << "--- AST ---" << std::endl
<< AstPrinter(isolate).PrintProgram(parse_info->literal()) << std::endl;
#endif // DEBUG
}
bool ShouldPrintBytecode(Handle<SharedFunctionInfo> shared) {
if (!FLAG_print_bytecode) return false;
......@@ -145,9 +174,7 @@ InterpreterCompilationJob::InterpreterCompilationJob(ParseInfo* parse_info,
background_execute_counter_("CompileBackgroundIgnition") {}
InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() {
// TODO(5203): Move code out of codegen.cc once FCG goes away.
CodeGenerator::MakeCodePrologue(parse_info(), compilation_info(),
"interpreter");
MaybePrintAst(parse_info(), compilation_info());
return SUCCEEDED;
}
......@@ -188,7 +215,7 @@ InterpreterCompilationJob::Status InterpreterCompilationJob::FinalizeJobImpl() {
if (ShouldPrintBytecode(compilation_info()->shared_info())) {
OFStream os(stdout);
std::unique_ptr<char[]> name = compilation_info()->GetDebugName();
os << "[generating bytecode for function: "
os << "[generated bytecode for function: "
<< compilation_info()->GetDebugName().get() << "]" << std::endl;
bytecodes->Disassemble(os);
os << std::flush;
......
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