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

📄 outi.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (gentype == srrefgen && outcol < 56)
    {
        oprintf(outputFile, ",%s,%d", name, val);
        outcol += strlen(name) + 1;
    }
    else
    {
        nl();
        oprintf(outputFile, "\tDC.A\t%s,%d", name, val);
        gentype = srrefgen;
        outcol = 25;
    }
}

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

void genref(SYM *sp, int offset)
/*
 * Output a reference to the data area (also gens fixups )
 */
{
    char sign;
    char buf[40];
    if (offset < 0)
    {
        sign = '-';
        offset =  - offset;
    }
    else
        sign = '+';
    sprintf(buf, "%s%c%d", sp->name, sign, offset);
    if (prm_asmfile)
    {
        if (gentype == longgen && outcol < 55-strlen(sp->name))
        {
            oprintf(outputFile, ",%s", buf);
            outcol += (11+strlen(sp->name));
        }
        else
        {
            nl();
            oprintf(outputFile, "\tDC.A\t%s", buf);
            outcol = 26+strlen(sp->name);
            gentype = longgen;
        }
    }
    dataofs += 4;
}

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

void genpcref(SYM *sp, int offset)
/*
 * Output a reference to the code area (also gens fixups )
 */
{
    char sign;
    char buf[40];
    if (offset < 0)
    {
        sign = '-';
        offset =  - offset;
    }
    else
        sign = '+';
    sprintf(buf, "%s%c%d", sp->name, sign, offset);
    if (prm_asmfile)
    {
        if (gentype == longgen && outcol < 55-strlen(sp->name))
        {
            oprintf(outputFile, ",%s", buf);
            outcol += (11+strlen(sp->name));
        }
        else
        {
            nl();
            oprintf(outputFile, "\tDC.A\t%s", buf);
            outcol = 26+strlen(sp->name);
            gentype = longgen;
        }
    }
    dataofs += 4;
}

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

void genstorage(int nbytes)
/*
 * Output bytes of storage
 */
{
    if (prm_asmfile)
    {
        nl();
        oprintf(outputFile, "\tDS.B\t$%X\n", nbytes);
    }
    dataofs += nbytes;
}

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

void gen_labref(int n)
/*
 * Generate a reference to a label
 */
{
    if (prm_asmfile)
    if (gentype == longgen && outcol < 58)
    {
        oprintf(outputFile, ",L_%d", n);
        outcol += 6;
    }
    else
    {
        nl();
        oprintf(outputFile, "\tDC.A\tL_%d", n);
        outcol = 22;
        gentype = longgen;
    }
    dataofs += 4;
}

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

int stringlit(char *s, int uselong, int len)
/*
 *      make s a string literal and return it's label number.
 */
{
    struct slit *lp = strtab;
    if (uselong)
        len *= 2;
    if (prm_optmult)
    {
        while (lp)
        {
            if (len == lp->len && !memcmp(lp->str, s, len))
                return lp->label;
            lp = lp->next;
        } 
    }
    ++global_flag; /* always allocate from global space. */
    lp = xalloc(sizeof(struct slit));
    lp->label = nextlabel++;
    lp->str = xalloc(len);
    memcpy(lp->str, s, len);
    lp->len = len;
    lp->next = strtab;
    lp->type = uselong;
    strtab = lp;
    --global_flag;
    return lp->label;
}

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

void dumplits(void)
/*
 *      dump the string literal pool.
 */
{
    if (prm_asmfile)
    {
        while (strtab != 0)
        {
            xstringseg();
            nl();
            put_label(strtab->label);
            genstring(strtab->str, strtab->type, strtab->len - 1);
            if (strtab->type)
                genword(0);
            else
                genbyte(0);
            strtab = strtab->next;
        } nl();
    }
}

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

void nl(void)
/*
 * New line
 */
{
    if (prm_asmfile)
    {
        if (outcol > 0)
        {
            fputc('\n', outputFile);
            outcol = 0;
            gentype = nogen;
        }
    }
}

/*
 * Switch to cseg 
 */
void cseg(void)
{
    if (prm_asmfile)
    if (curseg != codeseg)
    {
        nl();
        oprintf(outputFile, "\tSECTION\tcode\n");
        curseg = codeseg;
    }
}

