forked from OSchip/llvm-project
Implement correct parsing, representation, and printing of DAG argument names
Implements testcase TableGen/TreeNames.td llvm-svn: 7713
This commit is contained in:
parent
4eaf72fc3b
commit
3859c9a8db
|
@ -161,12 +161,12 @@ static void addSubClass(Record *SC, const std::vector<Init*> &TemplateArgs) {
|
||||||
int IntVal;
|
int IntVal;
|
||||||
RecTy *Ty;
|
RecTy *Ty;
|
||||||
Init *Initializer;
|
Init *Initializer;
|
||||||
std::vector<Init*> *DagValueList;
|
|
||||||
std::vector<Init*> *FieldList;
|
std::vector<Init*> *FieldList;
|
||||||
std::vector<unsigned>*BitList;
|
std::vector<unsigned>*BitList;
|
||||||
Record *Rec;
|
Record *Rec;
|
||||||
SubClassRefTy *SubClassRef;
|
SubClassRefTy *SubClassRef;
|
||||||
std::vector<SubClassRefTy> *SubClassList;
|
std::vector<SubClassRefTy> *SubClassList;
|
||||||
|
std::vector<std::pair<Init*, std::string> > *DagValueList;
|
||||||
};
|
};
|
||||||
|
|
||||||
%token INT BIT STRING BITS LIST CODE DAG CLASS DEF FIELD LET IN
|
%token INT BIT STRING BITS LIST CODE DAG CLASS DEF FIELD LET IN
|
||||||
|
@ -183,7 +183,7 @@ static void addSubClass(Record *SC, const std::vector<Init*> &TemplateArgs) {
|
||||||
%type <DagValueList> DagArgList DagArgListNE
|
%type <DagValueList> DagArgList DagArgListNE
|
||||||
%type <FieldList> ValueList ValueListNE
|
%type <FieldList> ValueList ValueListNE
|
||||||
%type <BitList> BitList OptBitList RBitList
|
%type <BitList> BitList OptBitList RBitList
|
||||||
%type <StrVal> Declaration OptID
|
%type <StrVal> Declaration OptID OptVarName
|
||||||
|
|
||||||
%start File
|
%start File
|
||||||
%%
|
%%
|
||||||
|
@ -282,16 +282,26 @@ Value : INTVAL {
|
||||||
delete $2; delete $3;
|
delete $2; delete $3;
|
||||||
};
|
};
|
||||||
|
|
||||||
DagArgListNE : Value {
|
OptVarName : /* empty */ {
|
||||||
$$ = new std::vector<Init*>();
|
$$ = new std::string();
|
||||||
$$->push_back($1);
|
|
||||||
}
|
}
|
||||||
| DagArgListNE ',' Value {
|
| ':' VARNAME {
|
||||||
$1->push_back($3);
|
$$ = $2;
|
||||||
|
};
|
||||||
|
|
||||||
|
DagArgListNE : Value OptVarName {
|
||||||
|
$$ = new std::vector<std::pair<Init*, std::string> >();
|
||||||
|
$$->push_back(std::make_pair($1, *$2));
|
||||||
|
delete $2;
|
||||||
|
}
|
||||||
|
| DagArgListNE ',' Value OptVarName {
|
||||||
|
$1->push_back(std::make_pair($3, *$4));
|
||||||
|
delete $4;
|
||||||
|
$$ = $1;
|
||||||
};
|
};
|
||||||
|
|
||||||
DagArgList : /*empty*/ {
|
DagArgList : /*empty*/ {
|
||||||
$$ = new std::vector<Init*>();
|
$$ = new std::vector<std::pair<Init*, std::string> >();
|
||||||
}
|
}
|
||||||
| DagArgListNE { $$ = $1; };
|
| DagArgListNE { $$ = $1; };
|
||||||
|
|
||||||
|
|
|
@ -172,15 +172,14 @@ MVT::ValueType Pattern::getIntrinsicType(Record *R) const {
|
||||||
|
|
||||||
TreePatternNode *Pattern::ParseTreePattern(DagInit *DI) {
|
TreePatternNode *Pattern::ParseTreePattern(DagInit *DI) {
|
||||||
Record *Operator = DI->getNodeType();
|
Record *Operator = DI->getNodeType();
|
||||||
const std::vector<Init*> &Args = DI->getArgs();
|
|
||||||
|
|
||||||
if (Operator->isSubClassOf("ValueType")) {
|
if (Operator->isSubClassOf("ValueType")) {
|
||||||
// If the operator is a ValueType, then this must be "type cast" of a leaf
|
// If the operator is a ValueType, then this must be "type cast" of a leaf
|
||||||
// node.
|
// node.
|
||||||
if (Args.size() != 1)
|
if (DI->getNumArgs() != 1)
|
||||||
error("Type cast only valid for a leaf node!");
|
error("Type cast only valid for a leaf node!");
|
||||||
|
|
||||||
Init *Arg = Args[0];
|
Init *Arg = DI->getArg(0);
|
||||||
TreePatternNode *New;
|
TreePatternNode *New;
|
||||||
if (DefInit *DI = dynamic_cast<DefInit*>(Arg)) {
|
if (DefInit *DI = dynamic_cast<DefInit*>(Arg)) {
|
||||||
New = new TreePatternNode(DI);
|
New = new TreePatternNode(DI);
|
||||||
|
@ -201,8 +200,8 @@ TreePatternNode *Pattern::ParseTreePattern(DagInit *DI) {
|
||||||
|
|
||||||
std::vector<TreePatternNode*> Children;
|
std::vector<TreePatternNode*> Children;
|
||||||
|
|
||||||
for (unsigned i = 0, e = Args.size(); i != e; ++i) {
|
for (unsigned i = 0, e = DI->getNumArgs(); i != e; ++i) {
|
||||||
Init *Arg = Args[i];
|
Init *Arg = DI->getArg(i);
|
||||||
if (DagInit *DI = dynamic_cast<DagInit*>(Arg)) {
|
if (DagInit *DI = dynamic_cast<DagInit*>(Arg)) {
|
||||||
Children.push_back(ParseTreePattern(DI));
|
Children.push_back(ParseTreePattern(DI));
|
||||||
} else if (DefInit *DI = dynamic_cast<DefInit*>(Arg)) {
|
} else if (DefInit *DI = dynamic_cast<DefInit*>(Arg)) {
|
||||||
|
|
|
@ -438,8 +438,11 @@ void DagInit::print(std::ostream &OS) const {
|
||||||
OS << "(" << NodeTypeDef->getName();
|
OS << "(" << NodeTypeDef->getName();
|
||||||
if (Args.size()) {
|
if (Args.size()) {
|
||||||
OS << " " << *Args[0];
|
OS << " " << *Args[0];
|
||||||
for (unsigned i = 1, e = Args.size(); i != e; ++i)
|
if (!ArgNames[0].empty()) OS << ":$" << ArgNames[0];
|
||||||
|
for (unsigned i = 1, e = Args.size(); i != e; ++i) {
|
||||||
OS << ", " << *Args[i];
|
OS << ", " << *Args[i];
|
||||||
|
if (!ArgNames[i].empty()) OS << ":$" << ArgNames[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
OS << ")";
|
OS << ")";
|
||||||
}
|
}
|
||||||
|
|
|
@ -591,9 +591,16 @@ public:
|
||||||
class DagInit : public Init {
|
class DagInit : public Init {
|
||||||
Record *NodeTypeDef;
|
Record *NodeTypeDef;
|
||||||
std::vector<Init*> Args;
|
std::vector<Init*> Args;
|
||||||
|
std::vector<std::string> ArgNames;
|
||||||
public:
|
public:
|
||||||
DagInit(Record *D, std::vector<Init*> &a) : NodeTypeDef(D) {
|
DagInit(Record *D, const std::vector<std::pair<Init*, std::string> > &args)
|
||||||
Args.swap(a); // DESTRUCTIVELY take the arguments
|
: NodeTypeDef(D) {
|
||||||
|
Args.reserve(args.size());
|
||||||
|
ArgNames.reserve(args.size());
|
||||||
|
for (unsigned i = 0, e = args.size(); i != e; ++i) {
|
||||||
|
Args.push_back(args[i].first);
|
||||||
|
ArgNames.push_back(args[i].second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Init *convertInitializerTo(RecTy *Ty) {
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
||||||
|
@ -601,7 +608,16 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Record *getNodeType() const { return NodeTypeDef; }
|
Record *getNodeType() const { return NodeTypeDef; }
|
||||||
const std::vector<Init*> &getArgs() const { return Args; }
|
|
||||||
|
unsigned getNumArgs() const { return Args.size(); }
|
||||||
|
Init *getArg(unsigned Num) const {
|
||||||
|
assert(Num < Args.size() && "Arg number out of range!");
|
||||||
|
return Args[Num];
|
||||||
|
}
|
||||||
|
const std::string &getArgName(unsigned Num) const {
|
||||||
|
assert(Num < ArgNames.size() && "Arg number out of range!");
|
||||||
|
return ArgNames[Num];
|
||||||
|
}
|
||||||
|
|
||||||
virtual void print(std::ostream &OS) const;
|
virtual void print(std::ostream &OS) const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue