aboutsummaryrefslogtreecommitdiff
path: root/utils/TableGen/SetTheory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/TableGen/SetTheory.cpp')
-rw-r--r--utils/TableGen/SetTheory.cpp41
1 files changed, 20 insertions, 21 deletions
diff --git a/utils/TableGen/SetTheory.cpp b/utils/TableGen/SetTheory.cpp
index a888bbc724..21ac09cb66 100644
--- a/utils/TableGen/SetTheory.cpp
+++ b/utils/TableGen/SetTheory.cpp
@@ -27,14 +27,14 @@ typedef SetTheory::RecVec RecVec;
// (add a, b, ...) Evaluate and union all arguments.
struct AddOp : public SetTheory::Operator {
- void apply(SetTheory &ST, const DagInit *Expr, RecSet &Elts) {
+ void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) {
ST.evaluate(Expr->arg_begin(), Expr->arg_end(), Elts);
}
};
// (sub Add, Sub, ...) Set difference.
struct SubOp : public SetTheory::Operator {
- void apply(SetTheory &ST, const DagInit *Expr, RecSet &Elts) {
+ void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) {
if (Expr->arg_size() < 2)
throw "Set difference needs at least two arguments: " +
Expr->getAsString();
@@ -49,7 +49,7 @@ struct SubOp : public SetTheory::Operator {
// (and S1, S2) Set intersection.
struct AndOp : public SetTheory::Operator {
- void apply(SetTheory &ST, const DagInit *Expr, RecSet &Elts) {
+ void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) {
if (Expr->arg_size() != 2)
throw "Set intersection requires two arguments: " + Expr->getAsString();
RecSet S1, S2;
@@ -63,16 +63,16 @@ struct AndOp : public SetTheory::Operator {
// SetIntBinOp - Abstract base class for (Op S, N) operators.
struct SetIntBinOp : public SetTheory::Operator {
- virtual void apply2(SetTheory &ST, const DagInit *Expr,
+ virtual void apply2(SetTheory &ST, DagInit *Expr,
RecSet &Set, int64_t N,
RecSet &Elts) =0;
- void apply(SetTheory &ST, const DagInit *Expr, RecSet &Elts) {
+ void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) {
if (Expr->arg_size() != 2)
throw "Operator requires (Op Set, Int) arguments: " + Expr->getAsString();
RecSet Set;
ST.evaluate(Expr->arg_begin()[0], Set);
- const IntInit *II = dynamic_cast<const IntInit*>(Expr->arg_begin()[1]);
+ IntInit *II = dynamic_cast<IntInit*>(Expr->arg_begin()[1]);
if (!II)
throw "Second argument must be an integer: " + Expr->getAsString();
apply2(ST, Expr, Set, II->getValue(), Elts);
@@ -81,7 +81,7 @@ struct SetIntBinOp : public SetTheory::Operator {
// (shl S, N) Shift left, remove the first N elements.
struct ShlOp : public SetIntBinOp {
- void apply2(SetTheory &ST, const DagInit *Expr,
+ void apply2(SetTheory &ST, DagInit *Expr,
RecSet &Set, int64_t N,
RecSet &Elts) {
if (N < 0)
@@ -93,7 +93,7 @@ struct ShlOp : public SetIntBinOp {
// (trunc S, N) Truncate after the first N elements.
struct TruncOp : public SetIntBinOp {
- void apply2(SetTheory &ST, const DagInit *Expr,
+ void apply2(SetTheory &ST, DagInit *Expr,
RecSet &Set, int64_t N,
RecSet &Elts) {
if (N < 0)
@@ -110,7 +110,7 @@ struct RotOp : public SetIntBinOp {
RotOp(bool Rev) : Reverse(Rev) {}
- void apply2(SetTheory &ST, const DagInit *Expr,
+ void apply2(SetTheory &ST, DagInit *Expr,
RecSet &Set, int64_t N,
RecSet &Elts) {
if (Reverse)
@@ -129,7 +129,7 @@ struct RotOp : public SetIntBinOp {
// (decimate S, N) Pick every N'th element of S.
struct DecimateOp : public SetIntBinOp {
- void apply2(SetTheory &ST, const DagInit *Expr,
+ void apply2(SetTheory &ST, DagInit *Expr,
RecSet &Set, int64_t N,
RecSet &Elts) {
if (N <= 0)
@@ -141,26 +141,25 @@ struct DecimateOp : public SetIntBinOp {
// (sequence "Format", From, To) Generate a sequence of records by name.
struct SequenceOp : public SetTheory::Operator {
- void apply(SetTheory &ST, const DagInit *Expr, RecSet &Elts) {
+ void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) {
if (Expr->arg_size() != 3)
throw "Bad args to (sequence \"Format\", From, To): " +
Expr->getAsString();
std::string Format;
- if (const StringInit *SI =
- dynamic_cast<const StringInit*>(Expr->arg_begin()[0]))
+ if (StringInit *SI = dynamic_cast<StringInit*>(Expr->arg_begin()[0]))
Format = SI->getValue();
else
throw "Format must be a string: " + Expr->getAsString();
int64_t From, To;
- if (const IntInit *II = dynamic_cast<const IntInit*>(Expr->arg_begin()[1]))
+ if (IntInit *II = dynamic_cast<IntInit*>(Expr->arg_begin()[1]))
From = II->getValue();
else
throw "From must be an integer: " + Expr->getAsString();
if (From < 0 || From >= (1 << 30))
throw "From out of range";
- if (const IntInit *II = dynamic_cast<const IntInit*>(Expr->arg_begin()[2]))
+ if (IntInit *II = dynamic_cast<IntInit*>(Expr->arg_begin()[2]))
To = II->getValue();
else
throw "From must be an integer: " + Expr->getAsString();
@@ -168,7 +167,7 @@ struct SequenceOp : public SetTheory::Operator {
throw "To out of range";
RecordKeeper &Records =
- dynamic_cast<const DefInit&>(*Expr->getOperator()).getDef()->getRecords();
+ dynamic_cast<DefInit&>(*Expr->getOperator()).getDef()->getRecords();
int Step = From <= To ? 1 : -1;
for (To += Step; From != To; From += Step) {
@@ -223,9 +222,9 @@ void SetTheory::addFieldExpander(StringRef ClassName, StringRef FieldName) {
addExpander(ClassName, new FieldExpander(FieldName));
}
-void SetTheory::evaluate(const Init *Expr, RecSet &Elts) {
+void SetTheory::evaluate(Init *Expr, RecSet &Elts) {
// A def in a list can be a just an element, or it may expand.
- if (const DefInit *Def = dynamic_cast<const DefInit*>(Expr)) {
+ if (DefInit *Def = dynamic_cast<DefInit*>(Expr)) {
if (const RecVec *Result = expand(Def->getDef()))
return Elts.insert(Result->begin(), Result->end());
Elts.insert(Def->getDef());
@@ -233,14 +232,14 @@ void SetTheory::evaluate(const Init *Expr, RecSet &Elts) {
}
// Lists simply expand.
- if (const ListInit *LI = dynamic_cast<const ListInit*>(Expr))
+ if (ListInit *LI = dynamic_cast<ListInit*>(Expr))
return evaluate(LI->begin(), LI->end(), Elts);
// Anything else must be a DAG.
- const DagInit *DagExpr = dynamic_cast<const DagInit*>(Expr);
+ DagInit *DagExpr = dynamic_cast<DagInit*>(Expr);
if (!DagExpr)
throw "Invalid set element: " + Expr->getAsString();
- const DefInit *OpInit = dynamic_cast<const DefInit*>(DagExpr->getOperator());
+ DefInit *OpInit = dynamic_cast<DefInit*>(DagExpr->getOperator());
if (!OpInit)
throw "Bad set expression: " + Expr->getAsString();
Operator *Op = Operators.lookup(OpInit->getDef()->getName());