freedreno: slurp in afuc
[mesa.git] / src / freedreno / afuc / lexer.l
1 /*
2 * Copyright (c) 2017 Rob Clark <robdclark@gmail.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 %{
25 #include <stdlib.h>
26 #include "parser.h"
27 #include "asm.h"
28
29 #define TOKEN(t) (yylval.tok = t)
30 extern YYSTYPE yylval;
31
32 %}
33
34 %option noyywrap
35
36 %%
37 "\n" yylineno++;
38 [ \t] ; /* ignore whitespace */
39 ";"[^\n]*"\n" yylineno++; /* ignore comments */
40 [1-9][0-9]* yylval.num = strtoul(yytext, NULL, 0); return T_INT;
41 "0x"[0-9a-fA-F]* yylval.num = strtoul(yytext, NULL, 0); return T_HEX;
42
43 "$"[0-9a-fA-F][0-9a-fA-F] yylval.num = parse_reg(yytext); return T_REGISTER;
44 "$"[a-zA-Z][a-zA-Z0-9]* yylval.num = parse_reg(yytext); return T_REGISTER;
45 "b"[0-9][0-9]* yylval.num = parse_bit(yytext); return T_BIT;
46 "@"[a-zA-Z_][a-zA-Z0-9_]* yylval.num = parse_control_reg(yytext); return T_CONTROL_REG;
47 "#"[a-zA-Z_][a-zA-Z0-9_]* yylval.str = strdup(yytext+1); return T_LABEL_REF; /* label reference */
48 [a-zA-Z_][a-zA-Z0-9_]*":" yylval.str = parse_label_decl(yytext); return T_LABEL_DECL; /* label declaration */
49 "["[0-9a-fA-F][0-9a-fA-F]*"]" yylval.num = parse_literal(yytext); return T_LITERAL;
50
51 /* instructions: */
52 "nop" return TOKEN(T_OP_NOP);
53 "add" return TOKEN(T_OP_ADD);
54 "addhi" return TOKEN(T_OP_ADDHI);
55 "sub" return TOKEN(T_OP_SUB);
56 "subhi" return TOKEN(T_OP_SUBHI);
57 "and" return TOKEN(T_OP_AND);
58 "or" return TOKEN(T_OP_OR);
59 "xor" return TOKEN(T_OP_XOR);
60 "not" return TOKEN(T_OP_NOT);
61 "shl" return TOKEN(T_OP_SHL);
62 "ushr" return TOKEN(T_OP_USHR);
63 "ishr" return TOKEN(T_OP_ISHR);
64 "rot" return TOKEN(T_OP_ROT);
65 "mul8" return TOKEN(T_OP_MUL8);
66 "min" return TOKEN(T_OP_MIN);
67 "max" return TOKEN(T_OP_MAX);
68 "cmp" return TOKEN(T_OP_CMP);
69 "msb" return TOKEN(T_OP_MSB);
70 "mov" return TOKEN(T_OP_MOV);
71 "cwrite" return TOKEN(T_OP_CWRITE);
72 "cread" return TOKEN(T_OP_CREAD);
73 "store" return TOKEN(T_OP_STORE);
74 "load" return TOKEN(T_OP_LOAD);
75 "brne" return TOKEN(T_OP_BRNE);
76 "breq" return TOKEN(T_OP_BREQ);
77 "ret" return TOKEN(T_OP_RET);
78 "call" return TOKEN(T_OP_CALL);
79 "jump" return TOKEN(T_OP_JUMP);
80 "waitin" return TOKEN(T_OP_WAITIN);
81 "preemptleave" return TOKEN(T_OP_PREEMPTLEAVE);
82 "<<" return TOKEN(T_LSHIFT);
83 "(rep)" return TOKEN(T_REP);
84
85 "," return ',';
86 "[" return '[';
87 "]" return ']';
88 "+" return '+';
89
90 . fprintf(stderr, "error at line %d: Unknown token: %s\n", yyget_lineno(), yytext); yyterminate();
91
92 %%