[llvm-commits] CVS: llvm/utils/TableGen/FileParser.y InstrSelectorEmitter.cpp Record.cpp Record.h
Chris Lattner
lattner at cs.uiuc.edu
Sun Aug 10 18:59:14 PDT 2003
Changes in directory llvm/utils/TableGen:
FileParser.y updated: 1.21 -> 1.22
InstrSelectorEmitter.cpp updated: 1.18 -> 1.19
Record.cpp updated: 1.27 -> 1.28
Record.h updated: 1.34 -> 1.35
---
Log message:
Implement correct parsing, representation, and printing of DAG argument names
Implements testcase TableGen/TreeNames.td
---
Diffs of the changes:
Index: llvm/utils/TableGen/FileParser.y
diff -u llvm/utils/TableGen/FileParser.y:1.21 llvm/utils/TableGen/FileParser.y:1.22
--- llvm/utils/TableGen/FileParser.y:1.21 Sun Aug 10 17:04:25 2003
+++ llvm/utils/TableGen/FileParser.y Sun Aug 10 17:14:13 2003
@@ -161,12 +161,12 @@
int IntVal;
RecTy *Ty;
Init *Initializer;
- std::vector<Init*> *DagValueList;
std::vector<Init*> *FieldList;
std::vector<unsigned>*BitList;
Record *Rec;
SubClassRefTy *SubClassRef;
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
@@ -183,7 +183,7 @@
%type <DagValueList> DagArgList DagArgListNE
%type <FieldList> ValueList ValueListNE
%type <BitList> BitList OptBitList RBitList
-%type <StrVal> Declaration OptID
+%type <StrVal> Declaration OptID OptVarName
%start File
%%
@@ -282,16 +282,26 @@
delete $2; delete $3;
};
-DagArgListNE : Value {
- $$ = new std::vector<Init*>();
- $$->push_back($1);
+OptVarName : /* empty */ {
+ $$ = new std::string();
}
- | DagArgListNE ',' Value {
- $1->push_back($3);
+ | ':' VARNAME {
+ $$ = $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*/ {
- $$ = new std::vector<Init*>();
+ $$ = new std::vector<std::pair<Init*, std::string> >();
}
| DagArgListNE { $$ = $1; };
Index: llvm/utils/TableGen/InstrSelectorEmitter.cpp
diff -u llvm/utils/TableGen/InstrSelectorEmitter.cpp:1.18 llvm/utils/TableGen/InstrSelectorEmitter.cpp:1.19
--- llvm/utils/TableGen/InstrSelectorEmitter.cpp:1.18 Sun Aug 10 16:54:43 2003
+++ llvm/utils/TableGen/InstrSelectorEmitter.cpp Sun Aug 10 17:14:13 2003
@@ -172,15 +172,14 @@
TreePatternNode *Pattern::ParseTreePattern(DagInit *DI) {
Record *Operator = DI->getNodeType();
- const std::vector<Init*> &Args = DI->getArgs();
if (Operator->isSubClassOf("ValueType")) {
// If the operator is a ValueType, then this must be "type cast" of a leaf
// node.
- if (Args.size() != 1)
+ if (DI->getNumArgs() != 1)
error("Type cast only valid for a leaf node!");
- Init *Arg = Args[0];
+ Init *Arg = DI->getArg(0);
TreePatternNode *New;
if (DefInit *DI = dynamic_cast<DefInit*>(Arg)) {
New = new TreePatternNode(DI);
@@ -201,8 +200,8 @@
std::vector<TreePatternNode*> Children;
- for (unsigned i = 0, e = Args.size(); i != e; ++i) {
- Init *Arg = Args[i];
+ for (unsigned i = 0, e = DI->getNumArgs(); i != e; ++i) {
+ Init *Arg = DI->getArg(i);
if (DagInit *DI = dynamic_cast<DagInit*>(Arg)) {
Children.push_back(ParseTreePattern(DI));
} else if (DefInit *DI = dynamic_cast<DefInit*>(Arg)) {
Index: llvm/utils/TableGen/Record.cpp
diff -u llvm/utils/TableGen/Record.cpp:1.27 llvm/utils/TableGen/Record.cpp:1.28
--- llvm/utils/TableGen/Record.cpp:1.27 Thu Aug 7 01:00:43 2003
+++ llvm/utils/TableGen/Record.cpp Sun Aug 10 17:14:13 2003
@@ -438,8 +438,11 @@
OS << "(" << NodeTypeDef->getName();
if (Args.size()) {
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];
+ if (!ArgNames[i].empty()) OS << ":$" << ArgNames[i];
+ }
}
OS << ")";
}
Index: llvm/utils/TableGen/Record.h
diff -u llvm/utils/TableGen/Record.h:1.34 llvm/utils/TableGen/Record.h:1.35
--- llvm/utils/TableGen/Record.h:1.34 Thu Aug 7 14:41:59 2003
+++ llvm/utils/TableGen/Record.h Sun Aug 10 17:14:13 2003
@@ -591,9 +591,16 @@
class DagInit : public Init {
Record *NodeTypeDef;
std::vector<Init*> Args;
+ std::vector<std::string> ArgNames;
public:
- DagInit(Record *D, std::vector<Init*> &a) : NodeTypeDef(D) {
- Args.swap(a); // DESTRUCTIVELY take the arguments
+ DagInit(Record *D, const std::vector<std::pair<Init*, std::string> > &args)
+ : 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) {
@@ -601,7 +608,16 @@
}
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;
};
More information about the llvm-commits
mailing list