コード例 #1
0
ファイル: floatnum.c プロジェクト: Acidburn0zzz/yasm
/*@-compdef@*/
void
yasm_floatnum_initialize(void)
/*@globals undef POT_TableN, undef POT_TableP, POT_TableP_Source,
   POT_TableN_Source @*/
{
    int dec_exp = 1;
    int i;

    /* Allocate space for two POT tables */
    POT_TableN = yasm_xmalloc(14*sizeof(POT_Entry));
    POT_TableP = yasm_xmalloc(15*sizeof(POT_Entry)); /* note 1 extra for -1 */

    /* Initialize entry[0..12] */
    for (i=12; i>=0; i--) {
        POT_Table_Init_Entry(&POT_TableN[i], &POT_TableN_Source[i], 0-dec_exp);
        POT_Table_Init_Entry(&POT_TableP[i+1], &POT_TableP_Source[i], dec_exp);
        dec_exp *= 2;       /* Update decimal exponent */
    }

    /* Initialize entry[13] */
    POT_Table_Init_Entry(&POT_TableN[13], &POT_TableN_Source[13], 0);
    POT_Table_Init_Entry(&POT_TableP[14], &POT_TableP_Source[13], 0);

    /* Initialize entry[-1] for POT_TableP */
    POT_Table_Init_Entry(&POT_TableP[0], &POT_TableP_Source[0], 4096);

    /* Offset POT_TableP so that [0] becomes [-1] */
    POT_TableP++;
}
コード例 #2
0
ファイル: cpp-preproc.c プロジェクト: venkatarajasekhar/Qt
/*******************************************************************************
    Interface functions.
*******************************************************************************/
static yasm_preproc *
cpp_preproc_create(const char *in, yasm_symtab *symtab, yasm_linemap *lm,
                   yasm_errwarns *errwarns)
{
    yasm_preproc_cpp *pp = yasm_xmalloc(sizeof(yasm_preproc_cpp));
    void * iter;
    const char * inc_dir;

    pp->preproc.module = &yasm_cpp_LTX_preproc;
    pp->f = pp->f_deps = NULL;
    pp->cur_lm = lm;
    pp->errwarns = errwarns;
    pp->flags = 0;
    pp->filename = yasm__xstrdup(in);

    TAILQ_INIT(&pp->cpp_args);

    /* Iterate through the list of include dirs. */
    iter = NULL;
    while ((inc_dir = yasm_get_include_dir(&iter)) != NULL) {
        cpp_arg_entry *arg = yasm_xmalloc(sizeof(cpp_arg_entry));
        arg->op = "-I";
        arg->param = yasm__xstrdup(inc_dir);

        TAILQ_INSERT_TAIL(&pp->cpp_args, arg, entry);
    }

    return (yasm_preproc *)pp;
}
コード例 #3
0
ファイル: inttree.c プロジェクト: Acidburn0zzz/yasm
IntervalTree *
IT_create(void)
{
    IntervalTree *it = yasm_xmalloc(sizeof(IntervalTree));

    it->nil = ITN_create(LONG_MIN, LONG_MIN, NULL);
    it->nil->left = it->nil;
    it->nil->right = it->nil;
    it->nil->parent = it->nil;
    it->nil->red = 0;
  
    it->root = ITN_create(LONG_MAX, LONG_MAX, NULL);
    it->root->left = it->nil;
    it->root->right = it->nil;
    it->root->parent = it->nil;
    it->root->red = 0;

    /* the following are used for the Enumerate function */
    it->recursionNodeStackSize = 128;
    it->recursionNodeStack = (it_recursion_node *) 
        yasm_xmalloc(it->recursionNodeStackSize*sizeof(it_recursion_node));
    it->recursionNodeStackTop = 1;
    it->recursionNodeStack[0].start_node = NULL;

    return it;
}
コード例 #4
0
ファイル: linemap.c プロジェクト: Acidburn0zzz/yasm
yasm_linemap *
yasm_linemap_create(void)
{
    size_t i;
    yasm_linemap *linemap = yasm_xmalloc(sizeof(yasm_linemap));

    linemap->filenames = HAMT_create(0, yasm_internal_error_);

    linemap->current = 1;

    /* initialize mapping vector */
    linemap->map_vector = yasm_xmalloc(8*sizeof(line_mapping));
    linemap->map_size = 0;
    linemap->map_allocated = 8;
    
    /* initialize source line information array */
    linemap->source_info_size = 2;
    linemap->source_info = yasm_xmalloc(linemap->source_info_size *
                                        sizeof(line_source_info));
    for (i=0; i<linemap->source_info_size; i++) {
        linemap->source_info[i].bc = NULL;
        linemap->source_info[i].source = NULL;
    }

    return linemap;
}
コード例 #5
0
ファイル: x86arch.c プロジェクト: Acidburn0zzz/yasm
static /*@only@*/ yasm_arch *
x86_create(const char *machine, const char *parser,
           /*@out@*/ yasm_arch_create_error *error)
{
    yasm_arch_x86 *arch_x86;
    unsigned int amd64_machine, address_size;

    *error = YASM_ARCH_CREATE_OK;

    if (yasm__strcasecmp(machine, "x86") == 0) {
        amd64_machine = 0;
	address_size = 32;
    } else if (yasm__strcasecmp(machine, "amd64") == 0) {
        amd64_machine = 1;
	address_size = 64;
    } else if (yasm__strcasecmp(machine, "x32") == 0) {
        amd64_machine = 1;
	address_size = 32;
    }
    else {
        *error = YASM_ARCH_CREATE_BAD_MACHINE;
        return NULL;
    }

    arch_x86 = yasm_xmalloc(sizeof(yasm_arch_x86));

    arch_x86->arch.module = &yasm_x86_LTX_arch;

    /* default to all instructions/features enabled */
    arch_x86->active_cpu = 0;
    arch_x86->cpu_enables_size = 1;
    arch_x86->cpu_enables = yasm_xmalloc(sizeof(wordptr));
    arch_x86->cpu_enables[0] = BitVector_Create(64, FALSE);
    BitVector_Fill(arch_x86->cpu_enables[0]);

    arch_x86->amd64_machine = amd64_machine;
    arch_x86->mode_bits = 0;
    arch_x86->address_size = address_size;
    arch_x86->force_strict = 0;
    arch_x86->default_rel = 0;
    arch_x86->gas_intel_mode = 0;
    arch_x86->nop = X86_NOP_BASIC;

    if (yasm__strcasecmp(parser, "nasm") == 0)
        arch_x86->parser = X86_PARSER_NASM;
    else if (yasm__strcasecmp(parser, "tasm") == 0)
        arch_x86->parser = X86_PARSER_TASM;
    else if (yasm__strcasecmp(parser, "gas") == 0
             || yasm__strcasecmp(parser, "gnu") == 0)
        arch_x86->parser = X86_PARSER_GAS;
    else {
        yasm_xfree(arch_x86);
        *error = YASM_ARCH_CREATE_BAD_PARSER;
        return NULL;
    }

    return (yasm_arch *)arch_x86;
}
コード例 #6
0
ファイル: elf.c プロジェクト: Mirocow/balancer
elf_strtab_head *
elf_strtab_create()
{
    elf_strtab_head *strtab = yasm_xmalloc(sizeof(elf_strtab_head));
    elf_strtab_entry *entry = yasm_xmalloc(sizeof(elf_strtab_entry));

    STAILQ_INIT(strtab);
    entry->index = 0;
    entry->str = yasm__xstrdup("");

    STAILQ_INSERT_TAIL(strtab, entry, qlink);
    return strtab;
}
コード例 #7
0
ファイル: intnum.c プロジェクト: kstephens/yasm
yasm_intnum *
yasm_intnum_create_leb128(const unsigned char *ptr, int sign,
                          unsigned long *size)
{
    yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
    const unsigned char *ptr_orig = ptr;
    unsigned long i = 0;

    BitVector_Empty(conv_bv);
    for (;;) {
        BitVector_Chunk_Store(conv_bv, 7, i, *ptr);
        i += 7;
        if ((*ptr & 0x80) != 0x80)
            break;
        ptr++;
    }

    *size = (unsigned long)(ptr-ptr_orig)+1;

    if(i > BITVECT_NATIVE_SIZE)
        yasm_error_set(YASM_ERROR_OVERFLOW,
                       N_("Numeric constant too large for internal format"));
    else if (sign && (*ptr & 0x40) == 0x40)
        BitVector_Interval_Fill(conv_bv, i, BITVECT_NATIVE_SIZE-1);

    intnum_frombv(intn, conv_bv);
    return intn;
}
コード例 #8
0
ファイル: elf.c プロジェクト: Mirocow/balancer
const elf_machine_handler *
elf_set_arch(yasm_arch *arch, yasm_symtab *symtab, int bits_pref)
{
    const char *machine = yasm_arch_get_machine(arch);
    int i;

    for (i=0, elf_march = elf_machine_handlers[0];
         elf_march != NULL;
         elf_march = elf_machine_handlers[++i])
    {
        if (yasm__strcasecmp(yasm_arch_keyword(arch), elf_march->arch)==0)
            if (yasm__strcasecmp(machine, elf_march->machine)==0)
                if (bits_pref == 0 || bits_pref == elf_march->bits)
                    break;
    }

    if (elf_march && elf_march->num_ssyms > 0)
    {
        /* Allocate "special" syms */
        elf_ssyms =
            yasm_xmalloc(elf_march->num_ssyms * sizeof(yasm_symrec *));
        for (i=0; (unsigned int)i<elf_march->num_ssyms; i++)
        {
            /* FIXME: misuse of NULL bytecode */
            elf_ssyms[i] = yasm_symtab_define_label(symtab,
                                                    elf_march->ssyms[i].name,
                                                    NULL, 0, 0);
        }
    }

    return elf_march;
}
コード例 #9
0
ファイル: expr.c プロジェクト: Acidburn0zzz/yasm
/*@-compmempass@*/
yasm_expr *
yasm_expr_create(yasm_expr_op op, yasm_expr__item *left,
                 yasm_expr__item *right, unsigned long line)
{
    yasm_expr *ptr, *sube;
    unsigned long z;
    ptr = yasm_xmalloc(sizeof(yasm_expr));

    ptr->op = op;
    ptr->numterms = 0;
    ptr->terms[0].type = YASM_EXPR_NONE;
    ptr->terms[1].type = YASM_EXPR_NONE;
    if (left) {
        ptr->terms[0] = *left;  /* structure copy */
        z = (unsigned long)(left-itempool);
        if (z>=31)
            yasm_internal_error(N_("could not find expritem in pool"));
        itempool_used &= ~(1<<z);
        ptr->numterms++;

        /* Search downward until we find something *other* than an
         * IDENT, then bring it up to the current level.
         */
        while (ptr->terms[0].type == YASM_EXPR_EXPR &&
               ptr->terms[0].data.expn->op == YASM_EXPR_IDENT) {
            sube = ptr->terms[0].data.expn;
            ptr->terms[0] = sube->terms[0];     /* structure copy */
            /*@-usereleased@*/
            yasm_xfree(sube);
            /*@=usereleased@*/
        }
    } else {
        yasm_internal_error(N_("Right side of expression must exist"));
    }

    if (right) {
        ptr->terms[1] = *right; /* structure copy */
        z = (unsigned long)(right-itempool);
        if (z>=31)
            yasm_internal_error(N_("could not find expritem in pool"));
        itempool_used &= ~(1<<z);
        ptr->numterms++;

        /* Search downward until we find something *other* than an
         * IDENT, then bring it up to the current level.
         */
        while (ptr->terms[1].type == YASM_EXPR_EXPR &&
               ptr->terms[1].data.expn->op == YASM_EXPR_IDENT) {
            sube = ptr->terms[1].data.expn;
            ptr->terms[1] = sube->terms[0];     /* structure copy */
            /*@-usereleased@*/
            yasm_xfree(sube);
            /*@=usereleased@*/
        }
    }

    ptr->line = line;

    return expr_level_op(ptr, 1, 1, 0);
}
コード例 #10
0
ファイル: cpp-preproc.c プロジェクト: venkatarajasekhar/Qt
/*
    Put all the options together into a command line that can be used to invoke
    cpp.
*/
static char *
cpp_build_cmdline(yasm_preproc_cpp *pp, const char *extra)
{
    char *cmdline, *p, *limit;
    cpp_arg_entry *arg;

    /* Initialize command line. */
    cmdline = p = yasm_xmalloc(strlen(CPP_PROG)+CMDLINE_SIZE);
    limit = p + CMDLINE_SIZE;
    strcpy(p, CPP_PROG);
    p += strlen(CPP_PROG);

    arg = TAILQ_FIRST(&pp->cpp_args);

    /* Append arguments from the list. */
    while ( arg ) {
        APPEND(" ");
        APPEND(arg->op);
        APPEND(" ");
        APPEND(arg->param);

        arg = TAILQ_NEXT(arg, entry);
    }

    /* Append extra arguments. */
    if (extra) {
        APPEND(" ");
        APPEND(extra);
    }
    /* Append final arguments. */
    APPEND(" -x assembler-with-cpp ");
    APPEND(pp->filename);

    return cmdline;
}
コード例 #11
0
ファイル: valparam.c プロジェクト: Jonnyliu/hf-2011
yasm_valparamhead *
yasm_vps_create(void)
{
    yasm_valparamhead *headp = yasm_xmalloc(sizeof(yasm_valparamhead));
    yasm_vps_initialize(headp);
    return headp;
}
コード例 #12
0
ファイル: intnum.c プロジェクト: kstephens/yasm
yasm_intnum *
yasm_intnum_create_sized(unsigned char *ptr, int sign, size_t srcsize,
                         int bigendian)
{
    yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
    unsigned long i = 0;

    if (srcsize*8 > BITVECT_NATIVE_SIZE)
        yasm_error_set(YASM_ERROR_OVERFLOW,
                       N_("Numeric constant too large for internal format"));

    /* Read the buffer into a bitvect */
    BitVector_Empty(conv_bv);
    if (bigendian) {
        /* TODO */
        yasm_internal_error(N_("big endian not implemented"));
    } else {
        for (i = 0; i < srcsize; i++)
            BitVector_Chunk_Store(conv_bv, 8, i*8, ptr[i]);
    }

    /* Sign extend if needed */
    if (srcsize*8 < BITVECT_NATIVE_SIZE && sign && (ptr[i-1] & 0x80) == 0x80)
        BitVector_Interval_Fill(conv_bv, i*8, BITVECT_NATIVE_SIZE-1);

    intnum_frombv(intn, conv_bv);
    return intn;
}
コード例 #13
0
ファイル: elf.c プロジェクト: Mirocow/balancer
/* takes ownership of addr */
elf_reloc_entry *
elf_reloc_entry_create(yasm_symrec *sym,
                       yasm_symrec *wrt,
                       yasm_intnum *addr,
                       int rel,
                       size_t valsize)
{
    elf_reloc_entry *entry;

    if (!elf_march->accepts_reloc)
        yasm_internal_error(N_("Unsupported machine for ELF output"));

    if (!elf_march->accepts_reloc(valsize, wrt, elf_ssyms))
    {
        if (addr)
            yasm_intnum_destroy(addr);
        return NULL;
    }

    if (sym == NULL)
        yasm_internal_error("sym is null");

    entry = yasm_xmalloc(sizeof(elf_reloc_entry));
    entry->reloc.sym = sym;
    entry->reloc.addr = addr;
    entry->rtype_rel = rel;
    entry->valsize = valsize;
    entry->addend = NULL;
    entry->wrt = wrt;

    return entry;
}
コード例 #14
0
ファイル: elf.c プロジェクト: Mirocow/balancer
/* strtab functions */
elf_strtab_entry *
elf_strtab_entry_create(const char *str)
{
    elf_strtab_entry *entry = yasm_xmalloc(sizeof(elf_strtab_entry));
    entry->str = yasm__xstrdup(str);
    entry->index = 0;
    return entry;
}
コード例 #15
0
static cv_leaf *
cv_leaf_create_label(int is_far)
{
    cv_leaf *leaf = yasm_xmalloc(sizeof(cv_leaf));
    leaf->type = CV5_LF_LABEL;
    leaf->format = "h";
    leaf->args[0].i = is_far ? 4 : 0;
    return leaf;
}
コード例 #16
0
ファイル: bc-org.c プロジェクト: venkatarajasekhar/Qt
yasm_bytecode *
yasm_bc_create_org(unsigned long start, unsigned long fill, unsigned long line)
{
    bytecode_org *org = yasm_xmalloc(sizeof(bytecode_org));

    org->start = start;
    org->fill = fill;

    return yasm_bc_create_common(&bc_org_callback, org, line);
}
コード例 #17
0
ファイル: valparam.c プロジェクト: Jonnyliu/hf-2011
yasm_valparam *
yasm_vp_create_expr(/*@keep@*/ char *v, /*@keep@*/ yasm_expr *p)
{
    yasm_valparam *r = yasm_xmalloc(sizeof(yasm_valparam));
    r->val = v;
    r->type = YASM_PARAM_EXPR;
    r->param.e = p;
    r->id_prefix = '\0';
    return r;
}
コード例 #18
0
ファイル: valparam.c プロジェクト: Jonnyliu/hf-2011
yasm_valparam *
yasm_vp_create_string(/*@keep@*/ char *v, /*@keep@*/ char *p)
{
    yasm_valparam *r = yasm_xmalloc(sizeof(yasm_valparam));
    r->val = v;
    r->type = YASM_PARAM_STRING;
    r->param.str = p;
    r->id_prefix = '\0';
    return r;
}
コード例 #19
0
ファイル: intnum.c プロジェクト: kstephens/yasm
yasm_intnum *
yasm_intnum_create_int(long i)
{
    yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));

    intn->val.l = i;
    intn->type = INTNUM_L;

    return intn;
}
コード例 #20
0
ファイル: valparam.c プロジェクト: Jonnyliu/hf-2011
yasm_valparam *
yasm_vp_create_id(/*@keep@*/ char *v, /*@keep@*/ char *p, int id_prefix)
{
    yasm_valparam *r = yasm_xmalloc(sizeof(yasm_valparam));
    r->val = v;
    r->type = YASM_PARAM_ID;
    r->param.id = p;
    r->id_prefix = (char)id_prefix;
    return r;
}
コード例 #21
0
ファイル: cpp-preproc.c プロジェクト: venkatarajasekhar/Qt
static void
cpp_preproc_undefine_macro(yasm_preproc *preproc, const char *macroname)
{
    yasm_preproc_cpp *pp = (yasm_preproc_cpp *)preproc;

    cpp_arg_entry *arg = yasm_xmalloc(sizeof(cpp_arg_entry));
    arg->op = "-U";
    arg->param = yasm__xstrdup(macroname);

    TAILQ_INSERT_TAIL(&pp->cpp_args, arg, entry);
}
コード例 #22
0
ファイル: cpp-preproc.c プロジェクト: venkatarajasekhar/Qt
static char *
cpp_preproc_get_line(yasm_preproc *preproc)
{
    yasm_preproc_cpp *pp = (yasm_preproc_cpp *)preproc;
    int bufsize = BSIZE;
    char *buf, *p;

    if (! (pp->flags & CPP_HAS_BEEN_INVOKED) ) {
        pp->flags |= CPP_HAS_BEEN_INVOKED;

        cpp_invoke(pp);
    }

    /*
        Once the preprocessor has been run, we're just dealing with a normal
        file.
    */

    /* Loop to ensure entire line is read (don't want to limit line length). */
    buf = yasm_xmalloc((size_t)bufsize);
    p = buf;
    for (;;) {
        if (!fgets(p, bufsize-(p-buf), pp->f)) {
            if (ferror(pp->f)) {
                yasm_error_set(YASM_ERROR_IO,
                               N_("error when reading from file"));
                yasm_errwarn_propagate(pp->errwarns,
                    yasm_linemap_get_current(pp->cur_lm));
            }
            break;
        }
        p += strlen(p);
        if (p > buf && p[-1] == '\n')
            break;
        if ((p-buf) >= bufsize) {
            /* Increase size of buffer */
            char *oldbuf = buf;
            bufsize *= 2;
            buf = yasm_xrealloc(buf, (size_t)bufsize);
            p = buf + (p-oldbuf);
        }
    }

    if (p == buf) {
        /* No data; must be at EOF */
        yasm_xfree(buf);
        return NULL;
    }

    /* Strip the line ending */
    buf[strcspn(buf, "\r\n")] = '\0';

    return buf;
}
コード例 #23
0
ファイル: cpp-preproc.c プロジェクト: venkatarajasekhar/Qt
static void
cpp_preproc_add_include_file(yasm_preproc *preproc, const char *filename)
{
    yasm_preproc_cpp *pp = (yasm_preproc_cpp *)preproc;

    cpp_arg_entry *arg = yasm_xmalloc(sizeof(cpp_arg_entry));
    arg->op = "-include";
    arg->param = yasm__xstrdup(filename);

    TAILQ_INSERT_TAIL(&pp->cpp_args, arg, entry);
}
コード例 #24
0
ファイル: xstrdup.c プロジェクト: Jonnyliu/hf-2011
char *
yasm__xstrdup(const char *str)
{
        size_t len;
        char *copy;

        len = strlen(str) + 1;
        copy = yasm_xmalloc(len);
        memcpy(copy, str, len);
        return (copy);
}
コード例 #25
0
ファイル: floatnum.c プロジェクト: Acidburn0zzz/yasm
yasm_floatnum *
yasm_floatnum_copy(const yasm_floatnum *flt)
{
    yasm_floatnum *f = yasm_xmalloc(sizeof(yasm_floatnum));

    f->mantissa = BitVector_Clone(flt->mantissa);
    f->exponent = flt->exponent;
    f->sign = flt->sign;
    f->flags = flt->flags;

    return f;
}
コード例 #26
0
ファイル: xstrdup.c プロジェクト: Jonnyliu/hf-2011
char *
yasm__xstrndup(const char *str, size_t max)
{
        size_t len = 0;
        char *copy;

        while (len < max && str[len] != '\0')
            len++;
        copy = yasm_xmalloc(len+1);
        memcpy(copy, str, len);
        copy[len] = '\0';
        return (copy);
}
コード例 #27
0
static yasm_effaddr *
lc3b_ea_create_expr(yasm_arch *arch, yasm_expr *e)
{
    yasm_effaddr *ea = yasm_xmalloc(sizeof(yasm_effaddr));
    yasm_value_initialize(&ea->disp, e, 0);
    ea->need_nonzero_len = 0;
    ea->need_disp = 1;
    ea->nosplit = 0;
    ea->strong = 0;
    ea->segreg = 0;
    ea->pc_rel = 0;
    ea->not_pc_rel = 0;
    return ea;
}
コード例 #28
0
yasm_bytecode *
yasm_bc_create_align(yasm_expr *boundary, yasm_expr *fill,
                     yasm_expr *maxskip, const unsigned char **code_fill,
                     unsigned long line)
{
    bytecode_align *align = yasm_xmalloc(sizeof(bytecode_align));

    align->boundary = boundary;
    align->fill = fill;
    align->maxskip = maxskip;
    align->code_fill = code_fill;

    return yasm_bc_create_common(&bc_align_callback, align, line);
}
コード例 #29
0
ファイル: inttree.c プロジェクト: Acidburn0zzz/yasm
IntervalTreeNode *
ITN_create(long low, long high, void *data)
{
    IntervalTreeNode *itn = yasm_xmalloc(sizeof(IntervalTreeNode));
    itn->data = data;
    if (low < high) {
        itn->low = low;
        itn->high = high;
    } else {
        itn->low = high;
        itn->high = low;
    }
    itn->maxHigh = high;
    return itn;
}
コード例 #30
0
/*@null@*/ /*@only@*/ unsigned char *
yasm_bc_tobytes(yasm_bytecode *bc, unsigned char *buf, unsigned long *bufsize,
                /*@out@*/ int *gap, void *d,
                yasm_output_value_func output_value,
                /*@null@*/ yasm_output_reloc_func output_reloc)
    /*@sets *buf@*/
{
    /*@only@*/ /*@null@*/ unsigned char *mybuf = NULL;
    unsigned char *origbuf, *destbuf;
    long i;
    int error = 0;

    if (yasm_bc_get_multiple(bc, &bc->mult_int, 1) || bc->mult_int == 0) {
        *bufsize = 0;
        return NULL;
    }

    /* special case for reserve bytecodes */
    if (bc->callback->special == YASM_BC_SPECIAL_RESERVE) {
        *bufsize = bc->len*bc->mult_int;
        *gap = 1;
        return NULL;    /* we didn't allocate a buffer */
    }
    *gap = 0;

    if (*bufsize < bc->len*bc->mult_int) {
        mybuf = yasm_xmalloc(bc->len*bc->mult_int);
        destbuf = mybuf;
    } else
        destbuf = buf;

    *bufsize = bc->len*bc->mult_int;

    if (!bc->callback)
        yasm_internal_error(N_("got empty bytecode in bc_tobytes"));
    else for (i=0; i<bc->mult_int; i++) {
        origbuf = destbuf;
        error = bc->callback->tobytes(bc, &destbuf, d, output_value,
                                      output_reloc);

        if (!error && ((unsigned long)(destbuf - origbuf) != bc->len))
            yasm_internal_error(
                N_("written length does not match optimized length"));
    }

    return mybuf;
}