libyasm
Public Types | Data Fields
yasm_bytecode_callback Struct Reference

Bytecode callback structure. More...

#include <bytecode.h>

Public Types

enum  yasm_bytecode_special_type { YASM_BC_SPECIAL_NONE = 0, YASM_BC_SPECIAL_RESERVE, YASM_BC_SPECIAL_OFFSET, YASM_BC_SPECIAL_INSN }
 Special bytecode classifications. More...
 

Data Fields

void(* destroy )(void *contents)
 Destroys the implementation-specific data. More...
 
void(* print )(const void *contents, FILE *f, int indent_level)
 Prints the implementation-specific data (for debugging purposes). More...
 
void(* finalize )(yasm_bytecode *bc, yasm_bytecode *prev_bc)
 Finalizes the bytecode after parsing. More...
 
int(* elem_size )(yasm_bytecode *bc)
 Return elements size of a data bytecode. More...
 
int(* calc_len )(yasm_bytecode *bc, yasm_bc_add_span_func add_span, void *add_span_data)
 Calculates the minimum size of a bytecode. More...
 
int(* expand )(yasm_bytecode *bc, int span, long old_val, long new_val, long *neg_thres, long *pos_thres)
 Recalculates the bytecode's length based on an expanded span length. More...
 
int(* tobytes )(yasm_bytecode *bc, unsigned char **bufp, unsigned char *bufstart, void *d, yasm_output_value_func output_value, yasm_output_reloc_func output_reloc)
 Convert a bytecode into its byte representation. More...
 
enum
yasm_bytecode_callback::yasm_bytecode_special_type 
special
 

Detailed Description

Bytecode callback structure.

Any implementation of a specific bytecode must implement these functions and this callback structure. The bytecode implementation-specific data is stored in yasm_bytecode.contents.

Definition at line 63 of file bytecode.h.

Member Enumeration Documentation

Special bytecode classifications.

Most bytecode types should use #YASM_BC_SPECIAL_NONE. Others cause special handling to kick in in various parts of yasm.

Enumerator
YASM_BC_SPECIAL_RESERVE 

Bytecode reserves space instead of outputting data.

YASM_BC_SPECIAL_OFFSET 

Adjusts offset instead of calculating len.

YASM_BC_SPECIAL_INSN 

Instruction bytecode.

Definition at line 168 of file bytecode.h.

Field Documentation

int(* yasm_bytecode_callback::calc_len)(yasm_bytecode *bc, yasm_bc_add_span_func add_span, void *add_span_data)

Calculates the minimum size of a bytecode.

Called from yasm_bc_calc_len(). A generic fill-in for this is yasm_bc_calc_len_common(), but as this function internal errors when called, be very careful when using it! This function should simply add to bc->len and not set it directly (it's initialized by yasm_bc_calc_len() prior to passing control to this function).

Parameters
bcbytecode
add_spanfunction to call to add a span
add_span_dataextra data to be passed to add_span function
Returns
0 if no error occurred, nonzero if there was an error recognized (and output) during execution.
Note
May store to bytecode updated expressions.

Definition at line 108 of file bytecode.h.

void(* yasm_bytecode_callback::destroy)(void *contents)

Destroys the implementation-specific data.

Called from yasm_bc_destroy().

Parameters
contentsyasm_bytecode.contents

Definition at line 68 of file bytecode.h.

int(* yasm_bytecode_callback::elem_size)(yasm_bytecode *bc)

Return elements size of a data bytecode.

This function should return the size of each elements of a data bytecode, for proper dereference of symbols attached to it.

Parameters
bcbytecode
Returns
0 if element size is unknown.

Definition at line 91 of file bytecode.h.

int(* yasm_bytecode_callback::expand)(yasm_bytecode *bc, int span, long old_val, long new_val,long *neg_thres,long *pos_thres)

Recalculates the bytecode's length based on an expanded span length.

Called from yasm_bc_expand(). A generic fill-in for this is yasm_bc_expand_common(), but as this function internal errors when called, if used, ensure that calc_len() never adds a span. This function should simply add to bc->len to increase the length by a delta amount.

Parameters
bcbytecode
spanspan ID (as given to add_span in calc_len)
old_valprevious span value
new_valnew span value
neg_thresnegative threshold for long/short decision (returned)
pos_threspositive threshold for long/short decision (returned)
Returns
0 if bc no longer dependent on this span's length, negative if there was an error recognized (and output) during execution, and positive if bc size may increase for this span further based on the new negative and positive thresholds returned.
Note
May store to bytecode updated expressions.

Definition at line 132 of file bytecode.h.

void(* yasm_bytecode_callback::finalize)(yasm_bytecode *bc, yasm_bytecode *prev_bc)

Finalizes the bytecode after parsing.

Called from yasm_bc_finalize(). A generic fill-in for this is yasm_bc_finalize_common().

Parameters
bcbytecode
prev_bcbytecode directly preceding bc

Definition at line 83 of file bytecode.h.

void(* yasm_bytecode_callback::print)(const void *contents, FILE *f, int indent_level)

Prints the implementation-specific data (for debugging purposes).

Called from yasm_bc_print().

Parameters
contentsyasm_bytecode.contents
ffile
indent_levelindentation level

Definition at line 76 of file bytecode.h.

int(* yasm_bytecode_callback::tobytes)(yasm_bytecode *bc, unsigned char **bufp, unsigned char *bufstart, void *d, yasm_output_value_func output_value,yasm_output_reloc_func output_reloc)

Convert a bytecode into its byte representation.

Called from yasm_bc_tobytes(). A generic fill-in for this is yasm_bc_tobytes_common(), but as this function internal errors when called, be very careful when using it!

Parameters
bcbytecode
bufpbyte representation destination buffer; should be incremented as it's written to, so that on return its delta from the passed-in buf matches the bytecode length (it's okay not to do this if an error indication is returned)
bufstartFor calculating the correct offset parameter for the output_value calls: *bufp - bufstart.
ddata to pass to each call to output_value/output_reloc
output_valuefunction to call to convert values into their byte representation
output_relocfunction to call to output relocation entries for a single sym
Returns
Nonzero on error, 0 on success.
Note
May result in non-reversible changes to the bytecode, but it's preferable if calling this function twice would result in the same output.

Definition at line 159 of file bytecode.h.


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