📄 outc30_r.c
字号:
/* * 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 * * 1995 Ivo Oesch, Started to build a codegenerator for the * signalprocessor TMS320C30 (December) *//*****************************************************************************/#include "config.h"#ifdef TMS320C30#ifdef TARGET_ROSSIN#define OUT_MODULE#include "chdr.h"#include "expr.h"#include "cglbdec.h"#include "proto.h"#include "genc30.h"#include "outproto.h"#include "version.h"#include <time.h>/********************************************************** Type Definitions */enum e_gt{ bytegen, wordgen, longgen, longlonggen, floatgen, nogen};enum e_sg{ noseg, codeseg, dataseg, romseg, constseg};/*********************************************** Static Function Definitions */static void nl P_ ((void));static void putop P_ ((OPCODE));static void putconst P_ ((const EXPR *));static void putamode P_ ((const ADDRESS *));static void putreg P_ ((REG));static void put_header P_ ((enum e_gt, SIZE));static void seg P_ ((enum e_sg, const char *, SIZE));/*********************************************** Global Function Definitions */PRIVATE void put_align P_ ((SIZE));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));/********************************************************** Static Variables */static enum e_gt gentype = nogen;static enum e_sg curseg = noseg;static int outcol = 0;static SIZE align_type;static const char *prefix = "L";static const char *comment = "*";static const char *opl[] = { "absf", /* op_absf */ "absi", /* op_absi */#ifdef USE_ALL_OPCODES "addc", /* op_addc */#endif "addf", /* op_addf */ "addi", /* op_addi */ "and", /* op_and */ "andn", /* op_andn */ "ash", /* op_ash */ "cmpf", /* op_cmpf */ "cmpi", /* op_cmpi */ "fix", /* op_fix */ "float", /* op_float */#ifdef USE_ALL_OPCODES "idle", /* op_idle */ "lde", /* op_lde */#endif "ldf", /* op_ldf */ "ldf", /* op_popldf */#ifdef USE_ALL_OPCODES "ldfi", /* op_ldfi */#endif "ldi", /* op_ldi */ "ldi", /* op_popldi */#ifdef USE_ALL_OPCODES "ldii", /* op_ldii */ "ldm", /* op_ldm */#endif "lsh", /* op_lsh */ "mpyf", /* op_mpyf */ "mpyi", /* op_mpyi */#ifdef USE_ALL_OPCODES "negb", /* op_negb */#endif "negf", /* op_negf */ "negi", /* op_negi */ "nop", /* op_nop */#ifdef USE_ALL_OPCODES "norm", /* op_norm */#endif "not", /* op_not */ "pop", /* op_pop */ "popf", /* op_popf */ "push", /* op_push */ "pushf", /* op_pushf */ "push", /* op_pushnopeep */ "pushf", /* op_pushfnopeep */ "or", /* op_or */#ifdef USE_ALL_OPCODES "rnd", /* op_rnd */ "rol", /* op_rol */ "rolc", /* op_rolc */ "ror", /* op_ror */ "rorc", /* op_rorc */#endif "rpts", /* op_rpts */ "stf", /* op_stf */#ifdef USE_ALL_OPCODES "stfi", /* op_stfi */#endif "sti", /* op_sti */#ifdef USE_ALL_OPCODES "stii", /* op_stii */ "sigi", /* op_sigi */ "subb", /* op_subb */ "subc", /* op_subc */#endif "subf", /* op_subf */ "subi", /* op_subi */#ifdef USE_ALL_OPCODES "subrb", /* op_subrb */#endif "subrf", /* op_subrf */ "subri", /* op_subri */ "tstb", /* op_tstb */ "xor", /* op_xor */#ifdef USE_ALL_OPCODES "iack", /* op_iack */ "addc3", /* op_addc3 */#endif "addf3", /* op_addf3 */ "addi3", /* op_addi3 */ "and3", /* op_and3 */ "andn3", /* op_andn3 */ "ash3", /* op_ash3 */ "cmpf3", /* op_cmpf3 */ "cmpf3", /* op_cmpf3 */ "lsh3", /* op_lsh3 */ "mpyf3", /* op_mpyf3 */ "mpyi3", /* op_mpyi3 */ "or3", /* op_or3 */#ifdef USE_ALL_OPCODES "subb3", /* op_subb3 */#endif "subf3", /* op_subf3 */ "subi3", /* op_subi3 */ "tstb3", /* op_tstb3 */ "xor3", /* op_xor3 */ "ldfu", /* op_ldfu */ "ldflo", /* op_ldflo */ "ldfls", /* op_ldfls */ "ldfhi", /* op_ldfhi */ "ldfhs", /* op_ldfhs */ "ldfeq", /* op_ldfeq */ "ldfne", /* op_ldfne */ "ldflt", /* op_ldflt */ "ldfle", /* op_ldfle */ "ldfgt", /* op_ldfgt */ "ldfge", /* op_ldfge */ "ldfz", /* op_ldfz */ "ldfnz", /* op_ldfnz */ "ldfp", /* op_ldfp */ "ldfn", /* op_ldfn */ "ldfnn", /* op_ldfnn */ "ldiu", /* op_ldiu */ "ldilo", /* op_ldilo */ "ldils", /* op_ldils */ "ldihi", /* op_ldihi */ "ldihs", /* op_ldihs */ "ldieq", /* op_ldieq */ "ldine", /* op_ldine */ "ldilt", /* op_ldilt */ "ldile", /* op_ldile */ "ldigt", /* op_ldigt */ "ldige", /* op_ldige */ "ldiz", /* op_ldiz */ "ldinz", /* op_ldinz */ "ldip", /* op_ldip */ "ldin", /* op_ldin */ "ldinn", /* op_ldinn */ "br", /* op_br */ "brd", /* op_brd */ "call", /* op_call */ "call", /* op_xcall !!!! */ "rptb", /* op_rptb */#ifdef USE_ALL_OPCODES "swi", /* op_swi */#endif "bu", /* op_bu */ "blo", /* op_blo */ "bls", /* op_bls */ "bhi", /* op_bhi */ "bhs", /* op_bhs */ "beq", /* op_beq */ "bne", /* op_bne */ "blt", /* op_blt */ "ble", /* op_ble */ "bgt", /* op_bgt */ "bge", /* op_bge */ "bz", /* op_bz */ "bnz", /* op_bnz */ "bp", /* op_bp */ "bn", /* op_bn */ "bnn", /* op_bnn */ "bud", /* op_bud */ "blod", /* op_blod */ "blsd", /* op_blsd */ "bhid", /* op_bhid */ "bhsd", /* op_bhsd */ "beqd", /* op_beqd */ "bned", /* op_bned */ "bltd", /* op_bltd */ "bled", /* op_bled */ "bgtd", /* op_bgtd */ "bged", /* op_bged */ "bzd", /* op_bzd */ "bnzd", /* op_bnzd */ "bpd", /* op_bpd */ "bnd", /* op_bnd */ "bnnd", /* op_bnnd */#ifdef USE_ALL_OPCODES "dbu", /* op_dbu */ "dblo", /* op_dblo */ "dbls", /* op_dbls */ "dbhi", /* op_dbhi */ "dbhs", /* op_dbhs */ "dbeq", /* op_dbeq */ "dbne", /* op_dbne */ "dblt", /* op_dblt */ "dble", /* op_dble */ "dbgt", /* op_dbgt */ "dbge", /* op_dbge */ "dbz", /* op_dbz */ "dbnz", /* op_dbnz */ "dbp", /* op_dbp */ "dbn", /* op_dbn */ "dbnn", /* op_dbnn */ "dbud", /* op_dbud */ "dblod", /* op_dblod */ "dblsd", /* op_dblsd */ "dbhid", /* op_dbhid */ "dbhsd", /* op_dbhsd */ "dbeqd", /* op_dbeqd */ "dbned", /* op_dbned */ "dbltd", /* op_dbltd */ "dbled", /* op_dbled */ "dbgtd", /* op_dbgtd */ "dbged", /* op_dbged */ "dbzd", /* op_dbzd */ "dbnzd", /* op_dbnzd */ "dbpd", /* op_dbpd */ "dbnd", /* op_dbnd */ "dbnnd", /* op_dbnnd */#endif "callu", /* op_callu */#ifdef USE_ALL_OPCODES "calllo", /* op_calllo */ "callls", /* op_callls */ "callhi", /* op_callhi */ "callhs", /* op_callhs */ "calleq", /* op_calleq */ "callne", /* op_callne */ "calllt", /* op_calllt */ "callle", /* op_callle */ "callgt", /* op_callgt */ "callge", /* op_callge */ "callz", /* op_callz */ "callnz", /* op_callnz */ "callp", /* op_callp */ "calln", /* op_calln */ "callnn", /* op_callnn */#endif "trapu", /* op_trapu */#ifdef USE_ALL_OPCODES "traplo", /* op_traplo */ "trapls", /* op_trapls */ "traphi", /* op_traphi */ "traphs", /* op_traphs */ "trapeq", /* op_trapeq */ "trapne", /* op_trapne */ "traplt", /* op_traplt */ "traple", /* op_traple */ "trapgt", /* op_trapgt */ "trapge", /* op_trapge */ "trapz", /* op_trapz */ "trapnz", /* op_trapnz */ "trapp", /* op_trapp */ "trapn", /* op_trapn */ "trapnn", /* op_trapnn */#endif "retiu", /* op_retiu */#ifdef USE_ALL_OPCODES "retilo", /* op_retilo */ "retils", /* op_retils */ "retihi", /* op_retihi */ "retihs", /* op_retihs */ "retieq", /* op_retieq */ "retine", /* op_retine */ "retilt", /* op_retilt */ "retile", /* op_retile */ "retigt", /* op_retigt */ "retige", /* op_retige */ "retiz", /* op_retiz */ "retinz", /* op_retinz */ "retip", /* op_retip */ "retin", /* op_retin */ "retinn", /* op_retinn */#endif "retsu", /* op_retsu */#ifdef USE_ALL_OPCODES "retslo", /* op_retslo */ "retsls", /* op_retsls */ "retshi", /* op_retshi */ "retshs", /* op_retshs */ "retseq", /* op_retseq */ "retsne", /* op_retsne */ "retslt", /* op_retslt */ "retsle", /* op_retsle */ "retsgt", /* op_retsgt */ "retsge", /* op_retsge */ "retsz", /* op_retsz */ "retsnz", /* op_retsnz */ "retsp", /* op_retsp */ "retsn", /* op_retsn */ "retsnn", /* op_retsnn */ "mpyf3_addf3", /* op_mpyf3_addf3 */ "mpyf3_subf3", /* op_mpyf3_subf3 */ "mpyi3_addi3", /* op_mpyi3_addi3 */ "mpyi3_subi3", /* op_mpyi3_subi3 */#endif "stf_stf", /* op_stf_stf */ "sti_sti", /* op_sti_sti */ "ldf_ldf", /* op_ldf_ldf */ "ldi_ldi", /* op_ldi_ldi */ "absf_stf", /* op_absf_stf */ "absi_sti", /* op_absi_sti */ "addf3_stf", /* op_addf3_stf */ "addi3_sti", /* op_addi3_sti */ "and3_sti", /* op_and3_sti */ "ash3_sti", /* op_ash3_sti */ "fix_sti", /* op_fix_sti */ "float_stf", /* op_float_stf */ "ldf_stf", /* op_ldf_stf */ "ldi_sti", /* op_ldi_sti */ "lsh3_sti", /* op_lsh3_sti */ "mpyf3_stf", /* op_mpyf3_stf */ "mpyi3_sti", /* op_mpyi3_sti */ "negf_stf", /* op_negf_stf */ "negi_sti", /* op_negi_sti */ "not_sti", /* op_not_sti */ "or3_sti", /* op_or3_sti */ "subf3_stf", /* op_subf3_stf */ "subi3_sti", /* op_subi3_sti */ "xor3_sti", /* op_xor3_sti */ (char *) NULL, /* op_divs (pseudo) */ (char *) NULL, /* op_divu (pseudo) */#ifdef ASM "", /* op_asm */#endif /* ASM */ "*.line", /* op_line */ (char *) NULL, /* op_label */ (char *) NULL /* op_abort */};static OPCODE ParallelOp[][2] = {#ifdef USE_ALL_OPCODES {op_mpyf3, op_addf3}, /* op_mpyf3_addf3 */ {op_mpyf3, op_subf3}, /* op_mpyf3_subf3 */ {op_mpyi3, op_addi3}, /* op_mpyi3_addi3 */ {op_mpyi3, op_subi3}, /* op_mpyi3_subi3 */#endif {op_stf, op_stf}, /* op_stf_stf */ {op_sti, op_sti}, /* op_sti_sti */ {op_ldf, op_ldf}, /* op_ldf_ldf */ {op_ldi, op_ldi}, /* op_ldi_ldi */ {op_absf, op_stf}, /* op_absf_stf */ {op_absi, op_sti}, /* op_absi_sti */ {op_addf3, op_stf}, /* op_addf3_stf */ {op_addi3, op_sti}, /* op_addi3_sti */ {op_and3, op_sti}, /* op_and3_sti */ {op_ash3, op_sti}, /* op_ash3_sti */ {op_fix, op_sti}, /* op_fix_sti */ {op_float, op_stf}, /* op_float_stf */ {op_ldf, op_stf}, /* op_ldf_stf */ {op_ldi, op_sti}, /* op_ldi_sti */ {op_lsh3, op_sti}, /* op_lsh3_sti */ {op_mpyf3, op_stf}, /* op_mpyf3_stf */ {op_mpyi3, op_sti}, /* op_mpyi3_sti */ {op_negf, op_stf}, /* op_negf_stf */ {op_negi, op_sti}, /* op_negi_sti */ {op_not, op_sti}, /* op_not_sti */ {op_or3, op_sti}, /* op_or3_sti */ {op_subf3, op_stf}, /* op_subf3_stf */ {op_subi3, op_sti}, /* op_subi3_sti */ {op_xor3, op_sti}, /* op_xor3_sti */};/*****************************************************************************/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 P1 (const EXPR *, ep){ switch (ep->nodetype) { case en_autocon: case en_icon: oprintf ("%ld", ep->v.i); break;#ifdef FLOAT_SUPPORT case en_fcon: if (is_short_float (ep->v.f, bt_float)) { oprintf ("%.9f", (double) ep->v.f); } else { FATAL ( (__FILE__, "putconst", "illegal constant node (float) %d", ep->nodetype)); } break;#endif /* FLOAT_SUPPORT */ case en_labcon: oprintf ("%s%u", prefix, (unsigned) ep->v.l); break; case en_nacon: oprintf ("%s", outlate (ep->v.str)); break; case en_add: if ((ep->v.p[0]->nodetype == en_icon) || (ep->v.p[0]->nodetype == en_autocon)) { /* avoid a number on first position (ROSSIN_AS30 2.4 hates that) */ putconst (ep->v.p[1]); oprintf ("+"); putconst (ep->v.p[0]); } else { putconst (ep->v.p[0]); oprintf ("+"); putconst (ep->v.p[1]); } break; case en_sub: putconst (ep->v.p[0]); oprintf ("-"); putconst (ep->v.p[1]); break; case en_uminus: oprintf ("-"); /*lint -fallthrough */ case en_cast: putconst (ep->v.p[0]); break;#ifdef ASM case en_str: oprintf ("%s", ep->v.str); break;#endif /* ASM */ default: FATAL ( (__FILE__, "putconst", "illegal constant node %d", ep->nodetype)); break; }}/* * put a constant to the output file. */static void putconstneg P1 (const EXPR *, ep){ switch (ep->nodetype) { case en_autocon: case en_icon: oprintf ("%ld", -ep->v.i); break;#ifdef FLOAT_SUPPORT case en_fcon: if (is_short_float (ep->v.f, bt_float)) { oprintf ("$%f", -(double) ep->v.f); } else { FATAL ( (__FILE__, "putconstneg", "illegal constant node (float) %d", ep->nodetype)); } break;#endif /* FLOAT_SUPPORT */ case en_labcon: oprintf ("-%s%u", prefix, (unsigned) ep->v.l); break; case en_nacon: oprintf ("-%s", outlate (ep->v.str)); break; case en_add: putconstneg (ep->v.p[0]); oprintf ("-"); putconst (ep->v.p[1]); break; case en_sub: putconst (ep->v.p[1]); oprintf ("-"); putconst (ep->v.p[0]); break; case en_uminus: /*oprintf("+"); */ /*lint -fallthrough */ case en_cast: putconst (ep->v.p[0]); break; default: FATAL ( (__FILE__, "putconstneg", "illegal constant node %d", ep->nodetype)); break; }}/* * put a constant to the output file. */static int testconst P1 (const EXPR *, ep){ switch (ep->nodetype) { case en_autocon: case en_icon: return (ep->v.i >= 0 ? 1 : -1);#ifdef FLOAT_SUPPORT case en_fcon: return (ep->v.f >= 0.0 ? 2 : -2);#endif /* FLOAT_SUPPORT */ case en_labcon:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -