summaryrefslogtreecommitdiffstats
path: root/src/vhd2vl.l
blob: b4de189fd70c72e64fe351dc4eb338bba55f00af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
    vhd2vl v2.3
    VHDL to Verilog RTL translator
    Copyright (C) 2001 Vincenzo Liguori - Ocean Logic Pty Ltd - http://www.ocean-logic.com
    Modifications Copyright (C) 2006 Mark Gonzales - PMC Sierra Inc
    Modifications Copyright (C) 2008-2010 Larry Doolittle - LBNL

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

%option noinput
%option nounput

%{
#include <stdio.h>
#include <string.h>
#include "def.h"
#include "vhd2vl.tab.h"

extern int lineno;

extern int skipRem;

void getstring(unsigned skip);
void getbasedstring(unsigned skip);

%}
%%

[ \t] {;}

"--".*\n {
  lineno++;
  if (skipRem == 0) {
    /* sometimes comments should be dropped by lex -
     * e.g. in expressions - this makes the grammar much simpler
     */
    size_t l=strlen(yytext);
    yylval.txt=malloc(l+1);
    strcpy(yylval.txt, yytext);
    yylval.txt[0]='/';
    yylval.txt[1]='/';
    if(yylval.txt[l-2]=='\r') {
       yylval.txt[l-2]='\n';
       yylval.txt[l-1]='\0';
    }
    return REM;
  }
}
"library ".*\n {lineno++;}
"use ".*\n {lineno++;}

"\x0d\n" |
\n { lineno++;}

"entity" { return ENTITY; }
"is" { return IS; }
"port" { return PORT; }
"generic" { return GENERIC; }
"map" { return MAP; }
"in" { return IN; }
"out" { return OUT; }
"inout" { return INOUT; }
"time" |
"natural" |
"positive" |
"integer" { return INTEGER; }
"boolean" |
"std_logic" |
"std_ulogic" { return BIT; }
"signed" |
"unsigned" |
"std_logic_vector" |
"std_ulogic_vector" { return BITVECT; }
"real" { return REAL; }
"downto" { return DOWNTO; }
"to" { return TO; }
"type" {return TYPE; }
"end" { return END; }
"for" { return FOR; }
"loop" { return LOOP; }
"generate" { return GENERATE; }
"architecture" { return ARCHITECTURE; }
"component" { return COMPONENT; }
"of" { return OF; }
"array" {return ARRAY; }
"signal" { return SIGNAL; }
"begin" { return BEGN; }
"not" { return NOT; }
"when" { return WHEN; }
"exit" { return EXIT; }
"with" { return WITH; }
"select" { return SELECT; }
"others" { return OTHERS; }
"range" { return RANGE; }
"process" { return PROCESS; }
"variable" { return VARIABLE; }
"constant" { return CONSTANT; }
"null" { return NULLV; }
"open" { return OPEN; }
"if" { return IF; }
"then" { return THEN; }
"elsif" { return ELSIF; }
"else" { return ELSE; }
"while" { return WHILE; }
"case" { return CASE; }
"after" { return AFTER; }
"and" { return AND; }
"or" { return OR; }
"xor" { return XOR; }
"xnor" { return XNOR; }
"mod" { return MOD; }
"**" { return POW; }
"event" { return EVENT; }
"rising_edge" { return POSEDGE;}
"falling_edge" { return NEGEDGE;}
"resize" { return CONVFUNC_2;}
"to_unsigned" { return CONVFUNC_2;}
"to_integer" |
"conv_integer" { return CONVFUNC_1;}
"left" { return LEFT;}
"high" { return LEFT;}
"assert" {return ASSERT;}
"report" {return REPORT;}
"severity" {return SEVERITY;}
"failure" {return FAILURE;}
"error" {return ERROR;}
"warning" {return WARNING;}
"note" {return NOTE;}

\"[ \!#-~]*\" |
\'[01xz]\' { getstring(1); return STRING;}

#[0-9a-f]*# {
  getbasedstring(1); /* skip leading # */
  return BASED;
}

[a-zA-Z_$][a-zA-Z0-9_$.]* {
  yylval.txt=malloc(strlen(yytext)+1);
  strcpy(yylval.txt, yytext);
  return NAME;
}

[0-9]+ {
  sscanf(yytext, "%d", &yylval.n);
  return NATURAL;
}

[0-9]+e[0-9]+ |
[0-9]+\.[0-9]+e[0-9]+ {
  yylval.txt=malloc(strlen(yytext)+1);
  strcpy(yylval.txt, yytext);
  return SCIENTIFIC;
}

[0-9]+\.[0-9]+ {
  getstring(0);
  return FLOAT;
}

. { return yytext[0]; }

%%

void getstring(unsigned skip){
/* Gets a string excluding " or ' */
  unsigned i;
  for(i=skip; yytext[i]!='"' && yytext[i]!='\'' && yytext[i]!=0; i++);
  yytext[i]=0;
  yylval.txt=malloc(i+1);
  strcpy(yylval.txt, yytext+skip);
}

void getbasedstring(unsigned skip){
/* Gets a string excluding # */
  unsigned i;
  for(i=skip; yytext[i]!='#' && yytext[i]!=0; i++);
  yytext[i]=0;
  yylval.txt=malloc(i+1);
  strcpy(yylval.txt, yytext+skip);
}

void yyerror(char *s){
  fprintf(stderr,"%s at \"%s\" in line %d.\n\n",s,yytext,lineno);
}
OpenPOWER on IntegriCloud