X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=utils%2FTableGen%2FSetTheory.cpp;h=ad3d7c7e189341854ae27d44166e055f3d6d927b;hb=75a8b23e1000f3db9f85f3582353f2af448f4622;hp=0dd9853843fee39006e4c09e451639f0437a37b2;hpb=61131ab15fd593a2e295d79fe2714e7bc21f2ec8;p=oota-llvm.git diff --git a/utils/TableGen/SetTheory.cpp b/utils/TableGen/SetTheory.cpp index 0dd9853843f..ad3d7c7e189 100644 --- a/utils/TableGen/SetTheory.cpp +++ b/utils/TableGen/SetTheory.cpp @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #include "SetTheory.h" +#include "llvm/Support/Format.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" -#include "llvm/Support/Format.h" using namespace llvm; @@ -27,14 +27,16 @@ typedef SetTheory::RecVec RecVec; // (add a, b, ...) Evaluate and union all arguments. struct AddOp : public SetTheory::Operator { - void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, ArrayRef Loc) { + virtual void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, + ArrayRef Loc) { ST.evaluate(Expr->arg_begin(), Expr->arg_end(), Elts, Loc); } }; // (sub Add, Sub, ...) Set difference. struct SubOp : public SetTheory::Operator { - void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, ArrayRef Loc) { + virtual void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, + ArrayRef Loc) { if (Expr->arg_size() < 2) PrintFatalError(Loc, "Set difference needs at least two arguments: " + Expr->getAsString()); @@ -49,7 +51,8 @@ struct SubOp : public SetTheory::Operator { // (and S1, S2) Set intersection. struct AndOp : public SetTheory::Operator { - void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, ArrayRef Loc) { + virtual void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, + ArrayRef Loc) { if (Expr->arg_size() != 2) PrintFatalError(Loc, "Set intersection requires two arguments: " + Expr->getAsString()); @@ -68,7 +71,8 @@ struct SetIntBinOp : public SetTheory::Operator { RecSet &Set, int64_t N, RecSet &Elts, ArrayRef Loc) =0; - void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, ArrayRef Loc) { + virtual void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, + ArrayRef Loc) { if (Expr->arg_size() != 2) PrintFatalError(Loc, "Operator requires (Op Set, Int) arguments: " + Expr->getAsString()); @@ -84,9 +88,9 @@ struct SetIntBinOp : public SetTheory::Operator { // (shl S, N) Shift left, remove the first N elements. struct ShlOp : public SetIntBinOp { - void apply2(SetTheory &ST, DagInit *Expr, - RecSet &Set, int64_t N, - RecSet &Elts, ArrayRef Loc) { + virtual void apply2(SetTheory &ST, DagInit *Expr, + RecSet &Set, int64_t N, + RecSet &Elts, ArrayRef Loc) { if (N < 0) PrintFatalError(Loc, "Positive shift required: " + Expr->getAsString()); @@ -97,9 +101,9 @@ struct ShlOp : public SetIntBinOp { // (trunc S, N) Truncate after the first N elements. struct TruncOp : public SetIntBinOp { - void apply2(SetTheory &ST, DagInit *Expr, - RecSet &Set, int64_t N, - RecSet &Elts, ArrayRef Loc) { + virtual void apply2(SetTheory &ST, DagInit *Expr, + RecSet &Set, int64_t N, + RecSet &Elts, ArrayRef Loc) { if (N < 0) PrintFatalError(Loc, "Positive length required: " + Expr->getAsString()); @@ -115,9 +119,9 @@ struct RotOp : public SetIntBinOp { RotOp(bool Rev) : Reverse(Rev) {} - void apply2(SetTheory &ST, DagInit *Expr, - RecSet &Set, int64_t N, - RecSet &Elts, ArrayRef Loc) { + virtual void apply2(SetTheory &ST, DagInit *Expr, + RecSet &Set, int64_t N, + RecSet &Elts, ArrayRef Loc) { if (Reverse) N = -N; // N > 0 -> rotate left, N < 0 -> rotate right. @@ -134,9 +138,9 @@ struct RotOp : public SetIntBinOp { // (decimate S, N) Pick every N'th element of S. struct DecimateOp : public SetIntBinOp { - void apply2(SetTheory &ST, DagInit *Expr, - RecSet &Set, int64_t N, - RecSet &Elts, ArrayRef Loc) { + virtual void apply2(SetTheory &ST, DagInit *Expr, + RecSet &Set, int64_t N, + RecSet &Elts, ArrayRef Loc) { if (N <= 0) PrintFatalError(Loc, "Positive stride required: " + Expr->getAsString()); @@ -147,7 +151,8 @@ struct DecimateOp : public SetIntBinOp { // (interleave S1, S2, ...) Interleave elements of the arguments. struct InterleaveOp : public SetTheory::Operator { - void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, ArrayRef Loc) { + virtual void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, + ArrayRef Loc) { // Evaluate the arguments individually. SmallVector Args(Expr->getNumArgs()); unsigned MaxSize = 0; @@ -165,7 +170,8 @@ 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, ArrayRef Loc) { + virtual void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, + ArrayRef Loc) { int Step = 1; if (Expr->arg_size() > 4) PrintFatalError(Loc, "Bad args to (sequence \"Format\", From, To): " + @@ -232,15 +238,16 @@ struct FieldExpander : public SetTheory::Expander { FieldExpander(StringRef fn) : FieldName(fn) {} - void expand(SetTheory &ST, Record *Def, RecSet &Elts) { + virtual void expand(SetTheory &ST, Record *Def, RecSet &Elts) { ST.evaluate(Def->getValueInit(FieldName), Elts, Def->getLoc()); } }; } // end anonymous namespace -void SetTheory::Operator::anchor() { } +// Pin the vtables to this file. +void SetTheory::Operator::anchor() {} +void SetTheory::Expander::anchor() {} -void SetTheory::Expander::anchor() { } SetTheory::SetTheory() { addOperator("add", new AddOp);