Add initial lexer and parser support for shifting values. Every use of this
authorChris Lattner <sabre@nondot.org>
Tue, 19 Apr 2005 01:11:03 +0000 (01:11 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 19 Apr 2005 01:11:03 +0000 (01:11 +0000)
will lead to it being rejected though.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21335 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/FileLexer.l
utils/TableGen/FileParser.y
utils/TableGen/Record.h

index 08daf2fc2e698f3d3f88f8b264d72d7296e06274..a43358799618e6347a162700439d129d1c27d920 100644 (file)
@@ -195,6 +195,11 @@ field          { return FIELD; }
 let            { return LET; }
 in             { return IN; }
 
+!sra           { return SRATOK; }
+!srl           { return SRLTOK; }
+!shl           { return SHLTOK; }
+
+
 {Identifier}   { Filelval.StrVal = new std::string(yytext, yytext+yyleng);
                  return ID; }
 ${Identifier}  { Filelval.StrVal = new std::string(yytext+1, yytext+yyleng);
index 8781049956b7a08704a2dfadc10d1f3ec85bee39..e7d50322ef4d4514817a64d13827f9309ea2954f 100644 (file)
@@ -189,6 +189,7 @@ using namespace llvm;
 };
 
 %token INT BIT STRING BITS LIST CODE DAG CLASS DEF FIELD LET IN
+%token SHLTOK SRATOK SRLTOK
 %token <IntVal>      INTVAL
 %token <StrVal>      ID VARNAME STRVAL CODEFRAGMENT
 
@@ -308,6 +309,24 @@ Value : INTVAL {
       exit(1);
     }
     delete $3;
+  } | SHLTOK '(' Value ',' Value ')' {
+    $$ = $3->getBinaryOp(Init::SHL, $5);
+    if ($$ == 0) {
+      err() << "Cannot shift values '" << *$3 << "' and '" << *$5 << "'!\n";
+      exit(1);
+    }
+  } | SRATOK '(' Value ',' Value ')' {
+    $$ = $3->getBinaryOp(Init::SRA, $5);
+    if ($$ == 0) {
+      err() << "Cannot shift values '" << *$3 << "' and '" << *$5 << "'!\n";
+      exit(1);
+    }
+  } | SRLTOK '(' Value ',' Value ')' {
+    $$ = $3->getBinaryOp(Init::SRL, $5);
+    if ($$ == 0) {
+      err() << "Cannot shift values '" << *$3 << "' and '" << *$5 << "'!\n";
+      exit(1);
+    }
   };
 
 OptVarName : /* empty */ {
index e2b9c0e6ef0b18ecbc9ad72c83e8dcee96a0114e..9c5166c0cc833f315b7eb8f5f38224a35e64c1ba 100644 (file)
@@ -463,6 +463,11 @@ struct Init {
   virtual Init *getFieldInit(Record &R, const std::string &FieldName) const {
     return 0;
   }
+  
+  enum BinaryOp { SHL, SRA, SRL };
+  virtual Init *getBinaryOp(BinaryOp Op, Init *RHS) {
+    return 0;
+  }
 
   /// resolveReferences - This method is used by classes that refer to other
   /// variables which may not be defined at the time they expression is formed.