示例#1
0
文件: dump.c 项目: chancelab/mruby
static int
mrb_write_irep(mrb_state *mrb, int top, char *bin)
{
  int rc;
  uint32_t rlen=0; /* size of irep record */
  int irep_no;
  char *bin_top;

  if (mrb == NULL || top < 0 || top >= mrb->irep_len || bin == NULL)
    return MRB_DUMP_INVALID_ARGUMENT;

  bin_top = bin;
  bin += sizeof(rite_binary_header) + MRB_DUMP_SIZE_OF_SHORT/* crc */;

  for (irep_no=top; irep_no<mrb->irep_len; irep_no++) {
    rc = write_irep_record(mrb, irep_no, bin, &rlen, DUMP_TYPE_BIN);
    if (rc != MRB_DUMP_OK)
      return rc;

    bin += (rlen + DUMP_SIZE(MRB_DUMP_SIZE_OF_LONG, DUMP_TYPE_BIN));
  }

  bin += uint32_dump(0, bin, DUMP_TYPE_BIN); /* end of file */

  rc = write_rite_header(mrb, top, bin_top, (bin - bin_top));    //TODO: Remove top(SIREP)

  return rc;
}
示例#2
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;
}
示例#3
0
文件: dump.c 项目: chancelab/mruby
static int
dump_irep_record(mrb_state *mrb, int irep_no, FILE* fp, uint32_t *rlen)
{
  int rc = MRB_DUMP_OK;
  uint32_t irep_record_size;
  char *buf;
  mrb_irep *irep = mrb->irep[irep_no];

  if (irep == NULL)
    return MRB_DUMP_INVALID_IREP;

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

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

  rc = write_irep_record(mrb, irep_no, buf, rlen, DUMP_TYPE_HEX);
  if (rc != MRB_DUMP_OK) {
    rc = MRB_DUMP_GENERAL_FAILURE;
    goto error_exit;
  }


  if (fwrite(buf, irep_record_size, 1, fp) != 1)
    rc = MRB_DUMP_WRITE_FAULT;

error_exit:
  mrb_free(mrb, buf);

  return rc;
}
示例#4
0
文件: dump.c 项目: takeru/mruby
static int
write_section_irep(mrb_state *mrb, mrb_irep *irep, uint8_t *bin)
{
  int result;
  size_t section_size = 0; /* size of irep record */
  size_t rsize = 0;
  uint8_t *cur = bin;

  if (mrb == NULL || bin == NULL) {
    return MRB_DUMP_INVALID_ARGUMENT;
  }

  cur += sizeof(struct rite_section_irep_header);
  section_size += sizeof(struct rite_section_irep_header);

  result = write_irep_record(mrb, irep, cur, &rsize);
  if (result != MRB_DUMP_OK) {
    return result;
  }
  cur += rsize;
  section_size += rsize;
  write_section_irep_header(mrb, section_size, bin);

  return MRB_DUMP_OK;
}
示例#5
0
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;
}
示例#6
0
文件: dump.c 项目: Hozum/mruby
static int
mrb_write_section_irep(mrb_state *mrb, size_t start_index, uint8_t *bin)
{
  int result;
  size_t irep_no;
  uint32_t section_size = 0, rlen = 0; /* size of irep record */
  uint8_t *cur = bin;

  if (mrb == NULL || start_index >= mrb->irep_len || bin == NULL) {
    return MRB_DUMP_INVALID_ARGUMENT;
  }

  cur += sizeof(struct rite_section_irep_header);
  section_size += sizeof(struct rite_section_irep_header);

  for (irep_no = start_index; irep_no < mrb->irep_len; irep_no++) {
    result = write_irep_record(mrb, mrb->irep[irep_no], cur, &rlen);
    if (result != MRB_DUMP_OK) {
      return result;
    }
    cur += rlen;
    section_size += rlen;
  }

  mrb_write_section_irep_header(mrb, section_size, mrb->irep_len - start_index, start_index, bin);

  return MRB_DUMP_OK;
}
示例#7
0
static int
write_section_irep(mrb_state *mrb, mrb_irep *irep, uint8_t *bin, size_t *len_p, uint8_t flags)
{
  int result;
  size_t rsize = 0;
  uint8_t *cur = bin;

  if (mrb == NULL || bin == NULL) {
    return MRB_DUMP_INVALID_ARGUMENT;
  }

  cur += sizeof(struct rite_section_irep_header);

  result = write_irep_record(mrb, irep, cur, &rsize, flags);
  if (result != MRB_DUMP_OK) {
    return result;
  }
  *len_p = cur - bin + rsize;
  write_section_irep_header(mrb, *len_p, bin);

  return MRB_DUMP_OK;
}