82 lines
1.7 KiB
C
82 lines
1.7 KiB
C
/*
|
|
* nanowasm, a tiny WebAssembly/Wasm interpreter
|
|
* Copyright (C) 2023-2024 Xavier Del Campo Romero
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#ifndef WASM_TYPES_H
|
|
#define WASM_TYPES_H
|
|
|
|
#include <nanowasm/nw.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
typedef bool varuint1;
|
|
typedef signed char varint7;
|
|
typedef unsigned char varuint7;
|
|
typedef unsigned long varuint32;
|
|
typedef long varint32;
|
|
typedef unsigned long long varuint64;
|
|
typedef long long varint64;
|
|
|
|
#define VALUE_TYPES \
|
|
X(VALUE_TYPE_I32) \
|
|
X(VALUE_TYPE_I64) \
|
|
X(VALUE_TYPE_F32) \
|
|
X(VALUE_TYPE_F64)
|
|
|
|
enum value_type
|
|
{
|
|
#define X(x) x,
|
|
VALUE_TYPES
|
|
#undef X
|
|
};
|
|
|
|
struct retval
|
|
{
|
|
bool returns;
|
|
enum value_type type;
|
|
};
|
|
|
|
struct nw_block
|
|
{
|
|
long pc;
|
|
struct nw_block *prev;
|
|
};
|
|
|
|
struct nw_frame
|
|
{
|
|
enum value_type local_type;
|
|
unsigned long n_locals;
|
|
struct retval retval;
|
|
struct nw_block *last_block;
|
|
struct nw_frame *prev, *next;
|
|
};
|
|
|
|
struct nw_gframe
|
|
{
|
|
enum value_type type;
|
|
bool mutable;
|
|
struct nw_gframe *next;
|
|
};
|
|
|
|
int varuint1_read(FILE *f, varuint1 *out);
|
|
int varint7_read(FILE *f, varint7 *out);
|
|
int varuint7_read(FILE *f, varuint7 *out);
|
|
int varuint32_read(FILE *f, varuint32 *out);
|
|
int varint32_read(FILE *f, varint32 *out);
|
|
int varuint64_read(FILE *f, varuint64 *out);
|
|
int varint64_read(FILE *f, varint64 *out);
|
|
|
|
int get_value_type(varint7 type, enum value_type *vtype);
|
|
size_t get_type_size(enum value_type type);
|
|
|
|
int32_t htoni32(int32_t in);
|
|
const char *value_type_tostr(enum value_type v);
|
|
|
|
#endif
|