Update for improved HOL syntax for Datatypes

Summary:
HOL now lets us omit quotations on Datatypes and make them look more
like the other new-style HOL definitions.

Reviewed By: jberdine

Differential Revision: D16983934

fbshipit-source-id: f8ef3abb5
master
Scott Owens 5 years ago committed by Facebook Github Bot
parent 84883127af
commit 85243ada62

@ -16,22 +16,25 @@ numLib.prefer_num ();
(* ----- Abstract syntax ----- *) (* ----- Abstract syntax ----- *)
Datatype ` Datatype:
typ = typ =
| FunctionT typ (typ list) | FunctionT typ (typ list)
| IntegerT num | IntegerT num
| PointerT typ | PointerT typ
| ArrayT typ num | ArrayT typ num
| TupleT (typ list)`; | TupleT (typ list)
End
Datatype ` Datatype:
var = Var_name string`; var = Var_name string
End
Datatype ` Datatype:
label = Lab_name string string`; label = Lab_name string string
End
(* Based on the constructor functions in exp.mli rather than the type definition *) (* Based on the constructor functions in exp.mli rather than the type definition *)
Datatype ` Datatype:
exp = exp =
| Var var | Var var
| Nondet | Nondet
@ -52,9 +55,10 @@ Datatype `
(* Args: Record, index *) (* Args: Record, index *)
| Select exp exp | Select exp exp
(* Args: Record, index, value *) (* Args: Record, index, value *)
| Update exp exp exp`; | Update exp exp exp
End
Datatype ` Datatype:
inst = inst =
(* Args: the list of variable, expression assignments to do *) (* Args: the list of variable, expression assignments to do *)
| Move ((var # exp) list) | Move ((var # exp) list)
@ -74,9 +78,10 @@ Datatype `
| Free exp | Free exp
(* Args: result reg *) (* Args: result reg *)
| NondetI var | NondetI var
| Abort`; | Abort
End
Datatype ` Datatype:
term = term =
(* Args: key, branch table, default exp *) (* Args: key, branch table, default exp *)
| Switch exp ((num # label) list) label | Switch exp ((num # label) list) label
@ -87,53 +92,62 @@ Datatype `
| Call var label (exp list) typ label label | Call var label (exp list) typ label label
| Return exp | Return exp
| Throw exp | Throw exp
| Unreachable`; | Unreachable
End
Datatype ` Datatype:
block = <| cmnd : inst list; term : term |>`; block = <| cmnd : inst list; term : term |>
End
(* The llair code doesn't have params here yet, but it will need to *) (* The llair code doesn't have params here yet, but it will need to *)
Datatype ` Datatype:
func = <| params : var list; func = <| params : var list;
locals : var set; locals : var set;
entry : label; entry : label;
cfg : (label, block) alist; cfg : (label, block) alist;
freturn : var; freturn : var;
fthrow : var |>`; fthrow : var |>
End
(* The int is how much space the global needs *) (* The int is how much space the global needs *)
Datatype ` Datatype:
global = <| var : var; init : (exp # int) option; typ: typ |>`; global = <| var : var; init : (exp # int) option; typ: typ |>
End
Datatype ` Datatype:
llair = <| globals : global list; functions : (label, func) alist |>`; llair = <| globals : global list; functions : (label, func) alist |>
End
(* ----- Semantic states ----- *) (* ----- Semantic states ----- *)
(* TODO Given the similarities with LLVM, consider moving some definitions into (* TODO Given the similarities with LLVM, consider moving some definitions into
* a common predecessor theory *) * a common predecessor theory *)
Datatype ` Datatype:
addr = A num`; addr = A num
End
(* These are the values that can be stored in registers. The implementation uses (* These are the values that can be stored in registers. The implementation uses
* integers with a bit-width to represent numbers, and keeps locations and sizes * integers with a bit-width to represent numbers, and keeps locations and sizes
* separate. * separate.
*) *)
Datatype ` Datatype:
v = v =
| LocV num | LocV num
| SizeV num | SizeV num
| IntV int num | IntV int num
| AggV (v list)`; | AggV (v list)
End
Datatype ` Datatype:
pc = <| l : label; i : num |>`; pc = <| l : label; i : num |>
End
Datatype ` Datatype:
frame = <| ret : pc; exn_ret : pc; ret_var : var; saved_locals : var |-> v; |>`; frame = <| ret : pc; exn_ret : pc; ret_var : var; saved_locals : var |-> v; |>
End
Datatype ` Datatype:
state = state =
<| ip : pc; <| ip : pc;
globals : var |-> word64; globals : var |-> word64;
@ -147,7 +161,8 @@ Datatype `
* semantics. *) * semantics. *)
allocations : (num # num) set; allocations : (num # num) set;
(* A byte addressed heap *) (* A byte addressed heap *)
heap : addr |-> word8 |>`; heap : addr |-> word8 |>
End
(* ----- Semantic transitions ----- *) (* ----- Semantic transitions ----- *)

@ -18,47 +18,56 @@ numLib.prefer_num ();
(* ----- Abstract syntax ----- *) (* ----- Abstract syntax ----- *)
(* Only support 1, 8, 32, and 64 bit words for now *) (* Only support 1, 8, 32, and 64 bit words for now *)
Datatype ` Datatype:
size = W1 | W8 | W32 | W64`; size = W1 | W8 | W32 | W64
End
Datatype ` Datatype:
ty = ty =
| FunT ty (ty list) | FunT ty (ty list)
| IntT size | IntT size
| PtrT ty | PtrT ty
| ArrT num ty | ArrT num ty
| StrT (ty list)`; | StrT (ty list)
End
Datatype ` Datatype:
label = Lab string`; label = Lab string
End
Datatype ` Datatype:
reg = Reg string`; reg = Reg string
End
Datatype ` Datatype:
glob_var = Glob_var string`; glob_var = Glob_var string
End
Datatype ` Datatype:
fun_name = Fn string`; fun_name = Fn string
End
Datatype ` Datatype:
const = const =
| IntC size int | IntC size int
| StrC ((ty # const) list) | StrC ((ty # const) list)
| ArrC ((ty # const) list) | ArrC ((ty # const) list)
| GepC ty const (ty # const) ((ty # const) list) | GepC ty const (ty # const) ((ty # const) list)
| GlobalC glob_var | GlobalC glob_var
| UndefC`; | UndefC
End
Datatype ` Datatype:
arg = Constant const | Variable reg`; arg = Constant const | Variable reg
End
type_abbrev ("targ", ``:ty # arg``); Type targ = ``:ty # arg``
Datatype ` Datatype:
cond = Eq | Ult | Slt`; cond = Eq | Ult | Slt
End
Datatype ` Datatype:
instr = instr =
(* Terminators *) (* Terminators *)
| Ret targ | Ret targ
@ -82,33 +91,40 @@ Datatype `
| Cxa_throw arg arg arg | Cxa_throw arg arg arg
| Cxa_begin_catch reg arg | Cxa_begin_catch reg arg
| Cxa_end_catch | Cxa_end_catch
| Cxa_get_exception_ptr reg arg`; | Cxa_get_exception_ptr reg arg
End
Datatype ` Datatype:
phi = Phi reg ty ((label option, arg) alist)`; phi = Phi reg ty ((label option, arg) alist)
End
Datatype ` Datatype:
clause = Catch targ`; clause = Catch targ
End
Datatype ` Datatype:
landingpad = Landingpad ty bool (clause list)`; landingpad = Landingpad ty bool (clause list)
End
Datatype ` Datatype:
blockHeader = blockHeader =
| Entry | Entry
| Head (phi list) (landingpad option)`; | Head (phi list) (landingpad option)
End
Datatype ` Datatype:
block = <| h : blockHeader; body : instr list |>`; block = <| h : blockHeader; body : instr list |>
End
Datatype ` Datatype:
def = def =
<| r : ty; <| r : ty;
params : reg list; params : reg list;
(* None -> entry block, and Some name -> non-entry block *) (* None -> entry block, and Some name -> non-entry block *)
blocks : (label option, block) alist |>`; blocks : (label option, block) alist |>
End
type_abbrev ("prog", ``:(fun_name, def) alist``); Type prog = ``:(fun_name, def) alist``
Definition terminator_def: Definition terminator_def:
(terminator (Ret _) T) (terminator (Ret _) T)
@ -120,10 +136,11 @@ End
(* ----- Semantic states ----- *) (* ----- Semantic states ----- *)
Datatype ` Datatype:
addr = A num`; addr = A num
End
Datatype ` Datatype:
v = v =
| W1V word1 | W1V word1
| W8V word8 | W8V word8
@ -131,18 +148,22 @@ Datatype `
| W64V word64 | W64V word64
| AggV (v list) | AggV (v list)
| PtrV word64 | PtrV word64
| UndefV`; | UndefV
End
Datatype ` Datatype:
pv = <| poison : bool; value : v |>`; pv = <| poison : bool; value : v |>
End
Datatype ` Datatype:
pc = <| f : fun_name; b : label option; i : num |>`; pc = <| f : fun_name; b : label option; i : num |>
End
Datatype ` Datatype:
frame = <| ret : pc; saved_locals : reg |-> pv; result_var : reg; stack_allocs : addr list |>`; frame = <| ret : pc; saved_locals : reg |-> pv; result_var : reg; stack_allocs : addr list |>
End
Datatype ` Datatype:
state = state =
<| ip : pc; <| ip : pc;
(* Keep the size of the global with its memory address *) (* Keep the size of the global with its memory address *)
@ -153,7 +174,8 @@ Datatype `
* free-able or not *) * free-able or not *)
allocations : (bool # num # num) set; allocations : (bool # num # num) set;
(* A byte addressed heap, with a poison tag *) (* A byte addressed heap, with a poison tag *)
heap : addr |-> bool # word8 |>`; heap : addr |-> bool # word8 |>
End
(* ----- Things about types ----- *) (* ----- Things about types ----- *)

@ -180,12 +180,13 @@ Definition translate_instr_to_term_def:
Iswitch (translate_arg emap a) [translate_label f l2; translate_label f l1] Iswitch (translate_arg emap a) [translate_label f l2; translate_label f l1]
End End
Datatype ` Datatype:
instr_class = instr_class =
| Exp reg | Exp reg
| Non_exp | Non_exp
| Term | Term
| Call`; | Call
End
Definition classify_instr_def: Definition classify_instr_def:
(classify_instr (Call _ _ _ _) = Call) (classify_instr (Call _ _ _ _) = Call)

Loading…
Cancel
Save