Commit 33caa50a authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Index: ChangeLog

from  Benoît Perrot  <benoit@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.
		
parent 58d67a3f
2004-09-26 Benot Perrot <benoit@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 Benot Perrot <benoit@lrde.epita.fr>
* src/inst/text_section.cc: Fix label search for program display.
......
......@@ -73,34 +73,54 @@ namespace inst
}
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)
void add_word(int imm)
{
program_->data_section ().add_word (imm);
}
void add_word (Label *label)
void add_word(Label *label)
{
// FIXME: use a precondition
program_->data_section ().
add_word (program_->data_section ().get_offset(* label));
}
void add_asciiz (const std::string *str)
void add_ascii(const std::string *str)
{
program_->data_section ().add_asciiz (str);
for (unsigned i = 0; i < str->size (); ++i)
program_->data_section ().add_byte((*str)[i]);
}
void add_asciiz(const std::string *str)
{
add_ascii(str);
add_byte(0);
}
void add_space (int size)
{
program_->data_section ().add_space(size);
}
public:"""
......
......@@ -92,8 +92,12 @@ using vm::Cpu;
%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,16 +124,27 @@ data
// Label
: LABEL_DEF
{ program_builder.add_data_label($1); }
// Reserve space
// Uninitialized space
| DIR_SPACE INTEGER
{ program_builder.add_space ($2); }
{ 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); }
{ program_builder.add_word($2); }
| DIR_WORD LABEL
{ program_builder.add_word ($2); }
{ program_builder.add_word($2); }
| DIR_ASCII STRING
{ program_builder.add_ascii($2); }
| DIR_ASCIIZ STRING
{ program_builder.add_asciiz ($2); }
{ program_builder.add_asciiz($2); }
// Instruction definitions
instructions
......
......@@ -95,9 +95,13 @@ label [a-zA-Z_][a-zA-Z_0-9]*
\".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 --------------------------------
......
......@@ -80,14 +80,6 @@ namespace inst
for (int i = 0; i < 4; ++i, pow /= 256)
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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment