From 22a1063cc014437bee07bdaff2c38c2e843d12d2 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 22 Aug 2006 10:15:33 -0700 Subject: Initial gen4asm code. --- assembler/lex.l | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 assembler/lex.l (limited to 'assembler/lex.l') 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; +} + +[-]?[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 + -- cgit v1.2.3