⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objieee.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (sp->value.classdata.cppflags &PF_INLINE)
        return ;
    if ((sp->tp->cflags &DF_CONST) && scalarnonfloat(sp->tp) && sp
        ->storage_class == sc_static)
        return ;

    seg = link_getseg(sp);
    putsym(buf, sp, sp->name);
    emit_record("NI%X,%02X%s.\r\n", pubIndex, strlen(buf), buf);
    emit_record("ASI%X,R%X,%X,+.\r\n", pubIndex++, seg, sp->mainsym->offset);
    #ifdef XXXXX
        if (prm_debug)
            if (p->datatype &TY_TYPE)
                emit_record("ATI%X,T%lX.\r\n", p->id, p->datatype &~TY_TYPE);
            else
                emit_record("ATI%X,%lX.\r\n", p->id, p->datatype);
    #endif 
}

//-------------------------------------------------------------------------

void link_Publics(void)
{
    SYM *sp;
    LIST *lf = localfuncs;
    int i;
    for (i = 0; i < HASHTABLESIZE; i++)
    {
        if ((sp = (SYM*)gsyms[i]) != 0)
        {
            while (sp)
            {
                if (sp->storage_class == sc_global && !(sp
                    ->value.classdata.cppflags &PF_INLINE))
                {
                    if (!sp->mainsym->gennedvirtfunc)
                        link_putpub(sp);
                }
                sp = sp->next;
            }
        }
    }
    while (lf)
    {
        SYM *sp = lf->data;
        if (sp->storage_class == sc_global && !(sp->value.classdata.cppflags
            &PF_INLINE))
        {
            if (!sp->mainsym->gennedvirtfunc)
                link_putpub(sp);
        }
        lf = lf->link;
    }
}

//-------------------------------------------------------------------------

void link_putexport(SYM *sp)
{
    #ifdef XXXXX
        char buf[512], obuf[512];
        int l;
        putsym(buf, sp, sp->name);
        l = strlen(buf);
        *(short*)obuf = 0xa000;
        obuf[2] = 2; // export
        obuf[3] = 0; // export flags
        obuf[4] = l;
        strcpy(obuf + 5, buf);
        buf[5+l] = l;
        strcpy(obuf + 6+l, buf);

        emit_record(COMENT, obuf, 6+2 * l);
    #endif 
}

//-------------------------------------------------------------------------

void link_Exports(void)
{
    SYM *sp;
    int i;
    for (i = 0; i < HASHTABLESIZE; i++)
    {
        if ((sp = (SYM*)gsyms[i]) != 0)
        {
            while (sp)
            {
                if (sp->storage_class == sc_global && sp->exportable)
                {
                    link_putexport(sp);
                }
                sp = sp->next;
            }
        }
    }
}

//-------------------------------------------------------------------------

void link_PassSeperator(void)
{
    emit_record("CO100,06ENDSYM.\r\n");
}

//-------------------------------------------------------------------------

int link_Fixups(char *buf, FIXUP *fixup, EMIT_LIST *rec, int curseg)
{
    int iseg, xseg;
    int rel = FALSE;
    switch (fixup->fmode)
    {
        case fm_relsymbol:
            rel = TRUE;
        case fm_symbol:
            if (fixup->sym->storage_class == sc_abs)
            {
                if (rel)
                {
                    strcpy(buf, "0");
                    DIAG("Relative absolute in link_Fixups");
                }
                else
                    sprintf(buf, "%X", fixup->sym->offset + fixup->ofs);
                return ;
            }
            iseg = link_getseg(fixup->sym);
            if (fixup->sym->gennedvirtfunc)
                xseg = iseg;
            else
                xseg = segxlattab[iseg];
            {
                SYM *sp = fixup->sym;
                if (sp->mainsym)
                    sp = sp->mainsym;
                if (sp->storage_class == sc_member && sp
                    ->value.classdata.gdeclare && sp->value.classdata.gdeclare
                    ->storage_class == sc_global)
                    sp = sp->value.classdata.gdeclare;
                if (sp->storage_class == sc_global || sp->storage_class ==
                    sc_static || (sp->storage_class == sc_external || sp
                    ->storage_class == sc_externalfunc) && !sp->mainsym
                    ->extflag)
                {
                    if (rel)
                    {
                        if (iseg == curseg)
                        {
                            sprintf(buf, "%X", sp->mainsym->offset - fixup
                                ->address);
                        }
                        else
                        {
                            sprintf(buf, "R%X,%X,+,P,-", xseg, sp->mainsym
                                ->offset);
                        }
                    }
                    else
                    {
                        sprintf(buf, "R%X,%X,+", xseg, sp->mainsym->offset +
                            fixup->ofs);
                    }
                    /* segment relative */
                }
                else
                {
                    if (rel)
                    {
                        sprintf(buf, "X%X,P,-,%X,+", sp->value.i, fixup->ofs);
                    }
                    else
                    {
                        sprintf(buf, "X%X", sp->value.i);
                    }
                    /* extdef relative */
                }
            }
            break;

        case fm_rellabel:
            rel = TRUE;
        case fm_label:
            iseg = LabelSeg(fixup->label);
            if (rel)
            {
                if (iseg == curseg)
                    sprintf(buf, "%X", LabelAddress(fixup->label) + fixup->ofs 
                        - fixup->address);
                else
                {
                    sprintf(buf, "R%X,%X,+,P,-", xseg, LabelAddress(fixup
                        ->label) + fixup->ofs);
                }
            }
            else
            {
                sprintf(buf, "R%X,%X,+", segxlattab[iseg], LabelAddress(fixup
                    ->label) + fixup->ofs);
            }
            /* segment relative */
            break;
    }
}

