Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mruby_mbed_web mirb_mbed
dump.h
00001 /* 00002 ** mruby/dump.h - mruby binary dumper (mrbc binary format) 00003 ** 00004 ** See Copyright Notice in mruby.h 00005 */ 00006 00007 #ifndef MRUBY_DUMP_H 00008 #define MRUBY_DUMP_H 00009 00010 #if defined(__cplusplus) 00011 extern "C" { 00012 #endif 00013 00014 #include "mruby.h" 00015 #include "mruby/irep.h" 00016 00017 int mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, int debug_info, uint8_t **bin, size_t *bin_size); 00018 #ifdef ENABLE_STDIO 00019 int mrb_dump_irep_binary(mrb_state*, mrb_irep*, int, FILE*); 00020 int mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep*, int, FILE *f, const char *initname); 00021 mrb_irep *mrb_read_irep_file(mrb_state*, FILE*); 00022 MRB_API mrb_value mrb_load_irep_file(mrb_state*,FILE*); 00023 MRB_API mrb_value mrb_load_irep_file_cxt(mrb_state*, FILE*, mrbc_context*); 00024 #endif 00025 MRB_API mrb_irep *mrb_read_irep(mrb_state*, const uint8_t*); 00026 00027 /* dump/load error code 00028 * 00029 * NOTE: MRB_DUMP_GENERAL_FAILURE is caused by 00030 * unspecified issues like malloc failed. 00031 */ 00032 #define MRB_DUMP_OK 0 00033 #define MRB_DUMP_GENERAL_FAILURE (-1) 00034 #define MRB_DUMP_WRITE_FAULT (-2) 00035 #define MRB_DUMP_READ_FAULT (-3) 00036 #define MRB_DUMP_CRC_ERROR (-4) 00037 #define MRB_DUMP_INVALID_FILE_HEADER (-5) 00038 #define MRB_DUMP_INVALID_IREP (-6) 00039 #define MRB_DUMP_INVALID_ARGUMENT (-7) 00040 00041 /* null symbol length */ 00042 #define MRB_DUMP_NULL_SYM_LEN 0xFFFF 00043 00044 /* Rite Binary File header */ 00045 #define RITE_BINARY_IDENTIFIER "RITE" 00046 #define RITE_BINARY_FORMAT_VER "0003" 00047 #define RITE_COMPILER_NAME "MATZ" 00048 #define RITE_COMPILER_VERSION "0000" 00049 00050 #define RITE_VM_VER "0000" 00051 00052 #define RITE_BINARY_EOF "END\0" 00053 #define RITE_SECTION_IREP_IDENTIFIER "IREP" 00054 #define RITE_SECTION_LINENO_IDENTIFIER "LINE" 00055 #define RITE_SECTION_DEBUG_IDENTIFIER "DBG\0" 00056 #define RITE_SECTION_LV_IDENTIFIER "LVAR" 00057 00058 #define MRB_DUMP_DEFAULT_STR_LEN 128 00059 #define MRB_DUMP_ALIGNMENT sizeof(uint32_t) 00060 00061 /* binary header */ 00062 struct rite_binary_header { 00063 uint8_t binary_identify[4]; /* Binary Identifier */ 00064 uint8_t binary_version[4]; /* Binary Format Version */ 00065 uint8_t binary_crc[2]; /* Binary CRC */ 00066 uint8_t binary_size[4]; /* Binary Size */ 00067 uint8_t compiler_name[4]; /* Compiler name */ 00068 uint8_t compiler_version[4]; 00069 }; 00070 00071 /* section header */ 00072 #define RITE_SECTION_HEADER \ 00073 uint8_t section_identify[4]; \ 00074 uint8_t section_size[4] 00075 00076 struct rite_section_header { 00077 RITE_SECTION_HEADER; 00078 }; 00079 00080 struct rite_section_irep_header { 00081 RITE_SECTION_HEADER; 00082 00083 uint8_t rite_version[4]; /* Rite Instruction Specification Version */ 00084 }; 00085 00086 struct rite_section_lineno_header { 00087 RITE_SECTION_HEADER; 00088 }; 00089 00090 struct rite_section_debug_header { 00091 RITE_SECTION_HEADER; 00092 }; 00093 00094 struct rite_section_lv_header { 00095 RITE_SECTION_HEADER; 00096 }; 00097 00098 #define RITE_LV_NULL_MARK UINT16_MAX 00099 00100 struct rite_binary_footer { 00101 RITE_SECTION_HEADER; 00102 }; 00103 00104 static inline size_t 00105 uint8_to_bin(uint8_t s, uint8_t *bin) 00106 { 00107 *bin = s; 00108 return sizeof(uint8_t); 00109 } 00110 00111 static inline size_t 00112 uint16_to_bin(uint16_t s, uint8_t *bin) 00113 { 00114 *bin++ = (s >> 8) & 0xff; 00115 *bin = s & 0xff; 00116 return sizeof(uint16_t); 00117 } 00118 00119 static inline size_t 00120 uint32_to_bin(uint32_t l, uint8_t *bin) 00121 { 00122 *bin++ = (l >> 24) & 0xff; 00123 *bin++ = (l >> 16) & 0xff; 00124 *bin++ = (l >> 8) & 0xff; 00125 *bin = l & 0xff; 00126 return sizeof(uint32_t); 00127 } 00128 00129 static inline uint32_t 00130 bin_to_uint32(const uint8_t *bin) 00131 { 00132 return (uint32_t)bin[0] << 24 | 00133 (uint32_t)bin[1] << 16 | 00134 (uint32_t)bin[2] << 8 | 00135 (uint32_t)bin[3]; 00136 } 00137 00138 static inline uint16_t 00139 bin_to_uint16(const uint8_t *bin) 00140 { 00141 return (uint16_t)bin[0] << 8 | 00142 (uint16_t)bin[1]; 00143 } 00144 00145 static inline uint8_t 00146 bin_to_uint8(const uint8_t *bin) 00147 { 00148 return (uint8_t)bin[0]; 00149 } 00150 00151 #if defined(__cplusplus) 00152 } /* extern "C" { */ 00153 #endif 00154 00155 /* crc.c */ 00156 uint16_t 00157 calc_crc_16_ccitt(const uint8_t *src, size_t nbytes, uint16_t crc); 00158 00159 #endif /* MRUBY_DUMP_H */ 00160
Generated on Tue Jul 12 2022 18:00:34 by
1.7.2