From 86b4687d2259a1cc174cdc78530e4bed934c88fe Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Wed, 16 Sep 2015 17:47:27 -0500 Subject: [PATCH] Remove globals to match MVP in design repo --- ml-proto/src/host/lexer.mll | 4 ---- ml-proto/src/host/parser.mly | 23 +++++------------------ ml-proto/src/host/print.ml | 6 +----- ml-proto/src/spec/ast.ml | 3 --- ml-proto/src/spec/check.ml | 16 +++------------- ml-proto/src/spec/eval.ml | 23 ++++------------------- ml-proto/test/forward.wasm | 3 --- 7 files changed, 13 insertions(+), 65 deletions(-) diff --git a/ml-proto/src/host/lexer.mll b/ml-proto/src/host/lexer.mll index ba82751a1f..28602a104b 100644 --- a/ml-proto/src/host/lexer.mll +++ b/ml-proto/src/host/lexer.mll @@ -143,9 +143,6 @@ rule token = parse | "get_local" { GETLOCAL } | "set_local" { SETLOCAL } - | "load_global" { LOADGLOBAL } - | "store_global" { STOREGLOBAL } - | (nxx as t)".load" { LOAD (loadop t ' ' "") } | (nxx as t)".load/"(align as a) { LOAD (loadop t ' ' a) } | (ixx)".load"(width as w)"_"(sign as s) { LOAD (loadop ("i" ^ w) s "") } @@ -246,7 +243,6 @@ rule token = parse | "module" { MODULE } | "memory" { MEMORY } | "segment" { SEGMENT } - | "global" { GLOBAL } | "import" { IMPORT } | "export" { EXPORT } | "table" { TABLE } diff --git a/ml-proto/src/host/parser.mly b/ml-proto/src/host/parser.mly index 81ce2c72f4..d1fe224f17 100644 --- a/ml-proto/src/host/parser.mly +++ b/ml-proto/src/host/parser.mly @@ -47,14 +47,12 @@ module VarMap = Map.Make(String) type space = {mutable map : int VarMap.t; mutable count : int} type context = - {funcs : space; imports : space; globals : space; locals : space; - labels : int VarMap.t} + {funcs : space; imports : space; locals : space; labels : int VarMap.t} let empty () = {map = VarMap.empty; count = 0} let c0 () = {funcs = empty (); imports = empty (); - globals = empty (); locals = empty (); - labels = VarMap.empty} + locals = empty (); labels = VarMap.empty} let enter_func c = assert (VarMap.is_empty c.labels); @@ -66,7 +64,6 @@ let lookup category space x = let func c x = lookup "function" c.funcs x let import c x = lookup "import" c.imports x -let global c x = lookup "global" c.globals x let local c x = lookup "local" c.locals x let table c x = lookup "table" (empty ()) x let label c x = @@ -81,7 +78,6 @@ let bind category space x = let bind_func c x = bind "function" c.funcs x let bind_import c x = bind "import" c.imports x -let bind_global c x = bind "global" c.globals x let bind_local c x = bind "local" c.locals x let bind_label c x = if VarMap.mem x.it c.labels then @@ -92,7 +88,6 @@ let anon space n = space.count <- space.count + n let anon_func c = anon c.funcs 1 let anon_import c = anon c.imports 1 -let anon_globals c ts = anon c.globals (List.length ts) let anon_locals c ts = anon c.locals (List.length ts) let anon_label c = {c with labels = VarMap.map ((+) 1) c.labels} %} @@ -100,9 +95,9 @@ let anon_label c = {c with labels = VarMap.map ((+) 1) c.labels} %token INT FLOAT TEXT VAR TYPE LPAR RPAR %token NOP BLOCK IF LOOP LABEL BREAK SWITCH CASE FALLTHROUGH %token CALL CALLIMPORT CALLINDIRECT RETURN -%token GETLOCAL SETLOCAL LOADGLOBAL STOREGLOBAL LOAD STORE +%token GETLOCAL SETLOCAL LOAD STORE %token CONST UNARY BINARY COMPARE CONVERT -%token FUNC PARAM RESULT LOCAL MODULE MEMORY SEGMENT GLOBAL IMPORT EXPORT TABLE +%token FUNC PARAM RESULT LOCAL MODULE MEMORY SEGMENT IMPORT EXPORT TABLE %token PAGESIZE MEMORYSIZE RESIZEMEMORY %token ASSERTINVALID ASSERTEQ ASSERTFAULT INVOKE %token EOF @@ -182,8 +177,6 @@ oper : | RETURN expr_opt { fun c -> Return ($2 c) } | GETLOCAL var { fun c -> GetLocal ($2 c local) } | SETLOCAL var expr { fun c -> SetLocal ($2 c local, $3 c) } - | LOADGLOBAL var { fun c -> LoadGlobal ($2 c global) } - | STOREGLOBAL var expr { fun c -> StoreGlobal ($2 c global, $3 c) } | LOAD expr { fun c -> Load ($1, $2 c) } | STORE expr expr { fun c -> Store ($1, $2 c, $3 c) } | CONST literal { fun c -> Const (literal (ati 2) $2 $1) } @@ -312,7 +305,7 @@ export : module_fields : | /* empty */ { fun c -> - {imports = []; exports = []; globals = []; tables = []; funcs = []; + {imports = []; exports = []; tables = []; funcs = []; memory = None} } | func module_fields { fun c -> let f = $1 c in let m = $2 c in @@ -323,12 +316,6 @@ module_fields : | export module_fields { fun c -> let m = $2 c in {m with exports = $1 c :: m.exports} } - | LPAR GLOBAL value_type_list RPAR module_fields - { fun c -> anon_globals c $3; let m = $5 c in - {m with globals = $3 @ m.globals} } - | LPAR GLOBAL bind_var value_type RPAR module_fields /* Sugar */ - { fun c -> bind_global c $3; let m = $6 c in - {m with globals = $4 :: m.globals} } | LPAR TABLE var_list RPAR module_fields { fun c -> let m = $5 c in {m with tables = ($3 c func @@ ati 3) :: m.tables} } diff --git a/ml-proto/src/host/print.ml b/ml-proto/src/host/print.ml index 9ee8f238ac..15b29a33d9 100644 --- a/ml-proto/src/host/print.ml +++ b/ml-proto/src/host/print.ml @@ -38,9 +38,6 @@ let print_table_sig prefix i t_opt = let print_func i f = print_func_sig "func" i f -let print_global i t = - print_var_sig "global" i t - let print_export m i ex = print_export_sig "export" ex.it.name (List.nth m.it.funcs ex.it.func.it) @@ -53,9 +50,8 @@ let print_table m i tab = let print_module m = - let {funcs; globals; exports; tables} = m.it in + let {funcs; exports; tables} = m.it in List.iteri print_func funcs; - List.iteri print_global globals; List.iteri (print_export m) exports; List.iteri (print_table m) tables; flush_all () diff --git a/ml-proto/src/spec/ast.ml b/ml-proto/src/spec/ast.ml index 39677ff863..c6bb8cb927 100644 --- a/ml-proto/src/spec/ast.ml +++ b/ml-proto/src/spec/ast.ml @@ -87,8 +87,6 @@ and expr' = | Return of expr option | GetLocal of var | SetLocal of var * expr - | LoadGlobal of var - | StoreGlobal of var * expr | Load of loadop * expr | Store of storeop * expr * expr | Const of literal @@ -151,5 +149,4 @@ and modul' = imports : import list; exports : export list; tables : table list; - globals : value_type list } diff --git a/ml-proto/src/spec/check.ml b/ml-proto/src/spec/check.ml index 073d2ef33b..e61cc58329 100644 --- a/ml-proto/src/spec/check.ml +++ b/ml-proto/src/spec/check.ml @@ -19,7 +19,6 @@ type context = { funcs : func_type list; imports : func_type list; - globals : value_type list; tables : func_type list; locals : value_type list; return : expr_type; @@ -27,7 +26,7 @@ type context = } let c0 = - {funcs = []; imports = []; globals = []; tables = []; + {funcs = []; imports = []; tables = []; locals = []; return = None; labels = []} let lookup category list x = @@ -37,7 +36,6 @@ let lookup category list x = let func c x = lookup "function" c.funcs x let import c x = lookup "import" c.imports x let local c x = lookup "local" c.locals x -let global c x = lookup "global" c.globals x let table c x = lookup "table" c.tables x let label c x = lookup "label" c.labels x @@ -184,13 +182,6 @@ let rec check_expr c et e = check_expr c (Some (local c x)) e1; check_type None et e.at - | LoadGlobal x -> - check_type (Some (global c x)) et e.at - - | StoreGlobal (x, e1) -> - check_expr c (Some (global c x)) e1; - check_type None et e.at - | Load (loadop, e1) -> check_align loadop.align e.at; check_expr c (Some Int32Type) e1; @@ -311,11 +302,10 @@ let check_memory memory = ignore (List.fold_left (check_segment memory.it.initial) 0 memory.it.segments) let check_module m = - let {imports; exports; globals; tables; funcs; memory} = m.it in + let {imports; exports; tables; funcs; memory} = m.it in Lib.Option.app check_memory memory; let c = {c0 with funcs = List.map type_func funcs; - imports = List.map type_import imports; - globals = List.map it globals} in + imports = List.map type_import imports} in let c' = List.fold_left check_table c tables in List.iter (check_func c') funcs; ignore (List.fold_left (check_export c') NameSet.empty exports) diff --git a/ml-proto/src/spec/eval.ml b/ml-proto/src/spec/eval.ml index a9d81d8136..a7034f2b72 100644 --- a/ml-proto/src/spec/eval.ml +++ b/ml-proto/src/spec/eval.ml @@ -25,7 +25,6 @@ type instance = imports : import list; exports : export_map; tables : func list list; - globals : value ref list; memory : Memory.t; host : host_params } @@ -52,7 +51,6 @@ let lookup category list x = let func c x = lookup "function" c.modul.funcs x let import c x = lookup "import" c.modul.imports x -let global c x = lookup "global" c.modul.globals x let table c x y = lookup "entry" (lookup "table" c.modul.tables x) y let local c x = lookup "local" c.locals x let label c x = lookup "label" c.labels x @@ -160,14 +158,6 @@ let rec eval_expr (c : config) (e : expr) = local c x := v1; None - | LoadGlobal x -> - Some !(global c x) - - | StoreGlobal (x, e1) -> - let v1 = some (eval_expr c e1) e1.at in - global c x := v1; - None - | Load ({mem; ext; align = _}, e1) -> let v1 = some (eval_expr c e1) e1.at in (try Some (Memory.load c.modul.memory (Memory.address_of_value v1) mem ext) @@ -237,13 +227,10 @@ and eval_arm c vo stage arm = | `Seek, false | `Done _, _ -> stage -and eval_decl t = - ref (default_value t.it) - and eval_func (m : instance) (f : func) (evs : value list) = let module Return = MakeLabel () in let args = List.map ref evs in - let vars = List.map eval_decl f.it.locals in + let vars = List.map (fun t -> ref (default_value t.it)) f.it.locals in let locals = args @ vars in let c = {modul = m; locals; labels = []; return = Return.label} in try eval_expr c f.it.body @@ -265,14 +252,13 @@ let init m imports host = assert (List.length imports = List.length m.it.Ast.imports); assert (host.page_size > 0); assert (Lib.Int.is_power_of_two host.page_size); - let {Ast.exports; globals; tables; funcs; memory; _} = m.it in + let {Ast.exports; tables; funcs; memory; _} = m.it in let mem = init_memory memory in let func x = List.nth funcs x.it in let export ex = ExportMap.add ex.it.name (func ex.it.func) in let exports = List.fold_right export exports ExportMap.empty in let tables = List.map (fun tab -> List.map func tab.it) tables in - let globals = List.map eval_decl globals in - {funcs; imports; exports; tables; globals; memory = mem; host} + {funcs; imports; exports; tables; memory = mem; host} let invoke m name vs = let f = export m (name @@ no_region) in @@ -284,6 +270,5 @@ let eval e = let memory = Memory.create 0 in let exports = ExportMap.singleton "eval" f in let host = {page_size = 1} in - let m = {imports = []; exports; globals = []; tables = []; funcs = [f]; - memory; host} in + let m = {imports = []; exports; tables = []; funcs = [f]; memory; host} in eval_func m f [] diff --git a/ml-proto/test/forward.wasm b/ml-proto/test/forward.wasm index 0e4c2a77f1..811884ff9b 100644 --- a/ml-proto/test/forward.wasm +++ b/ml-proto/test/forward.wasm @@ -12,14 +12,11 @@ ) (func $odd (param $n i32) (result i32) - (store_global $scratch (get_local $n)) (if (i32.eq (get_local $n) (i32.const 0)) (i32.const 0) (call $even (i32.sub (get_local $n) (i32.const 1))) ) ) - - (global $scratch i32) ) (assert_eq (invoke "even" (i32.const 13)) (i32.const 0))