module wasm.reader

Code Map

module wasm.reader;


enum SkipOrParse
{
	Skip,
	Parse,
}

enum OpcodeKind
{
	Error,
	Regular,
	Control,
	ControlType,
	Branch,
	BranchTable,
	Call,
	CallIndirect,
	Memory,
	VarAccess,
	I32Const,
	I64Const,
	F32Const,
	F64Const,
	Unhandled,
}

class InitExpr
{
public:
	union U
	{
	public:
		index: u32;
		_i32: i32;
		_i64: i64;
		_f32: f32;
		_f64: f64;
	}


public:
	u: U;
	type: Type;
	isImport: bool;


public:
	this() { }
}

class Reader
{
public:
	this() { }
	fn onHeader(header: Header);
	fn onSection(id: Section, data: const(u8)[]) SkipOrParse;
	fn onCustomSection(name: string, data: const(u8)[]);
	fn onTypeSection(count: u32);
	fn onTypeEntry(num: u32, from: Type, args: Type[], ret: Type);
	fn onImportSection(count: u32);
	fn onImportGlobal(num: u32, mod: string, field: string, t: Type, mut: bool);
	fn onImportFunc(num: u32, mod: string, field: string, index: u32);
	fn onFunctionSection(count: u32);
	fn onFunctionEntry(num: u32, index: u32);
	fn onTableSection(count: u32);
	fn onTableEntry(num: u32, elem_type: Type, l: Limits);
	fn onMemorySection(count: u32);
	fn onMemoryEntry(num: u32, l: Limits);
	fn onGlobalSection(count: u32);
	fn onGlobalEntry(num: u32, type: Type, mut: bool, exp: InitExpr);
	fn onExportSection(count: u32);
	fn onExportEntry(num: u32, name: string, kind: wasm.ExternalKind, index: u32);
	fn onRelocSection(section: wasm.Section, name: string, count: u32);
	fn onRelocEntry(num: u32, type: wasm.RelocType, offset: u32, index: u32, addend: u32);
	fn onRelocSectionEnd();
	fn onStart(index: u32);
	fn onCodeSection(count: u32);
	fn onFunctionBody(num: u32, types: Type[], counts: u32[]);
	fn onFunctionBodyEnd(num: u32);
	fn onCode(data: const(u8)[]);
	fn onOp(op: Opcode);
	fn onControl(op: Opcode, t: Type);
	fn onBranch(op: Opcode, relative_depth: u32);
	fn onCall(index: u32);
	fn onCallIndirect(typeIndex: u32);
	fn onOpMemory(op: Opcode, flags: u32, offset: u32);
	fn onOpVar(op: Opcode, index: u32);
	fn onOpI32Const(v: i32);
	fn onOpI64Const(v: i64);
	fn onOpF32Const(v: f32);
	fn onOpF64Const(v: f64);
	fn onReadError(err: string);
	fn onEOF();
}

fn readFile(r: Reader, data: const(u8)[]) { }
fn readCustomSection(r: Reader, data: const(u8)[]) { }
fn readTypeSection(r: Reader, data: const(u8)[]) { }
fn readTypeEntry(r: Reader, num: u32, data: const(u8)[]) { }
fn readImportSection(r: Reader, data: const(u8)[]) { }
fn readImportEntry(r: Reader, num: u32, data: const(u8)[]) { }
fn readFunctionSection(r: Reader, data: const(u8)[]) { }
fn readTableSection(r: Reader, data: const(u8)[]) { }
fn readMemorySection(r: Reader, data: const(u8)[]) { }
fn readGlobalSection(r: Reader, data: const(u8)[]) { }
fn readExportSection(r: Reader, data: const(u8)[]) { }
fn readStartSection(r: Reader, data: const(u8)[]) { }
fn readElementSection(r: Reader, data: const(u8)[]) { }
fn readDataSection(r: Reader, data: const(u8)[]) { }
fn readRelocSection(r: Reader, data: const(u8)[]) { }
fn readCodeSection(r: Reader, data: const(u8)[]) { }
fn readFunctionBody(r: Reader, num: u32, data: const(u8)[]) { }
fn readInitExpr(r: Reader, data: const(u8)[], ret: InitExpr) { }
fn readOpcodes(r: Reader, b: const(u8)[]) { }
fn opKind(op: Opcode) OpcodeKind { }