Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::vm::bitcode_writer Class Reference

#include <bitcode_writer.hpp>

Classes

struct  br_table_parser
 

Public Member Functions

 bitcode_writer (growable_allocator &alloc, std::size_t source_bytes, module &mod)
 
 ~bitcode_writer ()
 
void emit_unreachable ()
 
void emit_nop ()
 
uint32_t emit_end ()
 
uint32_temit_return (uint32_t depth_change)
 
void emit_block ()
 
uint32_t emit_loop ()
 
uint32_temit_if ()
 
uint32_temit_else (uint32_t *if_loc)
 
uint32_temit_br (uint32_t depth_change)
 
uint32_temit_br_if (uint32_t depth_change)
 
auto emit_br_table (uint32_t table_size)
 
void emit_call (const func_type &ft, uint32_t funcnum)
 
void emit_call_indirect (const func_type &ft, uint32_t functypeidx)
 
void emit_drop ()
 
void emit_select ()
 
void emit_get_local (uint32_t localidx)
 
void emit_set_local (uint32_t localidx)
 
void emit_tee_local (uint32_t localidx)
 
void emit_get_global (uint32_t localidx)
 
void emit_set_global (uint32_t localidx)
 
void emit_current_memory ()
 
void emit_grow_memory ()
 
void emit_i32_const (uint32_t value)
 
void emit_i64_const (uint64_t value)
 
void emit_f32_const (float value)
 
void emit_f64_const (double value)
 
void emit_error ()
 
void fix_branch (uint32_t *branch, uint32_t target)
 
void emit_prologue (const func_type &ft, const guarded_vector< local_entry > &, uint32_t idx)
 
void emit_epilogue (const func_type &ft, const guarded_vector< local_entry > &locals, uint32_t idx)
 
void finalize (function_body &body)
 
const void * get_addr () const
 
const void * get_base_addr () const
 
 bitcode_writer (growable_allocator &alloc, std::size_t source_bytes, module &mod)
 
 ~bitcode_writer ()
 
void emit_unreachable ()
 
void emit_nop ()
 
uint32_t emit_end ()
 
uint32_temit_return (uint32_t depth_change)
 
void emit_block ()
 
uint32_t emit_loop ()
 
uint32_temit_if ()
 
uint32_temit_else (uint32_t *if_loc)
 
uint32_temit_br (uint32_t depth_change)
 
uint32_temit_br_if (uint32_t depth_change)
 
auto emit_br_table (uint32_t table_size)
 
void emit_call (const func_type &ft, uint32_t funcnum)
 
void emit_call_indirect (const func_type &ft, uint32_t functypeidx)
 
void emit_drop ()
 
void emit_select ()
 
void emit_get_local (uint32_t localidx)
 
void emit_set_local (uint32_t localidx)
 
void emit_tee_local (uint32_t localidx)
 
void emit_get_global (uint32_t localidx)
 
void emit_set_global (uint32_t localidx)
 
void emit_current_memory ()
 
void emit_grow_memory ()
 
void emit_i32_const (uint32_t value)
 
void emit_i64_const (uint64_t value)
 
void emit_f32_const (float value)
 
void emit_f64_const (double value)
 
void emit_error ()
 
void fix_branch (uint32_t *branch, uint32_t target)
 
void emit_prologue (const func_type &ft, const guarded_vector< local_entry > &, uint32_t idx)
 
void emit_epilogue (const func_type &ft, const guarded_vector< local_entry > &locals, uint32_t idx)
 
void finalize (function_body &body)
 
const void * get_addr () const
 
const void * get_base_addr () const
 

Friends

struct br_table_parser
 

Detailed Description

Definition at line 14 of file bitcode_writer.hpp.

Constructor & Destructor Documentation

◆ bitcode_writer() [1/2]

sysio::vm::bitcode_writer::bitcode_writer ( growable_allocator & alloc,
std::size_t source_bytes,
module & mod )
inlineexplicit

