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

Subversion Repositories sc2v

[/] [sc2v/] [tags/] [arelease/] [src/] [list.c] - Blame information for rev 3

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
#include <stdlib.h>
25
#include <stdio.h>
26
 
27
#include "list.h"
28
 
29
void InitializeDefinesList(DefinesList *list)
30
{
31
        DefineNode *first;
32
        first = (DefineNode *)malloc(sizeof(DefineNode));
33
        list->first = first;
34
        list->last = NULL;
35
}
36
 
37
void InsertDefine(DefinesList *list, char *name)
38
{
39
        if(list->last == NULL)  //list empty
40
        {
41
                list->first->name = (char *)malloc(256*sizeof(char));
42
                strcpy(list->first->name ,name);
43
                list->first->next = NULL;
44
                list->last = list->first;
45
        }
46
        else
47
        {
48
                DefineNode *nuevo;
49
                nuevo = (DefineNode *)malloc(sizeof(DefineNode));
50
                nuevo->name = (char *)malloc(256*sizeof(char));
51
                strcpy(nuevo->name ,name);
52
                nuevo->next = NULL;
53
                list->last->next = nuevo;
54
                list->last = nuevo;
55
        }
56
}
57
 
58
int IsDefine(DefinesList *list, char *name)
59
{
60
        DefineNode *auxwrite = list->first;
61
 
62
        if(list->last == NULL)
63
        {
64
                return 0;
65
        }
66
        else
67
        {
68
                while(1)
69
                {
70
                        if((strcmp(name, auxwrite->name)==0))
71
                        {
72
                                return 1;
73
                        }
74
                        else if(auxwrite->next != NULL)
75
                        {
76
                                auxwrite = auxwrite->next;
77
                        }
78
                        else
79
                        {
80
                                break;
81
                        }
82
                }
83
        }
84
        return 0;
85
}
86
 
87
void ShowDefines(char *filedefines)
88
{
89
        int readok;
90
        char *auxchar;
91
        FILE *file;
92
 
93
        file = fopen(filedefines,(char *)"r");
94
 
95
        while(1)
96
                                {
97
                                readok = fread((void *)&auxchar, sizeof(char), 1, file);
98
                                if(readok)
99
                                        printf("%c",auxchar);
100
                                else
101
                                   break;
102
                        }
103
}
104
 
105
void InitializeWritesList(WritesList *list)
106
{
107
        WriteNode *first;
108
        first = (WriteNode *)malloc(sizeof(WriteNode));
109
        list->first = first;
110
        list->last = NULL;
111
}
112
 
113
void InsertWrite(WritesList *list, char *name)
114
{
115
        if(list->last == NULL)  //list empty
116
        {
117
                list->first->name = (char *)malloc(256*sizeof(char));
118
                strcpy(list->first->name ,name);
119
                list->first->next = NULL;
120
                list->last = list->first;
121
        }
122
        else
123
        {
124
                WriteNode *nuevo;
125
                nuevo = (WriteNode *)malloc(sizeof(WriteNode));
126
                nuevo->name = (char *)malloc(256*sizeof(char));
127
                strcpy(nuevo->name ,name);
128
                nuevo->next = NULL;
129
                list->last->next = nuevo;
130
                list->last = nuevo;
131
        }
132
}
133
 
134
int IsWrite(WritesList *list, char *name)
135
{
136
        WriteNode *auxwrite = list->first;
137
 
138
        if(list->last == NULL)
139
        {
140
                return 0;
141
        }
142
        else
143
        {
144
                while(1)
145
                {
146
                        if((strcmp(name, auxwrite->name)==0))
147
                        {
148
                                return 1;
149
                        }
150
                        else if(auxwrite->next != NULL)
151
                        {
152
                                auxwrite = auxwrite->next;
153
                        }
154
                        else
155
                        {
156
                                break;
157
                        }
158
                }
159
        }
160
        return 0;
161
}
162
 
163
void ShowWritesList(WritesList *list)
164
{
165
        if(list->last != NULL) //list not empty
166
        {
167
                WriteNode *aux = list->first;
168
                while(1)
169
                {
170
                        printf("%s\n",aux->name);
171
                        if(aux->next==NULL)
172
                        {
173
                                break;
174
                        }
175
                        aux = aux->next;
176
                }
177
        }
178
}
179
 
