Skip to content

Commit 0f170ce

Browse files
Convert from dotted identifier notation to hierarchy of symbol tables
1 parent 5912c38 commit 0f170ce

10 files changed

+410
-392
lines changed

.depend

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
vparser.cmo: vparser.cmi globals.cmo vparser.cmi vparser.ml
22
vparser.cmx: vparser.cmi globals.cmx vparser.cmi vparser.ml
3-
vlexer.cmo: vparser.cmi setup.cmo
4-
vlexer.cmx: vparser.cmi setup.cmx
3+
vlexer.cmo: vparser.cmi setup.cmo globals.cmo
4+
vlexer.cmx: vparser.cmi setup.cmx globals.cmx
55
vparser.cmo: vparser.cmi
66
vparser.cmx: vparser.cmi
77
dump.cmo: globals.cmi dump.cmi vlexer.cmo

check.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ let erc_chk_sig out_chan (syma:tset) siga =
3737
"is an undriven output"
3838
else if (TokSet.mem INOUT syma) then
3939
": is an inout"
40+
else if (TokSet.mem WIRE syma) && (TokSet.mem DRIVER siga) && not ((TokSet.mem RECEIVER siga) || (TokSet.mem SPECIFY syma)) then
41+
"is a wire which drives but is not driven"
4042
else if (TokSet.mem WIRE syma) && not ((TokSet.mem RECEIVER siga) || (TokSet.mem SPECIFY syma)) then
4143
"is an unused wire"
4244
else ""
@@ -47,7 +49,7 @@ let erc_chk_sig out_chan (syma:tset) siga =
4749
let erc_chk out_chan (gsyms:sentries) id s = match s.sigattr with
4850
| Sigarray attrs -> (
4951
match s.width with
50-
| RANGE range -> let (hi,lo) = iwidth out_chan "" (Shash {nxt=EndShash; syms=gsyms}) s.width in
52+
| RANGE range -> let (hi,lo) = iwidth out_chan (Shash {nxt=EndShash; syms=gsyms}) s.width in
5153
if not ((TokSet.mem IMPLICIT s.symattr)||(TokSet.mem MEMORY s.symattr)) then
5254
( let msg0 = ref "" and i0 = ref hi and i1 = ref hi in try for i = hi downto lo do
5355
let msg = erc_chk_sig out_chan s.symattr attrs.(i) in

const.ml

+22-30
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ open Globals
2222
open Setup
2323
open Ord
2424

25-
let rec exprBoolean out_chan stem (syms:shash) op expr1 expr2 =
26-
op (exprConst out_chan stem syms expr1) (exprConst out_chan stem syms expr2)
25+
let rec exprBoolean out_chan (syms:shash) op expr1 expr2 =
26+
op (exprConst out_chan syms expr1) (exprConst out_chan syms expr2)
2727

2828
and widthnum expbase (str:string) =
2929
let base = ref 10
@@ -66,54 +66,46 @@ and shash_chain_find (syms:shash) nam = match syms with
6666
| Shash symr -> if Hashtbl.mem symr.syms nam then Hashtbl.find symr.syms nam else shash_chain_find symr.nxt nam
6767
| EndShash -> failwith "Not found"
6868

69-
and exprConst out_chan stem (syms:shash) expr = Stack.push (stem, 67, expr) stk; let rslt = ( match expr with
69+
and exprConst out_chan (syms:shash) expr = Stack.push (67, expr) stk; let rslt = ( match expr with
7070
| INT n -> n
7171
| HEXNUM str -> snd(widthnum 16 str)
72-
| TRIPLE(TIMES, expr1, expr2) -> (exprConst out_chan stem syms expr1) * (exprConst out_chan stem syms expr2)
73-
| TRIPLE(PLUS, expr1, expr2) -> (exprConst out_chan stem syms expr1) + (exprConst out_chan stem syms expr2)
74-
| TRIPLE(MINUS, expr1, expr2) -> (exprConst out_chan stem syms expr1) - (exprConst out_chan stem syms expr2)
75-
| TRIPLE(P_EQUAL, expr1, expr2) -> if (exprBoolean out_chan stem syms (=)) expr1 expr2 then 1 else 0
76-
| TRIPLE(P_NOTEQUAL, expr1, expr2) -> if (exprBoolean out_chan stem syms (<>)) expr1 expr2 then 1 else 0
77-
| TRIPLE(LESS, expr1, expr2) -> if (exprBoolean out_chan stem syms (<)) expr1 expr2 then 1 else 0
78-
| TRIPLE(GREATER, expr1, expr2) -> if (exprBoolean out_chan stem syms (>)) expr1 expr2 then 1 else 0
79-
| TRIPLE(P_LTE, expr1, expr2) -> if (exprBoolean out_chan stem syms (<=)) expr1 expr2 then 1 else 0
80-
| TRIPLE(P_GTE, expr1, expr2) -> if (exprBoolean out_chan stem syms (>=)) expr1 expr2 then 1 else 0
72+
| TRIPLE(TIMES, expr1, expr2) -> (exprConst out_chan syms expr1) * (exprConst out_chan syms expr2)
73+
| TRIPLE(PLUS, expr1, expr2) -> (exprConst out_chan syms expr1) + (exprConst out_chan syms expr2)
74+
| TRIPLE(MINUS, expr1, expr2) -> (exprConst out_chan syms expr1) - (exprConst out_chan syms expr2)
75+
| TRIPLE(P_EQUAL, expr1, expr2) -> if (exprBoolean out_chan syms (=)) expr1 expr2 then 1 else 0
76+
| TRIPLE(P_NOTEQUAL, expr1, expr2) -> if (exprBoolean out_chan syms (<>)) expr1 expr2 then 1 else 0
77+
| TRIPLE(LESS, expr1, expr2) -> if (exprBoolean out_chan syms (<)) expr1 expr2 then 1 else 0
78+
| TRIPLE(GREATER, expr1, expr2) -> if (exprBoolean out_chan syms (>)) expr1 expr2 then 1 else 0
79+
| TRIPLE(P_LTE, expr1, expr2) -> if (exprBoolean out_chan syms (<=)) expr1 expr2 then 1 else 0
80+
| TRIPLE(P_GTE, expr1, expr2) -> if (exprBoolean out_chan syms (>=)) expr1 expr2 then 1 else 0
8181
| DOUBLE(CONCAT, TLIST [left; right]) -> Printf.fprintf (fst out_chan) "Concat expr not yet implemented, value 1 assumed\n"; 1
8282

83-
| ID id -> let pth = stem^id in begin
84-
if shash_chain_mem syms pth == false then begin
85-
if shash_chain_mem syms id == false then begin
86-
(* unhandled out_chan 81 expr; *)
87-
Printf.fprintf (fst out_chan) "constant %s not declared, value 1 assumed\n" pth;
83+
| ID id -> begin
84+
if shash_chain_mem syms id == false then begin
85+
Printf.fprintf (fst out_chan) "constant %s not declared, value 1 assumed\n" id;
8886
1
8987
end
90-
else
88+
else
9189
match (shash_chain_find syms id).sigattr with
92-
| Sigparam pexpr -> exprConst out_chan stem syms pexpr
90+
| Sigparam pexpr -> exprConst out_chan syms pexpr
9391
| Sigarray x -> Printf.fprintf (fst out_chan) "%s not a constant or for variable, value 1 assumed\n" id; 1
9492
| _ -> unhandled out_chan 89 expr; 1
9593
end
96-
else
97-
match (shash_chain_find syms pth).sigattr with
98-
| Sigparam pexpr -> exprConst out_chan stem syms pexpr
99-
| Sigarray x -> Printf.fprintf (fst out_chan) "%s not a constant or for variable, value 1 assumed\n" pth; 1
100-
| _ -> unhandled out_chan 95 expr; 1
101-
end
10294
| TRIPLE(FUNCREF, ID id, TLIST args) -> Printf.fprintf (fst out_chan) "%s is a function, value 1 assumed\n" id; 1
103-
| QUADRUPLE(PARTSEL, arg, INT hi, INT lo) -> (exprConst out_chan stem syms arg) lsr lo
95+
| QUADRUPLE(PARTSEL, arg, INT hi, INT lo) -> (exprConst out_chan syms arg) lsr lo
10496
| TRIPLE(P_SLEFT, INT 1, ID id) -> Printf.fprintf (fst out_chan) "Const expression 1<<%s is too complicated, value 1 assumed\n" id; 1
10597
| _ -> unhandled out_chan 97 expr; 1 ) in
10698
ignore(Stack.pop stk);
10799
rslt
108100

109-
let iwidth out_chan stem syms wid = match wid with
110-
| RANGE(expr1, expr2) -> (exprConst out_chan stem syms expr1,exprConst out_chan stem syms expr2)
101+
let iwidth out_chan syms wid = match wid with
102+
| RANGE(expr1, expr2) -> (exprConst out_chan syms expr1,exprConst out_chan syms expr2)
111103
| UNKNOWN -> (0,0)
112104
| SCALAR -> (0,0)
113105
| EMPTY -> (0,0)
114106
| _ -> unhandled out_chan 56 wid; (-1,-1)
115107

116-
let maxwidth out_chan stem syms neww = let w = iwidth out_chan stem syms neww in
108+
let maxwidth out_chan syms neww = let w = iwidth out_chan syms neww in
117109
1 + (max (fst w) (snd w))
118110

119111
let show_set s = TokSet.iter (fun e -> Printf.printf "%s " (str_token e)) s;;
@@ -128,7 +120,7 @@ let show_chk_sig nam syma siga =
128120
let show_sig_attr syms id s = match s.sigattr with
129121
| Sigarray attrs -> (
130122
match s.width with
131-
| RANGE range -> let (hi,lo) = iwidth (stderr,Format.err_formatter) "" syms s.width in
123+
| RANGE range -> let (hi,lo) = iwidth (stderr,Format.err_formatter) syms s.width in
132124
if not ((TokSet.mem IMPLICIT s.symattr)||(TokSet.mem MEMORY s.symattr)) then
133125
( try for i = hi downto lo do
134126
show_chk_sig (id^"["^(string_of_int i)^"]") s.symattr attrs.(i)

const.mli

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ val show_sym : string -> Setup.symtab -> unit
44
val maxwidth : Setup.fmt -> string -> Setup.shash -> Vparser.token -> int
55
val exprBoolean :
66
Setup.fmt ->
7-
string ->
87
Setup.shash ->
98
(int -> int -> bool) -> Vparser.token -> Vparser.token -> bool
10-
val exprConst : Setup.fmt -> string -> Setup.shash -> Vparser.token -> int
9+
val exprConst : Setup.fmt -> Setup.shash -> Vparser.token -> int
1110
val iwidth :
12-
Setup.fmt ->
13-
string -> Setup.shash -> Vparser.token -> int * int
11+
Setup.fmt -> Setup.shash -> Vparser.token -> int * int
1412
val maxwidth :
15-
Setup.fmt ->
16-
string -> Setup.shash -> Vparser.token -> int
13+
Setup.fmt -> Setup.shash -> Vparser.token -> int
1714
val widthnum : int -> string -> int*int
1815
val dump_sym : string -> string -> unit
1916
val dump_syms : string -> unit

ex/test.v

+16-12
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
`timescale 1ns/1ps
44

5-
module test2(input a, input b, output [1:0] c);
5+
module test2(input a, input b, input c, input r, output [1:0] cc);
66

7-
assign c = a+b;
7+
assign cc = a+b;
88

99
/* extended
1010
0: 0 @ P ` p 0: ( 2 < F P Z d n x
@@ -25,22 +25,22 @@ assign c = a+b;
2525
F: / ? O _ o DEL
2626
comment */
2727

28+
always @(posedge c)
29+
if (r)
30+
c = 0;
31+
else
32+
c = c+1;
33+
2834
endmodule
2935

3036
module test1(clk, rst, cnt, cc);
3137

3238
input clk, rst;
33-
output [7:0] cnt;
34-
reg [7:0] cnt;
39+
input [7:0] cnt;
40+
// reg [7:0] cnt;
3541
output [1:0] cc;
3642

37-
test2 cct(.a(), .b(), .c(cc));
38-
39-
always @(posedge clk)
40-
if (rst)
41-
cnt = 0;
42-
else
43-
cnt = cnt+1;
43+
test2 cct(.a(), .b(), .c(clk), .r(rst), .cc(cc));
4444

4545
endmodule
4646

@@ -50,7 +50,11 @@ input clk, rst;
5050
output [15:0] count;
5151
wire [1:0] cc;
5252

53-
test1 split(clk, rst, {count[7],count[6],count[5],count[4],count[3],count[2],count[1],count[0]}, cc[1:0]);
53+
wire count_7, count_6, count_5, count_4, count_3, count_2, count_1, count_0;
54+
55+
assign count = {count_7, count_6, count_5, count_4, count_3, count_2, count_1, count_0};
56+
57+
test1 split(clk, rst, {count_7, count_6, count_5, count_4, count_3, count_2, count_1, count_0}, cc[1:0]);
5458

5559
// another comment
5660

globals.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ val show_syms : ('a -> 'b -> unit) -> ('a, 'b) Hashtbl.t -> unit
2828
val show_table : string -> unit
2929
*)
3030
val unresolved_list : string list ref
31-
val stk : (string * int * Vparser.token) Stack.t
31+
val stk : (int * Vparser.token) Stack.t
3232
val logfile : Setup.logt ref
3333
val trace_file : Setup.logt ref

0 commit comments

Comments
 (0)