Global variable finder in pinpoint plugin

This commit is contained in:
York Jasper Niebuhr 2025-10-26 00:17:06 +02:00
parent 3b49742f87
commit 631fab7431
2 changed files with 38 additions and 37 deletions

View File

@ -1,5 +1,6 @@
#include <iostream>
#include <final.h>
#include <stage0.h>
#include <safe-input.h>
@ -11,5 +12,12 @@ void on_finish_unit(void* plugin_data, void* user_data) {
Add UID symbol to CU -> __spslr_cu_<uid>
Then dump accumulated data for finalizer
*/
std::cout << "Finishing unit \"" << lbasename(main_input_filename) << "\"" << std::endl;
std::cout << "Finishing unit \"" << lbasename(main_input_filename) << "\" ..." << std::endl;
for (const DataPin& dpin : dpins()) {
std::cout << " 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;
}
}

View File

@ -8,48 +8,41 @@ const std::list<DataPin>& dpins() {
return pins;
}
/*
struct DataPin {
struct Component {
std::size_t offset;
std::size_t level;
UID target;
};
static bool compile_datapin(tree type, DataPin& pin, std::size_t offset = 0, std::size_t level = 0) {
bool res = false;
std::string symbol;
std::list<Component> components;
};
*/
const TargetType* relevant = TargetType::find(type);
if (relevant) {
pin.components.push_back(DataPin::Component{
.offset = offset,
.level = level,
.target = relevant->uid()
});
/*
bool type_matches(tree t, hash_set<tree> *target_types)
{
if (!t) return false;
t = TYPE_MAIN_VARIANT(t);
if (target_types->contains(t))
return true;
if (TREE_CODE(t) == RECORD_TYPE || TREE_CODE(t) == UNION_TYPE)
{
for (tree field = TYPE_FIELDS(t); field; field = TREE_CHAIN(field))
{
if (TREE_CODE(field) == FIELD_DECL)
{
tree ftype = TREE_TYPE(field);
if (type_matches(ftype, target_types))
return true;
}
}
res = true;
}
return false;
}
*/
if (TREE_CODE(type) != RECORD_TYPE /* && TREE_CODE(type) != UNION_TYPE */)
return res;
static bool compile_datapin(tree type, DataPin& pin) {
// TODO
return true;
for (tree field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
if (TREE_CODE(field) != FIELD_DECL)
continue;
std::size_t field_offset;
bool field_bitfield;
if (!field_info(field, &field_offset, nullptr, &field_bitfield))
pinpoint_fatal("compile_datapin failed to get field info");
if (field_bitfield)
continue;
tree field_type = TREE_TYPE(field);
res = (res || compile_datapin(field_type, pin, offset + field_offset, level + 1));
}
return res;
}
static void on_static_var(tree var) {