source: vis_dev/vl2mv-2.3/src/parser/vl_edgedetector.c @ 18

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

vl2mv added

File size: 7.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/vl_edgedetector.c,v 1.2 2009/03/09 20:25:57 fabio Exp $
22
23
24*/
25
26#include <stdio.h>
27#include <math.h>
28#include "util.h"
29#include "st.h"
30#include "array.h"
31#include "list.h"
32#include "set.h"
33#include "vl_types.h"
34#include "vl_defs.h"
35#include "vlr_int.h"
36#include "vl_fg_defs.h"
37#include "vl_create.h"
38#include "vl_write.h"
39#include "vl_write_util.h"
40#include "vl_vardecl.h"
41#include "vl_edgedetector.h"
42#include "verilog.h"
43
44extern int smartEvent;
45extern int set_notation;
46extern int implicitClocking;
47extern int vlTimedSystem;
48extern int vl_noTimers;
49
50
51vl_term *write_ored_edge_detector(file, event)
52FILE *file;
53vl_event_expr *event;
54{
55    vl_term *retval;
56    int i;
57    lsGen gen;
58    lsHandle handle;
59    vl_event_expr *expr;
60    array_t *edge_terms;
61
62    assert(event->type == OrEventExpr);
63
64    retval = new_term(NIL(vl_range), 0, -1);
65   
66    edge_terms = array_alloc(vl_term*, 0);
67    for (gen=lsStart(event->list); 
68         lsNext(gen,(lsGeneric*)&expr,&handle)!=LS_NOMORE;) {
69        vl_term *eterm;
70        eterm = write_edge_detector(file, expr->expr, 
71                                    (expr->type==PosedgeEventExpr)?1:
72                                    (expr->type==NegedgeEventExpr)?-1:0);
73        array_insert_last(vl_term*, edge_terms, eterm);
74    }
75    (void)lsFinish(gen);
76
77    fprintf(file, ".names ");
78    for (i=0; i<array_n(edge_terms); i++) {
79        vl_term *eterm;
80        eterm = array_fetch(vl_term*,edge_terms,i);
81        fprintf(file, "%s ", eterm->name->name);
82    }
83
84    fprintf(file, "%s\n", retval->name->name);
85
86    fprintf(file, "%s 1\n", HSIS_DEFAULT);
87    for (i=0; i<lsLength(event->list); i++)
88      fprintf(file, "0 ");
89    fprintf(file, "0\n");
90
91    array_free(edge_terms);
92
93    return retval;
94}
95
96
97
98
99vl_term *write_edge_detector(file, expr, sign)
100FILE *file;
101vl_expr *expr;
102int sign;
103{
104    static int edge_detector_count=0;
105    vl_term *retval=NIL(vl_term);
106    vl_term *sig, *sig_prev;
107    vl_id_range *id_sym;
108    char buf[MAXSTRLEN];
109    int event_flag = 0;
110    int hi, lo;
111    int i;
112    vl_id_range *event_id_sym;
113    int nbits;
114    char sigbuf[MAXSTRLEN], sigprebuf[MAXSTRLEN], eventbuf[MAXSTRLEN];
115    char *delta_counter = NIL(char);
116
117
118
119    if (expr->type == IDExpr) {
120        event_id_sym = expr->u.name;
121        if (st_lookup(vl_currentModule->sig_st, event_id_sym->name,
122                      (char**)&id_sym)) 
123            get_hilo(id_sym, &hi, &lo);
124    } else {
125       
126       
127        vl_write_expr(file, expr, NIL(st_table));
128        event_id_sym = expr->term->name;
129        hi = expr->term->hi;
130        lo = expr->term->lo;
131    }
132
133   
134   
135    if (!st_lookup(vl_currentModule->sig_st, event_id_sym->name,
136                   (char**)&id_sym)) {
137        if (expr->type == IDExpr) {
138            sprintf(buf, "'%s': sensitive to undeclared variable %s",
139                    vl_currentModule->name->name, expr->u.name->name);
140            yylineno = -1;
141            compile_error(buf);
142        }
143    } else if (id_sym->flags & EventVar) {
144        event_flag = 1;
145    }
146
147    if (implicitClocking && !vlTimedSystem) return retval;
148
149    sig = vl_create_term(vl_copy_id_range(event_id_sym), 0, -1);
150    sprintf(buf, "%s%s%s%x", sig->name->name, SEP_GATEPIN, PIN_DELAY, 
151            edge_detector_count++);
152    sig_prev = create_rename_term(event_id_sym, buf, 0, -1);
153    retval = new_term(NIL(vl_range), 0,  -1);
154
155    if (event_flag) {
156        fprintf(file, ".names %s %s\n- %s%s\n", 
157                sig->name->name, retval->name->name,
158                HSIS_EQUAL, sig->name->name);
159        return retval;
160    } 
161
162    nbits = (hi<lo)?1:(hi-lo+1);
163   
164   
165    for (i=0; i<nbits; i++) {
166        if (hi<lo) {
167            sprintf(sigbuf, "%s", sig->name->name);
168            sprintf(sigprebuf, "%s", sig_prev->name->name);
169            sprintf(eventbuf, "%s", retval->name->name);
170        } else {
171            sprintf(sigbuf, "%s%s%d%s",
172                    sig->name->name, SEP_LBITSELECT, i+lo, SEP_RBITSELECT);
173            sprintf(sigprebuf, "%s%s%d%s",
174                    sig_prev->name->name, SEP_LBITSELECT, i+lo, SEP_RBITSELECT);
175            sprintf(eventbuf, "%s%s%d%s",
176                    retval->name->name, SEP_LBITSELECT, i+lo, SEP_RBITSELECT);
177        }
178
179        fprintf(file, ".latch %s %s\n", sigbuf, sigprebuf);
180       
181        fprintf(file, ".r %s\n0\n", sigprebuf);
182        if (sign > 0) {
183           
184            if ((vlTimedSystem || !implicitClocking) && !vl_noTimers) {
185                delta_counter=new_deltaTimer();
186                fprintf(file, ".timers %s\n", delta_counter);
187            }
188            fprintf(file, ".names %s %s %s\n", sigprebuf, sigbuf, eventbuf);
189            if (set_notation) {
190                if ((vlTimedSystem || !implicitClocking) && !vl_noTimers){
191                    fprintf(file, "%s 0\n", HSIS_DEFAULT);
192                    fprintf(file, "0 0 0 %s %s=0\n",
193                            HSIS_TIMER_SEP, delta_counter);
194                    fprintf(file, "0 1 1 %s %s==0\n",
195                            HSIS_TIMER_SEP, delta_counter);
196                } else {
197                    fprintf(file, "%s 0\n", HSIS_DEFAULT);
198                    fprintf(file, "0 1 1\n");
199                }
200            } else {
201                fprintf(file, "0 0 0\n0 1 1\n1 0 0\n1 1 0\n");
202            }
203        } else if (sign < 0) {
204           
205            if ((vlTimedSystem || !implicitClocking) && !vl_noTimers) {
206                delta_counter=new_deltaTimer();
207                fprintf(file, ".timers %s\n", delta_counter);
208            }
209            fprintf(file, ".names %s %s %s\n", sigprebuf, sigbuf, eventbuf);
210            if (set_notation) {
211                if ((vlTimedSystem || !implicitClocking) && !vl_noTimers) {
212                    fprintf(file, "%s 0\n", HSIS_DEFAULT);
213                    fprintf(file, "1 1 0 %s %s=0\n",
214                            HSIS_TIMER_SEP, delta_counter);
215                    fprintf(file, "1 0 1 %s %s==0\n",
216                            HSIS_TIMER_SEP, delta_counter);
217                } else {
218                    fprintf(file, "%s 0\n", HSIS_DEFAULT);
219                    fprintf(file, "1 0 1\n");
220                }
221            } else {
222                fprintf(file, "0 0 0\n0 1 0\n1 0 1\n1 1 0\n");
223            }
224        } else if (sign==0) {
225           
226            if ((vlTimedSystem || !implicitClocking) && !vl_noTimers) {
227                delta_counter=new_deltaTimer();
228                fprintf(file, ".timers %s\n", delta_counter);
229            }
230            fprintf(file, ".names %s %s %s\n", sigprebuf, sigbuf, eventbuf);
231            if (event_flag && smartEvent) {
232                if (set_notation) {
233                    fprintf(file, "%s 0\n", HSIS_DEFAULT);
234                    fprintf(file, "0 1 1\n");
235                } else {
236                    fprintf(file, "0 0 0\n0 1 1\n1 0 0\n1 1 0\n");
237                }
238            } else {
239                if (set_notation) {
240                    if ((vlTimedSystem || !implicitClocking) && !vl_noTimers) {
241                        fprintf(file, "0 0 0 %s %s=0\n",
242                                HSIS_TIMER_SEP, delta_counter);
243                        fprintf(file, "0 1 1 %s %s==0\n",
244                                HSIS_TIMER_SEP, delta_counter);
245                        fprintf(file, "1 1 0 %s %s=0\n",
246                                HSIS_TIMER_SEP, delta_counter);
247                        fprintf(file, "1 0 1 %s %s==0\n",
248                                HSIS_TIMER_SEP, delta_counter);
249                    } else {
250                        fprintf(file, "%s 0\n", HSIS_DEFAULT);
251                        fprintf(file, "1 0 1\n0 1 1\n");
252                    }
253                } else {
254                    fprintf(file, "0 0 0\n0 1 1\n1 0 1\n1 1 0\n");
255                }
256            }
257        }
258    }
259
260    if (hi >= lo) {
261        vl_term *redresult;
262        redresult = new_term(NIL(vl_range), 0, -1);
263        retval->hi = hi;
264        retval->lo = lo;
265        vl_write_vector_bop(file, UorExpr, retval, NIL(vl_term), redresult);
266        retval = redresult;
267    }
268
269    return retval;
270}
271
272char *new_deltaTimer()
273{
274    static int delta_timer_counter=0;
275    static char buf[MAXSTRLEN];
276
277    sprintf(buf, "%s%d", HSIS_DELTA_TIMER, delta_timer_counter++);
278    return buf;
279}
Note: See TracBrowser for help on using the repository browser.