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 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
|
#include <cstring>
#include <iostream>
#include <fstream>
class operand {
public:
operand(const char* name, const char* templateName, const char* iterator,
const char* numtype, const char* initialization)
: name_(name), template_(templateName), iterator_(iterator),
numtype_(numtype), initialization_(initialization)
{ }
int haveTemplate() const
{ return template_ != 0; }
void setOperandNum(int i)
{ operandNum_ = i; }
virtual void printName(std::ostream& os)
{
os << name_;
if (haveTemplate())
{
os << "<" << template_ << operandNum_ << ">";
}
}
virtual void printTemplate(std::ostream& os, int n=0)
{
if (haveTemplate())
os << template_ << operandNum_;
}
virtual void printTemplateType(std::ostream& os, int n=0)
{
if (haveTemplate())
os << "class";
}
virtual int numTemplateParameters() const
{
if (haveTemplate())
return 1;
else
return 0;
}
virtual int isScalar() const
{ return 0; }
virtual int isInteger() const
{ return 0; }
virtual int isComplex() const
{ return 0; }
virtual int isRange() const
{ return 0; }
virtual void printArgument(std::ostream& os)
{
printName(os);
os << " d" << operandNum_;
}
virtual void printIterator(std::ostream& os)
{
os << iterator_;
if (haveTemplate())
os << "<" << template_ << operandNum_ << ">";
}
virtual void printNumtype(std::ostream& os)
{
os << numtype_ << operandNum_;
}
virtual void printInitialization(std::ostream& os)
{
os << "d" << operandNum_;
if (initialization_ != 0)
os << initialization_;
}
protected:
const char* name_;
const char* template_;
const char* iterator_;
const char* numtype_;
const char* initialization_;
int operandNum_;
};
class VecOperand : public operand {
public:
VecOperand()
: operand("Vector", "P_numtype", "VectorIterConst",
"P_numtype", ".beginFast()")
{ }
virtual void printArgument(std::ostream& os)
{
os << "const ";
printName(os);
os << "& d" << operandNum_;
}
};
class TinyVecOperand : public operand {
public:
TinyVecOperand()
: operand("TinyVector", "P_numtype", "TinyVectorIterConst",
"P_numtype", ".beginFast()")
{ }
virtual void printArgument(std::ostream& os)
{
os << "const ";
printName(os);
os << "& d" << operandNum_;
}
virtual void printName(std::ostream& os)
{
os << "TinyVector<P_numtype" << operandNum_
<< ", N_length" << operandNum_ << ">";
}
virtual void printTemplate(std::ostream& os, int n)
{
if (n == 0)
{
os << "P_numtype" << operandNum_;
}
else if (n == 1)
{
os << "N_length" << operandNum_;
}
}
virtual void printTemplateType(std::ostream& os, int n)
{
if (n == 0)
os << "class";
else if (n == 1)
os << "int";
}
virtual int numTemplateParameters() const
{
return 2;
}
virtual void printIterator(std::ostream& os)
{
os << "TinyVectorIterConst<P_numtype" << operandNum_
<< ", N_length" << operandNum_ << ">";
}
};
class VecPickOperand : public operand {
public:
VecPickOperand()
: operand("VectorPick", "P_numtype", "VectorPickIterConst",
"P_numtype", ".beginFast()")
{ }
virtual void printArgument(std::ostream& os)
{
os << "const ";
printName(os);
os << "& d" << operandNum_;
}
};
class VecExprOperand : public operand {
public:
VecExprOperand()
: operand("_bz_VecExpr", "P_expr", "_bz_VecExpr",
0, 0)
{ }
virtual void printNumtype(std::ostream& os)
{
os << "typename P_expr" << operandNum_ << "::T_numtype";
}
};
class RangeOperand : public operand {
public:
RangeOperand()
: operand("Range", 0, "Range", 0, 0)
{ }
virtual void printNumtype(std::ostream& os)
{
os << "int";
}
virtual int isRange() const
{ return 1; }
};
class ScalarOperand : public operand {
public:
ScalarOperand(const char* name)
: operand(name, 0, 0, name, 0)
{ }
virtual void printIterator(std::ostream& os)
{
os << "_bz_VecExprConstant<" << name_ << ">";
}
virtual void printInitialization(std::ostream& os)
{
os << "_bz_VecExprConstant<" << name_ << ">(d"
<< operandNum_ << ")";
}
virtual void printNumtype(std::ostream& os)
{
os << name_;
}
virtual int isScalar() const
{ return 1; }
virtual int isInteger() const
{ return !strcmp(name_, "int"); }
};
class ComplexOperand : public operand {
public:
ComplexOperand()
: operand("complex", "T", 0, "complex", 0)
{ }
virtual int isComplex() const
{ return 1; }
virtual void printIterator(std::ostream& os)
{
os << "_bz_VecExprConstant<";
printNumtype(os);
os << "> ";
}
virtual void printInitialization(std::ostream& os)
{
printIterator(os);
os << "(d" << operandNum_ << ")";
}
virtual void printNumtype(std::ostream& os)
{
os << "complex<";
printTemplate(os);
os << "> ";
}
virtual int isScalar() const
{ return 1; }
virtual int isInteger() const
{ return !strcmp(name_, "int"); }
};
/**************************************************************************
*
* Operand Set
*
**************************************************************************/
#define BZ_VECEXPR_NUM_OPERANDS 10
class operandSet {
public:
operandSet()
{
operands_[0] = new VecOperand;
operands_[1] = new VecExprOperand;
operands_[2] = new VecPickOperand;
operands_[3] = new RangeOperand;
operands_[4] = new TinyVecOperand;
operands_[5] = new ScalarOperand("int");
operands_[6] = new ScalarOperand("float");
operands_[7] = new ScalarOperand("double");
operands_[8] = new ScalarOperand("long double");
operands_[9] = new ComplexOperand;
// operands_[8] = new ScalarOperand("complex<float> ");
// operands_[9] = new ScalarOperand("complex<double> ");
// operands_[10] = new ScalarOperand("complex<long double> ");
}
~operandSet()
{
for (int i=0; i < BZ_VECEXPR_NUM_OPERANDS; ++i)
delete operands_[i];
}
operand& operator[](int i)
{ return *operands_[i]; }
int numOperands() const
{ return BZ_VECEXPR_NUM_OPERANDS; }
void setOperandNum(int num)
{
for (int i=0; i < BZ_VECEXPR_NUM_OPERANDS; ++i)
operands_[i]->setOperandNum(num);
}
private:
operandSet(const operandSet&);
void operator=(const operandSet&);
operand * operands_[BZ_VECEXPR_NUM_OPERANDS];
};
|