//-------------------------------------------------------------------------

static long putlr(FIXUP *p, EMIT_LIST *s, int curseg)
{
    char buf[512];
    link_Fixups(buf, p, s, curseg);
    emit_record("LR(%s,%X).\r\n", buf, p->size);
    return (p->size);
}

//-------------------------------------------------------------------------

static long putld(long start, long end, unsigned char *buf)
{
    long count = 0;
    int i;
    if (start == end)
        return (start);
    while (end - start >= LDPERLINE)
    {
        emit_record("LD");
        for (i = 0; i < LDPERLINE; i++)
            emit_record("%02X", buf[count++]);
        start += LDPERLINE;
        emit_record(".\r\n");
    }
    if (start == end)
        return (start);
    emit_record("LD");
    while (start < end)
    {
        emit_record("%02X", buf[count++]);
        start++;
    }
    emit_record(".\r\n");
    return (start);
}

//-------------------------------------------------------------------------

void link_Data(void)
{
    char buf[1100];
    int i;
    VIRTUAL_LIST *v = virtualFirst;
    for (i = 1; i < MAX_SEGS; i++)
    if (segxlattab[i] && segs[i].curlast)
    {
        EMIT_LIST *rec = segs[i].first;
        emit_record("SB%X.\r\n", segxlattab[i]);
        while (rec)
        {
            int j = 0;
            int len;
            long size = segs[i].curlast;
            FIXUP *f = rec->fixups;
            while (j < rec->filled)
            {
                if (f)
                    len = f->address - rec->address - j;
                else
                    len = rec->filled - j;

                putld(j, len + j, rec->data + j);
                j += len;
                if (f)
                {
                    j += putlr(f, rec, i);
                    f = f->next;
                }
            }
            rec = rec->next;
        }
        emit_cs(FALSE);
    }
    i = firstVirtualSeg;
    while (v)
    {
        EMIT_LIST *rec = v->seg->first;
        emit_record("SB%X.\r\n", i);
        while (rec)
        {
            int j = 0;
            int len;
            long size = v->seg->curlast;
            FIXUP *f = rec->fixups;
            while (j < rec->filled)
            {
                if (f)
                    len = f->address - rec->address - j;
                else
                    len = rec->filled - j;

                putld(j, len + j, rec->data + j);
                j += len;
                if (f)
                {
                    j += putlr(f, rec, i);
                    f = f->next;
                }
            }
            rec = rec->next;
        }
        emit_cs(FALSE);
        i++;
        v = v->next;
    }
}

//-------------------------------------------------------------------------

void link_SourceFile(char *file, int num)
{
    file = fullqualify(file);
    #ifdef XXXXX
        unsigned short time, date;
        char buf[512];
        int fd;
        *(short*)buf = 0xe800;
        buf[2] = num;
        buf[3] = strlen(file);
        strcpy(buf + 4, file);
        if (_dos_open(file, 0, &fd))
        {
            time = 0;
            date = 0;
        }
        else
        {
            _dos_getftime(fd, &date, &time);
            _dos_close(fd);
        }
        *(short*)(buf + 4+buf[3]) = time;
        *(short*)(buf + 6+buf[3]) = date;
        emit_record(COMENT, buf, 8+buf[3]);
    #endif 
}

//-------------------------------------------------------------------------

void link_LineNumbers(int file)
{
    #ifdef XXXXX
        LINEBUF *l = linelist;
        char buf[1100],  *p;
        int lastnum =  - 1;
        while (l)
        {
            p = buf;
            *p++ = 0;
            *p++ = segxlattab[codeseg];
            while (l && p - buf < 1024-6)
            {
                if (l->file == file)
                {
                    //            if (l->address != lastnum) {
                    *(short*)p = l->lineno;
                    *(int*)(p + 2) = l->address;
                    p += 6;
                    lastnum = l->address;
                    //            }
                }
                l = l->next;
            }
            if (p - buf > 2)
            {
                emit_record(LINNUM, buf, p - buf);
            }
        }
    #endif 
}

//-------------------------------------------------------------------------

void link_EmitLineInfo(void)
{
    int i, q;
    FILELIST *l;
    link_SourceFile(infile, 1);
    link_LineNumbers(0);
    for (i = 1, q = 2, l = incfiles; l; i++, l = l->link)
    if (l->hascode)
    {
        link_SourceFile(l->data, q++);
        link_LineNumbers(i);
    }
}

//-------------------------------------------------------------------------

void output_obj_file(void)
{
    LIST *l = incfiles;
    int i, pos = 1;
    extIndex = pubIndex = 1;
    checksum = 0;
    for (i = 1; i < MAX_SEGS; i++)
    {
        if (segs[i].curlast)
        {
            segxlattab[i] = pos++;
        }
        else
            segxlattab[i] = 0;
    }
    link_header(fullqualify(infile));
    emit_cs(FALSE);
    link_Segs();
    emit_cs(FALSE);
    link_ExtDefs();
    link_Publics();
    emit_cs(FALSE);
    link_PassSeperator();
    link_Data();
    link_trailer();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -