Fix broken abc9.v test due to inout being 1'bx
[yosys.git] / frontends / ilang / ilang_lexer.l
1 /*
2 * yosys -- Yosys Open SYnthesis Suite
3 *
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 * ---
19 *
20 * A very simple and straightforward frontend for the RTLIL text
21 * representation (as generated by the 'ilang' backend).
22 *
23 */
24
25 %{
26
27 #ifdef __clang__
28 // bison generates code using the 'register' storage class specifier
29 #pragma clang diagnostic ignored "-Wdeprecated-register"
30 #endif
31
32 #include "frontends/ilang/ilang_frontend.h"
33 #include "ilang_parser.tab.hh"
34
35 USING_YOSYS_NAMESPACE
36
37 #define YY_INPUT(buf,result,max_size) \
38 result = readsome(*ILANG_FRONTEND::lexin, buf, max_size)
39
40 %}
41
42 %option yylineno
43 %option noyywrap
44 %option nounput
45 %option prefix="rtlil_frontend_ilang_yy"
46
47 %x STRING
48
49 %%
50
51 "autoidx" { return TOK_AUTOIDX; }
52 "module" { return TOK_MODULE; }
53 "attribute" { return TOK_ATTRIBUTE; }
54 "parameter" { return TOK_PARAMETER; }
55 "signed" { return TOK_SIGNED; }
56 "real" { return TOK_REAL; }
57 "wire" { return TOK_WIRE; }
58 "memory" { return TOK_MEMORY; }
59 "width" { return TOK_WIDTH; }
60 "upto" { return TOK_UPTO; }
61 "offset" { return TOK_OFFSET; }
62 "size" { return TOK_SIZE; }
63 "input" { return TOK_INPUT; }
64 "output" { return TOK_OUTPUT; }
65 "inout" { return TOK_INOUT; }
66 "cell" { return TOK_CELL; }
67 "connect" { return TOK_CONNECT; }
68 "switch" { return TOK_SWITCH; }
69 "case" { return TOK_CASE; }
70 "assign" { return TOK_ASSIGN; }
71 "sync" { return TOK_SYNC; }
72 "low" { return TOK_LOW; }
73 "high" { return TOK_HIGH; }
74 "posedge" { return TOK_POSEDGE; }
75 "negedge" { return TOK_NEGEDGE; }
76 "edge" { return TOK_EDGE; }
77 "always" { return TOK_ALWAYS; }
78 "global" { return TOK_GLOBAL; }
79 "init" { return TOK_INIT; }
80 "update" { return TOK_UPDATE; }
81 "process" { return TOK_PROCESS; }
82 "end" { return TOK_END; }
83
84 [a-z]+ { return TOK_INVALID; }
85
86 "\\"[^ \t\r\n]+ { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_ID; }
87 "$"[^ \t\r\n]+ { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_ID; }
88 "."[0-9]+ { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_ID; }
89
90 [0-9]+'[01xzm-]* { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_VALUE; }
91 -?[0-9]+ { rtlil_frontend_ilang_yylval.integer = atoi(yytext); return TOK_INT; }
92
93 \" { BEGIN(STRING); }
94 <STRING>\\. { yymore(); }
95 <STRING>\" {
96 BEGIN(0);
97 char *yystr = strdup(yytext);
98 yystr[strlen(yytext) - 1] = 0;
99 int i = 0, j = 0;
100 while (yystr[i]) {
101 if (yystr[i] == '\\' && yystr[i + 1]) {
102 i++;
103 if (yystr[i] == 'n')
104 yystr[i] = '\n';
105 else if (yystr[i] == 't')
106 yystr[i] = '\t';
107 else if ('0' <= yystr[i] && yystr[i] <= '7') {
108 yystr[i] = yystr[i] - '0';
109 if ('0' <= yystr[i + 1] && yystr[i + 1] <= '7') {
110 yystr[i + 1] = yystr[i] * 8 + yystr[i + 1] - '0';
111 i++;
112 }
113 if ('0' <= yystr[i + 1] && yystr[i + 1] <= '7') {
114 yystr[i + 1] = yystr[i] * 8 + yystr[i + 1] - '0';
115 i++;
116 }
117 }
118 }
119 yystr[j++] = yystr[i++];
120 }
121 yystr[j] = 0;
122 rtlil_frontend_ilang_yylval.string = yystr;
123 return TOK_STRING;
124 }
125 <STRING>. { yymore(); }
126
127 "#"[^\n]* /* ignore comments */
128 [ \t] /* ignore non-newline whitespaces */
129 [\r\n]+ { return TOK_EOL; }
130
131 . { return *yytext; }
132
133 %%
134
135 // this is a hack to avoid the 'yyinput defined but not used' error msgs
136 void *rtlil_frontend_ilang_avoid_input_warnings() {
137 return (void*)&yyinput;
138 }
139