Definition at line 22 of file bitcode_writer.hpp.

22 :
23 _allocator(alloc),
24 _code_segment_base(alloc.start_code()),
25 fb(alloc, source_bytes),
26 _mod(&mod) {}

◆ ~bitcode_writer() [1/2]

sysio::vm::bitcode_writer::~bitcode_writer ( )
inline

Definition at line 27 of file bitcode_writer.hpp.

27{ _allocator.end_code<false>(_code_segment_base); }
void end_code(void *code_base)
Here is the call graph for this function:

◆ bitcode_writer() [2/2]

sysio::vm::bitcode_writer::bitcode_writer ( growable_allocator & alloc,
std::size_t source_bytes,
module & mod )
inlineexplicit

Definition at line 22 of file bitcode_writer.hpp.

22 :
23 _allocator(alloc),
24 _code_segment_base(alloc.start_code()),
25 fb(alloc, source_bytes),
26 _mod(&mod) {}

◆ ~bitcode_writer() [2/2]

sysio::vm::bitcode_writer::~bitcode_writer ( )
inline

Definition at line 27 of file bitcode_writer.hpp.

27{ _allocator.end_code<false>(_code_segment_base); }
Here is the call graph for this function:

Member Function Documentation

◆ emit_block() [1/2]

void sysio::vm::bitcode_writer::emit_block ( )
inline

Definition at line 34 of file bitcode_writer.hpp.

34{}

◆ emit_block() [2/2]

void sysio::vm::bitcode_writer::emit_block ( )
inline

Definition at line 34 of file bitcode_writer.hpp.

34{}

◆ emit_br() [1/2]

uint32_t * sysio::vm::bitcode_writer::emit_br ( uint32_t depth_change)
inline

Definition at line 45 of file bitcode_writer.hpp.

45 {
46 auto& instr = append_instr(br_t{});
47 instr.data = depth_change;
48 return &instr.pc;
49 }
Here is the caller graph for this function:

◆ emit_br() [2/2]

uint32_t * sysio::vm::bitcode_writer::emit_br ( uint32_t depth_change)
inline

Definition at line 45 of file bitcode_writer.hpp.

45 {
46 auto& instr = append_instr(br_t{});
47 instr.data = depth_change;
48 return &instr.pc;
49 }

◆ emit_br_if() [1/2]

uint32_t * sysio::vm::bitcode_writer::emit_br_if ( uint32_t depth_change)
inline

Definition at line 50 of file bitcode_writer.hpp.

50 {
51 auto& instr = append_instr(br_if_t{});
52 instr.data = depth_change;
53 return &instr.pc;
54 }

◆ emit_br_if() [2/2]

uint32_t * sysio::vm::bitcode_writer::emit_br_if ( uint32_t depth_change)
inline

Definition at line 50 of file bitcode_writer.hpp.

50 {
51 auto& instr = append_instr(br_if_t{});
52 instr.data = depth_change;
53 return &instr.pc;
54 }

◆ emit_br_table() [1/2]

auto sysio::vm::bitcode_writer::emit_br_table ( uint32_t table_size)
inline

Definition at line 91 of file bitcode_writer.hpp.

91{ return br_table_parser{ *this, table_size }; }

◆ emit_br_table() [2/2]

auto sysio::vm::bitcode_writer::emit_br_table ( uint32_t table_size)
inline

Definition at line 91 of file bitcode_writer.hpp.

91{ return br_table_parser{ *this, table_size }; }

◆ emit_call() [1/2]

void sysio::vm::bitcode_writer::emit_call ( const func_type & ft,
uint32_t funcnum )
inline

Definition at line 92 of file bitcode_writer.hpp.

92{ fb[op_index++] = call_t{ funcnum }; }

◆ emit_call() [2/2]

void sysio::vm::bitcode_writer::emit_call ( const func_type & ft,
uint32_t funcnum )
inline

Definition at line 92 of file bitcode_writer.hpp.