/*
 * Switch to dseg
 */
void dseg(void)
{
    if (prm_asmfile)
    if (curseg != dataseg)
    {
        nl();
        oprintf(outputFile, "\tSECTION\tdata\n");
        curseg = dataseg;
    }
}

/*
 * Switch to bssseg
 */
void bssseg(void)
{
    if (prm_asmfile)
    if (curseg != bssxseg)
    {
        nl();
        oprintf(outputFile, "\tSECTION\tbss\n");
        curseg = bssxseg;
    }
}
/*
 * Switch to const seg
 */
void xconstseg(void)
{
    if (prm_asmfile)
    if (curseg != constseg)
    {
        nl();
        oprintf(outputFile, "\tSECTION\tconst\n");
        curseg = constseg;
    }
}
/*
 * Switch to string seg
 */
void xstringseg(void)
{
    if (prm_asmfile)
    if (curseg != stringseg)
    {
        nl();
        oprintf(outputFile, "\tSECTION\tstring\n");
        curseg = stringseg;
    }
}

/*
 * Switch to startupseg
 */
void startupseg(void)
{
    if (prm_asmfile)
    if (curseg != startupxseg)
    {
        nl();
        oprintf(outputFile, "\tSECTION\tcstartup\n");
        curseg = startupxseg;
    }
}

/*
 * Switch to rundownseg
 */
void rundownseg(void)
{
    if (prm_asmfile)
    if (curseg != rundownxseg)
    {
        nl();
        oprintf(outputFile, "\tSECTION\tcrundown\n");
        curseg = rundownxseg;
    }
}

/*
 * Switch to cppseg
 */
void cppseg(void)
{
    if (prm_asmfile)
    if (curseg != cppxseg)
    {
        nl();
        oprintf(outputFile, "\tSECTION\tcppinit\n");
        curseg = cppxseg;
    }
}

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

void cpprdseg(void)
{
    if (prm_asmfile)
    if (curseg != xcpprdseg)
    {
        nl();
        oprintf(outputFile, "\tSECTION\tcpprundown\n");
        curseg = xcpprdseg;
    }
}

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


void exitseg(void)
{
}
void gen_virtual(char *name, int data)
{
    if (prm_asmfile)
    {
        char buf[512];
		if (!data && curseg != codeseg)
            cseg();
        virtual_mode = data;
        curseg = virtseg;
        putsym(buf, sp, sp->name);

        nl();
        oprintf(outputFile, "@%s\tVIRTUAL", buf);
        oprintf(outputFile, "%s:\n", buf);
   }
}

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

void gen_endvirtual(char *name)
{
    if (prm_asmfile)
    {
        nl();
        oprintf(outputFile, "@%s\tENDVIRTUAL", name);
		if (virtual_mode)
			dseg();
		else
			cseg();
    }
}
void align(int size)
{
    if (curseg == codeseg)
        return ;
	nl();
	oprintf("align %d\n",size);
}
void dump_browsedata(unsigned char *data, int len)
{
}

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

void asm_header(void)
{
    oprintf(outputFile, ";Icode test - %s\n\n", outfile);
}

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

void globaldef(SYM *sp)
{
    char buf[100],  *q = buf,  *p = sp->name;
    if (curseg == codeseg && currentfunc->pascaldefn)
    {
        if (prm_cmangle)
            p++;
        while (*p)
            *q++ = toupper(*p++);
        *q++ = 0;
    }
    else
        strcpy(buf, p);
    oprintf(outputFile, "\tPUBLIC\t%s\n", buf);
}

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

void output_alias(SYM *sp)
{
    char buf[256];
    putsym(buf, sp, sp->name);
    oprintf(outputFile, "%s EQU\t<%s>\n", buf, sp->alias);
}

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

