OpenASIP 2.2
Loading...
Searching...
No Matches
EntryKeyData.cc
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 * @file EntryKeyData.cc
26 *
27 * Implementation of EntryKeyData, EntryKeyDataInt, EntryKeyDataDouble,
28 * EntryKeyDataOperationSet, EntryKeyDataBool and EntryKeyDataParameterSet
29 * classes.
30 *
31 * @author Tommi Rantanen 2003 (tommi.rantanen-no.spam-tut.fi)
32 * @author Jari Mäntyneva 2005 (jari.mantyneva-no.spam-tut.fi)
33 * @note rating: red
34 */
35
36#include <string>
37#include <sstream>
38#include <typeinfo>
39#include "EntryKeyData.hh"
40#include "Conversion.hh"
41#include "FunctionUnit.hh"
42#include "HWOperation.hh"
43
44using std::string;
45using std::set;
46using std::vector;
47using std::pair;
48using namespace TTAMachine;
49
50///////////////////////////////////////////////////////////////////////////////
51// EntryKeyData
52///////////////////////////////////////////////////////////////////////////////
53
54/**
55 * Default constructor.
56 */
59
60/**
61 * Destructor.
62 */
65
66///////////////////////////////////////////////////////////////////////////////
67// EntryKeyDataInt
68///////////////////////////////////////////////////////////////////////////////
69
70/**
71 * Default constructor.
72 */
75
76/**
77 * Constructor.
78 *
79 * @param fieldData An integer.
80 */
81EntryKeyDataInt::EntryKeyDataInt(int fieldData) : data_(fieldData) {
82}
83
84/**
85 * Destructor.
86 */
89
90/**
91 * Copies integer.
92 *
93 * Client is responsible of deallocating the memory reserved for the
94 * returned object.
95 *
96 * @return A copy of the integer.
97 */
100 return new EntryKeyDataInt(data_);
101}
102
103/**
104 * Checks if two integers are equal.
105 *
106 * Cannot compare integers to other data types.
107 *
108 * @param fieldData An integer.
109 * @return True if two integers are equal.
110 * @exception WrongSubclass Given data type was illegal.
111 */
112bool
113EntryKeyDataInt::isEqual(const EntryKeyData* fieldData) const {
114 EntryKeyDataInt* integer = dynamic_cast<EntryKeyDataInt*>(
115 const_cast<EntryKeyData*>(fieldData));
116 if (integer == NULL) {
117 throw WrongSubclass(__FILE__, __LINE__,
118 "EntryKeyDataInt::isEqual");
119 }
120 return data_ == integer->data_;
121}
122
123/**
124 * Checks if this integer is greater than another integer.
125 *
126 * Cannot compare integers to other data types.
127 *
128 * @param fieldData An integer.
129 * @return True if this integer is greater than another integer,
130 * otherwise false.
131 * @exception WrongSubclass Given data type was illegal.
132 */
133bool
135 EntryKeyDataInt* integer = dynamic_cast<EntryKeyDataInt*>(
136 const_cast<EntryKeyData*>(fieldData));
137 if (integer == NULL) {
138 throw WrongSubclass(__FILE__, __LINE__,
139 "EntryKeyDataInt::isGreater");
140 }
141 return data_ > integer->data_;
142}
143
144/**
145 * Checks if this integer is smaller than another integer.
146 *
147 * Cannot compare integers to other data types.
148 *
149 * @param fieldData An integer.
150 * @return True if this integer is smaller than another integer,
151 * otherwise false.
152 * @exception WrongSubclass Given data type was illegal.
153 */
154bool
156 EntryKeyDataInt* integer = dynamic_cast<EntryKeyDataInt*>(
157 const_cast<EntryKeyData*>(fieldData));
158 if (integer == NULL) {
159 throw WrongSubclass(__FILE__, __LINE__,
160 "EntryKeyDataInt::isSmaller");
161 }
162 return data_ < integer->data_;
163}
164
165/**
166 * Returns the relative position between two integers.
167 *
168 * Returns the integer's relative position to the first integer
169 * compared to the second. For example, if this integer is 14, the
170 * first integer is 10 and the second 20, relative position would be
171 * 0.4.
172 *
173 * @param data1 First integer.
174 * @param data2 Second integer.
175 * @return The relative position between two integers.
176 * @exception WrongSubclass Given data type was illegal.
177 */
178double
180 const EntryKeyData* data1, const EntryKeyData* data2) const {
181 EntryKeyDataInt* int1 = dynamic_cast<EntryKeyDataInt*>(
182 const_cast<EntryKeyData*>(data1));
183 EntryKeyDataInt* int2 = dynamic_cast<EntryKeyDataInt*>(
184 const_cast<EntryKeyData*>(data2));
185 if (int1 == NULL) {
186 throw WrongSubclass(__FILE__, __LINE__,
187 "EntryKeyDataInt::coefficient param1");
188 }
189 if (int2 == NULL) {
190 throw WrongSubclass(__FILE__, __LINE__,
191 "EntryKeyDataInt::coefficient param2");
192 }
193
194 return static_cast<double>(data_ - int1->data_) /
195 static_cast<double>(int2->data_ - int1->data_);
196}
197
198/**
199 * Converts the integer into a string.
200 *
201 * @return integer as a string
202 */
203std::string
207
208
209///////////////////////////////////////////////////////////////////////////////
210// EntryKeyDataDouble
211///////////////////////////////////////////////////////////////////////////////
212
213/**
214 * Default constructor.
215 */
218
219/**
220 * Constructor.
221 *
222 * @param fieldData A double.
223 */
224EntryKeyDataDouble::EntryKeyDataDouble(double fieldData) : data_(fieldData) {
225}
226
227/**
228 * Destructor.
229 */
232
233/**
234 * Copies the double.
235 *
236 * Client is responsible of deallocating the memory reserved for the
237 * returned object.
238 *
239 * @return A copy of the double.
240 */
243 return new EntryKeyDataDouble(data_);
244}
245
246/**
247 * Checks if two doubles are equal.
248 *
249 * Cannot compare double to other data types.
250 *
251 * @param fieldData A double.
252 * @return True if two doubles are equal.
253 * @exception WrongSubclass Given data type was illegal.
254 */
255bool
257 EntryKeyDataDouble* data = dynamic_cast<EntryKeyDataDouble*>(
258 const_cast<EntryKeyData*>(fieldData));
259 if (data == NULL) {
260 throw WrongSubclass(__FILE__, __LINE__,
261 "EntryKeyDataDouble::isEqual");
262 }
263 return data_ == data->data_;
264}
265
266/**
267 * Checks if another double is greater.
268 *
269 * Cannot compare double to other data types.
270 *
271 * @param fieldData A double.
272 * @return True if this double is greater than another double,
273 * otherwise false.
274 * @exception WrongSubclass Given data type was illegal.
275 */
276bool
278 EntryKeyDataDouble* data = dynamic_cast<EntryKeyDataDouble*>(
279 const_cast<EntryKeyData*>(fieldData));
280 if (data == NULL) {
281 throw WrongSubclass(__FILE__, __LINE__,
282 "EntryKeyDataDouble::isGreater");
283 }
284 return data_ > data->data_;
285}
286
287/**
288 * Checks if this double is smaller than another double.
289 *
290 * Cannot compare double to other data types.
291 *
292 * @param fieldData A double.
293 * @return True if this double is smaller than another double,
294 * otherwise false.
295 * @exception WrongSubclass Given data type was illegal.
296 */
297bool
299 EntryKeyDataDouble* data = dynamic_cast<EntryKeyDataDouble*>(
300 const_cast<EntryKeyData*>(fieldData));
301 if (data == NULL) {
302 throw WrongSubclass(__FILE__, __LINE__,
303 "EntryKeyDataDouble::isSmaller");
304 }
305 return data_ < data->data_;
306}
307
308/**
309 * Returns the relative position between two doubles.
310 *
311 * Returns the double's relative position to the first double
312 * compared to the second. For example, if this double is 14, the
313 * first double is 10 and the second 20, relative position would be
314 * 0.4.
315 *
316 * @param data1 First double.
317 * @param data2 Second double.
318 * @return The relative position between two doubles.
319 * @exception WrongSubclass Given data type was illegal.
320 */
321double
323 const EntryKeyData* data1, const EntryKeyData* data2) const {
324 EntryKeyDataDouble* double1 = dynamic_cast<EntryKeyDataDouble*>(
325 const_cast<EntryKeyData*>(data1));
326 EntryKeyDataDouble* double2 = dynamic_cast<EntryKeyDataDouble*>(
327 const_cast<EntryKeyData*>(data2));
328 if (double1 == NULL) {
329 throw WrongSubclass(__FILE__, __LINE__,
330 "EntryKeyDataDouble::coefficient param1");
331 }
332 if(double2 == NULL) {
333 throw WrongSubclass(__FILE__, __LINE__,
334 "EntryKeyDataDouble::coefficient param2");
335 }
336
337 return (data_ - double1->data_) / (double2->data_ - double1->data_);
338}
339
340/**
341 * Converts the double into a string.
342 *
343 * @return Double as a string.
344 */
345std::string
349
350///////////////////////////////////////////////////////////////////////////////
351// EntryKeyDataOperationSet
352///////////////////////////////////////////////////////////////////////////////
353
354/**
355 * Default constructor.
356 */
359
360/**
361 * Constructor.
362 *
363 * @param fieldData A set of operations.
364 */
366 std::set<std::string> fieldData) : data_(fieldData) {
367}
368
369/**
370 * Destructor.
371 */
374
375/**
376 * Copies the operation set.
377 *
378 * Client is responsible of deallocating the memory reserved for the
379 * returned object.
380 *
381 * @return A copy of the operation set.
382 */
387
388/**
389 * Checks if two operation sets are equal.
390 *
391 * Cannot compare to other data types.
392 *
393 * @param fieldData Operation set.
394 * @return True if two operation sets are equal.
395 * @exception WrongSubclass Given data type was illegal.
396 */
397bool
400 const_cast<EntryKeyData*>(fieldData));
401 if (data == NULL) {
402 throw WrongSubclass(__FILE__, __LINE__,
403 "EntryKeyDataOperationSet::isEqual");
404 }
405 return data_ == data->data_;
406}
407
408/**
409 * Checks if another operation set is greater.
410 *
411 * Cannot compare to other data types. Cannot compare to other operation sets
412 * and because of that returns always false.
413 *
414 * @param fieldData Operation set.
415 * @return Always false.
416 * @exception WrongSubclass Given data type was illegal.
417 */
418bool
420 return false;
421}
422
423/**
424 * Checks if this operation set is smaller than another set.
425 *
426 * Cannot compare to other data types. Cannot compare to other operation sets
427 * and because of that returns always true.
428 *
429 * @param fieldData Operation set.
430 * @return Always true.
431 * @exception WrongSubclass Given data type was illegal.
432 */
433bool
435 return true;
436}
437
438/**
439 * Cannot be called for EntryKeyDataOperationSet.
440 *
441 * Operation sets cannot be compared and no coefficient can be counted.
442 *
443 * @param data1 Nothing.
444 * @param data2 Nothing.
445 * @return Nothing.
446 * @exception WrongSubclass Given data type was illegal.
447 */
448double
450 const EntryKeyData*, const EntryKeyData*) const {
451 throw WrongSubclass(__FILE__, __LINE__,
452 "EntryKeyDataOperationSet::coefficient");
453 return 0.0; // stupid return statement to keep compiler quiet
454}
455
456/**
457 * Converts the operation set into a string.
458 *
459 * @return Operation set as a string.
460 */
461std::string
463
464 string result = "";
465 for (std::set<string>::iterator i = data_.begin();
466 i != data_.end();
467 i++) {
468
469 result += *i;
470 }
471 return result;
472}
473
474///////////////////////////////////////////////////////////////////////////////
475// EntryKeyDataBool
476///////////////////////////////////////////////////////////////////////////////
477
478/**
479 * Default constructor.
480 */
483
484/**
485 * Constructor.
486 *
487 * @param fieldData A boolean.
488 */
489EntryKeyDataBool::EntryKeyDataBool(bool fieldData) : data_(fieldData) {
490}
491
492/**
493 * Destructor.
494 */
497
498/**
499 * Copies the boolean.
500 *
501 * Client is responsible of deallocating the memory reserved for the
502 * returned object.
503 *
504 * @return A copy of the boolean.
505 */
508 return new EntryKeyDataBool(data_);
509}
510
511/**
512 * Checks if two booleans are equal.
513 *
514 * Cannot compare to other data types.
515 *
516 * @param fieldData Boolean.
517 * @return True if two booleans are equal.
518 * @exception WrongSubclass Given data type was illegal.
519 */
520bool
522 EntryKeyDataBool* data = dynamic_cast<EntryKeyDataBool*>(
523 const_cast<EntryKeyData*>(fieldData));
524 if (data == NULL) {
525 throw WrongSubclass(__FILE__, __LINE__,
526 "EntryKeyDataBool::isEqual");
527 }
528 return data_ == data->data_;
529}
530
531/**
532 * Checks if another operation set is greater.
533 *
534 * Cannot compare to other data types. You cannot say which is greater in
535 * case of booleans and false is returned always.
536 *
537 * @param fieldData Boolen.
538 * @return Always false.
539 * @exception WrongSubclass Given data type was illegal.
540 */
541bool
543 return false;
544}
545
546/**
547 * Checks if this operation set is smaller than another set.
548 *
549 * Cannot compare to other data types. You cannot say which is greater in
550 * case of booleans and true is returned always.
551 *
552 * @param fieldData Boolean.
553 * @return Always true.
554 * @exception WrongSubclass Given data type was illegal.
555 */
556bool
558 return true;
559}
560
561/**
562 * Cannot be called for EntryKeyDataBool.
563 *
564 * Booleans cannot be compared with greater of smaller and no coefficient
565 * can be counted.
566 *
567 * @param data1 Nothing.
568 * @param data2 Nothing.
569 * @return Nothing
570 * @exception WrongSubclass Given data type was illegal.
571 */
572double
574 throw WrongSubclass(__FILE__, __LINE__,
575 "EntryKeyDataBool::coefficient");
576 return 0.0; // stupid return statement to keep compiler quiet
577}
578
579/**
580 * Converts the boolean into a string.
581 *
582 * @return Boolean as a string.
583 */
584std::string
586
587 if (data_) {
588 return "true";
589 } else {
590 return "false";
591 }
592}
593
594
595///////////////////////////////////////////////////////////////////////////////
596// EntryKeyDataFunctioUnit
597///////////////////////////////////////////////////////////////////////////////
598
599/**
600 * Default constructor.
601 */
604
605/**
606 * Constructor.
607 *
608 * @param fieldData A set of parameters.
609 */
611 const FunctionUnit* fieldData) : data_(fieldData) {
612}
613
614/**
615 * Destructor.
616 */
619
620/**
621 * Copies the set of parameters.
622 *
623 * Client is responsible of deallocating the memory reserved for the
624 * returned object.
625 *
626 * @return A copy of the parameter set.
627 */
632
633/**
634 * Checks if two FunctionUnits are equal
635 *
636 * Cannot compare to other data types.
637 *
638 * @param fieldData FunctionUnit pointer.
639 * @return True if two FunctionUnits are equal.
640 * @exception WrongSubclass Given data type was illegal.
641 */
642bool
645 const_cast<EntryKeyData*>(fieldData));
646 if (data == NULL) {
647 throw WrongSubclass(__FILE__, __LINE__,
648 "EntryKeyDataFunctionUnit::isEqual");
649 }
650
651 return data_->isArchitectureEqual(data->data_, false);
652}
653
654/**
655 * Checks if another EntryKeyDataFunctionUnit is greater.
656 *
657 * Cannot compare to other data types. Cannot say which is greater in
658 * case of FunctionUnits and false is returned always.
659 *
660 * @param fieldData FunctionUnit*.
661 * @return Always false.
662 * @exception WrongSubclass Given data type was illegal.
663 */
664bool
666 return false;
667}
668
669/**
670 * Checks if another EntryKeyDataFunctionUnit is smaller.
671 *
672 * Cannot compare to other data types. Cannot say which is smaller in
673 * case of FunctionUnits and true is returned always.
674 *
675 * @param fieldData FunctionUnit*.
676 * @return Always true.
677 * @exception WrongSubclass Given data type was illegal.
678 */
679bool
681 return true;
682}
683
684/**
685 * Cannot be called for EntryKeyDataFunctionUnit.
686 *
687 * FunctionUnits cannot be compared with greater of smaller and no coefficient
688 * can be counted.
689 *
690 * @param data1 Nothing.
691 * @param data2 Nothing.
692 * @return Nothing
693 * @exception WrongSubclass Given data type was illegal.
694 */
695double
697 const EntryKeyData*, const EntryKeyData*) const {
698 throw WrongSubclass(__FILE__, __LINE__,
699 "EntryKeyDataFunctionUnit::coefficient");
700 return 0.0; // stupid return statement to keep compiler quiet
701}
702
703/**
704 * Converts the FunctionUnit name and operations into a string.
705 *
706 * @return FunctionUnit name and operations as a string.
707 */
708std::string
710
711 string result = "";
712 result += data_->name();
713 result += ":";
714 for (int i = 0; i < data_->operationCount(); i++) {
715 result += data_->operation(i)->name();
716 if ((i + 1) < data_->operationCount()) {
717 result += "_";
718 }
719 }
720 return result;
721}
static std::string toString(const T &source)
bool isGreater(const EntryKeyData *fieldData) const
std::string toString() const
virtual ~EntryKeyDataBool()
bool isEqual(const EntryKeyData *fieldData) const
bool data_
Boolean data.
bool isSmaller(const EntryKeyData *fieldData) const
EntryKeyData * copy() const
double coefficient(const EntryKeyData *data1, const EntryKeyData *data2) const
bool isGreater(const EntryKeyData *fieldData) const
virtual ~EntryKeyDataDouble()
bool isSmaller(const EntryKeyData *fieldData) const
EntryKeyData * copy() const
double coefficient(const EntryKeyData *data1, const EntryKeyData *data2) const
bool isEqual(const EntryKeyData *fieldData) const
std::string toString() const
double data_
Double data.
std::string toString() const
double coefficient(const EntryKeyData *data1, const EntryKeyData *data2) const
bool isEqual(const EntryKeyData *fieldData) const
bool isSmaller(const EntryKeyData *fieldData) const
EntryKeyData * copy() const
const TTAMachine::FunctionUnit * data_
FunctionUnit* data.
bool isGreater(const EntryKeyData *fieldData) const
EntryKeyData * copy() const
bool isGreater(const EntryKeyData *fieldData) const
virtual ~EntryKeyDataInt()
double coefficient(const EntryKeyData *data1, const EntryKeyData *data2) const
std::string toString() const
int data_
Integer data.
bool isSmaller(const EntryKeyData *fieldData) const
bool isEqual(const EntryKeyData *fieldData) const
std::set< std::string > data_
Operation set data.
double coefficient(const EntryKeyData *data1, const EntryKeyData *data2) const
EntryKeyData * copy() const
std::string toString() const
bool isSmaller(const EntryKeyData *fieldData) const
bool isEqual(const EntryKeyData *fieldData) const
bool isGreater(const EntryKeyData *fieldData) const
virtual ~EntryKeyData()
virtual TCEString name() const
virtual HWOperation * operation(const std::string &name) const
virtual int operationCount() const
virtual bool isArchitectureEqual(const FunctionUnit *fu, const bool checkPortWidths=true) const
const std::string & name() const