[llvm-commits] CVS: llvm/utils/TableGen/FileLexer.l FileParser.y Record.h
Chris Lattner
lattner at cs.uiuc.edu
Wed Jul 30 17:17:05 PDT 2003
Changes in directory llvm/utils/TableGen:
FileLexer.l updated: 1.5 -> 1.6
FileParser.y updated: 1.14 -> 1.15
Record.h updated: 1.15 -> 1.16
---
Log message:
Add support for code fragments
---
Diffs of the changes:
Index: llvm/utils/TableGen/FileLexer.l
diff -u llvm/utils/TableGen/FileLexer.l:1.5 llvm/utils/TableGen/FileLexer.l:1.6
--- llvm/utils/TableGen/FileLexer.l:1.5 Wed Jul 30 16:47:42 2003
+++ llvm/utils/TableGen/FileLexer.l Wed Jul 30 17:15:58 2003
@@ -132,19 +132,21 @@
%}
-Comment \/\/.*
+Comment \/\/.*
-Identifier [a-zA-Z_][0-9a-zA-Z_]*
-Integer [-+]?[0-9]+|0x[0-9a-fA-F]+|0b[01]+
-StringVal \"[^"]*\"
-IncludeStr include[ \t\n]+\"[^"]*\"
+Identifier [a-zA-Z_][0-9a-zA-Z_]*
+Integer [-+]?[0-9]+|0x[0-9a-fA-F]+|0b[01]+
+CodeFragment \[\{([^}]+|\}[^\]])*\}\]
+StringVal \"[^"]*\"
+IncludeStr include[ \t\n]+\"[^"]*\"
%%
{Comment} { /* Ignore comments */ }
{IncludeStr} { HandleInclude(yytext); }
-
+{CodeFragment} { Filelval.StrVal = new std::string(yytext+2, yytext+yyleng-2);
+ return CODEFRAGMENT; }
int { return INT; }
bit { return BIT; }
Index: llvm/utils/TableGen/FileParser.y
diff -u llvm/utils/TableGen/FileParser.y:1.14 llvm/utils/TableGen/FileParser.y:1.15
--- llvm/utils/TableGen/FileParser.y:1.14 Wed Jul 30 16:47:42 2003
+++ llvm/utils/TableGen/FileParser.y Wed Jul 30 17:15:58 2003
@@ -155,7 +155,7 @@
%token INT BIT STRING BITS LIST CODE CLASS DEF FIELD SET IN
%token <IntVal> INTVAL
-%token <StrVal> ID STRVAL
+%token <StrVal> ID STRVAL CODEFRAGMENT
%type <Ty> Type
%type <RecPtr> DefList DefListNE
@@ -216,6 +216,9 @@
$$ = new IntInit($1);
} | STRVAL {
$$ = new StringInit(*$1);
+ delete $1;
+ } | CODEFRAGMENT {
+ $$ = new CodeInit(*$1);
delete $1;
} | '?' {
$$ = new UnsetInit();
Index: llvm/utils/TableGen/Record.h
diff -u llvm/utils/TableGen/Record.h:1.15 llvm/utils/TableGen/Record.h:1.16
--- llvm/utils/TableGen/Record.h:1.15 Wed Jul 30 16:47:42 2003
+++ llvm/utils/TableGen/Record.h Wed Jul 30 17:15:58 2003
@@ -18,6 +18,7 @@
class BitsInit;
class IntInit;
class StringInit;
+class CodeInit;
class ListInit;
class DefInit;
class TypedInit;
@@ -39,6 +40,7 @@
virtual Init *convertValue( IntInit *II) { return 0; }
virtual Init *convertValue(StringInit *SI) { return 0; }
virtual Init *convertValue( ListInit *LI) { return 0; }
+ virtual Init *convertValue( CodeInit *CI) { return 0; }
virtual Init *convertValue(VarBitInit *VB) { return 0; }
virtual Init *convertValue( DefInit *DI) { return 0; }
virtual Init *convertValue( TypedInit *TI) { return 0; }
@@ -135,6 +137,7 @@
///
struct CodeRecTy : public RecTy {
Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
+ Init *convertValue( CodeInit *CI) { return (Init*)CI; }
void print(std::ostream &OS) const { OS << "code"; }
};
@@ -319,6 +322,20 @@
}
virtual void print(std::ostream &OS) const { OS << "\"" << Value << "\""; }
+};
+
+/// CodeInit - "[{...}]" - Represent a code fragment.
+///
+class CodeInit : public Init {
+ std::string Value;
+public:
+ CodeInit(const std::string &V) : Value(V) {}
+
+ virtual Init *convertInitializerTo(RecTy *Ty) {
+ return Ty->convertValue(this);
+ }
+
+ virtual void print(std::ostream &OS) const { OS << "[{" << Value << "}]"; }
};
/// ListInit - [AL, AH, CL] - Represent a list of defs
More information about the llvm-commits
mailing list