コード例 #1
0
ファイル: dump.c プロジェクト: ustbgaofan/mruby
static int
write_irep_record(mrb_state *mrb, mrb_irep *irep, uint8_t* bin, uint32_t *irep_record_size)
{
  size_t i;

  if (irep == NULL) {
    return MRB_DUMP_INVALID_IREP;
  }

  *irep_record_size = get_irep_record_size_1(mrb, irep);
  if (*irep_record_size == 0) {
    return MRB_DUMP_GENERAL_FAILURE;
  }

  memset(bin, 0, *irep_record_size);

  bin += write_irep_header(mrb, irep, bin);
  bin += write_iseq_block(mrb, irep, bin);
  bin += write_pool_block(mrb, irep, bin);
  bin += write_syms_block(mrb, irep, bin);

  for (i = 0; i < irep->rlen; i++) {
    int result;
    uint32_t rlen;

    result = write_irep_record(mrb, irep->reps[i], bin, &rlen);
    if (result != MRB_DUMP_OK) {
      return result;
    }
    *irep_record_size += rlen;
    bin += rlen;
  }
  return MRB_DUMP_OK;
}
コード例 #2
0
ファイル: dump.c プロジェクト: carsonmcdonald/mruby
static int
write_irep_record(mrb_state *mrb, mrb_irep *irep, uint8_t *bin, size_t *irep_record_size, uint8_t flags)
{
  uint32_t i;
  uint8_t *src = bin;

  if (irep == NULL) {
    return MRB_DUMP_INVALID_IREP;
  }

  *irep_record_size = get_irep_record_size_1(mrb, irep);
  if (*irep_record_size == 0) {
    return MRB_DUMP_GENERAL_FAILURE;
  }

  bin += write_irep_header(mrb, irep, bin);
  bin += write_iseq_block(mrb, irep, bin, flags);
  bin += write_pool_block(mrb, irep, bin);
  bin += write_syms_block(mrb, irep, bin);

  for (i = 0; i < irep->rlen; i++) {
    int result;
    size_t rsize;

    result = write_irep_record(mrb, irep->reps[i], bin, &rsize, flags);
    if (result != MRB_DUMP_OK) {
      return result;
    }
    bin += rsize;
  }
  *irep_record_size = bin - src;
  return MRB_DUMP_OK;
}
コード例 #3
0
ファイル: dump.c プロジェクト: Zyxwvu/mruby
static int
calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section)
{
  char *buf, *buf_top;
  uint32_t buf_size;
  int type = DUMP_TYPE_BIN;

  switch (section) {
  case DUMP_IREP_HEADER: buf_size = get_irep_header_size(mrb, irep, type); break;
  case DUMP_ISEQ_BLOCK:  buf_size = get_iseq_block_size(mrb, irep, type); break;
  case DUMP_POOL_BLOCK:  buf_size = get_pool_block_size(mrb, irep, type); break;
  case DUMP_SYMS_BLOCK:  buf_size = get_syms_block_size(mrb, irep, type); break;
  default: return MRB_DUMP_GENERAL_FAILURE;
  }

  if ((buf = mrb_malloc(mrb, buf_size)) == 0)
    return MRB_DUMP_GENERAL_FAILURE;

  buf_top = buf;
  memset(buf, 0, buf_size);

  switch (section) {
  case DUMP_IREP_HEADER: buf += write_irep_header(mrb, irep, buf, type); break;
  case DUMP_ISEQ_BLOCK: buf += write_iseq_block(mrb, irep, buf, type); break;
  case DUMP_POOL_BLOCK: buf += write_pool_block(mrb, irep, buf, type); break;
  case DUMP_SYMS_BLOCK: buf += write_syms_block(mrb, irep, buf, type); break;
  default: break;
  }

  *crc = calc_crc_16_ccitt((unsigned char*)buf_top, (int)(buf - buf_top));

  mrb_free(mrb, buf_top);

  return MRB_DUMP_OK;
}
コード例 #4
0
ファイル: dump.c プロジェクト: chancelab/mruby
static int
calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section)
{
  char *buf, *buf_top;
  uint32_t buf_size;
  int type = DUMP_TYPE_BIN;
  int result;

  switch (section) {
  case DUMP_IREP_HEADER: buf_size = get_irep_header_size(mrb, type); break;
  case DUMP_ISEQ_BLOCK:  buf_size = get_iseq_block_size(mrb, irep, type); break;
  case DUMP_POOL_BLOCK:  buf_size = get_pool_block_size(mrb, irep, type); break;
  case DUMP_SYMS_BLOCK:  buf_size = get_syms_block_size(mrb, irep, type); break;
  default: return MRB_DUMP_GENERAL_FAILURE;
  }

  buf = (char *)mrb_calloc(mrb, 1, buf_size);
  if (buf == NULL)
    return MRB_DUMP_GENERAL_FAILURE;

  buf_top = buf;

  switch (section) {
  case DUMP_IREP_HEADER:
    result = write_irep_header(mrb, irep, buf, type);
    break;
  case DUMP_ISEQ_BLOCK:
    result = write_iseq_block(mrb, irep, buf, type);
    break;
  case DUMP_POOL_BLOCK:
    result = write_pool_block(mrb, irep, buf, type);
    break;
  case DUMP_SYMS_BLOCK:
    result = write_syms_block(mrb, irep, buf, type);
    break;
  default:
    result = MRB_DUMP_GENERAL_FAILURE;
    break; /* Already checked above. */
  }
  if (result < 0) {
    goto error_exit;
  }
  buf += result;

  *crc = calc_crc_16_ccitt((unsigned char*)buf_top, (int)(buf - buf_top));

  mrb_free(mrb, buf_top);

  result = MRB_DUMP_OK;
 error_exit:
  return result;
}
コード例 #5
0
ファイル: dump.c プロジェクト: chancelab/mruby
static int
write_irep_record(mrb_state *mrb, int irep_no, char* bin, uint32_t *rlen, int type)
{
  uint32_t irep_record_size;
  mrb_irep *irep = mrb->irep[irep_no];
  int section;

  if (irep == NULL)
    return MRB_DUMP_INVALID_IREP;

  /* buf alloc */
  irep_record_size = get_irep_record_size(mrb, irep_no, type);
  if (irep_record_size == 0)
    return MRB_DUMP_GENERAL_FAILURE;

  memset( bin, 0, irep_record_size);

  /* rlen */
  *rlen = irep_record_size - DUMP_SIZE(MRB_DUMP_SIZE_OF_LONG, type);

  bin += uint32_dump(*rlen, bin, type);

  for (section = 0; section < DUMP_SECTION_NUM; section++) {
    int rc;
    uint16_t crc;

    switch (section) {
    case DUMP_IREP_HEADER: bin += write_irep_header(mrb, irep, bin, type); break;
    case DUMP_ISEQ_BLOCK: bin += write_iseq_block(mrb, irep, bin, type); break;
    case DUMP_POOL_BLOCK: bin += write_pool_block(mrb, irep, bin, type); break;
    case DUMP_SYMS_BLOCK: bin += write_syms_block(mrb, irep, bin, type); break;
    default: break;
    }

    rc = calc_crc_section(mrb, irep, &crc, section);
    if (rc != MRB_DUMP_OK)
      return rc;

    bin += uint16_dump(crc, bin, type); /* crc */
  }

  return MRB_DUMP_OK;
}
コード例 #6
0
ファイル: dump.c プロジェクト: Hozum/mruby
static int
write_irep_record(mrb_state *mrb, mrb_irep *irep, uint8_t* bin, uint32_t *irep_record_size)
{
  if (irep == NULL) {
    return MRB_DUMP_INVALID_IREP;
  }

  *irep_record_size = get_irep_record_size(mrb, irep);
  if (*irep_record_size == 0) {
    return MRB_DUMP_GENERAL_FAILURE;
  }

  memset(bin, 0, *irep_record_size);

  //bin += uint16_to_bin(*irep_record_size, bin);
  bin += write_irep_header(mrb, irep, bin);
  bin += write_iseq_block(mrb, irep, bin);
  bin += write_pool_block(mrb, irep, bin);
  bin += write_syms_block(mrb, irep, bin);

  return MRB_DUMP_OK;
}