3RX7PY4U2WNHO6H77BQHLGGZTA7NDPGEHRRBRAB5SNLNAUDBIA6QC
J3IOJKB25DA2K7QMQUTNUE6DVJKSZ3C7RVUL2YGDP6BB5JXYDSKQC
ZNFKFYBFLWN753DAGZODAGH4BN4OTKL275FUK372VY55XB6KC3WAC
YQMCMMBQODBB57JT6SOLIVY3R7A43GQCLWPNRVZGDGF3FIOZMUMQC
7LYBCG3UV5RJ46YMJMHRO6QCQDZVCO6WTB3DFGMKLKPZKYXPYMYAC
XUTVWAWRMPTZ7BORZVFUMSGKV2EOGN6GEWPHPSTZH5HFC7ME3G4QC
64WSQVMQZ4U4VHDNNO2HIYUB5WQT7U6E2463CSVBCZ7EDGTYUEDAC
6MJE6RNGPCT5J6WIYHXBSFKJJP4KNQ7YY4FDXR2XQKDAN6Q5PQ7AC
O2DTNJ3ZOJJKDHGPNE2DZSZF7CFU4G5D65RIDOYZHYYBH3JZAAIAC
EFKQM5UNVCK623Y6L2OBSBD4W3E6DHMDPMXORFLCSJGOXHKPAFHQC
2JXKNG3VODYXLJ3TINRQH3H7OG3XFV3HYWDTNJTIZNFOVIV6FGKAC
F2TD63MB77RLDLPHPNCOYEMW7QSWV6BXXR27SC2Y2OY42CGUQIKAC
F7J2TR37FEVHXRP522LY6Q3PNL42H4I77QFPAK6ZLSCX7I2X4L7QC
3BE42RZGZGKB6BMNUTRK3M64P6FZF6FBPK2S64DCQXYIY7VHNWCQC
ISDVVVJ4Q47MFFMWYC3XP3KZXLAKRA2VGRQ56MSD44475UNYBWDAC
FJZWJHLW5B2JGYHKSHIYBRG2IVTLCPKT3SR2PWKDPCLRATYEXEQQC
test "3_int_factorial" do
assert parse_file("test_data/3_int_factorial.opt.wasm")
|> Enum.filter(fn {k, _} -> k == :section_type or k == :section_body end) ==
[
{:section_type, :type},
{:section_body, [{[:i32], [:i32]}]},
{:section_type, :function},
{:section_body, [0]},
{:section_type, :memory},
{:section_body, [{2, nil}]},
{:section_type, :global},
{:section_body,
[{{:i32, :const}, ["i32.const": 66560]}, {{:i32, :const}, ["i32.const": 1024]}]},
{:section_type, :export},
{:section_body,
[
{"memory", {:mem, 0}},
{"__heap_base", {:global, 0}},
{"__data_end", {:global, 1}},
{"factorial", {:func, 0}}
]},
{:section_type, :code},
{:section_body,
[
%{
code: %{
expr: [
{:"i32.const", 1},
{:"local.set", 1},
{:"local.get", 0},
{:"i32.const", 1},
:"i32.ge_s",
{:if,
%{
blocktype: :empty,
instr: [
loop: %{
blocktype: :empty,
instr: [
{:"local.get", 2},
{:"i32.const", 1},
:"i32.add",
{:"local.tee", 2},
{:"local.get", 1},
:"i32.mul",
{:"local.set", 1},
{:"local.get", 0},
{:"local.get", 2},
:"i32.ne",
{:br_if, 0}
]
}
]
}},
{:"local.get", 1}
],
locals: [%{num: 2, type: :i32}]
},
size: 40
}
]}
]
end
},
%{
code: %{
expr: [
{:"i32.const", 1},
{:"local.set", 1},
{:"local.get", 0},
{:"i32.const", 1},
:"i32.ge_s",
{:if,
%{
blocktype: :empty,
instr: [
loop: %{
blocktype: :empty,
instr: [
{:"local.get", 2},
{:"i32.const", 1},
:"i32.add",
{:"local.tee", 2},
{:"local.get", 1},
:"i32.mul",
{:"local.set", 1},
{:"local.get", 0},
{:"local.get", 2},
:"i32.ne",
{:br_if, 0}
]
}
]
}},
{:"local.get", 1}
],
locals: [%{num: 2, type: :i32}]
},
size: 40
defp typeidx(binary) do
Atomic.u32(binary)
end
defp memidx(binary) do
Atomic.u32(binary)
end
defp globalidx(binary) do
Atomic.u32(binary)
end
defp funcidx(binary) do
Atomic.u32(binary)
end
defp localidx(binary) do
Atomic.u32(binary)
end
defp funcidx(binary), do: Atomic.u32(binary)
defp globalidx(binary), do: Atomic.u32(binary)
defp labelidx(binary), do: Atomic.u32(binary)
defp localidx(binary), do: Atomic.u32(binary)
defp memidx(binary), do: Atomic.u32(binary)
defp typeidx(binary), do: Atomic.u32(binary)