Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
validation.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <sysio/wasm_backend/exceptions.hpp>
4#include <sysio/wasm_backend/utils.hpp>
5
6#include <array>
7#include <iostream>
8
9namespace sysio { namespace vm {
10 class validator {
11 public:
12 // validate limits 3.2.1
13 inline bool validate(const resizable_limits& rl) {
14 return rl.flags ? rl.maximum >= rl.initial : true;
15 }
16
17 // validate a function type 3.2.2
18 inline bool validate(const func_type& ft) {
19 return (ft.return_count == 0 || ft.return_count == 1);
20 }
21
22 // validate a table type 3.2.3
23 inline bool validate(const table_type& tt) {
24 static constexpr uint64_t max_limit = (uint64_t)2 << 32;
25 bool max_not_exceeded = tt.flags ? tt.limits.maximum <= max_limit : true;
26 return tt.limits.initial <= max_limit && max_not_exceeded && validate(tt.limits);
27 }
28
29 // validate a memory type 3.2.4
30 inline bool validate(const memory_type& mt) {
31 static constexpr uint64_t max_limit = (uint64_t)2 << 16;
32 bool max_not_exceeded = mt.flags ? mt.limits.maximum <= max_limit : true;
33 return mt.limits.initial <= max_limit && max_not_exceeded && validate(mt.limits);
34 }
35
36 // validate a global type 3.2.5
37 inline bool validate(const global_type& gt) {
38 return true;
39 }
40
41 };
42}} // ns sysio::vm
bool validate(const resizable_limits &rl)
bool validate(const memory_type &mt)
bool validate(const global_type &gt)
bool validate(const table_type &tt)
bool validate(const func_type &ft)
unsigned __int64 uint64_t
Definition stdint.h:136
uint8_t return_count
Definition types.hpp:45
resizable_limits limits
Definition types.hpp:87
resizable_limits limits
Definition types.hpp:82