Skip to content

Commit

Permalink
cleanup C and C++ compilers code
Browse files Browse the repository at this point in the history
do more transparent definition of CPU and FPU related data, single consolitdated definition
use new message number for run-time libraries build
  • Loading branch information
jmalak committed Dec 16, 2023
1 parent 4c00f3d commit 5a6ce7e
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 199 deletions.
124 changes: 64 additions & 60 deletions bld/cc/c/coptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ static void SetCharacterEncoding( void )
CompFlags.use_double_byte = true;
SetDBChar( -1 ); /* set double-byte char type to default */
break;
default:
break;
}
}

Expand Down Expand Up @@ -400,16 +402,6 @@ static void SetFinalTargetSystem( void )
/* fall through */
case TS_NETWARE:
PreDefine_Macro( "__NETWARE_386__" );
/*
* If using NetWare, set Stack87 unless the target
* is NetWare 5 or higher.
*/
if( TargetSystem == TS_NETWARE ) {
Stack87 = 4;
}
if( SwData.mem == SW_M_DEF ) {
SwData.mem = SW_MS;
}
/*
* NETWARE uses stack based calling conventions
* by default - silly people.
Expand Down Expand Up @@ -473,25 +465,25 @@ static void SetGenSwitches( void )
/*
* setup CPU, if not specified then use default CPU
*/
if( SwData.cpu == SW_CPU_DEF ) {
#if _CPU == 8086
if( SwData.cpu == SW_CPU_DEF )
SwData.cpu = SW_CPU0;
#else
if( SwData.cpu == SW_CPU_DEF )
SwData.cpu = SW_CPU6;
#endif
}
SET_CPU( ProcRevision, SwData.cpu - SW_CPU0 + CPU_86 );

