usfold.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 779 行 · 第 1/2 页
C
779 行
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Constant folding routines.
*
****************************************************************************/
#include "ftnstd.h"
#include "optr.h"
#include "errcod.h"
#include "global.h"
#include "rtenv.h"
#include "ferror.h"
extern void (* const __FAR GenOprTable[])(TYPE, TYPE, OPTR);
extern void AddConst(itnode *);
extern int LexStrCmp(char PGM *,int,char PGM *,int);
extern bool AddIOFlo(intstar4 *,intstar4 *);
extern bool SubIOFlo(intstar4 *,intstar4 *);
extern bool MulIOFlo(intstar4 *,intstar4 *);
extern void ExpOp(TYPE,TYPE,OPTR);
static void MulIOFlow ( ftn_type *arg1, ftn_type *arg2 ) {
//===========================================================
MulIOFlo(&arg1->intstar4, &arg2->intstar4);
}
//--------------------------------------------- integer arithmetic
void AddI( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
if( AddIOFlo( &opnd1->intstar4, &opnd2->intstar4 ) ) {
Warning( KO_IOVERFLOW );
}
// opnd1->intstar4 = opnd1->intstar4 + opnd2->intstar4;
}
void SubI( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
if( SubIOFlo( &opnd1->intstar4, &opnd2->intstar4 ) ) {
Warning( KO_IOVERFLOW );
}
// opnd1->intstar4 = opnd1->intstar4 - opnd2->intstar4;
}
void MulI( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
if( MulIOFlo( &opnd1->intstar4, &opnd2->intstar4 ) ) {
Warning( KO_IOVERFLOW );
}
// opnd1->intstar4 = opnd1->intstar4 * opnd2->intstar4;
}
void DivI( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
if( opnd2->intstar4 != 0 ) {
opnd1->intstar4 /= opnd2->intstar4;
} else {
Warning( KO_IDIV_ZERO );
}
}
//--------------------------------------------- real arithmetic
void AddR( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->single = opnd1->single + opnd2->single;
}
void SubR( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->single = opnd1->single - opnd2->single;
}
void MulR( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->single = opnd1->single * opnd2->single;
}
void DivR( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->single = opnd1->single / opnd2->single;
}
//------------------------------------------- double arithmetic
void AddD( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->dble = opnd1->dble + opnd2->dble;
}
void SubD( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->dble = opnd1->dble - opnd2->dble;
}
void MulD( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->dble = opnd1->dble * opnd2->dble;
}
void DivD( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->dble = opnd1->dble / opnd2->dble;
}
//------------------------------------------- Extended arithmetic
void AddE( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->extended = opnd1->extended + opnd2->extended;
}
void SubE( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->extended = opnd1->extended - opnd2->extended;
}
void MulE( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->extended = opnd1->extended * opnd2->extended;
}
void DivE( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->extended = opnd1->extended / opnd2->extended;
}
//-------------------------------------------- complex arithmetic
void AddC( complex *x, complex *y ) {
//======================================
complex result;
result.realpart = x->realpart + y->realpart;
result.imagpart = x->imagpart + y->imagpart;
*x = result;
}
void SubC( complex *x, complex *y ) {
//======================================
complex result;
result.realpart = x->realpart - y->realpart;
result.imagpart = x->imagpart - y->imagpart;
*x = result;
}
void MulC( ftn_type *_x, ftn_type *_y ) {
//======================================
complex result;
complex *x = &_x->complex;
complex *y = &_y->complex;
result.realpart = x->realpart * y->realpart - x->imagpart * y->imagpart;
result.imagpart = x->realpart * y->imagpart + x->imagpart * y->realpart;
*x = result;
}
void DivC( ftn_type *_x, ftn_type *_y ) {
//======================================
single bottom;
complex result;
complex *x = &_x->complex;
complex *y = &_y->complex;
bottom = y->realpart * y->realpart + y->imagpart * y->imagpart;
result.realpart = x->realpart * y->realpart + x->imagpart * y->imagpart;
result.imagpart = x->imagpart * y->realpart - x->realpart * y->imagpart;
result.realpart /= bottom;
result.imagpart /= bottom;
*x = result;
}
//------------------------------------------- dcomplex arithmetic
void AddQ( dcomplex *x, dcomplex *y ) {
//========================================
dcomplex result;
result.realpart = x->realpart + y->realpart;
result.imagpart = x->imagpart + y->imagpart;
*x = result;
}
void SubQ( dcomplex *x, dcomplex *y ) {
//========================================
dcomplex result;
result.realpart = x->realpart - y->realpart;
result.imagpart = x->imagpart - y->imagpart;
*x = result;
}
void MulQ( ftn_type *_x, ftn_type *_y ) {
//========================================
dcomplex result;
dcomplex *x = &_x->dcomplex;
dcomplex *y = &_y->dcomplex;
result.realpart = x->realpart * y->realpart - x->imagpart * y->imagpart;
result.imagpart = x->realpart * y->imagpart + x->imagpart * y->realpart;
*x = result;
}
void DivQ( ftn_type *_x, ftn_type *_y ) {
//========================================
single bottom;
dcomplex result;
dcomplex *x = &_x->dcomplex;
dcomplex *y = &_y->dcomplex;
bottom = y->realpart * y->realpart + y->imagpart * y->imagpart;
result.realpart = x->realpart * y->realpart + x->imagpart * y->imagpart;
result.imagpart = x->imagpart * y->realpart - x->realpart * y->imagpart;
result.realpart /= bottom;
result.imagpart /= bottom;
*x = result;
}
//------------------------------------------- xcomplex arithmetic
void AddX( xcomplex *x, xcomplex *y ) {
//========================================
xcomplex result;
result.realpart = x->realpart + y->realpart;
result.imagpart = x->imagpart + y->imagpart;
*x = result;
}
void SubX( xcomplex *x, xcomplex *y ) {
//========================================
xcomplex result;
result.realpart = x->realpart - y->realpart;
result.imagpart = x->imagpart - y->imagpart;
*x = result;
}
void MulX( ftn_type *_x, ftn_type *_y ) {
//========================================
xcomplex result;
xcomplex *x = &_x->xcomplex;
xcomplex *y = &_y->xcomplex;
result.realpart = x->realpart * y->realpart - x->imagpart * y->imagpart;
result.imagpart = x->realpart * y->imagpart + x->imagpart * y->realpart;
*x = result;
}
void DivX( ftn_type *_x, ftn_type *_y ) {
//========================================
single bottom;
xcomplex result;
xcomplex *x = &_x->xcomplex;
xcomplex *y = &_y->xcomplex;
bottom = y->realpart * y->realpart + y->imagpart * y->imagpart;
result.realpart = x->realpart * y->realpart + x->imagpart * y->imagpart;
result.imagpart = x->imagpart * y->realpart - x->realpart * y->imagpart;
result.realpart /= bottom;
result.imagpart /= bottom;
*x = result;
}
//------------------------------------------- unary plus/minus
void XINeg( ftn_type *opnd1, ftn_type *opnd2 ) {
//=================================================
opnd1->intstar4 = -opnd2->intstar4;
}
void XRNeg( ftn_type *opnd1, ftn_type *opnd2 ) {
//=================================================
opnd1->single = -opnd2->single;
}
void XDNeg( ftn_type *opnd1, ftn_type *opnd2 ) {
//=================================================
opnd1->dble = -opnd2->dble;
}
void XENeg( ftn_type *opnd1, ftn_type *opnd2 ) {
//=================================================
opnd1->extended = -opnd2->extended;
}
void XCNeg( ftn_type *opnd1, ftn_type *opnd2 ) {
//=================================================
opnd1->complex.realpart = -opnd2->complex.realpart;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?