Hooked up on_finish_type for pinpoint plugin
This commit is contained in:
parent
162a0785c9
commit
bfb64990dc
9
pinpoint/safegcc/safe-diagnostic.h
Normal file
9
pinpoint/safegcc/safe-diagnostic.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include <safe-gcc-plugin.h>
|
||||||
|
|
||||||
|
#ifndef SAFEGCC_DIAGNOSTIC_H
|
||||||
|
#define SAFEGCC_DIAGNOSTIC_H
|
||||||
|
|
||||||
|
#include <diagnostic.h>
|
||||||
|
#include <diagnostic-core.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
8
pinpoint/spslr_error.h
Normal file
8
pinpoint/spslr_error.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <safe-diagnostic.h>
|
||||||
|
|
||||||
|
#define spslr_fatal_loc(loc, fmt, ...) \
|
||||||
|
fatal_error((loc), "[spslr_pinpoint] " fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#define spslr_fatal(fmt, ...) \
|
||||||
|
spslr_fatal_loc(UNKNOWN_LOCATION, fmt, ##__VA_ARGS__)
|
||||||
@ -1,6 +1,14 @@
|
|||||||
#include <stage0.h>
|
#include <stage0.h>
|
||||||
|
#include <spslr_error.h>
|
||||||
|
|
||||||
void on_finish_type(void* plugin_data, void* user_data) {
|
void on_finish_type(void* plugin_data, void* user_data) {
|
||||||
|
tree t = (tree)plugin_data;
|
||||||
|
|
||||||
|
TargetType* type = TargetType::find_mutable(t);
|
||||||
|
if (!type)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!type->fetch_fields())
|
||||||
|
spslr_fatal("on_finish_type failed to fetch fields of target \"%s\"", type->name().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include <safe-tree.h>
|
#include <safe-tree.h>
|
||||||
@ -38,13 +39,16 @@ public:
|
|||||||
|
|
||||||
bool valid() const;
|
bool valid() const;
|
||||||
bool fields() const;
|
bool fields() const;
|
||||||
|
std::string name() const;
|
||||||
bool fetch_fields();
|
|
||||||
|
|
||||||
static void add(tree t);
|
static void add(tree t);
|
||||||
static std::size_t count();
|
static std::size_t count();
|
||||||
static const TargetType* find(tree t); // O(n)
|
static const TargetType* find(tree t); // O(n)
|
||||||
static const TargetType* find(UID uid); // O(1)
|
static const TargetType* find(UID uid); // O(1)
|
||||||
|
private:
|
||||||
|
friend void on_finish_type(void*, void*);
|
||||||
|
bool fetch_fields();
|
||||||
|
static TargetType* find_mutable(tree t);
|
||||||
};
|
};
|
||||||
|
|
||||||
void on_register_attributes(void* plugin_data, void* user_data);
|
void on_register_attributes(void* plugin_data, void* user_data);
|
||||||
|
|||||||
@ -30,9 +30,23 @@ bool TargetType::fields() const {
|
|||||||
return (m_flags & FLAG_FIELDS) != 0;
|
return (m_flags & FLAG_FIELDS) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TargetType::fetch_fields() {
|
std::string TargetType::name() const {
|
||||||
// TODO
|
const char* error_name = "<error>";
|
||||||
return false;
|
const char* anonymous_name = "<anonymous>";
|
||||||
|
|
||||||
|
if (!valid())
|
||||||
|
return { error_name };
|
||||||
|
|
||||||
|
tree name_tree = TYPE_NAME(m_main_variant);
|
||||||
|
if (!name_tree)
|
||||||
|
return { anonymous_name };
|
||||||
|
|
||||||
|
if (TREE_CODE(name_tree) == TYPE_DECL && DECL_NAME(name_tree))
|
||||||
|
return { IDENTIFIER_POINTER(DECL_NAME(name_tree)) };
|
||||||
|
else if (TREE_CODE(name_tree) == IDENTIFIER_NODE)
|
||||||
|
return { IDENTIFIER_POINTER(name_tree) };
|
||||||
|
|
||||||
|
return { anonymous_name };
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetType::add(tree t) {
|
void TargetType::add(tree t) {
|
||||||
@ -64,6 +78,19 @@ const TargetType* TargetType::find(tree t) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TargetType* TargetType::find_mutable(tree t) {
|
||||||
|
tree main_variant = get_record_main_variant(t);
|
||||||
|
if (!main_variant)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
for (auto& [uid, target] : targets) {
|
||||||
|
if (lang_hooks.types_compatible_p(main_variant, target.m_main_variant))
|
||||||
|
return ⌖
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
const TargetType* TargetType::find(UID uid) {
|
const TargetType* TargetType::find(UID uid) {
|
||||||
auto it = targets.find(uid);
|
auto it = targets.find(uid);
|
||||||
if (it == targets.end())
|
if (it == targets.end())
|
||||||
@ -72,3 +99,8 @@ const TargetType* TargetType::find(UID uid) {
|
|||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TargetType::fetch_fields() {
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user