92{ fb[op_index++] = call_t{ funcnum }; }

◆ emit_call_indirect() [1/2]

void sysio::vm::bitcode_writer::emit_call_indirect ( const func_type & ft,
uint32_t functypeidx )
inline

Definition at line 93 of file bitcode_writer.hpp.

93{ fb[op_index++] = call_indirect_t{ functypeidx }; }

◆ emit_call_indirect() [2/2]

void sysio::vm::bitcode_writer::emit_call_indirect ( const func_type & ft,
uint32_t functypeidx )
inline

Definition at line 93 of file bitcode_writer.hpp.

93{ fb[op_index++] = call_indirect_t{ functypeidx }; }

◆ emit_current_memory() [1/2]

void sysio::vm::bitcode_writer::emit_current_memory ( )
inline

Definition at line 135 of file bitcode_writer.hpp.

135{ fb[op_index++] = current_memory_t{}; }

◆ emit_current_memory() [2/2]

void sysio::vm::bitcode_writer::emit_current_memory ( )
inline

Definition at line 135 of file bitcode_writer.hpp.

135{ fb[op_index++] = current_memory_t{}; }

◆ emit_drop() [1/2]

void sysio::vm::bitcode_writer::emit_drop ( )
inline

Definition at line 96 of file bitcode_writer.hpp.

96{ fb[op_index++] = drop_t{}; }

◆ emit_drop() [2/2]

void sysio::vm::bitcode_writer::emit_drop ( )
inline

Definition at line 96 of file bitcode_writer.hpp.

96{ fb[op_index++] = drop_t{}; }

◆ emit_else() [1/2]

uint32_t * sysio::vm::bitcode_writer::emit_else ( uint32_t * if_loc)
inline

Definition at line 40 of file bitcode_writer.hpp.

40 {
41 auto& else_ = append_instr(else_t{});
42 *if_loc = _base_offset + op_index;
43 return &else_.pc;
44 }

◆ emit_else() [2/2]

uint32_t * sysio::vm::bitcode_writer::emit_else ( uint32_t * if_loc)
inline

Definition at line 40 of file bitcode_writer.hpp.

40 {
41 auto& else_ = append_instr(else_t{});
42 *if_loc = _base_offset + op_index;
43 return &else_.pc;
44 }

◆ emit_end() [1/2]

uint32_t sysio::vm::bitcode_writer::emit_end ( )
inline

Definition at line 30 of file bitcode_writer.hpp.

30{ return op_index; }

◆ emit_end() [2/2]

uint32_t sysio::vm::bitcode_writer::emit_end ( )
inline

Definition at line 30 of file bitcode_writer.hpp.

30{ return op_index; }

◆ emit_epilogue() [1/2]

void sysio::vm::bitcode_writer::emit_epilogue ( const func_type & ft,
const guarded_vector< local_entry > & locals,
uint32_t idx )
inline

Definition at line 288 of file bitcode_writer.hpp.

288 {
289 fb.resize(op_index + 1);
290 uint32_t locals_count = 0;
291 for(uint32_t i = 0; i < locals.size(); ++i) {
292 locals_count += locals[i].count;
293 }
294 fb[fb.size() - 1] = return_t{ static_cast<uint32_t>(locals_count + ft.param_types.size()), ft.return_count, 0, 0 };
295 }
unsigned int uint32_t
Definition stdint.h:126

◆ emit_epilogue() [2/2]

void sysio::vm::bitcode_writer::emit_epilogue ( const func_type & ft,
const guarded_vector< local_entry > & locals,
uint32_t idx )
inline

Definition at line 288 of file bitcode_writer.hpp.

288 {
289 fb.resize(op_index + 1);
290 uint32_t locals_count = 0;
291 for(uint32_t i = 0; i < locals.size(); ++i) {
292 locals_count += locals[i].count;
293 }
294 fb[fb.size() - 1] = return_t{ static_cast<uint32_t>(locals_count + ft.param_types.size()), ft.return_count, 0, 0 };
295 }

