-
Benoit Perrot authored
from Benoît Perrot <benoit@lrde.epita.fr> Let concrete sections choose how to handle labels definitions. * src/inst/section.hh (add_label): Rename as `register_label'. * src/inst/data_section.hh, src/inst/text_section.hh: (add_label): Rename as... (define_label): This, and make it wait for a unique_string and build the label. * dev/parse-asm-scan-gen.py: Return a unique_string on a label definition. * dev/parse-asm-parse-gen.py: Update accordingly. Index: src/inst/data_section.hh --- src/inst/data_section.hh (revision 160) +++ src/inst/data_section.hh (working copy) @@ -54,9 +54,9 @@ } public: - void add_label(Label *label) + void define_label(const misc::unique_string &id) { - Section::add_label(label, size_); + Section::register_label(new inst::Label(id), size_); } public: Index: src/inst/section.hh --- src/inst/section.hh (revision 160) +++ src/inst/section.hh (working copy) @@ -49,7 +49,7 @@ {} protected: - void add_label(Label *label, int offset) + void register_label(Label *label, int offset) { // FIXME: check that this label has not already been added. offsets_[*label] = offset; Index: src/inst/text_section.hh --- src/inst/text_section.hh (revision 160) +++ src/inst/text_section.hh (working copy) @@ -54,9 +54,9 @@ } public: - void add_label(Label *label) + void define_label(const misc::unique_string &id) { - Section::add_label(label, insts_.size() * 4); + Section::register_label(new inst::Label(id), insts_.size() * 4); } public: Index: dev/inst-builder-gen.py --- dev/inst-builder-gen.py (revision 160) +++ dev/inst-builder-gen.py (working copy) @@ -78,14 +78,14 @@ } public: - void add_inst_label(Label *label) + void define_inst_label(const misc::unique_string &id) { - program_->text_section ().add_label(label); + program_->text_section ().define_label(id); } - void add_data_label(Label *label) + void define_data_label(const misc::unique_string &id) { - program_->data_section ().add_label(label); + program_->data_section ().define_label(id); } public: Index: dev/parse-asm-scan-gen.py --- dev/parse-asm-scan-gen.py (revision 160) +++ dev/parse-asm-scan-gen.py (working copy) @@ -71,7 +71,7 @@ dec_int [0-9]+ hex_int 0x[0-9A-Fa-f]+ -label [a-zA-Z_][a-zA-Z_0-9]* +id [a-zA-Z_][a-zA-Z_0-9]* %% %{ @@ -144,14 +144,14 @@ } -{label} { +{id} { yylval->label = new inst::Label (yytext); return LABEL; } -{label}\":\" { +{id}\":\" { std::string label = yytext; label.resize(yyleng - 1); - yylval->label = new inst::Label (label); + yylval->id = &misc::unique_string::create(label); return LABEL_DEF; } Index: dev/parse-asm-parse-gen.py --- dev/parse-asm-parse-gen.py (revision 160) +++ dev/parse-asm-parse-gen.py (working copy) @@ -75,6 +75,7 @@ { int i; std::string *s; + const misc::unique_string *id; inst::Label *label; inst::Register *reg; inst::Exp *exp; @@ -84,7 +85,7 @@ %} %token <label> LABEL \"label\" -%token <label> LABEL_DEF \"label definition\" +%token <id> LABEL_DEF \"label definition\" %token <i> INTEGER \"integer\" %token <s> STRING \"string\" %token <reg> REGISTER \"register\" @@ -138,7 +139,7 @@ data // Label : LABEL_DEF -{ program_builder.add_data_label($1); } +{ program_builder.define_data_label(*$1); } // Uninitialized space | DIR_SPACE INTEGER @@ -169,7 +170,7 @@ instruction // Label : LABEL_DEF -{ program_builder.add_inst_label($1); } +{ program_builder.define_inst_label(*$1); } // Opcodes"""
80ffde06