return ListTy.get();
}
-bool RecTy::baseClassOf(const RecTy *RHS) const{
+bool RecTy::baseClassOf(const RecTy *RHS) const {
assert (RHS && "NULL pointer");
return Kind == RHS->getRecTyKind();
}
Init *IntRecTy::convertValue(BitsInit *BI) {
int64_t Result = 0;
for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
- if (BitInit *Bit = dyn_cast<BitInit>(BI->getBit(i))) {
+ if (BitInit *Bit = dyn_cast<BitInit>(BI->getBit(i)))
Result |= Bit->getValue() << i;
- } else {
+ else
return nullptr;
- }
return IntInit::get(Result);
}
Init *TemplateArgName = QualifyName(*CurRec, CurMultiClass, Name,
":");
-
+
if (CurRec->isTemplateArg(TemplateArgName)) {
const RecordVal *RV = CurRec->getValue(TemplateArgName);
assert(RV && "Template arg doesn't exist??");
}
if (CurMultiClass) {
- Init *MCName = QualifyName(CurMultiClass->Rec, CurMultiClass, Name, "::");
+ Init *MCName = QualifyName(CurMultiClass->Rec, CurMultiClass, Name,
+ "::");
if (CurMultiClass->Rec.isTemplateArg(MCName)) {
const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
}
case EMPTY: {
if (ListInit *LHSl = dyn_cast<ListInit>(LHS)) {
- if (LHSl->getSize() == 0) {
+ if (LHSl->getSize() == 0)
return IntInit::get(1);
- } else {
- return IntInit::get(0);
- }
+ return IntInit::get(0);
}
if (StringInit *LHSs = dyn_cast<StringInit>(LHS)) {
- if (LHSs->getValue().empty()) {
+ if (LHSs->getValue().empty())
return IntInit::get(1);
- } else {
- return IntInit::get(0);
- }
+ return IntInit::get(0);
}
break;
return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
}
-TernOpInit *TernOpInit::get(TernaryOp opc, Init *lhs,
- Init *mhs, Init *rhs,
- RecTy *Type) {
+TernOpInit *TernOpInit::get(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
+ RecTy *Type) {
typedef std::pair<
std::pair<
std::pair<std::pair<unsigned, RecTy *>, Init *>,
OpInit *RHSo = dyn_cast<OpInit>(RHS);
- if (!RHSo) {
+ if (!RHSo)
PrintFatalError(CurRec->getLoc(), "!foreach requires an operator\n");
- }
TypedInit *LHSt = dyn_cast<TypedInit>(LHS);
Init *Val = MHSd->getOperator();
Init *Result = EvaluateOperation(RHSo, LHS, Val,
Type, CurRec, CurMultiClass);
- if (Result) {
+ if (Result)
Val = Result;
- }
std::vector<std::pair<Init *, std::string> > args;
for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) {
// Process args
Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type,
CurRec, CurMultiClass);
- if (Result) {
+ if (Result)
Arg = Result;
- }
// TODO: Process arg names
args.push_back(std::make_pair(Arg, ArgName));
NewOperands.clear();
for(int i = 0; i < RHSo->getNumOperands(); ++i) {
// First, replace the foreach variable with the list item
- if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
+ if (LHS->getAsString() == RHSo->getOperand(i)->getAsString())
NewOperands.push_back(Item);
- } else {
+ else
NewOperands.push_back(RHSo->getOperand(i));
- }
}
// Now run the operator and use its result as the new list item
(LHSs && MHSs && RHSs)) {
if (RHSd) {
Record *Val = RHSd->getDef();
- if (LHSd->getAsString() == RHSd->getAsString()) {
+ if (LHSd->getAsString() == RHSd->getAsString())
Val = MHSd->getDef();
- }
return DefInit::get(Val);
}
if (RHSv) {
std::string Val = RHSv->getName();
- if (LHSv->getAsString() == RHSv->getAsString()) {
+ if (LHSv->getAsString() == RHSv->getAsString())
Val = MHSv->getName();
- }
return VarInit::get(Val, getType());
}
if (RHSs) {
std::string::size_type idx = 0;
do {
found = Val.find(LHSs->getValue(), idx);
- if (found != std::string::npos) {
+ if (found != std::string::npos)
Val.replace(found, LHSs->getValue().size(), MHSs->getValue());
- }
idx = found + MHSs->getValue().size();
} while (found != std::string::npos);
case FOREACH: {
Init *Result = ForeachHelper(LHS, MHS, RHS, getType(),
CurRec, CurMultiClass);
- if (Result) {
+ if (Result)
return Result;
- }
break;
}
if (Init *I = LHS->convertInitializerTo(IntRecTy::get()))
LHSi = dyn_cast<IntInit>(I);
if (LHSi) {
- if (LHSi->getValue()) {
+ if (LHSi->getValue())
return MHS;
- } else {
- return RHS;
- }
+ return RHS;
}
break;
}
Init *mhs = MHS->resolveReferences(R, RV);
return (TernOpInit::get(getOpcode(), lhs, mhs,
RHS, getType()))->Fold(&R, nullptr);
- } else {
- Init *rhs = RHS->resolveReferences(R, RV);
- return (TernOpInit::get(getOpcode(), lhs, MHS,
- rhs, getType()))->Fold(&R, nullptr);
}
+ Init *rhs = RHS->resolveReferences(R, RV);
+ return (TernOpInit::get(getOpcode(), lhs, MHS,
+ rhs, getType()))->Fold(&R, nullptr);
}
}
RecordVal *RV = R.getValue(getNameInit());
assert(RV && "Reference to a non-existent variable?");
ListInit *LI = dyn_cast<ListInit>(RV->getValue());
- if (!LI) {
- TypedInit *VI = cast<TypedInit>(RV->getValue());
- return VarListElementInit::get(VI, Elt);
- }
+ if (!LI)
+ return VarListElementInit::get(cast<TypedInit>(RV->getValue()), Elt);
if (Elt >= LI->getSize())
return nullptr; // Out of range reference.
assert(TheInit != this && "Infinite loop detected!");
if (Init *I = TheInit->getFieldInit(R, RV, FieldName))
return I;
- else
- return nullptr;
+ return nullptr;
}
return nullptr;
}
}
std::string VarBitInit::getAsString() const {
- return TI->getAsString() + "{" + utostr(Bit) + "}";
+ return TI->getAsString() + "{" + utostr(Bit) + "}";
}
Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) const {
Init *VarListElementInit:: resolveListElementReference(Record &R,
const RecordVal *RV,
unsigned Elt) const {
- Init *Result = TI->resolveListElementReference(R, RV, Element);
-
- if (Result) {
+ if (Init *Result = TI->resolveListElementReference(R, RV, Element)) {
if (TypedInit *TInit = dyn_cast<TypedInit>(Result)) {
Init *Result2 = TInit->resolveListElementReference(R, RV, Elt);
if (Result2) return Result2;
}
return Result;
}
-
+
return nullptr;
}
Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) const {
Init *NewRec = RV ? Rec->resolveReferences(R, RV) : Rec;
- Init *BitsVal = NewRec->getFieldInit(R, RV, FieldName);
- if (BitsVal) {
+ if (Init *BitsVal = NewRec->getFieldInit(R, RV, FieldName)) {
Init *BVR = BitsVal->resolveReferences(R, RV);
return BVR->isComplete() ? BVR : const_cast<FieldInit *>(this);
}
- if (NewRec != Rec) {
+ if (NewRec != Rec)
return FieldInit::get(NewRec, FieldName);
- }
return const_cast<FieldInit *>(this);
}
ListInit *List = getValueAsListInit(FieldName);
std::vector<Record*> Defs;
for (unsigned i = 0; i < List->getSize(); i++) {
- if (DefInit *DI = dyn_cast<DefInit>(List->getElement(i))) {
+ if (DefInit *DI = dyn_cast<DefInit>(List->getElement(i)))
Defs.push_back(DI->getDef());
- } else {
+ else
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
FieldName + "' list is not entirely DefInit!");
- }
}
return Defs;
}
ListInit *List = getValueAsListInit(FieldName);
std::vector<int64_t> Ints;
for (unsigned i = 0; i < List->getSize(); i++) {
- if (IntInit *II = dyn_cast<IntInit>(List->getElement(i))) {
+ if (IntInit *II = dyn_cast<IntInit>(List->getElement(i)))
Ints.push_back(II->getValue());
- } else {
+ else
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
FieldName + "' does not have a list of ints initializer!");
- }
}
return Ints;
}
ListInit *List = getValueAsListInit(FieldName);
std::vector<std::string> Strings;
for (unsigned i = 0; i < List->getSize(); i++) {
- if (StringInit *II = dyn_cast<StringInit>(List->getElement(i))) {
+ if (StringInit *II = dyn_cast<StringInit>(List->getElement(i)))
Strings.push_back(II->getValue());
- } else {
+ else
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
FieldName + "' does not have a list of strings initializer!");
- }
}
return Strings;
}
Rec.dump();
errs() << "Defs:\n";
- for (const auto &Proto : DefPrototypes) {
+ for (const auto &Proto : DefPrototypes)
Proto->dump();
- }
}
MC->dump();
errs() << "Template args:\n";
- for (Init *TA : TemplateArgs) {
+ for (Init *TA : TemplateArgs)
TA->dump();
- }
}
} // end namespace llvm
// Convert the incoming value to a bits type of the appropriate size...
Init *BI = V->convertInitializerTo(BitsRecTy::get(BitList.size()));
- if (!BI) {
+ if (!BI)
return Error(Loc, "Initializer is not compatible with bit range");
- }
// We should have a BitsInit type now.
BitsInit *BInit = cast<BitsInit>(BI);
if (RV->setValue(V)) {
std::string InitType = "";
- if (BitsInit *BI = dyn_cast<BitsInit>(V)) {
+ if (BitsInit *BI = dyn_cast<BitsInit>(V))
InitType = (Twine("' of type bit initializer with length ") +
Twine(BI->getNumBits())).str();
- }
return Error(Loc, "Value '" + ValName->getAsUnquotedString() +
"' of type '" + RV->getType()->getAsString() +
"' is incompatible with initializer '" + V->getAsString() +
Lex.Lex();
// Add to the range.
- if (Start < End) {
+ if (Start < End)
for (; Start <= End; ++Start)
Ranges.push_back(Start);
- } else {
+ else
for (; Start >= End; --Start)
Ranges.push_back(Start);
- }
return false;
}
Error(NameLoc, "Variable not defined: '" + Name + "'");
return nullptr;
}
-
+
return StringInit::get(Name);
}
TokError("untyped list element in unary operator");
return nullptr;
}
- if (Code == UnOpInit::HEAD) {
- Type = Itemt->getType();
- } else {
- Type = ListRecTy::get(Itemt->getType());
- }
+ Type = (Code == UnOpInit::HEAD) ? Itemt->getType()
+ : ListRecTy::get(Itemt->getType());
} else {
assert(LHSt && "expected list type argument in unary operator");
ListRecTy *LType = dyn_cast<ListRecTy>(LHSt->getType());
TokError("expected list type argument in unary operator");
return nullptr;
}
- if (Code == UnOpInit::HEAD) {
- Type = LType->getElementType();
- } else {
- Type = LType;
- }
+ Type = (Code == UnOpInit::HEAD) ? LType->getElementType() : LType;
}
}
}
Error(PasteLoc, "LHS of paste is not typed!");
return nullptr;
}
-
+
if (LHS->getType() != StringRecTy::get()) {
LHS = UnOpInit::get(UnOpInit::CAST, LHS, StringRecTy::get());
}
// These are all of the tokens that can begin an object body.
// Some of these can also begin values but we disallow those cases
// because they are unlikely to be useful.
-
+
// Trailing paste, concat with an empty string.
RHS = StringInit::get("");
break;
if (RHS->getType() != StringRecTy::get()) {
RHS = UnOpInit::get(UnOpInit::CAST, RHS, StringRecTy::get());
}
-
+
break;
}
Lex.Lex();
if (ParsingTemplateArgs) {
- if (CurRec) {
+ if (CurRec)
DeclName = QualifyName(*CurRec, CurMultiClass, DeclName, ":");
- } else {
+ else
assert(CurMultiClass);
- }
if (CurMultiClass)
DeclName = QualifyName(CurMultiClass->Rec, CurMultiClass, DeclName,
"::");
}
}
- if (ProcessForeachDefs(CurRec, DefLoc)) {
+ if (ProcessForeachDefs(CurRec, DefLoc))
return Error(DefLoc, "Could not process loops for def" +
CurRec->getNameInitAsString());
- }
return false;
}
// FOREACH Declaration IN Object
if (ParseObject(CurMultiClass))
return true;
- }
- else {
+ } else {
SMLoc BraceLoc = Lex.getLoc();
// Otherwise, this is a group foreach.
Lex.Lex(); // eat the '{'.
if (SetValue(CurRec, DefmPrefixLoc, TArgs[i], std::vector<unsigned>(),
TemplateVals[i]))
return true;
-
+
// Resolve it next.
CurRec->resolveReferencesTo(CurRec->getValue(TArgs[i]));
if (DeleteArgs)
// Now remove it.
CurRec->removeValue(TArgs[i]);
-
+
} else if (!CurRec->getValue(TArgs[i])->getValue()->isComplete()) {
return Error(SubClassLoc, "value not specified for template argument #" +
utostr(i) + " (" + TArgs[i]->getAsUnquotedString() +