◆ emit_error() [1/2]

void sysio::vm::bitcode_writer::emit_error ( )
inline

Definition at line 280 of file bitcode_writer.hpp.

280{ fb[op_index++] = error_t{}; }

◆ emit_error() [2/2]

void sysio::vm::bitcode_writer::emit_error ( )
inline

Definition at line 280 of file bitcode_writer.hpp.

280{ fb[op_index++] = error_t{}; }

◆ emit_f32_const() [1/2]

void sysio::vm::bitcode_writer::emit_f32_const ( float value)
inline

Definition at line 140 of file bitcode_writer.hpp.

140{ fb[op_index++] = f32_const_t{ value }; }
#define value
Definition pkcs11.h:157

◆ emit_f32_const() [2/2]

void sysio::vm::bitcode_writer::emit_f32_const ( float value)
inline

Definition at line 140 of file bitcode_writer.hpp.

140{ fb[op_index++] = f32_const_t{ value }; }

◆ emit_f64_const() [1/2]

void sysio::vm::bitcode_writer::emit_f64_const ( double value)
inline

Definition at line 141 of file bitcode_writer.hpp.

141{ fb[op_index++] = f64_const_t{ value }; }

◆ emit_f64_const() [2/2]

void sysio::vm::bitcode_writer::emit_f64_const ( double value)
inline

Definition at line 141 of file bitcode_writer.hpp.

141{ fb[op_index++] = f64_const_t{ value }; }

◆ emit_get_global() [1/2]

void sysio::vm::bitcode_writer::emit_get_global ( uint32_t localidx)
inline

Definition at line 101 of file bitcode_writer.hpp.

101{ fb[op_index++] = get_global_t{localidx}; }

◆ emit_get_global() [2/2]

void sysio::vm::bitcode_writer::emit_get_global ( uint32_t localidx)
inline

Definition at line 101 of file bitcode_writer.hpp.

101{ fb[op_index++] = get_global_t{localidx}; }

◆ emit_get_local() [1/2]

void sysio::vm::bitcode_writer::emit_get_local ( uint32_t localidx)
inline

Definition at line 98 of file bitcode_writer.hpp.

98{ fb[op_index++] = get_local_t{localidx}; }

◆ emit_get_local() [2/2]

void sysio::vm::bitcode_writer::emit_get_local ( uint32_t localidx)
inline

Definition at line 98 of file bitcode_writer.hpp.

98{ fb[op_index++] = get_local_t{localidx}; }

◆ emit_grow_memory() [1/2]

void sysio::vm::bitcode_writer::emit_grow_memory ( )
inline

Definition at line 136 of file bitcode_writer.hpp.

136{ fb[op_index++] = grow_memory_t{}; }

◆ emit_grow_memory() [2/2]

void sysio::vm::bitcode_writer::emit_grow_memory ( )
inline

Definition at line 136 of file bitcode_writer.hpp.

136{ fb[op_index++] = grow_memory_t{}; }

◆ emit_i32_const() [1/2]

void sysio::vm::bitcode_writer::emit_i32_const ( uint32_t value)
inline

Definition at line 138 of file bitcode_writer.hpp.

138{ fb[op_index++] = i32_const_t{ value }; }

◆ emit_i32_const() [2/2]

void sysio::vm::bitcode_writer::emit_i32_const ( uint32_t value)
inline

Definition at line 138 of file bitcode_writer.hpp.

138{ fb[op_index++] = i32_const_t{ value }; }

◆ emit_i64_const() [1/2]

void sysio::vm::bitcode_writer::emit_i64_const ( uint64_t value)
inline

Definition at line 139 of file bitcode_writer.hpp.

139{ fb[op_index++] = i64_const_t{ value }; }

◆ emit_i64_const() [2/2]

void sysio::vm::bitcode_writer::emit_i64_const ( uint64_t value)
inline

