OpenASIP  2.0
MachInfo.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014 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 MachInfo.cc
26  *
27  * MachInfo tool prints out information of a given processor design,
28  * for documentation purposes.
29  *
30  * @author Pekka Jääskeläinen 2014
31  */
32 
33 #include "Machine.hh"
34 #include "ControlUnit.hh"
36 #include "OperationPool.hh"
37 #include "HWOperation.hh"
38 #include "Operation.hh"
39 #include "Conversion.hh"
40 #include "FUPort.hh"
41 
42 #include <iostream>
43 #include <fstream>
44 #include <stdlib.h>
45 
47 
50  OperationPool OSAL;
51  Operation* osalOp = &OSAL.operation(hwop.name().c_str());
52  if (osalOp == &NullOperation::instance()) {
53  return TCEString("");
54  }
55  TCEString operandBindings = "";
56  for (int i = 1; i < osalOp->operandCount() + 1; i++) {
57  if (hwop.port(i) == NULL) {
58  std::cerr << "Warning: Operand " << i << " of " << hwop.name()
59  << " was not bound to any port." << std::endl;
60  continue;
61  }
62  if (i > 1) {
63  operandBindings += ", ";
64  }
65  operandBindings += Conversion::toString(i) + ": "
66  + hwop.port(i)->name();
67  }
68  return operandBindings;
69 }
70 
71 void
73  std::ofstream& output) {
74 
75  OperationPool OSAL;
76 
77  output << "\\begin{longtable}{|l|p{7cm}|p{3.5cm}|}" << std::endl;
78 
81  for (int i = 0; i < nav.count(); ++i) {
82  TTAMachine::FunctionUnit& fu = *nav.item(i);
83  output << "\\hline" << std::endl;
84  // TODO: print description here
85  TCEString fuDescription;
86  if (fu.hasAddressSpace()) {
87  fuDescription << " Accesses address space \\textbf{"
88  << fu.addressSpace()->name() << "}.\n";
89  }
90  output << fu.name() << "\t& \\multicolumn{2}{p{10cm}|}{"
91  << fuDescription << "} \\\\" << std::endl;
92  output << "\\hline" << std::endl;
93  for (int op = 0; op < fu.operationCount(); ++op) {
94  TTAMachine::HWOperation& hwop = *fu.operation(op);
95  Operation* osalOp = NULL;
96  TCEString description;
97  TCEString operandBindings;
98  if (&OSAL.operation(hwop.name().c_str())
100  osalOp = &OSAL.operation(hwop.name().c_str());
101  description = osalOp->description();
102  operandBindings = operandBindingsString(hwop);
103  } else {
104  std::cerr << "warning: Could not find OSAL data for operation '"
105  << hwop.name() << "." << std::endl;
106  }
107 
108  TCEString opname = hwop.name();
109  opname = opname.replaceString("_", "\\_");
110  operandBindings = operandBindings.replaceString("_", "\\_");
111  output << "\\footnotesize{" << opname << " (" << hwop.latency() - 1
112  << ")} & \\footnotesize{" << description
113  << "} & \\footnotesize{" << operandBindings << "}\\\\"
114  << std::endl;
115  }
116  }
117  output << "\\hline" << std::endl;
118  output << "\\hline" << std::endl;
119 
121  output << fu.name() << "\t & control unit & \t \\\\" << std::endl;
122 
123  output << "\\hline" << std::endl;
124  for (int op = 0; op < fu.operationCount(); ++op) {
125  TTAMachine::HWOperation& hwop = *fu.operation(op);
126  Operation* osalOp = NULL;
127  TCEString description;
128  if (&OSAL.operation(hwop.name().c_str())
129  != &NullOperation::instance()) {
130  osalOp = &OSAL.operation(hwop.name().c_str());
131  description = osalOp->description();
132  } else {
133  std::cerr << "warning: Could not find OSAL data for operation '"
134  << hwop.name() << "." << std::endl;
135  }
136  TCEString opname = hwop.name();
137  opname = opname.replaceString("_", "\\_");
138  output << opname << " (" << hwop.latency() - 1 << ") & \\small{"
139  << description << "} & \\\\" << std::endl;
140  }
141 
142  output << "\\hline" << std::endl;
143 
144  output << "\\end{longtable}" << std::endl;
145 
146 }
147 
148 void
150  std::ofstream& output) {
151 
152  output << "\\begin{tabular}{|l|l|l|l|l|}" << std::endl;
153 
154  output << "\\hline" << std::endl;
155 
156  output << "name & start address & end address & width (b) & "
157  << "numerical id(s) \\\\"
158  << std::endl;
159 
160  output << "\\hline" << std::endl;
161 
164  for (int i = 0; i < nav.count(); ++i) {
165  TTAMachine::AddressSpace& as = *nav.item(i);
166  if (&as == machine.controlUnit()->addressSpace())
167  continue;
168  output << as.name() << " & " << as.start() << " & " << as.end()
169  << " & " << as.width() << " & ";
170  std::set<unsigned> ids = as.numericalIds();
171  for (std::set<unsigned>::iterator i = ids.begin(), e = ids.end();
172  i != e; ++i) {
173  output << *i << " ";
174  }
175  output << "\\\\" << std::endl;
176  }
177 
178  output << "\\hline" << std::endl;
179  output << "\\hline" << std::endl;
180 
182 
183  output << as.name() << " & " << as.start() << " & " << as.end() << " & "
184  << as.width() << " & ";
185  std::set<unsigned> ids = as.numericalIds();
186  for (std::set<unsigned>::iterator i = ids.begin(), e = ids.end(); i != e;
187  ++i) {
188  output << *i << " ";
189  }
190  output << "\\\\" << std::endl;
191 
192  output << "\\hline" << std::endl;
193 
194  output << "\\end{tabular}" << std::endl;
195 }
196 
197 int
198 main(int argc, char* argv[]) {
199  try {
200  options.parse(argv, argc);
201  } catch (const ParserStopRequest&) {
202  // In case --help was asked, or illegal command line parameters.
203  return EXIT_SUCCESS;
204  } catch (const IllegalCommandLine& exception) {
205  std::cerr << exception.errorMessage() << std::endl;
206  return EXIT_FAILURE;
207  }
208 
209  if (options.numberOfArguments() != 1) {
210  std::cerr << "Single ADF file required." << std::endl;
211  return EXIT_FAILURE;
212  }
213  TCEString ADFFile = options.argument(1);
214 
215  if (options.outputFormat() != "latex") {
216  std::cerr << "Unsupported output format." << std::endl;
217  return EXIT_FAILURE;
218  }
219 
220  const TTAMachine::Machine* mach = NULL;
221  try {
222  mach = TTAMachine::Machine::loadFromADF(ADFFile);
223  } catch (const Exception& e) {
224  std::cerr << e.errorMessage() << std::endl;
225  return EXIT_FAILURE;
226  }
227  std::ofstream fuDescOutput;
228  std::ofstream asDescOutput;
229  try {
230  fuDescOutput.open(
231  (options.outputFileNameSuffix() + ".fu_table.tex").c_str(),
232  std::ios::trunc);
233  asDescOutput.open(
234  (options.outputFileNameSuffix() + ".as_table.tex").c_str(),
235  std::ios::trunc);
236 
237  } catch (std::exception& e) {
238  std::cerr << e.what() << std::endl;
239  return EXIT_FAILURE;
240  }
241  if (options.outputFormat() == "latex") {
242  printLatexFunctionUnitDescription(*mach, fuDescOutput);
243  printLatexAddressSpaceDescription(*mach, asDescOutput);
244  }
245  fuDescOutput.close();
246  asDescOutput.close();
247  return EXIT_SUCCESS;
248 }
OperationPool::operation
Operation & operation(const char *name)
Definition: OperationPool.cc:99
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
ParserStopRequest
Definition: Exception.hh:491
MachInfoCmdLineOptions
Definition: MachInfoCmdLineOptions.hh:36
TTAMachine::FunctionUnit::hasAddressSpace
virtual bool hasAddressSpace() const
Definition: FunctionUnit.cc:608
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
TTAMachine::HWOperation
Definition: HWOperation.hh:52
TTAMachine::AddressSpace::numericalIds
std::set< unsigned > numericalIds() const
Definition: AddressSpace.cc:393
TTAMachine::AddressSpace
Definition: AddressSpace.hh:51
CmdLineParser::numberOfArguments
virtual int numberOfArguments() const
printLatexFunctionUnitDescription
void printLatexFunctionUnitDescription(const TTAMachine::Machine &machine, std::ofstream &output)
Definition: MachInfo.cc:72
operandBindingsString
TCEString operandBindingsString(TTAMachine::HWOperation &hwop)
Definition: MachInfo.cc:49
IllegalCommandLine
Definition: Exception.hh:438
TTAMachine::FunctionUnit::addressSpace
virtual AddressSpace * addressSpace() const
Definition: FunctionUnit.cc:580
TTAMachine::Machine::Navigator::count
int count() const
NullOperation::instance
static NullOperation & instance()
Conversion::toString
static std::string toString(const T &source)
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::HWOperation::port
virtual FUPort * port(int operand) const
Definition: HWOperation.cc:320
TTAMachine::Machine::controlUnit
virtual ControlUnit * controlUnit() const
Definition: Machine.cc:345
HWOperation.hh
TTAMachine::HWOperation::name
const std::string & name() const
Definition: HWOperation.cc:141
Conversion.hh
MachInfoCmdLineOptions::outputFileNameSuffix
TCEString outputFileNameSuffix() const
Definition: MachInfoCmdLineOptions.cc:63
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
TTAMachine::FunctionUnit::operationCount
virtual int operationCount() const
Definition: FunctionUnit.cc:419
Operation.hh
Machine.hh
Exception
Definition: Exception.hh:54
TTAMachine::Machine::addressSpaceNavigator
virtual AddressSpaceNavigator addressSpaceNavigator() const
Definition: Machine.cc:392
Operation
Definition: Operation.hh:59
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
Operation::operandCount
virtual int operandCount() const
Definition: Operation.cc:212
CmdLineOptions::parse
void parse(char *argv[], int argc)
Definition: CmdLineOptions.cc:107
TCEString::replaceString
TCEString & replaceString(const std::string &old, const std::string &newString)
Definition: TCEString.cc:94
MachInfoCmdLineOptions::outputFormat
TCEString outputFormat() const
Definition: MachInfoCmdLineOptions.cc:71
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
Operation::description
virtual TCEString description() const
Definition: Operation.cc:103
main
int main(int argc, char *argv[])
Definition: MachInfo.cc:198
TTAMachine::AddressSpace::width
virtual int width() const
Definition: AddressSpace.cc:155
MachInfoCmdLineOptions.hh
TTAMachine::Port::name
virtual std::string name() const
Definition: Port.cc:141
TCEString
Definition: TCEString.hh:53
FUPort.hh
ControlUnit.hh
printLatexAddressSpaceDescription
void printLatexAddressSpaceDescription(const TTAMachine::Machine &machine, std::ofstream &output)
Definition: MachInfo.cc:149
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
TTAMachine::HWOperation::latency
int latency() const
Definition: HWOperation.cc:216
OperationPool
Definition: OperationPool.hh:52
CmdLineParser::argument
virtual std::string argument(int index) const
TTAMachine::AddressSpace::start
virtual ULongWord start() const
Definition: AddressSpace.cc:166
OperationPool.hh
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
TTAMachine::AddressSpace::end
virtual ULongWord end() const
Definition: AddressSpace.cc:177
TTAMachine::Machine
Definition: Machine.hh:73
TTAMachine::Machine::loadFromADF
static Machine * loadFromADF(const std::string &adfFileName)
Definition: Machine.cc:905