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

2005-04-15 Benoît Perrot <benoit@lrde.epita.fr>

	Remove size limitation of data sections.
	
	* src/inst/data_section.hh, src/inst/data_section.cc:
	Prefer std::vector to int* (shame on me).
parent dddbcfb9
2005-04-15 Benoît Perrot <benoit@lrde.epita.fr>
Remove size limitation of data sections.
* src/inst/data_section.hh, src/inst/data_section.cc:
Prefer std::vector to int* (shame on me).
2005-04-02 Benoît Perrot <benoit@lrde.epita.fr>
Introduce `lockable' facility.
......@@ -25,7 +32,7 @@
2005-04-02 Benoît Perrot <benoit@lrde.epita.fr>
Fix distcheck broken since 2005-03-08's patch.
Fix distcheck broken since 2005-03-08's patch (shame on me).
* src/vm/Makefile.am: Do not distribute `table.hh' from here, but...
* src/misc/Makefile.am: From here.
......
......@@ -33,7 +33,7 @@ namespace inst
void
DataSection::define_label(const misc::unique_string &id)
{
Label *label = new inst::Label(id, size_);
Label *label = new inst::Label(id, size());
labels_.push_back(label);
Section::register_label(label);
......@@ -46,43 +46,43 @@ namespace inst
void
DataSection::print(std::ostream& ostr) const
{
if (size_ == 0)
return;
ostr << "\t" << name_ << std::endl;
if (0 < size())
{
ostr << "\t" << name_ << std::endl;
std::vector<const Label*>::const_iterator label_it = labels_.begin();
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();
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)
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())
{
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())
{
ostr << *(*label_it) << ':' << std::endl;
++label_it;
ostr << std::dec;
}
ostr << std::dec;
}
} // namespace inst
......@@ -29,9 +29,6 @@
# include "inst/section.hh"
# include "inst/inst.hh"
// FIXME: should not be a #define !
# define INST_DATA_DATASIZE 128 * 1024
namespace inst
{
......@@ -41,61 +38,54 @@ namespace inst
{
public:
DataSection(const std::string &name = ".data"):
Section(name),
size_(0)
{
std::memset(bytes_, 0, INST_DATA_DATASIZE);
}
Section(name)
{}
virtual ~DataSection();
public:
int size () const
int size() const
{
return size_;
return bytes_.size();
}
public:
void define_label(const misc::unique_string &id);
void define_label(const misc::unique_string &id);
public:
void add_space(int space_size)
void add_space(unsigned space_size)
{
// FIXME: check b in byte range
precondition(size_ + space_size < INST_DATA_DATASIZE);
size_ += space_size;
for (unsigned i = 0; i < space_size; ++i)
bytes_.push_back(0);
}
void add_byte(int b)
void add_byte(int b)
{
// FIXME: check b in byte range
precondition(size_ < INST_DATA_DATASIZE);
bytes_[size_] = b;
++size_;
bytes_.push_back(b);
}
void add_word(int w)
void add_word(int w)
{
unsigned pow = 256 * 256 * 256;
unsigned pow = 256 * 256 * 256;
for (int i = 0; i < 4; ++i, pow /= 256)
add_byte(w / pow);
}
public:
int load_byte(int offset) const
int load_byte(unsigned offset) const
{
precondition ((0 <= offset && offset < size_));
return (int8_t)bytes_[offset];
precondition(offset < bytes_.size());
return (int8_t) bytes_[offset];
}
public:
virtual void print(std::ostream& ostr) const;
virtual void print(std::ostream& ostr) const;
protected:
std::vector<const Label*> labels_;
int size_;
uint8_t bytes_[INST_DATA_DATASIZE];
std::vector<uint8_t> bytes_;
};
} // namespace inst
......
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