summaryrefslogtreecommitdiff
path: root/assembler/lex.l
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2006-08-22 10:15:33 -0700
committerDamien Lespiau <damien.lespiau@intel.com>2013-03-04 15:54:20 +0000
commit22a1063cc014437bee07bdaff2c38c2e843d12d2 (patch)
tree8d70cadb04b0fce33ab917e92198b080c89b8d55 /assembler/lex.l
parent7ee278f17613d07ee18070f83aca9f050a526a72 (diff)
Initial gen4asm code.
Diffstat (limited to 'assembler/lex.l')
-rw-r--r--assembler/lex.l94
1 files changed, 94 insertions, 0 deletions
diff --git a/assembler/lex.l b/assembler/lex.l
new file mode 100644
index 00000000..f835f377
--- /dev/null
+++ b/assembler/lex.l
@@ -0,0 +1,94 @@
+%option yylineno
+%{
+#include "gen4asm.h"
+#include "y.tab.h"
+%}
+%start IN_REG
+
+%%
+\/\/.*[\r\n] { } /* eat up single-line comments */
+
+"mov" { return MOV; }
+
+"mul" { return MUL; }
+"mac" { return MAC; }
+"mach" { return MACH; }
+"line" { return LINE; }
+"sad2" { return SAD2; }
+"sada2" { return SADA2; }
+"dp4" { return DP4; }
+"dph" { return DPH; }
+"dp3" { return DP3; }
+"dp2" { return DP2; }
+
+"add" { return ADD; }
+
+"send" { return SEND; }
+"mlen" { return MSGLEN; }
+"rlen" { return RETURNLEN; }
+"null" { return NULL_TOKEN; }
+"math" { return MATH; }
+"sampler" { return SAMPLER; }
+"gateway" { return GATEWAY; }
+"read" { return READ; }
+"write" { return WRITE; }
+"urb" { return URB; }
+"thread_spawner" { return THREAD_SPAWNER; }
+
+";" { return SEMICOLON; }
+"(" { return LPAREN; }
+")" { return RPAREN; }
+"<" { return LANGLE; }
+">" { return RANGLE; }
+"{" { return LCURLY; }
+"}" { return RCURLY; }
+"," { return COMMA; }
+"." { return DOT; }
+
+ /* XXX: this lexing of register files is shady */
+"m" { BEGIN(IN_REG); return MSGREGFILE; }
+[gr] { BEGIN(IN_REG); return GENREGFILE; }
+
+ /*
+ * Lexing of register types should probably require the ":" symbol specified
+ * in the BNF of the assembly, but our existing source didn't use that syntax.
+ */
+"UD" { BEGIN(INITIAL); return TYPE_UD; }
+"D" { BEGIN(INITIAL); return TYPE_D; }
+"UW" { BEGIN(INITIAL); return TYPE_UW; }
+"W" { BEGIN(INITIAL); return TYPE_W; }
+"UB" { BEGIN(INITIAL); return TYPE_UB; }
+"B" { BEGIN(INITIAL); return TYPE_B; }
+"F" { BEGIN(INITIAL); return TYPE_F; }
+
+"align1" { return ALIGN1; }
+
+[0-9]* {
+ yylval.integer = atoi(yytext);
+ return INTEGER;
+}
+
+<INITIAL>[-]?[0-9]+"."[0-9]+ {
+ yylval.number = strtod(yytext, NULL);
+ return NUMBER;
+}
+
+[ \t\n]+ { } /* eat up whitespace */
+
+. {
+ printf("parse error at line %d: unexpected \"%s\"\n",
+ yylineno, yytext);
+ exit(1);
+}
+%%
+
+char *
+lex_text(void)
+{
+ return yytext;
+}
+
+#ifndef yywrap
+yywrap() { return 1; }
+#endif
+