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

📄 iout.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 3 页
字号:
/*       
Copyright 1994-2003 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.  

This program is derived from the cc68k complier by 
Matthew Brandt (mattb@walkingdog.net) 

You may contact the author of this derivative at:

mailto::camille@bluegrass.net

or by snail mail at:

David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222
 */
/*
 * iout.c
 *
 * output routines for icode code gen.  Used only in optimizer tests.
 *
 */
#include <stdio.h>
#include "lists.h"
#include "expr.h"
#include "c.h"
#include "iexpr.h"
#include "diag.h"
#include "lists.h"

/*      variable initialization         */
extern HASHREC **gsyms;
extern QUAD *intermed_head;
extern int prm_optmult, prm_cplusplus;
extern int stdintsize, stdretblocksize;

enum e_gt
{
    nogen, bytegen, wordgen, intgen, enumgen, longgen, floatgen, doublegen, longdoublegen,
        srrefgen
};
enum e_sg
{
    noseg, codeseg, dataseg, bssxseg, stringseg, constseg, startupxseg,
        rundownxseg, cppxseg, xcpprdseg, virtseg = 100
};

extern LIST *localfuncs;
extern long nextlabel;
extern int global_flag;
extern int prm_lines;
extern FILE *icdFile;
extern char outfile[];
extern LIST *libincludes;
extern int prm_cmangle;
extern SYM *currentfunc;


int gentype = nogen; /* Current DC type */
int curseg = noseg; /* Current seg */
int outcol = 0; /* Curront col (roughly) */
int dataofs; /* Offset from last label */
char dataname[40]; /* Name of last label */

static int virtual_mode;
static struct slit *strtab;
static int newlabel;
/* Init module */
void outcodeini(void)
{
    gentype = nogen;
    curseg = noseg;
    outcol = 0;
	virtual_mode = 0;
	newlabel = FALSE;
} 
static void op_nop(QUAD *q)
{
    oprintf(icdFile,"\tNOP");
}
/*
 * ICODE op display handlers
 */
static void op_line(QUAD *q)
{
    if (!prm_lines)
        return ;
    oprintf(icdFile, ";\n; Line %d:\t%s\n;", (int)q->dc.label, (char*)q
        ->dc.left);
}

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

static void op_passthrough(QUAD *q)
{
    oprintf(icdFile, "%s\n", (char*)q->dc.left);
}

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

static void op_label(QUAD *q)
{
    oprintf(icdFile, "L_%d:", q->dc.label);
}

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

static void putsingle(IMODE *ap, char *string)
{
    oprintf(icdFile, "\t%s", string);
    if (ap)
    {
        oputc('\t', icdFile);
        putamode(ap);
    }
}

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

static void op_goto(QUAD *q)
{
    oprintf(icdFile, "\tGOTO\tL_%d:PC", q->dc.label);
}

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

static void op_gosub(QUAD *q)
{
    putsingle(q->dc.left, "GOSUB");
}

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

static void op_trap(QUAD *q)
{
    putsingle(q->dc.left, "TRAP");
}

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

static void op_int(QUAD *q)
{
    putsingle(q->dc.left, "INT");
}

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

static void op_ret(QUAD *q)
{
    oprintf(icdFile, "\tRET\n");
}

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

static void op_rett(QUAD *q)
{
    oprintf(icdFile, "\tRETT\n");
}

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

static void putbin(QUAD *q, char *str)
{
    oputc('\t', icdFile);
    putamode(q->ans);
    oprintf(icdFile, " = ");
    putamode(q->dc.left);
    oprintf(icdFile, " %s ", str);
    putamode(q->dc.right);
}

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

static void op_add(QUAD *q)
{
    putbin(q, "+");
}

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

static void op_sub(QUAD *q)
{
    putbin(q, "-");
}

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

static void op_udiv(QUAD *q)
{
    putbin(q, "U/");
}

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

static void op_umod(QUAD *q)
{
    putbin(q, "U%");
}

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

static void op_sdiv(QUAD *q)
{
    putbin(q, "S/");
}

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

static void op_smod(QUAD *q)
{
    putbin(q, "S%");
}

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

static void op_umul(QUAD *q)
{
    putbin(q, "U*");
}

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

static void op_smul(QUAD *q)
{
    putbin(q, "S*");
}

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

static void op_lsl(QUAD *q)
{
    putbin(q, "U<<");
}

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

static void op_lsr(QUAD *q)
{
    putbin(q, "U>>");
}

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

static void op_asl(QUAD *q)
{
    putbin(q, "S<<");
}

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

static void op_asr(QUAD *q)
{
    putbin(q, "S>>");
}

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

static void op_and(QUAD *q)
{
    putbin(q, "&");
}

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

static void op_or(QUAD *q)
{
    putbin(q, "|");
}

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

static void op_eor(QUAD *q)
{
    putbin(q, "^");
}

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

static void putunary(QUAD *q, char *str)
{
    oputc('\t', icdFile);
    putamode(q->ans);
    oprintf(icdFile, " = ");
    oprintf(icdFile, " %s ", str);
    putamode(q->dc.left);
}

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

static void putasunary(QUAD *q, char *str)
{
    oputc('\t', icdFile);
    putamode(q->ans);
    oprintf(icdFile, " %s ", str);
    putamode(q->dc.left);
}

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

static void op_neg(QUAD *q)
{
    putunary(q, "-");
}

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