180
void ReadWritesFile(WritesList *list, char *name)
181
{
182
        char *leido;
183
        int ret;
184
        FILE *file_writes;
185
        file_writes = fopen(name, (char *)"r");
186
 
187
        leido = (char *)malloc(256*sizeof(char));
188
 
189
        while(1)
190
        {
191
                ret = fscanf(file_writes,"%s",leido);
192
                if(ret == EOF)
193
                        break;
194
                InsertWrite(list, leido);
195
        }
196
 
197
 
198
}
199
 
200
void InitializeRegsList(RegsList *list)
201
{
202
        RegNode *first;
203
        first = (RegNode *)malloc(sizeof(RegNode));
204
        list->first = first;
205
        list->last = NULL;
206
}
207
 
208
void InsertReg(RegsList *list, char *name, char *name2)
209
{
210
        if(list->last == NULL)
211
        {
212
                list->first->name = (char *)malloc(256*sizeof(char));
213
                list->first->name2 = (char *)malloc(256*sizeof(char));
214
                strcpy(list->first->name ,name);
215
                strcpy(list->first->name2 ,name2);
216
                list->first->next = NULL;
217
                list->last = list->first;
218
        }
219
        else
220
        {
221
                RegNode *nuevo;
222
                nuevo = (RegNode *)malloc(sizeof(RegNode));
223
                nuevo->name = (char *)malloc(256*sizeof(char));
224
                nuevo->name2 = (char *)malloc(256*sizeof(char));
225
                strcpy(nuevo->name ,name);
226
                strcpy(nuevo->name2 ,name2);
227
                nuevo->next = NULL;
228
                list->last->next = nuevo;
229
                list->last = nuevo;
230
        }
231
}
232
 
233
/* Looks if a WORD of func.y file is a register of the process*/
234
char  *IsReg(RegsList *list, char *name)
235
{
236
        RegNode *auxreg = list->first;
237
 
238
        if(list->last == NULL)
239
        {
240
                return NULL;
241
        }
242
        else
243
        {
244
                while(1)
245
                {
246
                        if((strcmp(name, auxreg->name)==0))
247
                        {
248
                                return auxreg->name2;
249
                        }
250
                        else if(auxreg->next != NULL)
251
                        {
252
                                auxreg = auxreg->next;
253
                        }
254
                        else
255
                        {
256
                                break;
257
                        }
258
                }
259
        }
260
        return NULL;
261
}
262
 
263
void ShowRegsList(RegsList *list)
264
{
265
        if(list->last != NULL)
266
        {
267
                RegNode *aux = list->first;
268
                while(1)
269
                {
270
                        printf("%s\t",aux->name);
271
                        printf("%s;\n",aux->name2);
272
                        if(aux->next==NULL)
273
                        {
274
                                break;
275
                        }
276
                        aux = aux->next;
277
                }
278
        }
279
}
280
 
281
void InitializePortList(PortList *list)
282
{
283
        PortNode *first;
284
        first = (PortNode *)malloc(sizeof(PortNode));
285
        list->first = first;
286
        list->last = NULL;
287
}
288
 
289
void InsertPort(PortList *list, char *name, char *tipo, int size)
290
{
291
        if(list->last == NULL)
292
        {
293
                list->first->name = name;
294
                list->first->tipo = tipo;
295
                list->first->size = size;
296
                list->first->next = NULL;
297
                list->last = list->first;
298
        }
299
        else
300
        {
301
                PortNode *nuevo;
302
                nuevo = (PortNode *)malloc(sizeof(PortNode));
303
                nuevo->name = name;
304
                nuevo->tipo = tipo;
305
                nuevo->size = size;
306
                nuevo->next = NULL;
307
                list->last->next = nuevo;
308
                list->last = nuevo;
309
        }
310
}
311
 
