1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
#ifndef __TCompiler__
#define __TCompiler__
#include "TLang.hh"
#include "TSyntax.hh"
extern int gVecSize;
extern TBlockStatement* gExternalBlock;
extern TBlockStatement* gDecBlock;
struct TCompiler
{
virtual ~TCompiler() {}
virtual void compileTop(TSignal* signal) // Here a single signal
{
compileVector(signal);
}
virtual void compileVector(TSignal* signal)
{
int output_rate = signal->getRate();
TType* input_type = signal->getType();
#ifdef ALT_VECTOR
TVectorAddress* new_out_vec = MR_VECTOR_ADDRESS("output", MR_FLOAT_TYPE(), output_rate * gVecSize);
#else
TVectorType* vec_type = MR_VECTOR_TYPE(MR_FLOAT_TYPE(), output_rate * gVecSize);
TNamedAddress* new_out_vec = MR_VECTOR_ADDRESS("output", vec_type);
#endif
TIndex* var_in = MR_VAR("i");
TAddress* out_address = MR_INDEX_ADDRESS(new_out_vec, var_in);
// Type checking
CHECK_EQUAL_TYPE(input_type, out_address->getType());
// Compilation
TBlockStatement* sub_block = MR_BLOCK();
gExternalBlock = MR_BLOCK();
gDecBlock = MR_BLOCK();
#ifndef ALT_VECTOR
MR_PUSH_BLOCK(gDecBlock, MR_DEC_TYPE(vec_type));
#endif
signal->compileStatement(sub_block, out_address, var_in);
TLoopStatement* global_loop = MR_LOOP(output_rate * gVecSize, var_in, sub_block);
// Pseudo code generation
cout << "// -----------------" << endl;
cout << "// Declaration block" << endl;
cout << "// -----------------" << endl;
gDecBlock->generate(&cout, 0);
cout << endl << endl << "-----------------" << endl;
cout << "Separated loops" << endl;
cout << "-----------------" << endl;
gExternalBlock->generate(&cout, 0);
cout << endl << "-----------------" << endl;
cout << "Result" << endl;
cout << "-----------------" << endl;
global_loop->generate(&cout, 0);
cout << endl;
// C++ code generation
/*
#ifdef ALT_VECTOR
cout << "#include <stdio.h>" << endl;
cout << "#include <string.h>" << endl << endl;
cout << "// -----------------" << endl;
cout << "// Declaration block" << endl;
cout << "// -----------------" << endl;
gDecBlock->generateCPP(&cout, 0);
cout << endl << "void process()" << endl;
cout << "{" << endl;
cout << "\tfloat input0[32 * 16];" << endl; // Should use real input rate....
cout << "\tfloat input1[32 * 16];" << endl;
cout << "\tfloat input2[32 * 16];" << endl;
cout << "\tfloat input3[32 * 16];" << endl;
cout << "\tfloat output[32 * 16];" << endl;
// Should use real input rate....
cout << "\tfor (int i = 0; i < 32 * 16; i++) {" << endl;
cout << "\t\tinput0[i] = float(i);" << endl;
cout << "\t\tinput1[i] = float(i);" << endl;
cout << "\t\tinput2[i] = float(i);" << endl;
cout << "\t\tinput3[i] = float(i);" << endl;
cout << "\t}" << endl;
cout << "\tmemset(output, 0, sizeof(float) * 32 * 16);" << endl;
cout << endl << endl << "\t// -----------------" << endl;
cout << "\t// Separated loops" << endl;
cout << "\t// -----------------" << endl;
gExternalBlock->generateCPP(&cout, 1);
cout << endl << "\t// -----------------" << endl;
cout << "\t// Result" << endl;
cout << "\t// -----------------" << endl;
global_loop->generateCPP(&cout, 1);
cout << endl;
cout << "\tfor (int i = 0; i < 32 * 16; i++) {" << endl;
cout << "\t\tprintf(\"output %f \\n\", output[i]);" << endl;
cout << "\t}" << endl;
cout << "}" << endl << endl;
cout << "int main()" << endl;
cout << "{" << endl;
cout << "\tprocess();" << endl;
cout << "}" << endl << endl;
#else
cout << "#include <stdio.h>" << endl;
cout << "#include <string.h>" << endl << endl;
cout << "// -----------------" << endl;
cout << "// Declaration block" << endl;
cout << "// -----------------" << endl;
gDecBlock->generateCPP(&cout, 0);
cout << endl << "void process()" << endl;
cout << "{" << endl;
cout << "\t" << vec_type->fDecName << " input0;" << endl; // Should use real input rate....
cout << "\t" << vec_type->fDecName << " input1;" << endl;
cout << "\t" << vec_type->fDecName << " input2;" << endl;
cout << "\t" << vec_type->fDecName << " input3;" << endl;
cout << "\t" << vec_type->fDecName << " output;" << endl;
// Should use real input rate....
cout << "\tfor (int i = 0; i < sizeof(" << vec_type->fDecName << ") / sizeof(float); i++) {" << endl;
cout << "\t\tinput0.f[i] = float(i);" << endl;
cout << "\t\tinput1.f[i] = float(i);" << endl;
cout << "\t\tinput2.f[i] = float(i);" << endl;
cout << "\t\tinput3.f[i] = float(i);" << endl;
cout << "\t\toutput.f[i] = 0.f;" << endl;
cout << "\t}" << endl;
cout << endl << endl << "\t// -----------------" << endl;
cout << "\t// Separated loops" << endl;
cout << "\t// -----------------" << endl;
gExternalBlock->generateCPP(&cout, 1);
cout << endl << "\t// -----------------" << endl;
cout << "\t// Result" << endl;
cout << "\t// -----------------" << endl;
global_loop->generateCPP(&cout, 1);
cout << endl;
cout << "\tfor (int i = 0; i < sizeof(" << vec_type->fDecName << ") / sizeof(float); i++) {" << endl;
cout << "\t\tprintf(\"output %f \\n\", output.f[i]);" << endl;
cout << "\t}" << endl;
cout << "}" << endl << endl;
cout << "int main()" << endl;
cout << "{" << endl;
cout << "\tprocess();" << endl;
cout << "}" << endl << endl;
#endif
*/
// C++ code generation without aliasing
#ifdef ALT_VECTOR
cout << "#include <stdio.h>" << endl;
cout << "#include <string.h>" << endl << endl;
cout << "// -----------------" << endl;
cout << "// Declaration block" << endl;
cout << "// -----------------" << endl;
gDecBlock->generateCPPNoAlias(&cout, 0);
cout << endl << "void process()" << endl;
cout << "{" << endl;
cout << "\tfloat input0[32 * 16];" << endl; // Should use real input rate....
cout << "\tfloat input1[32 * 16];" << endl;
cout << "\tfloat input2[32 * 16];" << endl;
cout << "\tfloat input3[32 * 16];" << endl;
cout << "\tfloat output[32 * 16];" << endl;
// Should use real input rate....
cout << "\tfor (int i = 0; i < 32 * 16; i++) {" << endl;
cout << "\t\tinput0[i] = float(i);" << endl;
cout << "\t\tinput1[i] = float(i);" << endl;
cout << "\t\tinput2[i] = float(i);" << endl;
cout << "\t\tinput3[i] = float(i);" << endl;
cout << "\t}" << endl;
cout << "\tmemset(output, 0, sizeof(float) * 32 * 16);" << endl;
cout << endl << endl << "\t// -----------------" << endl;
cout << "\t// Separated loops" << endl;
cout << "\t// -----------------" << endl;
gExternalBlock->generateCPPNoAlias(&cout, 1);
cout << endl << "\t// -----------------" << endl;
cout << "\t// Result" << endl;
cout << "\t// -----------------" << endl;
global_loop->generateCPPNoAlias(&cout, 1);
cout << endl;
cout << "\tfor (int i = 0; i < 32 * 16; i++) {" << endl;
cout << "\t\tprintf(\"output %f \\n\", output[i]);" << endl;
cout << "\t}" << endl;
cout << "}" << endl << endl;
cout << "int main()" << endl;
cout << "{" << endl;
cout << "\tprocess();" << endl;
cout << "}" << endl << endl;
#else
cout << "#include <stdio.h>" << endl;
cout << "#include <string.h>" << endl << endl;
cout << "// -----------------" << endl;
cout << "// Declaration block" << endl;
cout << "// -----------------" << endl;
gDecBlock->generateCPPNoAlias(&cout, 0);
cout << endl << "void process()" << endl;
cout << "{" << endl;
cout << "\t" << vec_type->fDecName << " input0;" << endl; // Should use real input rate....
cout << "\t" << vec_type->fDecName << " input1;" << endl;
cout << "\t" << vec_type->fDecName << " input2;" << endl;
cout << "\t" << vec_type->fDecName << " input3;" << endl;
cout << "\t" << vec_type->fDecName << " output;" << endl;
// Should use real input rate....
cout << "\tfor (int i = 0; i < sizeof(" << vec_type->fDecName << ") / sizeof(float); i++) {" << endl;
cout << "\t\tinput0[i] = float(i);" << endl;
cout << "\t\tinput1[i] = float(i);" << endl;
cout << "\t\tinput2[i] = float(i);" << endl;
cout << "\t\tinput3[i] = float(i);" << endl;
cout << "\t\toutput[i] = 0.f;" << endl;
cout << "\t}" << endl;
cout << endl << endl << "\t// -----------------" << endl;
cout << "\t// Separated loops" << endl;
cout << "\t// -----------------" << endl;
gExternalBlock->generateCPPNoAlias(&cout, 1);
cout << endl << "\t// -----------------" << endl;
cout << "\t// Result" << endl;
cout << "\t// -----------------" << endl;
global_loop->generateCPPNoAlias(&cout, 1);
cout << endl;
cout << "\tfor (int i = 0; i < sizeof(" << vec_type->fDecName << ") / sizeof(float); i++) {" << endl;
cout << "\t\tprintf(\"output %f \\n\", output[i]);" << endl;
cout << "\t}" << endl;
cout << "}" << endl << endl;
cout << "int main()" << endl;
cout << "{" << endl;
cout << "\tprocess();" << endl;
cout << "}" << endl << endl;
#endif
}
};
#endif
|