if (AddValue(CurRec, SubMultiClass.RefRange.Start, SMCVals[i]))
return true;
- int newDefStart = CurMC->DefPrototypes.size();
+ unsigned newDefStart = CurMC->DefPrototypes.size();
// Add all of the defs in the subclass into the current multiclass.
for (MultiClass::RecordVector::const_iterator i = SMC->DefPrototypes.begin(),
if (AddValue(NewDef.get(), SubMultiClass.RefRange.Start, MCVals[i]))
return true;
- CurMC->DefPrototypes.push_back(NewDef.release());
+ CurMC->DefPrototypes.push_back(std::move(NewDef));
}
const std::vector<Init *> &SMCTArgs = SMC->Rec.getTemplateArgs();
jend = CurMC->DefPrototypes.end();
j != jend;
++j) {
- Record *Def = *j;
+ Record *Def = j->get();
if (SetValue(Def, SubMultiClass.RefRange.Start, SMCTArgs[i],
std::vector<unsigned>(),
return nullptr;
}
- MultiClass *Result = MultiClasses[Lex.getCurStrVal()];
- if (!Result)
+ auto it = MultiClasses.find(Lex.getCurStrVal());
+ if (it == MultiClasses.end())
TokError("Couldn't find multiclass '" + Lex.getCurStrVal() + "'");
Lex.Lex();
- return Result;
+ return &it->second;
}
/// ParseSubClassReference - Parse a reference to a subclass or to a templated
SMLoc EndLoc = Lex.getLoc();
// Create the new record, set it as CurRec temporarily.
- auto NewRecOwner = make_unique<Record>(GetNewAnonymousName(), NameLoc,
- Records, /*IsAnonymous=*/true);
+ auto NewRecOwner = llvm::make_unique<Record>(GetNewAnonymousName(), NameLoc,
+ Records, /*IsAnonymous=*/true);
Record *NewRec = NewRecOwner.get(); // Keep a copy since we may release.
SubClassReference SCRef;
SCRef.RefRange = SMRange(NameLoc, EndLoc);
// known before any use.
NewRec->setResolveFirst(true);
// Otherwise, we're inside a multiclass, add it to the multiclass.
- CurMultiClass->DefPrototypes.push_back(NewRecOwner.release());
+ CurMultiClass->DefPrototypes.push_back(std::move(NewRecOwner));
// Copy the template arguments for the multiclass into the def.
const std::vector<Init *> &TArgs =
if (Name)
CurRecOwner = make_unique<Record>(Name, DefLoc, Records);
else
- CurRecOwner = make_unique<Record>(GetNewAnonymousName(), DefLoc, Records,
- /*IsAnonymous=*/true);
+ CurRecOwner = llvm::make_unique<Record>(GetNewAnonymousName(), DefLoc,
+ Records, /*IsAnonymous=*/true);
Record *CurRec = CurRecOwner.get(); // Keep a copy since we may release.
if (!CurMultiClass && Loops.empty()) {
== CurRec->getNameInit())
return Error(DefLoc, "def '" + CurRec->getNameInitAsString() +
"' already defined in this multiclass!");
- CurMultiClass->DefPrototypes.push_back(CurRecOwner.release());
+ CurMultiClass->DefPrototypes.push_back(std::move(CurRecOwner));
} else if (ParseObjectBody(CurRec)) {
return true;
}
return TokError("expected identifier after multiclass for name");
std::string Name = Lex.getCurStrVal();
- if (MultiClasses.count(Name))
+ auto Result =
+ MultiClasses.insert(std::make_pair(Name,
+ MultiClass(Name, Lex.getLoc(),Records)));
+ if (!Result.second)
return TokError("multiclass '" + Name + "' already defined");
+ CurMultiClass = &Result.first->second;
- CurMultiClass = MultiClasses[Name] = new MultiClass(Name,
- Lex.getLoc(), Records);
Lex.Lex(); // Eat the identifier.
// If there are template args, parse them.
if (Lex.getCode() != tgtok::l_brace) {
if (!inherits)
return TokError("expected '{' in multiclass definition");
- else if (Lex.getCode() != tgtok::semi)
+ if (Lex.getCode() != tgtok::semi)
return TokError("expected ';' in multiclass definition");
- else
- Lex.Lex(); // eat the ';'.
+ Lex.Lex(); // eat the ';'.
} else {
if (Lex.Lex() == tgtok::r_brace) // eat the '{'.
return TokError("multiclass must contain at least one def");
while (Lex.getCode() != tgtok::r_brace) {
switch (Lex.getCode()) {
- default:
- return TokError("expected 'let', 'def' or 'defm' in multiclass body");
- case tgtok::Let:
- case tgtok::Def:
- case tgtok::Defm:
- case tgtok::Foreach:
- if (ParseObject(CurMultiClass))
- return true;
- break;
+ default:
+ return TokError("expected 'let', 'def' or 'defm' in multiclass body");
+ case tgtok::Let:
+ case tgtok::Def:
+ case tgtok::Defm:
+ case tgtok::Foreach:
+ if (ParseObject(CurMultiClass))
+ return true;
+ break;
}
}
Lex.Lex(); // eat the '}'.
== CurRec->getNameInit())
return Error(DefmPrefixLoc, "defm '" + CurRec->getNameInitAsString() +
"' already defined in this multiclass!");
- CurMultiClass->DefPrototypes.push_back(CurRec);
+ CurMultiClass->DefPrototypes.push_back(std::unique_ptr<Record>(CurRec));
// Copy the template arguments for the multiclass into the new def.
const std::vector<Init *> &TA =
// To instantiate a multiclass, we need to first get the multiclass, then
// instantiate each def contained in the multiclass with the SubClassRef
// template parameters.
- MultiClass *MC = MultiClasses[Ref.Rec->getName()];
- assert(MC && "Didn't lookup multiclass correctly?");
+ auto it = MultiClasses.find(Ref.Rec->getName());
+ assert(it != MultiClasses.end() && "Didn't lookup multiclass correctly?");
+ MultiClass *MC = &it->second;
std::vector<Init*> &TemplateVals = Ref.TemplateArgs;
// Verify that the correct number of template arguments were specified.
// Loop over all the def's in the multiclass, instantiating each one.
for (unsigned i = 0, e = MC->DefPrototypes.size(); i != e; ++i) {
- Record *DefProto = MC->DefPrototypes[i];
+ Record *DefProto = MC->DefPrototypes[i].get();
Record *CurRec = InstantiateMulticlassDef(*MC, DefProto, DefmPrefix,
SMRange(DefmLoc,