[llvm-commits] CVS: llvm/utils/TableGen/FileParser.y Record.cpp Record.h
Chris Lattner
lattner at cs.uiuc.edu
Mon Jul 26 16:21:44 PDT 2004
Changes in directory llvm/utils/TableGen:
FileParser.y updated: 1.29 -> 1.30
Record.cpp updated: 1.32 -> 1.33
Record.h updated: 1.39 -> 1.40
---
Log message:
Add initial support for list slices. This currently allows you to do stuff
like this:
def B {
list<int> X = [10, 20, 30, 4, 1, 1231, 20] [2-4,2,2,0-6];
}
... which isn't particularly useful, but more is to come.
---
Diffs of the changes: (+65 -16)
Index: llvm/utils/TableGen/FileParser.y
diff -u llvm/utils/TableGen/FileParser.y:1.29 llvm/utils/TableGen/FileParser.y:1.30
--- llvm/utils/TableGen/FileParser.y:1.29 Sat Feb 28 11:41:48 2004
+++ llvm/utils/TableGen/FileParser.y Mon Jul 26 18:21:34 2004
@@ -300,6 +300,14 @@
}
$$ = new DagInit(D, *$3);
delete $2; delete $3;
+ } | Value '[' BitList ']' {
+ std::reverse($3->begin(), $3->end());
+ $$ = $1->convertInitListSlice(*$3);
+ if ($$ == 0) {
+ err() << "Invalid list slice for value '" << *$1 << "'!\n";
+ exit(1);
+ }
+ delete $3;
};
OptVarName : /* empty */ {
@@ -330,41 +338,61 @@
$$ = new std::vector<unsigned>();
$$->push_back($1);
} | INTVAL '-' INTVAL {
- if ($1 < $3 || $1 < 0 || $3 < 0) {
- err() << "Invalid bit range: " << $1 << "-" << $3 << "!\n";
+ if ($1 < 0 || $3 < 0) {
+ err() << "Invalid range: " << $1 << "-" << $3 << "!\n";
exit(1);
}
$$ = new std::vector<unsigned>();
- for (int i = $1; i >= $3; --i)
- $$->push_back(i);
+ if ($1 < $3) {
+ for (int i = $1; i <= $3; ++i)
+ $$->push_back(i);
+ } else {
+ for (int i = $1; i >= $3; --i)
+ $$->push_back(i);
+ }
} | INTVAL INTVAL {
$2 = -$2;
- if ($1 < $2 || $1 < 0 || $2 < 0) {
- err() << "Invalid bit range: " << $1 << "-" << $2 << "!\n";
+ if ($1 < 0 || $2 < 0) {
+ err() << "Invalid range: " << $1 << "-" << $2 << "!\n";
exit(1);
}
$$ = new std::vector<unsigned>();
- for (int i = $1; i >= $2; --i)
- $$->push_back(i);
+ if ($1 < $2) {
+ for (int i = $1; i <= $2; ++i)
+ $$->push_back(i);
+ } else {
+ for (int i = $1; i >= $2; --i)
+ $$->push_back(i);
+ }
} | RBitList ',' INTVAL {
($$=$1)->push_back($3);
} | RBitList ',' INTVAL '-' INTVAL {
- if ($3 < $5 || $3 < 0 || $5 < 0) {
- err() << "Invalid bit range: " << $3 << "-" << $5 << "!\n";
+ if ($3 < 0 || $5 < 0) {
+ err() << "Invalid range: " << $3 << "-" << $5 << "!\n";
exit(1);
}
$$ = $1;
- for (int i = $3; i >= $5; --i)
- $$->push_back(i);
+ if ($3 < $5) {
+ for (int i = $3; i <= $5; ++i)
+ $$->push_back(i);
+ } else {
+ for (int i = $3; i >= $5; --i)
+ $$->push_back(i);
+ }
} | RBitList ',' INTVAL INTVAL {
$4 = -$4;
- if ($3 < $4 || $3 < 0 || $4 < 0) {
- err() << "Invalid bit range: " << $3 << "-" << $4 << "!\n";
+ if ($3 < 0 || $4 < 0) {
+ err() << "Invalid range: " << $3 << "-" << $4 << "!\n";
exit(1);
}
$$ = $1;
- for (int i = $3; i >= $4; --i)
- $$->push_back(i);
+ if ($3 < $4) {
+ for (int i = $3; i <= $4; ++i)
+ $$->push_back(i);
+ } else {
+ for (int i = $3; i >= $4; --i)
+ $$->push_back(i);
+ }
};
BitList : RBitList { $$ = $1; std::reverse($1->begin(), $1->end()); };
Index: llvm/utils/TableGen/Record.cpp
diff -u llvm/utils/TableGen/Record.cpp:1.32 llvm/utils/TableGen/Record.cpp:1.33
--- llvm/utils/TableGen/Record.cpp:1.32 Mon Jun 21 13:01:47 2004
+++ llvm/utils/TableGen/Record.cpp Mon Jul 26 18:21:34 2004
@@ -310,6 +310,16 @@
return BI;
}
+Init *ListInit::convertInitListSlice(const std::vector<unsigned> &Elements) {
+ std::vector<Init*> Vals;
+ for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
+ if (Elements[i] >= getSize())
+ return 0;
+ Vals.push_back(getElement(Elements[i]));
+ }
+ return new ListInit(Vals);
+}
+
void ListInit::print(std::ostream &OS) const {
OS << "[";
for (unsigned i = 0, e = Values.size(); i != e; ++i) {
Index: llvm/utils/TableGen/Record.h
diff -u llvm/utils/TableGen/Record.h:1.39 llvm/utils/TableGen/Record.h:1.40
--- llvm/utils/TableGen/Record.h:1.39 Thu Apr 15 10:30:15 2004
+++ llvm/utils/TableGen/Record.h Mon Jul 26 18:21:34 2004
@@ -304,6 +304,15 @@
return 0;
}
+ /// convertInitListSlice - This method is used to implement the list slice
+ /// selection operator. Given an initializer, it selects the specified list
+ /// elements, returning them as a new init of list type. If it is not legal
+ /// to take a slice of this, return null.
+ ///
+ virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements) {
+ return 0;
+ }
+
/// getFieldType - This method is used to implement the FieldInit class.
/// Implementors of this method should return the type of the named field if
/// they are of record type.
@@ -466,6 +475,8 @@
return Values[i];
}
+ Init *convertInitListSlice(const std::vector<unsigned> &Elements);
+
virtual Init *convertInitializerTo(RecTy *Ty) {
return Ty->convertValue(this);
}
More information about the llvm-commits
mailing list