91 template<
class I> Image<I> *Image<I>::Build(Timestamp timestamp, uint32 map_size, uint32 code_size, uint32 names_size) {
93 I *image =
new(map_size + code_size) I(timestamp, map_size, code_size, names_size);
94 return (Image<I> *)image;
97 template<
class I> Image<I> *Image<I>::Read(std::ifstream &stream) {
103 stream.read((
char *)×tamp,
sizeof(uint64));
104 stream.read((
char *)&map_size,
sizeof(uint32));
105 stream.read((
char *)&code_size,
sizeof(uint32));
106 stream.read((
char *)&names_size,
sizeof(uint32));
107 Image *image = Build(timestamp, map_size, code_size, names_size);
108 stream.read((
char *)image->data(), image->get_size() *
sizeof(word32));
112 template<
class I>
void Image<I>::Write(Image<I> *image, std::ofstream &stream) {
114 Timestamp timestamp = image->timestamp();
115 uint32 map_size = image->map_size();
116 uint32 code_size = image->code_size();
117 uint32 names_size = image->names_size();
118 stream.write((
char *)×tamp,
sizeof(uint64));
119 stream.write((
char *)&map_size,
sizeof(uint32));
120 stream.write((
char *)&code_size,
sizeof(uint32));
121 stream.write((
char *)&names_size,
sizeof(uint32));
122 stream.write((
char *)image->data(), image->get_size() *
sizeof(word32));
125 template<
class I> Image<I>::Image() : I() {
128 template<
class I> Image<I>::~Image() {
131 template<
class I> uint32 Image<I>::get_size()
const {
133 return map_size() + code_size() + names_size();
136 template<
class I> uint32 Image<I>::getObjectCount()
const {
141 template<
class I> word32 *Image<I>::get_object(uint32 i) {
143 return data() + data(i);
146 template<
class I> word32 *Image<I>::getCodeSegment() {
148 return data() + map_size();
151 template<
class I> uint32 Image<I>::getCodeSegmentSize()
const {
156 template<
class I>
void Image<I>::trace()
const {
158 std::cout <<
"---Image---\n";
159 std::cout <<
"Size: " << get_size() << std::endl;
160 std::cout <<
"Object Map Size: " << map_size() << std::endl;
161 std::cout <<
"Code Segment Size: " << code_size() << std::endl;
162 std::cout <<
"Names Size: " << names_size() << std::endl;
166 std::cout <<
"===Object Map===" << std::endl;
167 for (; i < map_size(); ++i)
168 std::cout << i <<
" " << data(i) << std::endl;
171 std::cout <<
"===Code Segment===" << std::endl;
172 uint32 code_start = map_size();
173 for (uint32 j = 0; j < code_start; ++j) {
175 uint32 object_axiom = data(data(j));
176 uint32 object_code_size = data(data(j) + 1);
177 uint32 object_reference_set_size = data(data(j) + 2);
178 uint32 object_marker_set_size = data(data(j) + 3);
179 uint32 object_view_set_size = data(data(j) + 4);
180 std::cout <<
"---object---\n";
182 std::cout << i++ <<
" code size: " << object_code_size << std::endl;
183 std::cout << i++ <<
" reference set size: " << object_reference_set_size << std::endl;
184 std::cout << i++ <<
" marker set size: " << object_marker_set_size << std::endl;
185 std::cout << i++ <<
" view set size: " << object_view_set_size << std::endl;
187 std::cout <<
"---code---\n";
188 for (; i < data(j) + 5 + object_code_size; ++i) {
190 std::cout << i <<
" ";
191 ((Atom *)&data(i))->trace();
192 std::cout << std::endl;
195 std::cout <<
"---reference set---\n";
196 for (; i < data(j) + 5 + object_code_size + object_reference_set_size; ++i)
197 std::cout << i <<
" " << data(i) << std::endl;
199 std::cout <<
"---marker set---\n";
200 for (; i < data(j) + 5 + object_code_size + object_reference_set_size + object_marker_set_size; ++i)
201 std::cout << i <<
" " << data(i) << std::endl;
203 std::cout <<
"---view set---\n";
204 for (uint32 k = 0; k < object_view_set_size; ++k) {
206 uint32 view_code_size = data(i);
207 uint32 view_reference_set_size = data(i + 1);
209 std::cout <<
"view[" << k <<
"]\n";
210 std::cout << i++ <<
" code size: " << view_code_size << std::endl;
211 std::cout << i++ <<
" reference set size: " << view_reference_set_size << std::endl;
213 std::cout <<
"---code---\n";
215 for (l = 0; l < view_code_size; ++i, ++l) {
217 std::cout << i <<
" ";
218 ((Atom *)&data(i))->trace();
219 std::cout << std::endl;
222 std::cout <<
"---reference set---\n";
223 for (l = 0; l < view_reference_set_size; ++i, ++l)
224 std::cout << i <<
" " << data(i) << std::endl;