summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2012-05-24 21:37:08 +0000
committerOwen Anderson <resistor@mac.com>2012-05-24 21:37:08 +0000
commit6b31d4ea3610b04d71e1eb38d8fc625eae7b759a (patch)
tree5a8152caa3dd148168f29df834b539b98136d5bb /utils
parentd6d05e3f788d60d5c76ab99ce95ea6f622932d90 (diff)
downloadexternal_llvm-6b31d4ea3610b04d71e1eb38d8fc625eae7b759a.zip
external_llvm-6b31d4ea3610b04d71e1eb38d8fc625eae7b759a.tar.gz
external_llvm-6b31d4ea3610b04d71e1eb38d8fc625eae7b759a.tar.bz2
Teach tblgen's set theory "sequence" operator to support an optional stride operand.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157416 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/SetTheory.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/utils/TableGen/SetTheory.cpp b/utils/TableGen/SetTheory.cpp
index 0649fd1..46e6db1 100644
--- a/utils/TableGen/SetTheory.cpp
+++ b/utils/TableGen/SetTheory.cpp
@@ -160,9 +160,17 @@ struct InterleaveOp : public SetTheory::Operator {
// (sequence "Format", From, To) Generate a sequence of records by name.
struct SequenceOp : public SetTheory::Operator {
void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) {
- if (Expr->arg_size() != 3)
+ int Step = 1;
+ if (Expr->arg_size() > 4)
throw "Bad args to (sequence \"Format\", From, To): " +
Expr->getAsString();
+ else if (Expr->arg_size() == 4) {
+ if (IntInit *II = dynamic_cast<IntInit*>(Expr->arg_begin()[3])) {
+ Step = II->getValue();
+ } else
+ throw "Stride must be an integer: " + Expr->getAsString();
+ }
+
std::string Format;
if (StringInit *SI = dynamic_cast<StringInit*>(Expr->arg_begin()[0]))
Format = SI->getValue();
@@ -187,8 +195,12 @@ struct SequenceOp : public SetTheory::Operator {
RecordKeeper &Records =
dynamic_cast<DefInit&>(*Expr->getOperator()).getDef()->getRecords();
- int Step = From <= To ? 1 : -1;
- for (To += Step; From != To; From += Step) {
+ Step *= From <= To ? 1 : -1;
+ while (true) {
+ if (Step > 0 && From > To)
+ break;
+ else if (Step < 0 && From < To)
+ break;
std::string Name;
raw_string_ostream OS(Name);
OS << format(Format.c_str(), unsigned(From));
@@ -200,6 +212,8 @@ struct SequenceOp : public SetTheory::Operator {
Elts.insert(Result->begin(), Result->end());
else
Elts.insert(Rec);
+
+ From += Step;
}
}
};