diff options
| author | Yukihiro Matz Matsumoto <[email protected]> | 2013-03-27 00:52:24 +0900 |
|---|---|---|
| committer | Yukihiro Matz Matsumoto <[email protected]> | 2013-03-27 00:52:24 +0900 |
| commit | a0f6e4d58edc296b0a3f8a3f7be5ab62ff61604d (patch) | |
| tree | 5c2c21a850129b3d596034d81bcdf063613305a4 /include | |
| parent | 1abe678e1c0a5fd153c07d71634f262fd51b7668 (diff) | |
| parent | 974febd315a6520184f95cb50a7c2b46e4582002 (diff) | |
| download | mruby-a0f6e4d58edc296b0a3f8a3f7be5ab62ff61604d.tar.gz mruby-a0f6e4d58edc296b0a3f8a3f7be5ab62ff61604d.zip | |
resolve conflict from #964
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby/dump.h | 156 | ||||
| -rw-r--r-- | include/mruby/irep.h | 4 |
2 files changed, 79 insertions, 81 deletions
diff --git a/include/mruby/dump.h b/include/mruby/dump.h index 196eefb3b..1af00371b 100644 --- a/include/mruby/dump.h +++ b/include/mruby/dump.h @@ -14,116 +14,104 @@ extern "C" { #include "mruby.h" #ifdef ENABLE_STDIO -int mrb_dump_irep(mrb_state*,int,FILE*); -int mrb_bdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname); - -int mrb_read_irep_file(mrb_state*,FILE*); +int mrb_dump_irep_binary(mrb_state*, size_t, FILE*); +int mrb_dump_irep_cfunc(mrb_state *mrb, size_t n, FILE *f, const char *initname); +int32_t mrb_read_irep_file(mrb_state*, FILE*); #endif -int mrb_read_irep(mrb_state*,const char*); +int mrb_read_irep(mrb_state*, const uint8_t*); #ifdef ENABLE_STDIO mrb_value mrb_load_irep_file(mrb_state*,FILE*); #endif -/* dump type */ -#define DUMP_TYPE_CODE 0 -#define DUMP_TYPE_BIN 1 -#define DUMP_TYPE_HEX 2 - /* dump/load error code * * NOTE: MRB_DUMP_GENERAL_FAILURE is caused by * unspecified issues like malloc failed. */ -#define MRB_DUMP_OK 0 -#define MRB_DUMP_GENERAL_FAILURE -1 -#define MRB_DUMP_WRITE_FAULT -2 -#define MRB_DUMP_READ_FAULT -3 -#define MRB_DUMP_CRC_ERROR -4 -#define MRB_DUMP_INVALID_FILE_HEADER -5 -#define MRB_DUMP_INVALID_IREP -6 -#define MRB_DUMP_INVALID_ARGUMENT -7 - -/* size of long/int/short value on dump/load */ -#define MRB_DUMP_SIZE_OF_LONG 4 -#define MRB_DUMP_SIZE_OF_INT 4 -#define MRB_DUMP_SIZE_OF_SHORT 2 -#define MRB_DUMP_SIZE_OF_CHAR 1 +#define MRB_DUMP_OK 0 +#define MRB_DUMP_GENERAL_FAILURE -1 +#define MRB_DUMP_WRITE_FAULT -2 +#define MRB_DUMP_READ_FAULT -3 +#define MRB_DUMP_CRC_ERROR -4 +#define MRB_DUMP_INVALID_FILE_HEADER -5 +#define MRB_DUMP_INVALID_IREP -6 +#define MRB_DUMP_INVALID_ARGUMENT -7 /* null symbol length */ -#define MRB_DUMP_NULL_SYM_LEN 0xFFFF +#define MRB_DUMP_NULL_SYM_LEN 0xFFFF -/* Use HEX format string */ -#define RITE_FILE_IS_HEX +/* Rite Binary File header */ +#define RITE_BINARY_IDENFIFIER "RITE" +#define RITE_BINARY_FORMAT_VER "0000" +#define RITE_COMPILER_NAME "MATZ" +#define RITE_COMPILER_VERSION "0000" -#ifdef RITE_FILE_IS_HEX -#define RITE_FILE_HEX_SIZE 2 -#else -#define RITE_FILE_HEX_SIZE 1 -#endif +#define RITE_VM_VER "0000" -/* Rite Binary File header */ -#define RITE_FILE_IDENFIFIER "RITE" -#define RITE_FILE_FORMAT_VER "00090000" -#define RITE_VM_VER "00090000" -#define RITE_COMPILER_TYPE "MATZ " -#define RITE_COMPILER_VER "00090000" -#define RITE_RESERVED " " - -/* irep header */ -#define RITE_IREP_IDENFIFIER 'S' -#define RITE_IREP_TYPE_CLASS 'C' -#define RITE_IREP_TYPE_MODULE 'M' - -#define MRB_DUMP_DEFAULT_STR_LEN 128 - -//Rite Binary file_header -typedef struct { - unsigned char rbfi[4]; //Rite Binary File Identify - unsigned char rbfv[8]; //Rite Binary File Format Version - unsigned char risv[8]; //Rite Instruction Specification Version - unsigned char rct[8]; //Rite Compiler Type - unsigned char rcv[8]; //Rite Compiler Version - unsigned char rbds[4]; //Rite Binary Data Size - unsigned char nirep[2]; //Number of ireps - unsigned char sirep[2]; //Start index - unsigned char rsv[8]; //Reserved -} rite_binary_header; - -// Rite File file_header -typedef struct { - unsigned char rbfi[4]; //Rite Binary File Identify - unsigned char rbfv[8]; //Rite Binary File Format Version - unsigned char risv[8]; //Rite Instruction Specification Version - unsigned char rct[8]; //Rite Compiler Type - unsigned char rcv[8]; //Rite Compiler Version - unsigned char rbds[8]; //Rite Binary Data Size - unsigned char nirep[4]; //Number of ireps - unsigned char sirep[4]; //Start index - unsigned char rsv[8]; //Reserved - unsigned char hcrc[4]; //HCRC -} rite_file_header; +#define RITE_BINARY_EOF "END\0" +#define RITE_SECTION_IREP_IDENTIFIER "IREP" + +#define MRB_DUMP_DEFAULT_STR_LEN 128 + +// Rite binary header +struct rite_binary_header { + uint8_t binary_identify[4]; // Rite Binary Identify + uint8_t binary_version[4]; // Rite Binary Format Version + uint8_t binary_crc[2]; // Rite Binary CRC + uint8_t binary_size[4]; // Rite Binary Size + uint8_t compiler_name[4]; // Rite Compiler name + uint8_t compiler_version[4]; +}; + +// Rite section header +#define RITE_SECTION_HEADER \ + uint8_t section_identify[4]; \ + uint8_t section_size[4]; + +struct rite_section_header { + RITE_SECTION_HEADER; +}; + +struct rite_section_irep_header { + RITE_SECTION_HEADER; + + uint8_t rite_version[4]; // Rite Instruction Specification Version + uint8_t nirep[2]; // Number of ireps + uint8_t sirep[2]; // Start index +}; + +struct rite_binary_footer { + RITE_SECTION_HEADER; +}; + +static inline int +uint8_to_bin(uint8_t s, uint8_t *bin) +{ + *bin = s; + return sizeof(uint8_t); +} static inline int -uint16_to_bin(uint16_t s, char *bin) +uint16_to_bin(uint16_t s, uint8_t *bin) { *bin++ = (s >> 8) & 0xff; *bin = s & 0xff; - return (MRB_DUMP_SIZE_OF_SHORT); + return sizeof(uint16_t); } static inline int -uint32_to_bin(uint32_t l, char *bin) +uint32_to_bin(uint32_t l, uint8_t *bin) { *bin++ = (l >> 24) & 0xff; *bin++ = (l >> 16) & 0xff; *bin++ = (l >> 8) & 0xff; *bin = l & 0xff; - return (MRB_DUMP_SIZE_OF_LONG); + return sizeof(uint32_t); } static inline uint32_t -bin_to_uint32(unsigned char bin[]) +bin_to_uint32(const uint8_t *bin) { return (uint32_t)bin[0] << 24 | (uint32_t)bin[1] << 16 | @@ -132,12 +120,22 @@ bin_to_uint32(unsigned char bin[]) } static inline uint16_t -bin_to_uint16(unsigned char bin[]) +bin_to_uint16(const uint8_t *bin) { return (uint16_t)bin[0] << 8 | (uint16_t)bin[1]; } +static inline uint8_t +bin_to_uint8(const uint8_t *bin) +{ + return (uint8_t)bin[0]; +} + +/* crc.c */ +uint32_t +calc_crc_16_ccitt(const uint8_t *src, uint32_t nbytes, uint16_t crcwk); + #if defined(__cplusplus) } /* extern "C" { */ #endif diff --git a/include/mruby/irep.h b/include/mruby/irep.h index fe732a43a..982ab4ac2 100644 --- a/include/mruby/irep.h +++ b/include/mruby/irep.h @@ -25,13 +25,13 @@ typedef struct mrb_irep { const char *filename; short *lines; - int ilen, plen, slen; + size_t ilen, plen, slen; } mrb_irep; #define MRB_ISEQ_NO_FREE 1 mrb_irep *mrb_add_irep(mrb_state *mrb); -mrb_value mrb_load_irep(mrb_state*,const char*); +mrb_value mrb_load_irep(mrb_state*, const uint8_t*); #if defined(__cplusplus) } /* extern "C" { */ |
