OpenASIP 2.2
Loading...
Searching...
No Matches
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 */
52std::string
53operandTypeCString(const Operand& operand) {
54 switch (operand.type()) {
55 default:
57 return "int";
58 break;
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 */
85void
86generateHeader(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
114int 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}
TTAMachine::Machine * machine
the architecture definition of the estimated processor
int main(int argc, char *argv[])
void generateHeader(std::ostream &stream, const TTAMachine::Machine &machine)
std::string operandTypeCString(const Operand &operand)
std::string errorMessage() const
Definition Exception.cc:123
virtual OperandType type() const
Definition Operand.cc:165
@ FLOAT_WORD
Definition Operand.hh:61
@ SINT_WORD
Definition Operand.hh:59
@ DOUBLE_WORD
Definition Operand.hh:62
@ UINT_WORD
Definition Operand.hh:60
static std::string stringToUpper(const std::string &source)
virtual HWOperation * operation(const std::string &name) const
virtual int operationCount() const
const std::string & name() const
ComponentType * item(int index) const
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition Machine.cc:380
static Machine * loadFromADF(const std::string &adfFileName)
Definition Machine.cc:899