Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::vm::machine_code_writer< Context >::br_table_generator Struct Reference

#include <x86_64.hpp>

Collaboration diagram for sysio::vm::machine_code_writer< Context >::br_table_generator:

Classes

struct  stack_item
 

Public Member Functions

void * emit_case (uint32_t depth_change)
 
void * emit_default (uint32_t depth_change)
 
void * emit_case (uint32_t depth_change)
 
void * emit_default (uint32_t depth_change)
 

Public Attributes

machine_code_writer_this
 
int _i = 0
 
std::vector< stack_itemstack
 

Detailed Description

template<typename Context>
struct sysio::vm::machine_code_writer< Context >::br_table_generator

Definition at line 228 of file x86_64.hpp.

Member Function Documentation

◆ emit_case() [1/2]

template<typename Context >
void * sysio::vm::machine_code_writer< Context >::br_table_generator::emit_case ( uint32_t depth_change)
inline

Definition at line 229 of file x86_64.hpp.

229 {
230 while(true) {
231 assert(!stack.empty() && "The parser is supposed to handle the number of elements in br_table.");
232 auto [min, max, label] = stack.back();
233 stack.pop_back();
234 if (label) {
235 fix_branch(label, _this->code);
236 }
237 if (max - min > 1) {
238 // Emit a comparison to the midpoint of the current range
239 uint32_t mid = min + (max - min)/2;
240 // cmp i, %mid
241 _this->emit_bytes(0x3d);
242 _this->emit_operand32(mid);
243 // jae MID
244 _this->emit_bytes(0x0f, 0x83);
245 void* mid_label = _this->emit_branch_target32();
246 stack.push_back({mid,max,mid_label});
247 stack.push_back({min,mid,nullptr});
248 } else {
249 assert(min == static_cast<uint32_t>(_i));
250 _i++;
251 if (depth_change == 0u || depth_change == 0x80000001u) {
252 if(label) {
253 return label;
254 } else {
255 // jmp TARGET
256 _this->emit_bytes(0xe9);
257 return _this->emit_branch_target32();
258 }
259 } else {
260 // jne NEXT
261 _this->emit_multipop(depth_change);
262 // jmp TARGET
263 _this->emit_bytes(0xe9);
264 return _this->emit_branch_target32();
265 }
266 }
267 }
268
269 }
static void fix_branch(void *branch, void *target)
Definition x86_64.hpp:2080
const T & min(const T &a, const T &b)
Definition utility.hpp:140
unsigned int uint32_t
Definition stdint.h:126
char * label
Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_case() [2/2]

template<typename Context >
void * sysio::vm::machine_code_writer< Context >::br_table_generator::emit_case ( uint32_t depth_change)
inline

Definition at line 229 of file x86_64.hpp.

229 {
230 while(true) {
231 assert(!stack.empty() && "The parser is supposed to handle the number of elements in br_table.");
232 auto [min, max, label] = stack.back();
233 stack.pop_back();
234 if (label) {
235 fix_branch(label, _this->code);
236 }
237 if (max - min > 1) {
238 // Emit a comparison to the midpoint of the current range
239 uint32_t mid = min + (max - min)/2;
240 // cmp i, %mid
241 _this->emit_bytes(0x3d);
242 _this->emit_operand32(mid);
243 // jae MID
244 _this->emit_bytes(0x0f, 0x83);
245 void* mid_label = _this->emit_branch_target32();
246 stack.push_back({mid,max,mid_label});
247 stack.push_back({min,mid,nullptr});
248 } else {
249 assert(min == static_cast<uint32_t>(_i));
250 _i++;
251 if (depth_change == 0u || depth_change == 0x80000001u) {
252 if(label) {
253 return label;
254 } else {
255 // jmp TARGET
256 _this->emit_bytes(0xe9);
257 return _this->emit_branch_target32();
258 }
259 } else {
260 // jne NEXT
261 _this->emit_multipop(depth_change);
262 // jmp TARGET
263 _this->emit_bytes(0xe9);
264 return _this->emit_branch_target32();
265 }
266 }
267 }
268
269 }
Here is the call graph for this function:

◆ emit_default() [1/2]

template<typename Context >
void * sysio::vm::machine_code_writer< Context >::br_table_generator::emit_default ( uint32_t depth_change)
inline

Definition at line 270 of file x86_64.hpp.

270 {
271 void* result = emit_case(depth_change);
272 assert(stack.empty() && "unexpected default.");
273 return result;
274 }
void * emit_case(uint32_t depth_change)
Definition x86_64.hpp:229
Here is the call graph for this function:

◆ emit_default() [2/2]

template<typename Context >
void * sysio::vm::machine_code_writer< Context >::br_table_generator::emit_default ( uint32_t depth_change)
inline

Definition at line 270 of file x86_64.hpp.

270 {
271 void* result = emit_case(depth_change);
272 assert(stack.empty() && "unexpected default.");
273 return result;
274 }
Here is the call graph for this function:

Member Data Documentation

◆ _i

template<typename Context >
int sysio::vm::machine_code_writer< Context >::br_table_generator::_i = 0

Definition at line 276 of file x86_64.hpp.

◆ _this

template<typename Context >
machine_code_writer * sysio::vm::machine_code_writer< Context >::br_table_generator::_this

Definition at line 275 of file x86_64.hpp.

◆ stack

template<typename Context >
std::vector< stack_item > sysio::vm::machine_code_writer< Context >::br_table_generator::stack

Definition at line 285 of file x86_64.hpp.


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