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

📄 gexpr68.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 5 页
字号:
- BESZ_DWORD: BESZ_DWORD/*        
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
 */
#include <stdio.h>
#include <string.h>
#include "lists.h"
#include "expr.h"
#include "c.h"
#include "gen68.h"
#include "diag.h"

#define ABS(x) ( (x) < 0 ? -(x) : (x))
/*
 *      this module contains all of the code generation routines
 *      for evaluating expressions and conditions.
 */
extern SYM *declclass;
extern OCODE *peep_tail,  *frame_ins;
extern int stdinttype, stdunstype, stdintsize, stdldoublesize, stdaddrsize;
extern int cf_freeaddress, cf_freedata;
extern int linkreg, basereg, stackadd, stackmod;
extern long stackdepth, framedepth;
extern int prm_largedata, prm_68020, prm_phiform, prm_linkreg, prm_coldfire;
extern int prm_smallcode, prm_pcrel, prm_datarel, prm_smalldata;
extern AMODE push[], pop[];
extern int prm_68020, prm_cmangle;
extern SYM *currentfunc;
extern long lc_maxauto;
extern long nextlabel;
extern char regstack[], rsold[], rsodepth, rsdepth;
extern int retlab;
extern char dregs[3], aregs[3], fregs[3];
extern int floatstack_mode;
extern int pushcount;

