Merge pull request #573 from cr1901/msys-64
[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.h"
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 "wire" { return TOK_WIRE; }
57 "memory" { return TOK_MEMORY; }
58 "width" { return TOK_WIDTH; }
59 "upto" { return TOK_UPTO; }
60 "offset" { return TOK_OFFSET; }
61 "size" { return TOK_SIZE; }
62 "input" { return TOK_INPUT; }
63 "output" { return TOK_OUTPUT; }
64 "inout" { return TOK_INOUT; }
65 "cell" { return TOK_CELL; }
66 "connect" { return TOK_CONNECT; }
67 "switch" { return TOK_SWITCH; }
68 "case" { return TOK_CASE; }
69 "assign" { return TOK_ASSIGN; }
70 "sync" { return TOK_SYNC; }
71 "low" { return TOK_LOW; }
72 "high" { return TOK_HIGH; }
73 "posedge" { return TOK_POSEDGE; }
74 "negedge" { return TOK_NEGEDGE; }
75 "edge" { return TOK_EDGE; }
76 "always" { return TOK_ALWAYS; }
77 "global" { return TOK_GLOBAL; }
78 "init" { return TOK_INIT; }
79 "update" { return TOK_UPDATE; }
80 "process" { return TOK_PROCESS; }
81 "end" { return TOK_END; }
82
83 [a-z]+ { return TOK_INVALID; }
84
85 "\\"[^ \t\r\n]+ { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_ID; }
86 "$"[^ \t\r\n]+ { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_ID; }
87 "."[0-9]+ { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_ID; }
88
89 [0-9]+'[01xzm-]* { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_VALUE; }
90 -?[0-9]+ { rtlil_frontend_ilang_yylval.integer = atoi(yytext); return TOK_INT; }
91
92 \" { BEGIN(STRING); }
93 <STRING>\\. { yymore(); }
94 <STRING>\" {
95 BEGIN(0);
96 char *yystr = strdup(yytext);
97 yystr[strlen(yytext) - 1] = 0;
98 int i = 0, j = 0;
99 while (yystr[i]) {
100 if (yystr[i] == '\\' && yystr[i + 1]) {
101 i++;
102 if (yystr[i] == 'n')
103 yystr[i] = '\n';
104 else if (yystr[i] == 't')
105 yystr[i] = '\t';
106 else if ('0' <= yystr[i] && yystr[i] <= '7') {
107 yystr[i] = yystr[i] - '0';
108 if ('0' <= yystr[i + 1] && yystr[i + 1] <= '7') {
109 yystr[i + 1] = yystr[i] * 8 + yystr[i + 1] - '0';
110 i++;
111 }
112 if ('0' <= yystr[i + 1] && yystr[i + 1] <= '7') {
113 yystr[i + 1] = yystr[i] * 8 + yystr[i + 1] - '0';
114 i++;
115 }
116 }
117 }
118 yystr[j++] = yystr[i++];
119 }
120 yystr[j] = 0;
121 rtlil_frontend_ilang_yylval.string = yystr;
122 return TOK_STRING;
123 }
124 <STRING>. { yymore(); }
125
126 "#"[^\n]* /* ignore comments */
127 [ \t] /* ignore non-newline whitespaces */
128 [\r\n]+ { return TOK_EOL; }
129
130 . { return *yytext; }
131
132 %%
133
134 // this is a hack to avoid the 'yyinput defined but not used' error msgs
135 void *rtlil_frontend_ilang_avoid_input_warnings() {
136 return (void*)&yyinput;
137 }
138