Skip to content

Commit

Permalink
heterogeneous bv operators
Browse files Browse the repository at this point in the history
  • Loading branch information
strub committed Oct 11, 2024
1 parent 4411b4c commit 9b02e43
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 147 deletions.
8 changes: 4 additions & 4 deletions src/ecCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,10 @@ and process_dump scope (source, tc) =
(* -------------------------------------------------------------------- *)
and process_crbind (scope : EcScope.scope) (binding : pcrbinding) =
match binding.binding with
| CRB_Bitstring bs -> EcScope.Circuit.add_bitstring scope binding.locality bs
| CRB_Array ba -> EcScope.Circuit.add_bsarray scope binding.locality ba
| CRB_BvOperator op -> EcScope.Circuit.add_qfabvop scope binding.locality op
| CRB_Circuit cr -> EcScope.Circuit.add_circuit scope binding.locality cr
| CRB_Bitstring bs -> EcScope.Circuit.add_bitstring scope binding.locality bs
| CRB_Array ba -> EcScope.Circuit.add_array scope binding.locality ba
| CRB_BvOperator op -> EcScope.Circuit.add_bvoperator scope binding.locality op
| CRB_Circuit cr -> EcScope.Circuit.add_circuit scope binding.locality cr

(* -------------------------------------------------------------------- *)
and process (ld : Loader.loader) (scope : EcScope.scope) g =
Expand Down
39 changes: 23 additions & 16 deletions src/ecDecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ type ty_params = ty_param list
type ty_pctor = [ `Int of int | `Named of ty_params ]

type tydecl = {
tyd_params : ty_params;
tyd_type : ty_body;
tyd_loca : locality;
tyd_resolve : bool;
tyd_params : ty_params;
tyd_type : ty_body;
tyd_loca : locality;
tyd_resolve : bool;
tyd_clinline : bool;
}

and ty_body = [
Expand Down Expand Up @@ -60,7 +61,11 @@ let abs_tydecl ?(resolve = true) ?(tc = Sp.empty) ?(params = `Int 0) lc =
(EcUid.NameGen.bulk ~fmt n)
in

{ tyd_params = params; tyd_type = `Abstract tc; tyd_resolve = resolve; tyd_loca = lc; }
{ tyd_params = params
; tyd_type = `Abstract tc
; tyd_resolve = resolve
; tyd_loca = lc
; tyd_clinline = false }

(* -------------------------------------------------------------------- *)
let ty_instanciate (params : ty_params) (args : ty list) (ty : ty) =
Expand Down Expand Up @@ -361,21 +366,23 @@ type crb_array =
; size : int }

type bv_opkind = [
| `Add of int
| `Sub of int
| `Mul of int
| `UDiv of int
| `URem of int
| `Shl of int
| `Shr of int
| `And of int
| `Or of int
| `Not of int
| `Add of int
| `Sub of int
| `Mul of int
| `UDiv of int
| `URem of int
| `Shl of int
| `Shr of int
| `And of int
| `Or of int
| `Not of int
| `ZExtend of int * int
| `Truncate of int * int
]

type crb_bvoperator =
{ kind : bv_opkind
; type_ : EcPath.path
; types : EcPath.path list
; operator : EcPath.path
; theory : EcPath.path }

Expand Down
33 changes: 18 additions & 15 deletions src/ecDecl.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ type ty_params = ty_param list
type ty_pctor = [ `Int of int | `Named of ty_params ]

type tydecl = {
tyd_params : ty_params;
tyd_type : ty_body;
tyd_loca : locality;
tyd_resolve : bool;
tyd_params : ty_params;
tyd_type : ty_body;
tyd_loca : locality;
tyd_resolve : bool;
tyd_clinline : bool;
}

and ty_body = [
Expand Down Expand Up @@ -211,21 +212,23 @@ type crb_array =
; size : int }

type bv_opkind = [
| `Add of int
| `Sub of int
| `Mul of int
| `UDiv of int
| `URem of int
| `Shl of int
| `Shr of int
| `And of int
| `Or of int
| `Not of int
| `Add of int
| `Sub of int
| `Mul of int
| `UDiv of int
| `URem of int
| `Shl of int
| `Shr of int
| `And of int
| `Or of int
| `Not of int
| `ZExtend of int * int
| `Truncate of int * int
]

type crb_bvoperator =
{ kind : bv_opkind
; type_ : EcPath.path
; types : EcPath.path list
; operator : EcPath.path
; theory : EcPath.path }

Expand Down
9 changes: 5 additions & 4 deletions src/ecHiInductive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ let trans_datatype (env : EcEnv.env) (name : ptydname) (dt : pdatatype) =
let tpath = EcPath.pqname (EcEnv.root env) (unloc name) in
let env0 =
let myself = {
tyd_params = EcUnify.UniEnv.tparams ue;
tyd_type = `Abstract EcPath.Sp.empty;
tyd_loca = lc;
tyd_resolve = true;
tyd_params = EcUnify.UniEnv.tparams ue;
tyd_type = `Abstract EcPath.Sp.empty;
tyd_loca = lc;
tyd_resolve = true;
tyd_clinline = false;
} in
EcEnv.Ty.bind (unloc name) myself env
in
Expand Down
5 changes: 4 additions & 1 deletion src/ecParser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -3898,7 +3898,10 @@ cr_binding_r:
{ CRB_Array { get; set; tolist; type_; size; } }

| BIND OP type_=loc(simpl_type_exp) operator=qoident name=loc(STRING)
{ CRB_BvOperator { type_; operator; name; } }
{ CRB_BvOperator { types = [type_]; operator; name; } }

| BIND OP types=bracket(plist1(loc(simpl_type_exp), AMP)) operator=qoident name=loc(STRING)
{ CRB_BvOperator { types; operator; name; } }

| BIND CIRCUIT operator=qoident circuit=loc(STRING)
{ CRB_Circuit { operator; circuit; } }
Expand Down
2 changes: 1 addition & 1 deletion src/ecParsetree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ type pbind_array =
(* -------------------------------------------------------------------- *)
type pbind_bvoperator =
{ name : string located
; type_ : pty
; types : pty list
; operator : pqsymbol }

(* -------------------------------------------------------------------- *)
Expand Down
26 changes: 14 additions & 12 deletions src/ecPrinting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3393,20 +3393,22 @@ let rec pp_theory ppe (fmt : Format.formatter) (path, cth) =
| CRB_BvOperator op ->
let kind =
match op.kind with
| `Add _ -> "add"
| `Sub _ -> "sub"
| `Mul _ -> "mul"
| `UDiv _ -> "udiv"
| `URem _ -> "urem"
| `Shl _ -> "shl"
| `Shr _ -> "shr"
| `Not _ -> "not"
| `And _ -> "and"
| `Or _ -> "or"
| `Add _ -> "add"
| `Sub _ -> "sub"
| `Mul _ -> "mul"
| `UDiv _ -> "udiv"
| `URem _ -> "urem"
| `Shl _ -> "shl"
| `Shr _ -> "shr"
| `Not _ -> "not"
| `And _ -> "and"
| `Or _ -> "or"
| `ZExtend _ -> "zextend"
| `Truncate _ -> "truncate"
in
Format.fprintf fmt "%abind op %a %a \"%s\""
Format.fprintf fmt "%abind op [%a] %a \"%s\"."
pp_locality lc
(pp_tyname ppe) op.type_
(pp_list " & " (pp_tyname ppe)) op.types
(pp_opname ppe) op.operator
kind

Expand Down
Loading

0 comments on commit 9b02e43

Please sign in to comment.