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

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

	* src/inst/data_section.hh, src/inst/data_section.cc,
	* src/inst/text_section.hh, src/inst/text_section.cc:
	Maintain a list of encountered (not sorted) labels. Use it to 
	print the content of the sections.
	* src/inst/section.hh: Remove deprecated attributes.
	* src/inst/text_label.hh (get_iterator): Constify return value.
parent 72081162
2005-02-03 Benoît Perrot <benoit@lrde.epita.fr>
* src/inst/data_section.hh, src/inst/data_section.cc,
* src/inst/text_section.hh, src/inst/text_section.cc:
Maintain a list of encountered (not sorted) labels. Use it to
print the content of the sections.
* src/inst/section.hh: Remove deprecated attributes.
* src/inst/text_label.hh (get_iterator): Constify return value.
2005-02-03 Benoît Perrot <benoit@lrde.epita.fr>
* src/inst/section.hh: Store the labels in a set. Use Labels to get
......
//
// This file is part of Nolimips, a MIPS simulator with unlimited registers
// Copyright (C) 2003, 2004 Benoit Perrot <benoit@lrde.epita.fr>
// Copyright (C) 2003, 2004, 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
......@@ -28,6 +28,17 @@ namespace inst
DataSection::~DataSection()
{}
// --------------------------------------------------------------------------
void
DataSection::define_label(const misc::unique_string &id)
{
Label *label = new inst::Label(id, size_);
labels_.push_back(label);
Section::register_label(label);
}
// --------------------------------------------------------------------------
// Print operator
// --------------------------------------------------------------------------
......@@ -40,19 +51,37 @@ namespace inst
ostr << "\t" << name_ << std::endl;
int i = 0;
while (i < size_)
std::vector<const Label*>::const_iterator label_it = labels_.begin();
int next_labeled_offset = size_;
if (!labels_.empty())
next_labeled_offset = (*label_it)->get_offset();
for (int i = 0; i < size_; ++i)
{
while (i == next_labeled_offset)
{
ostr << *(*label_it) << ':' << std::endl;
++label_it;
if (label_it != labels_.end())
next_labeled_offset = (*label_it)->get_offset();
else // No more labels
break;
}
ostr << "\t.byte\t0x"
<< std::hex << static_cast<unsigned>(bytes_[i])
<< std::endl;
}
// Print labels that point right after the last data
while (label_it != labels_.end())
{
std::map<int, label_list_type>::const_iterator it = labels_.find(i);
if (it != labels_.end())
for (label_list_type::const_iterator l = (*it).second.begin();
l != (*it).second.end(); ++l)
ostr << *(*l) << ':' << std::endl;
ostr << "\t.byte\t0x"
<< std::hex << static_cast<unsigned>(bytes_[i++])
<< std::endl;
ostr << *(*label_it) << ':' << std::endl;
++label_it;
}
ostr << std::dec;
}
......
//
// This file is part of Nolimips, a MIPS simulator with unlimited registers
// Copyright (C) 2003, 2004 Benoit Perrot <benoit@lrde.epita.fr>
// Copyright (C) 2003, 2004, 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
......@@ -24,6 +24,7 @@
# include <stdint.h>
# include <iostream>
# include <vector>
# include "inst/section.hh"
# include "inst/inst.hh"
......@@ -54,10 +55,7 @@ namespace inst
}
public:
void define_label(const misc::unique_string &id)
{
Section::register_label(new inst::Label(id, size_));
}
void define_label(const misc::unique_string &id);
public:
void add_space(int space_size)
......@@ -94,6 +92,8 @@ namespace inst
virtual void print(std::ostream& ostr) const;
protected:
std::vector<const Label*> labels_;
int size_;
uint8_t bytes_[INST_DATA_DATASIZE];
};
......
......@@ -19,8 +19,7 @@
#ifndef INST_SECTION_HH
# define INST_SECTION_HH
# include <list>
# include <map>
# include <set>
# include "misc/contract.hh"
# include "misc/unique_string.hh"
......@@ -34,12 +33,8 @@ namespace inst
class Section
{
protected:
typedef std::list<const Label*> label_list_type;
typedef std::set<const Label*, Label::deref_ptr_less> label_set_type;
public:
typedef std::map<int, label_list_type> offset_label_type;
public:
/// Construct an abstract section `\a name'
Section(const std::string &name):
......@@ -53,8 +48,6 @@ namespace inst
{
// FIXME: check that this label has not already been added.
sorted_labels_.insert(label);
labels_[label->get_offset()].push_back(label);
}
public:
bool has_label(const misc::unique_string &label) const
......@@ -80,9 +73,6 @@ namespace inst
const misc::unique_string &name_;
label_set_type sorted_labels_;
// FIXME: Might be static, to avoid multi-definition of labels.
offset_label_type labels_;
};
inline std::ostream&
......
......@@ -40,7 +40,7 @@ namespace inst
offset_ = offset;
}
TextSection::instruction_list_type::iterator get_iterator() const
const TextSection::instruction_list_type::iterator &get_iterator() const
{
return it_;
}
......
......@@ -41,6 +41,8 @@ namespace inst
{
TextLabel *label = new TextLabel(id, sentry_);
label->set_offset((insts_.size() - 1) * 4);
labels_.push_back(label);
Section::register_label(label);
}
......@@ -53,18 +55,35 @@ namespace inst
{
ostr << "\t" << name_ << std::endl;
unsigned i = 0;
//
std::vector<const TextLabel*>::const_iterator label_it = labels_.begin();
instruction_list_type::const_iterator next_labeled_it = end();
if (!labels_.empty())
next_labeled_it = (*label_it)->get_iterator();
for (instruction_list_type::const_iterator
inst_it = begin(); inst_it != end(); ++inst_it, ++i)
inst_it = begin(); inst_it != end(); ++inst_it)
{
std::map<int, label_list_type>::const_iterator it =
labels_.find(i * 4);
if (it != labels_.end())
for (label_list_type::const_iterator l = (*it).second.begin();
l != (*it).second.end(); ++l)
ostr << *(*l) << ':' << std::endl;
while (inst_it == next_labeled_it)
{
ostr << *(*label_it) << ':' << std::endl;
++label_it;
if (label_it != labels_.end())
next_labeled_it = (*label_it)->get_iterator();
else // No more labels
break;
}
ostr << '\t' << *(*inst_it) << std::endl;
}
ostr << '\t' << (*inst_it) << std::endl;
// Print labels that point right after the last instruction
while (label_it != labels_.end())
{
ostr << *(*label_it) << ':' << std::endl;
++label_it;
}
}
......
......@@ -19,6 +19,7 @@
#ifndef INST_TEXT_SECTION_HH
# define INST_TEXT_SECTION_HH
# include <list>
# include <vector>
# include <iostream>
......@@ -74,6 +75,8 @@ namespace inst
virtual void print(std::ostream& ostr) const;
protected:
std::vector<const TextLabel*> labels_;
instruction_list_type insts_;
instruction_list_type::iterator sentry_;
};
......
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