wf77aux.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,750 行 · 第 1/4 页
C
1,750 行
/****************************************************************************
*
* 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: auxiliary information processing
*
****************************************************************************/
#include "ftnstd.h"
#include "global.h"
#include "fcgbls.h"
#include "wf77aux.h"
#include "errcod.h"
#include "cpopt.h"
#include "progsw.h"
#include "fio.h"
#include "sdfile.h"
#include "fmemmgr.h"
#include "ferror.h"
#include "inout.h"
#if _INTEL_CPU
#include "asminlin.h"
#elif ( _CPU == _AXP || _CPU == _PPC )
#include "asinline.h"
#else
#error Unknow Target
#endif
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
extern int KwLookUp(char **,int,char *,int,int);
extern int MkHexConst(char *,char *,int);
extern void Suicide(void);
extern char *SkipBlanks(char *);
extern int Spawn(void (*)(void));
extern aux_info *AuxLookupName(char *,int);
extern sym_id SymFind(char *,uint);
extern void FreeChain(void **);
static aux_info *CurrAux;
static char *TokStart;
static char *TokEnd;
static aux_info *AliasInfo;
static char SymName[MAX_SYMLEN];
static int SymLen;
#if ( _CPU == 8086 || _CPU == 386 )
static arr_info *ArrayInfo;
#endif
extern char *RegNames[];
extern hw_reg_set RegValue[];
extern byte MaxReg;
#if _CPU == 8086
extern hw_reg_set WinParms[];
#elif _CPU == 386
extern hw_reg_set StackParms[];
#endif
extern aux_info IFInfo;
extern aux_info IFCharInfo;
extern aux_info IFChar2Info;
extern aux_info IFVarInfo;
extern aux_info IFXInfo;
extern aux_info CoRtnInfo;
extern aux_info RtRtnInfo;
extern aux_info RtVarInfo;
extern aux_info RtStopInfo;
extern char MsHexConst[];
extern char MsPragCallBytes[];
extern char MsArray[];
#if _CPU == 8086
#define _FLIBM 5
#define _FLIB7M 6
#define _FLIBL 5
#define _FLIB7L 6
#define _CLIBM 5
#define _CLIBL 5
#define _MATHM 5
#define _MATH7M 7
#define _MATHL 5
#define _MATH7L 7
#define _EMU87 5
#define _NOEMU87 7
#define _WRESL 5
#define _WRESM 5
static char _flibm[] = { "flibm" };
static char _flib7m[] = { "flib7m" };
static char _flibl[] = { "flibl" };
static char _flib7l[] = { "flib7l" };
static char _clibm[] = { "clibm" };
static char _clibl[] = { "clibl" };
static char _mathm[] = { "mathm" };
static char _math7m[] = { "math87m" };
static char _mathl[] = { "mathl" };
static char _math7l[] = { "math87l" };
static char _emu87[] = { "emu87" };
static char _noemu87[] = { "noemu87" };
static char _wresl[] = { "wresl" };
static char _wresm[] = { "wresm" };
#elif _CPU == 386
#define _FLIB 4
#define _FLIB7 5
#define _FLIBS 5
#define _FLIB7S 6
#define _CLIB 6
#define _CLIBS 6
#define _MATH 6
#define _MATHS 6
#define _MATH7 8
#define _MATH7S 8
#define _EMU387 6
#define _NOEMU387 8
#define _WRESF 5
#define _WRESFS 6
static char _flib[] = { "flib" };
static char _flibs[] = { "flibs" };
static char _flib7[] = { "flib7" };
static char _flib7s[] = { "flib7s" };
static char _clib[] = { "clib3r" };
static char _clibs[] = { "clib3s" };
static char _math[] = { "math3r" };
static char _maths[] = { "math3s" };
static char _math7[] = { "math387r" };
static char _math7s[] = { "math387s" };
static char _emu387[] = { "emu387" };
static char _noemu387[] = { "noemu387" };
static char _wresf[] = { "wresf" };
static char _wresfs[] = { "wresfs" };
#elif _CPU == _AXP
#define _FLIB 4
#define _CLIB 4
#define _MATH 4
#define _WRESAXP 7
static char _flib[] = { "flib" };
static char _clib[] = { "clib" };
static char _math[] = { "math" };
static char _wresaxp[] = { "wresaxp" };
#elif _CPU == _PPC
#define _FLIB 4
#define _CLIB 4
#define _MATH 4
#define _WRESPPC 7
static char _flib[] = { "flib" };
static char _clib[] = { "clib" };
static char _math[] = { "math" };
static char _wresppc[] = { "wresppc" };
#else
#error Unknown Platform
#endif
#define MAX_REG_SETS 16
#define MAXIMUM_BYTESEQ 127
#if ( _CPU == 8086 || _CPU == 386 )
#elif _CPU == _AXP || _CPU == _PPC
#define AsmSymFini AsmFini
#else
#error Unknown Target
#endif
#if _CPU == 386
static char __Syscall[] = { "aux __syscall \"*\""
"parm caller []"
"value struct struct caller []"
"modify [eax ecx edx]" };
static char __Cdecl[] = { "aux __cdecl \"_*\""
"parm caller loadds []"
"value struct float struct routine [eax]"
"modify [eax ebx ecx edx]" };
static char __Pascal[] = { "aux __pascal \"^\""
"parm reverse routine []"
"value struct float struct caller []"
"modify [eax ebx ecx edx]" };
static char __Stdcall[] = { "aux __stdcall \"_*#\""
"parm routine []"
"value struct []"
"modify [eax ecx edx]" };
#elif _CPU == 8086
static char __Pascal[] = { "aux __pascal \"^\""
"parm routine reverse []"
"value struct float struct caller []"
"modify [ax bx cx dx]" };
static char __Cdecl[] = { "aux __cdecl \"_*\""
"parm caller []"
"value struct float struct routine [ax]"
"modify [ax bx cx dx]" };
#endif
extern aux_info DefaultInfo;
default_lib *DefaultLibs;
aux_info *AuxInfo;
aux_info FortranInfo;
aux_info ProgramInfo;
dep_info *DependencyInfo;
void InitAuxInfo( void ) {
//=============================
#if ( _CPU == 8086 || _CPU == 386 )
int cpu;
int fpu;
int use32;
#if _CPU == 8086
use32 = 0;
#elif _CPU == 386
use32 = 1;
#endif
cpu = 0;
fpu = 0;
#if _CPU == 8086
if( CPUOpts & CPUOPT_80186 ) cpu = 1;
if( CPUOpts & CPUOPT_80286 ) cpu = 2;
#endif
if( CPUOpts & CPUOPT_80386 ) cpu = 3;
if( CPUOpts & CPUOPT_80486 ) cpu = 4;
if( CPUOpts & CPUOPT_80586 ) cpu = 5;
if( CPUOpts & CPUOPT_80686 ) cpu = 6;
if( CPUOpts & ( CPUOPT_FPI87 | CPUOPT_FPI ) ) fpu = 1;
AsmInit( cpu, fpu, use32, 1 );
#elif _CPU == _AXP || _CPU == _PPC
AsmInit();
#else
#error Unknown Target
#endif
DefaultLibs = NULL;
AuxInfo = NULL;
DependencyInfo = NULL;
#if _CPU == 8086 || _CPU == 386
#if _CPU == 8086
// Change auxiliary information for calls to run-time routines to match
// the options used to compile the run-time routines
if( CGOpts & CGOPT_M_LARGE ) {
if( !(CGOpts & CGOPT_WINDOWS) ) {
HW_CTurnOff( IFXInfo.save, HW_DS );
HW_CTurnOff( RtRtnInfo.save, HW_DS );
HW_CTurnOff( RtStopInfo.save, HW_DS );
HW_CTurnOff( RtVarInfo.save, HW_DS );
HW_CTurnOff( CoRtnInfo.save, HW_DS );
HW_CTurnOff( IFInfo.save, HW_DS );
HW_CTurnOff( IFCharInfo.save, HW_DS );
HW_CTurnOff( IFChar2Info.save, HW_DS );
HW_CTurnOff( IFVarInfo.save, HW_DS );
}
}
HW_CTurnOff( IFXInfo.save, HW_ES );
HW_CTurnOff( RtRtnInfo.save, HW_ES );
HW_CTurnOff( RtStopInfo.save, HW_ES );
HW_CTurnOff( RtVarInfo.save, HW_ES );
HW_CTurnOff( CoRtnInfo.save, HW_ES );
HW_CTurnOff( IFInfo.save, HW_ES );
HW_CTurnOff( IFCharInfo.save, HW_ES );
HW_CTurnOff( IFChar2Info.save, HW_ES );
HW_CTurnOff( IFVarInfo.save, HW_ES );
#endif
if( !(CGOpts & CGOPT_SEG_REGS) ) {
if( _FloatingDS( CGOpts ) ) {
HW_CTurnOff( DefaultInfo.save, HW_DS );
}
if( _FloatingES( CGOpts ) ) {
HW_CTurnOff( DefaultInfo.save, HW_ES );
}
#if _CPU == 8086
if( CPUOpts & (CPUOPT_80386 | CPUOPT_80486 | CPUOPT_80586 | CPUOPT_80686) )
#endif
{
if( _FloatingFS( CGOpts ) ) {
HW_CTurnOff( DefaultInfo.save, HW_FS );
}
if( _FloatingGS( CGOpts ) ) {
HW_CTurnOff( DefaultInfo.save, HW_GS );
}
}
}
if( OZOpts & OZOPT_O_FRAME ) {
DefaultInfo.cclass |= GENERATE_STACK_FRAME;
}
#endif
#if _CPU == 386
if( CGOpts & CGOPT_STK_ARGS ) {
DefaultInfo.cclass |= CALLER_POPS | NO_8087_RETURNS;
DefaultInfo.parms = StackParms;
HW_CTurnOff( DefaultInfo.save, HW_EAX );
HW_CTurnOff( DefaultInfo.save, HW_EDX );
HW_CTurnOff( DefaultInfo.save, HW_ECX );
HW_CTurnOff( DefaultInfo.save, HW_FLTS );
IFXInfo.cclass |= CALLER_POPS | NO_8087_RETURNS;
IFXInfo.parms = StackParms;
HW_CTurnOff( IFXInfo.save, HW_FLTS );
HW_CTurnOff( RtRtnInfo.save, HW_FLTS );
HW_CTurnOff( RtStopInfo.save, HW_FLTS );
HW_CTurnOff( RtVarInfo.save, HW_FLTS );
HW_CTurnOff( CoRtnInfo.save, HW_FLTS );
HW_CTurnOff( IFInfo.save, HW_FLTS );
HW_CTurnOff( IFCharInfo.save, HW_FLTS );
HW_CTurnOff( IFChar2Info.save, HW_FLTS );
HW_CTurnOff( IFVarInfo.save, HW_FLTS );
}
#endif
#if _CPU == 8086
if( CGOpts & CGOPT_WINDOWS ) {
DefaultInfo.parms = WinParms;
IFXInfo.parms = WinParms;
}
#endif
FortranInfo = DefaultInfo;
ProgramInfo = DefaultInfo;
#if _CPU == 386
DoPragma( __Syscall );
DoPragma( __Stdcall );
#endif
#if _CPU == 8086 || _CPU == 386
DoPragma( __Pascal );
DoPragma( __Cdecl );
#endif
}
void FiniAuxInfo( void ) {
//=============================
void *next;
while( AuxInfo != NULL ) {
next = AuxInfo->link;
FreeAuxEntry( AuxInfo );
AuxInfo = next;
}
FreeAuxElements( &FortranInfo );
FreeChain( &DefaultLibs );
// in case of fatal error, FiniAuxInfo() is called
// from TDPurge()
#if ( _CPU == 8086 || _CPU == 386 )
FreeChain( &ArrayInfo );
#endif
FreeChain( &DependencyInfo );
AsmSymFini();
}
void SubAuxInit( void ) {
//====================
#if ( _CPU == 8086 || _CPU == 386 )
// Initialize aux information for a subprogram.
ArrayInfo = NULL;
#endif
}
void SubAuxFini( void ) {
//====================
#if ( _CPU == 8086 || _CPU == 386 )
// Finalize aux information for a subprogram.
arr_info *next;
sym_id arr;
while( ArrayInfo != NULL ) {
next = ArrayInfo->link;
arr = SymFind( ArrayInfo->arr, strlen( ArrayInfo->arr ) );
if( ( arr != NULL ) && ( arr->ns.flags & SY_SUBSCRIPTED ) &&
( arr->ns.typ != TY_CHAR ) &&
( ( arr->ns.flags & SY_SUB_PARM ) || _Allocatable( arr ) ) ) {
arr->ns.si.va.dim_ext->dim_flags |= DIM_EXTENDED;
}
FMemFree( ArrayInfo );
ArrayInfo = next;
}
#endif
}
#if ( _CPU == 8086 || _CPU == 386 )
static void AddArrayInfo( char *arr_name, uint arr_len ) {
//============================================================
// Process aux information for an array.
arr_info **arr;
arr_info *new_arr;
for( arr = &ArrayInfo; *arr != NULL; arr = &(*arr)->link ) {
if( strlen( &(*arr)->arr ) != arr_len )
continue;
if( memcmp( &(*arr)->arr, arr_name, arr_len ) == 0 ) {
return;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?