OpenASIP 2.2
Loading...
Searching...
No Matches
ParserStructs.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24
25/**
26 * @file ParsetStructs.hh
27 *
28 * Structures that assembler parser uses for storing parsed information.
29 *
30 * @author Mikael Lepistö 2005 (tmlepist-no.spam-cs.tut.fi)
31 * @note rating: yellow
32 */
33
34#ifndef TCEASM_PARSER_STRUCTS_HH
35#define TCEASM_PARSER_STRUCTS_HH
36
37#include <map>
38#include <string>
39#include <vector>
40#include <sstream>
41
42#include "Conversion.hh"
43
44typedef unsigned long UValue;
45typedef long SValue;
46
47/// Buffer size.
48const UValue MAX_VALUE_LENGTH_IN_BYTES = 16; // oversized buffer...
49
50/**
51 * Parsed data of one BridgeTerm.
52 */
53class BusTerm {
54public:
55 /// Previous or next bus register.
56 bool prev;
57
58 /**
59 * String representation of term for error message generation.
60 */
61 std::string toString() const {
62 if (prev) {
63 return "{prev}";
64 } else {
65 return "{next}";
66 }
67 }
68};
69
70/**
71 * Parsed data of function unit operand port or
72 * special register reference.
73 *
74 * Form: unit.port[.operation]
75 */
76class FUTerm {
77public:
78 /// Is operation part of the term used.
80 /// Unit name
81 std::string part1;
82 /// Port name.
83 std::string part2;
84 /// Operation name.
85 std::string part3;
86
87 /**
88 * String representation of term for error message generation.
89 */
90 std::string toString() const {
91 std::string retVal = part1 + "." + part2;
92 if (part3Used) {
93 retVal += "." + part3;
94 }
95 return retVal;
96 }
97};
98
99/**
100 * Parsed data of registerfile index or
101 * function unit operation operand reference.
102 *
103 * Form: rf[.port].index and fu.operation.index
104 */
106public:
107 /// Is port name used.
109 /// Unit name.
110 std::string part1;
111 /// Port or operation name.
112 std::string part2;
113 /// Register or operand index.
115
116 /**
117 * String representation of term for error message generation.
118 */
119 std::string toString() const {
120 std::string retVal = part1;
121 if (part2Used) {
122 retVal += "." + part2;
123 }
124 retVal += "." + Conversion::toString(index);
125 return retVal;
126 }
127};
128
129/**
130 * Parsed data of register term
131 *
132 * This is used for presenting any type of port or register reference.
133 *
134 * Register term can be BusTerm, FUTerm or IndexTerm.
135 */
137public:
138
139 /**
140 * Register term types.
141 */
142 enum TermType {
143 BUS, ///< Bus term.
144 FUNCTION_UNIT, ///< FU term.
145 INDEX ///< Index term.
146 };
147
148 /// Type of terminal that is represented by this object.
150
151 /// The bus term, if type field is BUS. Otherwise not used.
153 /// The fu term, if type field is FUNCTION_UNIT. Otherwise not used.
155 /// The index term, if type field is INDEX. Otherwise not used.
157
158 /**
159 * String representation of term for error message generation.
160 */
161 std::string toString() const {
162
163 switch (type) {
164 case BUS:
165 return busTerm.toString();
166 break;
167
168 case FUNCTION_UNIT:
169 return fuTerm.toString();
170 break;
171
172 case INDEX:
173 return indexTerm.toString();
174 break;
175
176 default:
177 return "Unknown register term type";
178 }
179 }
180};
181
182/**
183 * Parsed expression.
184 *
185 * Expression is label with possibly some additional information.
186 *
187 * Form: name[(+|-)offset][=literal]
188 * e.g. myDataStructLabel+8=16, myCodeLabel=3, myDataStructLabel+8 or
189 * myDataStructLabel
190 *
191 * Part after '=' sign is just value of label, if value is always
192 * resolved by compiler and it is also given by user values will
193 * be compared to match.
194 *
195 * Offset can be used for example with structures,
196 * if one want's to refer different datafields.
197 */
199public:
200 /// Name of the label.
201 std::string label;
202
203 /// Is resolved value defined in struct.
205 /// Resolved value.
207
208 /// Is offset defined.
210 /// Is offset minus.
212 /// Value of offset.
214
215 /**
216 * String representation of term for error message generation.
217 */
218 std::string toString() const {
219
220 std::stringstream retVal;
221
222 retVal << label;
223
224 if (hasOffset) {
225 if (isMinus) {
226 retVal << '-';
227 } else {
228 retVal << '+';
229 }
230
231 retVal << std::dec << offset;
232 }
233
234 if (hasValue) {
235 retVal << "=" << std::hex << value;
236 }
237
238 return retVal.str();
239 }
240};
241
242/**
243 * Parsed literal or expression.
244 */
246public:
247
249
250 /// Does object contain expression or literal.
252 /// If expression the expression, Otherwise not used.
254
255 /// If literal, the literal. Otherwise not used.
257 /// Sign of the value.
259
260 /**
261 * String representation of term for error message generation.
262 */
263 std::string toString() const {
264 std::stringstream retVal;
265 if (isExpression) {
266 retVal << expression.toString();
267 } else {
268 retVal << std::dec << static_cast<int>(value);
269 }
270 return retVal.str();
271 }
272};
273
274/**
275 * Source field of parsed move.
276 *
277 * Source can be either RegisterTerm or Immediate.
278 */
280public:
281 /// Is source register or immediate reference.
283 /// If register, the register. Otherwise not used.
285 /// If immediate value, the literal or expression. Otherwise not used.
287
288 /**
289 * String representation of term for error message generation.
290 */
291 std::string toString() const {
292 std::stringstream retVal;
293 if (isRegister) {
294 retVal << regTerm.toString();
295 } else {
296 retVal << immTerm.toString();
297 }
298 return retVal.str();
299 }
300};
301
302/**
303 * Guard field of parsed move.
304 */
306public:
307 /// Is guard used.
309 /// Is guard inverted.
311 /// Guard port or register.
313
314 /**
315 * String representation of term for error message generation.
316 */
317 std::string toString() const {
318 std::stringstream retVal;
319 if (isGuarded) {
320 if (isInverted) {
321 retVal << '!';
322 } else {
323 retVal << '?';
324 }
325
326 retVal << regTerm.toString();
327 }
328 return retVal.str();
329 }
330};
331
332/**
333 * One init data field of data line.
334 *
335 * Form: [width:]literalOrExpression
336 *
337 * e.g.these are valid 4:codeLabel, 0b1010010, 0x139da 4:0x1abcd -4
338 */
340public:
341 /// Number of MAUs that are initialized by the init field.
343 /// Initialisation value.
345
346 /**
347 * String representation of term for error message generation.
348 */
349 std::string toString() const {
350 std::stringstream retVal;
351 retVal << std::dec << (int)width << ":";
353 retVal << std::dec << (litOrExpr.expression.label);
354 } else {
355 retVal << std::dec << (int)(litOrExpr.value);
356 }
357 return retVal.str();
358 }
359};
360
361/**
362 * One annotation.
363 */
365public:
366 // Id of annotation
368 // Payload
369 std::vector<InitDataField> payload;
370
371 std::string toString() const {
372 std::stringstream retVal;
373 retVal << "[0x" << std::hex << id;
374
375 for (unsigned int i = 0; i < payload.size(); i++) {
376 retVal << " " << payload[i].toString();
377 }
378
379 retVal << "]";
380
381 return retVal.str();
382 }
383};
384
385/**
386 * All info of one parsed instruction slot.
387 *
388 * Instruction slot defines a move or long immediate. An instruction slot can
389 * also be empty (unused).
390 */
392public:
393 /// Types of instruction slots.
394 enum MoveType {
395 EMPTY, ///< Empty move slot.
396 LONG_IMMEDIATE, ///< Encoding of one long immediate slot.
397 TRANSPORT ///< Data transport (move).
398 };
399
400 /// Type of move.
402
403 /// Tells whether the slot is the first of the instruction.
405
406 /// Guard field.
408 /// Source field.
410 /// Destination field.
412 /// Line number of source code for errors.
414
415 std::vector<Annotation> annotationes;
416
417 /**
418 * Empty constructor.
419 *
420 * All values are set by hand.
421 */
423 }
424
425 /**
426 * Constructor.
427 *
428 * @param aType Type of created move.
429 * @param begin Is first move of an instruction.
430 */
431 ParserMove(MoveType aType, bool begin) :
432 type(aType), isBegin(begin) {
433 }
434
435 /**
436 * String representation of term for error message generation.
437 */
438 std::string toString() const {
439 std::stringstream retVal;
440 switch (type) {
441 case EMPTY:
442 retVal << "...";
443 break;
444
445 case LONG_IMMEDIATE:
446 retVal << "[" << destination.toString()
447 << "=" << source.toString()
448 << "]";
449
450 for (unsigned int i = 0;i < annotationes.size();i++) {
451 retVal << annotationes[i].toString();
452 }
453
454 break;
455
456 case TRANSPORT:
457 retVal << guard.toString() << " "
458 << source.toString() << " -> "
460
461 for (unsigned int i = 0;i < annotationes.size();i++) {
462 retVal << annotationes[i].toString();
463 }
464
465 break;
466
467 default:
468 retVal << "Unknown move type!\n";
469 }
470 return retVal.str();
471 }
472};
473
474/**
475 * Parsed data area definition.
476 */
477class DataLine {
478public:
479 /// Number of MAUs initialized by this data line.
481 /// Address space whose MAUs are initialized.
482 std::string dataSpace;
483
484 /// Init data fields of data line. Uninitilized data line, if empty.
485 std::vector<InitDataField> initData;
486 /// Labels of this data line.
487 std::vector<std::string> labels;
488
489 /// Line number where in source code this DA line is found.
491
492 /**
493 * String representation of term for error message generation.
494 */
495 std::string toString() const {
496
497 std::stringstream retVal;
498
499 retVal << "DataLine:\n"
500 << "address space:\t" << dataSpace << std::endl
501 << "data maus: \t" << width << std::endl;
502
503 retVal << "Labels:" << std::endl;
504 for (unsigned int i = 0; i < labels.size(); i++) {
505 retVal << "\t" << labels[i] << std::endl;
506 }
507
508 retVal << "Init data:" << std::endl;
509 for (unsigned int i = 0; i < initData.size(); i++) {
510 retVal << (int)initData[i].width << ":";
511
512 if (initData[i].litOrExpr.isExpression) {
513 retVal << initData[i].litOrExpr.expression.label;
514 } else {
515 retVal << (int)initData[i].litOrExpr.value;
516 }
517
518 retVal << "\t";
519
520 if ((i+1)%16 == 0) retVal << std::endl;
521 }
522
523 retVal << "\n";
524
525 return retVal.str();
526 }
527};
528
529#endif
const UValue MAX_VALUE_LENGTH_IN_BYTES
Buffer size.
unsigned long UValue
long SValue
std::string toString() const
std::vector< InitDataField > payload
bool prev
Previous or next bus register.
std::string toString() const
static std::string toString(const T &source)
std::string toString() const
UValue width
Number of MAUs initialized by this data line.
std::vector< InitDataField > initData
Init data fields of data line. Uninitilized data line, if empty.
std::vector< std::string > labels
Labels of this data line.
std::string dataSpace
Address space whose MAUs are initialized.
UValue asmLineNumber
Line number where in source code this DA line is found.
bool hasOffset
Is offset defined.
std::string toString() const
bool isMinus
Is offset minus.
UValue value
Resolved value.
bool hasValue
Is resolved value defined in struct.
std::string label
Name of the label.
UValue offset
Value of offset.
std::string toString() const
std::string part3
Operation name.
std::string part2
Port name.
std::string part1
Unit name.
bool part3Used
Is operation part of the term used.
std::string part1
Unit name.
std::string part2
Port or operation name.
bool part2Used
Is port name used.
std::string toString() const
UValue index
Register or operand index.
std::string toString() const
LiteralOrExpression litOrExpr
Initialisation value.
UValue width
Number of MAUs that are initialized by the init field.
std::string toString() const
bool isExpression
Does object contain expression or literal.
UValue value
If literal, the literal. Otherwise not used.
bool isSigned
Sign of the value.
Expression expression
If expression the expression, Otherwise not used.
RegisterTerm regTerm
Guard port or register.
bool isInverted
Is guard inverted.
bool isGuarded
Is guard used.
std::string toString() const
MoveType
Types of instruction slots.
@ TRANSPORT
Data transport (move).
@ EMPTY
Empty move slot.
@ LONG_IMMEDIATE
Encoding of one long immediate slot.
std::vector< Annotation > annotationes
MoveType type
Type of move.
ParserSource source
Source field.
ParserMove(MoveType aType, bool begin)
std::string toString() const
bool isBegin
Tells whether the slot is the first of the instruction.
UValue asmLineNumber
Line number of source code for errors.
ParserGuard guard
Guard field.
RegisterTerm destination
Destination field.
bool isRegister
Is source register or immediate reference.
std::string toString() const
LiteralOrExpression immTerm
If immediate value, the literal or expression. Otherwise not used.
RegisterTerm regTerm
If register, the register. Otherwise not used.
@ BUS
Bus term.
@ FUNCTION_UNIT
FU term.
@ INDEX
Index term.
FUTerm fuTerm
The fu term, if type field is FUNCTION_UNIT. Otherwise not used.
IndexTerm indexTerm
The index term, if type field is INDEX. Otherwise not used.
TermType type
Type of terminal that is represented by this object.
std::string toString() const
BusTerm busTerm
The bus term, if type field is BUS. Otherwise not used.