summaryrefslogtreecommitdiff
path: root/sched/netlist_parser.mly
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2013-11-07 11:05:54 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2013-11-07 11:05:54 +0100
commite78802739247d120d6694993675e5a2a1cd6debb (patch)
tree719e659b286fddaacf3de40d7679d4062711961d /sched/netlist_parser.mly
parentf57717d1a662d519515d5431198709bcb703b8dd (diff)
downloadSystDigit-Projet-e78802739247d120d6694993675e5a2a1cd6debb.tar.gz
SystDigit-Projet-e78802739247d120d6694993675e5a2a1cd6debb.zip
Correction to netlist parser (not taken into account in the caml simulator, which is kind of abandonned).
Diffstat (limited to 'sched/netlist_parser.mly')
-rw-r--r--sched/netlist_parser.mly38
1 files changed, 14 insertions, 24 deletions
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) }