Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(compiler): Update binaryen.ml to v0.20.1 #1599

Merged
merged 3 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/esy.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"check-format": "dune build @fmt"
},
"dependencies": {
"@grain/binaryen.ml": ">= 0.19.0 < 0.20.0",
"@grain/binaryen.ml": ">= 0.20.1 < 0.21.0",
"@opam/cmdliner": ">= 1.1.1",
"@opam/dune": ">= 3.6.1 < 4.0.0",
"@opam/dune-build-info": ">= 3.6.1 < 4.0.0",
Expand Down
38 changes: 19 additions & 19 deletions compiler/esy.lock/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions compiler/src/codegen/comp_utils.re
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ let grain_main = "_gmain";
let grain_start = "_start";
let grain_env_name = "_genv";
let grain_global_function_table = "tbl";
// TODO(#): Use a more descriptive name once we get fixes into Binaryen
let grain_memory = "0";

let wasm_type =
fun
Expand Down Expand Up @@ -114,7 +116,16 @@ let store = (~ty=Type.int32, ~align=?, ~offset=0, ~sz=?, wasm_mod, ptr, arg) =>
sz,
);
let align = Option.value(~default=sz, align);
Expression.Store.make(wasm_mod, sz, offset, align, ptr, arg, ty);
Expression.Store.make(
wasm_mod,
sz,
offset,
align,
ptr,
arg,
ty,
grain_memory,
);
};

let load =
Expand All @@ -130,7 +141,16 @@ let load =
sz,
);
let align = Option.value(~default=sz, align);
Expression.Load.make(~signed, wasm_mod, sz, offset, align, ty, ptr);
Expression.Load.make(
~signed,
wasm_mod,
sz,
offset,
align,
ty,
ptr,
grain_memory,
);
};

let is_grain_env = str => grain_env_name == str;
Expand Down Expand Up @@ -235,6 +255,7 @@ let write_universal_exports =
2,
Type.int32,
get_closure(),
grain_memory,
);
Expression.Call_indirect.make(
wasm_mod,
Expand Down
1 change: 1 addition & 0 deletions compiler/src/codegen/comp_utils.rei
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let grain_main: string;
let grain_start: string;
let grain_env_name: string;
let grain_global_function_table: string;
let grain_memory: string;

let wasm_type: Types.allocation_type => Type.t;

Expand Down
19 changes: 16 additions & 3 deletions compiler/src/codegen/compcore.re
Original file line number Diff line number Diff line change
Expand Up @@ -2176,7 +2176,8 @@ let compile_prim0 = (wasm_mod, env, p0): Expression.t => {
allocate_alt_num_uninitialized(wasm_mod, env, Uint32Type)
| AllocateUint64 =>
allocate_alt_num_uninitialized(wasm_mod, env, Uint64Type)
| WasmMemorySize => Expression.Memory_size.make(wasm_mod)
| WasmMemorySize =>
Expression.Memory_size.make(wasm_mod, grain_memory, false)
| Unreachable => Expression.Unreachable.make(wasm_mod)
| HeapStart => get_runtime_heap_start(wasm_mod)
};
Expand Down Expand Up @@ -2285,7 +2286,8 @@ let compile_prim1 = (wasm_mod, env, p1, arg, loc): Expression.t => {
// no-op
compile_imm(wasm_mod, env, arg)
| WasmToGrain => compiled_arg // no-op
| WasmMemoryGrow => Expression.Memory_grow.make(wasm_mod, compiled_arg)
| WasmMemoryGrow =>
Expression.Memory_grow.make(wasm_mod, compiled_arg, grain_memory, false)
| WasmUnaryI32({wasm_op, ret_type})
| WasmUnaryI64({wasm_op, ret_type})
| WasmUnaryF32({wasm_op, ret_type})
Expand Down Expand Up @@ -2472,6 +2474,8 @@ let compile_primn = (wasm_mod, env: codegen_env, p, args): Expression.t => {
compile_imm(wasm_mod, env, List.nth(args, 0)),
compile_imm(wasm_mod, env, List.nth(args, 1)),
compile_imm(wasm_mod, env, List.nth(args, 2)),
grain_memory,
grain_memory,
),
Expression.Const.make(wasm_mod, const_void()),
],
Expand All @@ -2486,6 +2490,7 @@ let compile_primn = (wasm_mod, env: codegen_env, p, args): Expression.t => {
compile_imm(wasm_mod, env, List.nth(args, 0)),
compile_imm(wasm_mod, env, List.nth(args, 1)),
compile_imm(wasm_mod, env, List.nth(args, 2)),
grain_memory,
),
Expression.Const.make(wasm_mod, const_void()),
],
Expand Down Expand Up @@ -3527,7 +3532,15 @@ let compile_wasm_module = (~env=?, ~name=?, prog) => {
Option.is_none(Grain_utils.Config.memory_base^),
);
let _ =
Memory.set_memory(wasm_mod, 0, Memory.unlimited, "memory", [], false);
Memory.set_memory(
wasm_mod,
0,
Memory.unlimited,
"memory",
[],
false,
grain_memory,
);

let compile_all = () => {
ignore @@ compile_globals(wasm_mod, env, prog);
Expand Down
11 changes: 8 additions & 3 deletions compiler/src/linking/link.re
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ let rec globalize_names = (~function_names, ~global_names, ~label_names, expr) =
| RefTest
| RefCast
| BrOn
| RttCanon
| RttSub
| StructNew
| StructGet
| StructSet
Expand Down Expand Up @@ -689,9 +687,16 @@ let link_all = (linked_mod, dependencies, signature) => {
"memory",
data_segments,
false,
Comp_utils.grain_memory,
);
if (Config.import_memory^) {
Import.add_memory_import(linked_mod, "memory", "env", "memory", false);
Import.add_memory_import(
linked_mod,
Comp_utils.grain_memory,
"env",
"memory",
false,
);
};

let starts =
Expand Down