Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::vm::varint< N > Class Template Reference

#include <leb128.hpp>

Public Member Functions

constexpr varint (int8_t v)
 
constexpr varint (int32_t v)
 
constexpr varint (int64_t v)
 
constexpr varint (guarded_ptr< uint8_t > &code)
 
constexpr void from (int8_t v)
 
constexpr void from (int32_t v)
 
constexpr void from (int64_t v)
 
constexpr void from (guarded_ptr< uint8_t > &code)
 
size_t size () const
 
template<size_t M = N, typename = typename std::enable_if_t<M == 1, int>>
constexpr bool to ()
 
template<size_t M = N, typename = typename std::enable_if_t<M == 7, int>>
constexpr int8_t to ()
 
template<size_t M = N, typename = typename std::enable_if_t<M == 32, int>>
constexpr int32_t to ()
 
template<size_t M = N, typename = typename std::enable_if_t<M == 64, int>>
constexpr int64_t to ()
 
void print () const
 
constexpr varint (int8_t v)
 
constexpr varint (int32_t v)
 
constexpr varint (int64_t v)
 
constexpr varint (guarded_ptr< uint8_t > &code)
 
constexpr void from (int8_t v)
 
constexpr void from (int32_t v)
 
constexpr void from (int64_t v)
 
constexpr void from (guarded_ptr< uint8_t > &code)
 
size_t size () const
 
template<size_t M = N, typename = typename std::enable_if_t<M == 1, int>>
constexpr bool to ()
 
template<size_t M = N, typename = typename std::enable_if_t<M == 7, int>>
constexpr int8_t to ()
 
template<size_t M = N, typename = typename std::enable_if_t<M == 32, int>>
constexpr int32_t to ()
 
template<size_t M = N, typename = typename std::enable_if_t<M == 64, int>>
constexpr int64_t to ()
 
void print () const
 

Detailed Description

template<size_t N>
class sysio::vm::varint< N >

Definition at line 111 of file leb128.hpp.

Constructor & Destructor Documentation

◆ varint() [1/8]

template<size_t N>
sysio::vm::varint< N >::varint ( int8_t v)
inlineexplicitconstexpr

Definition at line 115 of file leb128.hpp.

115{ from(v); }
constexpr void from(int8_t v)
Definition leb128.hpp:120
Here is the call graph for this function:

◆ varint() [2/8]

template<size_t N>
sysio::vm::varint< N >::varint ( int32_t v)
inlineexplicitconstexpr

Definition at line 116 of file leb128.hpp.

116{ from(v); }
Here is the call graph for this function:

◆ varint() [3/8]

template<size_t N>
sysio::vm::varint< N >::varint ( int64_t v)
inlineexplicitconstexpr

Definition at line 117 of file leb128.hpp.

117{ from(v); }
Here is the call graph for this function:

◆ varint() [4/8]

template<size_t N>
sysio::vm::varint< N >::varint ( guarded_ptr< uint8_t > & code)
inlineconstexpr

Definition at line 118 of file leb128.hpp.

118{ from(code); }
Here is the call graph for this function:

◆ varint() [5/8]

template<size_t N>
sysio::vm::varint< N >::varint ( int8_t v)
inlineexplicitconstexpr

Definition at line 115 of file leb128.hpp.

115{ from(v); }
Here is the call graph for this function:

◆ varint() [6/8]

template<size_t N>
sysio::vm::varint< N >::varint ( int32_t v)
inlineexplicitconstexpr

Definition at line 116 of file leb128.hpp.

116{ from(v); }
Here is the call graph for this function:

◆ varint() [7/8]

template<size_t N>
sysio::vm::varint< N >::varint ( int64_t v)
inlineexplicitconstexpr

Definition at line 117 of file leb128.hpp.

117{ from(v); }
Here is the call graph for this function:

◆ varint() [8/8]

template<size_t N>
sysio::vm::varint< N >::varint ( guarded_ptr< uint8_t > & code)
inlineconstexpr

