diff options
| author | Yuichiro MASUI <[email protected]> | 2013-03-02 23:40:34 +0900 |
|---|---|---|
| committer | Yuichiro MASUI <[email protected]> | 2013-03-08 03:14:21 +0900 |
| commit | 284258367881d74f784485c2e5d282f4f5d490a5 (patch) | |
| tree | a160d3c745f14e600edaed724f67d3107b362049 /include | |
| parent | 7d47096434994d9eb9712546879e3b52b04d3443 (diff) | |
| download | mruby-284258367881d74f784485c2e5d282f4f5d490a5.tar.gz mruby-284258367881d74f784485c2e5d282f4f5d490a5.zip | |
New mrb format. The detail is in https://github.com/mruby/mruby/issues/944
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby/dump.h | 156 | ||||
| -rw-r--r-- | include/mruby/irep.h | 2 |
2 files changed, 78 insertions, 80 deletions
diff --git a/include/mruby/dump.h b/include/mruby/dump.h index 8b78e74d0..91ad76a46 100644 --- a/include/mruby/dump.h +++ b/include/mruby/dump.h @@ -18,116 +18,104 @@ extern "C" { #include <stdint.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*, int, FILE*); +int mrb_dump_irep_cfunc(mrb_state *mrb, int n, FILE *f, const char *initname); +int mrb_read_irep_file(mrb_state*, FILE*); #endif -int mrb_read_irep(mrb_state*,const char*); +int mrb_read_irep(mrb_state*, const unsigned char*); #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 { + unsigned char binary_identify[4]; // Rite Binary Identify + unsigned char binary_version[4]; // Rite Binary Format Version + unsigned char binary_crc[2]; // Rite Binary CRC + unsigned char binary_size[4]; // Rite Binary Size + unsigned char compiler_name[4]; // Rite Compiler name + unsigned char compiler_version[4]; +}; + +// Rite section header +#define RITE_SECTION_HEADER \ + unsigned char section_identify[4]; \ + unsigned char section_size[4]; + +struct rite_section_header { + RITE_SECTION_HEADER; +}; + +struct rite_section_irep_header { + RITE_SECTION_HEADER; + + unsigned char rite_version[4]; // Rite Instruction Specification Version + unsigned char nirep[2]; // Number of ireps + unsigned char sirep[2]; // Start index +}; + +struct rite_binary_footer { + RITE_SECTION_HEADER; +}; + +static inline int +uint8_to_bin(uint8_t s, unsigned char *bin) +{ + *bin = s; + return sizeof(uint8_t); +} static inline int -uint16_to_bin(uint16_t s, char *bin) +uint16_to_bin(uint16_t s, unsigned char *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, unsigned char *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 unsigned char *bin) { return (uint32_t)bin[0] << 24 | (uint32_t)bin[1] << 16 | @@ -136,12 +124,22 @@ bin_to_uint32(unsigned char bin[]) } static inline uint16_t -bin_to_uint16(unsigned char bin[]) +bin_to_uint16(const unsigned char *bin) { return (uint16_t)bin[0] << 8 | (uint16_t)bin[1]; } +static inline uint8_t +bin_to_uint8(const unsigned char *bin) +{ + return (uint8_t)bin[0]; +} + +/* crc.c */ +uint32_t +calc_crc_16_ccitt(const unsigned char *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 100afb494..d812723ba 100644 --- a/include/mruby/irep.h +++ b/include/mruby/irep.h @@ -31,7 +31,7 @@ typedef struct 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 unsigned char*); #if defined(__cplusplus) } /* extern "C" { */ |
