diff --git a/finalize/finalize.cpp b/finalize/finalize.cpp index e7899bf..dda1fe6 100644 --- a/finalize/finalize.cpp +++ b/finalize/finalize.cpp @@ -3,7 +3,7 @@ /* .spslr: -SPSLR_FINALIZE_HEADER +SPSLR target f f diff --git a/pinpoint/final/on_finish_unit.cpp b/pinpoint/final/on_finish_unit.cpp index 708b173..b01144f 100644 --- a/pinpoint/final/on_finish_unit.cpp +++ b/pinpoint/final/on_finish_unit.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -98,6 +99,15 @@ static void emit_cu_uid_label(const std::string& uid) { fprintf(asm_out_file, "%s:\n", label); } +static std::ofstream open_spslr_output_file(const std::filesystem::path& p) { + std::filesystem::create_directories(p.parent_path()); + std::ofstream out(p); + if (!out) + pinpoint_fatal("open_spslr_output_file failed to open spslr dump file"); + + return std::move(out); +} + void on_finish_unit(void* plugin_data, void* user_data) { std::filesystem::path infile = relative_src_path(); std::filesystem::path outfile = spslr_output_file(infile); @@ -110,20 +120,45 @@ void on_finish_unit(void* plugin_data, void* user_data) { emit_cu_uid_label(cu_uid); - // TODO -> Dump to outfile + // Dump all accumulated data to spslr file - for (const auto& [uid, target] : TargetType::all()) - std::cout << " Target " << uid << " -> \"" << target.name() << "\" (" << target.size() << ")" << std::endl; + std::ofstream out = open_spslr_output_file(outfile); + + // Header associates data with compilation unit + + out << "SPSLR " << infile.string() << " " << cu_uid << std::endl; + + // Dump all target structs + + for (const auto& [uid, target] : TargetType::all()) { + // target + out << "target " << target.name() << " " << uid << " " << target.size() + << " " << target.fields().size() << std::endl; + + if (!target.has_fields()) + pinpoint_fatal("on_finish_unit encountered incomplete target type"); + + for (const auto& [off, field] : target.fields()) { + // f + out << "f " << field.offset << " " << field.size << " " << field.flags << std::endl; + } + } + + // Dump all data pins for (const DataPin& dpin : DataPin::all()) { - std::cout << " " << (dpin.global ? "Global" : "Local") << " data pin at symbol \"" - << dpin.symbol << "\":" << std::endl; - for (const DataPin::Component& c : dpin.components) - std::cout << " offset " << c.offset << " (level " << c.level << ") -> target " << c.target << std::endl; + for (const DataPin::Component& c : dpin.components) { + // dpin + out << "dpin " << (dpin.global ? "g" : "l") << " " << dpin.symbol << " " + << c.offset << " " << c.level << " " << c.target << std::endl; + } } + // Dump all instruction pins + for (const auto& [uid, ipin] : S1InstructionPin::all()) { - std::cout << " Instruction pin at symbol \"" << SPSLR_PINPOINT_STAGE1_PIN - << uid << "\" -> target " << ipin.target << ", offset " << ipin.offset << std::endl; + // ipin