Commit 24ea94c9 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Index: ChangeLog

from  Benoît Perrot  <benoit@lrde.epita.fr>

	Make LabelExp independent from Label.

	* src/inst/exp.hh, src/inst/exp.cc:
	Make LabelExp aggregate a unique_string instead of a Label.
	* dev/parse-asm-scan-gen.py: Return a unique_string when 
	scanning an identifier (instead	of a Label).
	* dev/parse-asm-parse-gen.py: Update accordingly.
	* src/inst/section.hh (has_label, get_offset): Wait for a
	unique_string (instead of a Label).
	* dev/inst-builder-gen.py, dev/inst-solver-gen.py,
	* src/vm/virtual_machine.cc, src/shell/shell.cc:
	Update accordingly.
parent 80ffde06
2005-01-27 Benot Perrot <benoit@lrde.epita.fr>
Make LabelExp independent from Label.
* src/inst/exp.hh, src/inst/exp.cc:
Make LabelExp aggregate a unique_string instead of a Label.
* dev/parse-asm-scan-gen.py: Return a unique_string when
scanning an identifier (instead of a Label).
* dev/parse-asm-parse-gen.py: Update accordingly.
* src/inst/section.hh (has_label, get_offset): Wait for a
unique_string (instead of a Label).
* dev/inst-builder-gen.py, dev/inst-solver-gen.py,
* src/vm/virtual_machine.cc, src/shell/shell.cc:
Update accordingly.
2005-01-26 Benot Perrot <benoit@lrde.epita.fr>
Let concrete sections choose how to handle labels definitions.
......
......@@ -105,11 +105,11 @@ namespace inst
{
program_->data_section ().add_word (imm);
}
void add_word(Label *label)
void add_word(LabelExp *l)
{
// FIXME: use a precondition
program_->data_section ().
add_word (program_->data_section ().get_offset(* label));
add_word (program_->data_section ().get_offset(l->get_name()));
}
void add_ascii(const std::string *str)
......
......@@ -155,18 +155,18 @@ namespace inst
void
ProgramSolver::visit(LabelExp &l)
{
if (! program_->data_section().has_label(l.get_label()))
if (! program_->text_section().has_label(l.get_label()))
if (! program_->data_section().has_label(l.get_name()))
if (! program_->text_section().has_label(l.get_name()))
{
std::cerr << \"Undefined label: \" << l.get_label()
std::cerr << \"Undefined label: \" << l.get_name()
<< std::endl;
exit_set(exit_solve);
}
else
l.set_immediate(program_->text_section().
get_offset(l.get_label()) - pc_);
get_offset(l.get_name()) - pc_);
else
l.set_immediate(program_->data_section().get_offset(l.get_label()));
l.set_immediate(program_->data_section().get_offset(l.get_name()));
}
void
......
......@@ -84,7 +84,7 @@ using vm::Cpu;
#include \"parse/asm-scan.hh\"
%}
%token <label> LABEL \"label\"
%token <id> LABEL \"label\"
%token <id> LABEL_DEF \"label definition\"
%token <i> INTEGER \"integer\"
%token <s> STRING \"string\"
......@@ -155,7 +155,7 @@ data
| DIR_WORD INTEGER
{ program_builder.add_word($2); }
| DIR_WORD LABEL
{ program_builder.add_word($2); }
{ program_builder.add_word(new LabelExp(*$2)); }
| DIR_ASCII STRING
{ program_builder.add_ascii($2); }
......@@ -278,7 +278,7 @@ exp:
{ $$ = new OpExp(new IntExp(0), OpExp::sub, $2); }
| LPAREN exp RPAREN { $$ = $2; }
| INTEGER { $$ = new IntExp($1); }
| LABEL { $$ = new LabelExp($1); }
| LABEL { $$ = new LabelExp(*$1); }
%%
void
......
......@@ -145,7 +145,7 @@ print """
{id} {
yylval->label = new inst::Label (yytext);
yylval->id = &misc::unique_string::create(yytext);
return LABEL;
}
{id}\":\" {
......
......@@ -107,7 +107,7 @@ namespace inst
void
LabelExp::print(std::ostream& ostr) const
{
ostr << *label_;
ostr << *name_;
}
......
......@@ -23,8 +23,8 @@
# include "misc/contract.hh"
# include "misc/counted_ptr.hh"
# include "misc/unique_string.hh"
# include "inst/label.hh"
# include "inst/exp-visitor.hh"
namespace inst
......@@ -101,10 +101,9 @@ namespace inst
public Exp
{
public:
LabelExp(Label *label):
label_(label)
{
}
LabelExp(const misc::unique_string &name):
name_(name)
{}
virtual ~LabelExp();
public:
......@@ -112,20 +111,16 @@ namespace inst
virtual void accept (ExpVisitor& v);
public:
const Label& get_label() const
{
return *label_;
}
Label& get_label()
const misc::unique_string &get_name() const
{
return *label_;
return name_;
}
public:
virtual void print(std::ostream& ostr) const;
protected:
Label *label_;
const misc::unique_string &name_;
};
......
......@@ -56,15 +56,15 @@ namespace inst
labels_[offset].push_back(label);
}
public:
bool has_label(const Label& label) const
bool has_label(const misc::unique_string &label) const
{
label_offset_type::const_iterator it = offsets_.find(label);
label_offset_type::const_iterator it = offsets_.find(Label(label));
return it != offsets_.end();
}
int get_offset(const Label& label) const
int get_offset(const misc::unique_string &label) const
{
label_offset_type::const_iterator it = offsets_.find(label);
label_offset_type::const_iterator it = offsets_.find(Label(label));
assertion(it != offsets_.end());
return (*it).second;
}
......
......@@ -378,18 +378,23 @@ namespace shell
if (!program_)
std::cerr << "No program loaded." << std::endl;
else
if (!program_->text_section().has_label(*cmd.get_args().begin()))
std::cerr << "Label " << *cmd.get_args().begin()
<< " not found." << std::endl;
else
{
int offset =
program_->text_section().get_offset(*cmd.get_args().begin());
{
const misc::unique_string &label =
misc::unique_string::create(*cmd.get_args().begin());
std::cout << "Breakpoint " << *cmd.get_args().begin()
<< " at " << offset << " (+4)." << std::endl;
vm_.add_breakpoint(offset + 4);
}
if (!program_->text_section().has_label(label))
std::cerr << "Label " << label
<< " not found." << std::endl;
else
{
int offset =
program_->text_section().get_offset(label);
std::cout << "Breakpoint " << label
<< " at " << offset << " (+4)." << std::endl;
vm_.add_breakpoint(offset + 4);
}
}
}
void
......
......@@ -35,13 +35,14 @@ namespace vm
{
reset();
if (! program.text_section ().has_label(inst::Label("main")))
const misc::unique_string &main = misc::unique_string::create("main");
if (! program.text_section ().has_label(main))
{
std::cerr << "No `main' label in assembly file." << std::endl;
exit_set(exit_runtime);
return;
}
main_offset_ = program.text_section().get_offset(inst::Label("main"));
main_offset_ = program.text_section().get_offset(main);
mmu_.data_store(program.data_section());
mmu_.inst_store(program.text_section());
}
......
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