diff options
Diffstat (limited to 'sched')
-rw-r--r-- | sched/netlist_dumb.ml | 2 | ||||
-rw-r--r-- | sched/netlist_lexer.mll | 2 | ||||
-rw-r--r-- | sched/netlist_parser.mly | 38 |
3 files changed, 16 insertions, 26 deletions
diff --git a/sched/netlist_dumb.ml b/sched/netlist_dumb.ml index 19b16a8..7736d94 100644 --- a/sched/netlist_dumb.ml +++ b/sched/netlist_dumb.ml @@ -52,7 +52,7 @@ let mkbinstr a = let make_program_dumb p = let vars = ref [] in - let var_map = Hashtbl.create (Env.size p.p_vars) in + let var_map = Hashtbl.create (Env.cardinal p.p_vars) in () (* TODO *) (* 1. Identify constants and create new variables for them, put them on the variable list diff --git a/sched/netlist_lexer.mll b/sched/netlist_lexer.mll index 78b0410..60cb223 100644 --- a/sched/netlist_lexer.mll +++ b/sched/netlist_lexer.mll @@ -29,7 +29,7 @@ rule token = parse | "=" { EQUAL } | ":" { COLON } | "," { COMMA } - | ['0'-'9']+ as lxm { INT(int_of_string lxm) } + | ['0'-'9']+ as lxm { INT(lxm) } | ('_' ? ['A'-'Z' 'a'-'z']('_' ? ['A'-'Z' 'a'-'z' ''' '0'-'9']) * as id) { let s = Lexing.lexeme lexbuf in try List.assoc s keyword_list diff --git a/sched/netlist_parser.mly b/sched/netlist_parser.mly index 0908703..1f76528 100644 --- a/sched/netlist_parser.mly +++ b/sched/netlist_parser.mly @@ -1,26 +1,16 @@ %{ open Netlist_ast - let value_of_int n = - let rec aux n = - let b = - match n mod 10 with - | 0 -> false - | 1 -> true - | i -> Format.eprintf "Unexpected: %d@." i; raise Parsing.Parse_error - in - if n < 10 then - [b] - else - b::(aux (n / 10)) - in - match aux n with - | [] -> Format.eprintf "Empty list@."; raise Parsing.Parse_error - | [b] -> VBit b - | bl -> VBitArray (Array.of_list (List.rev bl)) + let value_of_string n = + let ret = Array.make (String.length n) false in + for i = 0 to String.length n - 1 do + if n.[i] = '1' then ret.(i) <- true + done; + VBitArray(ret) + %} -%token <int> INT +%token <string> INT %token <string> NAME %token AND MUX NAND OR RAM ROM XOR REG NOT %token CONCAT SELECT SLICE @@ -50,21 +40,21 @@ exp: | XOR x=arg y=arg { Ebinop(Xor, x, y) } | MUX x=arg y=arg z=arg { Emux(x, y, z) } | ROM addr=INT word=INT ra=arg - { Erom(addr, word, ra) } + { Erom(int_of_string addr, int_of_string word, ra) } | RAM addr=INT word=INT ra=arg we=arg wa=arg data=arg - { Eram(addr, word, ra, we, wa, data) } + { Eram(int_of_string addr, int_of_string word, ra, we, wa, data) } | CONCAT x=arg y=arg { Econcat(x, y) } | SELECT idx=INT x=arg - { Eselect (idx, x) } + { Eselect (int_of_string idx, x) } | SLICE min=INT max=INT x=arg - { Eslice (min, max, x) } + { Eslice (int_of_string min, int_of_string max, x) } arg: - | n=INT { Aconst (value_of_int n) } + | n=INT { Aconst (value_of_string n) } | id=NAME { Avar id } var: x=NAME ty=ty_exp { (x, ty) } ty_exp: | /*empty*/ { TBit } - | COLON n=INT { TBitArray n } + | COLON n=INT { TBitArray (int_of_string n) } |