Skip to content

Commit

Permalink
Rename StoreTrunc to StoreWrap for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewagner committed Sep 30, 2015
1 parent 1c9d69b commit 74c0752
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 20 deletions.
10 changes: 4 additions & 6 deletions ml-proto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ type expr =
| GetParam of var (* read parameter
| GetLocal of var (* read local variable
| SetLocal of var * expr (* write local variable
| LoadGlobal of var (* read global variable
| StoreGlobal of var * expr (* write global variable
| Load of loadop * expr (* read memory address
| Store of storeop * expr * expr (* write memory address
| Load of memop * expr (* read memory address
| Store of memop * expr * expr (* write memory address
| LoadExtend of extendop * expr (* read memory address with sign- or zero-extension
| StoreWrap of wrapop * expr * expr (* write memory address with wrapping
| Const of value (* constant
| Unary of unop * expr (* unary arithmetic operator
| Binary of binop * expr * expr (* binary arithmetic operator
Expand Down Expand Up @@ -178,8 +178,6 @@ expr:
( return <expr>? )
( get_local <var> )
( set_local <var> <expr> )
( load_global <var> )
( store_global <var> <expr> )
( <type>.load((8|16)_<sign>)?(/<align>)? <expr> )
( <type>.store(/<align>)? <expr> <expr> )
( <type>.const <value> )
Expand Down
6 changes: 3 additions & 3 deletions ml-proto/src/host/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ let extension = function
let extendop t sz s a =
{memop = memop t a; sz = mem_size sz; ext = extension s}

let truncop t sz a =
let wrapop t sz a =
{memop = memop t a; sz = mem_size sz}
}

Expand Down Expand Up @@ -147,9 +147,9 @@ rule token = parse
| (ixx as t)".load"(mem_size as sz)"_"(sign as s)"/"(align as a)
{ LOADEXTEND (extendop t sz s a) }
| (ixx as t)".store"(mem_size as sz)
{ STORETRUNC (truncop t sz "") }
{ STOREWRAP (wrapop t sz "") }
| (ixx as t)".store"(mem_size as sz)"/"(align as a)
{ STORETRUNC (truncop t sz a) }
{ STOREWRAP (wrapop t sz a) }

| (nxx as t)".switch" { SWITCH (value_type t) }
| (nxx as t)".const" { CONST (value_type t) }
Expand Down
4 changes: 2 additions & 2 deletions ml-proto/src/host/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ let anon_label c = {c with labels = VarMap.map ((+) 1) c.labels}
%token<Ast.memop> LOAD
%token<Ast.memop> STORE
%token<Ast.extendop> LOADEXTEND
%token<Ast.truncop> STORETRUNC
%token<Ast.wrapop> STOREWRAP

%start script
%type<Script.script> script
Expand Down Expand Up @@ -182,7 +182,7 @@ oper :
| LOAD expr { fun c -> Load ($1, $2 c) }
| STORE expr expr { fun c -> Store ($1, $2 c, $3 c) }
| LOADEXTEND expr { fun c -> LoadExtend ($1, $2 c) }
| STORETRUNC expr expr { fun c -> StoreTrunc ($1, $2 c, $3 c) }
| STOREWRAP expr expr { fun c -> StoreWrap ($1, $2 c, $3 c) }
| CONST literal { let at = at() in fun c -> Const (literal at $2 $1) }
| UNARY expr { fun c -> Unary ($1, $2 c) }
| BINARY expr expr { fun c -> Binary ($1, $2 c, $3 c) }
Expand Down
4 changes: 2 additions & 2 deletions ml-proto/src/spec/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type cvt = (Int32Op.cvt, Int64Op.cvt, Float32Op.cvt, Float64Op.cvt) op

type memop = {ty : Types.value_type; align : int option}
type extendop = {memop : memop; sz : Memory.mem_size; ext : Memory.extension}
type truncop = {memop : memop; sz : Memory.mem_size}
type wrapop = {memop : memop; sz : Memory.mem_size}

(* Expressions *)

Expand All @@ -90,7 +90,7 @@ and expr' =
| Load of memop * expr
| Store of memop * expr * expr
| LoadExtend of extendop * expr
| StoreTrunc of truncop * expr * expr
| StoreWrap of wrapop * expr * expr
| Const of literal
| Unary of unop * expr
| Binary of binop * expr * expr
Expand Down
6 changes: 3 additions & 3 deletions ml-proto/src/spec/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ let rec check_expr c et e =
check_mem_type extendop.memop.ty extendop.sz e.at;
check_load c et extendop.memop e1 e.at

| StoreTrunc (truncop, e1, e2) ->
check_mem_type truncop.memop.ty truncop.sz e.at;
check_store c et truncop.memop e1 e2 e.at
| StoreWrap (wrapop, e1, e2) ->
check_mem_type wrapop.memop.ty wrapop.sz e.at;
check_store c et wrapop.memop e1 e2 e.at

| Const v ->
check_literal c et v
Expand Down
4 changes: 2 additions & 2 deletions ml-proto/src/spec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ let rec eval_expr (c : config) (e : expr) =
(try Some (Memory.load_extend c.modul.memory a sz ext ty)
with exn -> memory_error e.at exn)

| StoreTrunc ({memop = {ty; align = _}; sz}, e1, e2) ->
| StoreWrap ({memop = {ty; align = _}; sz}, e1, e2) ->
let v1 = some (eval_expr c e1) e1.at in
let v2 = some (eval_expr c e2) e2.at in
let a = Memory.address_of_value v1 in
(try Memory.store_trunc c.modul.memory a sz v2
(try Memory.store_wrap c.modul.memory a sz v2
with exn -> memory_error e.at exn);
None

Expand Down
2 changes: 1 addition & 1 deletion ml-proto/src/spec/memory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ let load_extend mem a sz ext t =
| Mem32, SX, Int64Type -> Int64 (loadn_sx mem 4 a)
| _ -> raise Type

let store_trunc mem a sz v =
let store_wrap mem a sz v =
match sz, v with
| Mem8, Int32 x -> storen mem 1 a (Int64.of_int32 x)
| Mem8, Int64 x -> storen mem 1 a x
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/src/spec/memory.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ val resize : memory -> size -> unit
val load : memory -> address -> value_type -> value
val store : memory -> address -> value -> unit
val load_extend : memory -> address -> mem_size -> extension -> value_type -> value
val store_trunc : memory -> address -> mem_size -> value -> unit
val store_wrap : memory -> address -> mem_size -> value -> unit

val address_of_value : Values.value -> address

0 comments on commit 74c0752

Please sign in to comment.