//===----------------------------------------------------------------------===//
#include "SetTheory.h"
-#include "Record.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/Record.h"
#include "llvm/Support/Format.h"
using namespace llvm;
// (sequence "Format", From, To) Generate a sequence of records by name.
struct SequenceOp : public SetTheory::Operator {
- RecordKeeper &Records;
-
- SequenceOp(RecordKeeper&R) : Records(R) {}
-
void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) {
if (Expr->arg_size() != 3)
throw "Bad args to (sequence \"Format\", From, To): " +
From = II->getValue();
else
throw "From must be an integer: " + Expr->getAsString();
+ if (From < 0 || From >= (1 << 30))
+ throw "From out of range";
+
if (IntInit *II = dynamic_cast<IntInit*>(Expr->arg_begin()[2]))
To = II->getValue();
else
throw "From must be an integer: " + Expr->getAsString();
+ if (To < 0 || To >= (1 << 30))
+ throw "To out of range";
+
+ RecordKeeper &Records =
+ dynamic_cast<DefInit&>(*Expr->getOperator()).getDef()->getRecords();
int Step = From <= To ? 1 : -1;
for (To += Step; From != To; From += Step) {
std::string Name;
raw_string_ostream OS(Name);
- OS << format(Format.c_str(), From);
+ OS << format(Format.c_str(), unsigned(From));
Record *Rec = Records.getDef(OS.str());
if (!Rec)
throw "No def named '" + Name + "': " + Expr->getAsString();
};
} // end anonymous namespace
-SetTheory::SetTheory(RecordKeeper *Records) {
+SetTheory::SetTheory() {
addOperator("add", new AddOp);
addOperator("sub", new SubOp);
addOperator("and", new AndOp);
addOperator("rotl", new RotOp(false));
addOperator("rotr", new RotOp(true));
addOperator("decimate", new DecimateOp);
- if (Records)
- addOperator("sequence", new SequenceOp(*Records));
+ addOperator("sequence", new SequenceOp);
}
void SetTheory::addOperator(StringRef Name, Operator *Op) {