int64_t Val = II->getValue();
if (Val != 0 && Val != 1) return 0; // Only accept 0 or 1 for a bit!
- return new BitInit(Val != 0);
+ return BitInit::get(Val != 0);
}
const Init *BitRecTy::convertValue(const TypedInit *VI) {
SmallVector<const Init *, 16> NewBits(Size);
for (unsigned i = 0; i != Size; ++i)
- NewBits[i] = new UnsetInit();
+ NewBits[i] = UnsetInit::get();
- return new BitsInit(ArrayRef<const Init *>(NewBits));
+ return BitsInit::get(NewBits);
}
const Init *BitsRecTy::convertValue(const BitInit *UI) {
if (Size != 1) return 0; // Can only convert single bit.
- return new BitsInit(ArrayRef<const Init *>(UI));
+ return BitsInit::get(UI);
}
/// canFitInBitfield - Return true if the number of bits is large enough to hold
SmallVector<const Init *, 16> NewBits(Size);
for (unsigned i = 0; i != Size; ++i)
- NewBits[i] = new BitInit(Value & (1LL << i));
+ NewBits[i] = BitInit::get(Value & (1LL << i));
- return new BitsInit(ArrayRef<const Init *>(NewBits));
+ return BitsInit::get(NewBits);
}
const Init *BitsRecTy::convertValue(const BitsInit *BI) {
SmallVector<const Init *, 16> NewBits(Size);
for (unsigned i = 0; i != Size; ++i)
- NewBits[i] = new VarBitInit(VI, i);
- return new BitsInit(ArrayRef<const Init *>(NewBits));
+ NewBits[i] = VarBitInit::get(VI, i);
+ return BitsInit::get(NewBits);
}
if (Size == 1 && dynamic_cast<BitRecTy*>(VI->getType()))
- return new BitsInit(ArrayRef<const Init *>(VI));
+ return BitsInit::get(VI);
if (const TernOpInit *Tern = dynamic_cast<const TernOpInit*>(VI)) {
if (Tern->getOpcode() == TernOpInit::IF) {
for (unsigned i = 0; i != Size; ++i)
NewBits[i] =
- new TernOpInit(TernOpInit::IF, LHS,
- new IntInit((MHSVal & (1LL << i)) ? 1 : 0),
- new IntInit((RHSVal & (1LL << i)) ? 1 : 0),
- VI->getType());
+ TernOpInit::get(TernOpInit::IF, LHS,
+ IntInit::get((MHSVal & (1LL << i)) ? 1 : 0),
+ IntInit::get((RHSVal & (1LL << i)) ? 1 : 0),
+ VI->getType());
- return new BitsInit(ArrayRef<const Init *>(NewBits));
+ return BitsInit::get(NewBits);
}
} else {
const BitsInit *MHSbs = dynamic_cast<const BitsInit*>(MHS);
SmallVector<const Init *, 16> NewBits(Size);
for (unsigned i = 0; i != Size; ++i)
- NewBits[i] = new TernOpInit(TernOpInit::IF, LHS,
- MHSbs->getBit(i),
- RHSbs->getBit(i),
- VI->getType());
+ NewBits[i] = TernOpInit::get(TernOpInit::IF, LHS,
+ MHSbs->getBit(i),
+ RHSbs->getBit(i),
+ VI->getType());
- return new BitsInit(ArrayRef<const Init *>(NewBits));
+ return BitsInit::get(NewBits);
}
}
}
}
const Init *IntRecTy::convertValue(const BitInit *BI) {
- return new IntInit(BI->getValue());
+ return IntInit::get(BI->getValue());
}
const Init *IntRecTy::convertValue(const BitsInit *BI) {
} else {
return 0;
}
- return new IntInit(Result);
+ return IntInit::get(Result);
}
const Init *IntRecTy::convertValue(const TypedInit *TI) {
const Init *L = BO->getOperand()->convertInitializerTo(this);
if (L == 0) return 0;
if (L != BO->getOperand())
- return new UnOpInit(UnOpInit::CAST, L, new StringRecTy);
+ return UnOpInit::get(UnOpInit::CAST, L, new StringRecTy);
return BO;
}
const Init *R = BO->getRHS()->convertInitializerTo(this);
if (L == 0 || R == 0) return 0;
if (L != BO->getLHS() || R != BO->getRHS())
- return new BinOpInit(BinOpInit::STRCONCAT, L, R, new StringRecTy);
+ return BinOpInit::get(BinOpInit::STRCONCAT, L, R, new StringRecTy);
return BO;
}
return 0;
}
- return new ListInit(Elements, this);
+ return ListInit::get(Elements, this);
}
const Init *ListRecTy::convertValue(const TypedInit *TI) {
const Init *L = BO->getOperand()->convertInitializerTo(this);
if (L == 0) return 0;
if (L != BO->getOperand())
- return new UnOpInit(UnOpInit::CAST, L, new DagRecTy);
+ return UnOpInit::get(UnOpInit::CAST, L, new DagRecTy);
return BO;
}
return 0;
const Init *R = BO->getRHS()->convertInitializerTo(this);
if (L == 0 || R == 0) return 0;
if (L != BO->getLHS() || R != BO->getRHS())
- return new BinOpInit(BinOpInit::CONCAT, L, R, new DagRecTy);
+ return BinOpInit::get(BinOpInit::CONCAT, L, R, new DagRecTy);
return BO;
}
return 0;
void Init::dump() const { return print(errs()); }
+const UnsetInit *UnsetInit::get() {
+ return new UnsetInit;
+}
+
+const BitInit *BitInit::get(bool V) {
+ return new BitInit(V);
+}
+
+const BitsInit *BitsInit::get(ArrayRef<const Init *> Range) {
+ return new BitsInit(Range);
+}
+
const Init *
BitsInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) const {
SmallVector<const Init *, 16> NewBits(Bits.size());
return 0;
NewBits[i] = getBit(Bits[i]);
}
- return new BitsInit(ArrayRef<const Init *>(NewBits));
+ return BitsInit::get(NewBits);
}
std::string BitsInit::getAsString() const {
}
if (Changed)
- return new BitsInit(ArrayRef<const Init *>(NewBits));
+ return BitsInit::get(NewBits);
return this;
}
+const IntInit *IntInit::get(int64_t V) {
+ return new IntInit(V);
+}
+
std::string IntInit::getAsString() const {
return itostr(Value);
}
if (Bits[i] >= 64)
return 0;
- NewBits[i] = new BitInit(Value & (INT64_C(1) << Bits[i]));
+ NewBits[i] = BitInit::get(Value & (INT64_C(1) << Bits[i]));
}
- return new BitsInit(ArrayRef<const Init *>(NewBits));
+ return BitsInit::get(NewBits);
+}
+
+const StringInit *StringInit::get(const std::string &V) {
+ return new StringInit(V);
+}
+
+const CodeInit *CodeInit::get(const std::string &V) {
+ return new CodeInit(V);
+}
+
+const ListInit *ListInit::get(ArrayRef<const Init *> Range, RecTy *EltTy) {
+ return new ListInit(Range, EltTy);
}
const Init *
return 0;
Vals.push_back(getElement(Elements[i]));
}
- return new ListInit(Vals, getType());
+ return ListInit::get(Vals, getType());
}
Record *ListInit::getElementAsRecord(unsigned i) const {
}
if (Changed)
- return new ListInit(Resolved, getType());
+ return ListInit::get(Resolved, getType());
return this;
}
return 0;
}
+const UnOpInit *UnOpInit::get(UnaryOp opc, const Init *lhs, RecTy *Type) {
+ return new UnOpInit(opc, lhs, Type);
+}
+
const Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
switch (getOpcode()) {
default: assert(0 && "Unknown unop");
const DefInit *LHSd = dynamic_cast<const DefInit*>(LHS);
if (LHSd) {
- return new StringInit(LHSd->getDef()->getName());
+ return StringInit::get(LHSd->getDef()->getName());
}
} else {
const StringInit *LHSs = dynamic_cast<const StringInit*>(LHS);
if (const RecordVal *RV = CurRec->getValue(Name)) {
if (RV->getType() != getType())
throw "type mismatch in cast";
- return new VarInit(Name, RV->getType());
+ return VarInit::get(Name, RV->getType());
}
std::string TemplateArgName = CurRec->getName()+":"+Name;
if (RV->getType() != getType())
throw "type mismatch in cast";
- return new VarInit(TemplateArgName, RV->getType());
+ return VarInit::get(TemplateArgName, RV->getType());
}
}
if (RV->getType() != getType())
throw "type mismatch in cast";
- return new VarInit(MCName, RV->getType());
+ return VarInit::get(MCName, RV->getType());
}
}
assert(0 && "Empty list in cdr");
return 0;
}
- ListInit::const_iterator begin = LHSl->begin()+1;
- ListInit::const_iterator end = LHSl->end();
- // We can't pass these iterators directly to ArrayRef because
- // they are not convertible to Init **. Fortunately,
- // RandomAccessIterator::operator * is guaranteed to return an
- // lvalue.
- ListInit *Result =
- new ListInit(ArrayRef<const Init *>(&*begin, end - begin),
- LHSl->getType());
+ // Note the +1. We can't just pass the result of getValues()
+ // directly.
+ ArrayRef<const Init *>::iterator begin = LHSl->getValues().begin()+1;
+ ArrayRef<const Init *>::iterator end = LHSl->getValues().end();
+ const ListInit *Result =
+ ListInit::get(ArrayRef<const Init *>(begin, end - begin),
+ LHSl->getType());
return Result;
}
break;
const ListInit *LHSl = dynamic_cast<const ListInit*>(LHS);
if (LHSl) {
if (LHSl->getSize() == 0) {
- return new IntInit(1);
+ return IntInit::get(1);
} else {
- return new IntInit(0);
+ return IntInit::get(0);
}
}
const StringInit *LHSs = dynamic_cast<const StringInit*>(LHS);
if (LHSs) {
if (LHSs->getValue().empty()) {
- return new IntInit(1);
+ return IntInit::get(1);
} else {
- return new IntInit(0);
+ return IntInit::get(0);
}
}
const Init *lhs = LHS->resolveReferences(R, RV);
if (LHS != lhs)
- return (new UnOpInit(getOpcode(), lhs, getType()))->Fold(&R, 0);
+ return (UnOpInit::get(getOpcode(), lhs, getType()))->Fold(&R, 0);
return Fold(&R, 0);
}
return Result + "(" + LHS->getAsString() + ")";
}
+const BinOpInit *BinOpInit::get(BinaryOp opc, const Init *lhs,
+ const Init *rhs, RecTy *Type) {
+ return new BinOpInit(opc, lhs, rhs, Type);
+}
+
const Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
switch (getOpcode()) {
default: assert(0 && "Unknown binop");
Args.push_back(RHSs->getArg(i));
ArgNames.push_back(RHSs->getArgName(i));
}
- return new DagInit(LHSs->getOperator(), "", Args, ArgNames);
+ return DagInit::get(LHSs->getOperator(), "", Args, ArgNames);
}
break;
}
const StringInit *LHSs = dynamic_cast<const StringInit*>(LHS);
const StringInit *RHSs = dynamic_cast<const StringInit*>(RHS);
if (LHSs && RHSs)
- return new StringInit(LHSs->getValue() + RHSs->getValue());
+ return StringInit::get(LHSs->getValue() + RHSs->getValue());
break;
}
case EQ: {
dynamic_cast<const IntInit*>(RHS->convertInitializerTo(IntRecTy::get()));
if (L && R)
- return new IntInit(L->getValue() == R->getValue());
+ return IntInit::get(L->getValue() == R->getValue());
const StringInit *LHSs = dynamic_cast<const StringInit*>(LHS);
const StringInit *RHSs = dynamic_cast<const StringInit*>(RHS);
// Make sure we've resolved
if (LHSs && RHSs)
- return new IntInit(LHSs->getValue() == RHSs->getValue());
+ return IntInit::get(LHSs->getValue() == RHSs->getValue());
break;
}
case SRA: Result = LHSv >> RHSv; break;
case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
}
- return new IntInit(Result);
+ return IntInit::get(Result);
}
break;
}
const Init *rhs = RHS->resolveReferences(R, RV);
if (LHS != lhs || RHS != rhs)
- return (new BinOpInit(getOpcode(), lhs, rhs, getType()))->Fold(&R, 0);
+ return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))->Fold(&R, 0);
return Fold(&R, 0);
}
return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
}
+const TernOpInit *TernOpInit::get(TernaryOp opc, const Init *lhs,
+ const Init *mhs, const Init *rhs,
+ RecTy *Type) {
+ return new TernOpInit(opc, lhs, mhs, rhs, Type);
+}
+
static const Init *ForeachHelper(const Init *LHS, const Init *MHS,
const Init *RHS, RecTy *Type,
Record *CurRec, MultiClass *CurMultiClass);
// Now run the operator and use its result as the new leaf
const OpInit *NewOp = RHSo->clone(NewOperands);
const Init *NewVal = NewOp->Fold(CurRec, CurMultiClass);
- if (NewVal != NewOp) {
- delete NewOp;
+ if (NewVal != NewOp)
return NewVal;
- }
+
return 0;
}
args.push_back(std::make_pair(Arg, ArgName));
}
- return new DagInit(Val, "", args);
+ return DagInit::get(Val, "", args);
}
if (MHSl) {
std::vector<const Init *> NewOperands;
// Now run the operator and use its result as the new list item
const OpInit *NewOp = RHSo->clone(NewOperands);
const Init *NewItem = NewOp->Fold(CurRec, CurMultiClass);
- if (NewItem != NewOp) {
+ if (NewItem != NewOp)
*li = NewItem;
- delete NewOp;
- }
}
- return new ListInit(NewList, MHSl->getType());
+ return ListInit::get(NewList, MHSl->getType());
}
}
return 0;
if (LHSv->getAsString() == RHSv->getAsString()) {
Val = MHSv->getName();
}
- return new VarInit(Val, getType());
+ return VarInit::get(Val, getType());
}
if (RHSs) {
std::string Val = RHSs->getValue();
idx = found + MHSs->getValue().size();
} while (found != std::string::npos);
- return new StringInit(Val);
+ return StringInit::get(Val);
}
}
break;
// Short-circuit
if (Value->getValue()) {
const Init *mhs = MHS->resolveReferences(R, RV);
- return (new TernOpInit(getOpcode(), lhs, mhs,
- RHS, getType()))->Fold(&R, 0);
+ return (TernOpInit::get(getOpcode(), lhs, mhs,
+ RHS, getType()))->Fold(&R, 0);
} else {
const Init *rhs = RHS->resolveReferences(R, RV);
- return (new TernOpInit(getOpcode(), lhs, MHS,
- rhs, getType()))->Fold(&R, 0);
+ return (TernOpInit::get(getOpcode(), lhs, MHS,
+ rhs, getType()))->Fold(&R, 0);
}
}
}
const Init *rhs = RHS->resolveReferences(R, RV);
if (LHS != lhs || MHS != mhs || RHS != rhs)
- return (new TernOpInit(getOpcode(), lhs, mhs, rhs, getType()))->Fold(&R, 0);
+ return (TernOpInit::get(getOpcode(), lhs, mhs, rhs,
+ getType()))->Fold(&R, 0);
return Fold(&R, 0);
}
if (Bits[i] >= NumBits)
return 0;
- NewBits[i] = new VarBitInit(this, Bits[i]);
+ NewBits[i] = VarBitInit::get(this, Bits[i]);
}
- return new BitsInit(ArrayRef<const Init *>(NewBits));
+ return BitsInit::get(NewBits);
}
const Init *
if (T == 0) return 0; // Cannot subscript a non-list variable.
if (Elements.size() == 1)
- return new VarListElementInit(this, Elements[0]);
+ return VarListElementInit::get(this, Elements[0]);
std::vector<const Init*> ListInits;
ListInits.reserve(Elements.size());
for (unsigned i = 0, e = Elements.size(); i != e; ++i)
- ListInits.push_back(new VarListElementInit(this, Elements[i]));
- return new ListInit(ListInits, T);
+ ListInits.push_back(VarListElementInit::get(this, Elements[i]));
+ return ListInit::get(ListInits, T);
}
+const VarInit *VarInit::get(const std::string &VN, RecTy *T) {
+ return new VarInit(VN, T);
+}
+
const Init *VarInit::resolveBitReference(Record &R, const RecordVal *IRV,
unsigned Bit) const {
if (R.isTemplateArg(getName())) return 0;
if (!LI) {
const VarInit *VI = dynamic_cast<const VarInit*>(RV->getValue());
assert(VI && "Invalid list element!");
- return new VarListElementInit(VI, Elt);
+ return VarListElementInit::get(VI, Elt);
}
if (Elt >= LI->getSize())
return this;
}
+const VarBitInit *VarBitInit::get(const TypedInit *T, unsigned B) {
+ return new VarBitInit(T, B);
+}
+
std::string VarBitInit::getAsString() const {
return TI->getAsString() + "{" + utostr(Bit) + "}";
}
return this;
}
+const VarListElementInit *VarListElementInit::get(const TypedInit *T,
+ unsigned E) {
+ return new VarListElementInit(T, E);
+}
+
std::string VarListElementInit::getAsString() const {
return TI->getAsString() + "[" + utostr(Element) + "]";
}
return 0;
}
-DefInit *DefInit::get(Record *R) {
+const DefInit *DefInit::get(Record *R) {
return R->getDefInit();
}
return Def->getName();
}
+const FieldInit *FieldInit::get(const Init *R, const std::string &FN) {
+ return new FieldInit(R, FN);
+}
+
const Init *FieldInit::resolveBitReference(Record &R, const RecordVal *RV,
unsigned Bit) const {
if (const Init *BitsVal = Rec->getFieldInit(R, RV, FieldName))
}
if (NewRec != Rec) {
- return new FieldInit(NewRec, FieldName);
+ return FieldInit::get(NewRec, FieldName);
}
return this;
}
+const DagInit *
+DagInit::get(const Init *V, const std::string &VN,
+ const std::vector<std::pair<const Init*, std::string> > &args) {
+ typedef std::pair<const Init*, std::string> PairType;
+
+ std::vector<const Init *> Args;
+ std::vector<std::string> Names;
+
+ for (std::vector<PairType>::const_iterator i = args.begin(),
+ iend = args.end();
+ i != iend;
+ ++i) {
+ Args.push_back(i->first);
+ Names.push_back(i->second);
+ }
+
+ return DagInit::get(V, VN, Args, Names);
+}
+
+const DagInit *
+DagInit::get(const Init *V, const std::string &VN,
+ const std::vector<const Init*> &args,
+ const std::vector<std::string> &argNames) {
+ return new DagInit(V, VN, args, argNames);
+}
+
const Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) const {
std::vector<const Init*> NewArgs;
for (unsigned i = 0, e = Args.size(); i != e; ++i)
const Init *Op = Val->resolveReferences(R, RV);
if (Args != NewArgs || Op != Val)
- return new DagInit(Op, ValName, NewArgs, ArgNames);
+ return DagInit::get(Op, ValName, NewArgs, ArgNames);
return this;
}
RecordVal::RecordVal(const std::string &N, RecTy *T, unsigned P)
: Name(N), Ty(T), Prefix(P) {
- Value = Ty->convertValue(new UnsetInit());
+ Value = Ty->convertValue(UnsetInit::get());
assert(Value && "Cannot create unset value for current type!");
}
#define RECORD_H
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/Allocator.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/raw_ostream.h"
//===----------------------------------------------------------------------===//
class Init {
+ Init(const Init &); // Do not define.
+ Init &operator=(const Init &); // Do not define.
+
+protected:
+ Init(void) {}
+
public:
virtual ~Init() {}
///
class TypedInit : public Init {
RecTy *Ty;
-public:
+
+ TypedInit(const TypedInit &Other); // Do not define.
+ TypedInit &operator=(const TypedInit &Other); // Do not define.
+
+protected:
explicit TypedInit(RecTy *T) : Ty(T) {}
+public:
RecTy *getType() const { return Ty; }
virtual const Init *
/// UnsetInit - ? - Represents an uninitialized value
///
class UnsetInit : public Init {
+ UnsetInit() : Init() {}
+ UnsetInit(const UnsetInit &); // Do not define.
+ UnsetInit &operator=(const UnsetInit &Other); // Do not define.
+
public:
+ static const UnsetInit *get();
+
virtual const Init *convertInitializerTo(RecTy *Ty) const {
return Ty->convertValue(this);
}
///
class BitInit : public Init {
bool Value;
-public:
+
explicit BitInit(bool V) : Value(V) {}
+ BitInit(const BitInit &Other); // Do not define.
+ BitInit &operator=(BitInit &Other); // Do not define.
+
+public:
+ static const BitInit *get(bool V);
bool getValue() const { return Value; }
///
class BitsInit : public Init {
std::vector<const Init*> Bits;
-public:
- explicit BitsInit(unsigned Size) : Bits(Size) {}
+
+ BitsInit(unsigned Size) : Bits(Size) {}
+
BitsInit(ArrayRef<const Init *> Range) : Bits(Range.begin(), Range.end()) {}
+ BitsInit(const BitsInit &Other); // Do not define.
+ BitsInit &operator=(const BitsInit &Other); // Do not define.
+
+public:
+ static const BitsInit *get(ArrayRef<const Init *> Range);
+
unsigned getNumBits() const { return Bits.size(); }
const Init *getBit(unsigned Bit) const {
///
class IntInit : public TypedInit {
int64_t Value;
-public:
+
explicit IntInit(int64_t V) : TypedInit(IntRecTy::get()), Value(V) {}
+ IntInit(const IntInit &Other); // Do not define.
+ IntInit &operator=(const IntInit &Other); // Do note define.
+
+public:
+ static const IntInit *get(int64_t V);
+
int64_t getValue() const { return Value; }
virtual const Init *convertInitializerTo(RecTy *Ty) const {
///
class StringInit : public TypedInit {
std::string Value;
-public:
+
explicit StringInit(const std::string &V)
: TypedInit(StringRecTy::get()), Value(V) {}
+ StringInit(const StringInit &Other); // Do not define.
+ StringInit &operator=(const StringInit &Other); // Do not define.
+
+public:
+ static const StringInit *get(const std::string &V);
+
const std::string &getValue() const { return Value; }
virtual const Init *convertInitializerTo(RecTy *Ty) const {
///
class CodeInit : public Init {
std::string Value;
-public:
+
explicit CodeInit(const std::string &V) : Value(V) {}
+ CodeInit(const CodeInit &Other); // Do not define.
+ CodeInit &operator=(const CodeInit &Other); // Do not define.
+
+public:
+ static const CodeInit *get(const std::string &V);
+
const std::string &getValue() const { return Value; }
virtual const Init *convertInitializerTo(RecTy *Ty) const {
explicit ListInit(ArrayRef<const Init *> Range, RecTy *EltTy)
: TypedInit(ListRecTy::get(EltTy)), Values(Range.begin(), Range.end()) {}
+ ListInit(const ListInit &Other); // Do not define.
+ ListInit &operator=(const ListInit &Other); // Do not define.
+
+public:
+ static const ListInit *get(ArrayRef<const Init *> Range, RecTy *EltTy);
+
unsigned getSize() const { return Values.size(); }
const Init *getElement(unsigned i) const {
assert(i < Values.size() && "List element index out of range!");
/// OpInit - Base class for operators
///
class OpInit : public TypedInit {
-public:
- OpInit(RecTy *Type) : TypedInit(Type) {}
+ OpInit(const OpInit &Other); // Do not define.
+ OpInit &operator=(OpInit &Other); // Do not define.
+protected:
+ explicit OpInit(RecTy *Type) : TypedInit(Type) {}
+
+public:
// Clone - Clone this operator, replacing arguments with the new list
virtual const OpInit *clone(std::vector<const Init *> &Operands) const = 0;
private:
UnaryOp Opc;
const Init *LHS;
+
+ UnOpInit(UnaryOp opc, const Init *lhs, RecTy *Type)
+ : OpInit(Type), Opc(opc), LHS(lhs) {}
+
+ UnOpInit(const UnOpInit &Other); // Do not define.
+ UnOpInit &operator=(const UnOpInit &Other); // Do not define.
+
public:
- UnOpInit(UnaryOp opc, const Init *lhs, RecTy *Type) :
- OpInit(Type), Opc(opc), LHS(lhs) {
- }
+ static const UnOpInit *get(UnaryOp opc, const Init *lhs, RecTy *Type);
// Clone - Clone this operator, replacing arguments with the new list
virtual const OpInit *clone(std::vector<const Init *> &Operands) const {
assert(Operands.size() == 1 &&
"Wrong number of operands for unary operation");
- return new UnOpInit(getOpcode(), *Operands.begin(), getType());
+ return UnOpInit::get(getOpcode(), *Operands.begin(), getType());
}
int getNumOperands() const { return 1; }
private:
BinaryOp Opc;
const Init *LHS, *RHS;
-public:
+
BinOpInit(BinaryOp opc, const Init *lhs, const Init *rhs, RecTy *Type) :
- OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) {
- }
+ OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) {}
+
+ BinOpInit(const BinOpInit &Other); // Do not define.
+ BinOpInit &operator=(const BinOpInit &Other); // Do not define.
+
+public:
+ static const BinOpInit *get(BinaryOp opc, const Init *lhs, const Init *rhs,
+ RecTy *Type);
// Clone - Clone this operator, replacing arguments with the new list
virtual const OpInit *clone(std::vector<const Init *> &Operands) const {
assert(Operands.size() == 2 &&
"Wrong number of operands for binary operation");
- return new BinOpInit(getOpcode(), Operands[0], Operands[1], getType());
+ return BinOpInit::get(getOpcode(), Operands[0], Operands[1], getType());
}
int getNumOperands() const { return 2; }
private:
TernaryOp Opc;
const Init *LHS, *MHS, *RHS;
-public:
+
TernOpInit(TernaryOp opc, const Init *lhs, const Init *mhs, const Init *rhs,
RecTy *Type) :
- OpInit(Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {
- }
+ OpInit(Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
+
+ TernOpInit(const TernOpInit &Other); // Do not define.
+ TernOpInit &operator=(const TernOpInit &Other); // Do not define.
+
+public:
+ static const TernOpInit *get(TernaryOp opc, const Init *lhs,
+ const Init *mhs, const Init *rhs,
+ RecTy *Type);
// Clone - Clone this operator, replacing arguments with the new list
virtual const OpInit *clone(std::vector<const Init *> &Operands) const {
assert(Operands.size() == 3 &&
"Wrong number of operands for ternary operation");
- return new TernOpInit(getOpcode(), Operands[0], Operands[1], Operands[2],
- getType());
+ return TernOpInit::get(getOpcode(), Operands[0], Operands[1], Operands[2],
+ getType());
}
int getNumOperands() const { return 3; }
///
class VarInit : public TypedInit {
std::string VarName;
-public:
+
explicit VarInit(const std::string &VN, RecTy *T)
- : TypedInit(T), VarName(VN) {}
+ : TypedInit(T), VarName(VN) {}
+
+ VarInit(const VarInit &Other); // Do not define.
+ VarInit &operator=(const VarInit &Other); // Do not define.
+
+public:
+ static const VarInit *get(const std::string &VN, RecTy *T);
+ static const VarInit *get(const Init *VN, RecTy *T);
virtual const Init *convertInitializerTo(RecTy *Ty) const {
return Ty->convertValue(this);
class VarBitInit : public Init {
const TypedInit *TI;
unsigned Bit;
-public:
+
VarBitInit(const TypedInit *T, unsigned B) : TI(T), Bit(B) {
assert(T->getType() && dynamic_cast<BitsRecTy*>(T->getType()) &&
((BitsRecTy*)T->getType())->getNumBits() > B &&
"Illegal VarBitInit expression!");
}
+ VarBitInit(const VarBitInit &Other); // Do not define.
+ VarBitInit &operator=(const VarBitInit &Other); // Do not define.
+
+public:
+ static const VarBitInit *get(const TypedInit *T, unsigned B);
+
virtual const Init *convertInitializerTo(RecTy *Ty) const {
return Ty->convertValue(this);
}
class VarListElementInit : public TypedInit {
const TypedInit *TI;
unsigned Element;
-public:
+
VarListElementInit(const TypedInit *T, unsigned E)
- : TypedInit(dynamic_cast<ListRecTy*>(T->getType())->getElementType()),
- TI(T), Element(E) {
+ : TypedInit(dynamic_cast<ListRecTy*>(T->getType())->getElementType()),
+ TI(T), Element(E) {
assert(T->getType() && dynamic_cast<ListRecTy*>(T->getType()) &&
"Illegal VarBitInit expression!");
}
+ VarListElementInit(const VarListElementInit &Other); // Do not define.
+ VarListElementInit &operator=(const VarListElementInit &Other); // Do
+ // not
+ // define.
+
+public:
+ static const VarListElementInit *get(const TypedInit *T, unsigned E);
+
virtual const Init *convertInitializerTo(RecTy *Ty) const {
return Ty->convertValue(this);
}
///
class DefInit : public TypedInit {
Record *Def;
+
DefInit(Record *D, RecordRecTy *T) : TypedInit(T), Def(D) {}
friend class Record;
+
+ DefInit(const DefInit &Other); // Do not define.
+ DefInit &operator=(const DefInit &Other); // Do not define.
+
public:
- static DefInit *get(Record*);
+ static const DefInit *get(Record*);
virtual const Init *convertInitializerTo(RecTy *Ty) const {
return Ty->convertValue(this);
class FieldInit : public TypedInit {
const Init *Rec; // Record we are referring to
std::string FieldName; // Field we are accessing
-public:
+
FieldInit(const Init *R, const std::string &FN)
- : TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) {
+ : TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) {
assert(getType() && "FieldInit with non-record type!");
}
+ FieldInit(const FieldInit &Other); // Do not define.
+ FieldInit &operator=(const FieldInit &Other); // Do not define.
+
+public:
+ static const FieldInit *get(const Init *R, const std::string &FN);
+ static const FieldInit *get(const Init *R, const Init *FN);
+
virtual const Init *convertInitializerTo(RecTy *Ty) const {
return Ty->convertValue(this);
}
std::string ValName;
std::vector<const Init*> Args;
std::vector<std::string> ArgNames;
-public:
- DagInit(const Init *V, std::string VN,
+
+ DagInit(const Init *V, const std::string &VN,
const std::vector<std::pair<const Init*, std::string> > &args)
: TypedInit(DagRecTy::get()), Val(V), ValName(VN) {
Args.reserve(args.size());
ArgNames.push_back(args[i].second);
}
}
- DagInit(const Init *V, std::string VN, const std::vector<const Init*> &args,
+ DagInit(const Init *V, const std::string &VN,
+ const std::vector<const Init*> &args,
const std::vector<std::string> &argNames)
: TypedInit(DagRecTy::get()), Val(V), ValName(VN), Args(args),
ArgNames(argNames) { }
+ DagInit(const DagInit &Other); // Do not define.
+ DagInit &operator=(const DagInit &Other); // Do not define.
+
+public:
+ static const DagInit *get(const Init *V, const std::string &VN,
+ const std::vector<
+ std::pair<const Init*, std::string> > &args);
+
+ static const DagInit *get(const Init *V, const std::string &VN,
+ const std::vector<const Init*> &args,
+ const std::vector<std::string> &argNames);
+
virtual const Init *convertInitializerTo(RecTy *Ty) const {
return Ty->convertValue(this);
}
if (NewBits[i] == 0)
NewBits[i] = CurVal->getBit(i);
- V = new BitsInit(ArrayRef<const Init *>(NewBits));
+ V = BitsInit::get(NewBits);
}
if (RV->setValue(V))
const std::string &Name, SMLoc NameLoc) {
if (CurRec) {
if (const RecordVal *RV = CurRec->getValue(Name))
- return new VarInit(Name, RV->getType());
+ return VarInit::get(Name, RV->getType());
std::string TemplateArgName = CurRec->getName()+":"+Name;
if (CurRec->isTemplateArg(TemplateArgName)) {
const RecordVal *RV = CurRec->getValue(TemplateArgName);
assert(RV && "Template arg doesn't exist??");
- return new VarInit(TemplateArgName, RV->getType());
+ return VarInit::get(TemplateArgName, RV->getType());
}
}
if (CurMultiClass->Rec.isTemplateArg(MCName)) {
const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
assert(RV && "Template arg doesn't exist??");
- return new VarInit(MCName, RV->getType());
+ return VarInit::get(MCName, RV->getType());
}
}
return 0;
}
Lex.Lex(); // eat the ')'
- return (new UnOpInit(Code, LHS, Type))->Fold(CurRec, CurMultiClass);
+ return (UnOpInit::get(Code, LHS, Type))->Fold(CurRec, CurMultiClass);
}
case tgtok::XConcat:
if (Code == BinOpInit::STRCONCAT) {
while (InitList.size() > 2) {
const Init *RHS = InitList.pop_back_val();
- RHS = (new BinOpInit(Code, InitList.back(), RHS, Type))
- ->Fold(CurRec, CurMultiClass);
+ RHS = (BinOpInit::get(Code, InitList.back(), RHS, Type))
+ ->Fold(CurRec, CurMultiClass);
InitList.back() = RHS;
}
}
if (InitList.size() == 2)
- return (new BinOpInit(Code, InitList[0], InitList[1], Type))
+ return (BinOpInit::get(Code, InitList[0], InitList[1], Type))
->Fold(CurRec, CurMultiClass);
Error(OpLoc, "expected two operands to operator");
break;
}
}
- return (new TernOpInit(Code, LHS, MHS, RHS, Type))->Fold(CurRec,
+ return (TernOpInit::get(Code, LHS, MHS, RHS, Type))->Fold(CurRec,
CurMultiClass);
}
}
const Init *R = 0;
switch (Lex.getCode()) {
default: TokError("Unknown token when parsing a value"); break;
- case tgtok::IntVal: R = new IntInit(Lex.getCurIntVal()); Lex.Lex(); break;
+ case tgtok::IntVal: R = IntInit::get(Lex.getCurIntVal()); Lex.Lex(); break;
case tgtok::StrVal: {
std::string Val = Lex.getCurStrVal();
Lex.Lex();
Lex.Lex();
}
- R = new StringInit(Val);
+ R = StringInit::get(Val);
break;
}
case tgtok::CodeFragment:
- R = new CodeInit(Lex.getCurStrVal());
+ R = CodeInit::get(Lex.getCurStrVal());
Lex.Lex();
break;
case tgtok::question:
- R = new UnsetInit();
+ R = UnsetInit::get();
Lex.Lex();
break;
case tgtok::Id: {
}
NewBits[Vals.size()-i-1] = Bit;
}
- return new BitsInit(ArrayRef<const Init *>(NewBits));
+ return BitsInit::get(NewBits);
}
case tgtok::l_square: { // Value ::= '[' ValueList ']'
Lex.Lex(); // eat the '['
DeducedEltTy = EltTy;
}
- return new ListInit(Vals, DeducedEltTy);
+ return ListInit::get(Vals, DeducedEltTy);
}
case tgtok::l_paren: { // Value ::= '(' IDValue DagArgList ')'
Lex.Lex(); // eat the '('
}
Lex.Lex(); // eat the ')'
- return new DagInit(Operator, OperatorName, DagArgs);
+ return DagInit::get(Operator, OperatorName, DagArgs);
}
case tgtok::XHead:
Result->getAsString() + "'");
return 0;
}
- Result = new FieldInit(Result, Lex.getCurStrVal());
+ Result = FieldInit::get(Result, Lex.getCurStrVal());
Lex.Lex(); // eat field name
break;
}