2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
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.
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.
20 * A very simple and straightforward frontend for the RTLIL text
21 * representation (as generated by the 'ilang' backend).
28 // bison generates code using the 'register' storage class specifier
29 #pragma clang diagnostic ignored "-Wdeprecated-register"
32 #include "frontends/ilang/ilang_frontend.h"
33 #include "ilang_parser.tab.hh"
37 #define YY_INPUT(buf,result,max_size) \
38 result = readsome(*ILANG_FRONTEND::lexin, buf, max_size)
45 %option prefix="rtlil_frontend_ilang_yy"
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; }
84 [a-z]+ { return TOK_INVALID; }
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; }
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; }
94 <STRING>\\. { yymore(); }
97 char *yystr = strdup(yytext);
98 yystr[strlen(yytext) - 1] = 0;
101 if (yystr[i] == '\\' && yystr[i + 1]) {
105 else if (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';
113 if ('0' <= yystr[i + 1] && yystr[i + 1] <= '7') {
114 yystr[i + 1] = yystr[i] * 8 + yystr[i + 1] - '0';
119 yystr[j++] = yystr[i++];
122 rtlil_frontend_ilang_yylval.string = yystr;
125 <STRING>. { yymore(); }
127 "#"[^\n]* /* ignore comments */
128 [ \t] /* ignore non-newline whitespaces */
129 [\r\n]+ { return TOK_EOL; }
131 . { return *yytext; }
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;