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,18 +46,17 @@ namespace inst
void
DataSection::print(std::ostream& ostr) const
{
if (size_ == 0)
return;
if (0 < size())
{
ostr << "\t" << name_ << std::endl;
std::vector<const Label*>::const_iterator label_it = labels_.begin();
int next_labeled_offset = size_;
int next_labeled_offset = size();
if (!labels_.empty())
next_labeled_offset = (*label_it)->get_offset();
for (int i = 0; i < size_; ++i)
for (int i = 0; i < size(); ++i)
{
while (i == next_labeled_offset)
{
......@@ -84,5 +83,6 @@ namespace inst
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,36 +38,30 @@ 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);
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)
{
// FIXME: check b in byte range
precondition(size_ < INST_DATA_DATASIZE);
bytes_[size_] = b;
++size_;
bytes_.push_back(b);
}
void add_word(int w)
......@@ -81,10 +72,10 @@ namespace inst
}
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];
}
......@@ -94,8 +85,7 @@ namespace inst
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