Index: ChangeLog
from Benoît Perrot <benoit(a)lrde.epita.fr>
Add data storage directives.
* dev/parse-asm-scan-gen.py, dev/parse-asm-parse-gen.py:
Add `.byte', .half', `.ascii' directives.
* dev/inst-builder-gen.py: Implement new directives.
* src/inst/data_section.hh: Move `.asciiz' implementation to
program_builder.hh.
2004-09-26 Benoît Perrot <benoit(a)lrde.epita.fr>
Index: src/inst/data_section.hh
--- src/inst/data_section.hh (revision 129)
+++ src/inst/data_section.hh (revision 130)
@@ -81,14 +81,6 @@
add_byte(w / pow);
}
- void add_asciiz(const std::string* s)
- {
- for (unsigned i = 0; i < s->size (); ++i)
- add_byte((*s)[i]);
- add_byte(0);
- }
-
-
public:
int load_byte(int offset) const
{
Index: dev/inst-builder-gen.py
--- dev/inst-builder-gen.py (revision 129)
+++ dev/inst-builder-gen.py (revision 130)
@@ -73,18 +73,27 @@
}
public:
+ void add_inst_label(Label *label)
+ {
+ program_->text_section ().add_label(label);
+ }
+
void add_data_label(Label *label)
{
program_->data_section ().add_label(label);
}
- void add_inst_label(Label *label)
+
+ public:
+ void add_byte(int imm)
{
- program_->text_section ().add_label(label);
+ program_->data_section ().add_byte(imm);
}
- void add_space (int size)
+ void add_half(int imm)
{
- program_->data_section ().add_space(size);
+ // FIXME: check that imm is less than 0x10000!
+ add_byte((imm >> 8) && 0xff);
+ add_byte(imm && 0xff);
}
void add_word (int imm)
@@ -98,9 +107,20 @@
add_word (program_->data_section ().get_offset(* label));
}
+ void add_ascii(const std::string *str)
+ {
+ for (unsigned i = 0; i < str->size (); ++i)
+ program_->data_section ().add_byte((*str)[i]);
+ }
void add_asciiz (const std::string *str)
{
- program_->data_section ().add_asciiz (str);
+ add_ascii(str);
+ add_byte(0);
+ }
+
+ void add_space (int size)
+ {
+ program_->data_section ().add_space(size);
}
public:"""
Index: dev/parse-asm-scan-gen.py
--- dev/parse-asm-scan-gen.py (revision 129)
+++ dev/parse-asm-scan-gen.py (revision 130)
@@ -95,9 +95,13 @@
\".text\" return DIR_TEXT;
\".data\" return DIR_DATA;
+
+\".space\" return DIR_SPACE;
+\".byte\" return DIR_BYTE;
+\".half\" return DIR_HALF;
\".word\" return DIR_WORD;
+\".ascii\" return DIR_ASCII;
\".asciiz\" return DIR_ASCIIZ;
-\".space\" return DIR_SPACE;
"""
## Body --------------------------------
Index: dev/parse-asm-parse-gen.py
--- dev/parse-asm-parse-gen.py (revision 129)
+++ dev/parse-asm-parse-gen.py (revision 130)
@@ -92,8 +92,12 @@
%token DIR_TEXT \".text\"
%token DIR_DATA \".data\"
+
%token DIR_SPACE \".space\"
+%token DIR_BYTE \".byte\"
+%token DIR_HALF \".half\"
%token DIR_WORD \".word\"
+%token DIR_ASCII \".ascii\"
%token DIR_ASCIIZ \".asciiz\"
"""
@@ -120,14 +124,25 @@
// Label
: LABEL_DEF
{ program_builder.add_data_label($1); }
-// Reserve space
+
+// Uninitialized space
| DIR_SPACE INTEGER
{ program_builder.add_space ($2); }
+
// Values
+| DIR_BYTE INTEGER
+{ program_builder.add_byte($2); }
+
+| DIR_HALF INTEGER
+{ program_builder.add_half($2); }
+
| DIR_WORD INTEGER
{ program_builder.add_word ($2); }
| DIR_WORD LABEL
{ program_builder.add_word ($2); }
+
+| DIR_ASCII STRING
+{ program_builder.add_ascii($2); }
| DIR_ASCIIZ STRING
{ program_builder.add_asciiz ($2); }
Show replies by date