HPCToolkit
Insn.cpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // $HeadURL$
51 //
52 // Purpose:
53 // [The purpose of this file]
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 //***************************************************************************
59 
60 //************************* System Include Files ****************************
61 
62 #include <iostream>
63 using std::hex;
64 using std::dec;
65 using std::showbase;
66 
67 #include <sstream>
68 
69 #include <string>
70 using std::string;
71 
72 //*************************** User Include Files ****************************
73 
74 #include <include/gcc-attr.h>
75 
76 #include "Insn.hpp"
77 
78 //*************************** Forward Declarations ***************************
79 
80 //****************************************************************************
81 
82 //****************************************************************************
83 // Instruction
84 //****************************************************************************
85 
86 void
87 BinUtil::Insn::dump(std::ostream& o, int GCC_ATTR_UNUSED flags,
88  const char* pre) const
89 {
90  string p(pre);
91  VMA target = targetVMA(m_vma);
92 
93  o << showbase
94  << p << hex << m_vma << dec << ": " << desc().toString();
95 
96  if (target != 0 || opIndex() != 0) {
97  o << " <" << hex << target << dec << "> ";
98  }
99  else {
100  o << " ";
101  }
102 
103  dumpme(o, p.c_str());
104  o << "\n";
105 }
106 
107 
108 string
109 BinUtil::Insn::toString(int flags, const char* pre) const
110 {
111  std::ostringstream os;
112  dump(os, flags, pre);
113  return os.str();
114 }
115 
116 
117 void
119 {
120  dump(std::cerr);
121 }
122 
123 
124 void
126  const char* GCC_ATTR_UNUSED pre) const
127 {
128 }
129 
130 
131 //***************************************************************************
132 // CISCInsn
133 //***************************************************************************
134 
135 void
136 BinUtil::CISCInsn::dump(std::ostream& o, int flags, const char* pre) const
137 {
138  Insn::dump(o, flags, pre);
139 }
140 
141 
142 void
144  const char* GCC_ATTR_UNUSED pre) const
145 {
146  o << "(CISC sz:" << size() << ")";
147 }
148 
149 
150 //***************************************************************************
151 // RISCInsn
152 //***************************************************************************
153 
154 void
155 BinUtil::RISCInsn::dump(std::ostream& o, int flags, const char* pre) const
156 {
157  Insn::dump(o, flags, pre);
158 }
159 
160 
161 void
163  const char* GCC_ATTR_UNUSED pre) const
164 {
165  o << "(RISC)";
166 }
167 
168 
169 //***************************************************************************
170 // VLIWInsn
171 //***************************************************************************
172 
173 void
174 BinUtil::VLIWInsn::dump(std::ostream& o, int flags, const char* pre) const
175 {
176  Insn::dump(o, flags, pre);
177 }
178 
179 
180 void
182  const char* GCC_ATTR_UNUSED pre) const
183 {
184  o << "(VLIW opIdx:" << opIndex() << ")";
185 }
ISA::InsnDesc desc() const
Definition: Insn.hpp:108
bfd_vma VMA
Definition: ISATypes.hpp:79
virtual void dump(std::ostream &o=std::cerr, int flags=LM::DUMP_Short, const char *pre="") const
Definition: Insn.cpp:174
virtual void dumpme(std::ostream &o=std::cerr, const char *pre="") const
Definition: Insn.cpp:162
virtual ushort opIndex() const =0
virtual void dumpme(std::ostream &o=std::cerr, const char *pre="") const
Definition: Insn.cpp:181
virtual VMA targetVMA(VMA vma) const
Definition: Insn.hpp:159
virtual void dump(std::ostream &o=std::cerr, int flags=LM::DUMP_Short, const char *pre="") const
Definition: Insn.cpp:87
virtual ushort size() const =0
virtual void dump(std::ostream &o=std::cerr, int flags=LM::DUMP_Short, const char *pre="") const
Definition: Insn.cpp:155
virtual void dump(std::ostream &o=std::cerr, int flags=LM::DUMP_Short, const char *pre="") const
Definition: Insn.cpp:136
void ddump() const
Definition: Insn.cpp:118
const char * toString() const
Definition: ISA.cpp:103
std::string toString(int flags=LM::DUMP_Short, const char *pre="") const
Definition: Insn.cpp:109
virtual void dumpme(std::ostream &o=std::cerr, const char *pre="") const
Definition: Insn.cpp:143
#define GCC_ATTR_UNUSED
Definition: gcc-attr.h:80
virtual void dumpme(std::ostream &o=std::cerr, const char *pre="") const
Definition: Insn.cpp:125