Commit 58ab9449 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

2005-01-29 Benoît Perrot <benoit@lrde.epita.fr>

	Make Label compose its associated offset.

	* src/inst/label.hh: Protect default constructor. Compose its
	associated offset. Add a constructor that waits for it.
	* src/inst/section.hh (has_label, get_offset): Update accordingly.
	(register_label): Wait for a Label only and use it to get its offset.
	* src/inst/data_section.hh: Update accordingly.
	* src/inst/text_label.hh: New.
	* src/inst/Makefile.am: Update accordingly.
	* src/inst/text_section.hh: Create TextLabels instead of Labels.
	* src/inst/text_section.cc: Include inst.hh to gain access
	to Inst's interface.
parent 24ea94c9
2005-01-29 Benot Perrot <benoit@lrde.epita.fr>
Make Label compose its associated offset.
* src/inst/label.hh: Protect default constructor. Compose its
associated offset. Add a constructor that waits for it.
* src/inst/section.hh (has_label, get_offset): Update accordingly.
(register_label): Wait for a Label only and use it to get its offset.
* src/inst/data_section.hh: Update accordingly.
* src/inst/text_label.hh: New.
* src/inst/Makefile.am: Update accordingly.
* src/inst/text_section.hh: Create TextLabels instead of Labels.
* src/inst/text_section.cc: Include inst.hh to gain access
to Inst's interface.
2005-01-27 Benot Perrot <benoit@lrde.epita.fr>
Make LabelExp independent from Label.
......
......@@ -50,6 +50,7 @@ libinst_a_SOURCES = \
inst.hh \
program.hh \
label.hh label.cc \
text_label.hh \
section.hh \
text_section.hh text_section.cc \
data_section.hh data_section.cc \
......
......@@ -56,7 +56,7 @@ namespace inst
public:
void define_label(const misc::unique_string &id)
{
Section::register_label(new inst::Label(id), size_);
Section::register_label(new inst::Label(id, size_));
}
public:
......
......@@ -30,16 +30,24 @@ namespace inst
class Label
{
public:
protected:
Label(const std::string &s):
ustr_(misc::unique_string::create(s))
{}
public:
Label(const std::string &s, int offset):
ustr_(misc::unique_string::create(s)), offset_(offset)
{}
public:
const std::string &get_name() const
{
return *ustr_;
}
int get_offset() const
{
return offset_;
}
public:
bool operator==(const Label &rhs) const
......@@ -55,8 +63,9 @@ namespace inst
return ustr_ < rhs.ustr_;
}
private:
const misc::unique_string ustr_;
protected:
const misc::unique_string &ustr_;
int offset_;
};
inline std::ostream&
......
......@@ -49,22 +49,22 @@ namespace inst
{}
protected:
void register_label(Label *label, int offset)
void register_label(Label *label)
{
// FIXME: check that this label has not already been added.
offsets_[*label] = offset;
labels_[offset].push_back(label);
offsets_[*label] = label->get_offset();
labels_[label->get_offset()].push_back(label);
}
public:
bool has_label(const misc::unique_string &label) const
{
label_offset_type::const_iterator it = offsets_.find(Label(label));
label_offset_type::const_iterator it = offsets_.find(Label(label, 0));
return it != offsets_.end();
}
int get_offset(const misc::unique_string &label) const
{
label_offset_type::const_iterator it = offsets_.find(Label(label));
label_offset_type::const_iterator it = offsets_.find(Label(label, 0));
assertion(it != offsets_.end());
return (*it).second;
}
......
//
// This file is part of Nolimips, a MIPS simulator with unlimited registers
// Copyright (C) 2003, 2004 Benoit Perrot <benoit@lrde.epita.fr>
//
// Nolimips is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Nolimips is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#ifndef INST_TEXT_LABEL_HH
# define INST_TEXT_LABEL_HH
# include "inst/label.hh"
namespace inst
{
class TextLabel:
public Label
{
public:
TextLabel(const std::string &s):
Label(s)
{}
public:
void set_offset(int offset)
{
offset_ = offset;
}
};
} // namespace inst
#endif // !INST_TEXT_LABEL_HH
......@@ -17,6 +17,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "inst/text_section.hh"
#include "inst/inst.hh"
namespace inst
{
......
......@@ -25,11 +25,13 @@
# include "misc/contract.hh"
# include "inst/section.hh"
# include "inst/inst.hh"
# include "inst/text_label.hh"
namespace inst
{
class Inst;
/// Implement an assembly text (code) section
class TextSection:
public Section
......@@ -56,7 +58,9 @@ namespace inst
public:
void define_label(const misc::unique_string &id)
{
Section::register_label(new inst::Label(id), insts_.size() * 4);
TextLabel *label = new TextLabel(id);
label->set_offset(insts_.size() * 4);
Section::register_label(label);
}
public:
......
Markdown is supported
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