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