int put_exdata(SYM *sp, int notyet)
{
    char buf[512],  *q = buf,  *p = sp->name;
    putsym(buf, sp, p);
    if (notyet)
    {
        oprintf(outputFile, "\n\t.CODE\n");
        notyet = FALSE;
    }
    oprintf(outputFile, "\tEXTRN\t%s:DATA\n", buf);
    if (sp->importable)
        oprintf(outputFile, "\timport %s %s\n", buf, sp->importfile);
    return notyet;
}
int put_exfunc(SYM *sp, int notyet)
{
    char buf[512],  *q = buf,  *p = sp->name;
    putsym(buf, sp, p);
    if (notyet)
    {
        oprintf(outputFile, "\n\t.CODE\n");
        notyet = FALSE;
    }
    oprintf(outputFile, "\tEXTRN\t%s:PROC\n", buf);
    if (sp->importable)
        oprintf(outputFile, "\timport %s %s\n", buf, sp->importfile);
    return notyet;
}

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

int put_expfunc(SYM *sp, int notyet)
{
    char buf[512];
    if (notyet)
    {
        oprintf(outputFile, "\n.CODE\n");
        notyet = FALSE;
    }
    putsym(buf, sp, sp->name);
    oprintf(outputFile, "\texport %s\n", buf);
}

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

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

static int dumphashtable(int notyet, HASHREC **syms)
{
    int i;
    SYM *sp;
    char buf[100];
    for (i = 0; i < HASHTABLESIZE; i++)
    {
        if ((sp = (SYM*)syms[i]) != 0)
        {
            while (sp)
            {
                if (sp->storage_class == sc_externalfunc && sp->mainsym
                    ->extflag && !(sp->tp->cflags &DF_INTRINS))
                    notyet = put_exfunc(sp, notyet);
                if (sp->storage_class == sc_external && sp->mainsym->extflag)
                    notyet = put_exfunc(sp, notyet);
                if (sp->storage_class == sc_defunc)
                {
                    SYM *sp1 = sp->tp->lst.head;
                    while (sp1)
                    {
                        if (sp1->mainsym->storage_class == sc_externalfunc &&
                            sp1->mainsym->extflag && !(sp1->tp->cflags
                            &DF_INTRINS))
                        {
                            notyet = put_exfunc(sp1, notyet);
                        }
                        if (sp1->mainsym->exportable && !(sp1->value.classdata.cppflags & PF_INLINE))
                            notyet = put_expfunc(sp1, notyet);
                        sp1 = sp1->next;
                    }
                }
                if (sp->storage_class == sc_namespace && !sp
                    ->value.classdata.parentns->anonymous)
                    notyet = dumphashtable(notyet, sp->value.classdata.parentns
                        ->table);
                if (sp->mainsym->exportable && !(sp->value.classdata.cppflags & PF_INLINE))
                    notyet = put_expfunc(sp, notyet);
                sp = sp->next;
            }
        }
    }
    return notyet;
}

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

void putexterns(void)
/*
 * Output the fixup tables and the global/external list
 */
{
    SYM *sp;
    int i;
    LIST *l;
    char buf[100];
    if (prm_asmfile)
    {
        int notyet = TRUE;
        nl();
        exitseg();
        notyet = dumphashtable(notyet, gsyms);

        while (localfuncs)
        {
            sp = localfuncs->data;
            if (sp->storage_class == sc_externalfunc && sp->mainsym->extflag &&
                !(sp->tp->cflags &DF_INTRINS))
                notyet = put_exfunc(sp, notyet);
            if (sp->exportable)
                notyet = put_expfunc(sp, notyet);
            localfuncs = localfuncs->link;
        }
        notyet = TRUE;

        for (i = 0; i < HASHTABLESIZE; i++)
        {
            struct _templatelist *tl;
            if ((tl = (struct templatelist*)templateFuncs[i]) != 0)
            {
                while (tl)
                {
                    if (!tl->sp->value.classdata.templatedata->hasbody && tl
                        ->finalsp)
                        notyet = put_exfunc(tl->finalsp, notyet);
                    tl = tl->next;
                } 
            }
        }
        notyet = TRUE;
        exitseg();
        while (localdata)
        {
            sp = localdata->data;
            if (sp->mainsym->extflag)
            {
                notyet = put_exdata(sp, notyet);
            }
            localdata = localdata->link;
        }
            if (libincludes)
            {
                while (libincludes)
                {
                    oprintf(outputFile, "\tINCLUDELIB\t%s\n", libincludes->data)
                        ;
                    libincludes = libincludes->link;
                }
                oputc('\n', outputFile);
            }
            oprintf(outputFile, "\tEND\n");
    }
}

⌨️ 快捷键说明

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