aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Structure/Instructions/Instrs/Control
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-01-03 01:35:32 +0900
committernsfisis <nsfisis@gmail.com>2024-01-27 12:05:23 +0900
commite2495878b872b341e6e04eed31dd255b1a6e256f (patch)
tree4057ab19765ea7fc13505798c6434dceac02f4b1 /src/Structure/Instructions/Instrs/Control
parent5b4652d080c7eae26f8aac482468a6777ad9defe (diff)
downloadphp-waddiwasi-e2495878b872b341e6e04eed31dd255b1a6e256f.tar.gz
php-waddiwasi-e2495878b872b341e6e04eed31dd255b1a6e256f.tar.zst
php-waddiwasi-e2495878b872b341e6e04eed31dd255b1a6e256f.zip
feat: implement binary decoder
Diffstat (limited to 'src/Structure/Instructions/Instrs/Control')
-rw-r--r--src/Structure/Instructions/Instrs/Control/Block.php19
-rw-r--r--src/Structure/Instructions/Instrs/Control/BlockType.php21
-rw-r--r--src/Structure/Instructions/Instrs/Control/BlockTypes/TypeIdx.php15
-rw-r--r--src/Structure/Instructions/Instrs/Control/BlockTypes/ValType.php15
-rw-r--r--src/Structure/Instructions/Instrs/Control/Br.php16
-rw-r--r--src/Structure/Instructions/Instrs/Control/BrIf.php16
-rw-r--r--src/Structure/Instructions/Instrs/Control/BrTable.php20
-rw-r--r--src/Structure/Instructions/Instrs/Control/Call.php16
-rw-r--r--src/Structure/Instructions/Instrs/Control/CallIndirect.php18
-rw-r--r--src/Structure/Instructions/Instrs/Control/Else_.php11
-rw-r--r--src/Structure/Instructions/Instrs/Control/End.php11
-rw-r--r--src/Structure/Instructions/Instrs/Control/If_.php21
-rw-r--r--src/Structure/Instructions/Instrs/Control/Loop.php19
-rw-r--r--src/Structure/Instructions/Instrs/Control/Nop.php11
-rw-r--r--src/Structure/Instructions/Instrs/Control/Return_.php11
-rw-r--r--src/Structure/Instructions/Instrs/Control/Unreachable.php11
16 files changed, 251 insertions, 0 deletions
diff --git a/src/Structure/Instructions/Instrs/Control/Block.php b/src/Structure/Instructions/Instrs/Control/Block.php
new file mode 100644
index 0000000..2be7a1f
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/Block.php
@@ -0,0 +1,19 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+
+final readonly class Block extends Instr
+{
+ /**
+ * @param list<Instr> $body
+ */
+ public function __construct(
+ public BlockType $type,
+ public array $body,
+ ) {
+ }
+}
diff --git a/src/Structure/Instructions/Instrs/Control/BlockType.php b/src/Structure/Instructions/Instrs/Control/BlockType.php
new file mode 100644
index 0000000..68c6bd4
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/BlockType.php
@@ -0,0 +1,21 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Types\TypeIdx;
+use Nsfisis\Waddiwasi\Structure\Types\ValType;
+
+abstract readonly class BlockType
+{
+ final public static function TypeIdx(TypeIdx $type): BlockTypes\TypeIdx
+ {
+ return new BlockTypes\TypeIdx($type);
+ }
+
+ final public static function ValType(?ValType $type): BlockTypes\ValType
+ {
+ return new BlockTypes\ValType($type);
+ }
+}
diff --git a/src/Structure/Instructions/Instrs/Control/BlockTypes/TypeIdx.php b/src/Structure/Instructions/Instrs/Control/BlockTypes/TypeIdx.php
new file mode 100644
index 0000000..b633bb7
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/BlockTypes/TypeIdx.php
@@ -0,0 +1,15 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control\BlockTypes;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control\BlockType;
+use Nsfisis\Waddiwasi\Structure\Types\TypeIdx as OrigTypeIdx;
+
+final readonly class TypeIdx extends BlockType
+{
+ protected function __construct(public OrigTypeIdx $inner)
+ {
+ }
+}
diff --git a/src/Structure/Instructions/Instrs/Control/BlockTypes/ValType.php b/src/Structure/Instructions/Instrs/Control/BlockTypes/ValType.php
new file mode 100644
index 0000000..1a56ce4
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/BlockTypes/ValType.php
@@ -0,0 +1,15 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control\BlockTypes;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control\BlockType;
+use Nsfisis\Waddiwasi\Structure\Types\ValType as OrigValType;
+
+final readonly class ValType extends BlockType
+{
+ protected function __construct(public ?OrigValType $inner)
+ {
+ }
+}
diff --git a/src/Structure/Instructions/Instrs/Control/Br.php b/src/Structure/Instructions/Instrs/Control/Br.php
new file mode 100644
index 0000000..836f3f1
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/Br.php
@@ -0,0 +1,16 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+use Nsfisis\Waddiwasi\Structure\Types\LabelIdx;
+
+final readonly class Br extends Instr
+{
+ public function __construct(
+ public LabelIdx $label,
+ ) {
+ }
+}
diff --git a/src/Structure/Instructions/Instrs/Control/BrIf.php b/src/Structure/Instructions/Instrs/Control/BrIf.php
new file mode 100644
index 0000000..a15a716
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/BrIf.php
@@ -0,0 +1,16 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+use Nsfisis\Waddiwasi\Structure\Types\LabelIdx;
+
+final readonly class BrIf extends Instr
+{
+ public function __construct(
+ public LabelIdx $label,
+ ) {
+ }
+}
diff --git a/src/Structure/Instructions/Instrs/Control/BrTable.php b/src/Structure/Instructions/Instrs/Control/BrTable.php
new file mode 100644
index 0000000..57a08f3
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/BrTable.php
@@ -0,0 +1,20 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+use Nsfisis\Waddiwasi\Structure\Types\LabelIdx;
+
+final readonly class BrTable extends Instr
+{
+ /**
+ * @param list<LabelIdx> $labelTable
+ */
+ public function __construct(
+ public array $labelTable,
+ public LabelIdx $defaultLabel,
+ ) {
+ }
+}
diff --git a/src/Structure/Instructions/Instrs/Control/Call.php b/src/Structure/Instructions/Instrs/Control/Call.php
new file mode 100644
index 0000000..c8702d3
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/Call.php
@@ -0,0 +1,16 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+use Nsfisis\Waddiwasi\Structure\Types\FuncIdx;
+
+final readonly class Call extends Instr
+{
+ public function __construct(
+ public FuncIdx $func,
+ ) {
+ }
+}
diff --git a/src/Structure/Instructions/Instrs/Control/CallIndirect.php b/src/Structure/Instructions/Instrs/Control/CallIndirect.php
new file mode 100644
index 0000000..2cf28a5
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/CallIndirect.php
@@ -0,0 +1,18 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+use Nsfisis\Waddiwasi\Structure\Types\TableIdx;
+use Nsfisis\Waddiwasi\Structure\Types\TypeIdx;
+
+final readonly class CallIndirect extends Instr
+{
+ public function __construct(
+ public TableIdx $funcTable,
+ public TypeIdx $type,
+ ) {
+ }
+}
diff --git a/src/Structure/Instructions/Instrs/Control/Else_.php b/src/Structure/Instructions/Instrs/Control/Else_.php
new file mode 100644
index 0000000..665b11f
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/Else_.php
@@ -0,0 +1,11 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+
+final readonly class Else_ extends Instr
+{
+}
diff --git a/src/Structure/Instructions/Instrs/Control/End.php b/src/Structure/Instructions/Instrs/Control/End.php
new file mode 100644
index 0000000..275dc6d
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/End.php
@@ -0,0 +1,11 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+
+final readonly class End extends Instr
+{
+}
diff --git a/src/Structure/Instructions/Instrs/Control/If_.php b/src/Structure/Instructions/Instrs/Control/If_.php
new file mode 100644
index 0000000..0536be0
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/If_.php
@@ -0,0 +1,21 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+
+final readonly class If_ extends Instr
+{
+ /**
+ * @param list<Instr> $thenBody
+ * @param list<Instr> $elseBody
+ */
+ public function __construct(
+ public BlockType $type,
+ public array $thenBody,
+ public array $elseBody,
+ ) {
+ }
+}
diff --git a/src/Structure/Instructions/Instrs/Control/Loop.php b/src/Structure/Instructions/Instrs/Control/Loop.php
new file mode 100644
index 0000000..30c85ef
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/Loop.php
@@ -0,0 +1,19 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+
+final readonly class Loop extends Instr
+{
+ /**
+ * @param list<Instr> $body
+ */
+ public function __construct(
+ public BlockType $type,
+ public array $body,
+ ) {
+ }
+}
diff --git a/src/Structure/Instructions/Instrs/Control/Nop.php b/src/Structure/Instructions/Instrs/Control/Nop.php
new file mode 100644
index 0000000..dbb1b6c
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/Nop.php
@@ -0,0 +1,11 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+
+final readonly class Nop extends Instr
+{
+}
diff --git a/src/Structure/Instructions/Instrs/Control/Return_.php b/src/Structure/Instructions/Instrs/Control/Return_.php
new file mode 100644
index 0000000..0322076
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/Return_.php
@@ -0,0 +1,11 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+
+final readonly class Return_ extends Instr
+{
+}
diff --git a/src/Structure/Instructions/Instrs/Control/Unreachable.php b/src/Structure/Instructions/Instrs/Control/Unreachable.php
new file mode 100644
index 0000000..49f586b
--- /dev/null
+++ b/src/Structure/Instructions/Instrs/Control/Unreachable.php
@@ -0,0 +1,11 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control;
+
+use Nsfisis\Waddiwasi\Structure\Instructions\Instr;
+
+final readonly class Unreachable extends Instr
+{
+}