-
Notifications
You must be signed in to change notification settings - Fork 1
/
globals.ml
83 lines (65 loc) · 2.88 KB
/
globals.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(******************************************************************************
*
* DESCRIPTION: Verilog parser ocamlyacc grammar file
*
******************************************************************************
*
* Copyright 2010 by Jonathan Kimmitt. This program is free software; you can
* redistribute it and/or modify it under the terms of either the GNU
* General Public License or the Perl Artistic License.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
******************************************************************************
* Based on verilator parser code by Paul Wasson, Duane Galbi and Wilson Snyder
*******************************************************************************)
open Vparser;;
type uptr = UPTR of (Setup.fmt -> int -> Vparser.token -> unit) | UNIL;;
type modtree = {
tree: token;
symbols: Setup.shash;
mutable unresolved: string list;
};;
let modprims = Hashtbl.create 256;;
let pending = Hashtbl.create 256;;
let black_box = Hashtbl.create 256;;
let env_cache = Hashtbl.create 256;;
let tmpnam = "report."^(string_of_int(Unix.getpid()))^"."^Unix.gethostname()^".report";;
let unresolved_list = ref [];;
let stk = Stack.create();;
let logfile = ref Setup.Closed;;
let trace_file = ref Setup.Closed;;
let (unhand_list:(int*token) list ref) = ref [];;
let (implicit_params:string list ref) = ref [];;
let (implicit_wires:string list ref) = ref [];;
let unhandled_dflt out_chan ln argt = let arg = (ln,argt) in if (List.mem arg !unhand_list == false) then begin
unhand_list := arg :: !unhand_list;
Printf.fprintf (fst out_chan) "\n\n**** Unhandled %d ****\n" (List.length !unhand_list);
end
let unhandled_ptr = ref (UPTR unhandled_dflt);;
let unhandled out_chan ln arg = match !unhandled_ptr with UPTR fn -> fn out_chan ln arg | UNIL -> ();;
let last_mod = ref "";;
let get_table (m:string) = Hashtbl.find modprims m;;
let get_syms (r:modtree) = r.symbols;;
let tsymbols = Hashtbl.create 256;;
let mygetenv str = if Hashtbl.mem env_cache str then Hashtbl.find env_cache str else
try let env = Sys.getenv str in Hashtbl.add env_cache str env; env; with Not_found -> (); ""
let mygetenv_int str = try int_of_string (mygetenv str) with Failure("int_of_string") -> 0;;
let verbose = mygetenv_int "VCHK_VERBOSE"
let yesno cond = if cond then "true" else "false"
let rec quicksort = function
| (x::xs) ->
(quicksort (List.filter (fun i -> i < x) xs))
@ [x] @
(quicksort (List.filter (fun i -> i >= x) xs))
| [] -> []
;;
let rec qsort = function
| [] -> []
| pivot :: rest ->
let is_less x = x < pivot in
let left, right = List.partition is_less rest in
qsort left @ [pivot] @ qsort right