Pinpoint plugin accumulation dump

This commit is contained in:
York Jasper Niebuhr 2025-10-26 17:22:17 +01:00
parent 5f28fd2b22
commit 31d80c3783
4 changed files with 52 additions and 12 deletions

View File

@ -3,7 +3,7 @@
/*
<sourcefile>.spslr:
SPSLR_FINALIZE_HEADER <CU filename> <CU uid symbol>
SPSLR <CU filename> <CU uid symbol>
target <name> <local uid> <size> <field count>
f <offset> <size> <flags>
f <offset> <size> <flags>

View File

@ -4,6 +4,7 @@
#include <stage1.h>
#include <string>
#include <filesystem>
#include <fstream>
#include <safe-input.h>
#include <safe-output.h>
@ -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 <name> <local uid> <size> <field count>
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 <offset> <size> <flags>
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 <local/global> <symbol> <offset> <level> <target uid>
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 <label> <target uid> <field offset>
out << "ipin " << SPSLR_PINPOINT_STAGE1_PIN << uid << " "
<< ipin.target << " " << ipin.offset << std::endl;
}
}

View File

@ -42,7 +42,8 @@ public:
~TargetType();
bool valid() const;
bool fields() const;
bool has_fields() const;
const std::map<std::size_t, Field>& fields() const;
std::string name() const;
const Field* field(std::size_t off, bool exact = true) const;
UID uid() const;

View File

@ -26,10 +26,14 @@ bool TargetType::valid() const {
return (m_flags & FLAG_MAIN_VARIANT) != 0;
}
bool TargetType::fields() const {
bool TargetType::has_fields() const {
return (m_flags & FLAG_FIELDS) != 0;
}
const std::map<std::size_t, TargetType::Field>& TargetType::fields() const {
return m_fields;
}
std::string TargetType::name() const {
const char* error_name = "<error>";
const char* anonymous_name = "<anonymous>";