blob: 493da2d47e044fa18a079edc22943efaa86f1ce0 [file] [log] [blame] [edit]
const PAGESIZE = 65536;
function print_origin(origin) {
print(";;");
print(";; Generated by ../meta/" + origin);
print(";; DO NOT EDIT THIS FILE. CHANGE THE SOURCE AND REGENERATE.");
print(";;");
}
function checkRangeCode(memtype) {
return `
(func (export "checkRange") (param $from ${memtype}) (param $to ${memtype}) (param $expected i32) (result ${memtype})
(loop $cont
(if (${memtype}.eq (local.get $from) (local.get $to))
(then
(return (${memtype}.const -1))))
(if (i32.eq (i32.load8_u (local.get $from)) (local.get $expected))
(then
(local.set $from (${memtype}.add (local.get $from) (${memtype}.const 1)))
(br $cont))))
(return (local.get $from)))
`;
}
function checkRange(memtype, from, to, expected) {
print(
`(assert_return (invoke "checkRange" (${memtype}.const ${from}) (${memtype}.const ${to}) (i32.const ${expected}))
(${memtype}.const -1))`);
}