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"
33 #include "frontends/ilang/ilang_frontend.h"
34 #include "ilang_parser.tab.hh"
38 #define YY_INPUT(buf,result,max_size) \
39 result = readsome(*ILANG_FRONTEND::lexin, buf, max_size)
46 %option prefix="rtlil_frontend_ilang_yy"
52 "autoidx" { return TOK_AUTOIDX; }
53 "module" { return TOK_MODULE; }
54 "attribute" { return TOK_ATTRIBUTE; }
55 "parameter" { return TOK_PARAMETER; }
56 "signed" { return TOK_SIGNED; }
57 "real" { return TOK_REAL; }
58 "wire" { return TOK_WIRE; }
59 "memory" { return TOK_MEMORY; }
60 "width" { return TOK_WIDTH; }
61 "upto" { return TOK_UPTO; }
62 "offset" { return TOK_OFFSET; }
63 "size" { return TOK_SIZE; }
64 "input" { return TOK_INPUT; }
65 "output" { return TOK_OUTPUT; }
66 "inout" { return TOK_INOUT; }
67 "cell" { return TOK_CELL; }
68 "connect" { return TOK_CONNECT; }
69 "switch" { return TOK_SWITCH; }
70 "case" { return TOK_CASE; }
71 "assign" { return TOK_ASSIGN; }
72 "sync" { return TOK_SYNC; }
73 "low" { return TOK_LOW; }
74 "high" { return TOK_HIGH; }
75 "posedge" { return TOK_POSEDGE; }
76 "negedge" { return TOK_NEGEDGE; }
77 "edge" { return TOK_EDGE; }
78 "always" { return TOK_ALWAYS; }
79 "global" { return TOK_GLOBAL; }
80 "init" { return TOK_INIT; }
81 "update" { return TOK_UPDATE; }
82 "process" { return TOK_PROCESS; }
83 "end" { return TOK_END; }
85 [a-z]+ { return TOK_INVALID; }
87 "\\"[^ \t\r\n]+ { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_ID; }
88 "$"[^ \t\r\n]+ { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_ID; }
89 "."[0-9]+ { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_ID; }
91 [0-9]+'[01xzm-]* { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_VALUE; }
94 long value = strtol(yytext, &end, 10);
95 if (end != yytext + strlen(yytext))
96 return TOK_INVALID; // literal out of range of long
97 if (value < INT_MIN || value > INT_MAX)
98 return TOK_INVALID; // literal out of range of int (relevant mostly for LP64 platforms)
99 rtlil_frontend_ilang_yylval.integer = value;
103 \" { BEGIN(STRING); }
104 <STRING>\\. { yymore(); }
107 char *yystr = strdup(yytext);
108 yystr[strlen(yytext) - 1] = 0;
111 if (yystr[i] == '\\' && yystr[i + 1]) {
115 else if (yystr[i] == 't')
117 else if ('0' <= yystr[i] && yystr[i] <= '7') {
118 yystr[i] = yystr[i] - '0';
119 if ('0' <= yystr[i + 1] && yystr[i + 1] <= '7') {
120 yystr[i + 1] = yystr[i] * 8 + yystr[i + 1] - '0';
123 if ('0' <= yystr[i + 1] && yystr[i + 1] <= '7') {
124 yystr[i + 1] = yystr[i] * 8 + yystr[i + 1] - '0';
129 yystr[j++] = yystr[i++];
132 rtlil_frontend_ilang_yylval.string = yystr;
135 <STRING>. { yymore(); }
137 "#"[^\n]* /* ignore comments */
138 [ \t] /* ignore non-newline whitespaces */
139 [\r\n]+ { return TOK_EOL; }
141 . { return *yytext; }
145 // this is a hack to avoid the 'yyinput defined but not used' error msgs
146 void *rtlil_frontend_ilang_avoid_input_warnings() {
147 return (void*)&yyinput;