static void op_not(QUAD *q)
{
    putunary(q, "~");
}

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

static void op_assn(QUAD *q)
{
    putunary(q, "");
}

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

static void op_asadd(QUAD *q)
{
    putasunary(q, "+=");
}

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

static void op_assub(QUAD *q)
{
    putasunary(q, "-=");
}

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

static void op_assmul(QUAD *q)
{
    putasunary(q, "S*=");
}

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

static void op_asumul(QUAD *q)
{
    putasunary(q, "U*=");
}

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

static void op_assdiv(QUAD *q)
{
    putasunary(q, "S/=");
}

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

static void op_asudiv(QUAD *q)
{
    putasunary(q, "U/=");
}

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

static void op_assmod(QUAD *q)
{
    putasunary(q, "S%=");
}

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

static void op_asumod(QUAD *q)
{
    putasunary(q, "U%=");
}

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

static void op_aslsl(QUAD *q)
{
    putasunary(q, "U<<=");
}

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

static void op_asasl(QUAD *q)
{
    putasunary(q, "S<<=");
}

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

static void op_aslsr(QUAD *q)
{
    putasunary(q, "U>>=");
}

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

static void op_asasr(QUAD *q)
{
    putasunary(q, "S>>=");
}

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

static void op_asand(QUAD *q)
{
    putasunary(q, "&=");
}

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

static void op_asor(QUAD *q)
{
    putasunary(q, "|=");
}

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

static void op_aseor(QUAD *q)
{
    putasunary(q, "^=");
}

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

static void op_asuminus(QUAD *q)
{
    putasunary(q, "=-");
}

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

static void op_ascompl(QUAD *q)
{
    putasunary(q, "=~");
}

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

static void op_genword(QUAD *q)
{
    putsingle(q->dc.left, "GENWORD");
}

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

static void op_coswitch(QUAD *q)
{
    oprintf(icdFile, "\tCOSWITCH(");
    putamode(q->ans);
    oputc(',', icdFile);
    putamode(q->dc.left);
    oputc(',', icdFile);
    putamode(q->dc.right);
    oputc(',', icdFile);
    oprintf(icdFile, "L_%d:PC)", q->dc.label);
}
static void op_swbranch(QUAD *q)
{
    oprintf(icdFile, "\tSWBRANCH(");
    putamode(q->dc.left);
    oputc(',', icdFile);
    oprintf(icdFile, "L_%d:PC)", q->dc.label);
}

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

static void op_dc(QUAD *q)
{
    oprintf(icdFile, "\tDC.L\tL_%d:PC", q->dc.label);
}

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

static void op_array(QUAD *q)
{
	oputc('\t',icdFile);
    putamode(q->ans);
    oprintf(icdFile, " = ");
    oprintf(icdFile, " ARRAY ");
    putamode(q->dc.left);
	oputc(',',icdFile);
    putamode(q->dc.right);
}

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

static void op_arrayindex(QUAD *q)
{
	oputc('\t',icdFile);
    putamode(q->ans);
    oprintf(icdFile, " = ");
    oprintf(icdFile, " ARRIND ");
    putamode(q->dc.left);
	oputc(',',icdFile);
    putamode(q->dc.right);
}
//-------------------------------------------------------------------------

static void op_assnblock(QUAD *q)
{
    oputc('\t', icdFile);
    putamode(q->ans);
    oprintf(icdFile, " BLOCK= ");
    putamode(q->dc.left);
    oprintf(icdFile, "(");
    putamode(q->dc.right);
    oprintf(icdFile, ")");
}

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

static void op_clrblock(QUAD *q)
{
    oputc('\t', icdFile);
    putamode(q->dc.left);
    oprintf(icdFile, " BLKCLR ");
    oprintf(icdFile, "(");
    putamode(q->dc.right);
    oprintf(icdFile, ")");
}
//-------------------------------------------------------------------------

static void putjmp(QUAD *q, char *str)
{
    oprintf(icdFile, "\tCONDGO\tL_%d:PC ; ", q->dc.label);
    if (q->dc.left)
        putamode(q->dc.left);
    oprintf(icdFile, " %s ", str);
    if (q->dc.right)
        putamode(q->dc.right);
}


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

static void putset(QUAD *q, char *str)
{
    oputc('\t',icdFile);
    putamode(q->ans);
    oprintf(icdFile, " = ");
    putamode(q->dc.left);
    oprintf(icdFile, " %s ", str);
    putamode(q->dc.right);
}

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

static void op_jc(QUAD *q)
{
    putjmp(q, "U<");
}

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

static void op_ja(QUAD *q)
{
    putjmp(q, "U>");
}

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

static void op_je(QUAD *q)
{
    putjmp(q, "==");
}

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

static void op_jnc(QUAD *q)
{
    putjmp(q, "U>=");
}

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

static void op_jbe(QUAD *q)
{
    putjmp(q, "U<=");
}

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

static void op_jne(QUAD *q)
{
    putjmp(q, "!=");
}

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

static void op_jl(QUAD *q)
{
    putjmp(q, "S<");
}

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

static void op_jg(QUAD *q)
{
    putjmp(q, "S>");
}

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

static void op_jle(QUAD *q)
{
    putjmp(q, "S<=");
}

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

static void op_jge(QUAD *q)
{
    putjmp(q, "S>=");
}

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

static void op_setc(QUAD *q)
{
    putset(q, "U<");

⌨️ 快捷键说明

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