mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
Read memarg flags through a function so the compiler compiles itself
readMemargFlags took its reader as a `{ u32(): number }` record, and the
validator (Reader) and translator (WasmCursor) pass class instances. The
self-hosted compiler refuses a class instance in a record-typed parameter
(SC2002), so the self-hosted LLVM emitter, the native frontend programs
and the bootstrap seed builds failed. readMemargFlags now takes the
reader's u32 function, and each caller passes `() => r.u32()`.
This commit is contained in:
@@ -1245,7 +1245,7 @@ class FunctionValidator {
|
||||
/** A memarg. A memory other than 0 stops typing (multi-memory). */
|
||||
memarg(naturalAlign: number): void {
|
||||
const r = this.r;
|
||||
const { align, memory } = readMemargFlags(r);
|
||||
const { align, memory } = readMemargFlags(() => r.u32());
|
||||
if (align < 0) r.malformed("malformed memop flags");
|
||||
if (memory !== 0) this.otherMemory(memory);
|
||||
if (this.m.memory64) r.u64();
|
||||
@@ -1831,7 +1831,7 @@ class FunctionValidator {
|
||||
|
||||
scanMemarg(): void {
|
||||
const r = this.r;
|
||||
const { align, memory } = readMemargFlags(r);
|
||||
const { align, memory } = readMemargFlags(() => r.u32());
|
||||
if (align < 0) r.malformed("malformed memop flags");
|
||||
if (memory !== 0) this.m.feature("multi-memory");
|
||||
if (this.m.memory64) r.u64();
|
||||
|
||||
@@ -289,11 +289,12 @@ function decodeUtf8(bytes: Uint8Array, start: number, end: number): string {
|
||||
* 0; flags of 128 or more are malformed and answer align -1 without
|
||||
* reading further. The offset follows. Validation (binary.ts), translation
|
||||
* and skipImmediates all read memargs through this function, so they agree
|
||||
* on where each instruction ends. */
|
||||
export function readMemargFlags(r: { u32(): number }): { align: number; memory: number } {
|
||||
const flags = r.u32();
|
||||
* on where each instruction ends; `u32` reads the next u32 immediate of
|
||||
* their own reader. */
|
||||
export function readMemargFlags(u32: () => number): { align: number; memory: number } {
|
||||
const flags = u32();
|
||||
if (flags >= 128) return { align: -1, memory: 0 };
|
||||
if (flags >= 64) return { align: flags - 64, memory: r.u32() };
|
||||
if (flags >= 64) return { align: flags - 64, memory: u32() };
|
||||
return { align: flags, memory: 0 };
|
||||
}
|
||||
|
||||
@@ -386,7 +387,7 @@ export function skipImmediates(c: WasmCursor, op: number): void {
|
||||
}
|
||||
default:
|
||||
if (op >= 0x28 && op <= 0x3e) {
|
||||
const flags = readMemargFlags(c);
|
||||
const flags = readMemargFlags(() => c.u32());
|
||||
if (flags.align < 0 || flags.memory !== 0)
|
||||
throw new Error(`wasm: memarg of memory ${flags.memory} is not supported`);
|
||||
c.u32();
|
||||
|
||||
@@ -851,7 +851,7 @@ class FunctionTranslator {
|
||||
/** The offset of a memarg over memory 0 (the only memory a translatable
|
||||
* module has). */
|
||||
memargOffset(c: WasmCursor): number {
|
||||
const flags = readMemargFlags(c);
|
||||
const flags = readMemargFlags(() => c.u32());
|
||||
if (flags.align < 0 || flags.memory !== 0)
|
||||
throw new WasmTranslateError(`memarg of memory ${flags.memory} is not supported`);
|
||||
return c.u32();
|
||||
|
||||
Reference in New Issue
Block a user