llvm.org GIT mirror llvm / d23a41c
Add an addition operator to TableGen This adds an !add(a, b) operator to tablegen; this will be used to cleanup the PPC register definitions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173445 91177308-0d34-0410-b5e6-96231b3b80d8 Hal Finkel 6 years ago
7 changed file(s) with 26 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
9090 .. productionlist::
9191 BangOperator: one of
9292 :!eq !if !head !tail !con
93 :!shl !sra !srl
93 :!add !shl !sra !srl
9494 :!cast !empty !subst !foreach !strconcat
9595
9696 Syntax
929929 ///
930930 class BinOpInit : public OpInit {
931931 public:
932 enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, EQ };
932 enum BinaryOp { ADD, SHL, SRA, SRL, STRCONCAT, CONCAT, EQ };
933933 private:
934934 BinaryOp Opc;
935935 Init *LHS, *RHS;
934934
935935 break;
936936 }
937 case ADD:
937938 case SHL:
938939 case SRA:
939940 case SRL: {
944945 int64_t Result;
945946 switch (getOpcode()) {
946947 default: llvm_unreachable("Bad opcode!");
948 case ADD: Result = LHSv + RHSv; break;
947949 case SHL: Result = LHSv << RHSv; break;
948950 case SRA: Result = LHSv >> RHSv; break;
949951 case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
969971 std::string Result;
970972 switch (Opc) {
971973 case CONCAT: Result = "!con"; break;
974 case ADD: Result = "!add"; break;
972975 case SHL: Result = "!shl"; break;
973976 case SRA: Result = "!sra"; break;
974977 case SRL: Result = "!srl"; break;
461461 .Case("head", tgtok::XHead)
462462 .Case("tail", tgtok::XTail)
463463 .Case("con", tgtok::XConcat)
464 .Case("add", tgtok::XADD)
464465 .Case("shl", tgtok::XSHL)
465466 .Case("sra", tgtok::XSRA)
466467 .Case("srl", tgtok::XSRL)
4545 MultiClass, String,
4646
4747 // !keywords.
48 XConcat, XSRA, XSRL, XSHL, XStrConcat, XCast, XSubst,
48 XConcat, XADD, XSRA, XSRL, XSHL, XStrConcat, XCast, XSubst,
4949 XForEach, XHead, XTail, XEmpty, XIf, XEq,
5050
5151 // Integer value.
911911 }
912912
913913 case tgtok::XConcat:
914 case tgtok::XADD:
914915 case tgtok::XSRA:
915916 case tgtok::XSRL:
916917 case tgtok::XSHL:
926927 switch (OpTok) {
927928 default: llvm_unreachable("Unhandled code!");
928929 case tgtok::XConcat: Code = BinOpInit::CONCAT;Type = DagRecTy::get(); break;
930 case tgtok::XADD: Code = BinOpInit::ADD; Type = IntRecTy::get(); break;
929931 case tgtok::XSRA: Code = BinOpInit::SRA; Type = IntRecTy::get(); break;
930932 case tgtok::XSRL: Code = BinOpInit::SRL; Type = IntRecTy::get(); break;
931933 case tgtok::XSHL: Code = BinOpInit::SHL; Type = IntRecTy::get(); break;
11411143 /// SimpleValue ::= '[' ValueList ']'
11421144 /// SimpleValue ::= '(' IDValue DagArgList ')'
11431145 /// SimpleValue ::= CONCATTOK '(' Value ',' Value ')'
1146 /// SimpleValue ::= ADDTOK '(' Value ',' Value ')'
11441147 /// SimpleValue ::= SHLTOK '(' Value ',' Value ')'
11451148 /// SimpleValue ::= SRATOK '(' Value ',' Value ')'
11461149 /// SimpleValue ::= SRLTOK '(' Value ',' Value ')'
13961399 case tgtok::XEmpty:
13971400 case tgtok::XCast: // Value ::= !unop '(' Value ')'
13981401 case tgtok::XConcat:
1402 case tgtok::XADD:
13991403 case tgtok::XSRA:
14001404 case tgtok::XSRL:
14011405 case tgtok::XSHL:
0 // RUN: llvm-tblgen %s | FileCheck %s
1
2 class Int {
3 int Value = value;
4 }
5
6 def v1024 : Int<1024>;
7 // CHECK: Value = 1024
8
9 def v1025 : Int;
10 // CHECK: Value = 1025
11
12 def v2048 : Int;
13 // CHECK: Value = 2048
14