33class Section :
virtual public Parsable,
virtual public Contextable {
34 static std::map<std::string, Section *> *sections;
37 static Section *get(
const char *name) { return ::get(sections, name); }
40 explicit Section(
const char *name_) : name(name_) {
41 if (!sections) sections =
new std::map<std::string, Section *>();
43 fprintf(stderr,
"Duplicate section handler for %s\n", name_);
46 (*sections)[name] =
this;
49 sections->erase(name);
50 if (sections->empty()) {
61 static int start_section(
int lineno,
char *name, VECTOR(
value_t) args) {
63 int prev_error_count = error_count;
65 sec->start(lineno, args);
66 return error_count > prev_error_count;
68 warning(lineno,
"Unknown section %s, ignoring\n", name);
72 static void asm_section(
char *name, VECTOR(value_t) args, value_t data) {
73 if (Section *sec = get(name)) sec->input(args, data);
75 static void process_all() {
77 for (
auto &it : *sections) it.second->process();
79 static void output_all(json::map &ctxtJson) {
81 for (
auto &it : *sections) {
83 if (it.first ==
"primitives")
continue;
84 it.second->output(ctxtJson);
87 if (s.count(
"primitives")) s[
"primitives"]->output(ctxtJson);
90 static bool no_sections_in_assembly() {
92 for (
auto &it : *sections) {
93 if (it.second->isInput)
return false;
98 static bool section_in_assembly(
const char *name) {
return get(name)->isInput; }
101 static Section *test_get(
const char *name) {
return get(name); }
void warning(const char *format, Args &&...args)
Report a warning with the given message.
Definition lib/error.h:122