Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::wasm_injections::injector_utils Struct Reference

#include <wasm_sysio_injection.hpp>

Static Public Member Functions

static void init (Module &mod)
 
static void build_type_slots (Module &mod)
 
template<ResultType Result, ValueType... Params>
static void add_type_slot (Module &mod)
 
static void get_next_indices (Module &module, int &next_function_index, int &next_actual_index)
 
template<ResultType Result, ValueType... Params>
static void add_import (Module &module, const char *func_name, int32_t &index)
 

Static Public Attributes

static std::map< std::vector< uint16_t >, uint32_ttype_slots
 
static std::map< std::string, uint32_tregistered_injected
 
static std::map< uint32_t, uint32_tinjected_index_mapping
 
static uint32_t next_injected_index
 

Detailed Description

Definition at line 24 of file wasm_sysio_injection.hpp.

Member Function Documentation

◆ add_import()

template<ResultType Result, ValueType... Params>
static void sysio::chain::wasm_injections::injector_utils::add_import ( Module & module,
const char * func_name,
int32_t & index )
inlinestatic

Definition at line 63 of file wasm_sysio_injection.hpp.

63 {
64 if (module.functions.imports.size() == 0 || registered_injected.find(func_name) == registered_injected.end() ) {
65 add_type_slot<Result, Params...>( module );
66 const uint32_t func_type_index = type_slots[{ FromResultType<Result>::value, FromValueType<Params>::value... }];
67 int actual_index;
68 get_next_indices( module, index, actual_index );
69 registered_injected.emplace( func_name, index );
70 decltype(module.functions.imports) new_import = { {{func_type_index}, sysio_injected_module_name, std::move(func_name)} };
71 // prepend to the head of the imports
72 module.functions.imports.insert( module.functions.imports.begin()+(registered_injected.size()-1), new_import.begin(), new_import.end() );
73 injected_index_mapping.emplace( index, actual_index );
74
75 // shift all exported functions by 1
76 for ( size_t i=0; i < module.exports.size(); i++ ) {
77 if ( module.exports[i].kind == IR::ObjectKind::function ) {
78 module.exports[i].index++;
79 }
80 }
81
82 // update the start function
83 if ( module.startFunctionIndex != UINTPTR_MAX ) {
84 module.startFunctionIndex++;
85 }
86
87 // shift all table entries for call indirect
88 for(TableSegment& ts : module.tableSegments) {
89 for(auto& idx : ts.indices)
90 idx++;
91 }
92 }
93 else {
94 index = registered_injected[func_name];
95 }
96 }
unsigned int uint32_t
Definition stdint.h:126
#define UINTPTR_MAX
Definition stdint.h:227
static std::map< std::vector< uint16_t >, uint32_t > type_slots
static void get_next_indices(Module &module, int &next_function_index, int &next_actual_index)
static std::map< uint32_t, uint32_t > injected_index_mapping
static std::map< std::string, uint32_t > registered_injected
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_type_slot()

template<ResultType Result, ValueType... Params>
static void sysio::chain::wasm_injections::injector_utils::add_type_slot ( Module & mod)
inlinestatic

Definition at line 49 of file wasm_sysio_injection.hpp.

49 {
50 if ( type_slots.find({FromResultType<Result>::value, FromValueType<Params>::value...}) == type_slots.end() ) {
51 type_slots.emplace( std::vector<uint16_t>{FromResultType<Result>::value, FromValueType<Params>::value...}, mod.types.size() );
52 mod.types.push_back( FunctionType::get( Result, { Params... } ) );
53 }
54 }
static IR_API const FunctionType * get(ResultType ret, const std::initializer_list< ValueType > &parameters)
Definition Types.cpp:38
Here is the call graph for this function:
Here is the caller graph for this function:

◆ build_type_slots()

static void sysio::chain::wasm_injections::injector_utils::build_type_slots ( Module & mod)
inlinestatic

Definition at line 38 of file wasm_sysio_injection.hpp.

38 {
39 // add the module types to the type_slots map
40 for ( size_t i=0; i < mod.types.size(); i++ ) {
41 std::vector<uint16_t> type_slot_list = { static_cast<uint16_t>(mod.types[i]->ret) };
42 for ( auto param : mod.types[i]->parameters )
43 type_slot_list.push_back( static_cast<uint16_t>(param) );
44 type_slots.emplace( type_slot_list, i );
45 }
46 }
unsigned short uint16_t
Definition stdint.h:125
Here is the caller graph for this function:

◆ get_next_indices()

static void sysio::chain::wasm_injections::injector_utils::get_next_indices ( Module & module,
int & next_function_index,
int & next_actual_index )
inlinestatic

Definition at line 57 of file wasm_sysio_injection.hpp.

57 {
58 next_function_index = module.functions.imports.size() + module.functions.defs.size() + registered_injected.size();
59 next_actual_index = next_injected_index++;
60 }
Here is the caller graph for this function:

◆ init()

static void sysio::chain::wasm_injections::injector_utils::init ( Module & mod)
inlinestatic

Definition at line 30 of file wasm_sysio_injection.hpp.

30 {
31 type_slots.clear();
32 registered_injected.clear();
34 build_type_slots( mod );
36 }
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ injected_index_mapping

std::map< uint32_t, uint32_t > sysio::chain::wasm_injections::injector_utils::injected_index_mapping
static

Definition at line 27 of file wasm_sysio_injection.hpp.

◆ next_injected_index

uint32_t sysio::chain::wasm_injections::injector_utils::next_injected_index
static

Definition at line 28 of file wasm_sysio_injection.hpp.

◆ registered_injected

std::map< std::string, uint32_t > sysio::chain::wasm_injections::injector_utils::registered_injected
static

Definition at line 26 of file wasm_sysio_injection.hpp.

◆ type_slots

std::map< std::vector< uint16_t >, uint32_t > sysio::chain::wasm_injections::injector_utils::type_slots
static

Definition at line 25 of file wasm_sysio_injection.hpp.


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