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
|
/************************************************************************
************************************************************************
FAUST compiler
Copyright (C) 2003-2018 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
************************************************************************
************************************************************************/
#ifndef _INSTRUCTIONS_TYPE_H
#define _INSTRUCTIONS_TYPE_H
#include <string>
#include "garbageable.hh"
// ============================
// Base class for instructions
// ============================
struct Printable : public virtual Garbageable {
static std::ostream* fOut;
Printable() {}
virtual ~Printable() {}
};
// ========================
// Base classes for types
// ========================
struct InstVisitor;
struct CloneVisitor;
struct Typed : public Printable {
enum VarType {
kInt32,
kInt32_ptr,
kInt32_vec,
kInt32_vec_ptr,
kInt64,
kInt64_ptr,
kInt64_vec,
kInt64_vec_ptr,
kBool,
kBool_ptr,
kBool_vec,
kBool_vec_ptr,
kFloat,
kFloat_ptr,
kFloat_ptr_ptr,
kFloat_vec,
kFloat_vec_ptr,
kFloatMacro,
kFloatMacro_ptr,
kFloatMacro_ptr_ptr,
kDouble,
kDouble_ptr,
kDouble_ptr_ptr,
kDouble_vec,
kDouble_vec_ptr,
kQuad,
kQuad_ptr,
kQuad_ptr_ptr,
kQuad_vec,
kQuad_vec_ptr,
kFixedPoint,
kFixedPoint_ptr,
kFixedPoint_ptr_ptr,
kFixedPoint_vec,
kFixedPoint_vec_ptr,
kVoid,
kVoid_ptr,
kObj,
kObj_ptr,
kSound,
kSound_ptr,
kUint_ptr,
kNoType
};
Typed() {}
virtual ~Typed() {}
// Returns the pointer type version of a primitive type
static VarType getPtrFromType(VarType type)
{
switch (type) {
case kFloatMacro:
return kFloatMacro_ptr;
case kFloatMacro_ptr:
return kFloatMacro_ptr_ptr;
case kFloat:
return kFloat_ptr;
case kFloat_ptr:
return kFloat_ptr_ptr;
case kFloat_vec:
return kFloat_vec_ptr;
case kInt32:
return kInt32_ptr;
case kInt32_vec:
return kInt32_vec_ptr;
case kDouble:
return kDouble_ptr;
case kDouble_ptr:
return kDouble_ptr_ptr;
case kDouble_vec:
return kDouble_vec_ptr;
case kQuad:
return kQuad_ptr;
case kQuad_ptr:
return kQuad_ptr_ptr;
case kQuad_vec:
return kQuad_vec_ptr;
case kFixedPoint:
return kFixedPoint_ptr;
case kFixedPoint_ptr:
return kFixedPoint_ptr_ptr;
case kFixedPoint_vec:
return kFixedPoint_vec_ptr;
case kBool:
return kBool_ptr;
case kBool_vec:
return kBool_vec_ptr;
case kVoid:
return kVoid_ptr;
case kObj:
return kObj_ptr;
case kSound:
return kSound_ptr;
default:
// Not supposed to happen
std::cerr << "ASSERT : getPtrFromType " << type << std::endl;
faustassert(false);
return kNoType;
}
}
// Returns the vector type version of a primitive type
static VarType getVecFromType(VarType type)
{
switch (type) {
case kFloat:
return kFloat_vec;
case kInt32:
return kInt32_vec;
case kDouble:
return kDouble_vec;
case kQuad:
return kQuad_vec;
case kFixedPoint:
return kFixedPoint_vec;
case kBool:
return kBool_vec;
default:
// Not supposed to happen
std::cerr << "ASSERT : getVecFromType " << type << std::endl;
faustassert(false);
return kNoType;
}
}
// Returns the type version from pointer on a primitive type
static VarType getTypeFromPtr(VarType type)
{
switch (type) {
case kFloatMacro_ptr:
return kFloatMacro;
case kFloatMacro_ptr_ptr:
return kFloatMacro_ptr;
case kFloat_ptr:
return kFloat;
case kFloat_ptr_ptr:
return kFloat_ptr;
case kFloat_vec_ptr:
return kFloat_vec;
case kInt32_ptr:
return kInt32;
case kInt32_vec_ptr:
return kInt32_vec;
case kDouble_ptr:
return kDouble;
case kDouble_ptr_ptr:
return kDouble_ptr;
case kDouble_vec_ptr:
return kDouble_vec;
case kQuad_ptr:
return kQuad;
case kQuad_ptr_ptr:
return kQuad_ptr;
case kQuad_vec_ptr:
return kQuad_vec;
case kFixedPoint_ptr:
return kFixedPoint;
case kFixedPoint_ptr_ptr:
return kFixedPoint_ptr;
case kFixedPoint_vec_ptr:
return kFixedPoint_vec;
case kBool_ptr:
return kBool;
case kBool_vec_ptr:
return kBool_vec;
case kVoid_ptr:
return kVoid;
case kObj_ptr:
return kObj;
case kSound_ptr:
return kSound;
default:
// Not supposed to happen
std::cerr << "ASSERT : getTypeFromPtr " << Typed::gTypeString[type] << std::endl;
faustassert(false);
return kNoType;
}
}
// Returns the type version from vector on a primitive type
static VarType getTypeFromVec(VarType type)
{
switch (type) {
case kFloat_vec:
return kFloat;
case kInt32_vec:
return kInt32;
case kDouble_vec:
return kDouble;
case kQuad_vec:
return kQuad;
case kFixedPoint_vec:
return kFixedPoint;
case kBool_vec:
return kBool;
default:
// Not supposed to happen
std::cerr << "ASSERT : getTypeFromVec " << Typed::gTypeString[type] << std::endl;
faustassert(false);
return kNoType;
}
}
static std::string gTypeString[];
static void init();
virtual VarType getType() const = 0;
virtual int getSizeBytes() const = 0;
virtual void accept(InstVisitor* visitor) = 0;
virtual Typed* clone(CloneVisitor* cloner) = 0;
bool isBasicTyped();
bool isNamedTyped();
bool isArrayTyped();
bool isStructTyped();
bool isVectorTyped();
virtual std::string toString() = 0;
};
#endif
|