OpenASIP  2.0
DisassemblyRegister.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 DisassemblyRegister.cc
26  *
27  * Implementation of DisassemblyRegister class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @author Heikki Kultala 2009 (hkultala-no.spam-cs.tut.fi)
31  * @note rating: red
32  */
33 
34 #include "DisassemblyRegister.hh"
35 #include "Conversion.hh"
36 #include "RegisterFile.hh"
37 #include "Terminal.hh"
38 
39 /**
40  * The constructor.
41  *
42  * @param rfName Name of the register file.
43  * @param index Index of the register in the register file.
44  */
45 DisassemblyRegister::DisassemblyRegister(std::string rfName, Word index) :
47  rfName_(rfName),
48  index_(index) {
49 }
50 
51 
52 /**
53  * The destructor.
54  */
56 }
57 
58 
59 
60 /**
61  * Returns disassembly of the register file.
62  *
63  * @return Disassembly of the register as a string.
64  */
65 std::string
67  return registerName(rfName_, index_);
68 }
69 
70 /**
71  * Returns a name of the register.
72  *
73  * Does the int -> string conversion itself, because
74  * Conversion::toString() uses stringstream which is slow.
75  */
78  const TCEString& rfName, int index, char delim) {
79  char buf[12];
80  char *ptr = buf + sizeof(buf);
81  *--ptr = 0; // last to terminating zero.
82  // conversion from 2 to 10 base
83  do {
84  *--ptr = (index%10) + 48; // 48 is conversion to ascii.
85  index /= 10;
86  } while (index);
87  *--ptr = delim;
88  return rfName + ptr;
89 }
90 
91 /**
92  * Returns name of a register.
93  */
96  const TTAMachine::RegisterFile& rf, int index, char delim) {
97  return registerName(rf.name(), index, delim);
98 }
99 
100 /**
101  * Returns name of a register which is in a terminalregister.
102  */
103 TCEString
105  const TTAProgram::Terminal& term) {
106  return registerName(term.registerFile(), term.index());
107 }
DisassemblyRegister::toString
std::string toString() const
Definition: DisassemblyRegister.cc:66
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
TTAProgram::Terminal::index
virtual int index() const
Definition: Terminal.cc:274
TTAProgram::Terminal::registerFile
virtual const TTAMachine::RegisterFile & registerFile() const
Definition: Terminal.cc:225
DisassemblyElement
Definition: DisassemblyElement.hh:41
Terminal.hh
DisassemblyRegister::index_
Word index_
Index of the register in the register file.
Definition: DisassemblyRegister.hh:74
Conversion.hh
DisassemblyRegister::rfName_
std::string rfName_
Name of the register file.
Definition: DisassemblyRegister.hh:72
DisassemblyRegister.hh
RegisterFile.hh
TCEString
Definition: TCEString.hh:53
TTAProgram::Terminal
Definition: Terminal.hh:60
DisassemblyRegister::registerName
static TCEString registerName(const TTAMachine::RegisterFile &rf, int index, char delim='.')
Definition: DisassemblyRegister.cc:95
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
DisassemblyRegister::~DisassemblyRegister
virtual ~DisassemblyRegister()
Definition: DisassemblyRegister.cc:55
DisassemblyRegister::DisassemblyRegister
DisassemblyRegister(std::string rfName, Word index)
Definition: DisassemblyRegister.cc:45