If the type of 'a' does not match *type*, TableGen aborts with an error.
- For historical reasons, 'a' can also be the name of a variable or a
- template argument in some cases, but this use is unreliable and is
- discouraged.
-
Otherwise, perform a normal type cast e.g. between an int and a bit, or
between record types. This allows casting a record to a subclass, though if
the types do not match, constant folding will be inhibited. !cast<string>
// Fold - If possible, fold this to a simpler init. Return this if not
// possible to fold.
- virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const = 0;
+ virtual Init *Fold(Record *CurRec) const = 0;
Init *getBit(unsigned Bit) const override;
};
// Fold - If possible, fold this to a simpler init. Return this if not
// possible to fold.
- Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
+ Init *Fold(Record *CurRec) const override;
Init *resolveReferences(Resolver &R) const override;
// Fold - If possible, fold this to a simpler init. Return this if not
// possible to fold.
- Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
+ Init *Fold(Record *CurRec) const override;
Init *resolveReferences(Resolver &R) const override;
// Fold - If possible, fold this to a simpler init. Return this if not
// possible to fold.
- Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
+ Init *Fold(Record *CurRec) const override;
bool isComplete() const override {
return LHS->isComplete() && MHS->isComplete() && RHS->isComplete();
ProfileUnOpInit(ID, getOpcode(), getOperand(), getType());
}
-Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
+Init *UnOpInit::Fold(Record *CurRec) const {
switch (getOpcode()) {
case CAST:
if (isa<StringRecTy>(getType())) {
return StringInit::get(LHSi->getAsString());
} else if (isa<RecordRecTy>(getType())) {
if (StringInit *Name = dyn_cast<StringInit>(LHS)) {
- // From TGParser::ParseIDValue
- if (CurRec) {
- if (const RecordVal *RV = CurRec->getValue(Name)) {
- if (RV->getType() != getType())
- PrintFatalError("type mismatch in cast");
- return VarInit::get(Name, RV->getType());
- }
-
- Init *TemplateArgName = QualifyName(*CurRec, CurMultiClass, Name,
- ":");
-
- if (CurRec->isTemplateArg(TemplateArgName)) {
- const RecordVal *RV = CurRec->getValue(TemplateArgName);
- assert(RV && "Template arg doesn't exist??");
-
- if (RV->getType() != getType())
- PrintFatalError("type mismatch in cast");
-
- return VarInit::get(TemplateArgName, RV->getType());
- }
- }
-
- if (CurMultiClass) {
- Init *MCName = QualifyName(CurMultiClass->Rec, CurMultiClass, Name,
- "::");
-
- if (CurMultiClass->Rec.isTemplateArg(MCName)) {
- const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
- assert(RV && "Template arg doesn't exist??");
-
- if (RV->getType() != getType())
- PrintFatalError("type mismatch in cast");
-
- return VarInit::get(MCName, RV->getType());
- }
- }
assert(CurRec && "NULL pointer");
if (Record *D = (CurRec->getRecords()).getDef(Name->getValue()))
return DefInit::get(D);
PrintFatalError(CurRec->getLoc(),
- "Undefined reference:'" + Name->getValue() + "'\n");
+ Twine("Undefined reference to record: '") +
+ Name->getValue() + "'\n");
}
}
if (LHS != lhs)
return (UnOpInit::get(getOpcode(), lhs, getType()))
- ->Fold(R.getCurrentRecord(), nullptr);
- return Fold(R.getCurrentRecord(), nullptr);
+ ->Fold(R.getCurrentRecord());
+ return Fold(R.getCurrentRecord());
}
std::string UnOpInit::getAsString() const {
return StringInit::get(Concat);
}
-Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
+Init *BinOpInit::Fold(Record *CurRec) const {
switch (getOpcode()) {
case CONCAT: {
DagInit *LHSs = dyn_cast<DagInit>(LHS);
if (LHS != lhs || RHS != rhs)
return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))
- ->Fold(R.getCurrentRecord(), nullptr);
- return Fold(R.getCurrentRecord(), nullptr);
+ ->Fold(R.getCurrentRecord());
+ return Fold(R.getCurrentRecord());
}
std::string BinOpInit::getAsString() const {
return nullptr;
}
-Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
+Init *TernOpInit::Fold(Record *CurRec) const {
switch (getOpcode()) {
case SUBST: {
DefInit *LHSd = dyn_cast<DefInit>(LHS);
if (LHS != lhs || MHS != mhs || RHS != rhs)
return (TernOpInit::get(getOpcode(), lhs, mhs, rhs, getType()))
- ->Fold(R.getCurrentRecord(), nullptr);
- return Fold(R.getCurrentRecord(), nullptr);
+ ->Fold(R.getCurrentRecord());
+ return Fold(R.getCurrentRecord());
}
std::string TernOpInit::getAsString() const {
return nullptr;
return UnOpInit::get(UnOpInit::CAST, const_cast<TypedInit *>(this), Ty)
- ->Fold(nullptr, nullptr);
+ ->Fold(nullptr);
}
Init *TypedInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
}
if (BinOpInit *BinOp = dyn_cast<BinOpInit>(NewName))
- NewName = BinOp->Fold(&CurRec, CurMultiClass);
+ NewName = BinOp->Fold(&CurRec);
return NewName;
}
return nullptr;
}
Lex.Lex(); // eat the ')'
- return (UnOpInit::get(Code, LHS, Type))->Fold(CurRec, CurMultiClass);
+ return (UnOpInit::get(Code, LHS, Type))->Fold(CurRec);
}
case tgtok::XIsA: {
Code == BinOpInit::AND || Code == BinOpInit::OR) {
while (InitList.size() > 2) {
Init *RHS = InitList.pop_back_val();
- RHS = (BinOpInit::get(Code, InitList.back(), RHS, Type))
- ->Fold(CurRec, CurMultiClass);
+ RHS = (BinOpInit::get(Code, InitList.back(), RHS, Type))->Fold(CurRec);
InitList.back() = RHS;
}
}
if (InitList.size() == 2)
return (BinOpInit::get(Code, InitList[0], InitList[1], Type))
- ->Fold(CurRec, CurMultiClass);
+ ->Fold(CurRec);
Error(OpLoc, "expected two operands to operator");
return nullptr;
}
return (TernOpInit::get(TernOpInit::FOREACH, LHS, MHS, RHS, OutType))
- ->Fold(CurRec, CurMultiClass);
+ ->Fold(CurRec);
}
case tgtok::XDag:
break;
}
}
- return (TernOpInit::get(Code, LHS, MHS, RHS, Type))->Fold(CurRec,
- CurMultiClass);
+ return (TernOpInit::get(Code, LHS, MHS, RHS, Type))->Fold(CurRec);
}
case tgtok::XFoldl: {
break;
}
- Result = BinOpInit::get(BinOpInit::STRCONCAT, LHS, RHS,
- StringRecTy::get())->Fold(CurRec, CurMultiClass);
+ Result =
+ BinOpInit::get(BinOpInit::STRCONCAT, LHS, RHS, StringRecTy::get())
+ ->Fold(CurRec);
break;
}
}
if (DefNameString) {
// We have a fully expanded string so there are no operators to
// resolve. We should concatenate the given prefix and name.
- DefName =
- BinOpInit::get(BinOpInit::STRCONCAT,
- UnOpInit::get(UnOpInit::CAST, DefmPrefix,
- StringRecTy::get())->Fold(DefProto, &MC),
- DefName, StringRecTy::get())->Fold(DefProto, &MC);
+ DefName = BinOpInit::get(
+ BinOpInit::STRCONCAT,
+ UnOpInit::get(UnOpInit::CAST, DefmPrefix, StringRecTy::get())
+ ->Fold(DefProto),
+ DefName, StringRecTy::get())
+ ->Fold(DefProto);
}
// Make a trail of SMLocs from the multiclass instantiations.
multiclass M0<string s> {
// This should work fine.
def _m00 : B<!cast<A>(s)>;
- // CHECK: error: Undefined reference:'d1_r1_no_such_record'
+ // CHECK: error: Undefined reference to record: 'd1_r1_no_such_record'
def _m01: B<!cast<A>(s#"_no_such_record")>;
}