///
class DagInit : public TypedInit, public FoldingSetNode {
Init *Val;
- std::string ValName;
+ StringInit *ValName;
std::vector<Init*> Args;
std::vector<std::string> ArgNames;
- DagInit(Init *V, StringRef VN, ArrayRef<Init *> ArgRange,
+ DagInit(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
ArrayRef<std::string> NameRange)
: TypedInit(IK_DagInit, DagRecTy::get()), Val(V), ValName(VN),
Args(ArgRange.begin(), ArgRange.end()),
return I->getKind() == IK_DagInit;
}
- static DagInit *get(Init *V, StringRef VN, ArrayRef<Init *> ArgRange,
+ static DagInit *get(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
ArrayRef<std::string> NameRange);
- static DagInit *get(Init *V, StringRef VN,
+ static DagInit *get(Init *V, StringInit *VN,
const std::vector<std::pair<Init*, std::string>> &args);
void Profile(FoldingSetNodeID &ID) const;
Init *getOperator() const { return Val; }
- StringRef getName() const { return ValName; }
+ StringInit *getName() const { return ValName; }
+ StringRef getNameStr() const {
+ return ValName ? ValName->getValue() : StringRef();
+ }
unsigned getNumArgs() const { return Args.size(); }
Init *getArg(unsigned Num) const {
Args.push_back(RHSs->getArg(i));
ArgNames.push_back(RHSs->getArgName(i));
}
- return DagInit::get(LHSs->getOperator(), "", Args, ArgNames);
+ return DagInit::get(LHSs->getOperator(), nullptr, Args, ArgNames);
}
break;
}
args.push_back(std::make_pair(Arg, ArgName));
}
- return DagInit::get(Val, "", args);
+ return DagInit::get(Val, nullptr, args);
}
ListInit *MHSl = dyn_cast<ListInit>(MHS);
return const_cast<FieldInit *>(this);
}
-static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, StringRef VN,
+static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, StringInit *VN,
ArrayRef<Init *> ArgRange,
ArrayRef<std::string> NameRange) {
ID.AddPointer(V);
- ID.AddString(VN);
+ ID.AddPointer(VN);
ArrayRef<Init *>::iterator Arg = ArgRange.begin();
ArrayRef<std::string>::iterator Name = NameRange.begin();
}
DagInit *
-DagInit::get(Init *V, StringRef VN, ArrayRef<Init *> ArgRange,
+DagInit::get(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
ArrayRef<std::string> NameRange) {
static FoldingSet<DagInit> ThePool;
static std::vector<DagInit*> TheActualPool;
}
DagInit *
-DagInit::get(Init *V, StringRef VN,
+DagInit::get(Init *V, StringInit *VN,
const std::vector<std::pair<Init*, std::string> > &args) {
std::vector<Init *> Args;
std::vector<std::string> Names;
std::string DagInit::getAsString() const {
std::string Result = "(" + Val->getAsString();
- if (!ValName.empty())
- Result += ":" + ValName;
+ if (ValName)
+ Result += ":" + ValName->getAsUnquotedString();
if (!Args.empty()) {
Result += " " + Args[0]->getAsString();
if (!ArgNames[0].empty()) Result += ":$" + ArgNames[0];
if (!Operator) return nullptr;
// If the operator name is present, parse it.
- std::string OperatorName;
+ StringInit *OperatorName = nullptr;
if (Lex.getCode() == tgtok::colon) {
if (Lex.Lex() != tgtok::VarName) { // eat the ':'
TokError("expected variable name in dag operator");
return nullptr;
}
- OperatorName = Lex.getCurStrVal();
+ OperatorName = StringInit::get(Lex.getCurStrVal());
Lex.Lex(); // eat the VarName.
}
/// (foo GPR, imm) -> (foo GPR, (imm))
if (R->isSubClassOf("SDNode") || R->isSubClassOf("PatFrag"))
return ParseTreePattern(
- DagInit::get(DI, "",
+ DagInit::get(DI, nullptr,
std::vector<std::pair<Init*, std::string> >()),
OpName);
TreePatternNode *Result = new TreePatternNode(Operator, Children, NumResults);
Result->setName(OpName);
- if (!Dag->getName().empty()) {
+ if (Dag->getName()) {
assert(Result->getName().empty());
- Result->setName(Dag->getName());
+ Result->setName(Dag->getNameStr());
}
return Result;
}
for (unsigned op = 0, e = DefaultInfo->getNumArgs(); op != e; ++op)
Ops.push_back(std::make_pair(DefaultInfo->getArg(op),
DefaultInfo->getArgName(op)));
- DagInit *DI = DagInit::get(SomeSDNode, "", Ops);
+ DagInit *DI = DagInit::get(SomeSDNode, nullptr, Ops);
// Create a TreePattern to parse this.
TreePattern P(DefaultOps[i], DI, false, *this);