aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Debug
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-07-11 02:57:23 +0900
committernsfisis <nsfisis@gmail.com>2024-07-11 02:57:23 +0900
commit26f49b7e27076e689541b9e13a1b54f60a4ee5c2 (patch)
treea3762813c34a384f21ddeed630ddf333a1cc1b05 /src/Debug
parent326273f20c2d7dfe3d866eb720d1bb914570e3a3 (diff)
downloadphp-waddiwasi-26f49b7e27076e689541b9e13a1b54f60a4ee5c2.tar.gz
php-waddiwasi-26f49b7e27076e689541b9e13a1b54f60a4ee5c2.tar.zst
php-waddiwasi-26f49b7e27076e689541b9e13a1b54f60a4ee5c2.zip
feat: organize namespaces
Diffstat (limited to 'src/Debug')
-rw-r--r--src/Debug/Debug.php112
1 files changed, 0 insertions, 112 deletions
diff --git a/src/Debug/Debug.php b/src/Debug/Debug.php
deleted file mode 100644
index 56dcdae..0000000
--- a/src/Debug/Debug.php
+++ /dev/null
@@ -1,112 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Debug;
-
-use Nsfisis\Waddiwasi\Structure\Modules\ImportDescs;
-use Nsfisis\Waddiwasi\Structure\Modules\Module;
-use Nsfisis\Waddiwasi\Structure\Types\FuncType;
-use Nsfisis\Waddiwasi\Structure\Types\GlobalType;
-use Nsfisis\Waddiwasi\Structure\Types\Limits;
-use Nsfisis\Waddiwasi\Structure\Types\MemType;
-use Nsfisis\Waddiwasi\Structure\Types\Mut;
-use Nsfisis\Waddiwasi\Structure\Types\NumType;
-use Nsfisis\Waddiwasi\Structure\Types\RefType;
-use Nsfisis\Waddiwasi\Structure\Types\ResultType;
-use Nsfisis\Waddiwasi\Structure\Types\TableType;
-use Nsfisis\Waddiwasi\Structure\Types\ValType;
-use Nsfisis\Waddiwasi\Structure\Types\ValTypes;
-
-final readonly class Debug
-{
- public static function printImports(Module $module): void
- {
- foreach ($module->imports as $import) {
- $mod = $import->module;
- $name = $import->name;
- $desc = $import->desc;
- $type = match ($desc::class) {
- ImportDescs\Func::class => 'func',
- ImportDescs\Table::class => 'table',
- ImportDescs\Mem::class => 'mem',
- ImportDescs\Global_::class => 'global',
- default => 'unknown',
- };
- $extraInfo = match ($desc::class) {
- ImportDescs\Func::class => self::typeIdxToString($desc->func, $module),
- ImportDescs\Table::class => self::tableTypeToString($desc->table),
- ImportDescs\Mem::class => self::memTypeToString($desc->mem),
- ImportDescs\Global_::class => self::globalTypeToString($desc->global),
- default => 'unknown',
- };
- echo "$mod::$name: $type $extraInfo\n";
- }
- }
-
- private static function typeIdxToString(int $idx, Module $module): string
- {
- $type = $module->types[$idx];
- return self::funcTypeToString($type);
- }
-
- private static function tableTypeToString(TableType $type): string
- {
- return self::valTypeToString(ValType::RefType($type->refType)) . ' ' . self::limitsToString($type->limits);
- }
-
- private static function memTypeToString(MemType $type): string
- {
- return self::limitsToString($type->limits);
- }
-
- private static function globalTypeToString(GlobalType $type): string
- {
- return self::mutToString($type->mut) . ' ' . self::valTypeToString($type->valType);
- }
-
- private static function funcTypeToString(FuncType $type): string
- {
- $params = self::resultTypeToString($type->params);
- $results = self::resultTypeToString($type->results);
- return "($params) -> ($results)";
- }
-
- private static function valTypeToString(ValType $type): string
- {
- return match ($type::class) {
- ValTypes\NumType::class => match ($type->inner) {
- NumType::I32 => 'i32',
- NumType::I64 => 'i64',
- NumType::F32 => 'f32',
- NumType::F64 => 'f64',
- },
- ValTypes\VecType::class => 'v128',
- ValTypes\RefType::class => match ($type->inner) {
- RefType::FuncRef => 'funcref',
- RefType::ExternRef => 'externref',
- },
- default => 'unknown',
- };
- }
-
- private static function limitsToString(Limits $limit): string
- {
- $min = $limit->min;
- $max = $limit->max;
- return $max === null ? "[$min, inf)" : "[$min, $max]";
- }
-
- private static function mutToString(Mut $mut): string
- {
- return match ($mut) {
- Mut::Const => 'const',
- Mut::Var => 'var',
- };
- }
-
- private static function resultTypeToString(ResultType $type): string
- {
- return implode(', ', array_map(self::valTypeToString(...), $type->types));
- }
-}