OpenASIP  2.0
ExtensionGen.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  * Generates OpenCL C extension functions and definitions for the
26  * (custom) operations in the given ADF.
27  *
28  * @author Pekka Jääskeläinen 2009 (pjaaskel-no.spam-cs.tut.fi)
29  *
30  * @note rating: red
31  */
32 
33 #include <iostream>
34 #include <fstream>
35 #include <set>
36 #include <assert.h>
37 #include <boost/format.hpp>
38 
39 #include "OperationPool.hh"
40 #include "Operation.hh"
41 #include "Conversion.hh"
42 #include "OperationIndex.hh"
43 #include "Operand.hh"
44 #include "Machine.hh"
45 #include "StringTools.hh"
46 #include "HWOperation.hh"
47 
48 
49 /**
50  * Returns a C type string for the given operand type.
51  */
52 std::string
53 operandTypeCString(const Operand& operand) {
54  switch (operand.type()) {
55  default:
56  case Operand::SINT_WORD:
57  return "int";
58  break;
59  case Operand::UINT_WORD:
60  return "unsigned";
61  break;
63  return"float";
64  break;
66  return "double";
67  break;
68  }
69  return "unsigned"; // a good guess ;)
70 }
71 /**
72  * Writes the macros that can be written to the tceoclext.h header file to
73  * stdout.
74  *
75  * Following macros are produced for all operations found in the
76  * given machine (for example, in case of ADDSUB):
77  *
78  * #define cl_TCE_ADDSUB
79  * #define clADDSUBTCE _TCE_ADDSUB
80  *
81  * Thus, it's possible to figure out whether ADDSUB is implemented in the
82  * machine using the first define and actually call the ADDSUB with the
83  * latter.
84  */
85 void
86 generateHeader(std::ostream& stream, const TTAMachine::Machine& machine) {
87  std::set<std::string> opNames;
88 
91 
92  for (int i = 0; i < fuNav.count(); i++) {
93  const TTAMachine::FunctionUnit* fu = fuNav.item(i);
94  for (int o = 0; o < fu->operationCount(); o++) {
95  const std::string opName = fu->operation(o)->name();
96  opNames.insert(StringTools::stringToUpper(opName));
97  }
98  }
99  stream
100  << "// automatically generated by tceoclextgen" << std::endl
101  << std::endl;
102 
103  for (std::set<std::string>::const_iterator i = opNames.begin();
104  i != opNames.end(); ++i) {
105  std::string name = (*i);
106  stream
107  << (boost::format(
108  "#define cl_TCE_%s\n"
109  "#define cl%sTCE _TCE_%s\n\n")
110  % name % name % name).str();
111  }
112 }
113 
114 int main(int argc, char* argv[]) {
115 
116  if (argc != 2) {
117  std::cout << "Usage: tceoclextgen ADF" << std::endl;
118  return EXIT_FAILURE;
119  }
120 
121  try {
124  generateHeader(std::cout, *machine);
125 
126  delete machine; machine = NULL;
127  } catch (const Exception& e) {
128  std::cerr << e.errorMessage() << std::endl;
129  return EXIT_FAILURE;
130  }
131  return EXIT_SUCCESS;
132 }
Operand
Definition: Operand.hh:52
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
Operand::UINT_WORD
@ UINT_WORD
Definition: Operand.hh:60
TTAMachine::Machine::Navigator::count
int count() const
StringTools::stringToUpper
static std::string stringToUpper(const std::string &source)
Definition: StringTools.cc:143
StringTools.hh
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
HWOperation.hh
TTAMachine::HWOperation::name
const std::string & name() const
Definition: HWOperation.cc:141
Conversion.hh
operandTypeCString
std::string operandTypeCString(const Operand &operand)
Definition: ExtensionGen.cc:53
OperationIndex.hh
main
int main(int argc, char *argv[])
Definition: ExtensionGen.cc:114
Operand::FLOAT_WORD
@ FLOAT_WORD
Definition: Operand.hh:61
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
TTAMachine::FunctionUnit::operationCount
virtual int operationCount() const
Definition: FunctionUnit.cc:419
Operation.hh
Operand::SINT_WORD
@ SINT_WORD
Definition: Operand.hh:59
Machine.hh
Exception
Definition: Exception.hh:54
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
Operand.hh
Operand::DOUBLE_WORD
@ DOUBLE_WORD
Definition: Operand.hh:62
Operand::type
virtual OperandType type() const
Definition: Operand.cc:165
generateHeader
void generateHeader(std::ostream &stream, const TTAMachine::Machine &machine)
Definition: ExtensionGen.cc:86
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
OperationPool.hh
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
TTAMachine::Machine
Definition: Machine.hh:73
TTAMachine::Machine::loadFromADF
static Machine * loadFromADF(const std::string &adfFileName)
Definition: Machine.cc:905