mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-26 05:32:25 +00:00
[TableGen] Correctly generate implicit anonymous prototype defs in multiclasses
Even within a multiclass, we had been generating concrete implicit anonymous defs when parsing values (generally in value lists). This behavior was incorrect, and led to errors when multiclass parameters were used in the parameter list of the implicit anonymous def. If we had some multiclass: multiclass mc<string n> { ... : SomeClass<SomeOtherClass<n> > The capture of the multiclass parameter 'n' would not work correctly, and depending on how the implicit SomeOtherClass was used, either TableGen would ignore something it shouldn't, or would crash. To fix this problem, when inside a multiclass, we generate prototype anonymous defs for implicit anonymous defs (just as we do for explicit anonymous defs). Within the multiclass, the current record prototype is populated with a node that is essentially: !cast<SomeOtherClass>(!strconcat(NAME, anon_value_name)). This is then resolved to the correct concrete anonymous def, in the usual way, when NAME is resolved during multiclass instantiation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198348 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6fa9961327
commit
0a3368cde5
@ -1225,8 +1225,36 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
|
|||||||
// Add info about the subclass to NewRec.
|
// Add info about the subclass to NewRec.
|
||||||
if (AddSubClass(NewRec, SCRef))
|
if (AddSubClass(NewRec, SCRef))
|
||||||
return 0;
|
return 0;
|
||||||
NewRec->resolveReferences();
|
if (!CurMultiClass) {
|
||||||
Records.addDef(NewRec);
|
NewRec->resolveReferences();
|
||||||
|
Records.addDef(NewRec);
|
||||||
|
} else {
|
||||||
|
// Otherwise, we're inside a multiclass, add it to the multiclass.
|
||||||
|
CurMultiClass->DefPrototypes.push_back(NewRec);
|
||||||
|
|
||||||
|
// Copy the template arguments for the multiclass into the def.
|
||||||
|
const std::vector<Init *> &TArgs =
|
||||||
|
CurMultiClass->Rec.getTemplateArgs();
|
||||||
|
|
||||||
|
for (unsigned i = 0, e = TArgs.size(); i != e; ++i) {
|
||||||
|
const RecordVal *RV = CurMultiClass->Rec.getValue(TArgs[i]);
|
||||||
|
assert(RV && "Template arg doesn't exist?");
|
||||||
|
NewRec->addValue(*RV);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We can't return the prototype def here, instead return:
|
||||||
|
// !cast<ItemType>(!strconcat(NAME, AnonName)).
|
||||||
|
const RecordVal *MCNameRV = CurMultiClass->Rec.getValue("NAME");
|
||||||
|
assert(MCNameRV && "multiclass record must have a NAME");
|
||||||
|
|
||||||
|
return UnOpInit::get(UnOpInit::CAST,
|
||||||
|
BinOpInit::get(BinOpInit::STRCONCAT,
|
||||||
|
VarInit::get(MCNameRV->getName(),
|
||||||
|
MCNameRV->getType()),
|
||||||
|
NewRec->getNameInit(),
|
||||||
|
StringRecTy::get()),
|
||||||
|
Class->getDefInit()->getType());
|
||||||
|
}
|
||||||
|
|
||||||
// The result of the expression is a reference to the new record.
|
// The result of the expression is a reference to the new record.
|
||||||
return DefInit::get(NewRec);
|
return DefInit::get(NewRec);
|
||||||
@ -1962,7 +1990,18 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Records.addDef(CurRec);
|
Records.addDef(CurRec);
|
||||||
|
|
||||||
|
if (ParseObjectBody(CurRec))
|
||||||
|
return true;
|
||||||
} else if (CurMultiClass) {
|
} else if (CurMultiClass) {
|
||||||
|
// Parse the body before adding this prototype to the DefPrototypes vector.
|
||||||
|
// That way implicit definitions will be added to the DefPrototypes vector
|
||||||
|
// before this object, instantiated prior to defs derived from this object,
|
||||||
|
// and this available for indirect name resolution when defs derived from
|
||||||
|
// this object are instantiated.
|
||||||
|
if (ParseObjectBody(CurRec))
|
||||||
|
return true;
|
||||||
|
|
||||||
// Otherwise, a def inside a multiclass, add it to the multiclass.
|
// Otherwise, a def inside a multiclass, add it to the multiclass.
|
||||||
for (unsigned i = 0, e = CurMultiClass->DefPrototypes.size(); i != e; ++i)
|
for (unsigned i = 0, e = CurMultiClass->DefPrototypes.size(); i != e; ++i)
|
||||||
if (CurMultiClass->DefPrototypes[i]->getNameInit()
|
if (CurMultiClass->DefPrototypes[i]->getNameInit()
|
||||||
@ -1972,9 +2011,7 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
CurMultiClass->DefPrototypes.push_back(CurRec);
|
CurMultiClass->DefPrototypes.push_back(CurRec);
|
||||||
}
|
} else if (ParseObjectBody(CurRec))
|
||||||
|
|
||||||
if (ParseObjectBody(CurRec))
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (CurMultiClass == 0) // Def's in multiclasses aren't really defs.
|
if (CurMultiClass == 0) // Def's in multiclasses aren't really defs.
|
||||||
|
@ -29,3 +29,13 @@ multiclass MC<string name> {
|
|||||||
|
|
||||||
defm : MC<"foo">;
|
defm : MC<"foo">;
|
||||||
|
|
||||||
|
multiclass MC2<string name> {
|
||||||
|
def there : Outer<C<name> >;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that we've correctly captured the reference to name from the implicit
|
||||||
|
// anonymous C def in the template parameter list of Outer.
|
||||||
|
// CHECK-NOT: MC2::name
|
||||||
|
|
||||||
|
defm : MC2<"bar">;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user