diff options
author | terminaldweller <thabogre@gmail.com> | 2022-02-14 19:22:31 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2022-02-14 19:22:31 +0000 |
commit | bddd10b1dab1cb88905489f93a77b5a8c465650b (patch) | |
tree | d33e31e4da2b4da846969c4ab21fe45712cdf853 /dwasm-cpp/wasm.h | |
parent | listened to lgtm... (diff) | |
download | dwasm-master.tar.gz dwasm-master.zip |
Diffstat (limited to '')
-rw-r--r-- | dwasm-cpp/wasm.h | 337 |
1 files changed, 173 insertions, 164 deletions
diff --git a/dwasm-cpp/wasm.h b/dwasm-cpp/wasm.h index a7b916f..6687c03 100644 --- a/dwasm-cpp/wasm.h +++ b/dwasm-cpp/wasm.h @@ -16,7 +16,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +USA.*/ /**********************************************************************************************************************/ #ifndef WASM_H #define WASM_H @@ -34,147 +35,156 @@ typedef int8_t varuint1; typedef int8_t varuint7; typedef int32_t varuint32; - enum value_type_t {f64_vt = -4, f32_vt, i64_vt, i32_vt}; - enum external_kind_t {Function, Table, Memory, Global}; - enum type_ctor_t {i32_ctor = -1, i64_ctor = -2, f32_ctor = -3, f64_ctor = -4, anyfunc_ctor = -16, func_ctor = -32, block_type_ctor = -64}; - - typedef struct { - varuint32 size; - char* code; - }init_expr_t; - - typedef struct { - varuint1 flags; - varuint32 initial; - varuint32 maximum; - } resizable_limit_t; - - typedef struct { - enum value_type_t value_type; - varuint1 mutability; - }global_type_t; - - typedef struct { - varint7 element_type; - resizable_limit_t* resizable_limit; - }table_type_t; - - typedef struct { - resizable_limit_t* resizable_limit; - }memory_type_t; - - // func_type - typedef struct { - varint7 form; - varuint32 param_count; - varint7* param_types; - varuint1 return_count; - varint7 * return_types; - }W_Type_Section_Entry; - - typedef struct { - varuint32 count; - W_Type_Section_Entry** entries; - }W_Type_Section; - - typedef struct { - varuint32 module_length; - char* module_str; - varuint32 field_len; - char* field_str; - enum external_kind_t kind; - // based on external_kind it can be 4 different types. thats why im casting to void*. - void* type; - }W_Import_Section_Entry; - - typedef struct { - varuint32 count; - W_Import_Section_Entry** entries; - }W_Import_Section; - - typedef struct { - varuint32 count; - // indexes into the type section - varuint32* types; - }W_Function_Section; - - typedef struct W_Table_Section { - varuint32 count; - table_type_t** entries; - }W_Table_Section; - - typedef struct { - varuint32 count; - memory_type_t** entries; - }W_Memory_Section; - - typedef struct { - global_type_t* type; - init_expr_t* init; - }W_Global_Entry; - - typedef struct { - varuint32 count; - W_Global_Entry** globals; - }W_Global_Section; - - typedef struct { - varuint32 field_len; - char* field_str; - enum external_kind_t kind; - varuint32 index; - }W_Export_Entry; - - typedef struct { - int count; - W_Export_Entry** entries; - }W_Export_Section; - - typedef struct { - varuint32 index; - }W_Start_Section; - - typedef struct { - varuint32 index; - init_expr_t* offset; - varuint32 num_length; - varuint32* elems; - }W_Elem_Segment; - - typedef struct { - varuint32 count; - W_Elem_Segment** entries; - }W_Element_Section; - - typedef struct { - varuint32 count; - enum value_type_t type; - }W_Local_Entry; - - typedef struct W_Function_Body { - varuint32 body_size; - varuint32 local_count; - W_Local_Entry** locals; - char* code; - //char end = 0x0b; - }W_Function_Body; - - typedef struct { - varuint32 count; - W_Function_Body** bodies; - }W_Code_Section; - - typedef struct { - varuint32 index; - init_expr_t* offset; - varuint32 size; - char* data; - }W_Data_Segment; - - typedef struct { - varuint32 count; - W_Data_Segment** entries; - }W_Data_Section; +enum value_type_t { f64_vt = -4, f32_vt, i64_vt, i32_vt }; +enum external_kind_t { Function, Table, Memory, Global }; +enum type_ctor_t { + i32_ctor = -1, + i64_ctor = -2, + f32_ctor = -3, + f64_ctor = -4, + anyfunc_ctor = -16, + func_ctor = -32, + block_type_ctor = -64 +}; + +typedef struct { + varuint32 size; + char *code; +} init_expr_t; + +typedef struct { + varuint1 flags; + varuint32 initial; + varuint32 maximum; +} resizable_limit_t; + +typedef struct { + enum value_type_t value_type; + varuint1 mutability; +} global_type_t; + +typedef struct { + varint7 element_type; + resizable_limit_t *resizable_limit; +} table_type_t; + +typedef struct { + resizable_limit_t *resizable_limit; +} memory_type_t; + +// func_type +typedef struct { + varint7 form; + varuint32 param_count; + varint7 *param_types; + varuint1 return_count; + varint7 *return_types; +} W_Type_Section_Entry; + +typedef struct { + varuint32 count; + W_Type_Section_Entry **entries; +} W_Type_Section; + +typedef struct { + varuint32 module_length; + char *module_str; + varuint32 field_len; + char *field_str; + enum external_kind_t kind; + // based on external_kind it can be 4 different types. thats why im casting to + // void*. + void *type; +} W_Import_Section_Entry; + +typedef struct { + varuint32 count; + W_Import_Section_Entry **entries; +} W_Import_Section; + +typedef struct { + varuint32 count; + // indexes into the type section + varuint32 *types; +} W_Function_Section; + +typedef struct W_Table_Section { + varuint32 count; + table_type_t **entries; +} W_Table_Section; + +typedef struct { + varuint32 count; + memory_type_t **entries; +} W_Memory_Section; + +typedef struct { + global_type_t *type; + init_expr_t *init; +} W_Global_Entry; + +typedef struct { + varuint32 count; + W_Global_Entry **globals; +} W_Global_Section; + +typedef struct { + varuint32 field_len; + char *field_str; + enum external_kind_t kind; + varuint32 index; +} W_Export_Entry; + +typedef struct { + int count; + W_Export_Entry **entries; +} W_Export_Section; + +typedef struct { + varuint32 index; +} W_Start_Section; + +typedef struct { + varuint32 index; + init_expr_t *offset; + varuint32 num_length; + varuint32 *elems; +} W_Elem_Segment; + +typedef struct { + varuint32 count; + W_Elem_Segment **entries; +} W_Element_Section; + +typedef struct { + varuint32 count; + enum value_type_t type; +} W_Local_Entry; + +typedef struct W_Function_Body { + varuint32 body_size; + varuint32 local_count; + W_Local_Entry **locals; + char *code; + // char end = 0x0b; +} W_Function_Body; + +typedef struct { + varuint32 count; + W_Function_Body **bodies; +} W_Code_Section; + +typedef struct { + varuint32 index; + init_expr_t *offset; + varuint32 size; + char *data; +} W_Data_Segment; + +typedef struct { + varuint32 count; + W_Data_Segment **entries; +} W_Data_Section; #if 0 typedef struct W_Custom_Section {}; @@ -182,27 +192,27 @@ typedef int32_t varuint32; typedef struct W_Relocation_Section {}; #endif - typedef struct Wasm_Module { - W_Type_Section* type_section; - W_Import_Section* import_section; - W_Function_Section* function_section; - W_Table_Section* table_section; - W_Memory_Section* memory_section; - W_Global_Section* global_section; - W_Export_Section* export_section; - W_Start_Section* start_section; - W_Element_Section* element_section; - W_Code_Section* code_section; - W_Data_Section* data_section; - void** W_Custom_Sections; - char* name; - }Wasm_Module; - - // get the raw binary of the wasm module - // char* getWRaw(); - - // get wasm section raw binary by name - // char* get_W_Section_Raw(const char* section_name); +typedef struct Wasm_Module { + W_Type_Section *type_section; + W_Import_Section *import_section; + W_Function_Section *function_section; + W_Table_Section *table_section; + W_Memory_Section *memory_section; + W_Global_Section *global_section; + W_Export_Section *export_section; + W_Start_Section *start_section; + W_Element_Section *element_section; + W_Code_Section *code_section; + W_Data_Section *data_section; + void **W_Custom_Sections; + char *name; +} Wasm_Module; + +// get the raw binary of the wasm module +// char* getWRaw(); + +// get wasm section raw binary by name +// char* get_W_Section_Raw(const char* section_name); #ifdef __cplusplus } @@ -210,4 +220,3 @@ typedef int32_t varuint32; #endif // end of header guard /**********************************************************************************************************************/ /*last line intentionally left blank.*/ - |