/*
* setup FPU, if not specified then use default FPU
*/
if( SwData.fpu == SW_FPU_DEF ) {
#if _CPU == 8086
if( SwData.fpu == SW_FPU_DEF )
SwData.fpu = SW_FPU0;
#else
if( SwData.fpu == SW_FPU_DEF )
SwData.fpu = SW_FPU3;
#endif
}
switch( SwData.fpu ) {
case SW_FPU0:
SET_FPU_LEVEL( ProcRevision, FPU_87 );
Expand All @@ -512,34 +504,48 @@ static void SetGenSwitches( void )
case SW_FPT_DEF:
case SW_FPT_EMU:
#if _CPU == 386
if( TargetSystem == TS_WINDOWS ) {
SwData.fpt = SW_FPT_INLINE;
SET_FPU_INLINE( ProcRevision );
if( TargetSystem != TS_WINDOWS ) {
#endif
SET_FPU_EMU( ProcRevision );
break;
#if _CPU == 386
}
/* fall through */
#endif
SwData.fpt = SW_FPT_EMU;
SET_FPU_EMU( ProcRevision );
break;
case SW_FPT_INLINE:
SET_FPU_INLINE( ProcRevision );
break;
case SW_FPT_CALLS:
SET_FPU( ProcRevision, FPU_NONE );
SET_FPU_FPC( ProcRevision );
CompFlags.op_switch_used = false;
break;
}
/*
* If using NetWare, set Stack87 unless the target
* is NetWare 5 or higher.
*/
if( TargetSystem == TS_NETWARE ) {
Stack87 = 4;
}

#if _CPU == 386
TargetSwitches |= CGSW_X86_USE_32;
#endif

/*
* setup memory model, if not specified then use default model
*/
if( SwData.mem == SW_M_DEF ) {
#if _CPU == 8086
if( SwData.mem == SW_M_DEF )
SwData.mem = SW_MS;
#else
if( SwData.mem == SW_M_DEF )
SwData.mem = SW_MF;
TargetSwitches |= CGSW_X86_USE_32;
if( TargetSystem == TS_NETWARE ) {
SwData.mem = SW_MS;
} else {
SwData.mem = SW_MF;
}
#endif
}
switch( SwData.mem ) {
case SW_MF:
TargetSwitches |= CGSW_X86_FLAT_MODEL | CGSW_X86_CHEAP_POINTER;
Expand Down Expand Up @@ -575,6 +581,10 @@ static void SetGenSwitches( void )
if( !SwData.peg_gs_on )
TargetSwitches |= CGSW_X86_FLOATING_GS;
#endif

/*
* DWARF is the default
*/
switch( SwData.dbg_fmt ) {
case SW_DF_WATCOM:
/*
Expand All @@ -585,9 +595,6 @@ static void SetGenSwitches( void )
GenSwitches |= CGSW_GEN_DBG_CV;
break;
case SW_DF_DEF:
/*
* DWARF is the default
*/
case SW_DF_DWARF:
GenSwitches |= CGSW_GEN_DBG_DF;
break;
Expand All @@ -599,11 +606,13 @@ static void SetGenSwitches( void )
GenSwitches |= CGSW_GEN_DBG_DF | CGSW_GEN_DBG_PREDEF;
SymDFAbbr = SpcSymbol( "__DFABBREV", GetType( TYP_USHORT ), SC_NONE );
break;
default:
break;
}
}

#if _INTEL_CPU
static void PreDefine_UMIX86Macro( void )
static void PreDefine_UMIX86_Macro( void )
{
unsigned cpu;
char buff[32];
Expand Down Expand Up @@ -839,7 +848,7 @@ static void MacroDefs( void )
DefSwitchMacro( "EC" );
}
#if _INTEL_CPU
PreDefine_UMIX86Macro();
PreDefine_UMIX86_Macro();
switch( GET_CPU( ProcRevision ) ) {
case CPU_86:
DefSwitchMacro( "0" );
Expand All @@ -862,26 +871,10 @@ static void MacroDefs( void )
case CPU_686:
DefSwitchMacro( "6" );
break;
}
switch( SwData.fpt ) {
case SW_FPT_CALLS:
CompFlags.op_switch_used = false;
DefSwitchMacro( "FPC" );
break;
case SW_FPT_EMU:
DefSwitchMacro( "FPI" );
Define_Macro( "__FPI__" );
break;
case SW_FPT_INLINE:
DefSwitchMacro( "FPI87" );
Define_Macro( "__FPI__" );
break;
default:
break;
}
switch( GET_FPU_LEVEL( ProcRevision ) ) {
case FPU_NONE:
break;
case FPU_87:
DefSwitchMacro( "FP2" );
break;
Expand All @@ -894,7 +887,20 @@ static void MacroDefs( void )
case FPU_686:
DefSwitchMacro( "FP6" );
break;
default:
break;
}
if( GET_FPU_FPC( ProcRevision ) ) {
DefSwitchMacro( "FPC" );
} else {
if( GET_FPU_EMU( ProcRevision ) ) {
DefSwitchMacro( "FPI" );
} else {
DefSwitchMacro( "FPI87" );
}
Define_Macro( "__FPI__" );
}

if( SwData.nd_used ) {
DefSwitchMacro( "ND" );
}
Expand Down Expand Up @@ -2301,15 +2307,16 @@ static void Define_Memory_Model( void )
strcpy( CLIB_Name, "1clibdl?" );
}
}
if( GET_FPU_EMU( ProcRevision ) ) {
strcpy( MATHLIB_Name, "7math87?" );
EmuLib_Name = "8emu87";
} else if( GET_FPU_LEVEL( ProcRevision ) == FPU_NONE ) {
if( GET_FPU_FPC( ProcRevision ) ) {
strcpy( MATHLIB_Name, "5math?" );
EmuLib_Name = NULL;
} else {
strcpy( MATHLIB_Name, "7math87?" );
EmuLib_Name = "8noemu87";
if( GET_FPU_EMU( ProcRevision ) ) {
EmuLib_Name = "8emu87";
} else {
EmuLib_Name = "8noemu87";
}
}
*strchr( CLIB_Name, '?' ) = lib_model;
*strchr( MATHLIB_Name, '?' ) = lib_model;
Expand All @@ -2322,14 +2329,7 @@ static void Define_Memory_Model( void )
} else {
strcpy( CLIB_Name, "1clib3?" ); /* There is only 1 CLIB now! */
}
if( GET_FPU_EMU( ProcRevision ) ) {
if( CompFlags.br_switch_used ) {
strcpy( MATHLIB_Name, "7mt7?dll" );
} else {
strcpy( MATHLIB_Name, "7math387?" );
}
EmuLib_Name = "8emu387";
} else if( GET_FPU_LEVEL( ProcRevision ) == FPU_NONE ) {
if( GET_FPU_FPC( ProcRevision ) ) {
if( CompFlags.br_switch_used ) {
strcpy( MATHLIB_Name, "5mth?dll" );
} else {
Expand All @@ -2342,7 +2342,11 @@ static void Define_Memory_Model( void )
} else {
strcpy( MATHLIB_Name, "7math387?" );
}
EmuLib_Name = "8noemu387";
if( GET_FPU_EMU( ProcRevision ) ) {
EmuLib_Name = "8emu387";
} else {
EmuLib_Name = "8noemu387";
}
}
*strchr( CLIB_Name, '?' ) = lib_model;
*strchr( MATHLIB_Name, '?' ) = lib_model;
Expand Down
4 changes: 3 additions & 1 deletion bld/cc/gml/options.gml
Original file line number Diff line number Diff line change
Expand Up @@ -1328,12 +1328,14 @@
:jusage. 無メッセージモードで動作します(エラーメッセージのみ表示されます)

:option. zro
:target. any
:target. i86 386
:enumerate. fp_rounding
:usage. omit floating point rounding calls (non ANSI)
:jusage.

:option. zri
:target. i86 386
:enumerate. fp_rounding
:usage. inline floating point rounding calls
:jusage.

Expand Down
4 changes: 3 additions & 1 deletion bld/cg/intel/h/cgx86swi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved.
* Copyright (c) 2002-2023 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -84,5 +84,7 @@ typedef enum {
#define SET_FPU_LEVEL( r, v ) SET_FPU( r, (v) | ( GET_FPU( r ) & FPU_EMU ) )
#define SET_FPU_EMU( r ) SET_FPU( r, GET_FPU( r ) | FPU_EMU )
#define SET_FPU_INLINE( r ) SET_FPU( r, GET_FPU( r ) & ~FPU_EMU )
#define SET_FPU_FPC( r ) SET_FPU( r, FPU_NONE )

#define GET_FPU_EMU( r ) ( ( GET_FPU( r ) & FPU_EMU ) != FPU_NONE )
#define GET_FPU_FPC( r ) ( GET_FPU( r ) == FPU_NONE )
2 changes: 1 addition & 1 deletion bld/clib/flags.mif
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ clib_cpp_flags += $(clib_cpp_flags_$(system)) $(clib_cpp_flags_$(system)_$(proce
##########################
# C COMPILER SETINGS
######
sw_c_common = $(watcom_common_cflags)-we-j-za99-zl-x-xx-zam-wpx
sw_c_common = $(watcom_common_cflags)-we-j-zastd=c99-zl-x-xx-zam-wpx
!ifneq debug 0
!else
sw_c_common += -s
Expand Down
2 changes: 1 addition & 1 deletion bld/f77/f77lib/flags.mif
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ f77lib_cpp_flags += $(f77lib_cpp_$(system)) $(f77lib_cpp_$(system)_$(processor))
##########################
# C COMPILER SETINGS
######
sw_c_common = $(watcom_common_cflags)-j-za99-we-zl-x-xx-zam-wpx
sw_c_common = $(watcom_common_cflags)-j-zastd=c99-we-zl-x-xx-zam-wpx
!ifneq debug 0
!else
sw_c_common += -s
Expand Down
27 changes: 15 additions & 12 deletions bld/f77/wfc/c/fcgmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved.
* Copyright (c) 2002-2023 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -297,16 +297,6 @@ static void CGStart( void )
SET_CPU( cpu, CPU_686 );
}

// set floating-point model

SET_FPU( cpu, FPU_NONE ); // floating-point calls
if( CPUOpts & CPUOPT_FPI ) {
SET_FPU_EMU( cpu );
}
if( CPUOpts & CPUOPT_FPI87 ) {
SET_FPU_INLINE( cpu );
}

// Set Floating-point level

if( CPUOpts & CPUOPT_FP287 ) {
Expand All @@ -326,6 +316,19 @@ static void CGStart( void )
#endif
}

// set floating-point model

if( CPUOpts & (CPUOPT_FPI | CPUOPT_FPI87) ) {
if( CPUOpts & CPUOPT_FPI ) {
SET_FPU_EMU( cpu );
}
if( CPUOpts & CPUOPT_FPI87 ) {
SET_FPU_INLINE( cpu );
}
} else {
SET_FPU_FPC( cpu ); // floating-point calls
}

if( CPUOpts & CPUOPT_FPD ) {
cg_target_opts |= CGSW_X86_P5_DIVIDE_CHECK;
}
Expand Down Expand Up @@ -366,7 +369,7 @@ static void CGStart( void )
}
}
#if _INTEL_CPU
if( GET_FPU( cpu ) > FPU_NONE ) {
if( !GET_FPU_FPC( cpu ) ) {
CGFlags |= CG_FP_MODEL_80x87;
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions bld/mathlib/flags.mif
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
!ifneq debug 0
sw_c_common = $(watcom_common_cflags)-j-za99-we-x-xx-zam-oax-zl-wpx
sw_c_common = $(watcom_common_cflags)-j-zastd=c99-we-x-xx-zam-oax-zl-wpx
!else
sw_c_common = $(watcom_common_cflags)-j-za99-we-x-xx-zam-s-oax-zl-wpx
sw_c_common = $(watcom_common_cflags)-j-zastd=c99-we-x-xx-zam-s-oax-zl-wpx
!endif
!ifdef __UNIX__
sw_c_common += -fo=.obj
Expand Down
4 changes: 2 additions & 2 deletions bld/plusplus/c/cginfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ static const inline_funcs *InlineLookup( NAME name )
{
const inline_funcs *ifunc;

if( GET_FPU( CpuSwitches ) > FPU_NONE ) {
if( !GET_FPU_FPC( CpuSwitches ) ) {
ifunc = _8087_Functions;
while( ifunc->name ) {
if( strcmp( ifunc->name, NameStr( name ) ) == 0 )
Expand Down Expand Up @@ -1106,7 +1106,7 @@ static void addDefaultImports( void )
CgInfoAddImport( "__init_387_emulator" );
#endif
}
if( GET_FPU( CpuSwitches ) > FPU_NONE ) {
if( !GET_FPU_FPC( CpuSwitches ) ) {
if( Stack87 == 4 ) {
CgInfoAddImport( "__old_8087" );
} else {
Expand Down
Loading

0 comments on commit 5a6ce7e

Please sign in to comment.