// 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. #ifndef V8_COMPILER_GRAPH_VISUALIZER_H_ #define V8_COMPILER_GRAPH_VISUALIZER_H_ #include #include // NOLINT(readability/streams) #include #include #include "src/globals.h" #include "src/handles.h" namespace v8 { namespace internal { class OptimizedCompilationInfo; class SharedFunctionInfo; class SourcePosition; namespace compiler { class Graph; class InstructionSequence; class NodeOrigin; class NodeOriginTable; class RegisterAllocationData; class Schedule; class SourcePositionTable; struct TurboJsonFile : public std::ofstream { TurboJsonFile(OptimizedCompilationInfo* info, std::ios_base::openmode mode); ~TurboJsonFile(); }; struct SourcePositionAsJSON { explicit SourcePositionAsJSON(const SourcePosition& sp) : sp(sp) {} const SourcePosition& sp; }; V8_INLINE V8_EXPORT_PRIVATE SourcePositionAsJSON AsJSON(const SourcePosition& sp) { return SourcePositionAsJSON(sp); } struct NodeOriginAsJSON { explicit NodeOriginAsJSON(const NodeOrigin& no) : no(no) {} const NodeOrigin& no; }; V8_INLINE V8_EXPORT_PRIVATE NodeOriginAsJSON AsJSON(const NodeOrigin& no) { return NodeOriginAsJSON(no); } std::ostream& operator<<(std::ostream& out, const SourcePositionAsJSON& pos); // Small helper that deduplicates SharedFunctionInfos. class SourceIdAssigner { public: explicit SourceIdAssigner(size_t size) { printed_.reserve(size); source_ids_.reserve(size); } int GetIdFor(Handle shared); int GetIdAt(size_t pos) const { return source_ids_[pos]; } private: std::vector> printed_; std::vector source_ids_; }; void JsonPrintAllSourceWithPositions(std::ostream& os, OptimizedCompilationInfo* info, Isolate* isolate); void JsonPrintFunctionSource(std::ostream& os, int source_id, std::unique_ptr function_name, Handle