pj.c
来自「gcc3.2.1源代码」· C语言 代码 · 共 1,287 行 · 第 1/3 页
C
1,287 行
/* Output routines for GCC for picoJava II Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.This file is part of GNU CC.GNU CC is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU CC is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU CC; see the file COPYING. If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA. *//* Contributed by Steve Chamberlain (sac@pobox.com), of Transmeta. *//* The picoJava architecture doesn't have general registers, it has an operand stack. Any of the first 256 words on the operand stack between the locations indicated by the vars register and the optop register are accessible with one instruction, almost as if they were registers. The opstack isn't aliased into memory, so deferecencing address of something on the opstack is impossible. Small scalar incoming arguments to a function arrive on the operand stack, large scalars and aggregates arrive in the `aggregate' stack. The aggregate stack lives in normal memory. just before a call after the call insn and frame setup. vars-> .... arg-5 vars->arg-5 arg-4 arg-4 arg-3 arg-3 arg-2 arg-2 arg-1 arg-1 arg-0 arg-0 target-addr old-vars #arg words old-pc optop-> saved globals local-0 local-1 .... optop-> This port generates code for a machine with 32 general purpose registers, and on output changes the references to the fake registers into offsets from the vars register. Because the opstack grows downwards and all indexes are negated, some care has to be taken here to deal with endian problems; for example after a call on a little endian machine, an incoming DImode argument of value 0x1122334455667788 in `register 0', would live on the opstack like this: vars - 0 0x11223344 vars - 4 0x55667788 vars - 8 old-vars vars - 12 old-pc The picoJava instructon to read and put that onto the opstack as a DImode value is `lload 0', yet the least significant word lives at vars - 4, for which the instruction is `iload 1'. The incoming argument code remembers which arguments arrive swapped in the CUMULATIVE_ARGS structure. The information is used to fill in pj_si_vars_offset_vec and pj_di_vars_offset_vec during the prologue printing. Outgoing arguments are collected in fake `outgoing' registers, or in the aggregate stack. The emitted code to write into an outgoing register does nothing, which leaves the expression to be written on the top of the opstack. GCC always evaluates arguments in the right order, so nothing more needs to be done. */#include "config.h"#include "system.h"#include "rtl.h"#include "tree.h"#include "tm_p.h"#include "regs.h"#include "hard-reg-set.h"#include "real.h"#include "insn-config.h"#include "conditions.h"#include "output.h"#include "insn-attr.h"#include "flags.h"#include "except.h"#include "function.h"#include "recog.h"#include "expr.h"#include "optabs.h"#include "toplev.h"#include "basic-block.h"#include "ggc.h"#include "target.h"#include "target-def.h"/* Compare insns in pj.md store the information needed to generate branch instructions here. */rtx pj_cmp_op0;rtx pj_cmp_op1;enum machine_mode pj_cmp_mode;static void pj_output_rval PARAMS ((rtx, enum machine_mode, rtx));static void pj_output_store_into_lval PARAMS ((enum machine_mode mode, rtx op));static void pj_output_push_int PARAMS ((int));static void pj_output_load PARAMS ((enum machine_mode, int));static void pj_output_inc PARAMS ((rtx, int));static void pj_output_cnv_op PARAMS ((enum insn_code, rtx));static char mode_to_char PARAMS ((enum machine_mode));static void pj_output_varidx PARAMS ((enum machine_mode, int, int));static void pj_print_cond PARAMS ((enum rtx_code));static rtx *unique_src_operand PARAMS ((rtx *, rtx));/* These vectors turn a register number into an offset from the vars pointer register. */short pj_si_vars_offset_vec[FIRST_PSEUDO_REGISTER];short pj_di_vars_offset_vec[FIRST_PSEUDO_REGISTER];short pj_debugreg_renumber_vec[FIRST_PSEUDO_REGISTER];/* Number of fake registers in the frame, used by prologue and epilogue code. */static int nfakes;/* Whether anything has been printed to the current assembly output line. */int pj_stuff_on_line;/* Initialize the GCC target structure. */struct gcc_target targetm = TARGET_INITIALIZER;/* printf to the asm_out_file, with special format control characters for decoding operands. %* - start of opcode %d,%x,%c,%s - as printf %X - address constant. %<alpha><digit> - operand <digit> passed to pj_print_operand with code <alpha>. */static voidpj_printf VPARAMS ((const char *template, ...)){ register int c; int ops_read = 0; rtx operands[10]; VA_OPEN (argptr, template); VA_FIXEDARG (argptr, const char *, template); while ((c = *template++)) { int was_stuff_on_line = pj_stuff_on_line; pj_stuff_on_line = 1; switch (c) { case '\n': putc (c, asm_out_file); pj_stuff_on_line = 0; break; default: putc (c, asm_out_file); break; case '%': { switch (*template) { case '%': putc ('%', asm_out_file); template++; pj_stuff_on_line = 1; break; case '*': /* Marks start of opcode, tab out. */ if (was_stuff_on_line) fprintf (asm_out_file, "; "); template++; break; case 'd': template++; fprintf (asm_out_file, "%d", va_arg (argptr, int)); break; case 'x': template++; fprintf (asm_out_file, "%x", va_arg (argptr, int)); break; case 'c': template++; fprintf (asm_out_file, "%c", va_arg (argptr, int)); break; case 's': template++; fputs (va_arg (argptr, const char *), asm_out_file); break; case 'X': template++; output_addr_const (asm_out_file, va_arg (argptr, rtx)); break; default: { int code = 0; rtx send; if (ISALPHA (*template)) code = *template++; if (ISDIGIT (*template)) { int num = atoi (template); template++; while (ops_read <= num) operands[ops_read++] = va_arg (argptr, rtx); send = operands[num]; } else send = va_arg (argptr, rtx); /* A null means leave the word on the stack, so there's no need to do anything for that. */ if (send) pj_print_operand (asm_out_file, send, code); } } } } } VA_CLOSE (argptr);}/* Output code to efficiently push a single word integer constant onto the opstack. */static voidpj_output_push_int (val) int val;{ int low = ((val & 0x8000) ? ~0xffff : 0) | (val & 0xffff); if (low == -1) pj_printf ("%*iconst_m1"); else if (low >= 0 && low <= 5) pj_printf ("%*iconst_%d", low); else if (low >= -128 && low < 128) pj_printf ("%*bipush %d", low); else pj_printf ("%*sipush %d", low); if ((low & 0xffff0000) != (val & 0xffff0000)) pj_printf ("%*sethi 0x%x", (val >> 16) & 0xffff);}/* Output code to add a constant to the value on the top of the opstack. */static voidpj_output_print_add_k (int size){ if (size >= 0) { pj_output_push_int (size); pj_printf ("%*iadd"); } else { pj_output_push_int (-size); pj_printf ("%*isub"); }}/* Output code to load the value pointed to by the top of stack onto the stack. */static voidpj_output_load (mode, uns) enum machine_mode mode; int uns;{ int i; switch (GET_MODE_SIZE (mode)) { case 1: pj_printf (uns ? "%*load_ubyte" : "%*load_byte"); break; case 2: pj_printf (uns ? "%*load_char" : "%*load_short"); break; case 8: if (TARGET_TM_EXTENSIONS) { pj_printf ("%*tm_load_long"); break; } /* Fall through. */ default: for (i = GET_MODE_SIZE (mode); i > 4; i -= 4) { pj_printf ("%*dup"); pj_output_print_add_k (i - 4); pj_printf ("%*load_word"); pj_printf ("%*swap"); } pj_printf ("%*load_word"); }}/* Output code to increment the provided lval operand. */static voidpj_output_inc (op, size) rtx op; int size;{ if (STACK_REG_RTX_P (op)) pj_printf ("%*iinc %d,%d", pj_si_vars_offset_vec[REGNO (op)], size); else { pj_output_rval (op, SImode, 0); pj_output_push_int (size); pj_printf ("%*iadd"); pj_output_store_into_lval (SImode, op); }}/* Output the text for a conversion operator. */static voidpj_output_cnv_op (e, op) enum insn_code e; rtx op;{ pj_printf ((const char *) insn_data[(int) e].output, 0, XEXP (op, 0));}/* Turn a machine_mode into an opcode modifier chararacter. */static charmode_to_char (mode) enum machine_mode mode;{ switch (mode) { case QImode: case HImode: case SImode: return 'i'; break; case DImode: return 'l'; break; case DFmode: return 'd'; break; case SFmode: return 'f'; break; default: abort (); }}/* Output an index off the var register. If we're moving an 8 byte value then reduce the index, since the picoJava instruction loading the value uses the index of the highest part of the register as it's name. */static voidpj_output_varidx (mode, do_store, idx) enum machine_mode mode; int do_store; int idx;{ pj_printf ("%*%c%s%c%d", mode_to_char (mode), do_store ? "store" : "load", (GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8) && idx <= 3 ? '_' : ' ', idx);}/* Output an rvalue expression. */static voidpj_output_rval (op, mode, outer_op) rtx op; enum machine_mode mode; rtx outer_op;{ enum rtx_code code = GET_CODE (op); optab tab; if (code == DIV && GET_MODE_CLASS (mode) == MODE_INT) tab = sdiv_optab; else tab = code_to_optab[code]; if (code == PLUS) { pj_output_rval (XEXP (op, 0), mode, op); pj_output_rval (XEXP (op, 1), mode, op); pj_printf ("%*%cadd", mode_to_char (mode)); } else if (tab && tab->handlers[mode].insn_code != CODE_FOR_nothing) { const char *const template = (const char *) insn_data[tab->handlers[mode].insn_code].output; if (code == NEG) pj_printf (template, 0, XEXP (op, 0)); else pj_printf (template, 0, XEXP (op, 0), XEXP (op, 1)); } else switch (GET_CODE (op)) { case PC: fprintf (asm_out_file, " pc "); break; case CONST: pj_output_rval (XEXP (op, 0), mode, op); break; case MEM:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?