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