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

📄 out68k_a.c

📁 一款拥有一定历史的C语言编译器
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * C compiler * ========== * * Copyright 1989, 1990, 1991 Christoph van Wuellen. * Credits to Matthew Brandt. * All commercial rights reserved. * * This compiler may be redistributed as long there is no * commercial interest. The compiler must not be redistributed * without its full sources. This notice must stay intact. * * History: * * 1989   starting an 68000 C compiler, starting with material *		  originally by M. Brandt * 1990   68000 C compiler further bug fixes *		  started i386 port (December) * 1991   i386 port finished (January) *		  further corrections in the front end and in the 68000 *		  code generator. *		  The next port will be a SPARC port *//*****************************************************************************/#include "config.h"#ifdef MC680X0#ifdef TARGET_ACK#define OUT_MODULE#include "chdr.h"#include "expr.h"#include "cglbdec.h"#include "proto.h"#include "gen68k.h"#include "outproto.h"#include "version.h"#include <time.h>/********************************************************** Type Definitions */enum e_gt{    bytegen, wordgen, longgen, longlonggen, stringgen, nogen};enum e_sg{    noseg, codeseg, dataseg, bssseg, romseg};/*********************************************** Static Function Definitions */static void nl P_ ((void));static void putop P_ ((OPCODE));static void putconst P_ ((const EXPR *, ILEN));static void putlen P_ ((ILEN));static void putamode P_ ((const ADDRESS *, ILEN));static void put_mask P_ ((REGMASK));static void put_rmask P_ ((REGMASK));static void put_smask P_ ((REGMASK));static void putreg P_ ((REG));static void put_header P_ ((enum e_gt, SIZE));static void seg P_ ((enum e_sg, const char *, SIZE));static void put_bseg P_ ((SIZE));static void put_align P_ ((SIZE));/*********************************************** Global Function Definitions */
#ifndef MULTIPLE_ASSEMBLERPRIVATE void put_name P_ ((SYM *));PRIVATE void put_dword P_ ((UVAL));PRIVATE void put_cseg P_ ((SIZE));PRIVATE void put_dseg P_ ((SIZE));PRIVATE void put_kseg P_ ((SIZE));PRIVATE void put_rseg P_ ((SIZE));PRIVATE void put_label P_ ((LABEL));PRIVATE void put_reference P_ ((SYM *));PRIVATE void put_byte P_ ((UVAL));#endif /* MULTIPLE_ASSEMBLER*/
/********************************************************** Static Variables *//* variable initialization */static enum e_gt gentype = nogen;static enum e_sg curseg = noseg;static int outcol = 0;static SIZE align_type = 0L;static const char *prefix = "I_";static const char *comment = "!";static const char *opl[] = {    "move",			/* op_move */    "move.l",			/* op_moveq */    "move",			/* op_movea */    "add",			/* op_add */    "add",			/* op_addi */    "add",			/* op_addq */    "add",			/* op_adda */    "addx",			/* op_addx */    "sub",			/* op_sub */    "sub",			/* op_subi */    "sub",			/* op_subq */    "sub",			/* op_suba */    "subx",			/* op_subx */    "muls",			/* op_muls */    "mulu",			/* op_mulu */    "divs",			/* op_divs */    "divu",			/* op_divu */    "and",			/* op_and */    "or",			/* op_or */    "eor",			/* op_eor */    "asl",			/* op_asl */    "lsr",			/* op_lsr */    "jmp",			/* op_jmp */    "jsr",			/* op_jsr */    "bsr",			/* op_brs */    "movem",			/* op_movem */    "rts",			/* op_rts */    "rte",			/* op_rte */    "bra",			/* op_bra */    "beq",			/* op_beq */    "bne",			/* op_bne */    "blt",			/* op_blt */    "ble",			/* op_ble */    "bgt",			/* op_bgt */    "bge",			/* op_bge */    "bhi",			/* op_bhi */    "bcc",			/* op_bhs */    "bcs",			/* op_blo */    "bls",			/* op_bls */    "tst",			/* op_tst */    "ext",			/* op_ext */    "extb",			/* op_extb */    "lea",			/* op_lea */    "swap",			/* op_swap */    "neg",			/* op_neg */    "negx",			/* op_negx */     "not",			/* op_not */    "cmp",			/* op_cmp */    "cmp",			/* op_cmpa */    "clr",			/* op_clr */    "link",			/* op_link */    "unlk",			/* op_unlk */    "pea",			/* op_pea */    "cmp",			/* op_cmpi */    "dbra",			/* op_dbra */    "asr",			/* op_asr */    "rol",			/* op_rol */    "ror",			/* op_ror */    "roxl",			/* op_roxl */    "roxr",			/* op_roxr */    "seq",			/* op_seq */    "sne",			/* op_sne */    "slt",			/* op_slt */    "sle",			/* op_sle */    "sgt",			/* op_sgt */    "sge",			/* op_sge */    "shi",			/* op_shi */    "scc",			/* op_shs */    "scs",			/* op_slo */    "sls",			/* op_sls */    "st",			/* op_st */    "nop",			/* op_nop */
    "trap",			/* op_trap */#ifdef FLOAT_IEEE    "fadd",			/* op_fadd */    "fsub",			/* op_fsub */    "fdiv",			/* op_fdiv */    "fmul",			/* op_fmul */    "fcmp",			/* op_fcmp */    "fmove",			/* op_fmove */    "fmovem",			/* op_fmovem */#endif				/* FLOAT_IEEE */#ifdef ASM    "",				/* op_asm */#endif				/* ASM */    ".line",			/* op_line */    (const char *) NULL,	/* op_label */};/*****************************************************************************/static void putop P1 (OPCODE, op){    if (op >= OP_MIN && op <= OP_MAX && opl[op] != (char *) 0) {	oprintf ("\t%s", opl[op]);    } else {	FATAL ((__FILE__, "putop", "illegal opcode %d", op));    }}/* * put a constant to the output file. */static void putconst P2 (const EXPR *, ep, ILEN, len){    switch (ep->nodetype) {    case en_autocon:    case en_icon:	if (len == IL8) {#ifdef LONGLONG	    oprintf ("%ld", (long) ((UVAL) ep->v.i >> 32));#else	/*  */	    if (is_signed_type (ep->etp) && ep->v.i < 0) {		oprintf ("-1");	    } else {		oprintf ("0");	    }	    #endif /* LONGLONG */	} else {	    oprintf ("%ld", (long) ep->v.i);	}	break;#ifndef FLOAT_BOOTSTRAP#ifdef FLOAT_MFFP    case en_fcon:	oprintf ("0x%lx", genffp (ep->v.f));	break;#endif /* FLOAT_MFFP */#endif /* FLOAT_BOOTSTRAP */    case en_labcon:	oprintf ("%s%u", prefix, (unsigned) ep->v.l);	break;    case en_nacon:	if (len == IL8) {	    oprintf ("0");	} else {	    oprintf ("%s", outlate (ep->v.str));	}	break;    case en_sym:	oprintf ("%s", outlate (nameof (ep->v.sp)));	break;    case en_add:	putconst (ep->v.p[0], len);	oprintf ("+");	putconst (ep->v.p[1], len);	break;    case en_sub:	putconst (ep->v.p[0], len);	oprintf ("-");	putconst (ep->v.p[1], len);	break;    case en_uminus:	oprintf ("-");	/*lint -fallthrough */    case en_cast:	putconst (ep->v.p[0], len);	break;    case en_str:	oprintf ("%s", ep->v.str);	break;    default:	FATAL (	       (__FILE__, "putconst", "illegal constant node %d",		ep->nodetype));	break;    }}/* * append the length field to an instruction. */static void putlen P1 (ILEN, l){    switch (l) {    case IL0:	break;    case IL1:	oprintf (".b");	break;    case IL2:	oprintf (".w");	break;    case IL4:	oprintf (".l");	break;    case (ILEN) (IL4 + 1):	oprintf (".s");	break;    case (ILEN) (IL8 + 1):	oprintf (".d");	break;    case (ILEN) (IL12 + 1):	oprintf (".x");	break;    default:	FATAL ((__FILE__, "putlen", "illegal length field %d", (int) l));	break;    }}/* * output a general addressing mode. */static void putamode P2 (const ADDRESS *, ap, ILEN, len){    switch (ap->mode) {    case am_immed:	oprintf ("#");	/*	 * Suppress overflow in immediate arguments -	 * which may occur due to optimization of constants	 */	if (is_icon (ap->u.offset)) {	    IVAL    i_val = ap->u.offset->v.i;	    switch (len) {	    case IL1:		i_val &= (IVAL) 0x000000ffL;		break;	    case IL2:		i_val &= (IVAL) 0x0000ffffL;		break;	    default:		break;	    }	    oprintf ("%ld", (long) i_val);	    break;	}	/*lint -fallthrough */    case am_direct:	putconst (ap->u.offset, len);	break;    case am_areg:	oprintf ("a%d", (int) ap->preg - (int) A0);	break;    case am_dreg:	oprintf ("d%d", (int) ap->preg);	break;    case am_ind:	oprintf ("(a%d)", (int) ap->preg - (int) A0);	break;    case am_ainc:	oprintf ("(a%d)+", (int) ap->preg - (int) A0);	break;    case am_adec:	oprintf ("-(a%d)", (int) ap->preg - (int) A0);	break;    case am_indx:	/* allow 32-bit offsets */	putconst (ap->u.offset, len);	oprintf ("(a%d)", (int) ap->preg - (int) A0);	break;    case am_indx2:	/* allow 32-bit offsets */	putconst (ap->u.offset, len);	oprintf ("(a%d,d%d.%c)", (int) ap->preg - (int) A0, (int) ap->sreg,		 'l');	break;    case am_indx3:	/* allow 32-bit offsets */	putconst (ap->u.offset, len);	oprintf ("(a%d,a%d.l)", (int) ap->preg - (int) A0,		 (int) ap->sreg - (int) A0);	break;    case am_indx4:	/* allow 32-bit offsets */	putconst (ap->u.offset, len);	oprintf ("(a%d,d%d.%c)", (int) ap->preg - (int) A0, (int) ap->sreg,		 'w');	break;    case am_indxpc:	putconst (ap->u.offset, len);	oprintf ("(pc)");	break;    case am_indx2pc:	putconst (ap->u.offset, len);	oprintf ("(a%d,pc)", (int) ap->preg - (int) A0);	break;    case am_rmask:	put_rmask (ap->u.mask);	break;    case am_smask:	put_smask (ap->u.mask);	break;    case am_freg:	oprintf ("fp%d", (int) ap->preg - (int) FP0);	break;    case am_line:    case am_str:	putconst (ap->u.offset, len);	break;    default:	FATAL ((__FILE__, "putamode", "illegal address mode %d", ap->mode));	break;    }}/* * output a generic instruction. */PRIVATE void put_code P1 (const CODE *, ip){    putop (ip->opcode);    putlen (ip->length);    if (ip->oper1 != NIL_ADDRESS) {	oprintf ("\t");	putamode (ip->oper1, ip->length);	if (ip->oper2 != NIL_ADDRESS) {	    if (ip->opcode == op_line) {		oprintf ("%s%s>>>>\t", newline, comment);	    } else {		oprintf (",");	    }	    putamode (ip->oper2, ip->length);	}    }    oprintf ("%s", newline);}/* * generate a register mask. */static void put_mask P1 (REGMASK, mask){    REG     reg;    BOOL    pending = FALSE;

⌨️ 快捷键说明

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