-
Notifications
You must be signed in to change notification settings - Fork 11
/
CircuitSemantics.v
39 lines (33 loc) · 1.19 KB
/
CircuitSemantics.v
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
(*! Circuits | Interpretation of circuits !*)
Require Export Koika.Common Koika.Environments Koika.CircuitSyntax.
Import PrimTyped CircuitSignatures.
Section Interpretation.
Context {rule_name_t reg_t ext_fn_t: Type}.
Context {CR: reg_t -> nat}.
Context {CSigma: ext_fn_t -> CExternalSignature}.
Context {REnv: Env reg_t}.
Context (cr: REnv.(env_t) (fun idx => bits (CR (idx)))).
Context (csigma: forall f, CSig_denote (CSigma f)).
Context {rwdata: nat -> Type}.
Notation circuit := (@circuit rule_name_t reg_t ext_fn_t rwdata CR CSigma).
Fixpoint interp_circuit {n} (c: circuit n) : bits n :=
match c with
| CMux select c1 c2 =>
if Bits.single (interp_circuit select) then interp_circuit c1
else interp_circuit c2
| CConst cst =>
cst
| CReadRegister idx =>
REnv.(getenv) cr idx
| CExternal fn arg =>
csigma fn (interp_circuit arg)
| CUnop fn arg1 =>
PrimSpecs.sigma1 (Bits1 fn) (interp_circuit arg1)
| CBinop fn arg1 arg2 =>
PrimSpecs.sigma2 (Bits2 fn) (interp_circuit arg1) (interp_circuit arg2)
| CBundleRef _ _ _ _ c =>
interp_circuit c
| CAnnot _ c =>
interp_circuit c
end.
End Interpretation.