Commit c87d6b9a authored by Benoit Perrot's avatar Benoit Perrot
Browse files

2005-09-03 Benoît Perrot <benoit@lrde.epita.fr>

	Detect several definitions of the same label in a section.

	* src/inst/section.hh (register_label):
	Return false when label is already known in the section, true
	otherwise. Move implementation to...
	* src/inst/section.cc, src/inst/Makefile.am:
	This new file.
	* src/inst/data_section.hh, src/inst/data_section.cc,
	* src/inst/text_section.hh, src/inst/text_section.cc (define_label):
	Propagate status of register_label.
	* src/inst/program_builder.hh.gen.py:
	Generate an error when a label is defined more than once.
	* tests/solve/data-label-already-defined.s,
	* tests/solve/text-label-already-defined.s,
	* tests/solve/Makefile.am:
	Test it.
parent cca2f866
2005-09-03 Benot Perrot <benoit@lrde.epita.fr>
Detect several definitions of the same label in a section.
* src/inst/section.hh (register_label):
Return false when label is already known in the section, true
otherwise. Move implementation to...
* src/inst/section.cc, src/inst/Makefile.am:
This new file.
* src/inst/data_section.hh, src/inst/data_section.cc,
* src/inst/text_section.hh, src/inst/text_section.cc (define_label):
Propagate status of register_label.
* src/inst/program_builder.hh.gen.py:
Generate an error when a label is defined more than once.
* tests/solve/data-label-already-defined.s,
* tests/solve/text-label-already-defined.s,
* tests/solve/Makefile.am:
Test it.
2005-09-03 Benot Perrot <benoit@lrde.epita.fr>
* src/misc/unique_string.hh, src/misc/unique_string.cc:
......
......@@ -58,7 +58,7 @@ libinst_a_SOURCES = \
program.hh \
label.hh label.cc \
text_label.hh \
section.hh \
section.hh section.cc \
text_section.hh text_section.cc \
data_section.hh data_section.cc \
program.hh \
......
......@@ -30,13 +30,13 @@ namespace inst
// --------------------------------------------------------------------------
void
bool
DataSection::define_label(const misc::unique_string &id)
{
Label *label = new inst::Label(id, size());
labels_.push_back(label);
Section::register_label(label);
return Section::register_label(label);
}
// --------------------------------------------------------------------------
......
......@@ -49,7 +49,7 @@ namespace inst
}
public:
void define_label(const misc::unique_string &id);
bool define_label(const misc::unique_string &id);
public:
void add_space(unsigned space_size)
......
......@@ -85,14 +85,24 @@ namespace inst
}
public:
void define_inst_label(const misc::unique_string &id)
void define_inst_label(const misc::unique_string &id)
{
program_->text_section ().define_label(id);
if (!program_->text_section ().define_label(id))
{
std::cerr << \"Instruction label already defined in this section.\"
<< std::endl;
exit_set(exit_solve);
}
}
void define_data_label(const misc::unique_string &id)
void define_data_label(const misc::unique_string &id)
{
program_->data_section ().define_label(id);
if (!program_->data_section ().define_label(id))
{
std::cerr << \"Data label already defined in this section.\"
<< std::endl;
exit_set(exit_solve);
}
}
public:
......
//
// This file is part of Nolimips, a MIPS simulator with unlimited registers
// Copyright (C) 2005 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
//
#include "inst/section.hh"
namespace inst
{
Section::~Section()
{
// for (label_set_type::iterator
// it = sorted_labels_.begin(); it != sorted_labels_.end(); ++it)
// delete *it;
}
bool
Section::register_label(Label *label)
{
label_set_type::const_iterator it(sorted_labels_.find(label));
if (it == sorted_labels_.end()
|| *(*it) < *label)
{
it = sorted_labels_.insert(it, label);
return true;
}
return false;
}
} // namespace inst
......@@ -40,15 +40,13 @@ namespace inst
Section(const std::string &name):
name_(name)
{}
virtual ~Section()
{}
virtual ~Section();
protected:
void register_label(Label *label)
{
// FIXME: check that this label has not already been added.
sorted_labels_.insert(label);
}
/** Return false if the label already exists in this section, true
otherwise */
bool register_label(Label *label);
public:
bool has_label(const misc::unique_string &label) const
{
......
......@@ -36,14 +36,14 @@ namespace inst
// --------------------------------------------------------------------------
void
bool
TextSection::define_label(const misc::unique_string &id)
{
TextLabel *label = new TextLabel(id, sentry_);
label->set_offset((insts_.size() - 1) * 4);
labels_.push_back(label);
Section::register_label(label);
return Section::register_label(label);
}
// --------------------------------------------------------------------------
......
......@@ -60,10 +60,10 @@ namespace inst
}
public:
void define_label(const misc::unique_string &id);
bool define_label(const misc::unique_string &id);
public:
void add_inst(inst::Inst* inst)
void add_inst(inst::Inst* inst)
{
(*sentry_) = inst;
......
### Sources
ASM_FILES = \
undefined-labels.s \
unlimited-regs.s
unlimited-regs.s \
data-label-already-defined.s \
text-label-already-defined.s
dist_noinst_DATA = $(ASM_FILES)
......
.data
foo:
.asciiz "bar"
foo:
.asciiz "baz"
.text
main:
li $a0, 0
li $v0, 10
syscall
.text
main:
li $a0, 0
foo:
li $v0, 10
foo:
syscall
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