#include "src/compiler/pipeline.h"
+#include <fstream> // NOLINT(readability/streams)
#include <sstream>
#include "src/base/platform/elapsed-timer.h"
}
-void Pipeline::PrintCompilationStart() {
- std::ofstream turbo_cfg_stream;
- OpenTurboCfgFile(&turbo_cfg_stream);
- turbo_cfg_stream << AsC1VCompilation(info());
-}
-
-
-void Pipeline::OpenTurboCfgFile(std::ofstream* stream) {
- char buffer[512];
- Vector<char> filename(buffer, sizeof(buffer));
- isolate()->GetTurboCfgFileName(filename);
- stream->open(filename.start(), std::fstream::out | std::fstream::app);
-}
+struct TurboCfgFile : public std::ofstream {
+ explicit TurboCfgFile(Isolate* isolate)
+ : std::ofstream(isolate->GetTurboCfgFileName(), std::ios_base::app) {}
+};
void Pipeline::VerifyAndPrintGraph(
}
-void Pipeline::PrintScheduleAndInstructions(
- const char* phase, const Schedule* schedule,
- const SourcePositionTable* positions,
- const InstructionSequence* instructions) {
- std::ofstream turbo_cfg_stream;
- OpenTurboCfgFile(&turbo_cfg_stream);
- turbo_cfg_stream << AsC1V(phase, schedule, positions, instructions);
-}
-
-
-void Pipeline::PrintAllocator(const char* phase,
- const RegisterAllocator* allocator) {
- std::ofstream turbo_cfg_stream;
- OpenTurboCfgFile(&turbo_cfg_stream);
- turbo_cfg_stream << AsC1VAllocator(phase, allocator);
-}
-
-
class AstGraphBuilderWithPositions : public AstGraphBuilder {
public:
explicit AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info,
<< "Begin compiling method "
<< info()->function()->debug_name()->ToCString().get()
<< " using Turbofan" << std::endl;
- PrintCompilationStart();
+ TurboCfgFile(isolate()) << AsC1VCompilation(info());
}
ZonePool zone_pool(isolate());
OFStream os(stdout);
os << "----- Instruction sequence before register allocation -----\n"
<< sequence;
- PrintScheduleAndInstructions("CodeGen", schedule, source_positions,
- &sequence);
+ TurboCfgFile(isolate())
+ << AsC1V("CodeGen", schedule, source_positions, &sequence);
}
// Allocate registers.
return Handle<Code>::null();
}
if (FLAG_trace_turbo) {
- PrintAllocator("CodeGen", &allocator);
+ TurboCfgFile(isolate()) << AsC1VAllocator("CodeGen", &allocator);
}
}
#ifndef V8_COMPILER_PIPELINE_H_
#define V8_COMPILER_PIPELINE_H_
-#include <fstream> // NOLINT(readability/streams)
-
#include "src/v8.h"
#include "src/compiler.h"
Zone* zone() { return info_->zone(); }
Schedule* ComputeSchedule(ZonePool* zone_pool, Graph* graph);
- void OpenTurboCfgFile(std::ofstream* stream);
- void PrintCompilationStart();
- void PrintScheduleAndInstructions(const char* phase, const Schedule* schedule,
- const SourcePositionTable* positions,
- const InstructionSequence* instructions);
- void PrintAllocator(const char* phase, const RegisterAllocator* allocator);
void VerifyAndPrintGraph(Graph* graph, const char* phase,
bool untyped = false);
Handle<Code> GenerateCode(ZonePool* zone_pool, Linkage* linkage, Graph* graph,
if (!create_heap_objects) Assembler::QuietNaN(heap_.nan_value());
if (FLAG_trace_turbo) {
- // Erase the file.
- char buffer[512];
- Vector<char> filename(buffer, sizeof(buffer));
- GetTurboCfgFileName(filename);
- std::ofstream turbo_cfg_stream(filename.start(),
- std::fstream::out | std::fstream::trunc);
+ // Create an empty file.
+ std::ofstream(GetTurboCfgFileName(), std::ios_base::trunc);
}
// If we are deserializing, log non-function code objects and compiled
}
-void Isolate::GetTurboCfgFileName(Vector<char> filename) {
- if (FLAG_trace_turbo_cfg_file == NULL) {
- SNPrintF(filename, "turbo-%d-%d.cfg", base::OS::GetCurrentProcessId(),
- id());
- } else {
- StrNCpy(filename, FLAG_trace_turbo_cfg_file, filename.length());
- }
+std::string Isolate::GetTurboCfgFileName() {
+ return FLAG_trace_turbo_cfg_file == NULL
+ ? "turbo-" + std::to_string(base::OS::GetCurrentProcessId()) +
+ "-" + std::to_string(id()) + ".cfg"
+ : FLAG_trace_turbo_cfg_file;
}