Definition at line 118 of file leb128.hpp.

118{ from(code); }
Here is the call graph for this function:

Member Function Documentation

◆ from() [1/8]

template<size_t N>
void sysio::vm::varint< N >::from ( guarded_ptr< uint8_t > & code)
inlineconstexpr

Definition at line 133 of file leb128.hpp.

133 {
134 uint8_t cnt = 0;
135 for (;; cnt++) {
136 SYS_VM_ASSERT( cnt < bytes_needed<N>(), wasm_interpreter_exception, "incorrect leb128 encoding" );
137 SYS_VM_ASSERT( code.offset()+cnt < code.bounds(), wasm_interpreter_exception, "pointer out of bounds" );
138 storage[cnt] = code[cnt];
139 if ((storage[cnt] & 0x80) == 0) {
140 if( static_cast<size_t>(cnt + 1) == bytes_needed<N>() ) {
141 uint32_t offset = N - 7*(bytes_needed<N>()-1);
142 uint8_t mask = static_cast<uint8_t>(~(uint32_t)0 << offset) & 0x7F;
143 uint8_t expected = (storage[cnt] & (uint32_t(1) << uint32_t(offset - 1)))? mask : 0;
144 SYS_VM_ASSERT((mask & storage[cnt]) == expected, wasm_parse_exception, "unused bits of signed leb128 must be the same as the sign bit");
145 }
146 break;
147 }
148 }
149 code += cnt+1;
150 bytes_used = cnt+1;
151 }
size_t constexpr bytes_needed()
Definition leb128.hpp:14
const int N
Definition quantize.cpp:54
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
#define SYS_VM_ASSERT(expr, exc_type, msg)
Definition exceptions.hpp:8
Here is the call graph for this function:

◆ from() [2/8]

template<size_t N>
void sysio::vm::varint< N >::from ( guarded_ptr< uint8_t > & code)
inlineconstexpr

Definition at line 133 of file leb128.hpp.

133 {
134 uint8_t cnt = 0;
135 for (;; cnt++) {
136 SYS_VM_ASSERT( cnt < bytes_needed<N>(), wasm_interpreter_exception, "incorrect leb128 encoding" );
137 SYS_VM_ASSERT( code.offset()+cnt < code.bounds(), wasm_interpreter_exception, "pointer out of bounds" );
138 storage[cnt] = code[cnt];
139 if ((storage[cnt] & 0x80) == 0) {
140 if( static_cast<size_t>(cnt + 1) == bytes_needed<N>() ) {
141 uint32_t offset = N - 7*(bytes_needed<N>()-1);
142 uint8_t mask = static_cast<uint8_t>(~(uint32_t)0 << offset) & 0x7F;
143 uint8_t expected = (storage[cnt] & (uint32_t(1) << uint32_t(offset - 1)))? mask : 0;
144 SYS_VM_ASSERT((mask & storage[cnt]) == expected, wasm_parse_exception, "unused bits of signed leb128 must be the same as the sign bit");
145 }
146 break;
147 }
148 }
149 code += cnt+1;
150 bytes_used = cnt+1;
151 }
Here is the call graph for this function:

◆ from() [3/8]

template<size_t N>
void sysio::vm::varint< N >::from ( int32_t v)
inlineconstexpr

Definition at line 124 of file leb128.hpp.

124 {
125 static_assert(N >= 32, "cant use this constructor with N < 32");
126 _from(v);
127 }

◆ from() [4/8]

template<size_t N>
void sysio::vm::varint< N >::from ( int32_t v)
inlineconstexpr

Definition at line 124 of file leb128.hpp.

124 {
125 static_assert(N >= 32, "cant use this constructor with N < 32");
126 _from(v);
127 }

◆ from() [5/8]

template<size_t N>
void sysio::vm::varint< N >::from ( int64_t v)
inlineconstexpr

Definition at line 128 of file leb128.hpp.

128 {
129 static_assert(N >= 64, "cant use this constructor with N < 32");
130 _from(v);
131 }