int genning_inline;
static char opcomb[] = 
{
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1,
        1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
        0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
        1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1,
        1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/*
 * Routine replaces move instructions the coldfire can't handle
 * with sequences it can
 */
void gen_move(int nsize, AMODE *ap2, AMODE *apr)
{
    if (!prm_coldfire)
        gen_codes(op_move, nsize, ap2, apr);
    else
    {
        if (opcomb[(ap2->mode *43) + apr->mode])
        /* Check here for ColdFire move restrictions */
            gen_codes(op_move, nsize, ap2, apr);
        else
        {
            /* Check for #0,<mode> and allow since clr will replace */
            if (ap2->mode == am_immed && ap2->offset->v.i == 0)
            {
                gen_codes(op_move, nsize, ap2, apr);
            }
            else
            {
                do_extend(ap2, nsize, F_DREG | F_VOL);
                gen_codes(op_move, nsize, ap2, apr);
            }
        }
    }
}

/* little ditty to allocate stack space for floating point
 * conversions and return a pointer to it
 * it will be at the bottom for standard stack frames; top for 
 * using ESP for frames
 * 0-7 used for fistp, 8-15 used for long intermediate values
 */
AMODE *cmpconvpos(void)
{
    AMODE *ap1;
    int constv = 16;
    //   if (prm_cplusplus)
    //      constv = 12;
    if (!floatstack_mode)
    {
        if (!lc_maxauto)
        {
            OCODE *new = xalloc(sizeof(OCODE));
            new->opcode = op_sub;
            new->oper2 = make_immed(constv);
            new->oper1 = makedreg(7);
            new->back = frame_ins;
            new->fwd = frame_ins->fwd;
            frame_ins->fwd->back = new;
            frame_ins->fwd = new;
        }
        else
        {
            frame_ins->oper2->offset->v.i -= constv;
        }
        floatstack_mode += constv;
    }
    ap1 = xalloc(sizeof(AMODE));
    ap1->mode = am_indx;
    ap1->preg = linkreg;
    ap1->offset = makeintnode(en_icon,  - lc_maxauto - constv);
    ap1->length = BESZ_DWORD;
    return ap1;
}

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

AMODE *truncateFloat(AMODE *ap1, int size)
{
    do_extend(ap1, size, F_FREG);
    gen_codef(op_fmove, size, ap1, push);
    gen_codef(op_fmove, size, pop, ap1);
    return ap1;
}

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

int chksize(int lsize, int rsize)
{
    int l, r;
    l = lsize;
    r = rsize;
    if (l < 0)
        l =  - l;
    if (r < 0)
        r =  - r;
    if (rsize == 5)
     /* 5 is used for bools, which are the smallest type now */
        if (lsize == 5)
            return FALSE;
        else
            return TRUE;
    if (lsize == 5)
        return FALSE;
    return (l > r);
}

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

AMODE *make_label(int lab)
/*
 *      construct a reference node for an internal label number.
 */
{
    ENODE *lnode;
    AMODE *ap;
    lnode = xalloc(sizeof(ENODE));
    lnode->nodetype = en_labcon;
    lnode->v.i = lab;
    ap = xalloc(sizeof(AMODE));
    ap->mode = am_direct;
    ap->offset = lnode;
    return ap;
}

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

AMODE *makebf(ENODE *node, AMODE *ap1, int size)
/*
 *      construct a bit field reference for 68020 bit field instructions
 */
{
    AMODE *ap;
    if (node->startbit ==  - 1)
        DIAG("Illegal bit field");
    ap = xalloc(sizeof(AMODE));
    ap->mode = am_bf;
    ap->preg = node->startbit;
    ap->sreg = node->bits;
    switch (size)
    {
        case BESZ_BYTE:
            case  - BESZ_BYTE: ap->preg = 8-node->startbit - node->bits;
            break;
        case 2:
            case  - 2: ap->preg = 16-node->startbit - node->bits;
            break;
        case BESZ_DWORD:
            case  - BESZ_DWORD: ap->preg = 32-node->startbit - node->bits;
            break;
    }
    return ap;
}

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

AMODE *make_immed(long i)
/*
 *      make a node to reference an immediate value i.
 */
{
    AMODE *ap;
    ENODE *ep;
    ep = xalloc(sizeof(ENODE));
    ep->nodetype = en_icon;
    ep->v.i = i;
    ap = xalloc(sizeof(AMODE));
    ap->mode = am_immed;
    ap->offset = ep;
    return ap;
}

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

AMODE *make_immedt(long i, int size)
/*
 *      make a node to reference an immediate value i.
 */
{
    switch (size)
    {
        case BESZ_BYTE:
            case  - BESZ_BYTE: i &= 0xff;
            break;
        case 2:
            case  - 2: i &= 0xffff;
            break;
        case BESZ_DWORD:
            case  - BESZ_DWORD: i &= 0xffffffff;
            break;
    }
    return make_immed(i);
}

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

AMODE *make_offset(ENODE *node)
/*
 *      make a direct reference to a node.
 */
{
    AMODE *ap;
    ap = xalloc(sizeof(AMODE));
    ap->mode = am_direct;
    ap->offset = node;
    return ap;
}

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

AMODE *make_stack(int number)
{
    AMODE *ap = xalloc(sizeof(AMODE));
    ENODE *ep = xalloc(sizeof(ENODE));
    ep->nodetype = en_icon;
    ep->v.i =  - number;
    ap->mode = am_indx;
    ap->preg = 7;
    ap->offset = ep;
    return (ap);
}

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

void tofloat(AMODE *ap, int size)
{
    AMODE *ap2 = 0;
    int ss;
    if (ap->mode == am_freg)
        return ;
    if (size == 6 || size ==  - 6)
    {
        int pushed = FALSE;
        if (fregs[0])
        {
            pushed = TRUE;
            gen_codef(op_fmove, 10, makefreg(0), push);
        }
        ap2 = temp_float();
        if (ap->mode == am_doublereg)
        {
            gen_codes(op_move, BESZ_DWORD, makedreg(1), push);
            gen_codes(op_move, BESZ_DWORD, makedreg(0), push);
            gen_codes(op_move, BESZ_DWORD, makeareg(7), push);
            ss = 12;
        }
        else
        {
            AMODE *ap3 = direct_data(ap);
            if (ap3->mode == am_immed)
            {

⌨️ 快捷键说明

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