Commit 4e9dd27b authored by Aliaume Lopez's avatar Aliaume Lopez

Adding AND and OR gates

parent 7c6417b8
...@@ -151,6 +151,8 @@ let convert_label = function ...@@ -151,6 +151,8 @@ let convert_label = function
| "PMOS" -> Gate Pmos | "PMOS" -> Gate Pmos
| "WAIT" -> Gate Wait | "WAIT" -> Gate Wait
| "DISC" -> Disconnect | "DISC" -> Disconnect
| "OR" -> Gate Or
| "AND" -> Gate And
| "FORK" -> Gate Fork | "FORK" -> Gate Fork
| "JOIN" -> Gate Join | "JOIN" -> Gate Join
| x -> Gate (Box x) | x -> Gate (Box x)
...@@ -300,6 +302,7 @@ let rewrite_local rules ptg = ...@@ -300,6 +302,7 @@ let rewrite_local rules ptg =
while not (!inter == !older) do (* test physical equality in constant time *) while not (!inter == !older) do (* test physical equality in constant time *)
older := !inter; older := !inter;
inter := apply_local_rules rules !inter; inter := apply_local_rules rules !inter;
report "LOCAL REWRITE RULE APPLY" !inter;
done; done;
!inter;; !inter;;
......
let NAND1 = (2 | LOW) . (1 | NMOS) . NMOS in link xO:xI yO:yI for
let NAND2 = (HIGH | 1 | HIGH | 1) . (NMOS | NMOS) . JOIN in PAR
let NAND = xO:
link a0:a1 b0:b1 c1:c0 for (:xI | :yI) . AND
PAR (:yI | :xI) . OR . yO:
(a0: | b0:) . :c0 END
(:a1 | :b1) . NAND1 . c1:
(:a1 | :b1) . NAND2 . c1:
END in
(HIGH | LOW) . NAND
...@@ -166,6 +166,8 @@ let circuit_of_name = function ...@@ -166,6 +166,8 @@ let circuit_of_name = function
| "DISC" -> const "DISC" 1 0 | "DISC" -> const "DISC" 1 0
| "FORK" -> const "FORK" 1 2 | "FORK" -> const "FORK" 1 2
| "JOIN" -> const "JOIN" 2 1 | "JOIN" -> const "JOIN" 2 1
| "AND" -> const "AND" 2 1
| "OR" -> const "OR" 2 1
| x -> const x 1 1;; | x -> const x 1 1;;
(**** THE GRAMMAR (**** THE GRAMMAR
......
...@@ -97,6 +97,8 @@ type gate = ...@@ -97,6 +97,8 @@ type gate =
| Join | Join
| Nmos | Nmos
| Pmos | Pmos
| And
| Or
| Box of string | Box of string
| Wait | Wait
| Mux;; | Mux;;
...@@ -189,6 +191,8 @@ let string_of_gate = function ...@@ -189,6 +191,8 @@ let string_of_gate = function
| Pmos -> "P" | Pmos -> "P"
| Box s -> "B " ^ s | Box s -> "B " ^ s
| Wait -> "W" | Wait -> "W"
| And -> "AND"
| Or -> "OR"
| Mux -> "M";; | Mux -> "M";;
let rec string_of_value = function let rec string_of_value = function
......
...@@ -220,7 +220,34 @@ let reduce_pmos inputs = ...@@ -220,7 +220,34 @@ let reduce_pmos inputs =
with with
Match_failure _ -> NoOP;; Match_failure _ -> NoOP;;
(* A small function that gives the lowest common
(* The gate function for the AND gate *)
let reduce_and inputs =
try
let [a;b] = inputs in
match (a,b) with
| Some (Value Low), _ -> Result Low
| _, Some (Value Low) -> Result Low
| Some (Value High), Some (Value High) -> Result High
| _ -> NoOP
with
Match_failure _ -> NoOP;;
(* The gate function for the OR gate *)
let reduce_or inputs =
try
let [a;b] = inputs in
match (a,b) with
| Some (Value High), _ -> Result High
| _ , Some (Value High) -> Result High
| Some (Value Low), Some (Value Low) -> Result Low
| _ -> NoOP
with
Match_failure _ -> NoOP;;
(*
* A small function that gives the lowest common
* ancestor for two values of the lattice * ancestor for two values of the lattice
*) *)
let combine_values v1 v2 = match (v1,v2) with let combine_values v1 v2 = match (v1,v2) with
...@@ -264,6 +291,8 @@ let fun_of_gate = function ...@@ -264,6 +291,8 @@ let fun_of_gate = function
| Nmos -> reduce_nmos | Nmos -> reduce_nmos
| Pmos -> reduce_pmos | Pmos -> reduce_pmos
| Join -> reduce_join | Join -> reduce_join
| And -> reduce_and
| Or -> reduce_or
| _ -> (fun _ -> NoOP);; | _ -> (fun _ -> NoOP);;
(** (**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment