source: vis_dev/vl2mv-2.3/src/parser/main.c @ 64

Last change on this file since 64 was 18, checked in by cecile, 13 years ago

vl2mv added

File size: 11.4 KB
Line 
1/*
2
3  Copyright (c) 1992, 1993
4        Regents of the University of California
5  All rights reserved.
6
7  Use and copying of this software and preparation of derivative works
8  based upon this software are permitted.  However, any distribution of
9  this software or derivative works must include the above copyright
10  notice.
11
12  This software is made available AS IS, and neither the Electronics
13  Research Laboratory or the Universify of California make any
14  warranty about the software, its performance or its conformity to
15  any specification.
16
17  Author: Szu-Tsung Cheng, stcheng@ic.Berkeley.EDU
18          10/92
19          10/93
20
21  $Header: /projects/development/hsv/CVSRepository/vl2mv/src/parser/main.c,v 1.2 2009/03/09 20:25:57 fabio Exp $
22
23
24*/
25
26#include <stdio.h>
27#include <sys/time.h>
28#include <time.h>
29#include <unistd.h>
30#include "util.h"
31#include "array.h"
32#include "st.h"
33#include "list.h"
34#include "set.h"
35#include "stack.h"
36#include "vl_types.h"
37#include "vl_defs.h"
38#include "vlr_int.h"
39#include "vl_traverse.h"
40#include "vl_write.h"
41#include "vl_mux.h"
42#include "verilog.h"
43
44extern vl_descPtr vl_description;
45extern int YYTrace;
46extern lsList vl_module_stack;
47extern lsList vl_cur_type_stack;
48extern st_table *macros;
49extern int PrtEnable;
50extern int dumpSyncCkt;
51extern int dflow_analysis;
52extern int Loop_Unrolling;
53extern int Repeat_Unrolling;
54extern int do_encoding;
55extern int debug_mode;
56extern int Use_MV_Lib;
57extern int set_notation;
58extern int implicitDeclare;
59extern int implicitClocking;
60extern int combinationalReduction;
61extern int chk_IncompleteBranch;
62extern int vlTimedSystem;
63extern int wireRegister;
64extern int portPerLine;
65extern int compatibleChecking;
66extern int use_libraryGate;
67extern int vis_nond;
68extern int vl_noTimers;
69extern int decomposeTable;
70extern int smartEvent;
71extern int indexAssignment;
72extern int NoDetailedComment;
73extern int implicitClockWire;
74extern int arrayBoundNond;
75extern int RQautomata;
76extern int deadlock_semantic;
77extern int Zconnection;
78extern char *vl_filename;
79extern FILE *yyin;
80extern FILE *mv_file;
81extern FILE *open_file();
82extern stack_t file_stack;
83extern stack_t fname_stack;
84extern stack_t lineno_stack;
85extern stack_t buffer_stack;
86extern int instantiateAll;
87extern FILE *null_file;
88
89FILE *vl_OutStream=NIL(FILE);
90char *vl_OutStreamName=NIL(char);
91
92FILE *siserr;
93
94int noBus=0;
95
96int WarningLevel=0;
97int vlPhase=0;
98int encodeTimer=1;
99int userControlLibraryGate=0;
100
101char *opts = "AbBcdD:eEf:FgiIklMnNo:OpPrR:StT:uvwW:xyZz";
102int ith_module = 0;
103
104int Warn_Uninitialized = 0;
105int Warn_DuplicateInst = 0;
106
107#define VIS_LIB_PATH    "VIS_LIBRARY_PATH"
108#define SISLIB_MV       "sislib.mv"
109#define SISLIB_V        "sislib.v"
110
111UNUSED static char rcsid[] = "$Id: main.c,v 1.2 2009/03/09 20:25:57 fabio Exp $";
112
113static void usage ARGS((char *cmd));
114static void predefine_macros ARGS((st_table *macros));
115
116int main(int argc, char *argv[])
117{
118#ifdef _IBMR2
119    int c;
120#else
121    char c;
122#endif
123    lsHandle handle;
124    lsGen gen;
125    vl_module *mod;
126    int i;
127    int dumpOnly=0;
128    int use_stdout=0;
129    char *out_filename = NIL(char);
130    struct timeval tval;
131    struct timezone tzone;
132    struct tm *current_time;
133    char buf[MAXSTRLEN];
134    extern int optind;
135    extern char *optarg;
136    extern int use_rst_ckt;
137
138    mv_file = stdout;
139    siserr = stderr;
140
141    gettimeofday(&tval, &tzone);
142    current_time = localtime((time_t *)(&(tval.tv_sec)));
143
144
145    macros = st_init_table(strcmp, st_strhash);
146    predefine_macros(macros);
147
148
149    vl_module_stack = lsCreate();
150    vl_cur_type_stack = lsCreate();
151
152    if (argc <= 1) {
153        usage(argv[0]);
154    }
155
156    while ((c = getopt(argc, argv, opts)) != EOF) {
157        switch (c) {
158        case 'A': use_stdout=1; break;
159        case 'b': noBus=1; break;
160        case 'B': chk_IncompleteBranch = 0; break;
161        case 'c': implicitClocking = 0; vlTimedSystem = 1; break;
162        case 'C': compatibleChecking = 1; break;
163        case 'd': PrtEnable=1; dumpOnly=1; break;
164        case 'D':
165            switch (*optarg) {
166            case 'l': dflow_analysis |= DF_UninitVar; break;
167            default: usage(argv[0]);
168            }
169            break;
170        case 'e': do_encoding = 1; break;
171        case 'E': smartEvent = 0; break;
172        case 'f': portPerLine = atoi(optarg); break;
173        case 'F': vl_noTimers = 1; break;
174        case 'g': debug_mode=1; break;
175        case 'i': implicitDeclare=0; break;
176        case 'I': instantiateAll=0; break;
177        case 'k': deadlock_semantic = 1; break;
178        case 'l': Use_MV_Lib=1; break;
179        case 'L': userControlLibraryGate = 1; break;
180        case 'M': NoDetailedComment=1; break;
181        case 'n': dumpSyncCkt=1; break;
182        case 'N': arrayBoundNond=1; break;
183        case 'o': out_filename = vlStrdup(optarg); break;
184        case 'O': combinationalReduction = 1; break;
185        case 'P': Repeat_Unrolling = ~Repeat_Unrolling; break;
186        case 'p': PrtEnable=1; break;
187        case 'R': if (!strcmp(optarg,"Uninitialized")) Warn_Uninitialized=1;
188                  if (!strcmp(optarg,"DuplicateInst")) Warn_DuplicateInst=1;
189          break;
190        case 'r': use_rst_ckt = 1; break;
191        case 'S': set_notation=0; break;
192        case 't': YYTrace=1; break;
193        case 'T': decomposeTable = atoi(optarg); break;
194        case 'u': Loop_Unrolling=0; break;
195        case 'v': implicitClockWire=1; break;
196        case 'w': wireRegister=1; break;
197        case 'W': WarningLevel = atoi (optarg); break;
198        case 'x': indexAssignment = 1; break;
199        case 'y': RQautomata = 0; break;
200        case 'Z': vis_nond = 0; break;
201        case 'z': Zconnection = 1; break;
202        default: usage(argv[0]);
203        }
204    }
205
206
207    file_stack = create_stack();
208    fname_stack = create_stack();
209    lineno_stack = create_stack();
210    buffer_stack = create_stack();
211    vl_filename = argv[optind];
212    yyin = fopen(argv[optind],"r");
213    fprintf(stderr, "%s\n", vl_filename);
214    if (!yyin) {
215        fprintf(stderr, "failed to open file %s\n", vl_filename);
216        exit(1);
217    }
218
219
220    vlPhase = 0;
221    if (yyparse())
222        printf("-- parsing failure\n");
223    chk_mp_definitions(vl_description->mp_undefined);
224
225    if (!use_stdout) {
226        if (!out_filename) {
227            char *tmp_filename;
228            tmp_filename = basename(vl_filename);
229            out_filename = chk_malloc(strlen(tmp_filename)+15);
230            strcpy(out_filename, tmp_filename);
231            strcat(out_filename, ".mv");
232            vl_OutStreamName = vlStrdup(out_filename);
233            vl_OutStream = mv_file = open_file(out_filename, "w");
234            vl_chk_free(out_filename);
235            out_filename = NIL(char);
236        } else {
237            vl_OutStreamName = vlStrdup(out_filename);
238            vl_OutStream = mv_file = open_file(out_filename, "w");
239            vl_chk_free(out_filename);
240            out_filename = NIL(char);
241        }
242    }
243
244    null_file = open_file("/dev/null", "w");
245    fprintf(mv_file, "%s ", HSIS_COMMENT);
246    for (i=0; i<argc; i++) {
247        fprintf(mv_file, "%s ", argv[i]);
248    }
249    fprintf(mv_file, "\n");
250    fprintf(mv_file, "%s version: %s\n", HSIS_COMMENT, VL2MV_VERSION);
251    strftime(buf, MAXSTRLEN, "%T %m/%d/%Y (%Z)", current_time);
252    fprintf(mv_file, "%s date:    %s\n", HSIS_COMMENT, buf);
253
254    vlPhase = 1;
255
256    for (gen=lsStart(vl_description->modules);
257         lsNext(gen, (lsGeneric*)&mod, &handle) != LS_NOMORE; ) {
258        vl_step_desc(mod->name->name, (char*)mod, NIL(char));
259    }
260    lsFinish(gen);
261
262    if (!dumpOnly) {
263
264        vlPhase = 2;
265        PrtEnable = 1;
266        gen = lsStart(vl_description->modules);
267        while (lsNext(gen, (lsGeneric*)&mod, &handle) != LS_NOMORE) {
268            vl_write_desc(mod->name->name, (char*)mod, NIL(char));
269            ith_module++;
270        }
271        vl_dump_libs(mv_file, vl_description->decl_st);
272    }
273
274    if (use_libraryGate) {
275        if (!userControlLibraryGate) {
276            char *visLibPath;
277            if ((visLibPath=getenv(VIS_LIB_PATH))) {
278                char *file_path;
279                if ((file_path = util_file_search(SISLIB_MV,visLibPath,"r"))) {
280                    fprintf(mv_file, ".include %s\n", SISLIB_MV);
281                } else if ((file_path = util_file_search(SISLIB_V,
282                                                        visLibPath, "r"))) {
283                   if (!(yyin = fopen(file_path, "r"))) {
284                        fprintf(stderr, "fail to open %s\n", file_path);
285                        exit(1);
286                   }
287                   yylineno = 1;
288                   if (yyparse()) {
289                        fprintf(stderr, "parsing failure for library file %s\n",
290                                file_path);
291                        exit(1);
292                   }
293                   fclose(yyin);
294                } else {
295                    fprintf(stderr, "cannot file sislib.mv/sislib.v in $%s, insert \".include sislib.mv\" in your generated mv file\n",
296                            VIS_LIB_PATH);
297                    fprintf(mv_file, ".include %s\n", SISLIB_MV);
298                }
299            } else {
300                fprintf(stderr, "cannot file sislib.mv/sislib.v in $%s, insert \".include sislib.mv\" in your generated mv file\n",
301                        VIS_LIB_PATH);
302                fprintf(mv_file, ".include %s\n", SISLIB_MV);
303            }
304        }
305    }
306
307    return 0;
308}
309
310static void usage(char *cmd)
311{
312    fprintf(stderr, "usage: %s -%s <filename>\n", cmd, opts);
313    fprintf(stderr, "\tversion %s\n", VL2MV_VERSION);
314    fprintf(stderr, "       -A        : dump output to stdout\n");
315    fprintf(stderr, "       -b        : no multiple output for bus connection\n");
316    fprintf(stderr, "       -B        : disable check incomplete branches\n");
317    fprintf(stderr, "       -c        : explicit clocking\n");
318
319    fprintf(stderr, "       -d        : dump internal representation only\n");
320
321
322    fprintf(stderr, "       -E        : turn off smart event (save register)\n");
323    fprintf(stderr, "       -f        : split line for long port lists\n");
324    fprintf(stderr, "       -F        : ignore all timing (watch out!!)\n");
325    fprintf(stderr, "       -g        : put debugging information\n");
326    fprintf(stderr, "       -i        : turn off auto declaration of 1-bit wires\n");
327    fprintf(stderr, "       -I        : supress declaration of modules of included file when `VL2MVundefMod is in place\n");
328    fprintf(stderr, "       -L        : users wish to control the generation of gates instead of using default search/generation schemes.\n");
329
330    fprintf(stderr, "       -M        : forbidden verbose comments\n");
331    fprintf(stderr, "       -n        : check if create physically clocked latches\n");
332    fprintf(stderr, "       -N        : use nondeterminism for out-of-bound array access\n");
333    fprintf(stderr, "       -o <file> : send output to <file>\n");
334    fprintf(stderr, "       -O        : combinational reduction\n");
335    fprintf(stderr, "       -P        : disable repeat loop unrolling\n");
336    fprintf(stderr, "       -p        : dump internal representation\n");
337
338    fprintf(stderr, "       -R <warn> : provide various warning messages\n");
339    fprintf(stderr, "          <warn> = Uninitialized DuplicateInst\n");
340    fprintf(stderr, "       -t        : dump parsing trace\n");
341    fprintf(stderr, "       -T <width>: decompose nonblocking assignment table wider than <width>\n");
342    fprintf(stderr, "       -u        : turn off loop unrolling\n");
343    fprintf(stderr, "       -v        : wire for 'clocks' in implicit clocking\n");
344    fprintf(stderr, "       -w        : put register to prevent self reference wire in alwyas stmt\n");
345    fprintf(stderr, "       -W <level>: set warning level\n");
346    fprintf(stderr, "       -x        : put in assignment to idnex variable in for-loop unrolling\n");
347    fprintf(stderr, "       -y        : do not attempt to make Timing Maching RQ (save states)\n");
348    fprintf(stderr, "       -z        : use wire-or for resolution function instead of conflict arbiter\n");
349    fprintf(stderr, "                   useful for hi-Z modeling\n");
350    fprintf(stderr, "       -Z        : (turn on) limit $ND to only continuous assignments for VIS\n");
351    fprintf(stderr, "                 : WARNING: when this is on, only \"assign <id> = $ND(...);\" is allowed\n");
352    exit(255);
353}
354
355void vl_exit(int code)
356{
357    if (vl_OutStream != NIL(FILE))
358        unlink(vl_OutStreamName);
359    exit(code);
360}
361
362char *predefined_symbols[] = {
363    "__vl2mv__",
364    "__synth__",
365    NULL
366};
367
368static void predefine_macros(st_table *macros)
369{
370    int i;
371    char *cp;
372
373    for (i=0 ; (cp=predefined_symbols[i]); i++) {
374        st_insert(macros, cp, " ");
375    }
376}
Note: See TracBrowser for help on using the repository browser.