312
void ShowPortList(PortList *list)
313
{
314
        if(list->last != NULL)
315
        {
316
                PortNode *aux = list->first;
317
                while(1)
318
                {
319
                        printf("%s ",aux->tipo);
320
                        if(aux->size != 0)
321
                        {
322
                                printf("[%d:0] ",(-1 + aux->size));
323
                        }
324
                        printf("%s;\n",aux->name);
325
                        if(aux->next==NULL)
326
                        {
327
                                break;
328
                        }
329
                        aux = aux->next;
330
                }
331
        }
332
}
333
 
334
void RegOutputs(PortList *list)
335
{
336
        if(list->last != NULL)
337
        {
338
                PortNode *aux = list->first;
339
                while(1)
340
                {
341
                        if(strcmp(aux->tipo, (char *)"output")==0)
342
                        {
343
                                printf("reg ");
344
                                if(aux->size != 0)
345
                                {
346
                                        printf("[%d:0] ",(-1 + aux->size));
347
                                }
348
                                printf("%s;\n",aux->name);
349
                        }
350
                        if(aux->next==NULL)
351
                        {
352
                                break;
353
                        }
354
                        aux = aux->next;
355
                }
356
        }
357
}
358
 
359
void EnumeratePorts(PortList *list)
360
{
361
        if(list->last != NULL)
362
        {
363
                PortNode *aux = list->first;
364
                while(1)
365
                {
366
                        if(aux->next==NULL)
367
                        {
368
                                printf("%s",aux->name);
369
                                break;
370
                        }
371
                        else
372
                        {
373
                                printf("%s,",aux->name);
374
                                aux = aux->next;
375
                        }
376
                }
377
        }
378
}
379
 
380
void InitializeSignalsList(SignalsList *list)
381
{
382
        SignalNode *first;
383
        first = (SignalNode *)malloc(sizeof(SignalNode));
384
        list->first = first;
385
        list->last = NULL;
386
}
387
 
388
void InsertSignal(SignalsList *list, char *name, int size)
389
{
390
        if(list->last == NULL)
391
        {
392
                list->first->name = name;
393
                list->first->size = size;
394
                list->first->next = NULL;
395
                list->last = list->first;
396
        }
397
        else
398
        {
399
                SignalNode *nuevo;
400
                nuevo = (SignalNode *)malloc(sizeof(SignalNode));
401
                nuevo->name = name;
402
                nuevo->size = size;
403
                nuevo->next = NULL;
404
                list->last->next = nuevo;
405
                list->last = nuevo;
406
        }
407
}
408
 
409
void ShowSignalsList(SignalsList *list, WritesList *WritesList)
410
{
411
        if(list->last != NULL)
412
        {
413
                SignalNode *aux = list->first;
414
                while(1)
415
                {
416
                        if(IsWrite(WritesList, aux->name))
417
                        {
418
                                printf("reg ");
419
                                if(aux->size != 0)
420
                                {
421
                                        printf("[%d:0] ",(-1 + aux->size));
422
                                }
423
                        printf("%s;\n",aux->name);
424
                        }
425
                        else
426
                        {
427
                                printf("wire ");
428
                                if(aux->size != 0)
429
                                {
430
                                        printf("[%d:0] ",(-1 + aux->size));
431
                                }
432
                        printf("%s;\n",aux->name);
433
                        }
434
 
435
                        if(aux->next==NULL)
436
                        {
437
                                break;
438
                        }
439
                        aux = aux->next;
440
                }
441
        }
442
}
443
 
444
/* Decides if a signal is a wire or a reg*/
445
int IsWire(char *name, InstancesList *list)
446
{
447
        InstanceNode *auxinstance = list->first;
448
        BindNode *auxbind;
449
        if(list->last == NULL)
450
        {
451
                return 0;
452
        }
453
    else
454
        {
455
                while(1)
456
                {
457
                        auxbind = auxinstance->bindslist->first;
458
                        while(1)
459
                        {
460
                                if((strcmp(name, auxbind->namebind)==0))
461
                                {
462
                                        return 1;
463
                                }
464
                                else if(auxbind->next != NULL)
465
                                {
466
                                        auxbind = auxbind->next;
467
                                }
468
                                else
469
                                {
470
                                        break;
471
                                }
472
                        }
473
                        if(auxinstance->next != NULL)
474
                        {
475
                                auxinstance = auxinstance->next;
476
                        }
477
                        else
478
                        {
479
                                break;
480
                        }
481
                }
482
        }
483
        return 0;
484
}
485
 
486
void InitializeSensibilityList(SensibilityList *list)
487
{
488
        SensibilityNode *first;
489
        first = (SensibilityNode *)malloc(sizeof(SensibilityNode));
490
        list->first = first;
491
        list->last = NULL;
492
}
493
 
494
void InsertSensibility(SensibilityList *list, char *name, char *tipo)
495
{
496
        if(list->last == NULL)
497
        {
498
                list->first->name = name;
499
                list->first->tipo = tipo;
500
                list->first->next = NULL;
501
                list->last = list->first;
502
        }
503
        else
504
        {
505
                SensibilityNode *nuevo;
506
                nuevo = (SensibilityNode *)malloc(sizeof(SensibilityNode));
507
                nuevo->name = name;
508
                nuevo->tipo = tipo;
509
                nuevo->next = NULL;
510
                list->last->next = nuevo;
511
                list->last = nuevo;
512
        }
513
}
514
 
515
void ShowSensibilityList(SensibilityList *list)
516
{
517
        if(list->last != NULL)
518
        {
519
                SensibilityNode *aux = list->first;
520
                while(1)
521
                {
522
                        printf("%s ",aux->tipo);
523
                        if(aux->next==NULL)
524
                        {
525
                                printf("%s",aux->name);
526
                                break;
527
                        }
528
                        else
529
                        {
530
                                printf("%s or ",aux->name);
531
                        }
532
                aux = aux->next;
533
                }
534
        }
535
}
536
 
537
 
538
void InitializeProcessList(ProcessList *list)
539
{
540
        ProcessNode *first;
541
        first = (ProcessNode *)malloc(sizeof(ProcessNode));
542
        list->first = first;
543
        list->last = NULL;
544
}
545
 
546
void InsertProcess(ProcessList *list, char *name, SensibilityList *SensibilityList, char *tipo)
547
{
548
        if(list->last == NULL)
549
        {
550
                list->first->name = name;
551
                list->first->tipo = tipo;
552
                list->first->list = SensibilityList;
553
                list->first->next = NULL;
554
                list->last = list->first;
555
        }
556
        else
557
        {
558
                ProcessNode *nuevo;
559
                nuevo = (ProcessNode *)malloc(sizeof(ProcessNode));
560
                nuevo->name = name;
561
                nuevo->tipo = tipo;
562
                nuevo->list = SensibilityList;
563
                nuevo->next = NULL;
564
                list->last->next = nuevo;
565
                list->last = nuevo;
566
        }
567
}
568
 
569
void ShowProcessList(ProcessList *list)
570
{
571
        if(list->last != NULL)
572
        {
573
                ProcessNode *aux = list->first;
574
                while(1)
575
                {
576
                        printf("%s: always @(", aux->name);
577
                        ShowSensibilityList(aux->list);
578
                        printf(")\n");
579
                        if(aux->next==NULL)
580
                        {
581
                                break;
582
                        }
583
                        aux = aux->next;
584
                }
585
        }
586
}
587
 
588
void ShowProcessCode(ProcessList *list)
589
{
590
        if(list->last != NULL)
591
        {
592
                ProcessNode *aux = list->first;
593
                FILE *archivo;
594
                int readok;
595
                char *filename;
596
                char auxchar;
597
 
598
                while(1)
599
                {
600
                        printf("//%s:\n", aux->name);
601
                        filename = (char *)malloc(256*sizeof(char));
602
                        strcpy(filename,aux->name);
603
                        strcat(filename,(char *)"_regs.sc2v");
604
                        archivo = fopen(filename,(char *)"r");
605
 
606
                        while(1)
607
                                {
608
                                readok = fread((void *)&auxchar, sizeof(char), 1, archivo);
609
                                if(readok)
610
                                        printf("%c",auxchar);
611
                                else
612
                                   break;
613
                        }
614
 
615
                        fclose(archivo);
616
 
617
                        printf("always @(");
618
                        ShowSensibilityList(aux->list);
619
                        printf(")\n");
620
                        strcpy(filename,aux->name);
621
                        strcat(filename,(char *)".sc2v");
622
                        archivo = fopen(filename,(char *)"r");
623
 
624
                        while(1)
625
                                {
626
                                readok = fread((void *)&auxchar, sizeof(char), 1, archivo);
627
                                if(readok)
628
                                        printf("%c",auxchar);
629
                                else
630
                                   break;
631
                        }
632
 
633
                        fclose(archivo);
634
 
635
                        if(aux->next==NULL)
636
                        {
637
                                break;
638
                        }
639
                        aux = aux->next;
640
                }
641
        }
642
}
643
 
644
 
645
void InitializeInstancesList(InstancesList *list)
646
{
647
        InstanceNode *first;
648
        first = (InstanceNode *)malloc(sizeof(InstanceNode));
649
        list->first = first;
650
        list->last = NULL;
651
}
652
 
653
void InsertInstance(InstancesList *list, char *nameinstance, char *namemodulo)
654
{
655
        if(list->last == NULL)
656
        {
657
                list->first->nameinstance = nameinstance;
658
                list->first->namemodulo = namemodulo;
659
                list->first->next = NULL;
660
                list->last = list->first;
661
                list->last->bindslist = (BindsList *)malloc(sizeof(BindsList));
662
                list->last->bindslist = (BindsList *)malloc(sizeof(BindsList));
663
                InitializeBindsList(list->last->bindslist);
664
        }
665
        else
666
        {
667
                InstanceNode *nuevo;
668
                nuevo = (InstanceNode *)malloc(sizeof(InstanceNode));
669
                nuevo->nameinstance = nameinstance;
670
                nuevo->namemodulo = namemodulo;
671
                nuevo->next = NULL;
672
                list->last->next = nuevo;
673
                list->last = nuevo;
674
                list->last->bindslist = (BindsList *)malloc(sizeof(BindsList));
675
                InitializeBindsList(list->last->bindslist);
676
        }
677
}
678
 
679
void InitializeBindsList(BindsList *list)
680
{
681
        BindNode *first;
682
        first = (BindNode *)malloc(sizeof(BindNode));
683
        list->first = first;
684
        list->last = NULL;
685
}
686
 
687
void InsertBind(BindsList *list, char *nameport, char *namebind)
688
{
689
        if(list->last == NULL)
690
        {
691
                list->first->nameport = nameport;
692
                list->first->namebind = namebind;
693
                list->first->next = NULL;
694
                list->last = list->first;
695
        }
696
        else
697
        {
698
                BindNode *nuevo;
699
                nuevo = (BindNode *)malloc(sizeof(BindNode));
700
                nuevo->nameport = nameport;
701
                nuevo->namebind = namebind;
702
                nuevo->next = NULL;
703
                list->last->next = nuevo;
704
                list->last = nuevo;
705
        }
706
}
707
 
708
void ShowInstancedModules(InstancesList *list)
709
{
710
        if(list->last != NULL)
711
                        {
712
                                InstanceNode *auxinstance;
713
                                auxinstance = list->first;
714
                                BindNode *auxbind;
715
                                auxbind = auxinstance->bindslist->first;
716
                                while(1)
717
                                {
718
                                        printf("%s %s (",auxinstance->namemodulo, auxinstance->nameinstance);
719
                                        while(1)
720
                                        {
721
                                                printf(".%s(%s)",auxbind->nameport, auxbind->namebind);
722
                                                if(auxbind->next == NULL)
723
                                                {
724
                                                        printf(");\n");
725
                                                        break;
726
                                                }
727
                                                else
728
                                                {
729
                                                        printf(", ");
730
                                                        auxbind = auxbind->next;
731
                                                }
732
                                        }
733
                                        if(auxinstance->next == NULL)
734
                                        {
735
                                                break;
736
                                        }
737
                                        else
738
                                        {
739
                                                auxinstance = auxinstance->next;
740
                                                auxbind = auxinstance->bindslist->first;
741
                                        }
742
                                }
743
                        }
744
}

powered by: WebSVN 2.1.0

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