Debian Codegraph @

media_softlet/agnostic/common/vp/hal/utils/vp_visa.h

raw
1 /*
2 * Copyright (c) 2022, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file vp_visa.h
24 //! \brief Contains Class ISAfile definitions
25 //!
26
27 #ifndef __VP_VISA_H__
28 #define __VP_VISA_H__
29
30 #include <cstdint>
31 #include <cstring>
32 #include <vector>
33 #include <array>
34 #include "media_class_trace.h"
35
36 namespace vp
37 {
38 namespace vISA
39 {
40 enum Datatype { ONE, TWO, FOUR, EIGHT, VARCHAR, VARCHAR_POOL, GDATA, STRUCT, REMOVED };
41
42 //!
43 //! \brief Field Struct.
44 //! \details This struct represents any field from the ISA file.
45 //! Fields are tagged according their data size in bytes (1 to 8 bytes).
46 //! Regular strings are tagged as VARCHAR and strings from the String
47 //! Pool as VARCHAR_POOL.
48 //!
49 struct Field {
50 Datatype type = ONE;
51 uint8_t countField = 0;
52 uint32_t size = 0;
53 union {
54 int8_t number8;
55 int16_t number16;
56 int32_t number32;
57 int64_t number64;
58 int8_t ui8[8];
59 char *varchar;
60 const uint8_t *gdata;
61 };
62
63 //!
64 //! \brief Constructor of Field struct.
65 //!
66 Field() : countField(0), number64(0) {}
67
68 //!
69 //! \brief Constructor of Field struct.
70 //!
71 Field(Datatype t) : type(t), countField(0), number64(0) {}
72
73 //!
74 //! \brief Constructor of Field struct.
75 //!
76 Field(Datatype t, uint8_t cf) : type(t), countField(cf), number64(0) {}
77
78 //!
79 //! \brief Destructor of Field struct.
80 //!
81 ~Field() {
82 if (type == Datatype::VARCHAR || type == Datatype::VARCHAR_POOL)
83 delete[] varchar;
84 else if (type == Datatype::GDATA)
85 delete[] gdata;
86 }
87 };
88
89 class Header;
90 class KernelBody;
91 class FunctionBody;
92
93 //!
94 //! \brief ISAfile Class.
95 //! \details This class provides the functionality to manage ISA files: read
96 //! parse and write ISA files. Access to Header, Kernels and
97 //! Functions is also provided.
98 //! It supports from vISA 3.4.
99 //!
100 class ISAfile
101 {
102 private:
103 unsigned version = 0;
104 const uint8_t *data = nullptr;
105 const uint8_t *end = nullptr;
106 unsigned size = 0;
107 const char *error = nullptr;
108 unsigned errorIndex = 0;
109 Header *header = nullptr;
110 bool kernel_data_loaded = false;
111 bool function_data_loaded = false;
112 std::vector<KernelBody*> kernel_data;
113 std::vector<FunctionBody*> function_data;
114
115 //!
116 //! \brief Reads and parses the Header from ISA file.
117 //! \retval True if sucessfully parsers the header.
118 //! False otherwise.
119 //!
120 bool loadHeader();
121
122 //!
123 //! \brief Reads and parses the kernels from ISA file.
124 //! \retval True if sucessfully parsers all the kernels.
125 //! False otherwise.
126 //!
127 bool loadKernelData();
128
129 //!
130 //! \brief Reads and parses the functions from ISA file.
131 //! \retval True if sucessfully parsers all the functions.
132 //! False otherwise.
133 //!
134 bool loadFunctionData();
135 public:
136 //!
137 //! \brief Constructor of ISAfile class.
138 //! \param [in] data.
139 //! Pointer to buffer data from ISA file.
140 //! \param [in] size.
141 //! Size of ISA file buffer.
142 //!
143 ISAfile(const uint8_t *data, unsigned size);
144
145 //!
146 //! \brief Copy Constructor of ISAfile class.
147 //! \param [in] other.
148 //! Reference to object to copy.
149 //!
150 ISAfile(const ISAfile& other);
151
152 //!
153 //! \brief Assignment operator.
154 //! \param [in] other.
155 //! Reference to object to copy.
156 //!
157 ISAfile& operator= (const ISAfile& other);
158
159 //!
160 //! \brief Destructor of ISAfile class.
161 //!
162 ~ISAfile();
163
164 //!
165 //! \brief Reads the ISA file.
166 //! \retval True if it reads successfully.
167 //!
168 bool readFile();
169
170 //!
171 //! \brief Returns the Header object.
172 //! \retval The pointer to Header object.
173 //!
174 Header *getHeader() { return header; }
175
176 //!
177 //! \brief Returns the vector of kernels.
178 //! \retval The reference to the vector with the kernels.
179 //!
180 std::vector<KernelBody*> &getKernelsData();
181
182 //!
183 //! \brief Returns the vector of functions.
184 //! \retval The reference to the vector with the functions.
185 //!
186 std::vector<FunctionBody*> &getFunctionsData();
187
188 //!
189 //! \brief Reads a value from buffer and assigns to field.
190 //! \param [in] p.
191 //! Pointer to buffer data from ISA file.
192 //! \param [in] buffEnd.
193 //! Pointer to the end of buffer data from ISA file.
194 //! \param [out] field.
195 //! Reference to field.
196 //! \param [in] size.
197 //! Size of the value to be read.
198 //! \retval The pointer to buffer after reading the value.
199 //!
200 const uint8_t* readField(const uint8_t *p, const uint8_t *buffEnd, Field &field, unsigned size);
201
202 //!
203 //! \brief Returns the error message.
204 //! \retval The pointer to string with the error message.
205 //!
206 const char *getError() { return error; }
207
208 //!
209 //! \brief Returns the error index.
210 //! \retval The index to the error.
211 //!
212 unsigned getErrorOffset() { return errorIndex; }
213
214 //!
215 //! \brief Sets the error message.
216 //! \param [int] e.
217 //! Error message.
218 //! \param [in] index.
219 //! Index to the error.
220 //!
221 const uint8_t *setError(const char * e, unsigned index);
222
223 //!
224 //! \brief Returns the vISA version of current file.
225 //! \retval The vISA version as integer.
226 //!
227 unsigned getCurrentVISAVersion() { return version; }
228
229 //!
230 //! \brief Sets the ISA file version
231 //! \param The ISA file version
232 //!
233 void setCurrentVISAVersion(unsigned v) { version = v; }
234
235 //!
236 //! \brief Writes a new ISA file with the current information in this class.
237 //! \param [in] filename.
238 //! String with the file name.
239 //! \param [in] originalBuffer.
240 //! Buffer data of the original ISA file.
241 //! \retval True if successfully writes the ISA file.
242 //!
243 bool writeToFile(const char *filename, std::vector<uint8_t> &originalBuffer);
244
245 //!
246 //! \brief Adds the value from a field to buffer.
247 //! This function is called when writing a ISA file.
248 //! \param [in] field.
249 //! The field to get its value.
250 //! \param [out] buffer.
251 //! Buffer data where the field's field is added.
252 //!
253 void addToBuffer(Field &field, std::vector<char> &buffer);
254
255 MEDIA_CLASS_DEFINE_END(vp__vISA__ISAfile)
256 };
257
258 //!
259 //! \brief AttributeInfo Class.
260 //! \details This class represents the AttributeInfo from vISA Object Format.
261 //! Provides getters, setters for its fields and structs as well as
262 //! functions to read/write it from/to file.
263 //!
264 class AttributeInfo {
265 public:
266 std::array<Field, 3> fields = std::array<Field, 3>
267 {
268 Field(Datatype::FOUR), // name
269 Field(Datatype::ONE), // size
270 Field(Datatype::GDATA, 1) // value
271 };
272
273 //!
274 //! \brief Constructor of AttributeInfo class.
275 //! \param [in] version.
276 //! Version of current ISA file.
277 //!
278 AttributeInfo(unsigned version) {
279 if (version <= 303) setVersion303();
280 }
281
282 //!
283 //! \brief Constructor of AttributeInfo class.
284 //!
285 AttributeInfo() { }
286
287 //!
288 //! \brief Destructor of AttributeInfo class.
289 //!
290 ~AttributeInfo() {
291 }
292
293 //!
294 //! \brief Returns the integer value of the Name field.
295 //! \details Name field is at index 0 in the internal
296 //! array of Fields.
297 //! \retval An integer.
298 //!
299 uint32_t getName() {
300 return (uint32_t)fields[0].number32;
301 }
302
303 //!
304 //! \brief Sets the integer value of the Name field.
305 //! \details Name field is at index 0 in the internal
306 //! array of Fields.
307 //! \param [in] value.
308 //! Integer be assigned.
309 //!
310 void setName(uint32_t value) {
311 fields[0].number32 = value;
312 }
313
314 //!
315 //! \brief Returns the integer value of the Size field.
316 //! \details Size field is at index 1 in the internal
317 //! array of Fields.
318 //! \retval An integer.
319 //!
320 uint8_t getSize() {
321 return (uint8_t)fields[1].number8;
322 }
323
324 //!
325 //! \brief Sets the integer value of the Size field.
326 //! \details Size field is at index 1 in the internal
327 //! array of Fields.
328 //! \param [in] value.
329 //! Integer be assigned.
330 //!
331 void setSize(uint8_t value) {
332 fields[1].number8 = value;
333 }
334
335 //!
336 //! \brief Returns the pointer to buffer data from Value field.
337 //! \details Value field is at index 2 in the internal
338 //! array of Fields.
339 //! \retval A pointer to buffer data (const uint8_t*).
340 //!
341 const uint8_t* getValue() {
342 return fields[2].gdata;
343 }
344
345 //!
346 //! \brief Sets the pointer to buffer data of the Value field.
347 //! \details Value field is at index 2 in the internal
348 //! array of Fields.
349 //! \param [in] value.
350 //! Pointer to buffer data (uint8_t*) to be assigned.
351 //!
352 void setValue(uint8_t * value) {
353 fields[2].gdata = value;
354 }
355
356 //!
357 //! \brief Parses one AttributeInfo object from ISA file.
358 //! \details Reads and parses all the fields of the AttributeInfo object
359 //! from the file buffer and returns the pointer immediately
360 //! after all this data.
361 //! If this class contains internal structs, their Parse
362 //! functions are called when corresponding.
363 //! \param [in] p.
364 //! Pointer to file buffer to start reading.
365 //! \param [in] end.
366 //! Pointer to end of file buffer.
367 //! \param [in] m.
368 //! Pointer ISAfile object.
369 //! \retval Pointer to file buffe after parsing one AttributeInfo object.
370 //!
371 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
372 unsigned i = 0;
373 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
374 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
375 if (!p) return m->setError("bad offset/size for AttributeInfo's field", i);
376 i++;
377 }
378 return p;
379 }
380
381 //!
382 //! \brief Adds all the AttributeInfo's fields to a buffer.
383 //! \details Every field from this class is added to a buffer
384 //! in order to be written into an ISA file afterwards
385 //! If this class contains other internal structus, their addToBuffer
386 //! functions are called when corresponding.
387 //! \param [out] buffer.
388 //! The buffer where the fields data will be added.
389 //! \param [in] m.
390 //! Pointer to ISAfile object.
391 //!
392 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
393 unsigned i = 0;
394 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
395 m->addToBuffer(fields[i], buffer);
396 i++;
397 }
398 }
399
400 //!
401 //! \brief Makes the changes needed to support 303 version's AttributeInfo.
402 //! \details This function is called when the current ISA file has the 303 version.
403 //! Initially all the objects are created with last version's format, so
404 //! in order to suppport previous versions, changes of datatypes and insertion/removal
405 //! of fields can be needed.
406 //!
407 void setVersion303() {
408 fields[0] = Datatype::TWO;
409 }
410 MEDIA_CLASS_DEFINE_END(vp__vISA__AttributeInfo)
411 };
412
413 //!
414 //! \brief InputInfo Class.
415 //! \details This class represents the InputInfo from vISA Object Format.
416 //! Provides getters, setters for its fields and structs as well as
417 //! functions to read/write it from/to file.
418 //!
419 class InputInfo {
420 public:
421 std::array<Field, 4> fields = std::array<Field, 4>
422 {
423 Field(Datatype::ONE), // kind
424 Field(Datatype::FOUR), // id
425 Field(Datatype::TWO), // offset
426 Field(Datatype::TWO) // size
427 };
428
429 //!
430 //! \brief Constructor of InputInfo class.
431 //! \param [in] version.
432 //! Version of current ISA file.
433 //!
434 InputInfo(unsigned version) {
435 if (version <= 303) setVersion303();
436 }
437
438 //!
439 //! \brief Destructor of InputInfo class.
440 //!
441 ~InputInfo() {
442 }
443
444 //!
445 //! \brief Returns the integer value of the Kind field.
446 //! \details Kind field is at index 0 in the internal
447 //! array of Fields.
448 //! \retval An integer.
449 //!
450 int8_t getKind() {
451 return fields[0].number8;
452 }
453
454 //!
455 //! \brief Sets the integer value of the Kind field.
456 //! \details Kind field is at index 0 in the internal
457 //! array of Fields.
458 //! \param [in] value.
459 //! Integer be assigned.
460 //!
461 void setKind(int8_t value) {
462 fields[0].number8 = value;
463 }
464
465 //!
466 //! \brief Returns the integer value of the Id field.
467 //! \details Id field is at index 1 in the internal
468 //! array of Fields.
469 //! \retval An integer.
470 //!
471 uint32_t getId() {
472 return (uint32_t)fields[1].number32;
473 }
474
475 //!
476 //! \brief Sets the integer value of the Id field.
477 //! \details Id field is at index 1 in the internal
478 //! array of Fields.
479 //! \param [in] value.
480 //! Integer be assigned.
481 //!
482 void setId(uint32_t value) {
483 fields[1].number32 = value;
484 }
485
486 //!
487 //! \brief Returns the integer value of the Offset field.
488 //! \details Offset field is at index 2 in the internal
489 //! array of Fields.
490 //! \retval An integer.
491 //!
492 int16_t getOffset() {
493 return fields[2].number16;
494 }
495
496 //!
497 //! \brief Sets the integer value of the Offset field.
498 //! \details Offset field is at index 2 in the internal
499 //! array of Fields.
500 //! \param [in] value.
501 //! Integer be assigned.
502 //!
503 void setOffset(int16_t value) {
504 fields[2].number16 = value;
505 }
506
507 //!
508 //! \brief Returns the integer value of the Size field.
509 //! \details Size field is at index 3 in the internal
510 //! array of Fields.
511 //! \retval An integer.
512 //!
513 uint16_t getSize() {
514 return (uint16_t)fields[3].number16;
515 }
516
517 //!
518 //! \brief Sets the integer value of the Size field.
519 //! \details Size field is at index 3 in the internal
520 //! array of Fields.
521 //! \param [in] value.
522 //! Integer be assigned.
523 //!
524 void setSize(uint16_t value) {
525 fields[3].number16 = value;
526 }
527
528 //!
529 //! \brief Parses one InputInfo object from ISA file.
530 //! \details Reads and parses all the fields of the InputInfo object
531 //! from the file buffer and returns the pointer immediately
532 //! after all this data.
533 //! If this class contains internal structs, their Parse
534 //! functions are called when corresponding.
535 //! \param [in] p.
536 //! Pointer to file buffer to start reading.
537 //! \param [in] end.
538 //! Pointer to end of file buffer.
539 //! \param [in] m.
540 //! Pointer ISAfile object.
541 //! \retval Pointer to file buffe after parsing one InputInfo object.
542 //!
543 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
544 unsigned i = 0;
545 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
546 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
547 if (!p) return m->setError("bad offset/size for InputInfo's field", i);
548 i++;
549 }
550 return p;
551 }
552
553 //!
554 //! \brief Adds all the InputInfo's fields to a buffer.
555 //! \details Every field from this class is added to a buffer
556 //! in order to be written into an ISA file afterwards
557 //! If this class contains other internal structus, their addToBuffer
558 //! functions are called when corresponding.
559 //! \param [out] buffer.
560 //! The buffer where the fields data will be added.
561 //! \param [in] m.
562 //! Pointer to ISAfile object.
563 //!
564 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
565 unsigned i = 0;
566 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
567 m->addToBuffer(fields[i], buffer);
568 i++;
569 }
570 }
571
572 //!
573 //! \brief Makes the changes needed to support 303 version's InputInfo.
574 //! \details This function is called when the current ISA file has the 303 version.
575 //! Initially all the objects are created with last version's format, so
576 //! in order to suppport previous versions, changes of datatypes and insertion/removal
577 //! of fields can be needed.
578 //!
579 void setVersion303() {
580 fields[1] = Datatype::TWO;
581 }
582 MEDIA_CLASS_DEFINE_END(vp__vISA__InputInfo)
583 };
584
585 //!
586 //! \brief VmeInfo Class.
587 //! \details This class represents the VmeInfo from vISA Object Format.
588 //! Provides getters, setters for its fields and structs as well as
589 //! functions to read/write it from/to file.
590 //!
591 class VmeInfo {
592 public:
593 std::array<Field, 4> fields = std::array<Field, 4>
594 {
595 Field(Datatype::FOUR), // name_index
596 Field(Datatype::TWO), // num_elements
597 Field(Datatype::ONE), // attribute_count
598 Field(Datatype::STRUCT, 2), // attribute_info
599 };
600 std::vector<AttributeInfo*> attribute_info;
601
602 //!
603 //! \brief Constructor of VmeInfo class.
604 //! \param [in] version.
605 //! Version of current ISA file.
606 //!
607 VmeInfo(unsigned version) {
608 if (version <= 303) setVersion303();
609 }
610
611 //!
612 //! \brief Destructor of VmeInfo class.
613 //!
614 ~VmeInfo() {
615 for (AttributeInfo *s : attribute_info) delete s;
616 }
617
618 //!
619 //! \brief Returns the integer value of the NameIndex field.
620 //! \details NameIndex field is at index 0 in the internal
621 //! array of Fields.
622 //! \retval An integer.
623 //!
624 uint32_t getNameIndex() {
625 return (uint32_t)fields[0].number32;
626 }
627
628 //!
629 //! \brief Sets the integer value of the NameIndex field.
630 //! \details NameIndex field is at index 0 in the internal
631 //! array of Fields.
632 //! \param [in] value.
633 //! Integer be assigned.
634 //!
635 void setNameIndex(uint32_t value) {
636 fields[0].number32 = value;
637 }
638
639 //!
640 //! \brief Returns the integer value of the NumElements field.
641 //! \details NumElements field is at index 1 in the internal
642 //! array of Fields.
643 //! \retval An integer.
644 //!
645 uint16_t getNumElements() {
646 return (uint16_t)fields[1].number16;
647 }
648
649 //!
650 //! \brief Sets the integer value of the NumElements field.
651 //! \details NumElements field is at index 1 in the internal
652 //! array of Fields.
653 //! \param [in] value.
654 //! Integer be assigned.
655 //!
656 void setNumElements(uint16_t value) {
657 fields[1].number16 = value;
658 }
659
660 //!
661 //! \brief Returns the integer value of the AttributeCount field.
662 //! \details AttributeCount field is at index 2 in the internal
663 //! array of Fields.
664 //! \retval An integer.
665 //!
666 uint8_t getAttributeCount() {
667 return (uint8_t)fields[2].number8;
668 }
669
670 //!
671 //! \brief Sets the integer value of the AttributeCount field.
672 //! \details AttributeCount field is at index 2 in the internal
673 //! array of Fields.
674 //! \param [in] value.
675 //! Integer be assigned.
676 //!
677 void setAttributeCount(uint8_t value) {
678 fields[2].number8 = value;
679 }
680
681 //!
682 //! \brief Returns the reference to the vector of AttributeInfo objects.
683 //! \details VmeInfo has a vector of AttributeInfo objects
684 //! that represents another entity within the vISA object format.
685 //! \retval Reference to the vector of AttributeInfo*.
686 //!
687 std::vector<AttributeInfo*> &getAttributeInfo() {
688 return attribute_info;
689 }
690
691 //!
692 //! \brief Parses one VmeInfo object from ISA file.
693 //! \details Reads and parses all the fields of the VmeInfo object
694 //! from the file buffer and returns the pointer immediately
695 //! after all this data.
696 //! If this class contains internal structs, their Parse
697 //! functions are called when corresponding.
698 //! \param [in] p.
699 //! Pointer to file buffer to start reading.
700 //! \param [in] end.
701 //! Pointer to end of file buffer.
702 //! \param [in] m.
703 //! Pointer ISAfile object.
704 //! \retval Pointer to file buffe after parsing one VmeInfo object.
705 //!
706 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
707 unsigned i = 0, count = 0;
708 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
709 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
710 if (!p) return m->setError("bad offset/size for VmeInfo's field", i);
711 i++;
712 }
713 // AttributeInfo
714 count = fields[fields[i].countField].number32;
715 attribute_info.resize(count);
716 for (unsigned j = 0; j < count; j++) {
717 AttributeInfo *r = new AttributeInfo(m->getCurrentVISAVersion());
718 p = r->parse(p, end, m);
719 if (!p) {
720 delete r;
721 return 0;
722 }
723 attribute_info[j] = r;
724 }
725 i++;
726 return p;
727 }
728
729 //!
730 //! \brief Adds all the VmeInfo's fields to a buffer.
731 //! \details Every field from this class is added to a buffer
732 //! in order to be written into an ISA file afterwards
733 //! If this class contains other internal structus, their addToBuffer
734 //! functions are called when corresponding.
735 //! \param [out] buffer.
736 //! The buffer where the fields data will be added.
737 //! \param [in] m.
738 //! Pointer to ISAfile object.
739 //!
740 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
741 unsigned i = 0;
742 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
743 m->addToBuffer(fields[i], buffer);
744 i++;
745 }
746 // AttributeInfo
747 for (AttributeInfo *r : attribute_info) {
748 r->addToBuffer(buffer, m);
749 }
750 i++;
751 }
752
753 //!
754 //! \brief Makes the changes needed to support 303 version's VmeInfo.
755 //! \details This function is called when the current ISA file has the 303 version.
756 //! Initially all the objects are created with last version's format, so
757 //! in order to suppport previous versions, changes of datatypes and insertion/removal
758 //! of fields can be needed.
759 //!
760 void setVersion303() {
761 fields[0] = Datatype::TWO;
762 }
763 MEDIA_CLASS_DEFINE_END(vp__vISA__VmeInfo)
764 };
765
766 //!
767 //! \brief SurfaceInfo Class.
768 //! \details This class represents the SurfaceInfo from vISA Object Format.
769 //! Provides getters, setters for its fields and structs as well as
770 //! functions to read/write it from/to file.
771 //!
772 class SurfaceInfo {
773 public:
774 std::array<Field, 4> fields = std::array<Field, 4>
775 {
776 Field(Datatype::FOUR), // name_index
777 Field(Datatype::TWO), // num_elements
778 Field(Datatype::ONE), // attribute_count
779 Field(Datatype::STRUCT, 2), // attribute_info
780 };
781 std::vector<AttributeInfo*> attribute_info;
782
783 //!
784 //! \brief Constructor of SurfaceInfo class.
785 //! \param [in] version.
786 //! Version of current ISA file.
787 //!
788 SurfaceInfo(unsigned version) {
789 if (version <= 303) setVersion303();
790 }
791
792 //!
793 //! \brief Destructor of SurfaceInfo class.
794 //!
795 ~SurfaceInfo() {
796 for (AttributeInfo *s : attribute_info) delete s;
797 }
798
799 //!
800 //! \brief Returns the integer value of the NameIndex field.
801 //! \details NameIndex field is at index 0 in the internal
802 //! array of Fields.
803 //! \retval An integer.
804 //!
805 uint32_t getNameIndex() {
806 return (uint32_t)fields[0].number32;
807 }
808
809 //!
810 //! \brief Sets the integer value of the NameIndex field.
811 //! \details NameIndex field is at index 0 in the internal
812 //! array of Fields.
813 //! \param [in] value.
814 //! Integer be assigned.
815 //!
816 void setNameIndex(uint32_t value) {
817 fields[0].number32 = value;
818 }
819
820 //!
821 //! \brief Returns the integer value of the NumElements field.
822 //! \details NumElements field is at index 1 in the internal
823 //! array of Fields.
824 //! \retval An integer.
825 //!
826 uint16_t getNumElements() {
827 return (uint16_t)fields[1].number16;
828 }
829
830 //!
831 //! \brief Sets the integer value of the NumElements field.
832 //! \details NumElements field is at index 1 in the internal
833 //! array of Fields.
834 //! \param [in] value.
835 //! Integer be assigned.
836 //!
837 void setNumElements(uint16_t value) {
838 fields[1].number16 = value;
839 }
840
841 //!
842 //! \brief Returns the integer value of the AttributeCount field.
843 //! \details AttributeCount field is at index 2 in the internal
844 //! array of Fields.
845 //! \retval An integer.
846 //!
847 uint8_t getAttributeCount() {
848 return (uint8_t)fields[2].number8;
849 }
850
851 //!
852 //! \brief Sets the integer value of the AttributeCount field.
853 //! \details AttributeCount field is at index 2 in the internal
854 //! array of Fields.
855 //! \param [in] value.
856 //! Integer be assigned.
857 //!
858 void setAttributeCount(uint8_t value) {
859 fields[2].number8 = value;
860 }
861
862 //!
863 //! \brief Returns the reference to the vector of AttributeInfo objects.
864 //! \details SurfaceInfo has a vector of AttributeInfo objects
865 //! that represents another entity within the vISA object format.
866 //! \retval Reference to the vector of AttributeInfo*.
867 //!
868 std::vector<AttributeInfo*> &getAttributeInfo() {
869 return attribute_info;
870 }
871
872 //!
873 //! \brief Parses one SurfaceInfo object from ISA file.
874 //! \details Reads and parses all the fields of the SurfaceInfo object
875 //! from the file buffer and returns the pointer immediately
876 //! after all this data.
877 //! If this class contains internal structs, their Parse
878 //! functions are called when corresponding.
879 //! \param [in] p.
880 //! Pointer to file buffer to start reading.
881 //! \param [in] end.
882 //! Pointer to end of file buffer.
883 //! \param [in] m.
884 //! Pointer ISAfile object.
885 //! \retval Pointer to file buffe after parsing one SurfaceInfo object.
886 //!
887 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
888 unsigned i = 0, count = 0;
889 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
890 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
891 if (!p) return m->setError("bad offset/size for SurfaceInfo's field", i);
892 i++;
893 }
894 // AttributeInfo
895 count = fields[fields[i].countField].number32;
896 attribute_info.resize(count);
897 for (unsigned j = 0; j < count; j++) {
898 AttributeInfo *r = new AttributeInfo(m->getCurrentVISAVersion());
899 p = r->parse(p, end, m);
900 if (!p) {
901 delete r;
902 return 0;
903 }
904 attribute_info[j] = r;
905 }
906 i++;
907 return p;
908 }
909
910 //!
911 //! \brief Adds all the SurfaceInfo's fields to a buffer.
912 //! \details Every field from this class is added to a buffer
913 //! in order to be written into an ISA file afterwards
914 //! If this class contains other internal structus, their addToBuffer
915 //! functions are called when corresponding.
916 //! \param [out] buffer.
917 //! The buffer where the fields data will be added.
918 //! \param [in] m.
919 //! Pointer to ISAfile object.
920 //!
921 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
922 unsigned i = 0;
923 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
924 m->addToBuffer(fields[i], buffer);
925 i++;
926 }
927 // AttributeInfo
928 for (AttributeInfo *r : attribute_info) {
929 r->addToBuffer(buffer, m);
930 }
931 i++;
932 }
933
934 //!
935 //! \brief Makes the changes needed to support 303 version's SurfaceInfo.
936 //! \details This function is called when the current ISA file has the 303 version.
937 //! Initially all the objects are created with last version's format, so
938 //! in order to suppport previous versions, changes of datatypes and insertion/removal
939 //! of fields can be needed.
940 //!
941 void setVersion303() {
942 fields[0] = Datatype::TWO;
943 }
944 MEDIA_CLASS_DEFINE_END(vp__vISA__SurfaceInfo)
945 };
946
947 //!
948 //! \brief SamplerInfo Class.
949 //! \details This class represents the SamplerInfo from vISA Object Format.
950 //! Provides getters, setters for its fields and structs as well as
951 //! functions to read/write it from/to file.
952 //!
953 class SamplerInfo {
954 public:
955 std::array<Field, 4> fields = std::array<Field, 4>
956 {
957 Field(Datatype::FOUR), // name_index
958 Field(Datatype::TWO), // num_elements
959 Field(Datatype::ONE), // attribute_count
960 Field(Datatype::STRUCT, 2), // attribute_info
961 };
962 std::vector<AttributeInfo*> attribute_info;
963
964 //!
965 //! \brief Constructor of SamplerInfo class.
966 //! \param [in] version.
967 //! Version of current ISA file.
968 //!
969 SamplerInfo(unsigned version) {
970 if (version <= 303) setVersion303();
971 }
972
973 //!
974 //! \brief Destructor of SamplerInfo class.
975 //!
976 ~SamplerInfo() {
977 for (AttributeInfo *s : attribute_info) delete s;
978 }
979
980 //!
981 //! \brief Returns the integer value of the NameIndex field.
982 //! \details NameIndex field is at index 0 in the internal
983 //! array of Fields.
984 //! \retval An integer.
985 //!
986 uint32_t getNameIndex() {
987 return (uint32_t)fields[0].number32;
988 }
989
990 //!
991 //! \brief Sets the integer value of the NameIndex field.
992 //! \details NameIndex field is at index 0 in the internal
993 //! array of Fields.
994 //! \param [in] value.
995 //! Integer be assigned.
996 //!
997 void setNameIndex(uint32_t value) {
998 fields[0].number32 = value;
999 }
1000
1001 //!
1002 //! \brief Returns the integer value of the NumElements field.
1003 //! \details NumElements field is at index 1 in the internal
1004 //! array of Fields.
1005 //! \retval An integer.
1006 //!
1007 uint16_t getNumElements() {
1008 return (uint16_t)fields[1].number16;
1009 }
1010
1011 //!
1012 //! \brief Sets the integer value of the NumElements field.
1013 //! \details NumElements field is at index 1 in the internal
1014 //! array of Fields.
1015 //! \param [in] value.
1016 //! Integer be assigned.
1017 //!
1018 void setNumElements(uint16_t value) {
1019 fields[1].number16 = value;
1020 }
1021
1022 //!
1023 //! \brief Returns the integer value of the AttributeCount field.
1024 //! \details AttributeCount field is at index 2 in the internal
1025 //! array of Fields.
1026 //! \retval An integer.
1027 //!
1028 uint8_t getAttributeCount() {
1029 return (uint8_t)fields[2].number8;
1030 }
1031
1032 //!
1033 //! \brief Sets the integer value of the AttributeCount field.
1034 //! \details AttributeCount field is at index 2 in the internal
1035 //! array of Fields.
1036 //! \param [in] value.
1037 //! Integer be assigned.
1038 //!
1039 void setAttributeCount(uint8_t value) {
1040 fields[2].number8 = value;
1041 }
1042
1043 //!
1044 //! \brief Returns the reference to the vector of AttributeInfo objects.
1045 //! \details SamplerInfo has a vector of AttributeInfo objects
1046 //! that represents another entity within the vISA object format.
1047 //! \retval Reference to the vector of AttributeInfo*.
1048 //!
1049 std::vector<AttributeInfo*> &getAttributeInfo() {
1050 return attribute_info;
1051 }
1052
1053 //!
1054 //! \brief Parses one SamplerInfo object from ISA file.
1055 //! \details Reads and parses all the fields of the SamplerInfo object
1056 //! from the file buffer and returns the pointer immediately
1057 //! after all this data.
1058 //! If this class contains internal structs, their Parse
1059 //! functions are called when corresponding.
1060 //! \param [in] p.
1061 //! Pointer to file buffer to start reading.
1062 //! \param [in] end.
1063 //! Pointer to end of file buffer.
1064 //! \param [in] m.
1065 //! Pointer ISAfile object.
1066 //! \retval Pointer to file buffe after parsing one SamplerInfo object.
1067 //!
1068 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
1069 unsigned i = 0, count = 0;
1070 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
1071 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
1072 if (!p) return m->setError("bad offset/size for SamplerInfo's field", i);
1073 i++;
1074 }
1075 // AttributeInfo
1076 count = fields[fields[i].countField].number32;
1077 attribute_info.resize(count);
1078 for (unsigned j = 0; j < count; j++) {
1079 AttributeInfo *r = new AttributeInfo(m->getCurrentVISAVersion());
1080 p = r->parse(p, end, m);
1081 if (!p) {
1082 delete r;
1083 return 0;
1084 }
1085 attribute_info[j] = r;
1086 }
1087 i++;
1088 return p;
1089 }
1090
1091 //!
1092 //! \brief Adds all the SamplerInfo's fields to a buffer.
1093 //! \details Every field from this class is added to a buffer
1094 //! in order to be written into an ISA file afterwards
1095 //! If this class contains other internal structus, their addToBuffer
1096 //! functions are called when corresponding.
1097 //! \param [out] buffer.
1098 //! The buffer where the fields data will be added.
1099 //! \param [in] m.
1100 //! Pointer to ISAfile object.
1101 //!
1102 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
1103 unsigned i = 0;
1104 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
1105 m->addToBuffer(fields[i], buffer);
1106 i++;
1107 }
1108 // AttributeInfo
1109 for (AttributeInfo *r : attribute_info) {
1110 r->addToBuffer(buffer, m);
1111 }
1112 i++;
1113 }
1114
1115 //!
1116 //! \brief Makes the changes needed to support 303 version's SamplerInfo.
1117 //! \details This function is called when the current ISA file has the 303 version.
1118 //! Initially all the objects are created with last version's format, so
1119 //! in order to suppport previous versions, changes of datatypes and insertion/removal
1120 //! of fields can be needed.
1121 //!
1122 void setVersion303() {
1123 fields[0] = Datatype::TWO;
1124 }
1125 MEDIA_CLASS_DEFINE_END(vp__vISA__SamplerInfo)
1126 };
1127
1128 //!
1129 //! \brief LabelInfo Class.
1130 //! \details This class represents the LabelInfo from vISA Object Format.
1131 //! Provides getters, setters for its fields and structs as well as
1132 //! functions to read/write it from/to file.
1133 //!
1134 class LabelInfo {
1135 public:
1136 std::array<Field, 4> fields = std::array<Field, 4>
1137 {
1138 Field(Datatype::FOUR), // name_index
1139 Field(Datatype::ONE), // kind
1140 Field(Datatype::ONE), // attribute_count
1141 Field(Datatype::STRUCT, 2), // attribute_info
1142 };
1143 std::vector<AttributeInfo*> attribute_info;
1144
1145 //!
1146 //! \brief Constructor of LabelInfo class.
1147 //! \param [in] version.
1148 //! Version of current ISA file.
1149 //!
1150 LabelInfo(unsigned version) {
1151 if (version <= 303) setVersion303();
1152 }
1153
1154 //!
1155 //! \brief Destructor of LabelInfo class.
1156 //!
1157 ~LabelInfo() {
1158 for (AttributeInfo *s : attribute_info)
1159 {
1160 if (s)
1161 {
1162 delete s;
1163 }
1164 }
1165 }
1166
1167 //!
1168 //! \brief Returns the integer value of the NameIndex field.
1169 //! \details NameIndex field is at index 0 in the internal
1170 //! array of Fields.
1171 //! \retval An integer.
1172 //!
1173 uint32_t getNameIndex() {
1174 return (uint32_t)fields[0].number32;
1175 }
1176
1177 //!
1178 //! \brief Sets the integer value of the NameIndex field.
1179 //! \details NameIndex field is at index 0 in the internal
1180 //! array of Fields.
1181 //! \param [in] value.
1182 //! Integer be assigned.
1183 //!
1184 void setNameIndex(uint32_t value) {
1185 fields[0].number32 = value;
1186 }
1187
1188 //!
1189 //! \brief Returns the integer value of the Kind field.
1190 //! \details Kind field is at index 1 in the internal
1191 //! array of Fields.
1192 //! \retval An integer.
1193 //!
1194 uint8_t getKind() {
1195 return (uint8_t)fields[1].number8;
1196 }
1197
1198 //!
1199 //! \brief Sets the integer value of the Kind field.
1200 //! \details Kind field is at index 1 in the internal
1201 //! array of Fields.
1202 //! \param [in] value.
1203 //! Integer be assigned.
1204 //!
1205 void setKind(uint8_t value) {
1206 fields[1].number8 = value;
1207 }
1208
1209 //!
1210 //! \brief Returns the integer value of the AttributeCount field.
1211 //! \details AttributeCount field is at index 2 in the internal
1212 //! array of Fields.
1213 //! \retval An integer.
1214 //!
1215 uint8_t getAttributeCount() {
1216 return (uint8_t)fields[2].number8;
1217 }
1218
1219 //!
1220 //! \brief Sets the integer value of the AttributeCount field.
1221 //! \details AttributeCount field is at index 2 in the internal
1222 //! array of Fields.
1223 //! \param [in] value.
1224 //! Integer be assigned.
1225 //!
1226 void setAttributeCount(uint8_t value) {
1227 fields[2].number8 = value;
1228 }
1229
1230 //!
1231 //! \brief Returns the reference to the vector of AttributeInfo objects.
1232 //! \details LabelInfo has a vector of AttributeInfo objects
1233 //! that represents another entity within the vISA object format.
1234 //! \retval Reference to the vector of AttributeInfo*.
1235 //!
1236 std::vector<AttributeInfo*> &getAttributeInfo() {
1237 return attribute_info;
1238 }
1239
1240 //!
1241 //! \brief Parses one LabelInfo object from ISA file.
1242 //! \details Reads and parses all the fields of the LabelInfo object
1243 //! from the file buffer and returns the pointer immediately
1244 //! after all this data.
1245 //! If this class contains internal structs, their Parse
1246 //! functions are called when corresponding.
1247 //! \param [in] p.
1248 //! Pointer to file buffer to start reading.
1249 //! \param [in] end.
1250 //! Pointer to end of file buffer.
1251 //! \param [in] m.
1252 //! Pointer ISAfile object.
1253 //! \retval Pointer to file buffe after parsing one LabelInfo object.
1254 //!
1255 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
1256 unsigned i = 0, count = 0;
1257 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
1258 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
1259 if (!p) return m->setError("bad offset/size for LabelInfo's field", i);
1260 i++;
1261 }
1262 // AttributeInfo
1263 count = fields[fields[i].countField].number32;
1264 attribute_info.resize(count);
1265 for (unsigned j = 0; j < count; j++) {
1266 AttributeInfo *r = new AttributeInfo(m->getCurrentVISAVersion());
1267 p = r->parse(p, end, m);
1268 if (!p) {
1269 delete r;
1270 return 0;
1271 }
1272 attribute_info[j] = r;
1273 }
1274 i++;
1275 return p;
1276 }
1277
1278 //!
1279 //! \brief Adds all the LabelInfo's fields to a buffer.
1280 //! \details Every field from this class is added to a buffer
1281 //! in order to be written into an ISA file afterwards
1282 //! If this class contains other internal structus, their addToBuffer
1283 //! functions are called when corresponding.
1284 //! \param [out] buffer.
1285 //! The buffer where the fields data will be added.
1286 //! \param [in] m.
1287 //! Pointer to ISAfile object.
1288 //!
1289 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
1290 unsigned i = 0;
1291 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
1292 m->addToBuffer(fields[i], buffer);
1293 i++;
1294 }
1295 // AttributeInfo
1296 for (AttributeInfo *r : attribute_info) {
1297 r->addToBuffer(buffer, m);
1298 }
1299 i++;
1300 }
1301
1302 //!
1303 //! \brief Makes the changes needed to support 303 version's LabelInfo.
1304 //! \details This function is called when the current ISA file has the 303 version.
1305 //! Initially all the objects are created with last version's format, so
1306 //! in order to suppport previous versions, changes of datatypes and insertion/removal
1307 //! of fields can be needed.
1308 //!
1309 void setVersion303() {
1310 fields[0] = Datatype::TWO;
1311 }
1312 MEDIA_CLASS_DEFINE_END(vp__vISA__LabelInfo)
1313 };
1314
1315 //!
1316 //! \brief PredicateInfo Class.
1317 //! \details This class represents the PredicateInfo from vISA Object Format.
1318 //! Provides getters, setters for its fields and structs as well as
1319 //! functions to read/write it from/to file.
1320 //!
1321 class PredicateInfo {
1322 public:
1323 std::array<Field, 4> fields = std::array<Field, 4>
1324 {
1325 Field(Datatype::FOUR), // name_index
1326 Field(Datatype::TWO), // num_elements
1327 Field(Datatype::ONE), // attribute_count
1328 Field(Datatype::STRUCT, 2), // attribute_info
1329 };
1330 std::vector<AttributeInfo*> attribute_info;
1331
1332 //!
1333 //! \brief Constructor of PredicateInfo class.
1334 //! \param [in] version.
1335 //! Version of current ISA file.
1336 //!
1337 PredicateInfo(unsigned version) {
1338 if (version <= 303) setVersion303();
1339 }
1340
1341 //!
1342 //! \brief Destructor of PredicateInfo class.
1343 //!
1344 ~PredicateInfo() {
1345 for (AttributeInfo *s : attribute_info)
1346 {
1347 if (s)
1348 {
1349 delete s;
1350 }
1351 }
1352 }
1353
1354 //!
1355 //! \brief Returns the integer value of the NameIndex field.
1356 //! \details NameIndex field is at index 0 in the internal
1357 //! array of Fields.
1358 //! \retval An integer.
1359 //!
1360 uint32_t getNameIndex() {
1361 return (uint32_t)fields[0].number32;
1362 }
1363
1364 //!
1365 //! \brief Sets the integer value of the NameIndex field.
1366 //! \details NameIndex field is at index 0 in the internal
1367 //! array of Fields.
1368 //! \param [in] value.
1369 //! Integer be assigned.
1370 //!
1371 void setNameIndex(uint32_t value) {
1372 fields[0].number32 = value;
1373 }
1374
1375 //!
1376 //! \brief Returns the integer value of the NumElements field.
1377 //! \details NumElements field is at index 1 in the internal
1378 //! array of Fields.
1379 //! \retval An integer.
1380 //!
1381 uint16_t getNumElements() {
1382 return (uint16_t)fields[1].number16;
1383 }
1384
1385 //!
1386 //! \brief Sets the integer value of the NumElements field.
1387 //! \details NumElements field is at index 1 in the internal
1388 //! array of Fields.
1389 //! \param [in] value.
1390 //! Integer be assigned.
1391 //!
1392 void setNumElements(uint16_t value) {
1393 fields[1].number16 = value;
1394 }
1395
1396 //!
1397 //! \brief Returns the integer value of the AttributeCount field.
1398 //! \details AttributeCount field is at index 2 in the internal
1399 //! array of Fields.
1400 //! \retval An integer.
1401 //!
1402 uint8_t getAttributeCount() {
1403 return (uint8_t)fields[2].number8;
1404 }
1405
1406 //!
1407 //! \brief Sets the integer value of the AttributeCount field.
1408 //! \details AttributeCount field is at index 2 in the internal
1409 //! array of Fields.
1410 //! \param [in] value.
1411 //! Integer be assigned.
1412 //!
1413 void setAttributeCount(uint8_t value) {
1414 fields[2].number8 = value;
1415 }
1416
1417 //!
1418 //! \brief Returns the reference to the vector of AttributeInfo objects.
1419 //! \details PredicateInfo has a vector of AttributeInfo objects
1420 //! that represents another entity within the vISA object format.
1421 //! \retval Reference to the vector of AttributeInfo*.
1422 //!
1423 std::vector<AttributeInfo*> &getAttributeInfo() {
1424 return attribute_info;
1425 }
1426
1427 //!
1428 //! \brief Parses one PredicateInfo object from ISA file.
1429 //! \details Reads and parses all the fields of the PredicateInfo object
1430 //! from the file buffer and returns the pointer immediately
1431 //! after all this data.
1432 //! If this class contains internal structs, their Parse
1433 //! functions are called when corresponding.
1434 //! \param [in] p.
1435 //! Pointer to file buffer to start reading.
1436 //! \param [in] end.
1437 //! Pointer to end of file buffer.
1438 //! \param [in] m.
1439 //! Pointer ISAfile object.
1440 //! \retval Pointer to file buffe after parsing one PredicateInfo object.
1441 //!
1442 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
1443 unsigned i = 0, count = 0;
1444 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
1445 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
1446 if (!p) return m->setError("bad offset/size for PredicateInfo's field", i);
1447 i++;
1448 }
1449 // AttributeInfo
1450 count = fields[fields[i].countField].number32;
1451 attribute_info.resize(count);
1452 for (unsigned j = 0; j < count; j++) {
1453 AttributeInfo *r = new AttributeInfo(m->getCurrentVISAVersion());
1454 p = r->parse(p, end, m);
1455 if (!p) {
1456 delete r;
1457 return 0;
1458 }
1459 attribute_info[j] = r;
1460 }
1461 i++;
1462 return p;
1463 }
1464
1465 //!
1466 //! \brief Adds all the PredicateInfo's fields to a buffer.
1467 //! \details Every field from this class is added to a buffer
1468 //! in order to be written into an ISA file afterwards
1469 //! If this class contains other internal structus, their addToBuffer
1470 //! functions are called when corresponding.
1471 //! \param [out] buffer.
1472 //! The buffer where the fields data will be added.
1473 //! \param [in] m.
1474 //! Pointer to ISAfile object.
1475 //!
1476 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
1477 unsigned i = 0;
1478 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
1479 m->addToBuffer(fields[i], buffer);
1480 i++;
1481 }
1482 // AttributeInfo
1483 for (AttributeInfo *r : attribute_info) {
1484 r->addToBuffer(buffer, m);
1485 }
1486 i++;
1487 }
1488
1489 //!
1490 //! \brief Makes the changes needed to support 303 version's PredicateInfo.
1491 //! \details This function is called when the current ISA file has the 303 version.
1492 //! Initially all the objects are created with last version's format, so
1493 //! in order to suppport previous versions, changes of datatypes and insertion/removal
1494 //! of fields can be needed.
1495 //!
1496 void setVersion303() {
1497 fields[0] = Datatype::TWO;
1498 }
1499 MEDIA_CLASS_DEFINE_END(vp__vISA__PredicateInfo)
1500 };
1501
1502 //!
1503 //! \brief RelocationInfo Class.
1504 //! \details This class represents the RelocationInfo from vISA Object Format.
1505 //! Provides getters, setters for its fields and structs as well as
1506 //! functions to read/write it from/to file.
1507 //!
1508 class RelocationInfo {
1509 public:
1510 std::array<Field, 2> fields = std::array<Field, 2>
1511 {
1512 Field(Datatype::TWO), // symbolic_index
1513 Field(Datatype::TWO) // resolved_index
1514 };
1515
1516 //!
1517 //! \brief Constructor of RelocationInfo class.
1518 //! \param [in] version.
1519 //! Version of current ISA file.
1520 //!
1521 RelocationInfo(unsigned version) {}
1522
1523 //!
1524 //! \brief Constructor of RelocationInfo class.
1525 //!
1526 RelocationInfo() {}
1527
1528 //!
1529 //! \brief Copy Constructor of RelocationInfo class.
1530 //! \param [in] other.
1531 //! Reference to object to copy..
1532 //!
1533 RelocationInfo(const RelocationInfo& other) {
1534 fields = other.fields;
1535 }
1536
1537 //!
1538 //! \brief Assignment operator.
1539 //! \param [in] other.
1540 //! Reference to object to copy..
1541 //!
1542 RelocationInfo& operator= (const RelocationInfo& other) {
1543 if (this != &other) {
1544 fields = other.fields;
1545 }
1546 return *this;
1547 }
1548
1549 //!
1550 //! \brief Destructor of RelocationInfo class.
1551 //!
1552 ~RelocationInfo() {
1553 }
1554
1555 //!
1556 //! \brief Returns the integer value of the SymbolicIndex field.
1557 //! \details SymbolicIndex field is at index 0 in the internal
1558 //! array of Fields.
1559 //! \retval An integer.
1560 //!
1561 uint16_t getSymbolicIndex() {
1562 return (uint16_t)fields[0].number16;
1563 }
1564
1565 //!
1566 //! \brief Sets the integer value of the SymbolicIndex field.
1567 //! \details SymbolicIndex field is at index 0 in the internal
1568 //! array of Fields.
1569 //! \param [in] value.
1570 //! Integer be assigned.
1571 //!
1572 void setSymbolicIndex(uint16_t value) {
1573 fields[0].number16 = value;
1574 }
1575
1576 //!
1577 //! \brief Returns the integer value of the ResolvedIndex field.
1578 //! \details ResolvedIndex field is at index 1 in the internal
1579 //! array of Fields.
1580 //! \retval An integer.
1581 //!
1582 uint16_t getResolvedIndex() {
1583 return (uint16_t)fields[1].number16;
1584 }
1585
1586 //!
1587 //! \brief Sets the integer value of the ResolvedIndex field.
1588 //! \details ResolvedIndex field is at index 1 in the internal
1589 //! array of Fields.
1590 //! \param [in] value.
1591 //! Integer be assigned.
1592 //!
1593 void setResolvedIndex(uint16_t value) {
1594 fields[1].number16 = value;
1595 }
1596
1597 //!
1598 //! \brief Parses one RelocationInfo object from ISA file.
1599 //! \details Reads and parses all the fields of the RelocationInfo object
1600 //! from the file buffer and returns the pointer immediately
1601 //! after all this data.
1602 //! If this class contains internal structs, their Parse
1603 //! functions are called when corresponding.
1604 //! \param [in] p.
1605 //! Pointer to file buffer to start reading.
1606 //! \param [in] end.
1607 //! Pointer to end of file buffer.
1608 //! \param [in] m.
1609 //! Pointer ISAfile object.
1610 //! \retval Pointer to file buffe after parsing one RelocationInfo object.
1611 //!
1612 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
1613 unsigned i = 0;
1614 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
1615 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
1616 if (!p) return m->setError("bad offset/size for RelocationInfo's field", i);
1617 i++;
1618 }
1619 return p;
1620 }
1621
1622 //!
1623 //! \brief Adds all the RelocationInfo's fields to a buffer.
1624 //! \details Every field from this class is added to a buffer
1625 //! in order to be written into an ISA file afterwards
1626 //! If this class contains other internal structus, their addToBuffer
1627 //! functions are called when corresponding.
1628 //! \param [out] buffer.
1629 //! The buffer where the fields data will be added.
1630 //! \param [in] m.
1631 //! Pointer to ISAfile object.
1632 //!
1633 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
1634 unsigned i = 0;
1635 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
1636 m->addToBuffer(fields[i], buffer);
1637 i++;
1638 }
1639 }
1640 MEDIA_CLASS_DEFINE_END(vp__vISA__RelocationInfo)
1641 };
1642
1643 //!
1644 //! \brief AddressInfo Class.
1645 //! \details This class represents the AddressInfo from vISA Object Format.
1646 //! Provides getters, setters for its fields and structs as well as
1647 //! functions to read/write it from/to file.
1648 //!
1649 class AddressInfo {
1650 public:
1651 std::array<Field, 4> fields = std::array<Field, 4>
1652 {
1653 Field(Datatype::FOUR), // name_index
1654 Field(Datatype::TWO), // num_elements
1655 Field(Datatype::ONE), // attribute_count
1656 Field(Datatype::STRUCT, 2), // attribute_info
1657 };
1658 std::vector<AttributeInfo*> attribute_info;
1659
1660 //!
1661 //! \brief Constructor of AddressInfo class.
1662 //! \param [in] version.
1663 //! Version of current ISA file.
1664 //!
1665 AddressInfo(unsigned version) {
1666 if (version <= 303) setVersion303();
1667 }
1668
1669 //!
1670 //! \brief Destructor of AddressInfo class.
1671 //!
1672 ~AddressInfo() {
1673 for (AttributeInfo *s : attribute_info)
1674 {
1675 if (s)
1676 {
1677 delete s;
1678 }
1679 }
1680 }
1681
1682 //!
1683 //! \brief Returns the integer value of the NameIndex field.
1684 //! \details NameIndex field is at index 0 in the internal
1685 //! array of Fields.
1686 //! \retval An integer.
1687 //!
1688 uint32_t getNameIndex() {
1689 return (uint32_t)fields[0].number32;
1690 }
1691
1692 //!
1693 //! \brief Sets the integer value of the NameIndex field.
1694 //! \details NameIndex field is at index 0 in the internal
1695 //! array of Fields.
1696 //! \param [in] value.
1697 //! Integer be assigned.
1698 //!
1699 void setNameIndex(uint32_t value) {
1700 fields[0].number32 = value;
1701 }
1702
1703 //!
1704 //! \brief Returns the integer value of the NumElements field.
1705 //! \details NumElements field is at index 1 in the internal
1706 //! array of Fields.
1707 //! \retval An integer.
1708 //!
1709 uint16_t getNumElements() {
1710 return (uint16_t)fields[1].number16;
1711 }
1712
1713 //!
1714 //! \brief Sets the integer value of the NumElements field.
1715 //! \details NumElements field is at index 1 in the internal
1716 //! array of Fields.
1717 //! \param [in] value.
1718 //! Integer be assigned.
1719 //!
1720 void setNumElements(uint16_t value) {
1721 fields[1].number16 = value;
1722 }
1723
1724 //!
1725 //! \brief Returns the integer value of the AttributeCount field.
1726 //! \details AttributeCount field is at index 2 in the internal
1727 //! array of Fields.
1728 //! \retval An integer.
1729 //!
1730 uint8_t getAttributeCount() {
1731 return (uint8_t)fields[2].number8;
1732 }
1733
1734 //!
1735 //! \brief Sets the integer value of the AttributeCount field.
1736 //! \details AttributeCount field is at index 2 in the internal
1737 //! array of Fields.
1738 //! \param [in] value.
1739 //! Integer be assigned.
1740 //!
1741 void setAttributeCount(uint8_t value) {
1742 fields[2].number8 = value;
1743 }
1744
1745 //!
1746 //! \brief Returns the reference to the vector of AttributeInfo objects.
1747 //! \details AddressInfo has a vector of AttributeInfo objects
1748 //! that represents another entity within the vISA object format.
1749 //! \retval Reference to the vector of AttributeInfo*.
1750 //!
1751 std::vector<AttributeInfo*> &getAttributeInfo() {
1752 return attribute_info;
1753 }
1754
1755 //!
1756 //! \brief Parses one AddressInfo object from ISA file.
1757 //! \details Reads and parses all the fields of the AddressInfo object
1758 //! from the file buffer and returns the pointer immediately
1759 //! after all this data.
1760 //! If this class contains internal structs, their Parse
1761 //! functions are called when corresponding.
1762 //! \param [in] p.
1763 //! Pointer to file buffer to start reading.
1764 //! \param [in] end.
1765 //! Pointer to end of file buffer.
1766 //! \param [in] m.
1767 //! Pointer ISAfile object.
1768 //! \retval Pointer to file buffe after parsing one AddressInfo object.
1769 //!
1770 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
1771 unsigned i = 0, count = 0;
1772 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
1773 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
1774 if (!p) return m->setError("bad offset/size for AddressInfo's field", i);
1775 i++;
1776 }
1777 // AttributeInfo
1778 count = fields[fields[i].countField].number32;
1779 attribute_info.resize(count);
1780 for (unsigned j = 0; j < count; j++) {
1781 AttributeInfo *r = new AttributeInfo(m->getCurrentVISAVersion());
1782 p = r->parse(p, end, m);
1783 if (!p) {
1784 delete r;
1785 return 0;
1786 }
1787 attribute_info[j] = r;
1788 }
1789 i++;
1790 return p;
1791 }
1792
1793 //!
1794 //! \brief Adds all the AddressInfo's fields to a buffer.
1795 //! \details Every field from this class is added to a buffer
1796 //! in order to be written into an ISA file afterwards
1797 //! If this class contains other internal structus, their addToBuffer
1798 //! functions are called when corresponding.
1799 //! \param [out] buffer.
1800 //! The buffer where the fields data will be added.
1801 //! \param [in] m.
1802 //! Pointer to ISAfile object.
1803 //!
1804 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
1805 unsigned i = 0;
1806 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
1807 m->addToBuffer(fields[i], buffer);
1808 i++;
1809 }
1810 // AttributeInfo
1811 for (AttributeInfo *r : attribute_info) {
1812 r->addToBuffer(buffer, m);
1813 }
1814 i++;
1815 }
1816
1817 //!
1818 //! \brief Makes the changes needed to support 303 version's AddressInfo.
1819 //! \details This function is called when the current ISA file has the 303 version.
1820 //! Initially all the objects are created with last version's format, so
1821 //! in order to suppport previous versions, changes of datatypes and insertion/removal
1822 //! of fields can be needed.
1823 //!
1824 void setVersion303() {
1825 fields[0] = Datatype::TWO;
1826 }
1827 MEDIA_CLASS_DEFINE_END(vp__vISA__AddressInfo)
1828 };
1829
1830 //!
1831 //! \brief Variable Class.
1832 //! \details This class represents the Variable from vISA Object Format.
1833 //! Provides getters, setters for its fields and structs as well as
1834 //! functions to read/write it from/to file.
1835 //!
1836 class Variable {
1837 public:
1838 std::array<Field, 8> fields = std::array<Field, 8>
1839 {
1840 Field(Datatype::FOUR), // name_index
1841 Field(Datatype::ONE), // bit_properties
1842 Field(Datatype::TWO), // num_elements
1843 Field(Datatype::FOUR), // alias_index
1844 Field(Datatype::TWO), // alias_offset
1845 Field(Datatype::ONE), // alias_scope_specifier
1846 Field(Datatype::ONE), // attribute_count
1847 Field(Datatype::STRUCT, 6), // attribute_info
1848 };
1849 std::vector<AttributeInfo*> attribute_info;
1850
1851 //!
1852 //! \brief Constructor of Variable class.
1853 //! \param [in] version.
1854 //! Version of current ISA file.
1855 //!
1856 Variable(unsigned version) {
1857 if (version <= 303) setVersion303();
1858 }
1859
1860 //!
1861 //! \brief Destructor of Variable class.
1862 //!
1863 ~Variable() {
1864 for (AttributeInfo *s : attribute_info)
1865 {
1866 if (s)
1867 {
1868 delete s;
1869 }
1870 }
1871 }
1872
1873 //!
1874 //! \brief Returns the integer value of the NameIndex field.
1875 //! \details NameIndex field is at index 0 in the internal
1876 //! array of Fields.
1877 //! \retval An integer.
1878 //!
1879 uint32_t getNameIndex() {
1880 return (uint32_t)fields[0].number32;
1881 }
1882
1883 //!
1884 //! \brief Sets the integer value of the NameIndex field.
1885 //! \details NameIndex field is at index 0 in the internal
1886 //! array of Fields.
1887 //! \param [in] value.
1888 //! Integer be assigned.
1889 //!
1890 void setNameIndex(uint32_t value) {
1891 fields[0].number32 = value;
1892 }
1893
1894 //!
1895 //! \brief Returns the integer value of the BitProperties field.
1896 //! \details BitProperties field is at index 1 in the internal
1897 //! array of Fields.
1898 //! \retval An integer.
1899 //!
1900 uint8_t getBitProperties() {
1901 return (uint8_t)fields[1].number8;
1902 }
1903
1904 //!
1905 //! \brief Sets the integer value of the BitProperties field.
1906 //! \details BitProperties field is at index 1 in the internal
1907 //! array of Fields.
1908 //! \param [in] value.
1909 //! Integer be assigned.
1910 //!
1911 void setBitProperties(uint8_t value) {
1912 fields[1].number8 = value;
1913 }
1914
1915 //!
1916 //! \brief Returns the integer value of the NumElements field.
1917 //! \details NumElements field is at index 2 in the internal
1918 //! array of Fields.
1919 //! \retval An integer.
1920 //!
1921 uint16_t getNumElements() {
1922 return (uint16_t)fields[2].number16;
1923 }
1924
1925 //!
1926 //! \brief Sets the integer value of the NumElements field.
1927 //! \details NumElements field is at index 2 in the internal
1928 //! array of Fields.
1929 //! \param [in] value.
1930 //! Integer be assigned.
1931 //!
1932 void setNumElements(uint16_t value) {
1933 fields[2].number16 = value;
1934 }
1935
1936 //!
1937 //! \brief Returns the integer value of the AliasIndex field.
1938 //! \details AliasIndex field is at index 3 in the internal
1939 //! array of Fields.
1940 //! \retval An integer.
1941 //!
1942 uint32_t getAliasIndex() {
1943 return (uint32_t)fields[3].number32;
1944 }
1945
1946 //!
1947 //! \brief Sets the integer value of the AliasIndex field.
1948 //! \details AliasIndex field is at index 3 in the internal
1949 //! array of Fields.
1950 //! \param [in] value.
1951 //! Integer be assigned.
1952 //!
1953 void setAliasIndex(uint32_t value) {
1954 fields[3].number32 = value;
1955 }
1956
1957 //!
1958 //! \brief Returns the integer value of the AliasOffset field.
1959 //! \details AliasOffset field is at index 4 in the internal
1960 //! array of Fields.
1961 //! \retval An integer.
1962 //!
1963 uint16_t getAliasOffset() {
1964 return (uint16_t)fields[4].number16;
1965 }
1966
1967 //!
1968 //! \brief Sets the integer value of the AliasOffset field.
1969 //! \details AliasOffset field is at index 4 in the internal
1970 //! array of Fields.
1971 //! \param [in] value.
1972 //! Integer be assigned.
1973 //!
1974 void setAliasOffset(uint16_t value) {
1975 fields[4].number16 = value;
1976 }
1977
1978 //!
1979 //! \brief Returns the integer value of the AliasScopeSpecifier field.
1980 //! \details AliasScopeSpecifier field is at index 5 in the internal
1981 //! array of Fields.
1982 //! \retval An integer.
1983 //!
1984 uint8_t getAliasScopeSpecifier() {
1985 return (uint8_t)fields[5].number8;
1986 }
1987
1988 //!
1989 //! \brief Sets the integer value of the AliasScopeSpecifier field.
1990 //! \details AliasScopeSpecifier field is at index 5 in the internal
1991 //! array of Fields.
1992 //! \param [in] value.
1993 //! Integer be assigned.
1994 //!
1995 void setAliasScopeSpecifier(uint8_t value) {
1996 fields[5].number8 = value;
1997 }
1998
1999 //!
2000 //! \brief Returns the integer value of the AttributeCount field.
2001 //! \details AttributeCount field is at index 6 in the internal
2002 //! array of Fields.
2003 //! \retval An integer.
2004 //!
2005 uint8_t getAttributeCount() {
2006 return (uint8_t)fields[6].number8;
2007 }
2008
2009 //!
2010 //! \brief Sets the integer value of the AttributeCount field.
2011 //! \details AttributeCount field is at index 6 in the internal
2012 //! array of Fields.
2013 //! \param [in] value.
2014 //! Integer be assigned.
2015 //!
2016 void setAttributeCount(uint8_t value) {
2017 fields[6].number8 = value;
2018 }
2019
2020 //!
2021 //! \brief Returns the reference to the vector of AttributeInfo objects.
2022 //! \details Variable has a vector of AttributeInfo objects
2023 //! that represents another entity within the vISA object format.
2024 //! \retval Reference to the vector of AttributeInfo*.
2025 //!
2026 std::vector<AttributeInfo*> &getAttributeInfo() {
2027 return attribute_info;
2028 }
2029
2030 //!
2031 //! \brief Parses one Variable object from ISA file.
2032 //! \details Reads and parses all the fields of the Variable object
2033 //! from the file buffer and returns the pointer immediately
2034 //! after all this data.
2035 //! If this class contains internal structs, their Parse
2036 //! functions are called when corresponding.
2037 //! \param [in] p.
2038 //! Pointer to file buffer to start reading.
2039 //! \param [in] end.
2040 //! Pointer to end of file buffer.
2041 //! \param [in] m.
2042 //! Pointer ISAfile object.
2043 //! \retval Pointer to file buffe after parsing one Variable object.
2044 //!
2045 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
2046 unsigned i = 0, count = 0;
2047 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
2048 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
2049 if (!p) return m->setError("bad offset/size for Variable's field", i);
2050 i++;
2051 }
2052 // AttributeInfo
2053 count = fields[fields[i].countField].number32;
2054 attribute_info.resize(count);
2055 for (unsigned j = 0; j < count; j++) {
2056 AttributeInfo *r = new AttributeInfo(m->getCurrentVISAVersion());
2057 p = r->parse(p, end, m);
2058 if (!p) {
2059 delete r;
2060 return 0;
2061 }
2062 attribute_info[j] = r;
2063 }
2064 i++;
2065 return p;
2066 }
2067
2068 //!
2069 //! \brief Adds all the Variable's fields to a buffer.
2070 //! \details Every field from this class is added to a buffer
2071 //! in order to be written into an ISA file afterwards
2072 //! If this class contains other internal structus, their addToBuffer
2073 //! functions are called when corresponding.
2074 //! \param [out] buffer.
2075 //! The buffer where the fields data will be added.
2076 //! \param [in] m.
2077 //! Pointer to ISAfile object.
2078 //!
2079 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
2080 unsigned i = 0;
2081 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
2082 m->addToBuffer(fields[i], buffer);
2083 i++;
2084 }
2085 // AttributeInfo
2086 for (AttributeInfo *r : attribute_info) {
2087 r->addToBuffer(buffer, m);
2088 }
2089 i++;
2090 }
2091
2092 //!
2093 //! \brief Makes the changes needed to support 303 version's Variable.
2094 //! \details This function is called when the current ISA file has the 303 version.
2095 //! Initially all the objects are created with last version's format, so
2096 //! in order to suppport previous versions, changes of datatypes and insertion/removal
2097 //! of fields can be needed.
2098 //!
2099 void setVersion303() {
2100 fields[0] = Datatype::TWO;
2101 fields[3] = Datatype::TWO;
2102 }
2103 MEDIA_CLASS_DEFINE_END(vp__vISA__Variable)
2104 };
2105
2106 //!
2107 //! \brief StringPool Class.
2108 //! \details This class represents the StringPool from vISA Object Format.
2109 //! Provides getters, setters for its fields and structs as well as
2110 //! functions to read/write it from/to file.
2111 //!
2112 class StringPool {
2113 public:
2114 std::array<Field, 1> fields = std::array<Field, 1>
2115 {
2116 Field(Datatype::VARCHAR_POOL) // string
2117 };
2118
2119 //!
2120 //! \brief Constructor of StringPool class.
2121 //! \param [in] version.
2122 //! Version of current ISA file.
2123 //!
2124 StringPool(unsigned version) {}
2125
2126 //!
2127 //! \brief Copy Constructor of StringPool class.
2128 //! \param [in] other.
2129 //! Reference to object to copy..
2130 //!
2131 StringPool(const StringPool& other) {
2132 fields = other.fields;
2133 }
2134
2135 //!
2136 //! \brief Assignment operator.
2137 //! \param [in] other.
2138 //! Reference to object to copy..
2139 //!
2140 StringPool& operator= (const StringPool& other) {
2141 if (this != &other) {
2142 fields = other.fields;
2143 }
2144 return *this;
2145 }
2146
2147 //!
2148 //! \brief Destructor of StringPool class.
2149 //!
2150 ~StringPool() {
2151 }
2152
2153 //!
2154 //! \brief Returns the string value of the String field.
2155 //! \details String field is at index 0 in the internal
2156 //! array of Fields.
2157 //! \retval A pointer to the string (const char*).
2158 //!
2159 const char * getString() {
2160 return fields[0].varchar;
2161 }
2162
2163 //!
2164 //! \brief Sets the string value of the String field.
2165 //! \details String field is at index 0 in the internal
2166 //! array of Fields.
2167 //! \param [in] value.
2168 //! Pointer to string (char*) to be assigned.
2169 //!
2170 void setString(char * value) {
2171 fields[0].varchar = value;
2172 }
2173
2174 //!
2175 //! \brief Parses one StringPool object from ISA file.
2176 //! \details Reads and parses all the fields of the StringPool object
2177 //! from the file buffer and returns the pointer immediately
2178 //! after all this data.
2179 //! If this class contains internal structs, their Parse
2180 //! functions are called when corresponding.
2181 //! \param [in] p.
2182 //! Pointer to file buffer to start reading.
2183 //! \param [in] end.
2184 //! Pointer to end of file buffer.
2185 //! \param [in] m.
2186 //! Pointer ISAfile object.
2187 //! \retval Pointer to file buffe after parsing one StringPool object.
2188 //!
2189 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
2190 unsigned i = 0;
2191 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
2192 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
2193 if (!p) return m->setError("bad offset/size for StringPool's field", i);
2194 i++;
2195 }
2196 return p;
2197 }
2198
2199 //!
2200 //! \brief Adds all the StringPool's fields to a buffer.
2201 //! \details Every field from this class is added to a buffer
2202 //! in order to be written into an ISA file afterwards
2203 //! If this class contains other internal structus, their addToBuffer
2204 //! functions are called when corresponding.
2205 //! \param [out] buffer.
2206 //! The buffer where the fields data will be added.
2207 //! \param [in] m.
2208 //! Pointer to ISAfile object.
2209 //!
2210 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
2211 unsigned i = 0;
2212 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
2213 m->addToBuffer(fields[i], buffer);
2214 i++;
2215 }
2216 }
2217 MEDIA_CLASS_DEFINE_END(vp__vISA__StringPool)
2218 };
2219
2220 //!
2221 //! \brief GenBinary Class.
2222 //! \details This class represents the GenBinary from vISA Object Format.
2223 //! Provides getters, setters for its fields and structs as well as
2224 //! functions to read/write it from/to file.
2225 //!
2226 class GenBinary {
2227 public:
2228 std::array<Field, 3> fields = std::array<Field, 3>
2229 {
2230 Field(Datatype::ONE), // gen_platform
2231 Field(Datatype::FOUR), // binary_offset
2232 Field(Datatype::FOUR) // binary_size
2233 };
2234
2235 //!
2236 //! \brief Constructor of GenBinary class.
2237 //! \param [in] version.
2238 //! Version of current ISA file.
2239 //!
2240 GenBinary(unsigned version) {}
2241
2242 //!
2243 //! \brief Constructor of GenBinary class.
2244 //!
2245 GenBinary() {}
2246
2247 //!
2248 //! \brief Copy Constructor of GenBinary class.
2249 //! \param [in] other.
2250 //! Reference to object to copy..
2251 //!
2252 GenBinary(const GenBinary& other) {
2253 fields = other.fields;
2254 }
2255
2256 //!
2257 //! \brief Assignment operator.
2258 //! \param [in] other.
2259 //! Reference to object to copy..
2260 //!
2261 GenBinary& operator= (const GenBinary& other) {
2262 if (this != &other) {
2263 fields = other.fields;
2264 }
2265 return *this;
2266 }
2267
2268 //!
2269 //! \brief Destructor of GenBinary class.
2270 //!
2271 ~GenBinary() {
2272 }
2273
2274 //!
2275 //! \brief Returns the integer value of the GenPlatform field.
2276 //! \details GenPlatform field is at index 0 in the internal
2277 //! array of Fields.
2278 //! \retval An integer.
2279 //!
2280 uint8_t getGenPlatform() {
2281 return (uint8_t)fields[0].number8;
2282 }
2283
2284 //!
2285 //! \brief Sets the integer value of the GenPlatform field.
2286 //! \details GenPlatform field is at index 0 in the internal
2287 //! array of Fields.
2288 //! \param [in] value.
2289 //! Integer be assigned.
2290 //!
2291 void setGenPlatform(uint8_t value) {
2292 fields[0].number8 = value;
2293 }
2294
2295 //!
2296 //! \brief Returns the integer value of the BinaryOffset field.
2297 //! \details BinaryOffset field is at index 1 in the internal
2298 //! array of Fields.
2299 //! \retval An integer.
2300 //!
2301 uint32_t getBinaryOffset() {
2302 return (uint32_t)fields[1].number32;
2303 }
2304
2305 //!
2306 //! \brief Sets the integer value of the BinaryOffset field.
2307 //! \details BinaryOffset field is at index 1 in the internal
2308 //! array of Fields.
2309 //! \param [in] value.
2310 //! Integer be assigned.
2311 //!
2312 void setBinaryOffset(uint32_t value) {
2313 fields[1].number32 = value;
2314 }
2315
2316 //!
2317 //! \brief Returns the integer value of the BinarySize field.
2318 //! \details BinarySize field is at index 2 in the internal
2319 //! array of Fields.
2320 //! \retval An integer.
2321 //!
2322 uint32_t getBinarySize() {
2323 return (uint32_t)fields[2].number32;
2324 }
2325
2326 //!
2327 //! \brief Sets the integer value of the BinarySize field.
2328 //! \details BinarySize field is at index 2 in the internal
2329 //! array of Fields.
2330 //! \param [in] value.
2331 //! Integer be assigned.
2332 //!
2333 void setBinarySize(uint32_t value) {
2334 fields[2].number32 = value;
2335 }
2336
2337 //!
2338 //! \brief Parses one GenBinary object from ISA file.
2339 //! \details Reads and parses all the fields of the GenBinary object
2340 //! from the file buffer and returns the pointer immediately
2341 //! after all this data.
2342 //! If this class contains internal structs, their Parse
2343 //! functions are called when corresponding.
2344 //! \param [in] p.
2345 //! Pointer to file buffer to start reading.
2346 //! \param [in] end.
2347 //! Pointer to end of file buffer.
2348 //! \param [in] m.
2349 //! Pointer ISAfile object.
2350 //! \retval Pointer to file buffe after parsing one GenBinary object.
2351 //!
2352 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
2353 unsigned i = 0;
2354 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
2355 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
2356 if (!p) return m->setError("bad offset/size for GenBinary's field", i);
2357 i++;
2358 }
2359 return p;
2360 }
2361
2362 //!
2363 //! \brief Adds all the GenBinary's fields to a buffer.
2364 //! \details Every field from this class is added to a buffer
2365 //! in order to be written into an ISA file afterwards
2366 //! If this class contains other internal structus, their addToBuffer
2367 //! functions are called when corresponding.
2368 //! \param [out] buffer.
2369 //! The buffer where the fields data will be added.
2370 //! \param [in] m.
2371 //! Pointer to ISAfile object.
2372 //!
2373 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
2374 unsigned i = 0;
2375 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
2376 m->addToBuffer(fields[i], buffer);
2377 i++;
2378 }
2379 }
2380 MEDIA_CLASS_DEFINE_END(vp__vISA__GenBinary)
2381 };
2382
2383 //!
2384 //! \brief Function Class.
2385 //! \details This class represents the Function from vISA Object Format.
2386 //! Provides getters, setters for its fields and structs as well as
2387 //! functions to read/write it from/to file.
2388 //!
2389 class Function {
2390 public:
2391 std::array<Field, 9> fields = std::array<Field, 9>
2392 {
2393 Field(Datatype::ONE), // linkage
2394 Field(Datatype::TWO), // name_len
2395 Field(Datatype::VARCHAR, 1), // name
2396 Field(Datatype::FOUR), // offset
2397 Field(Datatype::FOUR), // size
2398 Field(Datatype::TWO), // num_syms_variable
2399 Field(Datatype::STRUCT, 5), // variable_reloc_symtab
2400 Field(Datatype::TWO), // num_syms_function
2401 Field(Datatype::STRUCT, 7), // function_reloc_symtab
2402 };
2403 std::vector<RelocationInfo*> variable_reloc_symtab;
2404 std::vector<RelocationInfo*> function_reloc_symtab;
2405
2406 //!
2407 //! \brief Constructor of Function class.
2408 //! \param [in] version.
2409 //! Version of current ISA file.
2410 //!
2411 Function(unsigned version) {
2412 if (version <= 306) setVersion306();
2413 }
2414
2415 //!
2416 //! \brief Constructor of Function class.
2417 //!
2418 Function() {}
2419
2420 //!
2421 //! \brief Copy Constructor of Function class.
2422 //! \param [in] other.
2423 //! Reference to object to copy..
2424 //!
2425 Function(const Function& other) {
2426 fields = other.fields;
2427 for (RelocationInfo *r : other.variable_reloc_symtab) {
2428 RelocationInfo *s = new RelocationInfo();
2429 *s = *r;
2430 variable_reloc_symtab.push_back(s);
2431 }
2432 for (RelocationInfo *r : other.function_reloc_symtab) {
2433 RelocationInfo *s = new RelocationInfo();
2434 *s = *r;
2435 function_reloc_symtab.push_back(s);
2436 }
2437 }
2438
2439 //!
2440 //! \brief Assignment operator.
2441 //! \param [in] other.
2442 //! Reference to object to copy..
2443 //!
2444 Function& operator= (const Function& other) {
2445 if (this != &other) {
2446 fields = other.fields;
2447 for (RelocationInfo *r : variable_reloc_symtab)
2448 delete r;
2449 for (RelocationInfo *r : other.variable_reloc_symtab) {
2450 RelocationInfo *s = new RelocationInfo();
2451 *s = *r;
2452 variable_reloc_symtab.push_back(s);
2453 }
2454 for (RelocationInfo *r : function_reloc_symtab)
2455 delete r;
2456 for (RelocationInfo *r : other.function_reloc_symtab) {
2457 RelocationInfo *s = new RelocationInfo();
2458 *s = *r;
2459 function_reloc_symtab.push_back(s);
2460 }
2461 }
2462 return *this;
2463 }
2464
2465 //!
2466 //! \brief Destructor of Function class.
2467 //!
2468 ~Function() {
2469 for (RelocationInfo *s : variable_reloc_symtab) delete s;
2470 for (RelocationInfo *s : function_reloc_symtab) delete s;
2471 }
2472
2473 //!
2474 //! \brief Returns the integer value of the Linkage field.
2475 //! \details Linkage field is at index 0 in the internal
2476 //! array of Fields.
2477 //! \retval An integer.
2478 //!
2479 uint8_t getLinkage() {
2480 return (uint8_t)fields[0].number8;
2481 }
2482
2483 //!
2484 //! \brief Sets the integer value of the Linkage field.
2485 //! \details Linkage field is at index 0 in the internal
2486 //! array of Fields.
2487 //! \param [in] value.
2488 //! Integer be assigned.
2489 //!
2490 void setLinkage(uint8_t value) {
2491 fields[0].number8 = value;
2492 }
2493
2494 //!
2495 //! \brief Returns the integer value of the NameLen field.
2496 //! \details NameLen field is at index 1 in the internal
2497 //! array of Fields for version <= 306
2498 //! \retval An integer.
2499 //!
2500 uint8_t getNameLen_Ver306() {
2501 return (uint8_t)fields[1].number8;
2502 }
2503
2504 //!
2505 //! \brief Returns the integer value of the NameLen field.
2506 //! \details NameLen field is at index 1 in the internal
2507 //! array of Fields
2508 //! \retval An integer.
2509 //!
2510 uint16_t getNameLen() {
2511 return (uint16_t)fields[1].number16;
2512 }
2513
2514 //!
2515 //! \brief Sets the integer value of the NameLen field.
2516 //! \details NameLen field is at index 1 in the internal
2517 //! array of Fields for version <= 306
2518 //! \param [in] value.
2519 //! Integer be assigned.
2520 //!
2521 void setNameLen_Ver306(uint8_t value) {
2522 fields[1].number8 = value;
2523 }
2524
2525 //!
2526 //! \brief Sets the integer value of the NameLen field.
2527 //! \details NameLen field is at index 1 in the internal
2528 //! array of Fields.
2529 //! \param [in] value.
2530 //! Integer be assigned.
2531 //!
2532 void setNameLen(uint16_t value)
2533 {
2534 fields[1].number16 = value;
2535 }
2536
2537 //!
2538 //! \brief Returns the string value of the Name field.
2539 //! \details Name field is at index 2 in the internal
2540 //! array of Fields.
2541 //! \retval A pointer to the string (const char*).
2542 //!
2543 const char * getName() {
2544 return fields[2].varchar;
2545 }
2546
2547 //!
2548 //! \brief Sets the string value of the Name field.
2549 //! \details Name field is at index 2 in the internal
2550 //! array of Fields.
2551 //! \param [in] value.
2552 //! Pointer to string (char*) to be assigned.
2553 //!
2554 void setName(char * value) {
2555 fields[2].varchar = value;
2556 }
2557
2558 //!
2559 //! \brief Returns the integer value of the Offset field.
2560 //! \details Offset field is at index 3 in the internal
2561 //! array of Fields.
2562 //! \retval An integer.
2563 //!
2564 uint32_t getOffset() {
2565 return (uint32_t)fields[3].number32;
2566 }
2567
2568 //!
2569 //! \brief Sets the integer value of the Offset field.
2570 //! \details Offset field is at index 3 in the internal
2571 //! array of Fields.
2572 //! \param [in] value.
2573 //! Integer be assigned.
2574 //!
2575 void setOffset(uint32_t value) {
2576 fields[3].number32 = value;
2577 }
2578
2579 //!
2580 //! \brief Returns the integer value of the Size field.
2581 //! \details Size field is at index 4 in the internal
2582 //! array of Fields.
2583 //! \retval An integer.
2584 //!
2585 uint32_t getSize() {
2586 return (uint32_t)fields[4].number32;
2587 }
2588
2589 //!
2590 //! \brief Sets the integer value of the Size field.
2591 //! \details Size field is at index 4 in the internal
2592 //! array of Fields.
2593 //! \param [in] value.
2594 //! Integer be assigned.
2595 //!
2596 void setSize(uint32_t value) {
2597 fields[4].number32 = value;
2598 }
2599
2600 //!
2601 //! \brief Returns the integer value of the NumSymsVariable field.
2602 //! \details NumSymsVariable field is at index 5 in the internal
2603 //! array of Fields.
2604 //! \retval An integer.
2605 //!
2606 uint16_t getNumSymsVariable() {
2607 return (uint16_t)fields[5].number16;
2608 }
2609
2610 //!
2611 //! \brief Sets the integer value of the NumSymsVariable field.
2612 //! \details NumSymsVariable field is at index 5 in the internal
2613 //! array of Fields.
2614 //! \param [in] value.
2615 //! Integer be assigned.
2616 //!
2617 void setNumSymsVariable(uint16_t value) {
2618 fields[5].number16 = value;
2619 }
2620
2621 //!
2622 //! \brief Returns the reference to the vector of RelocationInfo objects.
2623 //! \details Function has a vector of RelocationInfo objects
2624 //! that represents another entity within the vISA object format.
2625 //! \retval Reference to the vector of RelocationInfo*.
2626 //!
2627 std::vector<RelocationInfo*> &getVariableRelocSymtab() {
2628 return variable_reloc_symtab;
2629 }
2630
2631 //!
2632 //! \brief Returns the integer value of the NumSymsFunction field.
2633 //! \details NumSymsFunction field is at index 7 in the internal
2634 //! array of Fields.
2635 //! \retval An integer.
2636 //!
2637 uint16_t getNumSymsFunction() {
2638 return (uint16_t)fields[7].number16;
2639 }
2640
2641 //!
2642 //! \brief Sets the integer value of the NumSymsFunction field.
2643 //! \details NumSymsFunction field is at index 7 in the internal
2644 //! array of Fields.
2645 //! \param [in] value.
2646 //! Integer be assigned.
2647 //!
2648 void setNumSymsFunction(uint16_t value) {
2649 fields[7].number16 = value;
2650 }
2651
2652 //!
2653 //! \brief Returns the reference to the vector of RelocationInfo objects.
2654 //! \details Function has a vector of RelocationInfo objects
2655 //! that represents another entity within the vISA object format.
2656 //! \retval Reference to the vector of RelocationInfo*.
2657 //!
2658 std::vector<RelocationInfo*> &getFunctionRelocSymtab() {
2659 return function_reloc_symtab;
2660 }
2661
2662 //!
2663 //! \brief Parses one Function object from ISA file.
2664 //! \details Reads and parses all the fields of the Function object
2665 //! from the file buffer and returns the pointer immediately
2666 //! after all this data.
2667 //! If this class contains internal structs, their Parse
2668 //! functions are called when corresponding.
2669 //! \param [in] p.
2670 //! Pointer to file buffer to start reading.
2671 //! \param [in] end.
2672 //! Pointer to end of file buffer.
2673 //! \param [in] m.
2674 //! Pointer ISAfile object.
2675 //! \retval Pointer to file buffe after parsing one Function object.
2676 //!
2677 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
2678 unsigned i = 0, count = 0;
2679 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
2680 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
2681 if (!p) return m->setError("bad offset/size for Function's field", i);
2682 i++;
2683 }
2684 // RelocationInfo
2685 count = fields[fields[i].countField].number32;
2686 variable_reloc_symtab.resize(count);
2687 for (unsigned j = 0; j < count; j++) {
2688 RelocationInfo *r = new RelocationInfo(m->getCurrentVISAVersion());
2689 p = r->parse(p, end, m);
2690 if (!p) {
2691 delete r;
2692 return 0;
2693 }
2694 variable_reloc_symtab[j] = r;
2695 }
2696 i++;
2697 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
2698 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
2699 if (!p) return m->setError("bad offset/size for Function's field", i);
2700 i++;
2701 }
2702 // RelocationInfo
2703 count = fields[fields[i].countField].number32;
2704 function_reloc_symtab.resize(count);
2705 for (unsigned j = 0; j < count; j++) {
2706 RelocationInfo *r = new RelocationInfo(m->getCurrentVISAVersion());
2707 p = r->parse(p, end, m);
2708 if (!p) {
2709 delete r;
2710 return 0;
2711 }
2712 function_reloc_symtab[j] = r;
2713 }
2714 i++;
2715 return p;
2716 }
2717
2718 //!
2719 //! \brief Adds all the Function's fields to a buffer.
2720 //! \details Every field from this class is added to a buffer
2721 //! in order to be written into an ISA file afterwards
2722 //! If this class contains other internal structus, their addToBuffer
2723 //! functions are called when corresponding.
2724 //! \param [out] buffer.
2725 //! The buffer where the fields data will be added.
2726 //! \param [in] m.
2727 //! Pointer to ISAfile object.
2728 //!
2729 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
2730 unsigned i = 0;
2731 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
2732 m->addToBuffer(fields[i], buffer);
2733 i++;
2734 }
2735 // RelocationInfo
2736 for (RelocationInfo *r : variable_reloc_symtab) {
2737 r->addToBuffer(buffer, m);
2738 }
2739 i++;
2740 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
2741 m->addToBuffer(fields[i], buffer);
2742 i++;
2743 }
2744 // RelocationInfo
2745 for (RelocationInfo *r : function_reloc_symtab) {
2746 r->addToBuffer(buffer, m);
2747 }
2748 i++;
2749 }
2750
2751 //!
2752 //! \brief Makes the changes needed to support 306 version's Function.
2753 //! \details This function is called when the current ISA file has the 306 version.
2754 //! Initially all the objects are created with last version's format, so
2755 //! in order to suppport newer versions, changes of datatypes and insertion/removal
2756 //! of fields can be needed.
2757 //!
2758 void setVersion306()
2759 {
2760 fields[1] = Datatype::ONE;
2761 }
2762 MEDIA_CLASS_DEFINE_END(vp__vISA__Function)
2763 };
2764
2765 //!
2766 //! \brief GlobalVariable Class.
2767 //! \details This class represents the GlobalVariable from vISA Object Format.
2768 //! Provides getters, setters for its fields and structs as well as
2769 //! functions to read/write it from/to file.
2770 //!
2771 class GlobalVariable {
2772 public:
2773 std::array<Field, 7> fields = std::array<Field, 7>
2774 {
2775 Field(Datatype::ONE), // linkage
2776 Field(Datatype::TWO), // name_len
2777 Field(Datatype::VARCHAR, 1), // name
2778 Field(Datatype::ONE), // bit_properties
2779 Field(Datatype::TWO), // num_elements
2780 Field(Datatype::ONE), // attribute_count
2781 Field(Datatype::STRUCT, 5), // attribute_info
2782 };
2783 std::vector<AttributeInfo*> attribute_info;
2784
2785 //!
2786 //! \brief Constructor of GlobalVariable class.
2787 //! \param [in] version.
2788 //! Version of current ISA file.
2789 //!
2790 GlobalVariable(unsigned version) {}
2791
2792 //!
2793 //! \brief Constructor of GlobalVariable class.
2794 //!
2795 GlobalVariable() {}
2796
2797 //!
2798 //! \brief Copy Constructor of GlobalVariable class.
2799 //! \param [in] other.
2800 //! Reference to object to copy..
2801 //!
2802 GlobalVariable(const GlobalVariable& other) {
2803 fields = other.fields;
2804 for (AttributeInfo *r : other.attribute_info) {
2805 AttributeInfo *s = new AttributeInfo();
2806 *s = *r;
2807 attribute_info.push_back(s);
2808 }
2809 }
2810
2811 //!
2812 //! \brief Assignment operator.
2813 //! \param [in] other.
2814 //! Reference to object to copy..
2815 //!
2816 GlobalVariable& operator= (const GlobalVariable& other) {
2817 if (this != &other) {
2818 fields = other.fields;
2819 for (AttributeInfo *r : attribute_info)
2820 delete r;
2821 for (AttributeInfo *r : other.attribute_info) {
2822 AttributeInfo *s = new AttributeInfo();
2823 *s = *r;
2824 attribute_info.push_back(s);
2825 }
2826 }
2827 return *this;
2828 }
2829
2830 //!
2831 //! \brief Destructor of GlobalVariable class.
2832 //!
2833 ~GlobalVariable() {
2834 for (AttributeInfo *s : attribute_info)
2835 {
2836 if (s)
2837 {
2838 delete s;
2839 }
2840 }
2841 }
2842
2843 //!
2844 //! \brief Returns the integer value of the Linkage field.
2845 //! \details Linkage field is at index 0 in the internal
2846 //! array of Fields.
2847 //! \retval An integer.
2848 //!
2849 uint8_t getLinkage() {
2850 return (uint8_t)fields[0].number8;
2851 }
2852
2853 //!
2854 //! \brief Sets the integer value of the Linkage field.
2855 //! \details Linkage field is at index 0 in the internal
2856 //! array of Fields.
2857 //! \param [in] value.
2858 //! Integer be assigned.
2859 //!
2860 void setLinkage(uint8_t value) {
2861 fields[0].number8 = value;
2862 }
2863
2864 //!
2865 //! \brief Returns the integer value of the NameLen field.
2866 //! \details NameLen field is at index 1 in the internal
2867 //! array of Fields.
2868 //! \retval An integer.
2869 //!
2870 uint16_t getNameLen() {
2871 return (uint16_t)fields[1].number16;
2872 }
2873
2874 //!
2875 //! \brief Sets the integer value of the NameLen field.
2876 //! \details NameLen field is at index 1 in the internal
2877 //! array of Fields.
2878 //! \param [in] value.
2879 //! Integer be assigned.
2880 //!
2881 void setNameLen(uint16_t value) {
2882 fields[1].number16 = value;
2883 }
2884
2885 //!
2886 //! \brief Returns the string value of the Name field.
2887 //! \details Name field is at index 2 in the internal
2888 //! array of Fields.
2889 //! \retval A pointer to the string (const char*).
2890 //!
2891 const char * getName() {
2892 return fields[2].varchar;
2893 }
2894
2895 //!
2896 //! \brief Sets the string value of the Name field.
2897 //! \details Name field is at index 2 in the internal
2898 //! array of Fields.
2899 //! \param [in] value.
2900 //! Pointer to string (char*) to be assigned.
2901 //!
2902 void setName(char * value) {
2903 fields[2].varchar = value;
2904 }
2905
2906 //!
2907 //! \brief Returns the integer value of the BitProperties field.
2908 //! \details BitProperties field is at index 3 in the internal
2909 //! array of Fields.
2910 //! \retval An integer.
2911 //!
2912 uint8_t getBitProperties() {
2913 return (uint8_t)fields[3].number8;
2914 }
2915
2916 //!
2917 //! \brief Sets the integer value of the BitProperties field.
2918 //! \details BitProperties field is at index 3 in the internal
2919 //! array of Fields.
2920 //! \param [in] value.
2921 //! Integer be assigned.
2922 //!
2923 void setBitProperties(uint8_t value) {
2924 fields[3].number8 = value;
2925 }
2926
2927 //!
2928 //! \brief Returns the integer value of the NumElements field.
2929 //! \details NumElements field is at index 4 in the internal
2930 //! array of Fields.
2931 //! \retval An integer.
2932 //!
2933 uint16_t getNumElements() {
2934 return (uint16_t)fields[4].number16;
2935 }
2936
2937 //!
2938 //! \brief Sets the integer value of the NumElements field.
2939 //! \details NumElements field is at index 4 in the internal
2940 //! array of Fields.
2941 //! \param [in] value.
2942 //! Integer be assigned.
2943 //!
2944 void setNumElements(uint16_t value) {
2945 fields[4].number16 = value;
2946 }
2947
2948 //!
2949 //! \brief Returns the integer value of the AttributeCount field.
2950 //! \details AttributeCount field is at index 5 in the internal
2951 //! array of Fields.
2952 //! \retval An integer.
2953 //!
2954 uint8_t getAttributeCount() {
2955 return (uint8_t)fields[5].number8;
2956 }
2957
2958 //!
2959 //! \brief Sets the integer value of the AttributeCount field.
2960 //! \details AttributeCount field is at index 5 in the internal
2961 //! array of Fields.
2962 //! \param [in] value.
2963 //! Integer be assigned.
2964 //!
2965 void setAttributeCount(uint8_t value) {
2966 fields[5].number8 = value;
2967 }
2968
2969 //!
2970 //! \brief Returns the reference to the vector of AttributeInfo objects.
2971 //! \details GlobalVariable has a vector of AttributeInfo objects
2972 //! that represents another entity within the vISA object format.
2973 //! \retval Reference to the vector of AttributeInfo*.
2974 //!
2975 std::vector<AttributeInfo*> &getAttributeInfo() {
2976 return attribute_info;
2977 }
2978
2979 //!
2980 //! \brief Parses one GlobalVariable object from ISA file.
2981 //! \details Reads and parses all the fields of the GlobalVariable object
2982 //! from the file buffer and returns the pointer immediately
2983 //! after all this data.
2984 //! If this class contains internal structs, their Parse
2985 //! functions are called when corresponding.
2986 //! \param [in] p.
2987 //! Pointer to file buffer to start reading.
2988 //! \param [in] end.
2989 //! Pointer to end of file buffer.
2990 //! \param [in] m.
2991 //! Pointer ISAfile object.
2992 //! \retval Pointer to file buffe after parsing one GlobalVariable object.
2993 //!
2994 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
2995 unsigned i = 0, count = 0;
2996 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
2997 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
2998 if (!p) return m->setError("bad offset/size for GlobalVariable's field", i);
2999 i++;
3000 }
3001 // AttributeInfo
3002 count = fields[fields[i].countField].number32;
3003 attribute_info.resize(count);
3004 for (unsigned j = 0; j < count; j++) {
3005 AttributeInfo *r = new AttributeInfo(m->getCurrentVISAVersion());
3006 p = r->parse(p, end, m);
3007 if (!p) {
3008 delete r;
3009 return 0;
3010 }
3011 attribute_info[j] = r;
3012 }
3013 i++;
3014 return p;
3015 }
3016
3017 //!
3018 //! \brief Adds all the GlobalVariable's fields to a buffer.
3019 //! \details Every field from this class is added to a buffer
3020 //! in order to be written into an ISA file afterwards
3021 //! If this class contains other internal structus, their addToBuffer
3022 //! functions are called when corresponding.
3023 //! \param [out] buffer.
3024 //! The buffer where the fields data will be added.
3025 //! \param [in] m.
3026 //! Pointer to ISAfile object.
3027 //!
3028 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
3029 unsigned i = 0;
3030 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3031 m->addToBuffer(fields[i], buffer);
3032 i++;
3033 }
3034 // AttributeInfo
3035 for (AttributeInfo *r : attribute_info) {
3036 r->addToBuffer(buffer, m);
3037 }
3038 i++;
3039 }
3040 MEDIA_CLASS_DEFINE_END(vp__vISA__GlobalVariable)
3041 };
3042
3043 //!
3044 //! \brief FunctionBody Class.
3045 //! \details This class represents the FunctionBody from vISA Object Format.
3046 //! Provides getters, setters for its fields and structs as well as
3047 //! functions to read/write it from/to file.
3048 //!
3049 class FunctionBody {
3050 public:
3051 std::array<Field, 24> fields = std::array<Field, 24>
3052 {
3053 Field(Datatype::FOUR), // string_count
3054 Field(Datatype::STRUCT, 0), // string_pool
3055 Field(Datatype::FOUR), // name_index
3056 Field(Datatype::FOUR), // variable_count
3057 Field(Datatype::STRUCT, 3), // var_info
3058 Field(Datatype::TWO), // address_count
3059 Field(Datatype::STRUCT, 5), // address_info
3060 Field(Datatype::TWO), // predicate_count
3061 Field(Datatype::STRUCT, 7), // predicate_info
3062 Field(Datatype::TWO), // label_count
3063 Field(Datatype::STRUCT, 9), // label_info
3064 Field(Datatype::ONE), // sampler_count
3065 Field(Datatype::STRUCT, 11), // sampler_info
3066 Field(Datatype::ONE), // surface_count
3067 Field(Datatype::STRUCT, 13), // surface_info
3068 Field(Datatype::ONE), // vme_count
3069 Field(Datatype::STRUCT, 15), // vme_info
3070 Field(Datatype::FOUR), // size
3071 Field(Datatype::FOUR), // entry
3072 Field(Datatype::ONE), // input_size
3073 Field(Datatype::ONE), // return_value_size
3074 Field(Datatype::TWO), // attribute_count
3075 Field(Datatype::STRUCT, 21), // attribute_info
3076 Field(Datatype::GDATA, 17) // instructions
3077 };
3078 std::vector<StringPool*> string_pool;
3079 std::vector<Variable*> var_info;
3080 std::vector<AddressInfo*> address_info;
3081 std::vector<PredicateInfo*> predicate_info;
3082 std::vector<LabelInfo*> label_info;
3083 std::vector<SamplerInfo*> sampler_info;
3084 std::vector<SurfaceInfo*> surface_info;
3085 std::vector<VmeInfo*> vme_info;
3086 std::vector<AttributeInfo*> attribute_info;
3087
3088 //!
3089 //! \brief Constructor of FunctionBody class.
3090 //! \param [in] version.
3091 //! Version of current ISA file.
3092 //!
3093 FunctionBody(unsigned version) {
3094 if (version <= 303) setVersion303();
3095 }
3096
3097 //!
3098 //! \brief Destructor of FunctionBody class.
3099 //!
3100 ~FunctionBody() {
3101 for (StringPool *s : string_pool) delete s;
3102 for (Variable *s : var_info) delete s;
3103 for (AddressInfo *s : address_info) delete s;
3104 for (PredicateInfo *s : predicate_info) delete s;
3105 for (LabelInfo *s : label_info) delete s;
3106 for (SamplerInfo *s : sampler_info) delete s;
3107 for (SurfaceInfo *s : surface_info) delete s;
3108 for (VmeInfo *s : vme_info) delete s;
3109 for (AttributeInfo *s : attribute_info) delete s;
3110 }
3111
3112 //!
3113 //! \brief Returns the integer value of the StringCount field.
3114 //! \details StringCount field is at index 0 in the internal
3115 //! array of Fields.
3116 //! \retval An integer.
3117 //!
3118 uint32_t getStringCount() {
3119 return (uint32_t)fields[0].number32;
3120 }
3121
3122 //!
3123 //! \brief Sets the integer value of the StringCount field.
3124 //! \details StringCount field is at index 0 in the internal
3125 //! array of Fields.
3126 //! \param [in] value.
3127 //! Integer be assigned.
3128 //!
3129 void setStringCount(uint32_t value) {
3130 fields[0].number32 = value;
3131 }
3132
3133 //!
3134 //! \brief Returns the reference to the vector of StringPool objects.
3135 //! \details FunctionBody has a vector of StringPool objects
3136 //! that represents another entity within the vISA object format.
3137 //! \retval Reference to the vector of StringPool*.
3138 //!
3139 std::vector<StringPool*> &getStringPool() {
3140 return string_pool;
3141 }
3142
3143 //!
3144 //! \brief Returns the integer value of the NameIndex field.
3145 //! \details NameIndex field is at index 2 in the internal
3146 //! array of Fields.
3147 //! \retval An integer.
3148 //!
3149 uint32_t getNameIndex() {
3150 return (uint32_t)fields[2].number32;
3151 }
3152
3153 //!
3154 //! \brief Sets the integer value of the NameIndex field.
3155 //! \details NameIndex field is at index 2 in the internal
3156 //! array of Fields.
3157 //! \param [in] value.
3158 //! Integer be assigned.
3159 //!
3160 void setNameIndex(uint32_t value) {
3161 fields[2].number32 = value;
3162 }
3163
3164 //!
3165 //! \brief Returns the integer value of the VariableCount field.
3166 //! \details VariableCount field is at index 3 in the internal
3167 //! array of Fields.
3168 //! \retval An integer.
3169 //!
3170 uint32_t getVariableCount() {
3171 return (uint32_t)fields[3].number32;
3172 }
3173
3174 //!
3175 //! \brief Sets the integer value of the VariableCount field.
3176 //! \details VariableCount field is at index 3 in the internal
3177 //! array of Fields.
3178 //! \param [in] value.
3179 //! Integer be assigned.
3180 //!
3181 void setVariableCount(uint32_t value) {
3182 fields[3].number32 = value;
3183 }
3184
3185 //!
3186 //! \brief Returns the reference to the vector of Variable objects.
3187 //! \details FunctionBody has a vector of Variable objects
3188 //! that represents another entity within the vISA object format.
3189 //! \retval Reference to the vector of Variable*.
3190 //!
3191 std::vector<Variable*> &getVarInfo() {
3192 return var_info;
3193 }
3194
3195 //!
3196 //! \brief Returns the integer value of the AddressCount field.
3197 //! \details AddressCount field is at index 5 in the internal
3198 //! array of Fields.
3199 //! \retval An integer.
3200 //!
3201 uint16_t getAddressCount() {
3202 return (uint16_t)fields[5].number16;
3203 }
3204
3205 //!
3206 //! \brief Sets the integer value of the AddressCount field.
3207 //! \details AddressCount field is at index 5 in the internal
3208 //! array of Fields.
3209 //! \param [in] value.
3210 //! Integer be assigned.
3211 //!
3212 void setAddressCount(uint16_t value) {
3213 fields[5].number16 = value;
3214 }
3215
3216 //!
3217 //! \brief Returns the reference to the vector of AddressInfo objects.
3218 //! \details FunctionBody has a vector of AddressInfo objects
3219 //! that represents another entity within the vISA object format.
3220 //! \retval Reference to the vector of AddressInfo*.
3221 //!
3222 std::vector<AddressInfo*> &getAddressInfo() {
3223 return address_info;
3224 }
3225
3226 //!
3227 //! \brief Returns the integer value of the PredicateCount field.
3228 //! \details PredicateCount field is at index 7 in the internal
3229 //! array of Fields.
3230 //! \retval An integer.
3231 //!
3232 uint16_t getPredicateCount() {
3233 return (uint16_t)fields[7].number16;
3234 }
3235
3236 //!
3237 //! \brief Sets the integer value of the PredicateCount field.
3238 //! \details PredicateCount field is at index 7 in the internal
3239 //! array of Fields.
3240 //! \param [in] value.
3241 //! Integer be assigned.
3242 //!
3243 void setPredicateCount(uint16_t value) {
3244 fields[7].number16 = value;
3245 }
3246
3247 //!
3248 //! \brief Returns the reference to the vector of PredicateInfo objects.
3249 //! \details FunctionBody has a vector of PredicateInfo objects
3250 //! that represents another entity within the vISA object format.
3251 //! \retval Reference to the vector of PredicateInfo*.
3252 //!
3253 std::vector<PredicateInfo*> &getPredicateInfo() {
3254 return predicate_info;
3255 }
3256
3257 //!
3258 //! \brief Returns the integer value of the LabelCount field.
3259 //! \details LabelCount field is at index 9 in the internal
3260 //! array of Fields.
3261 //! \retval An integer.
3262 //!
3263 uint16_t getLabelCount() {
3264 return (uint16_t)fields[9].number16;
3265 }
3266
3267 //!
3268 //! \brief Sets the integer value of the LabelCount field.
3269 //! \details LabelCount field is at index 9 in the internal
3270 //! array of Fields.
3271 //! \param [in] value.
3272 //! Integer be assigned.
3273 //!
3274 void setLabelCount(uint16_t value) {
3275 fields[9].number16 = value;
3276 }
3277
3278 //!
3279 //! \brief Returns the reference to the vector of LabelInfo objects.
3280 //! \details FunctionBody has a vector of LabelInfo objects
3281 //! that represents another entity within the vISA object format.
3282 //! \retval Reference to the vector of LabelInfo*.
3283 //!
3284 std::vector<LabelInfo*> &getLabelInfo() {
3285 return label_info;
3286 }
3287
3288 //!
3289 //! \brief Returns the integer value of the SamplerCount field.
3290 //! \details SamplerCount field is at index 11 in the internal
3291 //! array of Fields.
3292 //! \retval An integer.
3293 //!
3294 uint8_t getSamplerCount() {
3295 return (uint8_t)fields[11].number8;
3296 }
3297
3298 //!
3299 //! \brief Sets the integer value of the SamplerCount field.
3300 //! \details SamplerCount field is at index 11 in the internal
3301 //! array of Fields.
3302 //! \param [in] value.
3303 //! Integer be assigned.
3304 //!
3305 void setSamplerCount(uint8_t value) {
3306 fields[11].number8 = value;
3307 }
3308
3309 //!
3310 //! \brief Returns the reference to the vector of SamplerInfo objects.
3311 //! \details FunctionBody has a vector of SamplerInfo objects
3312 //! that represents another entity within the vISA object format.
3313 //! \retval Reference to the vector of SamplerInfo*.
3314 //!
3315 std::vector<SamplerInfo*> &getSamplerInfo() {
3316 return sampler_info;
3317 }
3318
3319 //!
3320 //! \brief Returns the integer value of the SurfaceCount field.
3321 //! \details SurfaceCount field is at index 13 in the internal
3322 //! array of Fields.
3323 //! \retval An integer.
3324 //!
3325 uint8_t getSurfaceCount() {
3326 return (uint8_t)fields[13].number8;
3327 }
3328
3329 //!
3330 //! \brief Sets the integer value of the SurfaceCount field.
3331 //! \details SurfaceCount field is at index 13 in the internal
3332 //! array of Fields.
3333 //! \param [in] value.
3334 //! Integer be assigned.
3335 //!
3336 void setSurfaceCount(uint8_t value) {
3337 fields[13].number8 = value;
3338 }
3339
3340 //!
3341 //! \brief Returns the reference to the vector of SurfaceInfo objects.
3342 //! \details FunctionBody has a vector of SurfaceInfo objects
3343 //! that represents another entity within the vISA object format.
3344 //! \retval Reference to the vector of SurfaceInfo*.
3345 //!
3346 std::vector<SurfaceInfo*> &getSurfaceInfo() {
3347 return surface_info;
3348 }
3349
3350 //!
3351 //! \brief Returns the integer value of the VmeCount field.
3352 //! \details VmeCount field is at index 15 in the internal
3353 //! array of Fields.
3354 //! \retval An integer.
3355 //!
3356 uint8_t getVmeCount() {
3357 return (uint8_t)fields[15].number8;
3358 }
3359
3360 //!
3361 //! \brief Sets the integer value of the VmeCount field.
3362 //! \details VmeCount field is at index 15 in the internal
3363 //! array of Fields.
3364 //! \param [in] value.
3365 //! Integer be assigned.
3366 //!
3367 void setVmeCount(uint8_t value) {
3368 fields[15].number8 = value;
3369 }
3370
3371 //!
3372 //! \brief Returns the reference to the vector of VmeInfo objects.
3373 //! \details FunctionBody has a vector of VmeInfo objects
3374 //! that represents another entity within the vISA object format.
3375 //! \retval Reference to the vector of VmeInfo*.
3376 //!
3377 std::vector<VmeInfo*> &getVmeInfo() {
3378 return vme_info;
3379 }
3380
3381 //!
3382 //! \brief Returns the integer value of the Size field.
3383 //! \details Size field is at index 17 in the internal
3384 //! array of Fields.
3385 //! \retval An integer.
3386 //!
3387 uint32_t getSize() {
3388 return (uint32_t)fields[17].number32;
3389 }
3390
3391 //!
3392 //! \brief Sets the integer value of the Size field.
3393 //! \details Size field is at index 17 in the internal
3394 //! array of Fields.
3395 //! \param [in] value.
3396 //! Integer be assigned.
3397 //!
3398 void setSize(uint32_t value) {
3399 fields[17].number32 = value;
3400 }
3401
3402 //!
3403 //! \brief Returns the integer value of the Entry field.
3404 //! \details Entry field is at index 18 in the internal
3405 //! array of Fields.
3406 //! \retval An integer.
3407 //!
3408 uint32_t getEntry() {
3409 return (uint32_t)fields[18].number32;
3410 }
3411
3412 //!
3413 //! \brief Sets the integer value of the Entry field.
3414 //! \details Entry field is at index 18 in the internal
3415 //! array of Fields.
3416 //! \param [in] value.
3417 //! Integer be assigned.
3418 //!
3419 void setEntry(uint32_t value) {
3420 fields[18].number32 = value;
3421 }
3422
3423 //!
3424 //! \brief Returns the integer value of the InputSize field.
3425 //! \details InputSize field is at index 19 in the internal
3426 //! array of Fields.
3427 //! \retval An integer.
3428 //!
3429 uint8_t getInputSize() {
3430 return (uint8_t)fields[19].number8;
3431 }
3432
3433 //!
3434 //! \brief Sets the integer value of the InputSize field.
3435 //! \details InputSize field is at index 19 in the internal
3436 //! array of Fields.
3437 //! \param [in] value.
3438 //! Integer be assigned.
3439 //!
3440 void setInputSize(uint8_t value) {
3441 fields[19].number8 = value;
3442 }
3443
3444 //!
3445 //! \brief Returns the integer value of the ReturnValueSize field.
3446 //! \details ReturnValueSize field is at index 20 in the internal
3447 //! array of Fields.
3448 //! \retval An integer.
3449 //!
3450 uint8_t getReturnValueSize() {
3451 return (uint8_t)fields[20].number8;
3452 }
3453
3454 //!
3455 //! \brief Sets the integer value of the ReturnValueSize field.
3456 //! \details ReturnValueSize field is at index 20 in the internal
3457 //! array of Fields.
3458 //! \param [in] value.
3459 //! Integer be assigned.
3460 //!
3461 void setReturnValueSize(uint8_t value) {
3462 fields[20].number8 = value;
3463 }
3464
3465 //!
3466 //! \brief Returns the integer value of the AttributeCount field.
3467 //! \details AttributeCount field is at index 21 in the internal
3468 //! array of Fields.
3469 //! \retval An integer.
3470 //!
3471 uint16_t getAttributeCount() {
3472 return (uint16_t)fields[21].number16;
3473 }
3474
3475 //!
3476 //! \brief Sets the integer value of the AttributeCount field.
3477 //! \details AttributeCount field is at index 21 in the internal
3478 //! array of Fields.
3479 //! \param [in] value.
3480 //! Integer be assigned.
3481 //!
3482 void setAttributeCount(uint16_t value) {
3483 fields[21].number16 = value;
3484 }
3485
3486 //!
3487 //! \brief Returns the reference to the vector of AttributeInfo objects.
3488 //! \details FunctionBody has a vector of AttributeInfo objects
3489 //! that represents another entity within the vISA object format.
3490 //! \retval Reference to the vector of AttributeInfo*.
3491 //!
3492 std::vector<AttributeInfo*> &getAttributeInfo() {
3493 return attribute_info;
3494 }
3495
3496 //!
3497 //! \brief Returns the pointer to buffer data from Instructions field.
3498 //! \details Instructions field is at index 23 in the internal
3499 //! array of Fields.
3500 //! \retval A pointer to buffer data (const uint8_t*).
3501 //!
3502 const uint8_t* getInstructions() {
3503 return fields[23].gdata;
3504 }
3505
3506 //!
3507 //! \brief Sets the pointer to buffer data of the Instructions field.
3508 //! \details Instructions field is at index 23 in the internal
3509 //! array of Fields.
3510 //! \param [in] value.
3511 //! Pointer to buffer data (uint8_t*) to be assigned.
3512 //!
3513 void setInstructions(uint8_t * value) {
3514 fields[23].gdata = value;
3515 }
3516
3517 //!
3518 //! \brief Parses one FunctionBody object from ISA file.
3519 //! \details Reads and parses all the fields of the FunctionBody object
3520 //! from the file buffer and returns the pointer immediately
3521 //! after all this data.
3522 //! If this class contains internal structs, their Parse
3523 //! functions are called when corresponding.
3524 //! \param [in] p.
3525 //! Pointer to file buffer to start reading.
3526 //! \param [in] end.
3527 //! Pointer to end of file buffer.
3528 //! \param [in] m.
3529 //! Pointer ISAfile object.
3530 //! \retval Pointer to file buffe after parsing one FunctionBody object.
3531 //!
3532 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
3533 unsigned i = 0, count = 0;
3534 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3535 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
3536 if (!p) return m->setError("bad offset/size for FunctionBody's field", i);
3537 i++;
3538 }
3539 // StringPool
3540 count = fields[fields[i].countField].number32;
3541 string_pool.resize(count);
3542 for (unsigned j = 0; j < count; j++) {
3543 StringPool *r = new StringPool(m->getCurrentVISAVersion());
3544 p = r->parse(p, end, m);
3545 if (!p) {
3546 delete r;
3547 return 0;
3548 }
3549 string_pool[j] = r;
3550 }
3551 i++;
3552 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3553 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
3554 if (!p) return m->setError("bad offset/size for FunctionBody's field", i);
3555 i++;
3556 }
3557 // Variable
3558 count = fields[fields[i].countField].number32;
3559 var_info.resize(count);
3560 for (unsigned j = 0; j < count; j++) {
3561 Variable *r = new Variable(m->getCurrentVISAVersion());
3562 p = r->parse(p, end, m);
3563 if (!p) {
3564 delete r;
3565 return 0;
3566 }
3567 var_info[j] = r;
3568 }
3569 i++;
3570 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3571 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
3572 if (!p) return m->setError("bad offset/size for FunctionBody's field", i);
3573 i++;
3574 }
3575 // AddressInfo
3576 count = fields[fields[i].countField].number32;
3577 address_info.resize(count);
3578 for (unsigned j = 0; j < count; j++) {
3579 AddressInfo *r = new AddressInfo(m->getCurrentVISAVersion());
3580 p = r->parse(p, end, m);
3581 if (!p) {
3582 delete r;
3583 return 0;
3584 }
3585 address_info[j] = r;
3586 }
3587 i++;
3588 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3589 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
3590 if (!p) return m->setError("bad offset/size for FunctionBody's field", i);
3591 i++;
3592 }
3593 // PredicateInfo
3594 count = fields[fields[i].countField].number32;
3595 predicate_info.resize(count);
3596 for (unsigned j = 0; j < count; j++) {
3597 PredicateInfo *r = new PredicateInfo(m->getCurrentVISAVersion());
3598 p = r->parse(p, end, m);
3599 if (!p) {
3600 delete r;
3601 return 0;
3602 }
3603 predicate_info[j] = r;
3604 }
3605 i++;
3606 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3607 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
3608 if (!p) return m->setError("bad offset/size for FunctionBody's field", i);
3609 i++;
3610 }
3611 // LabelInfo
3612 count = fields[fields[i].countField].number32;
3613 label_info.resize(count);
3614 for (unsigned j = 0; j < count; j++) {
3615 LabelInfo *r = new LabelInfo(m->getCurrentVISAVersion());
3616 p = r->parse(p, end, m);
3617 if (!p) {
3618 delete r;
3619 return 0;
3620 }
3621 label_info[j] = r;
3622 }
3623 i++;
3624 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3625 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
3626 if (!p) return m->setError("bad offset/size for FunctionBody's field", i);
3627 i++;
3628 }
3629 // SamplerInfo
3630 count = fields[fields[i].countField].number32;
3631 sampler_info.resize(count);
3632 for (unsigned j = 0; j < count; j++) {
3633 SamplerInfo *r = new SamplerInfo(m->getCurrentVISAVersion());
3634 p = r->parse(p, end, m);
3635 if (!p) {
3636 delete r;
3637 return 0;
3638 }
3639 sampler_info[j] = r;
3640 }
3641 i++;
3642 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3643 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
3644 if (!p) return m->setError("bad offset/size for FunctionBody's field", i);
3645 i++;
3646 }
3647 // SurfaceInfo
3648 count = fields[fields[i].countField].number32;
3649 surface_info.resize(count);
3650 for (unsigned j = 0; j < count; j++) {
3651 SurfaceInfo *r = new SurfaceInfo(m->getCurrentVISAVersion());
3652 p = r->parse(p, end, m);
3653 if (!p) {
3654 delete r;
3655 return 0;
3656 }
3657 surface_info[j] = r;
3658 }
3659 i++;
3660 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3661 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
3662 if (!p) return m->setError("bad offset/size for FunctionBody's field", i);
3663 i++;
3664 }
3665 // VmeInfo
3666 count = fields[fields[i].countField].number32;
3667 vme_info.resize(count);
3668 for (unsigned j = 0; j < count; j++) {
3669 VmeInfo *r = new VmeInfo(m->getCurrentVISAVersion());
3670 p = r->parse(p, end, m);
3671 if (!p) {
3672 delete r;
3673 return 0;
3674 }
3675 vme_info[j] = r;
3676 }
3677 i++;
3678 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3679 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
3680 if (!p) return m->setError("bad offset/size for FunctionBody's field", i);
3681 i++;
3682 }
3683 // AttributeInfo
3684 count = fields[fields[i].countField].number32;
3685 attribute_info.resize(count);
3686 for (unsigned j = 0; j < count; j++) {
3687 AttributeInfo *r = new AttributeInfo(m->getCurrentVISAVersion());
3688 p = r->parse(p, end, m);
3689 if (!p) {
3690 delete r;
3691 return 0;
3692 }
3693 attribute_info[j] = r;
3694 }
3695 i++;
3696 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3697 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
3698 if (!p) return m->setError("bad offset/size for FunctionBody's field", i);
3699 i++;
3700 }
3701 return p;
3702 }
3703
3704 //!
3705 //! \brief Adds all the FunctionBody's fields to a buffer.
3706 //! \details Every field from this class is added to a buffer
3707 //! in order to be written into an ISA file afterwards
3708 //! If this class contains other internal structus, their addToBuffer
3709 //! functions are called when corresponding.
3710 //! \param [out] buffer.
3711 //! The buffer where the fields data will be added.
3712 //! \param [in] m.
3713 //! Pointer to ISAfile object.
3714 //!
3715 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
3716 unsigned i = 0;
3717 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3718 m->addToBuffer(fields[i], buffer);
3719 i++;
3720 }
3721 // StringPool
3722 for (StringPool *r : string_pool) {
3723 r->addToBuffer(buffer, m);
3724 }
3725 i++;
3726 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3727 m->addToBuffer(fields[i], buffer);
3728 i++;
3729 }
3730 // Variable
3731 for (Variable *r : var_info) {
3732 r->addToBuffer(buffer, m);
3733 }
3734 i++;
3735 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3736 m->addToBuffer(fields[i], buffer);
3737 i++;
3738 }
3739 // AddressInfo
3740 for (AddressInfo *r : address_info) {
3741 r->addToBuffer(buffer, m);
3742 }
3743 i++;
3744 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3745 m->addToBuffer(fields[i], buffer);
3746 i++;
3747 }
3748 // PredicateInfo
3749 for (PredicateInfo *r : predicate_info) {
3750 r->addToBuffer(buffer, m);
3751 }
3752 i++;
3753 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3754 m->addToBuffer(fields[i], buffer);
3755 i++;
3756 }
3757 // LabelInfo
3758 for (LabelInfo *r : label_info) {
3759 r->addToBuffer(buffer, m);
3760 }
3761 i++;
3762 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3763 m->addToBuffer(fields[i], buffer);
3764 i++;
3765 }
3766 // SamplerInfo
3767 for (SamplerInfo *r : sampler_info) {
3768 r->addToBuffer(buffer, m);
3769 }
3770 i++;
3771 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3772 m->addToBuffer(fields[i], buffer);
3773 i++;
3774 }
3775 // SurfaceInfo
3776 for (SurfaceInfo *r : surface_info) {
3777 r->addToBuffer(buffer, m);
3778 }
3779 i++;
3780 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3781 m->addToBuffer(fields[i], buffer);
3782 i++;
3783 }
3784 // VmeInfo
3785 for (VmeInfo *r : vme_info) {
3786 r->addToBuffer(buffer, m);
3787 }
3788 i++;
3789 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3790 m->addToBuffer(fields[i], buffer);
3791 i++;
3792 }
3793 // AttributeInfo
3794 for (AttributeInfo *r : attribute_info) {
3795 r->addToBuffer(buffer, m);
3796 }
3797 i++;
3798 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
3799 m->addToBuffer(fields[i], buffer);
3800 i++;
3801 }
3802 }
3803
3804 //!
3805 //! \brief Makes the changes needed to support 303 version's FunctionBody.
3806 //! \details This function is called when the current ISA file has the 303 version.
3807 //! Initially all the objects are created with last version's format, so
3808 //! in order to suppport previous versions, changes of datatypes and insertion/removal
3809 //! of fields can be needed.
3810 //!
3811 void setVersion303() {
3812 fields[0] = Datatype::TWO;
3813 fields[2] = Datatype::TWO;
3814 fields[3] = Datatype::TWO;
3815 }
3816 MEDIA_CLASS_DEFINE_END(vp__vISA__FunctionBody)
3817 };
3818
3819 //!
3820 //! \brief KernelBody Class.
3821 //! \details This class represents the KernelBody from vISA Object Format.
3822 //! Provides getters, setters for its fields and structs as well as
3823 //! functions to read/write it from/to file.
3824 //!
3825 class KernelBody {
3826 public:
3827 std::array<Field, 24> fields = std::array<Field, 24>
3828 {
3829 Field(Datatype::FOUR), // string_count
3830 Field(Datatype::STRUCT, 0), // string_pool
3831 Field(Datatype::FOUR), // name_index
3832 Field(Datatype::FOUR), // variable_count
3833 Field(Datatype::STRUCT, 3), // var_info
3834 Field(Datatype::TWO), // address_count
3835 Field(Datatype::STRUCT, 5), // address_info
3836 Field(Datatype::TWO), // predicate_count
3837 Field(Datatype::STRUCT, 7), // predicate_info
3838 Field(Datatype::TWO), // label_count
3839 Field(Datatype::STRUCT, 9), // label_info
3840 Field(Datatype::ONE), // sampler_count
3841 Field(Datatype::STRUCT, 11), // sampler_info
3842 Field(Datatype::ONE), // surface_count
3843 Field(Datatype::STRUCT, 13), // surface_info
3844 Field(Datatype::ONE), // vme_count
3845 Field(Datatype::STRUCT, 15), // vme_info
3846 Field(Datatype::FOUR), // num_inputs
3847 Field(Datatype::STRUCT, 17), // input_info
3848 Field(Datatype::FOUR), // size
3849 Field(Datatype::FOUR), // entry
3850 Field(Datatype::TWO), // attribute_count
3851 Field(Datatype::STRUCT, 21), // attribute_info
3852 Field(Datatype::GDATA, 19) // instructions
3853 };
3854 std::vector<StringPool*> string_pool;
3855 std::vector<Variable*> var_info;
3856 std::vector<AddressInfo*> address_info;
3857 std::vector<PredicateInfo*> predicate_info;
3858 std::vector<LabelInfo*> label_info;
3859 std::vector<SamplerInfo*> sampler_info;
3860 std::vector<SurfaceInfo*> surface_info;
3861 std::vector<VmeInfo*> vme_info;
3862 std::vector<InputInfo*> input_info;
3863 std::vector<AttributeInfo*> attribute_info;
3864
3865 //!
3866 //! \brief Constructor of KernelBody class.
3867 //! \param [in] version.
3868 //! Version of current ISA file.
3869 //!
3870 KernelBody(unsigned version) {
3871 if (version <= 304) setVersion304();
3872 if (version <= 303) setVersion303();
3873 }
3874
3875 //!
3876 //! \brief Destructor of KernelBody class.
3877 //!
3878 ~KernelBody() {
3879 for (StringPool *s : string_pool) delete s;
3880 for (Variable *s : var_info) delete s;
3881 for (AddressInfo *s : address_info) delete s;
3882 for (PredicateInfo *s : predicate_info) delete s;
3883 for (LabelInfo *s : label_info) delete s;
3884 for (SamplerInfo *s : sampler_info) delete s;
3885 for (SurfaceInfo *s : surface_info) delete s;
3886 for (VmeInfo *s : vme_info) delete s;
3887 for (InputInfo *s : input_info) delete s;
3888 for (AttributeInfo *s : attribute_info) delete s;
3889 }
3890
3891 //!
3892 //! \brief Returns the integer value of the StringCount field.
3893 //! \details StringCount field is at index 0 in the internal
3894 //! array of Fields.
3895 //! \retval An integer.
3896 //!
3897 uint32_t getStringCount() {
3898 return (uint32_t)fields[0].number32;
3899 }
3900
3901 //!
3902 //! \brief Sets the integer value of the StringCount field.
3903 //! \details StringCount field is at index 0 in the internal
3904 //! array of Fields.
3905 //! \param [in] value.
3906 //! Integer be assigned.
3907 //!
3908 void setStringCount(uint32_t value) {
3909 fields[0].number32 = value;
3910 }
3911
3912 //!
3913 //! \brief Returns the reference to the vector of StringPool objects.
3914 //! \details KernelBody has a vector of StringPool objects
3915 //! that represents another entity within the vISA object format.
3916 //! \retval Reference to the vector of StringPool*.
3917 //!
3918 std::vector<StringPool*> &getStringPool() {
3919 return string_pool;
3920 }
3921
3922 //!
3923 //! \brief Returns the integer value of the NameIndex field.
3924 //! \details NameIndex field is at index 2 in the internal
3925 //! array of Fields.
3926 //! \retval An integer.
3927 //!
3928 uint32_t getNameIndex() {
3929 return (uint32_t)fields[2].number32;
3930 }
3931
3932 //!
3933 //! \brief Sets the integer value of the NameIndex field.
3934 //! \details NameIndex field is at index 2 in the internal
3935 //! array of Fields.
3936 //! \param [in] value.
3937 //! Integer be assigned.
3938 //!
3939 void setNameIndex(uint32_t value) {
3940 fields[2].number32 = value;
3941 }
3942
3943 //!
3944 //! \brief Returns the integer value of the VariableCount field.
3945 //! \details VariableCount field is at index 3 in the internal
3946 //! array of Fields.
3947 //! \retval An integer.
3948 //!
3949 uint32_t getVariableCount() {
3950 return (uint32_t)fields[3].number32;
3951 }
3952
3953 //!
3954 //! \brief Sets the integer value of the VariableCount field.
3955 //! \details VariableCount field is at index 3 in the internal
3956 //! array of Fields.
3957 //! \param [in] value.
3958 //! Integer be assigned.
3959 //!
3960 void setVariableCount(uint32_t value) {
3961 fields[3].number32 = value;
3962 }
3963
3964 //!
3965 //! \brief Returns the reference to the vector of Variable objects.
3966 //! \details KernelBody has a vector of Variable objects
3967 //! that represents another entity within the vISA object format.
3968 //! \retval Reference to the vector of Variable*.
3969 //!
3970 std::vector<Variable*> &getVarInfo() {
3971 return var_info;
3972 }
3973
3974 //!
3975 //! \brief Returns the integer value of the AddressCount field.
3976 //! \details AddressCount field is at index 5 in the internal
3977 //! array of Fields.
3978 //! \retval An integer.
3979 //!
3980 uint16_t getAddressCount() {
3981 return (uint16_t)fields[5].number16;
3982 }
3983
3984 //!
3985 //! \brief Sets the integer value of the AddressCount field.
3986 //! \details AddressCount field is at index 5 in the internal
3987 //! array of Fields.
3988 //! \param [in] value.
3989 //! Integer be assigned.
3990 //!
3991 void setAddressCount(uint16_t value) {
3992 fields[5].number16 = value;
3993 }
3994
3995 //!
3996 //! \brief Returns the reference to the vector of AddressInfo objects.
3997 //! \details KernelBody has a vector of AddressInfo objects
3998 //! that represents another entity within the vISA object format.
3999 //! \retval Reference to the vector of AddressInfo*.
4000 //!
4001 std::vector<AddressInfo*> &getAddressInfo() {
4002 return address_info;
4003 }
4004
4005 //!
4006 //! \brief Returns the integer value of the PredicateCount field.
4007 //! \details PredicateCount field is at index 7 in the internal
4008 //! array of Fields.
4009 //! \retval An integer.
4010 //!
4011 uint16_t getPredicateCount() {
4012 return (uint16_t)fields[7].number16;
4013 }
4014
4015 //!
4016 //! \brief Sets the integer value of the PredicateCount field.
4017 //! \details PredicateCount field is at index 7 in the internal
4018 //! array of Fields.
4019 //! \param [in] value.
4020 //! Integer be assigned.
4021 //!
4022 void setPredicateCount(uint16_t value) {
4023 fields[7].number16 = value;
4024 }
4025
4026 //!
4027 //! \brief Returns the reference to the vector of PredicateInfo objects.
4028 //! \details KernelBody has a vector of PredicateInfo objects
4029 //! that represents another entity within the vISA object format.
4030 //! \retval Reference to the vector of PredicateInfo*.
4031 //!
4032 std::vector<PredicateInfo*> &getPredicateInfo() {
4033 return predicate_info;
4034 }
4035
4036 //!
4037 //! \brief Returns the integer value of the LabelCount field.
4038 //! \details LabelCount field is at index 9 in the internal
4039 //! array of Fields.
4040 //! \retval An integer.
4041 //!
4042 uint16_t getLabelCount() {
4043 return (uint16_t)fields[9].number16;
4044 }
4045
4046 //!
4047 //! \brief Sets the integer value of the LabelCount field.
4048 //! \details LabelCount field is at index 9 in the internal
4049 //! array of Fields.
4050 //! \param [in] value.
4051 //! Integer be assigned.
4052 //!
4053 void setLabelCount(uint16_t value) {
4054 fields[9].number16 = value;
4055 }
4056
4057 //!
4058 //! \brief Returns the reference to the vector of LabelInfo objects.
4059 //! \details KernelBody has a vector of LabelInfo objects
4060 //! that represents another entity within the vISA object format.
4061 //! \retval Reference to the vector of LabelInfo*.
4062 //!
4063 std::vector<LabelInfo*> &getLabelInfo() {
4064 return label_info;
4065 }
4066
4067 //!
4068 //! \brief Returns the integer value of the SamplerCount field.
4069 //! \details SamplerCount field is at index 11 in the internal
4070 //! array of Fields.
4071 //! \retval An integer.
4072 //!
4073 uint8_t getSamplerCount() {
4074 return (uint8_t)fields[11].number8;
4075 }
4076
4077 //!
4078 //! \brief Sets the integer value of the SamplerCount field.
4079 //! \details SamplerCount field is at index 11 in the internal
4080 //! array of Fields.
4081 //! \param [in] value.
4082 //! Integer be assigned.
4083 //!
4084 void setSamplerCount(uint8_t value) {
4085 fields[11].number8 = value;
4086 }
4087
4088 //!
4089 //! \brief Returns the reference to the vector of SamplerInfo objects.
4090 //! \details KernelBody has a vector of SamplerInfo objects
4091 //! that represents another entity within the vISA object format.
4092 //! \retval Reference to the vector of SamplerInfo*.
4093 //!
4094 std::vector<SamplerInfo*> &getSamplerInfo() {
4095 return sampler_info;
4096 }
4097
4098 //!
4099 //! \brief Returns the integer value of the SurfaceCount field.
4100 //! \details SurfaceCount field is at index 13 in the internal
4101 //! array of Fields.
4102 //! \retval An integer.
4103 //!
4104 uint8_t getSurfaceCount() {
4105 return (uint8_t)fields[13].number8;
4106 }
4107
4108 //!
4109 //! \brief Sets the integer value of the SurfaceCount field.
4110 //! \details SurfaceCount field is at index 13 in the internal
4111 //! array of Fields.
4112 //! \param [in] value.
4113 //! Integer be assigned.
4114 //!
4115 void setSurfaceCount(uint8_t value) {
4116 fields[13].number8 = value;
4117 }
4118
4119 //!
4120 //! \brief Returns the reference to the vector of SurfaceInfo objects.
4121 //! \details KernelBody has a vector of SurfaceInfo objects
4122 //! that represents another entity within the vISA object format.
4123 //! \retval Reference to the vector of SurfaceInfo*.
4124 //!
4125 std::vector<SurfaceInfo*> &getSurfaceInfo() {
4126 return surface_info;
4127 }
4128
4129 //!
4130 //! \brief Returns the integer value of the VmeCount field.
4131 //! \details VmeCount field is at index 15 in the internal
4132 //! array of Fields.
4133 //! \retval An integer.
4134 //!
4135 uint8_t getVmeCount() {
4136 return (uint8_t)fields[15].number8;
4137 }
4138
4139 //!
4140 //! \brief Sets the integer value of the VmeCount field.
4141 //! \details VmeCount field is at index 15 in the internal
4142 //! array of Fields.
4143 //! \param [in] value.
4144 //! Integer be assigned.
4145 //!
4146 void setVmeCount(uint8_t value) {
4147 fields[15].number8 = value;
4148 }
4149
4150 //!
4151 //! \brief Returns the reference to the vector of VmeInfo objects.
4152 //! \details KernelBody has a vector of VmeInfo objects
4153 //! that represents another entity within the vISA object format.
4154 //! \retval Reference to the vector of VmeInfo*.
4155 //!
4156 std::vector<VmeInfo*> &getVmeInfo() {
4157 return vme_info;
4158 }
4159
4160 //!
4161 //! \brief Returns the integer value of the NumInputs field.
4162 //! \details NumInputs field is at index 17 in the internal
4163 //! array of Fields.
4164 //! \retval An integer.
4165 //!
4166 uint32_t getNumInputs() {
4167 return (uint32_t)fields[17].number32;
4168 }
4169
4170 //!
4171 //! \brief Sets the integer value of the NumInputs field.
4172 //! \details NumInputs field is at index 17 in the internal
4173 //! array of Fields.
4174 //! \param [in] value.
4175 //! Integer be assigned.
4176 //!
4177 void setNumInputs(uint32_t value) {
4178 fields[17].number32 = value;
4179 }
4180
4181 //!
4182 //! \brief Returns the reference to the vector of InputInfo objects.
4183 //! \details KernelBody has a vector of InputInfo objects
4184 //! that represents another entity within the vISA object format.
4185 //! \retval Reference to the vector of InputInfo*.
4186 //!
4187 std::vector<InputInfo*> &getInputInfo() {
4188 return input_info;
4189 }
4190
4191 //!
4192 //! \brief Returns the integer value of the Size field.
4193 //! \details Size field is at index 19 in the internal
4194 //! array of Fields.
4195 //! \retval An integer.
4196 //!
4197 uint32_t getSize() {
4198 return (uint32_t)fields[19].number32;
4199 }
4200
4201 //!
4202 //! \brief Sets the integer value of the Size field.
4203 //! \details Size field is at index 19 in the internal
4204 //! array of Fields.
4205 //! \param [in] value.
4206 //! Integer be assigned.
4207 //!
4208 void setSize(uint32_t value) {
4209 fields[19].number32 = value;
4210 }
4211
4212 //!
4213 //! \brief Returns the integer value of the Entry field.
4214 //! \details Entry field is at index 20 in the internal
4215 //! array of Fields.
4216 //! \retval An integer.
4217 //!
4218 uint32_t getEntry() {
4219 return (uint32_t)fields[20].number32;
4220 }
4221
4222 //!
4223 //! \brief Sets the integer value of the Entry field.
4224 //! \details Entry field is at index 20 in the internal
4225 //! array of Fields.
4226 //! \param [in] value.
4227 //! Integer be assigned.
4228 //!
4229 void setEntry(uint32_t value) {
4230 fields[20].number32 = value;
4231 }
4232
4233 //!
4234 //! \brief Returns the integer value of the AttributeCount field.
4235 //! \details AttributeCount field is at index 21 in the internal
4236 //! array of Fields.
4237 //! \retval An integer.
4238 //!
4239 uint16_t getAttributeCount() {
4240 return (uint16_t)fields[21].number16;
4241 }
4242
4243 //!
4244 //! \brief Sets the integer value of the AttributeCount field.
4245 //! \details AttributeCount field is at index 21 in the internal
4246 //! array of Fields.
4247 //! \param [in] value.
4248 //! Integer be assigned.
4249 //!
4250 void setAttributeCount(uint16_t value) {
4251 fields[21].number16 = value;
4252 }
4253
4254 //!
4255 //! \brief Returns the reference to the vector of AttributeInfo objects.
4256 //! \details KernelBody has a vector of AttributeInfo objects
4257 //! that represents another entity within the vISA object format.
4258 //! \retval Reference to the vector of AttributeInfo*.
4259 //!
4260 std::vector<AttributeInfo*> &getAttributeInfo() {
4261 return attribute_info;
4262 }
4263
4264 //!
4265 //! \brief Returns the pointer to buffer data from Instructions field.
4266 //! \details Instructions field is at index 23 in the internal
4267 //! array of Fields.
4268 //! \retval A pointer to buffer data (const uint8_t*).
4269 //!
4270 const uint8_t* getInstructions() {
4271 return fields[23].gdata;
4272 }
4273
4274 //!
4275 //! \brief Sets the pointer to buffer data of the Instructions field.
4276 //! \details Instructions field is at index 23 in the internal
4277 //! array of Fields.
4278 //! \param [in] value.
4279 //! Pointer to buffer data (uint8_t*) to be assigned.
4280 //!
4281 void setInstructions(uint8_t * value) {
4282 fields[23].gdata = value;
4283 }
4284
4285 //!
4286 //! \brief Parses one KernelBody object from ISA file.
4287 //! \details Reads and parses all the fields of the KernelBody object
4288 //! from the file buffer and returns the pointer immediately
4289 //! after all this data.
4290 //! If this class contains internal structs, their Parse
4291 //! functions are called when corresponding.
4292 //! \param [in] p.
4293 //! Pointer to file buffer to start reading.
4294 //! \param [in] end.
4295 //! Pointer to end of file buffer.
4296 //! \param [in] m.
4297 //! Pointer ISAfile object.
4298 //! \retval Pointer to file buffe after parsing one KernelBody object.
4299 //!
4300 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
4301 unsigned i = 0, count = 0;
4302 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4303 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4304 if (!p) return m->setError("bad offset/size for KernelBody's field", i);
4305 i++;
4306 }
4307 // StringPool
4308 count = fields[fields[i].countField].number32;
4309 string_pool.resize(count);
4310 for (unsigned j = 0; j < count; j++) {
4311 StringPool *r = new StringPool(m->getCurrentVISAVersion());
4312 p = r->parse(p, end, m);
4313 if (!p) {
4314 delete r;
4315 return 0;
4316 }
4317 string_pool[j] = r;
4318 }
4319 i++;
4320 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4321 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4322 if (!p) return m->setError("bad offset/size for KernelBody's field", i);
4323 i++;
4324 }
4325 // Variable
4326 count = fields[fields[i].countField].number32;
4327 var_info.resize(count);
4328 for (unsigned j = 0; j < count; j++) {
4329 Variable *r = new Variable(m->getCurrentVISAVersion());
4330 p = r->parse(p, end, m);
4331 if (!p) {
4332 delete r;
4333 return 0;
4334 }
4335 var_info[j] = r;
4336 }
4337 i++;
4338 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4339 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4340 if (!p) return m->setError("bad offset/size for KernelBody's field", i);
4341 i++;
4342 }
4343 // AddressInfo
4344 count = fields[fields[i].countField].number32;
4345 address_info.resize(count);
4346 for (unsigned j = 0; j < count; j++) {
4347 AddressInfo *r = new AddressInfo(m->getCurrentVISAVersion());
4348 p = r->parse(p, end, m);
4349 if (!p) {
4350 delete r;
4351 return 0;
4352 }
4353 address_info[j] = r;
4354 }
4355 i++;
4356 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4357 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4358 if (!p) return m->setError("bad offset/size for KernelBody's field", i);
4359 i++;
4360 }
4361 // PredicateInfo
4362 count = fields[fields[i].countField].number32;
4363 predicate_info.resize(count);
4364 for (unsigned j = 0; j < count; j++) {
4365 PredicateInfo *r = new PredicateInfo(m->getCurrentVISAVersion());
4366 p = r->parse(p, end, m);
4367 if (!p) {
4368 delete r;
4369 return 0;
4370 }
4371 predicate_info[j] = r;
4372 }
4373 i++;
4374 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4375 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4376 if (!p) return m->setError("bad offset/size for KernelBody's field", i);
4377 i++;
4378 }
4379 // LabelInfo
4380 count = fields[fields[i].countField].number32;
4381 label_info.resize(count);
4382 for (unsigned j = 0; j < count; j++) {
4383 LabelInfo *r = new LabelInfo(m->getCurrentVISAVersion());
4384 p = r->parse(p, end, m);
4385 if (!p) {
4386 delete r;
4387 return 0;
4388 }
4389 label_info[j] = r;
4390 }
4391 i++;
4392 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4393 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4394 if (!p) return m->setError("bad offset/size for KernelBody's field", i);
4395 i++;
4396 }
4397 // SamplerInfo
4398 count = fields[fields[i].countField].number32;
4399 sampler_info.resize(count);
4400 for (unsigned j = 0; j < count; j++) {
4401 SamplerInfo *r = new SamplerInfo(m->getCurrentVISAVersion());
4402 p = r->parse(p, end, m);
4403 if (!p) {
4404 delete r;
4405 return 0;
4406 }
4407 sampler_info[j] = r;
4408 }
4409 i++;
4410 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4411 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4412 if (!p) return m->setError("bad offset/size for KernelBody's field", i);
4413 i++;
4414 }
4415 // SurfaceInfo
4416 count = fields[fields[i].countField].number32;
4417 surface_info.resize(count);
4418 for (unsigned j = 0; j < count; j++) {
4419 SurfaceInfo *r = new SurfaceInfo(m->getCurrentVISAVersion());
4420 p = r->parse(p, end, m);
4421 if (!p) {
4422 delete r;
4423 return 0;
4424 }
4425 surface_info[j] = r;
4426 }
4427 i++;
4428 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4429 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4430 if (!p) return m->setError("bad offset/size for KernelBody's field", i);
4431 i++;
4432 }
4433 // VmeInfo
4434 count = fields[fields[i].countField].number32;
4435 vme_info.resize(count);
4436 for (unsigned j = 0; j < count; j++) {
4437 VmeInfo *r = new VmeInfo(m->getCurrentVISAVersion());
4438 p = r->parse(p, end, m);
4439 if (!p) {
4440 delete r;
4441 return 0;
4442 }
4443 vme_info[j] = r;
4444 }
4445 i++;
4446 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4447 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4448 if (!p) return m->setError("bad offset/size for KernelBody's field", i);
4449 i++;
4450 }
4451 // InputInfo
4452 count = fields[fields[i].countField].number32;
4453 input_info.resize(count);
4454 for (unsigned j = 0; j < count; j++) {
4455 InputInfo *r = new InputInfo(m->getCurrentVISAVersion());
4456 p = r->parse(p, end, m);
4457 if (!p) {
4458 delete r;
4459 return 0;
4460 }
4461 input_info[j] = r;
4462 }
4463 i++;
4464 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4465 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4466 if (!p) return m->setError("bad offset/size for KernelBody's field", i);
4467 i++;
4468 }
4469 // AttributeInfo
4470 count = fields[fields[i].countField].number32;
4471 attribute_info.resize(count);
4472 for (unsigned j = 0; j < count; j++) {
4473 AttributeInfo *r = new AttributeInfo(m->getCurrentVISAVersion());
4474 p = r->parse(p, end, m);
4475 if (!p) {
4476 delete r;
4477 return 0;
4478 }
4479 attribute_info[j] = r;
4480 }
4481 i++;
4482 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4483 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4484 if (!p) return m->setError("bad offset/size for KernelBody's field", i);
4485 i++;
4486 }
4487 return p;
4488 }
4489
4490 //!
4491 //! \brief Adds all the KernelBody's fields to a buffer.
4492 //! \details Every field from this class is added to a buffer
4493 //! in order to be written into an ISA file afterwards
4494 //! If this class contains other internal structus, their addToBuffer
4495 //! functions are called when corresponding.
4496 //! \param [out] buffer.
4497 //! The buffer where the fields data will be added.
4498 //! \param [in] m.
4499 //! Pointer to ISAfile object.
4500 //!
4501 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
4502 unsigned i = 0;
4503 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4504 m->addToBuffer(fields[i], buffer);
4505 i++;
4506 }
4507 // StringPool
4508 for (StringPool *r : string_pool) {
4509 r->addToBuffer(buffer, m);
4510 }
4511 i++;
4512 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4513 m->addToBuffer(fields[i], buffer);
4514 i++;
4515 }
4516 // Variable
4517 for (Variable *r : var_info) {
4518 r->addToBuffer(buffer, m);
4519 }
4520 i++;
4521 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4522 m->addToBuffer(fields[i], buffer);
4523 i++;
4524 }
4525 // AddressInfo
4526 for (AddressInfo *r : address_info) {
4527 r->addToBuffer(buffer, m);
4528 }
4529 i++;
4530 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4531 m->addToBuffer(fields[i], buffer);
4532 i++;
4533 }
4534 // PredicateInfo
4535 for (PredicateInfo *r : predicate_info) {
4536 r->addToBuffer(buffer, m);
4537 }
4538 i++;
4539 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4540 m->addToBuffer(fields[i], buffer);
4541 i++;
4542 }
4543 // LabelInfo
4544 for (LabelInfo *r : label_info) {
4545 r->addToBuffer(buffer, m);
4546 }
4547 i++;
4548 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4549 m->addToBuffer(fields[i], buffer);
4550 i++;
4551 }
4552 // SamplerInfo
4553 for (SamplerInfo *r : sampler_info) {
4554 r->addToBuffer(buffer, m);
4555 }
4556 i++;
4557 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4558 m->addToBuffer(fields[i], buffer);
4559 i++;
4560 }
4561 // SurfaceInfo
4562 for (SurfaceInfo *r : surface_info) {
4563 r->addToBuffer(buffer, m);
4564 }
4565 i++;
4566 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4567 m->addToBuffer(fields[i], buffer);
4568 i++;
4569 }
4570 // VmeInfo
4571 for (VmeInfo *r : vme_info) {
4572 r->addToBuffer(buffer, m);
4573 }
4574 i++;
4575 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4576 m->addToBuffer(fields[i], buffer);
4577 i++;
4578 }
4579 // InputInfo
4580 for (InputInfo *r : input_info) {
4581 r->addToBuffer(buffer, m);
4582 }
4583 i++;
4584 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4585 m->addToBuffer(fields[i], buffer);
4586 i++;
4587 }
4588 // AttributeInfo
4589 for (AttributeInfo *r : attribute_info) {
4590 r->addToBuffer(buffer, m);
4591 }
4592 i++;
4593 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4594 m->addToBuffer(fields[i], buffer);
4595 i++;
4596 }
4597 }
4598
4599 //!
4600 //! \brief Makes the changes needed to support 303 version's KernelBody.
4601 //! \details This function is called when the current ISA file has the 303 version.
4602 //! Initially all the objects are created with last version's format, so
4603 //! in order to suppport previous versions, changes of datatypes and insertion/removal
4604 //! of fields can be needed.
4605 //!
4606 void setVersion303() {
4607 fields[0] = Datatype::TWO;
4608 fields[2] = Datatype::TWO;
4609 fields[3] = Datatype::TWO;
4610 }
4611
4612 //!
4613 //! \brief Makes the changes needed to support 304 version's KernelBody.
4614 //! \details This function is called when the current ISA file has the 304 version.
4615 //! Initially all the objects are created with last version's format, so
4616 //! in order to suppport previous versions, changes of datatypes and insertion/removal
4617 //! of fields can be needed.
4618 //!
4619 void setVersion304() {
4620 fields[17] = Datatype::ONE;
4621 }
4622 MEDIA_CLASS_DEFINE_END(vp__vISA__KernelBody)
4623 };
4624
4625 //!
4626 //! \brief Kernel Class.
4627 //! \details This class represents the Kernel from vISA Object Format.
4628 //! Provides getters, setters for its fields and structs as well as
4629 //! functions to read/write it from/to file.
4630 //!
4631 class Kernel {
4632 public:
4633 std::array<Field, 11> fields = std::array<Field, 11>
4634 {
4635 Field(Datatype::TWO), // name_len
4636 Field(Datatype::VARCHAR, 0), // name
4637 Field(Datatype::FOUR), // offset
4638 Field(Datatype::FOUR), // size
4639 Field(Datatype::FOUR), // input_offset
4640 Field(Datatype::TWO), // num_syms_variable
4641 Field(Datatype::STRUCT, 5), // variable_reloc_symtab
4642 Field(Datatype::TWO), // num_syms_function
4643 Field(Datatype::STRUCT, 7), // function_reloc_symtab
4644 Field(Datatype::ONE), // num_gen_binaries
4645 Field(Datatype::STRUCT, 9), // gen_binary_info
4646 };
4647 std::vector<RelocationInfo*> variable_reloc_symtab;
4648 std::vector<RelocationInfo*> function_reloc_symtab;
4649 std::vector<GenBinary*> gen_binary_info;
4650
4651 //!
4652 //! \brief Constructor of Kernel class.
4653 //! \param [in] version.
4654 //! Version of current ISA file.
4655 //!
4656 Kernel(unsigned version) {
4657 if (version <= 306) setVersion306();
4658 }
4659
4660 //!
4661 //! \brief Constructor of Kernel class.
4662 //!
4663 Kernel() {}
4664
4665 //!
4666 //! \brief Copy Constructor of Kernel class.
4667 //! \param [in] other.
4668 //! Reference to object to copy..
4669 //!
4670 Kernel(const Kernel& other) {
4671 fields = other.fields;
4672 for (RelocationInfo *r : other.variable_reloc_symtab) {
4673 RelocationInfo *s = new RelocationInfo();
4674 *s = *r;
4675 variable_reloc_symtab.push_back(s);
4676 }
4677 for (RelocationInfo *r : other.function_reloc_symtab) {
4678 RelocationInfo *s = new RelocationInfo();
4679 *s = *r;
4680 function_reloc_symtab.push_back(s);
4681 }
4682 for (GenBinary *r : other.gen_binary_info) {
4683 GenBinary *s = new GenBinary();
4684 *s = *r;
4685 gen_binary_info.push_back(s);
4686 }
4687 }
4688
4689 //!
4690 //! \brief Assignment operator.
4691 //! \param [in] other.
4692 //! Reference to object to copy..
4693 //!
4694 Kernel& operator= (const Kernel& other) {
4695 if (this != &other) {
4696 fields = other.fields;
4697 for (RelocationInfo *r : variable_reloc_symtab)
4698 delete r;
4699 for (RelocationInfo *r : other.variable_reloc_symtab) {
4700 RelocationInfo *s = new RelocationInfo();
4701 *s = *r;
4702 variable_reloc_symtab.push_back(s);
4703 }
4704 for (RelocationInfo *r : function_reloc_symtab)
4705 delete r;
4706 for (RelocationInfo *r : other.function_reloc_symtab) {
4707 RelocationInfo *s = new RelocationInfo();
4708 *s = *r;
4709 function_reloc_symtab.push_back(s);
4710 }
4711 for (GenBinary *r : gen_binary_info)
4712 delete r;
4713 for (GenBinary *r : other.gen_binary_info) {
4714 GenBinary *s = new GenBinary();
4715 *s = *r;
4716 gen_binary_info.push_back(s);
4717 }
4718 }
4719 return *this;
4720 }
4721
4722 //!
4723 //! \brief Destructor of Kernel class.
4724 //!
4725 ~Kernel() {
4726 for (RelocationInfo *s : variable_reloc_symtab) delete s;
4727 for (RelocationInfo *s : function_reloc_symtab) delete s;
4728 for (GenBinary *s : gen_binary_info) delete s;
4729 }
4730
4731 //!
4732 //! \brief Returns the integer value of the NameLen field.
4733 //! \details NameLen field is at index 0 in the internal
4734 //! array of Fields for vesrion <= 306
4735 //! \retval An integer.
4736 //!
4737 uint8_t getNameLen_Ver306() {
4738 return (uint8_t)fields[0].number8;
4739 }
4740
4741 //!
4742 //! \brief Returns the integer value of the NameLen field.
4743 //! \details NameLen field is at index 0 in the internal
4744 //! array of Fields.
4745 //! \retval An integer.
4746 //!
4747 uint16_t getNameLen()
4748 {
4749 return (uint16_t)fields[0].number16;
4750 }
4751
4752 //!
4753 //! \brief Sets the integer value of the NameLen field.
4754 //! \details NameLen field is at index 0 in the internal
4755 //! array of Fields for version <= 306
4756 //! \param [in] value.
4757 //! Integer be assigned.
4758 //!
4759 void setNameLen_Ver306(uint8_t value) {
4760 fields[0].number8 = value;
4761 }
4762
4763 //!
4764 //! \brief Sets the integer value of the NameLen field.
4765 //! \details NameLen field is at index 0 in the internal
4766 //! array of Fields.
4767 //! \param [in] value.
4768 //! Integer be assigned.
4769 //!
4770 void setNameLen(uint16_t value)
4771 {
4772 fields[0].number16 = value;
4773 }
4774
4775 //!
4776 //! \brief Returns the string value of the Name field.
4777 //! \details Name field is at index 1 in the internal
4778 //! array of Fields.
4779 //! \retval A pointer to the string (const char*).
4780 //!
4781 const char * getName() {
4782 return fields[1].varchar;
4783 }
4784
4785 //!
4786 //! \brief Sets the string value of the Name field.
4787 //! \details Name field is at index 1 in the internal
4788 //! array of Fields.
4789 //! \param [in] value.
4790 //! Pointer to string (char*) to be assigned.
4791 //!
4792 void setName(char * value) {
4793 fields[1].varchar = value;
4794 }
4795
4796 //!
4797 //! \brief Returns the integer value of the Offset field.
4798 //! \details Offset field is at index 2 in the internal
4799 //! array of Fields.
4800 //! \retval An integer.
4801 //!
4802 uint32_t getOffset() {
4803 return (uint32_t)fields[2].number32;
4804 }
4805
4806 //!
4807 //! \brief Sets the integer value of the Offset field.
4808 //! \details Offset field is at index 2 in the internal
4809 //! array of Fields.
4810 //! \param [in] value.
4811 //! Integer be assigned.
4812 //!
4813 void setOffset(uint32_t value) {
4814 fields[2].number32 = value;
4815 }
4816
4817 //!
4818 //! \brief Returns the integer value of the Size field.
4819 //! \details Size field is at index 3 in the internal
4820 //! array of Fields.
4821 //! \retval An integer.
4822 //!
4823 uint32_t getSize() {
4824 return (uint32_t)fields[3].number32;
4825 }
4826
4827 //!
4828 //! \brief Sets the integer value of the Size field.
4829 //! \details Size field is at index 3 in the internal
4830 //! array of Fields.
4831 //! \param [in] value.
4832 //! Integer be assigned.
4833 //!
4834 void setSize(uint32_t value) {
4835 fields[3].number32 = value;
4836 }
4837
4838 //!
4839 //! \brief Returns the integer value of the InputOffset field.
4840 //! \details InputOffset field is at index 4 in the internal
4841 //! array of Fields.
4842 //! \retval An integer.
4843 //!
4844 uint32_t getInputOffset() {
4845 return (uint32_t)fields[4].number32;
4846 }
4847
4848 //!
4849 //! \brief Sets the integer value of the InputOffset field.
4850 //! \details InputOffset field is at index 4 in the internal
4851 //! array of Fields.
4852 //! \param [in] value.
4853 //! Integer be assigned.
4854 //!
4855 void setInputOffset(uint32_t value) {
4856 fields[4].number32 = value;
4857 }
4858
4859 //!
4860 //! \brief Returns the integer value of the NumSymsVariable field.
4861 //! \details NumSymsVariable field is at index 5 in the internal
4862 //! array of Fields.
4863 //! \retval An integer.
4864 //!
4865 uint16_t getNumSymsVariable() {
4866 return (uint16_t)fields[5].number16;
4867 }
4868
4869 //!
4870 //! \brief Sets the integer value of the NumSymsVariable field.
4871 //! \details NumSymsVariable field is at index 5 in the internal
4872 //! array of Fields.
4873 //! \param [in] value.
4874 //! Integer be assigned.
4875 //!
4876 void setNumSymsVariable(uint16_t value) {
4877 fields[5].number16 = value;
4878 }
4879
4880 //!
4881 //! \brief Returns the reference to the vector of RelocationInfo objects.
4882 //! \details Kernel has a vector of RelocationInfo objects
4883 //! that represents another entity within the vISA object format.
4884 //! \retval Reference to the vector of RelocationInfo*.
4885 //!
4886 std::vector<RelocationInfo*> &getVariableRelocSymtab() {
4887 return variable_reloc_symtab;
4888 }
4889
4890 //!
4891 //! \brief Returns the integer value of the NumSymsFunction field.
4892 //! \details NumSymsFunction field is at index 7 in the internal
4893 //! array of Fields.
4894 //! \retval An integer.
4895 //!
4896 uint16_t getNumSymsFunction() {
4897 return (uint16_t)fields[7].number16;
4898 }
4899
4900 //!
4901 //! \brief Sets the integer value of the NumSymsFunction field.
4902 //! \details NumSymsFunction field is at index 7 in the internal
4903 //! array of Fields.
4904 //! \param [in] value.
4905 //! Integer be assigned.
4906 //!
4907 void setNumSymsFunction(uint16_t value) {
4908 fields[7].number16 = value;
4909 }
4910
4911 //!
4912 //! \brief Returns the reference to the vector of RelocationInfo objects.
4913 //! \details Kernel has a vector of RelocationInfo objects
4914 //! that represents another entity within the vISA object format.
4915 //! \retval Reference to the vector of RelocationInfo*.
4916 //!
4917 std::vector<RelocationInfo*> &getFunctionRelocSymtab() {
4918 return function_reloc_symtab;
4919 }
4920
4921 //!
4922 //! \brief Returns the integer value of the NumGenBinaries field.
4923 //! \details NumGenBinaries field is at index 9 in the internal
4924 //! array of Fields.
4925 //! \retval An integer.
4926 //!
4927 uint8_t getNumGenBinaries() {
4928 return (uint8_t)fields[9].number8;
4929 }
4930
4931 //!
4932 //! \brief Sets the integer value of the NumGenBinaries field.
4933 //! \details NumGenBinaries field is at index 9 in the internal
4934 //! array of Fields.
4935 //! \param [in] value.
4936 //! Integer be assigned.
4937 //!
4938 void setNumGenBinaries(uint8_t value) {
4939 fields[9].number8 = value;
4940 }
4941
4942 //!
4943 //! \brief Returns the reference to the vector of GenBinary objects.
4944 //! \details Kernel has a vector of GenBinary objects
4945 //! that represents another entity within the vISA object format.
4946 //! \retval Reference to the vector of GenBinary*.
4947 //!
4948 std::vector<GenBinary*> &getGenBinaryInfo() {
4949 return gen_binary_info;
4950 }
4951
4952 //!
4953 //! \brief Parses one Kernel object from ISA file.
4954 //! \details Reads and parses all the fields of the Kernel object
4955 //! from the file buffer and returns the pointer immediately
4956 //! after all this data.
4957 //! If this class contains internal structs, their Parse
4958 //! functions are called when corresponding.
4959 //! \param [in] p.
4960 //! Pointer to file buffer to start reading.
4961 //! \param [in] end.
4962 //! Pointer to end of file buffer.
4963 //! \param [in] m.
4964 //! Pointer ISAfile object.
4965 //! \retval Pointer to file buffe after parsing one Kernel object.
4966 //!
4967 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
4968 unsigned i = 0, count = 0;
4969 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4970 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4971 if (!p) return m->setError("bad offset/size for Kernel's field", i);
4972 i++;
4973 }
4974 // RelocationInfo
4975 count = fields[fields[i].countField].number32;
4976 variable_reloc_symtab.resize(count);
4977 for (unsigned j = 0; j < count; j++) {
4978 RelocationInfo *r = new RelocationInfo(m->getCurrentVISAVersion());
4979 p = r->parse(p, end, m);
4980 if (!p) {
4981 delete r;
4982 return 0;
4983 }
4984 variable_reloc_symtab[j] = r;
4985 }
4986 i++;
4987 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
4988 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
4989 if (!p) return m->setError("bad offset/size for Kernel's field", i);
4990 i++;
4991 }
4992 // RelocationInfo
4993 count = fields[fields[i].countField].number32;
4994 function_reloc_symtab.resize(count);
4995 for (unsigned j = 0; j < count; j++) {
4996 RelocationInfo *r = new RelocationInfo(m->getCurrentVISAVersion());
4997 p = r->parse(p, end, m);
4998 if (!p) {
4999 delete r;
5000 return 0;
5001 }
5002 function_reloc_symtab[j] = r;
5003 }
5004 i++;
5005 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
5006 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
5007 if (!p) return m->setError("bad offset/size for Kernel's field", i);
5008 i++;
5009 }
5010 // GenBinary
5011 count = fields[fields[i].countField].number32;
5012 gen_binary_info.resize(count);
5013 for (unsigned j = 0; j < count; j++) {
5014 GenBinary *r = new GenBinary(m->getCurrentVISAVersion());
5015 p = r->parse(p, end, m);
5016 if (!p) {
5017 delete r;
5018 return 0;
5019 }
5020 gen_binary_info[j] = r;
5021 }
5022 i++;
5023 return p;
5024 }
5025
5026 //!
5027 //! \brief Adds all the Kernel's fields to a buffer.
5028 //! \details Every field from this class is added to a buffer
5029 //! in order to be written into an ISA file afterwards
5030 //! If this class contains other internal structus, their addToBuffer
5031 //! functions are called when corresponding.
5032 //! \param [out] buffer.
5033 //! The buffer where the fields data will be added.
5034 //! \param [in] m.
5035 //! Pointer to ISAfile object.
5036 //!
5037 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
5038 unsigned i = 0;
5039 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
5040 m->addToBuffer(fields[i], buffer);
5041 i++;
5042 }
5043 // RelocationInfo
5044 for (RelocationInfo *r : variable_reloc_symtab) {
5045 r->addToBuffer(buffer, m);
5046 }
5047 i++;
5048 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
5049 m->addToBuffer(fields[i], buffer);
5050 i++;
5051 }
5052 // RelocationInfo
5053 for (RelocationInfo *r : function_reloc_symtab) {
5054 r->addToBuffer(buffer, m);
5055 }
5056 i++;
5057 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
5058 m->addToBuffer(fields[i], buffer);
5059 i++;
5060 }
5061 // GenBinary
5062 for (GenBinary *r : gen_binary_info) {
5063 r->addToBuffer(buffer, m);
5064 }
5065 i++;
5066 }
5067
5068 //!
5069 //! \brief Makes the changes needed to support 306 version's Kernel.
5070 //! \details This function is called when the current ISA file has the 306 version.
5071 //! Initially all the objects are created with last version's format, so
5072 //! in order to suppport newer versions, changes of datatypes and insertion/removal
5073 //! of fields can be needed.
5074 //!
5075 void setVersion306()
5076 {
5077 fields[0] = Datatype::ONE;
5078 }
5079 MEDIA_CLASS_DEFINE_END(vp__vISA__Kernel)
5080 };
5081
5082 //!
5083 //! \brief Header Class.
5084 //! \details This class represents the Header from vISA Object Format.
5085 //! Provides getters, setters for its fields and structs as well as
5086 //! functions to read/write it from/to file.
5087 //!
5088 class Header {
5089 public:
5090 std::array<Field, 9> fields = std::array<Field, 9>
5091 {
5092 Field(Datatype::FOUR), // magic_number
5093 Field(Datatype::ONE), // major_version
5094 Field(Datatype::ONE), // minor_version
5095 Field(Datatype::TWO), // num_kernels
5096 Field(Datatype::STRUCT, 3), // kernel_info
5097 Field(Datatype::TWO), // num_variables
5098 Field(Datatype::STRUCT, 5), // file_scope_var_info
5099 Field(Datatype::TWO), // num_functions
5100 Field(Datatype::STRUCT, 7), // function_info
5101 };
5102 std::vector<Kernel*> kernel_info;
5103 std::vector<GlobalVariable*> file_scope_var_info;
5104 std::vector<Function*> function_info;
5105
5106 //!
5107 //! \brief Constructor of Header class.
5108 //! \param [in] version.
5109 //! Version of current ISA file.
5110 //!
5111 Header(unsigned version) {}
5112
5113 //!
5114 //! \brief Copy Constructor of Header class.
5115 //! \param [in] other.
5116 //! Reference to object to copy..
5117 //!
5118 Header(const Header& other) {
5119 fields = other.fields;
5120 for (Kernel *r : other.kernel_info) {
5121 Kernel *s = new Kernel();
5122 *s = *r;
5123 kernel_info.push_back(s);
5124 }
5125 for (GlobalVariable *r : other.file_scope_var_info) {
5126 GlobalVariable *s = new GlobalVariable();
5127 *s = *r;
5128 file_scope_var_info.push_back(s);
5129 }
5130 for (Function *r : other.function_info) {
5131 Function *s = new Function();
5132 *s = *r;
5133 function_info.push_back(s);
5134 }
5135 }
5136
5137 //!
5138 //! \brief Assignment operator.
5139 //! \param [in] other.
5140 //! Reference to object to copy..
5141 //!
5142 Header& operator= (const Header& other) {
5143 if (this != &other) {
5144 fields = other.fields;
5145 for (Kernel *r : kernel_info)
5146 delete r;
5147 for (Kernel *r : other.kernel_info) {
5148 Kernel *s = new Kernel();
5149 *s = *r;
5150 kernel_info.push_back(s);
5151 }
5152 for (GlobalVariable *r : file_scope_var_info)
5153 delete r;
5154 for (GlobalVariable *r : other.file_scope_var_info) {
5155 GlobalVariable *s = new GlobalVariable();
5156 *s = *r;
5157 file_scope_var_info.push_back(s);
5158 }
5159 for (Function *r : function_info)
5160 delete r;
5161 for (Function *r : other.function_info) {
5162 Function *s = new Function();
5163 *s = *r;
5164 function_info.push_back(s);
5165 }
5166 }
5167 return *this;
5168 }
5169
5170 //!
5171 //! \brief Destructor of Header class.
5172 //!
5173 ~Header() {
5174 for (Kernel *s : kernel_info) delete s;
5175 for (GlobalVariable *s : file_scope_var_info) delete s;
5176 for (Function *s : function_info) delete s;
5177 }
5178
5179 //!
5180 //! \brief Returns the integer value of the MagicNumber field.
5181 //! \details MagicNumber field is at index 0 in the internal
5182 //! array of Fields.
5183 //! \retval An integer.
5184 //!
5185 uint32_t getMagicNumber() {
5186 return (uint32_t)fields[0].number32;
5187 }
5188
5189 //!
5190 //! \brief Sets the integer value of the MagicNumber field.
5191 //! \details MagicNumber field is at index 0 in the internal
5192 //! array of Fields.
5193 //! \param [in] value.
5194 //! Integer be assigned.
5195 //!
5196 void setMagicNumber(uint32_t value) {
5197 fields[0].number32 = value;
5198 }
5199
5200 //!
5201 //! \brief Returns the integer value of the MajorVersion field.
5202 //! \details MajorVersion field is at index 1 in the internal
5203 //! array of Fields.
5204 //! \retval An integer.
5205 //!
5206 uint8_t getMajorVersion() {
5207 return (uint8_t)fields[1].number8;
5208 }
5209
5210 //!
5211 //! \brief Sets the integer value of the MajorVersion field.
5212 //! \details MajorVersion field is at index 1 in the internal
5213 //! array of Fields.
5214 //! \param [in] value.
5215 //! Integer be assigned.
5216 //!
5217 void setMajorVersion(uint8_t value) {
5218 fields[1].number8 = value;
5219 }
5220
5221 //!
5222 //! \brief Returns the integer value of the MinorVersion field.
5223 //! \details MinorVersion field is at index 2 in the internal
5224 //! array of Fields.
5225 //! \retval An integer.
5226 //!
5227 uint8_t getMinorVersion() {
5228 return (uint8_t)fields[2].number8;
5229 }
5230
5231 //!
5232 //! \brief Sets the integer value of the MinorVersion field.
5233 //! \details MinorVersion field is at index 2 in the internal
5234 //! array of Fields.
5235 //! \param [in] value.
5236 //! Integer be assigned.
5237 //!
5238 void setMinorVersion(uint8_t value) {
5239 fields[2].number8 = value;
5240 }
5241
5242 //!
5243 //! \brief Returns the integer value of the NumKernels field.
5244 //! \details NumKernels field is at index 3 in the internal
5245 //! array of Fields.
5246 //! \retval An integer.
5247 //!
5248 uint16_t getNumKernels() {
5249 return (uint16_t)fields[3].number16;
5250 }
5251
5252 //!
5253 //! \brief Sets the integer value of the NumKernels field.
5254 //! \details NumKernels field is at index 3 in the internal
5255 //! array of Fields.
5256 //! \param [in] value.
5257 //! Integer be assigned.
5258 //!
5259 void setNumKernels(uint16_t value) {
5260 fields[3].number16 = value;
5261 }
5262
5263 //!
5264 //! \brief Returns the reference to the vector of Kernel objects.
5265 //! \details Header has a vector of Kernel objects
5266 //! that represents another entity within the vISA object format.
5267 //! \retval Reference to the vector of Kernel*.
5268 //!
5269 std::vector<Kernel*> &getKernelInfo() {
5270 return kernel_info;
5271 }
5272
5273 //!
5274 //! \brief Returns the integer value of the NumVariables field.
5275 //! \details NumVariables field is at index 5 in the internal
5276 //! array of Fields.
5277 //! \retval An integer.
5278 //!
5279 uint16_t getNumVariables() {
5280 return (uint16_t)fields[5].number16;
5281 }
5282
5283 //!
5284 //! \brief Sets the integer value of the NumVariables field.
5285 //! \details NumVariables field is at index 5 in the internal
5286 //! array of Fields.
5287 //! \param [in] value.
5288 //! Integer be assigned.
5289 //!
5290 void setNumVariables(uint16_t value) {
5291 fields[5].number16 = value;
5292 }
5293
5294 //!
5295 //! \brief Returns the reference to the vector of GlobalVariable objects.
5296 //! \details Header has a vector of GlobalVariable objects
5297 //! that represents another entity within the vISA object format.
5298 //! \retval Reference to the vector of GlobalVariable*.
5299 //!
5300 std::vector<GlobalVariable*> &getFileScopeVarInfo() {
5301 return file_scope_var_info;
5302 }
5303
5304 //!
5305 //! \brief Returns the integer value of the NumFunctions field.
5306 //! \details NumFunctions field is at index 7 in the internal
5307 //! array of Fields.
5308 //! \retval An integer.
5309 //!
5310 uint16_t getNumFunctions() {
5311 return (uint16_t)fields[7].number16;
5312 }
5313
5314 //!
5315 //! \brief Sets the integer value of the NumFunctions field.
5316 //! \details NumFunctions field is at index 7 in the internal
5317 //! array of Fields.
5318 //! \param [in] value.
5319 //! Integer be assigned.
5320 //!
5321 void setNumFunctions(uint16_t value) {
5322 fields[7].number16 = value;
5323 }
5324
5325 //!
5326 //! \brief Returns the reference to the vector of Function objects.
5327 //! \details Header has a vector of Function objects
5328 //! that represents another entity within the vISA object format.
5329 //! \retval Reference to the vector of Function*.
5330 //!
5331 std::vector<Function*> &getFunctionInfo() {
5332 return function_info;
5333 }
5334
5335 //!
5336 //! \brief Parses one Header object from ISA file.
5337 //! \details Reads and parses all the fields of the Header object
5338 //! from the file buffer and returns the pointer immediately
5339 //! after all this data.
5340 //! If this class contains internal structs, their Parse
5341 //! functions are called when corresponding.
5342 //! \param [in] p.
5343 //! Pointer to file buffer to start reading.
5344 //! \param [in] end.
5345 //! Pointer to end of file buffer.
5346 //! \param [in] m.
5347 //! Pointer ISAfile object.
5348 //! \retval Pointer to file buffe after parsing one Header object.
5349 //!
5350 const uint8_t* parse(const uint8_t *p, const uint8_t *end, ISAfile *m) {
5351 unsigned i = 0, count = 0;
5352 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
5353 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
5354 if (!p) return m->setError("bad offset/size for Header's field", i);
5355 i++;
5356 }
5357 m->setCurrentVISAVersion(getMajorVersion() * 100 + getMinorVersion());
5358 // Kernel
5359 count = fields[fields[i].countField].number32;
5360 kernel_info.resize(count);
5361 for (unsigned j = 0; j < count; j++) {
5362 Kernel *r = new Kernel(m->getCurrentVISAVersion());
5363 p = r->parse(p, end, m);
5364 if (!p) {
5365 delete r;
5366 return 0;
5367 }
5368 kernel_info[j] = r;
5369 }
5370 i++;
5371 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
5372 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
5373 if (!p) return m->setError("bad offset/size for Header's field", i);
5374 i++;
5375 }
5376 // GlobalVariable
5377 count = fields[fields[i].countField].number32;
5378 file_scope_var_info.resize(count);
5379 for (unsigned j = 0; j < count; j++) {
5380 GlobalVariable *r = new GlobalVariable(m->getCurrentVISAVersion());
5381 p = r->parse(p, end, m);
5382 if (!p) {
5383 delete r;
5384 return 0;
5385 }
5386 file_scope_var_info[j] = r;
5387 }
5388 i++;
5389 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
5390 p = m->readField(p, end, fields[i], fields[fields[i].countField].number32);
5391 if (!p) return m->setError("bad offset/size for Header's field", i);
5392 i++;
5393 }
5394 // Function
5395 count = fields[fields[i].countField].number32;
5396 function_info.resize(count);
5397 for (unsigned j = 0; j < count; j++) {
5398 Function *r = new Function(m->getCurrentVISAVersion());
5399 p = r->parse(p, end, m);
5400 if (!p) {
5401 delete r;
5402 return 0;
5403 }
5404 function_info[j] = r;
5405 }
5406 i++;
5407 return p;
5408 }
5409
5410 //!
5411 //! \brief Adds all the Header's fields to a buffer.
5412 //! \details Every field from this class is added to a buffer
5413 //! in order to be written into an ISA file afterwards
5414 //! If this class contains other internal structus, their addToBuffer
5415 //! functions are called when corresponding.
5416 //! \param [out] buffer.
5417 //! The buffer where the fields data will be added.
5418 //! \param [in] m.
5419 //! Pointer to ISAfile object.
5420 //!
5421 void addToBuffer(std::vector<char> &buffer, ISAfile *m) {
5422 unsigned i = 0;
5423 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
5424 m->addToBuffer(fields[i], buffer);
5425 i++;
5426 }
5427 // Kernel
5428 for (Kernel *r : kernel_info) {
5429 r->addToBuffer(buffer, m);
5430 }
5431 i++;
5432 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
5433 m->addToBuffer(fields[i], buffer);
5434 i++;
5435 }
5436 // GlobalVariable
5437 for (GlobalVariable *r : file_scope_var_info) {
5438 r->addToBuffer(buffer, m);
5439 }
5440 i++;
5441 while (i < fields.size() && fields[i].type != Datatype::STRUCT) {
5442 m->addToBuffer(fields[i], buffer);
5443 i++;
5444 }
5445 // Function
5446 for (Function *r : function_info) {
5447 r->addToBuffer(buffer, m);
5448 }
5449 i++;
5450 }
5451 MEDIA_CLASS_DEFINE_END(vp__vISA__Header)
5452 };
5453
5454 } // namespace vISA
5455 } // namespace vp
5456
5457 #endif //__VP_VISA_H__