◆ from() [6/8]

template<size_t N>
void sysio::vm::varint< N >::from ( int64_t v)
inlineconstexpr

Definition at line 128 of file leb128.hpp.

128 {
129 static_assert(N >= 64, "cant use this constructor with N < 32");
130 _from(v);
131 }

◆ from() [7/8]

template<size_t N>
void sysio::vm::varint< N >::from ( int8_t v)
inlineconstexpr

Definition at line 120 of file leb128.hpp.

120 {
121 static_assert(N >= 7, "cant use this constructor with N < 7");
122 storage[0] = v & 0x7f;
123 }
Here is the caller graph for this function:

◆ from() [8/8]

template<size_t N>
void sysio::vm::varint< N >::from ( int8_t v)
inlineconstexpr

Definition at line 120 of file leb128.hpp.

120 {
121 static_assert(N >= 7, "cant use this constructor with N < 7");
122 storage[0] = v & 0x7f;
123 }

◆ print() [1/2]

template<size_t N>
void sysio::vm::varint< N >::print ( ) const
inline

Definition at line 171 of file leb128.hpp.

171 {
172 for (int i=0; i < bytes_used; i++) {
173 std::cout << std::hex << "0x" << (int)storage[i] << ' ';
174 }
175 std::cout << std::endl;
176 }

◆ print() [2/2]

template<size_t N>
void sysio::vm::varint< N >::print ( ) const
inline

Definition at line 171 of file leb128.hpp.

171 {
172 for (int i=0; i < bytes_used; i++) {
173 std::cout << std::hex << "0x" << (int)storage[i] << ' ';
174 }
175 std::cout << std::endl;
176 }

◆ size() [1/2]

template<size_t N>
size_t sysio::vm::varint< N >::size ( ) const
inline

Definition at line 153 of file leb128.hpp.

153{ return bytes_used; }

◆ size() [2/2]

template<size_t N>
size_t sysio::vm::varint< N >::size ( ) const
inline

Definition at line 153 of file leb128.hpp.

153{ return bytes_used; }

◆ to() [1/8]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 1, int>>
bool sysio::vm::varint< N >::to ( )
inlineconstexpr

Definition at line 156 of file leb128.hpp.

156{ return storage[0]; }
Here is the caller graph for this function:

◆ to() [2/8]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 7, int>>
int8_t sysio::vm::varint< N >::to ( )
inlineconstexpr

Definition at line 159 of file leb128.hpp.

159 {
160 if (storage[0] & 0x40)
161 return storage[0] | (~0u << 7);
162 return storage[0];
163 }

◆ to() [3/8]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 32, int>>
int32_t sysio::vm::varint< N >::to ( )
inlineconstexpr

Definition at line 166 of file leb128.hpp.

166{ return _to<int32_t>(); }

◆ to() [4/8]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 64, int>>
int64_t sysio::vm::varint< N >::to ( )
inlineconstexpr

Definition at line 169 of file leb128.hpp.

169{ return _to<int64_t>(); }

◆ to() [5/8]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 1, int>>
bool sysio::vm::varint< N >::to ( )
inlineconstexpr

Definition at line 156 of file leb128.hpp.

156{ return storage[0]; }

◆ to() [6/8]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 7, int>>
int8_t sysio::vm::varint< N >::to ( )
inlineconstexpr

Definition at line 159 of file leb128.hpp.

159 {
160 if (storage[0] & 0x40)
161 return storage[0] | (~0u << 7);
162 return storage[0];
163 }

◆ to() [7/8]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 32, int>>
int32_t sysio::vm::varint< N >::to ( )
inlineconstexpr

Definition at line 166 of file leb128.hpp.

166{ return _to<int32_t>(); }

◆ to() [8/8]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 64, int>>
int64_t sysio::vm::varint< N >::to ( )
inlineconstexpr

Definition at line 169 of file leb128.hpp.

169{ return _to<int64_t>(); }

The documentation for this class was generated from the following files: