[TableGen] Formatting cleanup. Mostly removing trailing whitespace and unnecessary curly braces. NFC

llvm-svn: 236397
This commit is contained in:
Craig Topper 2015-05-04 01:35:39 +00:00
parent 026137628f
commit a9642b4ec8
2 changed files with 59 additions and 100 deletions

View File

@ -95,7 +95,7 @@ ListRecTy *RecTy::getListTy() {
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();
}
@ -229,11 +229,10 @@ Init *IntRecTy::convertValue(BitInit *BI) {
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);
}
@ -741,7 +740,7 @@ Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
Init *TemplateArgName = QualifyName(*CurRec, CurMultiClass, Name,
":");
if (CurRec->isTemplateArg(TemplateArgName)) {
const RecordVal *RV = CurRec->getValue(TemplateArgName);
assert(RV && "Template arg doesn't exist??");
@ -754,7 +753,8 @@ Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
}
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);
@ -799,18 +799,14 @@ Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
}
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;
@ -971,9 +967,8 @@ std::string BinOpInit::getAsString() const {
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 *>,
@ -1034,9 +1029,8 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
OpInit *RHSo = dyn_cast<OpInit>(RHS);
if (!RHSo) {
if (!RHSo)
PrintFatalError(CurRec->getLoc(), "!foreach requires an operator\n");
}
TypedInit *LHSt = dyn_cast<TypedInit>(LHS);
@ -1048,9 +1042,8 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
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) {
@ -1062,9 +1055,8 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
// 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));
@ -1080,11 +1072,10 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
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
@ -1119,16 +1110,14 @@ Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
(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) {
@ -1138,9 +1127,8 @@ Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
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);
@ -1153,9 +1141,8 @@ Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
case FOREACH: {
Init *Result = ForeachHelper(LHS, MHS, RHS, getType(),
CurRec, CurMultiClass);
if (Result) {
if (Result)
return Result;
}
break;
}
@ -1164,11 +1151,9 @@ Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
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;
}
@ -1191,11 +1176,10 @@ Init *TernOpInit::resolveReferences(Record &R,
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);
}
}
@ -1295,10 +1279,8 @@ Init *VarInit::resolveListElementReference(Record &R,
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.
@ -1329,8 +1311,7 @@ Init *VarInit::getFieldInit(Record &R, const RecordVal *RV,
assert(TheInit != this && "Infinite loop detected!");
if (Init *I = TheInit->getFieldInit(R, RV, FieldName))
return I;
else
return nullptr;
return nullptr;
}
return nullptr;
}
@ -1359,7 +1340,7 @@ VarBitInit *VarBitInit::get(TypedInit *T, unsigned B) {
}
std::string VarBitInit::getAsString() const {
return TI->getAsString() + "{" + utostr(Bit) + "}";
return TI->getAsString() + "{" + utostr(Bit) + "}";
}
Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) const {
@ -1403,9 +1384,7 @@ Init *VarListElementInit::getBit(unsigned Bit) 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;
@ -1413,7 +1392,7 @@ Init *VarListElementInit:: resolveListElementReference(Record &R,
}
return Result;
}
return nullptr;
}
@ -1473,15 +1452,13 @@ Init *FieldInit::resolveListElementReference(Record &R, const RecordVal *RV,
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);
}
@ -1785,12 +1762,11 @@ Record::getValueAsListOfDefs(StringRef FieldName) const {
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;
}
@ -1820,12 +1796,11 @@ Record::getValueAsListOfInts(StringRef FieldName) const {
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;
}
@ -1839,12 +1814,11 @@ Record::getValueAsListOfStrings(StringRef FieldName) const {
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;
}
@ -1920,9 +1894,8 @@ void MultiClass::dump() const {
Rec.dump();
errs() << "Defs:\n";
for (const auto &Proto : DefPrototypes) {
for (const auto &Proto : DefPrototypes)
Proto->dump();
}
}

View File

@ -51,9 +51,8 @@ void SubMultiClassReference::dump() const {
MC->dump();
errs() << "Template args:\n";
for (Init *TA : TemplateArgs) {
for (Init *TA : TemplateArgs)
TA->dump();
}
}
} // end namespace llvm
@ -107,9 +106,8 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, Init *ValName,
// 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);
@ -134,10 +132,9 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, Init *ValName,
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() +
@ -580,13 +577,12 @@ bool TGParser::ParseRangePiece(std::vector<unsigned> &Ranges) {
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;
}
@ -763,7 +759,7 @@ Init *TGParser::ParseIDValue(Record *CurRec,
Error(NameLoc, "Variable not defined: '" + Name + "'");
return nullptr;
}
return StringInit::get(Name);
}
@ -856,11 +852,8 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
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());
@ -868,11 +861,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
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;
}
}
}
@ -1559,7 +1548,7 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
Error(PasteLoc, "LHS of paste is not typed!");
return nullptr;
}
if (LHS->getType() != StringRecTy::get()) {
LHS = UnOpInit::get(UnOpInit::CAST, LHS, StringRecTy::get());
}
@ -1574,7 +1563,7 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
// 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;
@ -1590,7 +1579,7 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
if (RHS->getType() != StringRecTy::get()) {
RHS = UnOpInit::get(UnOpInit::CAST, RHS, StringRecTy::get());
}
break;
}
@ -1724,11 +1713,10 @@ Init *TGParser::ParseDeclaration(Record *CurRec,
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,
"::");
@ -2061,10 +2049,9 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) {
}
}
if (ProcessForeachDefs(CurRec, DefLoc)) {
if (ProcessForeachDefs(CurRec, DefLoc))
return Error(DefLoc, "Could not process loops for def" +
CurRec->getNameInitAsString());
}
return false;
}
@ -2097,8 +2084,7 @@ bool TGParser::ParseForeach(MultiClass *CurMultiClass) {
// 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 '{'.
@ -2443,14 +2429,14 @@ bool TGParser::ResolveMulticlassDefArgs(MultiClass &MC,
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() +