Definition at line 139 of file bitcode_writer.hpp.

139{ fb[op_index++] = i64_const_t{ value }; }

◆ emit_if() [1/2]

uint32_t * sysio::vm::bitcode_writer::emit_if ( )
inline

Definition at line 36 of file bitcode_writer.hpp.

36 {
37 if_t& instr = append_instr(if_t{});
38 return &instr.pc;
39 }

◆ emit_if() [2/2]

uint32_t * sysio::vm::bitcode_writer::emit_if ( )
inline

Definition at line 36 of file bitcode_writer.hpp.

36 {
37 if_t& instr = append_instr(if_t{});
38 return &instr.pc;
39 }

◆ emit_loop() [1/2]

uint32_t sysio::vm::bitcode_writer::emit_loop ( )
inline

Definition at line 35 of file bitcode_writer.hpp.

35{ return op_index; }

◆ emit_loop() [2/2]

uint32_t sysio::vm::bitcode_writer::emit_loop ( )
inline

Definition at line 35 of file bitcode_writer.hpp.

35{ return op_index; }

◆ emit_nop() [1/2]

void sysio::vm::bitcode_writer::emit_nop ( )
inline

Definition at line 29 of file bitcode_writer.hpp.

29{ fb[op_index++] = nop_t{}; }

◆ emit_nop() [2/2]

void sysio::vm::bitcode_writer::emit_nop ( )
inline

Definition at line 29 of file bitcode_writer.hpp.

29{ fb[op_index++] = nop_t{}; }

◆ emit_prologue() [1/2]

void sysio::vm::bitcode_writer::emit_prologue ( const func_type & ft,
const guarded_vector< local_entry > & ,
uint32_t idx )
inline

Definition at line 283 of file bitcode_writer.hpp.

283 {
284 op_index = 0;
285 // pre-allocate for the function body code, so we have a big blob of memory to work with during function code parsing
286 fb = guarded_vector<opcode>{_allocator, _mod->code[idx].size };
287 }
managed_vector< T, growable_allocator > guarded_vector
Definition types.hpp:29
guarded_vector< function_body > code
Definition types.hpp:177

◆ emit_prologue() [2/2]

void sysio::vm::bitcode_writer::emit_prologue ( const func_type & ft,
const guarded_vector< local_entry > & ,
uint32_t idx )
inline

Definition at line 283 of file bitcode_writer.hpp.

283 {
284 op_index = 0;
285 // pre-allocate for the function body code, so we have a big blob of memory to work with during function code parsing
286 fb = guarded_vector<opcode>{_allocator, _mod->code[idx].size };
287 }

◆ emit_return() [1/2]

uint32_t * sysio::vm::bitcode_writer::emit_return ( uint32_t depth_change)
inline

Definition at line 31 of file bitcode_writer.hpp.

31 {
32 return emit_br(depth_change);
33 }
uint32_t * emit_br(uint32_t depth_change)
Here is the call graph for this function:

◆ emit_return() [2/2]

uint32_t * sysio::vm::bitcode_writer::emit_return ( uint32_t depth_change)
inline

Definition at line 31 of file bitcode_writer.hpp.

31 {
32 return emit_br(depth_change);
33 }
Here is the call graph for this function:

◆ emit_select() [1/2]

void sysio::vm::bitcode_writer::emit_select ( )
inline

Definition at line 97 of file bitcode_writer.hpp.

97{ fb[op_index++] = select_t{}; }

◆ emit_select() [2/2]

void sysio::vm::bitcode_writer::emit_select ( )
inline

Definition at line 97 of file bitcode_writer.hpp.

97{ fb[op_index++] = select_t{}; }

◆ emit_set_global() [1/2]

void sysio::vm::bitcode_writer::emit_set_global ( uint32_t localidx)
inline

Definition at line 102 of file bitcode_writer.hpp.

102{ fb[op_index++] = set_global_t{localidx}; }

◆ emit_set_global() [2/2]

