// Copyright 2013 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/compiler/graph-visualizer.h" #include #include #include #include "src/codegen/optimized-compilation-info.h" #include "src/codegen/source-position.h" #include "src/compiler/all-nodes.h" #include "src/compiler/backend/register-allocator.h" #include "src/compiler/compiler-source-position-table.h" #include "src/compiler/graph.h" #include "src/compiler/node-origin-table.h" #include "src/compiler/node-properties.h" #include "src/compiler/node.h" #include "src/compiler/opcodes.h" #include "src/compiler/operator-properties.h" #include "src/compiler/operator.h" #include "src/compiler/schedule.h" #include "src/compiler/scheduler.h" #include "src/interpreter/bytecodes.h" #include "src/objects/script-inl.h" #include "src/objects/shared-function-info.h" #include "src/utils/ostreams.h" #include "src/utils/vector.h" namespace v8 { namespace internal { namespace compiler { const char* get_cached_trace_turbo_filename(OptimizedCompilationInfo* info) { if (!info->trace_turbo_filename()) { info->set_trace_turbo_filename( GetVisualizerLogFileName(info, FLAG_trace_turbo_path, nullptr, "json")); } return info->trace_turbo_filename(); } TurboJsonFile::TurboJsonFile(OptimizedCompilationInfo* info, std::ios_base::openmode mode) : std::ofstream(get_cached_trace_turbo_filename(info), mode) {} TurboJsonFile::~TurboJsonFile() { flush(); } TurboCfgFile::TurboCfgFile(Isolate* isolate) : std::ofstream(Isolate::GetTurboCfgFileName(isolate).c_str(), std::ios_base::app) {} TurboCfgFile::~TurboCfgFile() { flush(); } std::ostream& operator<<(std::ostream& out, const SourcePositionAsJSON& asJSON) { asJSON.sp.PrintJson(out); return out; } std::ostream& operator<<(std::ostream& out, const NodeOriginAsJSON& asJSON) { asJSON.no.PrintJson(out); return out; } class JSONEscaped { public: explicit JSONEscaped(const std::ostringstream& os) : str_(os.str()) {} friend std::ostream& operator<<(std::ostream& os, const JSONEscaped& e) { for (char c : e.str_) PipeCharacter(os, c); return os; } private: static std::ostream& PipeCharacter(std::ostream& os, char c) { if (c == '"') return os << "\\\""; if (c == '\\') return os << "\\\\"; if (c == '\b') return os << "\\b"; if (c == '\f') return os << "\\f"; if (c == '\n') return os << "\\n"; if (c == '\r') return os << "\\r"; if (c == '\t') return os << "\\t"; return os << c; } const std::string str_; }; void JsonPrintFunctionSource(std::ostream& os, int source_id, std::unique_ptr function_name, Handle