39 lines
918 B
C++
39 lines
918 B
C++
#include "attrib.h"
|
|
|
|
#include <gcc-plugin.h>
|
|
#include <tree.h>
|
|
|
|
#include <unordered_set>
|
|
#include <string>
|
|
|
|
static std::unordered_set<std::string> targets;
|
|
|
|
static tree handle_spslr_attribute(tree* node, tree name, tree args, int flags, bool* no_add_attrs) {
|
|
if (!node)
|
|
return NULL_TREE;
|
|
|
|
if (TREE_CODE(*node) != RECORD_TYPE)
|
|
return *node; // Only allowed on structs
|
|
|
|
tree type_name_tree = TYPE_IDENTIFIER(*node);
|
|
if (type_name_tree == NULL_TREE)
|
|
return *node;
|
|
|
|
std::string name_str{ IDENTIFIER_POINTER(type_name_tree) };
|
|
targets.insert(name_str);
|
|
return *node;
|
|
}
|
|
|
|
static struct attribute_spec spslr_attribute = {
|
|
SPSRL_ATTRIBUTE, 0, 0, false, false, false, false, handle_spslr_attribute, NULL
|
|
};
|
|
|
|
void register_attributes(void* event_data, void* data) {
|
|
register_attribute(&spslr_attribute);
|
|
}
|
|
|
|
bool is_target(const char* name) {
|
|
std::string str{ name };
|
|
return targets.find(str) != targets.end();
|
|
}
|