void sysio::vm::bitcode_writer::emit_set_global ( uint32_t localidx)
inline

Definition at line 102 of file bitcode_writer.hpp.

102{ fb[op_index++] = set_global_t{localidx}; }

◆ emit_set_local() [1/2]

void sysio::vm::bitcode_writer::emit_set_local ( uint32_t localidx)
inline

Definition at line 99 of file bitcode_writer.hpp.

99{ fb[op_index++] = set_local_t{localidx}; }

◆ emit_set_local() [2/2]

void sysio::vm::bitcode_writer::emit_set_local ( uint32_t localidx)
inline

Definition at line 99 of file bitcode_writer.hpp.

99{ fb[op_index++] = set_local_t{localidx}; }

◆ emit_tee_local() [1/2]

void sysio::vm::bitcode_writer::emit_tee_local ( uint32_t localidx)
inline

Definition at line 100 of file bitcode_writer.hpp.

100{ fb[op_index++] = tee_local_t{localidx}; }

◆ emit_tee_local() [2/2]

void sysio::vm::bitcode_writer::emit_tee_local ( uint32_t localidx)
inline

Definition at line 100 of file bitcode_writer.hpp.

100{ fb[op_index++] = tee_local_t{localidx}; }

◆ emit_unreachable() [1/2]

void sysio::vm::bitcode_writer::emit_unreachable ( )
inline

Definition at line 28 of file bitcode_writer.hpp.

28{ fb[op_index++] = unreachable_t{}; };

◆ emit_unreachable() [2/2]

void sysio::vm::bitcode_writer::emit_unreachable ( )
inline

Definition at line 28 of file bitcode_writer.hpp.

28{ fb[op_index++] = unreachable_t{}; };

◆ finalize() [1/2]

void sysio::vm::bitcode_writer::finalize ( function_body & body)
inline

Definition at line 297 of file bitcode_writer.hpp.

297 {
298 op_index++;
299 fb.resize(op_index);
300 body.code = fb.raw();
301 body.size = op_index;
302 _base_offset += body.size;
303 }

◆ finalize() [2/2]

void sysio::vm::bitcode_writer::finalize ( function_body & body)
inline

Definition at line 297 of file bitcode_writer.hpp.

297 {
298 op_index++;
299 fb.resize(op_index);
300 body.code = fb.raw();
301 body.size = op_index;
302 _base_offset += body.size;
303 }

◆ fix_branch() [1/2]

void sysio::vm::bitcode_writer::fix_branch ( uint32_t * branch,
uint32_t target )
inline

Definition at line 282 of file bitcode_writer.hpp.

282{ if(branch) *branch = _base_offset + target; }

◆ fix_branch() [2/2]

void sysio::vm::bitcode_writer::fix_branch ( uint32_t * branch,
uint32_t target )
inline

Definition at line 282 of file bitcode_writer.hpp.

282{ if(branch) *branch = _base_offset + target; }

◆ get_addr() [1/2]

const void * sysio::vm::bitcode_writer::get_addr ( ) const
inline

Definition at line 305 of file bitcode_writer.hpp.

305{ return fb.raw() + op_index; }

◆ get_addr() [2/2]

const void * sysio::vm::bitcode_writer::get_addr ( ) const
inline

Definition at line 305 of file bitcode_writer.hpp.

305{ return fb.raw() + op_index; }

◆ get_base_addr() [1/2]

const void * sysio::vm::bitcode_writer::get_base_addr ( ) const
inline

Definition at line 306 of file bitcode_writer.hpp.

306{ return _code_segment_base; }

◆ get_base_addr() [2/2]

const void * sysio::vm::bitcode_writer::get_base_addr ( ) const
inline

Definition at line 306 of file bitcode_writer.hpp.

306{ return _code_segment_base; }

Friends And Related Symbol Documentation

◆ br_table_parser

br_table_parser
friend

Definition at line 57 of file bitcode_writer.hpp.


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