OpenCores
URL https://opencores.org/ocsvn/sc2v/sc2v/trunk

Subversion Repositories sc2v

[/] [sc2v/] [tags/] [arelease/] [src/] [sc2v_step2.y] - Blame information for rev 39

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jcastillo
/* -----------------------------------------------------------------------------
2
 *
3
 *  SystemC to Verilog Translator v0.1
4
 *  Provided by OpenSoc Design
5
 *
6
 *  www.opensocdesign.com
7
 *
8
 * -----------------------------------------------------------------------------
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Library General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program; if not, write to the Free Software
21
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
 */
23
 
24
%{
25
#include 
26
#include 
27
 
28
#include "list.h"
29
 
30
 
31
/*Global var to read from file_writes.sc2v*/
32
WritesList *writeslist;
33
 
34
/*Global var to store ports*/
35
PortList *portlist;
36
 
37
/* Global var to store signals*/
38
SignalsList *signalslist;
39
 
40
/* Global var to store sensitivity list*/
41
SensibilityList *sensibilitylist;
42
 
43
/* Global var to store instantiated modules*/
44
InstancesList *instanceslist;
45
 
46
/* Global var to store process list*/
47
ProcessList *processlist;
48
 
49
 
50
/* Global var to store process module name*/
51
char *module_name;
52
int module_name_found = 0;
53
 
54
/* Global var to store last port type*/
55
char *lastportkind;
56
int lastportsize;
57
int activeport = 0;     // 1 -> reading port list
58
 
59
/* Global var to store last signal type*/
60
int lastsignalsize;
61
int signalactive = 0;
62
 
63
/* Global var to store last SC_METHOD found*/
64
char *active_method;
65
char *active_method_type;
66
int method_found;
67
 
68
/* Global var to store last sensitivity found*/
69
char *last_sensibility;
70
int sensibility_active = 0;
71
 
72
 
73
 
74
 
75
 
76
void yyerror(const char *str)
77
{
78
        fprintf(stderr,"error: %s\n",str);
79
}
80
 
81
int yywrap()
82
{
83
        return 1;
84
}
85
 
86
main()
87
{
88
        writeslist = (WritesList *)malloc(sizeof(WritesList));
89
        InitializeWritesList(writeslist);
90
        portlist = (PortList *)malloc(sizeof(PortList));
91
        InitializePortList(portlist);
92
        signalslist = (SignalsList *)malloc(sizeof(SignalsList));
93
        InitializeSignalsList(signalslist);
94
        sensibilitylist = (SensibilityList *)malloc(sizeof(SensibilityList));
95
        InitializeSensibilityList(sensibilitylist);
96
        instanceslist = (InstancesList *)malloc(sizeof(InstancesList));
97
        InitializeInstancesList(instanceslist);
98
        processlist = (ProcessList *)malloc(sizeof(ProcessList));
99
        InitializeProcessList(processlist);
100
 
101
 
102
        yyparse();
103
        printf("module %s(",module_name);
104
        EnumeratePorts(portlist);
105
        printf(");\n");
106
 
107
        ShowPortList(portlist);
108
        printf("\n");
109
        RegOutputs(portlist);
110
        printf("\n");
111
 
112
        ReadWritesFile(writeslist, (char *)"file_writes.sc2v");
113
 
114
        ShowSignalsList(signalslist, writeslist);
115
        printf("\n");
116
 
117
        ShowInstancedModules(instanceslist);
118
        printf("\n");
119
 
120
        ShowDefines((char *)"file_defines.sc2v");
121
 
122
        ShowProcessCode(processlist);
123
        printf("\n");
124
 
125
        printf("endmodule\n");
126
}
127
 
128
%}
129
 
130
%token NUMBER SC_MODULE WORD OPENPAR CLOSEPAR SC_IN SC_OUT SEMICOLON BOOL
131
%token MENOR MAYOR SC_INT SC_UINT SC_METHOD SENSITIVE_POS SENSITIVE_NEG SENSITIVE
132
%token SENSIBLE CLOSEKEY OPENKEY SEMICOLON COLON SC_SIGNAL ARROW EQUALS NEW QUOTE
133
%token SC_CTOR VOID ASTERISCO
134
 
135
%%
136
 
137
commands: /* empty */
138
        | commands command
139
        ;
140
 
141
 
142
command:
143
        module
144
        |
145
        in_bool
146
        |
147
        in_sc_int
148
        |
149
        in_sc_uint
150
        |
151
        out_bool
152
        |
153
        out_sc_int
154
        |
155
        out_sc_uint
156
        |
157
        sc_method
158
        |
159
        sensitive_pos
160
        |
161
        sensitive_neg
162
        |
163
        sensitive
164
        |
165
        sensible_word_colon
166
        |
167
        sensible_word_semicolon
168
        |
169
        closekey
170
        |
171
        word_semicolon
172
        |
173
        word_colon
174
        |
175
        signal_bool
176
        |
177
        signal_uint
178
        |
179
        signal_int
180
        |
181
        instantation
182
        |
183
        port_binding
184
        |
185
        sc_ctor
186
        |
187
        void
188
        |
189
        inst_decl
190
        |
191
        closekey_semicolon
192
        ;
193
 
194
module:
195
        SC_MODULE OPENPAR WORD CLOSEPAR OPENKEY
196
        {
197
                if(module_name_found)
198
                        {
199
                        fprintf(stderr,"error: two or more modules found in the file\n");
200
                        exit(1);
201
                        }
202
                else
203
                        {
204
                        module_name = (char *)malloc(256*sizeof(char));
205
                        strcpy(module_name, (char *)$3);
206
                        module_name_found = 1;
207
                        }
208
        }
209
        ;
210
 
211
in_sc_uint:
212
        SC_IN MENOR SC_UINT MENOR NUMBER MAYOR MAYOR
213
        {
214
                activeport = 1;
215
                lastportsize = $5;
216
                lastportkind = (char *)"input";
217
        }
218
        ;
219
 
220
in_sc_int:
221
        SC_IN MENOR SC_INT MENOR NUMBER MAYOR MAYOR
222
        {
223
                activeport = 1;
224
                lastportsize = $5;
225
                lastportkind = (char *)"input";
226
        }
227
        ;
228
 
229
 
230
in_bool:
231
        SC_IN MENOR BOOL MAYOR
232
        {
233
                activeport = 1;
234
                lastportsize = 0;
235
                lastportkind = (char *)"input";
236
        }
237
        ;
238
 
239
signal_bool:
240
                SC_SIGNAL MENOR BOOL MAYOR
241
                {
242
                        signalactive = 1;
243
                        lastsignalsize = 0;
244
                }
245
                ;
246
signal_uint:
247
                SC_SIGNAL MENOR SC_UINT MENOR NUMBER MAYOR MAYOR
248
                {
249
                        signalactive = 1;
250
                        lastsignalsize = $5;
251
                }
252
                ;
253
signal_int:
254
                SC_SIGNAL MENOR SC_INT MENOR NUMBER MAYOR MAYOR
255
                {
256
                        signalactive = 1;
257
                        lastsignalsize = $5;
258
                }
259
                ;
260
 
261
out_bool:
262
        SC_OUT MENOR BOOL MAYOR
263
        {
264
                activeport = 1;
265
                lastportsize = 0;
266
                lastportkind = (char *)"output";
267
        }
268
        ;
269
 
270
out_sc_uint:
271
        SC_OUT MENOR SC_UINT MENOR NUMBER MAYOR MAYOR
272
        {
273
                activeport = 1;
274
                lastportsize = $5;
275
                lastportkind = (char *)"output";
276
        }
277
        ;
278
 
279
out_sc_int:
280
        SC_OUT MENOR SC_INT MENOR NUMBER MAYOR MAYOR
281
        {
282
                activeport = 1;
283
                lastportsize = $5;
284
                lastportkind = (char *)"output";
285
        }
286
        ;
287
 
288
sc_method:
289
        SC_METHOD OPENPAR WORD CLOSEPAR SEMICOLON
290
        {
291
                if(method_found)
292
                        {
293
                        InsertProcess(processlist, active_method, sensibilitylist, active_method_type);
294
                        }
295
                active_method = (char *)$3;
296
                method_found = 1;
297
                /* New sensitivity list */
298
                sensibilitylist = (SensibilityList *)malloc(sizeof(SensibilityList));
299
                InitializeSensibilityList(sensibilitylist);
300
        }
301
        ;
302
 
303
sensitive_pos:
304
        SENSITIVE_POS
305
        {
306
                last_sensibility = (char *)"posedge";
307
                active_method_type = (char *)"seq"; //seq
308
                sensibility_active = 1;
309
        }
310
        ;
311
 
312
sensitive_neg:
313
        SENSITIVE_NEG
314
        {
315
                last_sensibility = (char *)"negedge";
316
                active_method_type = (char *)"seq"; //seq
317
                sensibility_active = 1;
318
        }
319
        ;
320
 
321
sensitive:
322
        SENSITIVE
323
        {
324
                last_sensibility = (char *)" ";
325
                active_method_type = (char *)"comb"; //comb
326
                sensibility_active = 1;
327
        }
328
        ;
329
sensible_word_colon:
330
        SENSIBLE WORD
331
        {
332
                InsertSensibility(sensibilitylist, (char *)$2, (char *)last_sensibility);
333
        }
334
        ;
335
 
336
sensible_word_semicolon:
337
        SENSIBLE WORD SEMICOLON
338
        {
339
                InsertSensibility(sensibilitylist, (char *)$2, (char *)last_sensibility);
340
                if(sensibility_active)
341
                        {
342
                        sensibility_active = 0;
343
                        }
344
        }
345
        ;
346
 
347
closekey:
348
        CLOSEKEY
349
        {
350
                if(method_found)
351
                        {
352
                        method_found = 0;
353
                        InsertProcess(processlist, active_method, sensibilitylist, active_method_type);
354
                        }
355
        }
356
        ;
357
word_semicolon:
358
        WORD SEMICOLON
359
        {
360
                        if(activeport)
361
                        {
362
                                InsertPort(portlist, (char *)$1, lastportkind, lastportsize);
363
                                activeport = 0;
364
                        }
365
                        else if(signalactive)
366
                        {
367
                                InsertSignal(signalslist, (char *)$1, lastsignalsize);
368
                                signalactive = 0;
369
                        }
370
        }
371
        ;
372
 
373
word_colon:
374
                WORD COLON
375
                {
376
                        if(activeport)
377
                        {
378
                                InsertPort(portlist, (char *)$1, lastportkind, lastportsize);
379
                        }
380
                        else if(signalactive)
381
                        {
382
                                InsertSignal(signalslist, (char *)$1, lastsignalsize);
383
                        }
384
                }
385
                ;
386
 
387
instantation:
388
                WORD EQUALS NEW WORD OPENPAR QUOTE WORD QUOTE CLOSEPAR SEMICOLON
389
                {
390
                        InsertInstance(instanceslist, (char *)$1, (char *)$4);
391
                }
392
                ;
393
 
394
port_binding:
395
                WORD ARROW WORD OPENPAR WORD CLOSEPAR SEMICOLON
396
                {
397
                        if(instanceslist->last == NULL)
398
                        {
399
                                fprintf(stderr,"error: no instances found\n");
400
                        }
401
                        else
402
                        {
403
                                InstanceNode *aux;
404
                                aux = instanceslist->first;
405
                                while(1)
406
                                {
407
                                        if(strcmp(aux->nameinstance, (char *)$1) == 0)
408
                                        {
409
                                                break;
410
                                        }
411
                                        else
412
                                        {
413
                                                if(aux->next == NULL)
414
                                                {
415
                                                        fprintf(stderr,"error: instance %s not found\n",$1);
416
                                                        exit(1);
417
                                                }
418
                                                else
419
                                                {
420
                                                        aux = aux->next;
421
                                                }
422
                                        }
423
                                }
424
                                InsertBind(aux->bindslist, (char *)$3, (char *)$5);
425
                        }
426
                }
427
                ;
428
 
429
sc_ctor:
430
                SC_CTOR OPENPAR WORD CLOSEPAR OPENKEY
431
                {
432
 
433
                }
434
                ;
435
 
436
void:
437
                VOID WORD OPENPAR CLOSEPAR SEMICOLON
438
                {
439
 
440
                }
441
                ;
442
 
443
inst_decl:
444
                WORD ASTERISCO WORD SEMICOLON
445
                {
446
 
447
                }
448
                ;
449
 
450
closekey_semicolon:     CLOSEKEY SEMICOLON
451
                {
452
 
453
                }
454
                ;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.