From e2495878b872b341e6e04eed31dd255b1a6e256f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 3 Jan 2024 01:35:32 +0900 Subject: feat: implement binary decoder --- src/Structure/Instructions/Instr.php | 977 +++++++++++++++++++++++++++++++++++ 1 file changed, 977 insertions(+) create mode 100644 src/Structure/Instructions/Instr.php (limited to 'src/Structure/Instructions/Instr.php') diff --git a/src/Structure/Instructions/Instr.php b/src/Structure/Instructions/Instr.php new file mode 100644 index 0000000..f4f85cc --- /dev/null +++ b/src/Structure/Instructions/Instr.php @@ -0,0 +1,977 @@ + $types + */ + final public static function Select(array $types): Parametric\Select + { + return new Parametric\Select($types); + } + + // Variable instructions + final public static function GlobalGet(GlobalIdx $var): Variable\GlobalGet + { + return new Variable\GlobalGet($var); + } + final public static function GlobalSet(GlobalIdx $var): Variable\GlobalSet + { + return new Variable\GlobalSet($var); + } + final public static function LocalGet(LocalIdx $var): Variable\LocalGet + { + return new Variable\LocalGet($var); + } + final public static function LocalSet(LocalIdx $var): Variable\LocalSet + { + return new Variable\LocalSet($var); + } + final public static function LocalTee(LocalIdx $var): Variable\LocalTee + { + return new Variable\LocalTee($var); + } + + // Table instructions + final public static function ElemDrop(ElemIdx $elem): Table\ElemDrop + { + return new Table\ElemDrop($elem); + } + final public static function TableCopy(TableIdx $to, TableIdx $from): Table\TableCopy + { + return new Table\TableCopy($to, $from); + } + final public static function TableFill(TableIdx $table): Table\TableFill + { + return new Table\TableFill($table); + } + final public static function TableGet(TableIdx $table): Table\TableGet + { + return new Table\TableGet($table); + } + final public static function TableGrow(TableIdx $table): Table\TableGrow + { + return new Table\TableGrow($table); + } + final public static function TableInit(TableIdx $to, ElemIdx $from): Table\TableInit + { + return new Table\TableInit($to, $from); + } + final public static function TableSet(TableIdx $table): Table\TableSet + { + return new Table\TableSet($table); + } + final public static function TableSize(TableIdx $table): Table\TableSize + { + return new Table\TableSize($table); + } + + // Memory instructions + final public static function DataDrop(DataIdx $data): Memory\DataDrop + { + return new Memory\DataDrop($data); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function F32Load(int $offset, int $align): Memory\F32Load + { + return new Memory\F32Load($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function F32Store(int $offset, int $align): Memory\F32Store + { + return new Memory\F32Store($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function F64Load(int $offset, int $align): Memory\F64Load + { + return new Memory\F64Load($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function F64Store(int $offset, int $align): Memory\F64Store + { + return new Memory\F64Store($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I32Load(int $offset, int $align): Memory\I32Load + { + return new Memory\I32Load($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I32Load16S(int $offset, int $align): Memory\I32Load16S + { + return new Memory\I32Load16S($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I32Load16U(int $offset, int $align): Memory\I32Load16U + { + return new Memory\I32Load16U($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I32Load8S(int $offset, int $align): Memory\I32Load8S + { + return new Memory\I32Load8S($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I32Load8U(int $offset, int $align): Memory\I32Load8U + { + return new Memory\I32Load8U($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I32Store(int $offset, int $align): Memory\I32Store + { + return new Memory\I32Store($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I32Store16(int $offset, int $align): Memory\I32Store16 + { + return new Memory\I32Store16($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I32Store8(int $offset, int $align): Memory\I32Store8 + { + return new Memory\I32Store8($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I64Load(int $offset, int $align): Memory\I64Load + { + return new Memory\I64Load($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I64Load16S(int $offset, int $align): Memory\I64Load16S + { + return new Memory\I64Load16S($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I64Load16U(int $offset, int $align): Memory\I64Load16U + { + return new Memory\I64Load16U($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I64Load32S(int $offset, int $align): Memory\I64Load32S + { + return new Memory\I64Load32S($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I64Load32U(int $offset, int $align): Memory\I64Load32U + { + return new Memory\I64Load32U($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I64Load8S(int $offset, int $align): Memory\I64Load8S + { + return new Memory\I64Load8S($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I64Load8U(int $offset, int $align): Memory\I64Load8U + { + return new Memory\I64Load8U($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I64Store(int $offset, int $align): Memory\I64Store + { + return new Memory\I64Store($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I64Store16(int $offset, int $align): Memory\I64Store16 + { + return new Memory\I64Store16($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I64Store32(int $offset, int $align): Memory\I64Store32 + { + return new Memory\I64Store32($offset, $align); + } + /** + * @param U32 $offset + * @param U32 $align + */ + final public static function I64Store8(int $offset, int $align): Memory\I64Store8 + { + return new Memory\I64Store8($offset, $align); + } + final public static function MemoryCopy(): Memory\MemoryCopy + { + return new Memory\MemoryCopy(); + } + final public static function MemoryFill(): Memory\MemoryFill + { + return new Memory\MemoryFill(); + } + final public static function MemoryGrow(): Memory\MemoryGrow + { + return new Memory\MemoryGrow(); + } + final public static function MemoryInit(DataIdx $data): Memory\MemoryInit + { + return new Memory\MemoryInit($data); + } + final public static function MemorySize(): Memory\MemorySize + { + return new Memory\MemorySize(); + } + + // Control instructions + /** + * @param list $body + */ + final public static function Block(BlockType $type, array $body): Control\Block + { + return new Control\Block($type, $body); + } + final public static function Br(LabelIdx $label): Control\Br + { + return new Control\Br($label); + } + final public static function BrIf(LabelIdx $label): Control\BrIf + { + return new Control\BrIf($label); + } + /** + * @param list $labelTable + */ + final public static function BrTable(array $labelTable, LabelIdx $defaultLabel): Control\BrTable + { + return new Control\BrTable($labelTable, $defaultLabel); + } + final public static function Call(FuncIdx $func): Control\Call + { + return new Control\Call($func); + } + final public static function CallIndirect(TableIdx $funcTable, TypeIdx $type): Control\CallIndirect + { + return new Control\CallIndirect($funcTable, $type); + } + final public static function Else_(): Control\Else_ + { + return new Control\Else_(); + } + final public static function End(): Control\End + { + return new Control\End(); + } + /** + * @param list $thenBody + * @param list $elseBody + */ + final public static function If_(BlockType $type, array $thenBody, array $elseBody): Control\If_ + { + return new Control\If_($type, $thenBody, $elseBody); + } + /** + * @param list $body + */ + final public static function Loop(BlockType $type, array $body): Control\Loop + { + return new Control\Loop($type, $body); + } + final public static function Nop(): Control\Nop + { + return new Control\Nop(); + } + final public static function Return_(): Control\Return_ + { + return new Control\Return_(); + } + final public static function Unreachable(): Control\Unreachable + { + return new Control\Unreachable(); + } +} -- cgit v1.2.3-70-g09d2