/* Expand the basic unary and binary arithmetic operations, for GNU compiler.
- Copyright (C) 1987-1991 Free Software Foundation, Inc.
+ Copyright (C) 1987, 1988, 1992 Free Software Foundation, Inc.
This file is part of GNU CC.
{
enum mode_class class;
enum machine_mode wider_mode;
- enum machine_mode submode = mode_for_size (BITS_PER_WORD, MODE_INT, 0);
register rtx temp;
int commutative_op = 0;
int shift_op = (binoptab->code == ASHIFT
op0 = force_reg (mode, op0);
if (CONSTANT_P (op1) && preserve_subexpressions_p () && rtx_cost (op1) > 2)
- op1 = force_reg ((shift_op
- ? mode_for_size (BITS_PER_WORD, MODE_INT, 0)
- : mode),
- op1);
+ op1 = force_reg (shift_op ? word_mode : mode, op1);
#if 0 /* Turned off because it seems to be a kludgy method. */
/* If subtracting integer from pointer, and the pointer has a special mode,
if ((binoptab == and_optab || binoptab == ior_optab || binoptab == xor_optab)
&& class == MODE_INT
&& GET_MODE_SIZE (mode) > UNITS_PER_WORD
- && binoptab->handlers[(int) submode].insn_code != CODE_FOR_nothing)
+ && binoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
{
int i;
rtx insns;
for (i = 0; i < GET_MODE_BITSIZE (mode) / BITS_PER_WORD; i++)
{
rtx target_piece = operand_subword (target, i, 1, mode);
- rtx x = expand_binop (submode, binoptab,
+ rtx x = expand_binop (word_mode, binoptab,
operand_subword_force (op0, i, mode),
operand_subword_force (op1, i, mode),
target_piece, unsignedp, methods);
if ((binoptab == add_optab || binoptab == sub_optab)
&& class == MODE_INT
&& GET_MODE_SIZE (mode) >= 2 * UNITS_PER_WORD
- && binoptab->handlers[(int) submode].insn_code != CODE_FOR_nothing)
+ && binoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
{
int i;
- rtx carry_tmp = gen_reg_rtx (submode);
+ rtx carry_tmp = gen_reg_rtx (word_mode);
optab otheroptab = binoptab == add_optab ? sub_optab : add_optab;
int nwords = GET_MODE_BITSIZE (mode) / BITS_PER_WORD;
rtx carry_in, carry_out;
rtx x;
/* Main add/subtract of the input operands. */
- x = expand_binop (submode, binoptab,
+ x = expand_binop (word_mode, binoptab,
op0_piece, op1_piece,
target_piece, unsignedp, methods);
if (x == 0)
if (i + 1 < nwords)
{
/* Store carry from main add/subtract. */
- carry_out = gen_reg_rtx (submode);
+ carry_out = gen_reg_rtx (word_mode);
carry_out = emit_store_flag (carry_out,
binoptab == add_optab ? LTU : GTU,
x, op0_piece,
- submode, 1, normalizep);
+ word_mode, 1, normalizep);
if (!carry_out)
break;
}
if (i > 0)
{
/* Add/subtract previous carry to main result. */
- x = expand_binop (submode,
+ x = expand_binop (word_mode,
normalizep == 1 ? binoptab : otheroptab,
x, carry_in,
target_piece, 1, methods);
binoptab == add_optab
? LTU : GTU,
x, carry_in,
- submode, 1, normalizep);
+ word_mode, 1, normalizep);
/* Logical-ior the two poss. carry together. */
- carry_out = expand_binop (submode, ior_optab,
+ carry_out = expand_binop (word_mode, ior_optab,
carry_out, carry_tmp,
carry_out, 0, methods);
if (!carry_out)
because we are not operating on one word at a time.
The multiplication proceeds as follows:
- _______________________
- [__op0_high_|__op0_low__]
- _______________________
- * [__op1_high_|__op1_low__]
- _______________________________________________
- _______________________
-(1) [__op0_low__*__op1_low__]
- _______________________
-(2a) [__op0_low__*__op1_high_]
- _______________________
-(2b) [__op0_high_*__op1_low__]
- _______________________
-(3) [__op0_high_*__op1_high_]
+ _______________________
+ [__op0_high_|__op0_low__]
+ _______________________
+ * [__op1_high_|__op1_low__]
+ _______________________________________________
+ _______________________
+ (1) [__op0_low__*__op1_low__]
+ _______________________
+ (2a) [__op0_low__*__op1_high_]
+ _______________________
+ (2b) [__op0_high_*__op1_low__]
+ _______________________
+ (3) [__op0_high_*__op1_high_]
This gives a 4-word result. Since we are only interested in the
if (binoptab == smul_optab
&& class == MODE_INT
&& GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
- && smul_optab->handlers[(int) submode].insn_code != CODE_FOR_nothing
- && add_optab->handlers[(int) submode].insn_code != CODE_FOR_nothing
+ && smul_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
+ && add_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
&& ((umul_widen_optab->handlers[(int) mode].insn_code
!= CODE_FOR_nothing)
|| (smul_widen_optab->handlers[(int) mode].insn_code
rtx wordm1 = gen_rtx (CONST_INT, VOIDmode, BITS_PER_WORD - 1);
product = expand_binop (mode, smul_widen_optab, op0_low, op1_low,
target, 1, OPTAB_DIRECT);
- op0_xhigh = expand_binop (submode, lshr_optab, op0_low, wordm1,
+ op0_xhigh = expand_binop (word_mode, lshr_optab, op0_low, wordm1,
0, 1, OPTAB_DIRECT);
if (op0_xhigh)
- op0_xhigh = expand_binop (submode, add_optab, op0_high, op0_xhigh,
- op0_xhigh, 0, OPTAB_DIRECT);
+ op0_xhigh = expand_binop (word_mode, add_optab, op0_high,
+ op0_xhigh, op0_xhigh, 0, OPTAB_DIRECT);
else
{
- op0_xhigh = expand_binop (submode, ashr_optab, op0_low, wordm1,
+ op0_xhigh = expand_binop (word_mode, ashr_optab, op0_low, wordm1,
0, 0, OPTAB_DIRECT);
if (op0_xhigh)
- op0_xhigh = expand_binop (submode, sub_optab, op0_high,
+ op0_xhigh = expand_binop (word_mode, sub_optab, op0_high,
op0_xhigh, op0_xhigh, 0,
OPTAB_DIRECT);
}
- op1_xhigh = expand_binop (submode, lshr_optab, op1_low, wordm1,
+ op1_xhigh = expand_binop (word_mode, lshr_optab, op1_low, wordm1,
0, 1, OPTAB_DIRECT);
if (op1_xhigh)
- op1_xhigh = expand_binop (SImode, add_optab, op1_high, op1_xhigh,
- op1_xhigh, 0, OPTAB_DIRECT);
+ op1_xhigh = expand_binop (word_mode, add_optab, op1_high,
+ op1_xhigh, op1_xhigh, 0, OPTAB_DIRECT);
else
{
- op1_xhigh = expand_binop (submode, ashr_optab, op1_low, wordm1,
+ op1_xhigh = expand_binop (word_mode, ashr_optab, op1_low, wordm1,
0, 0, OPTAB_DIRECT);
if (op1_xhigh)
- op1_xhigh = expand_binop (SImode, sub_optab, op1_high,
+ op1_xhigh = expand_binop (word_mode, sub_optab, op1_high,
op1_xhigh, op1_xhigh, 0,
OPTAB_DIRECT);
}
{
rtx product_piece;
rtx product_high = operand_subword (product, high, 1, mode);
- rtx temp = expand_binop (submode, binoptab, op0_low, op1_xhigh, 0,
+ rtx temp = expand_binop (word_mode, binoptab, op0_low, op1_xhigh, 0,
0, OPTAB_DIRECT);
if (temp)
{
- product_piece = expand_binop (submode, add_optab, temp,
+ product_piece = expand_binop (word_mode, add_optab, temp,
product_high, product_high,
0, OPTAB_LIB_WIDEN);
if (product_piece != product_high)
emit_move_insn (product_high, product_piece);
- temp = expand_binop (submode, binoptab, op1_low, op0_xhigh, 0,
+ temp = expand_binop (word_mode, binoptab, op1_low, op0_xhigh, 0,
0, OPTAB_DIRECT);
- product_piece = expand_binop (submode, add_optab, temp,
+ product_piece = expand_binop (word_mode, add_optab, temp,
product_high, product_high,
0, OPTAB_LIB_WIDEN);
if (product_piece != product_high)
if the libcall is cse'd or moved. */
emit_library_call (binoptab->handlers[(int) mode].libfunc,
1, mode, 2, op0, mode, op1,
- (shift_op
- ? mode_for_size (BITS_PER_WORD, MODE_INT, 0)
- : mode));
+ (shift_op ? word_mode : mode));
insns = get_insns ();
end_sequence ();
methods = (methods == OPTAB_LIB_WIDEN ? OPTAB_LIB : OPTAB_DIRECT);
- /* Widening is now independent of specific machine modes.
- It is assumed that widening may be performed to any
- higher numbered mode in the same mode class. */
+ /* Look for a wider mode of the same class for which it appears we can do
+ the operation. */
if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
{
- for (wider_mode = GET_MODE_WIDER_MODE (mode);
- ((int) wider_mode < (int) MAX_MACHINE_MODE
- && GET_MODE_CLASS (wider_mode) == class);
+ for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
wider_mode = GET_MODE_WIDER_MODE (wider_mode))
{
if ((binoptab->handlers[(int) wider_mode].insn_code
rtx xop0 = op0, xop1 = op1;
int no_extend = 0;
- /* For certain operations, we need not actually extend
+ /* For certain integer operations, we need not actually extend
the narrow operands, as long as we will truncate
the results to the same narrowness. */
- if (binoptab == ior_optab || binoptab == and_optab
- || binoptab == xor_optab
- || binoptab == add_optab || binoptab == sub_optab
- || binoptab == smul_optab
- || binoptab == ashl_optab || binoptab == lshl_optab)
+ if ((binoptab == ior_optab || binoptab == and_optab
+ || binoptab == xor_optab
+ || binoptab == add_optab || binoptab == sub_optab
+ || binoptab == smul_optab
+ || binoptab == ashl_optab || binoptab == lshl_optab)
+ && class == MODE_INT)
no_extend = 1;
- if (GET_MODE (xop0) != VOIDmode
- && GET_MODE_BITSIZE (wider_mode) <= HOST_BITS_PER_INT)
- {
- if (no_extend)
- {
- temp = force_reg (GET_MODE (xop0), xop0);
- xop0 = gen_rtx (SUBREG, wider_mode, temp, 0);
- }
- else
- {
- temp = gen_reg_rtx (wider_mode);
- convert_move (temp, xop0, unsignedp);
- xop0 = temp;
- }
- }
- if (GET_MODE (xop1) != VOIDmode
- && GET_MODE_BITSIZE (wider_mode) <= HOST_BITS_PER_INT)
- {
- if (no_extend)
- {
- temp = force_reg (GET_MODE (xop1), xop1);
- xop1 = gen_rtx (SUBREG, wider_mode, temp, 0);
- }
- else
- {
- temp = gen_reg_rtx (wider_mode);
- convert_move (temp, xop1, unsignedp);
- xop1 = temp;
- }
- }
+ /* If an operand is a constant integer, we might as well
+ convert it since that is more efficient than using a SUBREG,
+ unlike the case for other operands. */
+
+ if (no_extend && GET_MODE (xop0) != VOIDmode)
+ xop0 = gen_rtx (SUBREG, wider_mode,
+ force_reg (GET_MODE (xop0), xop0), 0);
+ else
+ xop0 = convert_to_mode (wider_mode, xop0, unsignedp);
+
+ if (no_extend && GET_MODE (xop1) != VOIDmode)
+ xop1 = gen_rtx (SUBREG, wider_mode,
+ force_reg (GET_MODE (xop1), xop1), 0);
+ else
+ xop1 = convert_to_mode (wider_mode, xop1, unsignedp);
temp = expand_binop (wider_mode, binoptab, xop0, xop1, 0,
unsignedp, methods);
if (temp)
{
- if (class == MODE_FLOAT)
+ if (class != MODE_INT)
{
if (target == 0)
target = gen_reg_rtx (mode);
if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
{
- for (wider_mode = GET_MODE_WIDER_MODE (mode);
- GET_MODE_CLASS (wider_mode) == class;
+ for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
wider_mode = GET_MODE_WIDER_MODE (wider_mode))
{
if (binoptab->handlers[(int) wider_mode].insn_code
{
enum mode_class class;
enum machine_mode wider_mode;
- enum machine_mode submode = mode_for_size (BITS_PER_WORD, MODE_INT, 0);
register rtx temp;
rtx last = get_last_insn ();
rtx pat;
if (unoptab == one_cmpl_optab
&& class == MODE_INT
&& GET_MODE_SIZE (mode) > UNITS_PER_WORD
- && unoptab->handlers[(int) submode].insn_code != CODE_FOR_nothing)
+ && unoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
{
int i;
rtx insns;
for (i = 0; i < GET_MODE_BITSIZE (mode) / BITS_PER_WORD; i++)
{
rtx target_piece = operand_subword (target, i, 1, mode);
- rtx x = expand_unop (submode, unoptab,
+ rtx x = expand_unop (word_mode, unoptab,
operand_subword_force (op0, i, mode),
target_piece, unsignedp);
if (target_piece != x)
if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
{
- for (wider_mode = GET_MODE_WIDER_MODE (mode);
- GET_MODE_CLASS (wider_mode) == class;
+ for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
wider_mode = GET_MODE_WIDER_MODE (wider_mode))
{
if ((unoptab->handlers[(int) wider_mode].insn_code
!= CODE_FOR_nothing)
|| unoptab->handlers[(int) wider_mode].libfunc)
{
- if (GET_MODE (op0) != VOIDmode
- && GET_MODE_BITSIZE (wider_mode) <= HOST_BITS_PER_INT)
- {
- temp = gen_reg_rtx (wider_mode);
- convert_move (temp, op0, unsignedp);
- op0 = temp;
- }
+ rtx xop0 = op0;
+
+ /* For certain operations, we need not actually extend
+ the narrow operand, as long as we will truncate the
+ results to the same narrowness. */
+
+ if ((unoptab == neg_optab || unoptab == one_cmpl_optab)
+ && class == MODE_INT)
+ xop0 = gen_rtx (SUBREG, wider_mode, force_reg (mode, xop0), 0);
+ else
+ xop0 = convert_to_mode (wider_mode, xop0, unsignedp);
- target = expand_unop (wider_mode, unoptab, op0, 0, unsignedp);
- if (class == MODE_FLOAT)
+ temp = expand_unop (wider_mode, unoptab, xop0, 0, unsignedp);
+
+ if (temp)
{
- if (target == 0)
- target = gen_reg_rtx (mode);
- convert_move (target, temp, 0);
- return target;
+ if (class != MODE_INT)
+ {
+ if (target == 0)
+ target = gen_reg_rtx (mode);
+ convert_move (target, temp, 0);
+ return target;
+ }
+ else
+ return gen_lowpart (mode, temp);
}
else
- return gen_lowpart (mode, target);
+ delete_insns_since (last);
}
}
}
if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
{
- for (wider_mode = GET_MODE_WIDER_MODE (mode);
- GET_MODE_CLASS (wider_mode) == class;
+ for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
wider_mode = GET_MODE_WIDER_MODE (wider_mode))
{
if (cmp_optab->handlers[(int) wider_mode].insn_code
{
enum machine_mode wider_mode;
- for (wider_mode = GET_MODE_WIDER_MODE (mode);
- GET_MODE_CLASS (wider_mode) == MODE_FLOAT;
+ for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
wider_mode = GET_MODE_WIDER_MODE (wider_mode))
{
if ((cmp_optab->handlers[(int) wider_mode].insn_code
}
\f
/* Tables of patterns for extending one integer mode to another. */
-static enum insn_code zero_extend_codes[MAX_MACHINE_MODE][MAX_MACHINE_MODE];
-static enum insn_code sign_extend_codes[MAX_MACHINE_MODE][MAX_MACHINE_MODE];
+static enum insn_code extendtab[MAX_MACHINE_MODE][MAX_MACHINE_MODE][2];
-/* Return nonzero if it's possible to extend FROM_MODE to TO_MODE.
- UNSIGNEDP specifies zero-extension instead of sign-extension.
+/* Return the insn code used to extend FROM_MODE to TO_MODE.
+ UNSIGNEDP specifies zero-extension instead of sign-extension. If
+ no such operation exists, CODE_FOR_nothing will be returned. */
- Actually, the value is the instruction code for the extension pattern. */
-
-int
+enum insn_code
can_extend_p (to_mode, from_mode, unsignedp)
enum machine_mode to_mode, from_mode;
int unsignedp;
{
- return ((unsignedp ? zero_extend_codes : sign_extend_codes)
- [(int) to_mode][(int) from_mode]);
+ return extendtab[(int) to_mode][(int) from_mode][unsignedp];
}
/* Generate the body of an insn to extend Y (with mode MFROM)
enum machine_mode mto, mfrom;
int unsignedp;
{
- return (GEN_FCN ((unsignedp ? zero_extend_codes : sign_extend_codes)
- [(int)mto][(int)mfrom])
- (x, y));
+ return (GEN_FCN (extendtab[(int) mto][(int) mfrom][unsignedp]) (x, y));
}
static void
init_extends ()
{
- bzero (sign_extend_codes, sizeof sign_extend_codes);
- bzero (zero_extend_codes, sizeof zero_extend_codes);
+ enum insn_code *p;
+
+ for (p = extendtab[0][0];
+ p < extendtab[0][0] + sizeof extendtab / sizeof extendtab[0][0][0];
+ p++)
+ *p = CODE_FOR_nothing;
#ifdef HAVE_extendditi2
if (HAVE_extendditi2)
- sign_extend_codes[(int) TImode][(int) DImode] = CODE_FOR_extendditi2;
+ extendtab[(int) TImode][(int) DImode][0] = CODE_FOR_extendditi2;
#endif
#ifdef HAVE_extendsiti2
if (HAVE_extendsiti2)
- sign_extend_codes[(int) TImode][(int) SImode] = CODE_FOR_extendsiti2;
+ extendtab[(int) TImode][(int) SImode][0] = CODE_FOR_extendsiti2;
#endif
#ifdef HAVE_extendhiti2
if (HAVE_extendhiti2)
- sign_extend_codes[(int) TImode][(int) HImode] = CODE_FOR_extendhiti2;
+ extendtab[(int) TImode][(int) HImode][0] = CODE_FOR_extendhiti2;
#endif
#ifdef HAVE_extendqiti2
if (HAVE_extendqiti2)
- sign_extend_codes[(int) TImode][(int) QImode] = CODE_FOR_extendqiti2;
+ extendtab[(int) TImode][(int) QImode][0] = CODE_FOR_extendqiti2;
#endif
#ifdef HAVE_extendsidi2
if (HAVE_extendsidi2)
- sign_extend_codes[(int) DImode][(int) SImode] = CODE_FOR_extendsidi2;
+ extendtab[(int) DImode][(int) SImode][0] = CODE_FOR_extendsidi2;
#endif
#ifdef HAVE_extendhidi2
if (HAVE_extendhidi2)
- sign_extend_codes[(int) DImode][(int) HImode] = CODE_FOR_extendhidi2;
+ extendtab[(int) DImode][(int) HImode][0] = CODE_FOR_extendhidi2;
#endif
#ifdef HAVE_extendqidi2
if (HAVE_extendqidi2)
- sign_extend_codes[(int) DImode][(int) QImode] = CODE_FOR_extendqidi2;
+ extendtab[(int) DImode][(int) QImode][0] = CODE_FOR_extendqidi2;
#endif
#ifdef HAVE_extendhisi2
if (HAVE_extendhisi2)
- sign_extend_codes[(int) SImode][(int) HImode] = CODE_FOR_extendhisi2;
+ extendtab[(int) SImode][(int) HImode][0] = CODE_FOR_extendhisi2;
#endif
#ifdef HAVE_extendqisi2
if (HAVE_extendqisi2)
- sign_extend_codes[(int) SImode][(int) QImode] = CODE_FOR_extendqisi2;
+ extendtab[(int) SImode][(int) QImode][0] = CODE_FOR_extendqisi2;
#endif
#ifdef HAVE_extendqihi2
if (HAVE_extendqihi2)
- sign_extend_codes[(int) HImode][(int) QImode] = CODE_FOR_extendqihi2;
+ extendtab[(int) HImode][(int) QImode][0] = CODE_FOR_extendqihi2;
#endif
#ifdef HAVE_zero_extendditi2
if (HAVE_zero_extendsiti2)
- zero_extend_codes[(int) TImode][(int) DImode] = CODE_FOR_zero_extendditi2;
+ extendtab[(int) TImode][(int) DImode][1] = CODE_FOR_zero_extendditi2;
#endif
#ifdef HAVE_zero_extendsiti2
if (HAVE_zero_extendsiti2)
- zero_extend_codes[(int) TImode][(int) SImode] = CODE_FOR_zero_extendsiti2;
+ extendtab[(int) TImode][(int) SImode][1] = CODE_FOR_zero_extendsiti2;
#endif
#ifdef HAVE_zero_extendhiti2
if (HAVE_zero_extendhiti2)
- zero_extend_codes[(int) TImode][(int) HImode] = CODE_FOR_zero_extendhiti2;
+ extendtab[(int) TImode][(int) HImode][1] = CODE_FOR_zero_extendhiti2;
#endif
#ifdef HAVE_zero_extendqiti2
if (HAVE_zero_extendqiti2)
- zero_extend_codes[(int) TImode][(int) QImode] = CODE_FOR_zero_extendqiti2;
+ extendtab[(int) TImode][(int) QImode][1] = CODE_FOR_zero_extendqiti2;
#endif
#ifdef HAVE_zero_extendsidi2
if (HAVE_zero_extendsidi2)
- zero_extend_codes[(int) DImode][(int) SImode] = CODE_FOR_zero_extendsidi2;
+ extendtab[(int) DImode][(int) SImode][1] = CODE_FOR_zero_extendsidi2;
#endif
#ifdef HAVE_zero_extendhidi2
if (HAVE_zero_extendhidi2)
- zero_extend_codes[(int) DImode][(int) HImode] = CODE_FOR_zero_extendhidi2;
+ extendtab[(int) DImode][(int) HImode][1] = CODE_FOR_zero_extendhidi2;
#endif
#ifdef HAVE_zero_extendqidi2
if (HAVE_zero_extendqidi2)
- zero_extend_codes[(int) DImode][(int) QImode] = CODE_FOR_zero_extendqidi2;
+ extendtab[(int) DImode][(int) QImode][1] = CODE_FOR_zero_extendqidi2;
#endif
#ifdef HAVE_zero_extendhisi2
if (HAVE_zero_extendhisi2)
- zero_extend_codes[(int) SImode][(int) HImode] = CODE_FOR_zero_extendhisi2;
+ extendtab[(int) SImode][(int) HImode][1] = CODE_FOR_zero_extendhisi2;
#endif
#ifdef HAVE_zero_extendqisi2
if (HAVE_zero_extendqisi2)
- zero_extend_codes[(int) SImode][(int) QImode] = CODE_FOR_zero_extendqisi2;
+ extendtab[(int) SImode][(int) QImode][1] = CODE_FOR_zero_extendqisi2;
#endif
#ifdef HAVE_zero_extendqihi2
if (HAVE_zero_extendqihi2)
- zero_extend_codes[(int) HImode][(int) QImode] = CODE_FOR_zero_extendqihi2;
+ extendtab[(int) HImode][(int) QImode][1] = CODE_FOR_zero_extendqihi2;
#endif
}
\f
}
\f
/* Generate code to convert FROM to floating point
- and store in TO. FROM must be fixed point.
+ and store in TO. FROM must be fixed point and not VOIDmode.
UNSIGNEDP nonzero means regard FROM as unsigned.
Normally this is done by correcting the final value
if it is negative. */
register rtx target = to;
enum machine_mode fmode, imode;
+ /* Crash now, because we won't be able to decide which mode to use. */
+ if (GET_MODE (from) == VOIDmode)
+ abort ();
+
/* Look for an insn to do the conversion. Do it in the specified
modes if possible; otherwise convert either input, output or both to
wider mode. If the integer mode is wider than the mode of FROM,
and Computer Technology Corporation (MCC). The author's current
E-mail address is <rfg@ncd.com>.
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ Copyright (C) 1989, 1992 Free Software Foundation, Inc.
This file is part of GNU CC.
#define VOLATILE
#endif
-/* It is incorrect to include config.h here, because this file is being
- compiled for the target, and hence definitions concerning only the host
- do not apply. Instead we include tconfig.h, which is the xm file
- *for the target*, which also includes the tm.h file *for the target*.
- This way, we get definitions of POSIX, USG and VMS for the target. */
+#ifndef __STDC__
+#define const
+#endif
-#include "tconfig.h"
+#include "config.h"
-/* The documentation says to use TARGET_POSIX, so check for it as well
- as POSIX. */
-#if defined(TARGET_POSIX) && !defined(POSIX)
-#define POSIX
+#ifdef POSIX /* We should be able to define _POSIX_SOURCE unconditionally,
+ but some systems respond in buggy ways to it,
+ including Sunos 4.1.1. Which we don't classify as POSIX. */
+/* In case this is a POSIX system with an ANSI C compiler,
+ ask for definition of all POSIX facilities. */
+#define _POSIX_SOURCE
#endif
+#if 0
+/* Users are not supposed to use _POSIX_SOURCE to say the
+ system is a POSIX system. That is not what _POSIX_SOURCE means! -- rms */
/* If the user asked for POSIX via _POSIX_SOURCE, turn on POSIX code. */
#if defined(_POSIX_SOURCE) && !defined(POSIX)
#define POSIX
#endif
-
-/* On a POSIX system, request definition of all the POSIX facilities. */
-#if defined(POSIX) && !defined(_POSIX_SOURCE)
-#define _POSIX_SOURCE
-#endif
+#endif /* 0 */
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/dir.h>
+#if ! defined (USG) || defined (SVR4)
#include <sys/wait.h>
+#endif
#include <setjmp.h>
#include "gvarargs.h"
#include "getopt.h"
#ifndef PATH_MAX /* <limits.h> defines this on most POSIX systems. */
#include <sys/param.h>
-#define PATH_MAX MAXPATHLEN
/* Sometimes <sys/param.h> defines these macros. */
#undef CHAR_BIT
#undef CHAR_MAX
extern char *sys_errlist[];
extern char *version_string;
-#if defined(POSIX)
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <string.h>
-
/* Systems which are compatible only with POSIX 1003.1-1988 (but *not*
with POSIX 1003.1-1990), e.g. Ultrix 4.2, might not have
const qualifiers in the prototypes in the system include files.
calls to the following functions. To eliminate these warnings we
provide the following #defines. */
-#if (_POSIX_VERSION < 199009)
+#define my_access(file,flag) access((char *)file, flag)
+#define my_stat(file,pkt) stat((char *)file, pkt)
+#define my_execvp(prog,argv) execvp((char *)prog, (char **)argv)
+#define my_link(file1, file2) link((char *)file1, (char *)file2)
+#define my_unlink(file) unlink((char *)file)
+#define my_open(file, mode, flag) open((char *)file, mode, flag)
+#define my_chmod(file, mode) chmod((char *)file, mode)
+
+#if !(defined (USG) || defined (VMS) || defined (POSIX))
+#define GUESSPATHLEN (MAXPATHLEN + 1)
+#else /* (defined (USG) || defined (VMS) || defined (POSIX)) */
+/* We actually use this as a starting point, not a limit. */
+#define GUESSPATHLEN 200
+#endif /* (defined (USG) || defined (VMS) || defined (POSIX)) */
-#define access(file,flag) access((char *)file, flag)
-#define stat(file,pkt) stat((char *)file, pkt)
-#define execvp(prog,argv) execvp((char *)prog, (char **)argv)
-#define link(file1, file2) link((char *)file1, (char *)file2)
-#define unlink(file) unlink((char *)file)
-#define open(file, mode, flag) open((char *)file, mode, flag)
-#define chmod(file, mode) chmod((char *)file, mode)
+/* Aliases for pointers to void.
+ These were made to facilitate compilation with other compilers. */
-#endif /* (_POSIX_VERSION < 199009) */
+#ifdef __STDC__
+typedef void * pointer_type;
+typedef const void * const_pointer_type;
+#else
+typedef char * pointer_type;
+typedef char * const_pointer_type;
+#endif
+
+#if defined(POSIX)
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <string.h>
#else /* !defined(POSIX) */
the few exceptions to the general rule here. */
#if !(defined (USG) || defined (VMS))
-extern char *getwd (char *);
+extern char *getwd ();
#define getcwd(buf,len) getwd(buf)
#else /* (defined (USG) || defined (VMS)) */
-extern char *getcwd (char *, size_t);
+extern char *getcwd ();
#endif /* (defined (USG) || defined (VMS)) */
/* Declaring stat or __flsbuf with a prototype
causes conflicts with system headers on some systems. */
#ifndef abort
-extern VOLATILE void abort (void);
+extern VOLATILE void abort ();
#endif
-extern int kill(int, int);
-extern int creat (const char *, int);
-extern int open (const char *, int, ...);
+extern int kill();
+extern int creat ();
#if 0 /* These conflict with stdio.h on some systems. */
extern int fprintf (FILE *, const char *, ...);
extern int printf (const char *, ...);
#endif /* 0 */
-extern void exit (int);
-extern void *malloc (size_t);
-extern void *realloc (void *, size_t);
-extern void free (void *);
-extern int read (int, void *, size_t);
-extern int write (int, const void *, size_t);
-extern int close (int);
-extern int link (const char *, const char *);
-extern int unlink (const char *);
-extern int fflush (FILE *);
-extern int atoi (const char *);
-extern int access (const char *, int);
-extern int puts (const char *);
-extern int fputs (const char *, FILE *);
-extern int fputc (int, FILE *);
-extern int execvp (const char *, char *const *);
-extern int setjmp (jmp_buf);
-extern void longjmp (jmp_buf, int);
-
-extern char * strcat(char *, const char *);
-extern int strcmp(const char *, const char *);
-extern char * strcpy(char *, const char *);
+extern void exit ();
+extern pointer_type malloc ();
+extern pointer_type realloc ();
+extern void free ();
+extern int read ();
+extern int write ();
+extern int close ();
+extern int fflush ();
+extern int atoi ();
+extern int puts ();
+extern int fputs ();
+extern int fputc ();
+#if 0 /* Causes trouble on some systems that define setjmp as a macro. */
+extern int setjmp ();
+extern void longjmp ();
+#endif
+
+extern char * strcat();
+extern int strcmp();
+extern char * strcpy();
#if 0 /* size_t from sys/types.h may fail to match GCC.
If so, we would get a warning from this.
So do without the prototype. */
extern size_t strlen(const char *);
#endif
-extern int strncmp(const char *, const char *, size_t);
-extern char * strncpy(char *, const char *, size_t);
-extern char * strrchr(const char *, int);
+extern int strncmp();
+extern char * strncpy();
+extern char * strrchr();
#if !(defined (USG) || defined (VMS))
-extern int vfork (void);
+extern int vfork ();
#define fork vfork
#else
-extern int fork (void);
+extern int fork ();
#endif /* !(defined (USG) || defined (VMS)) */
#endif /* !defined(POSIX) */
#define NONCONST
-/* Aliases for pointers to void.
- These were made to facilitate compilation with other compilers. */
-
-typedef void * pointer_type;
-typedef const void * const_pointer_type;
-
-/* Define a STRINGIFY macro that's right for ANSI C. */
+/* Define a STRINGIFY macro that's right for ANSI or traditional C. */
+#ifdef __STDC__
#define STRINGIFY(STRING) #STRING
+#else
+#define STRINGIFY(STRING) "STRING"
+#endif
/* POSIX systems will not have definitions for WIFEXITED or WEXITSTATUS.
Define them correctly and so that they work for all environments. */
/* ??? These comments should say what the flag mean as well as the options
that set them. */
-static int version_flag = 0; /* set by -V option */
-static int quiet_flag = 0; /* set by -q option */
-#if 0
-static int force_flag = 0; /* set by -f option */
-#endif
-static int nochange_flag = 0; /* set by -n option */
-static int nosave_flag = 0; /* set by -N option */
-static int keep_flag = 0; /* set by -k option */
-static const char ** compile_params = 0; /* set by -c option */
+static int version_flag = 0; /* Print our version number. */
+static int quiet_flag = 0; /* Don't print messages normally. */
+static int nochange_flag = 0; /* Don't convert, just say what files
+ we would have converted. */
+static int nosave_flag = 0; /* Don't save the old version. */
+static int keep_flag = 0; /* Don't delete the .X files. */
+static const char ** compile_params = 0; /* Option string for gcc. */
#ifdef UNPROTOIZE
-static const char *indent_string = " "; /* set by -i option */
+static const char *indent_string = " "; /* Indentation for newly
+ inserted parm decls. */
#else /* !defined(UNPROTOIZE) */
-static int local_flag = 0; /* set by -l option */
+static int local_flag = 0; /* Insert new local decls (when?). */
static int global_flag = 0; /* set by -g option */
-static int cplusplus_flag = 0; /* set by -C option */
-static const char* nondefault_syscalls_dir = 0; /* set by -B option */
+static int cplusplus_flag = 0; /* Rename converted files to *.C. */
+static const char* nondefault_syscalls_dir = 0; /* Dir to look for
+ SYSCALLS.c.X in. */
#endif /* !defined(UNPROTOIZE) */
/* An index into the compile_params array where we should insert the filename
/* Forward declaration. */
-static const char *shortpath (const char *cwd, const char *filename);
+static const char *shortpath ();
\f
/* Allocate some space, but check that the allocation was successful. */
static pointer_type
-xmalloc (size_t byte_count)
+xmalloc (byte_count)
+ size_t byte_count;
{
pointer_type rv;
- if ((rv = malloc (byte_count)) == NULL)
+ rv = malloc (byte_count);
+ if (rv == NULL)
{
fprintf (stderr, "\n%s: fatal error: can't allocate %u more bytes of memory\n",
pname, byte_count);
/* Reallocate some space, but check that the reallocation was successful. */
static pointer_type
-xrealloc (pointer_type old_space, size_t byte_count)
+xrealloc (old_space, byte_count)
+ pointer_type old_space;
+ size_t byte_count;
{
pointer_type rv;
- if ((rv = realloc (old_space, byte_count)) == NULL)
+ rv = realloc (old_space, byte_count);
+ if (rv == NULL)
{
fprintf (stderr, "\n%s: fatal error: can't allocate %u more bytes of memory\n",
pname, byte_count);
is non-null. */
static void
-xfree (const_pointer_type p)
+xfree (p)
+ const_pointer_type p;
{
if (p)
free ((NONCONST pointer_type) p);
/* Make a copy of a string INPUT with size SIZE. */
static char *
-savestring (const char *input, int size)
+savestring (input, size)
+ const char *input;
+ int size;
{
char *output = (char *) xmalloc (size + 1);
strcpy (output, input);
/* Make a duplicate of a given string in a newly allocated area. */
static char *
-dupstr (const char *s)
+dupstr (s)
+ const char *s;
{
return strcpy ((char *) xmalloc (strlen (s) + 1), s);
}
allocated area. */
static char *
-dupnstr (const char *s, size_t n)
+dupnstr (s, n)
+ const char *s;
+ size_t n;
{
char *ret_val = strncpy ((char *) xmalloc (n + 1), s, n);
does not occur within s1. Assume neither s1 nor s2 are null pointers. */
static const char *
-substr (const char *s1, const char *const s2)
+substr (s1, s2)
+ const char *s1;
+ const char *const s2;
{
for (; *s1 ; s1++)
{
/* Get setup to recover in case the edit we are about to do goes awry. */
void
-save_pointers (void)
+save_pointers ()
{
saved_clean_read_ptr = clean_read_ptr;
saved_repl_write_ptr = repl_write_ptr;
too confusing in the source code we are trying to edit. */
void
-restore_pointers (void)
+restore_pointers ()
{
clean_read_ptr = saved_clean_read_ptr;
repl_write_ptr = saved_repl_write_ptr;
/* Return true if the given character is a legal identifier character. */
-inline static int
-is_id_char (char ch)
+static int
+is_id_char (ch)
+ char ch;
{
return (isalnum (ch) || (ch == '_') || (ch == '$'));
}
exit with non-zero status. */
static void
-usage (void)
+usage ()
{
#ifdef UNPROTOIZE
fprintf (stderr, "%s: usage '%s [ -VqfnkN ] [ -i <istring> ] [ filename ... ]'\n",
include directories. */
static int
-in_system_include_dir (const char *path)
+in_system_include_dir (path)
+ const char *path;
{
struct default_include *p;
{
char *const dir_name = (char *) alloca (strlen (path) + 1);
- if (access (path, R_OK))
+ if (my_access (path, R_OK))
return 0;
{
abort (); /* Should have been an absolutized filename. */
}
- if (access (path, W_OK))
+ if (my_access (path, W_OK))
return 0;
return 1;
abort (); /* Should have been an absolutized filename. */
}
- if (access (path, R_OK))
+ if (my_access (path, R_OK))
{
if (!quiet_flag)
fprintf (stderr, "%s: warning: no read access for file `%s'\n",
return 0;
}
- if (access (path, W_OK))
+ if (my_access (path, W_OK))
{
if (!quiet_flag)
fprintf (stderr, "%s: warning: no write access for file `%s'\n",
return 0;
}
- if (access (dir_name, W_OK))
+ if (my_access (dir_name, W_OK))
{
if (!quiet_flag)
fprintf (stderr, "%s: warning: no write access for dir containing `%s'\n",
file. Return false otherwise. */
static int
-is_syscalls_file (const file_info *fi_p)
+is_syscalls_file (fi_p)
+ const file_info *fi_p;
{
return (substr (fi_p->hash_entry->symbol, syscalls_filename) != NULL);
}
by connect_defs_and_decs(). */
static int
-needs_to_be_converted (const file_info *file_p)
+needs_to_be_converted (file_p)
+ const file_info *file_p;
{
const def_dec_info *ddp;
that should be converted. */
static int
-directory_specified_p (const char *name)
+directory_specified_p (name)
+ const char *name;
{
struct string_list *p;
/* Return 1 if the file named NAME should be excluded from conversion. */
static int
-file_excluded_p (const char *name)
+file_excluded_p (name)
+ const char *name;
{
struct string_list *p;
int len = strlen (name);
STRING is the new element value, and REST holds the remaining elements. */
static struct string_list *
-string_list_cons (char *string, struct string_list *rest)
+string_list_cons (string, rest)
+ char *string;
+ struct string_list *rest;
{
- struct string_list *temp = xmalloc (sizeof (struct string_list));
+ struct string_list *temp
+ = (struct string_list *) xmalloc (sizeof (struct string_list));
+
temp->next = rest;
temp->name = string;
return temp;
argument. */
static void
-visit_each_hash_node (const hash_table_entry *hash_tab_p, void (*func) (const hash_table_entry *))
+visit_each_hash_node (hash_tab_p, func)
+ const hash_table_entry *hash_tab_p;
+ void (*func)();
{
const hash_table_entry *primary;
called. */
static hash_table_entry *
-add_symbol (hash_table_entry *p, const char *s)
+add_symbol (p, s)
+ hash_table_entry *p;
+ const char *s;
{
p->hash_next = NULL;
p->symbol = dupstr (s);
hash table entry for the given name. */
static hash_table_entry *
-lookup (hash_table_entry *hash_tab_p, const char *search_symbol)
+lookup (hash_tab_p, search_symbol)
+ hash_table_entry *hash_tab_p;
+ const char *search_symbol;
{
int hash_value = 0;
const char *search_symbol_char_p = search_symbol;
Also, since we are not using this record anymore, free up all of the
stuff it pointed to. */
-inline static void
-free_def_dec (def_dec_info *p)
+static void
+free_def_dec (p)
+ def_dec_info *p;
{
xfree (p->ansi_decl);
return a pointer to the unexpanded copy. Otherwise return NULL. */
static char *
-unexpand_if_needed (const char *aux_info_line)
+unexpand_if_needed (aux_info_line)
+ const char *aux_info_line;
{
static char *line_buf = 0;
static int line_buf_size = 0;
NULL. */
static char *
-abspath (const char *cwd, const char *rel_filename)
+abspath (cwd, rel_filename)
+ const char *cwd;
+ const char *rel_filename;
{
/* Setup the current working directory as needed. */
const char *cwd2 = (cwd) ? cwd : cwd_buffer;
subpart of the original filename is actually a symbolic link. */
static const char *
-shortpath (const char *cwd, const char *filename)
+shortpath (cwd, filename)
+ const char *cwd;
+ const char *filename;
{
char *rel_buffer;
char *rel_buf_p;
--rel_buf_p;
if (*(rel_buf_p-1) == '/')
*--rel_buf_p = '\0';
- if (strlen (rel_buffer) > strlen (filename))
+ if (strlen (rel_buffer) > (unsigned) strlen (filename))
strcpy (rel_buffer, filename);
return rel_buffer;
}
- /* NOTREACHED */
- return 0; /* Prevent warnings for old versions of GCC. */
}
\f
/* Lookup the given filename in the hash table for filenames. If it is a
that record with some reasonable values. */
static file_info *
-find_file (char *filename, int do_not_stat)
+find_file (filename, do_not_stat)
+ char *filename;
+ int do_not_stat;
/* FILENAME was const, but that causes a warning on AIX when calling stat.
That is probably a bug in AIX, but might as well avoid the warning. */
{
stat_buf.st_mtime = (time_t) 0;
else
{
- if (stat (filename, &stat_buf) == -1)
+ if (my_stat (filename, &stat_buf) == -1)
{
fprintf (stderr, "%s: error: can't get status of `%s': %s\n",
pname, shortpath (NULL, filename), sys_errlist[errno]);
messed up. */
static void
-aux_info_corrupted (void)
+aux_info_corrupted ()
{
fprintf (stderr, "\n%s: fatal error: aux info file corrupted at line %d\n",
pname, current_aux_info_lineno);
/* ??? This comment is vague. Say what the condition is for. */
/* Check to see that a condition is true. This is kind of like an assert(). */
-inline static void
-check_aux_info (int cond)
+static void
+check_aux_info (cond)
+ int cond;
{
if (! cond)
aux_info_corrupted ();
return a pointer to it. */
static const char *
-find_corresponding_lparen (const char *p)
+find_corresponding_lparen (p)
+ const char *p;
{
const char *q;
int paren_depth;
file was created. If so, return non-zero, else return zero. */
static int
-referenced_file_is_newer (const char *l, time_t aux_info_mtime)
+referenced_file_is_newer (l, aux_info_mtime)
+ const char *l;
+ time_t aux_info_mtime;
{
const char *p;
file_info *fi_p;
pertaining to this particular function name. */
static void
-save_def_or_dec (const char *l, int is_syscalls)
+save_def_or_dec (l, is_syscalls)
+ const char *l;
+ int is_syscalls;
{
const char *p;
const char *semicolon_p;
/* p now points to the leftmost character of the function name. */
{
- char fn_string[past_fn - p + 1];
+ char *fn_string = (char *) alloca (past_fn - p + 1);
strncpy (fn_string, p, (size_t) (past_fn - p));
fn_string[past_fn-p] = '\0';
adding a final group of options like '-fgen-aux-info -S -o /dev/null'. */
static void
-munge_compile_params (const char *params_list)
+munge_compile_params (params_list)
+ const char *params_list;
{
- const char *temp_params[strlen (params_list) + 10];
+ char **temp_params = (char **) alloca (strlen (params_list) + 10);
int param_count = 0;
const char *param;
/* Make a copy of the compile_params in heap space. */
- compile_params = xmalloc (sizeof (char *) * (param_count+1));
+ compile_params
+ = (char **) xmalloc (sizeof (char *) * (param_count+1));
memcpy (compile_params, temp_params, sizeof (char *) * param_count);
}
file to go with a specific base source file. */
static int
-gen_aux_info_file (const char *base_filename)
+gen_aux_info_file (base_filename)
+ const char *base_filename;
{
int child_pid;
}
else
{
- if (execvp (compile_params[0], (char *const *) compile_params))
+ if (my_execvp (compile_params[0], (char *const *) compile_params))
{
fprintf (stderr, "%s: error: execvp returned: %s\n",
pname, sys_errlist[errno]);
Save all of the important stuff for later. */
static void
-process_aux_info_file (const char *base_source_filename, int keep_it, int is_syscalls)
+process_aux_info_file (base_source_filename, keep_it, is_syscalls)
+ const char *base_source_filename;
+ int keep_it;
+ int is_syscalls;
{
char *const aux_info_filename
= (char *) alloca (strlen (base_source_filename)
int retries = 0;
retry:
- if (access (aux_info_filename, R_OK) == -1)
+ if (my_access (aux_info_filename, R_OK) == -1)
{
if (errno == ENOENT && retries == 0)
{
/* Get some status information about this aux_info file. */
- if (stat (aux_info_filename, &stat_buf) == -1)
+ if (my_stat (aux_info_filename, &stat_buf) == -1)
{
fprintf (stderr, "%s: error: can't get status of aux info file `%s': %s\n",
pname, shortpath (NULL, aux_info_filename),
/* Open the aux_info file. */
- if ((aux_info_file = open (aux_info_filename, O_RDONLY, 0444 )) == -1)
+ if ((aux_info_file = my_open (aux_info_filename, O_RDONLY, 0444 )) == -1)
{
fprintf (stderr, "%s: error: can't open aux info file `%s' for reading: %s\n",
pname, shortpath (NULL, aux_info_filename),
fails for some reason, don't even worry about it. */
if (!keep_it)
- if (unlink (aux_info_filename) == -1)
+ if (my_unlink (aux_info_filename) == -1)
fprintf (stderr, "%s: error: can't delete aux info file `%s': %s\n",
pname, shortpath (NULL, aux_info_filename),
sys_errlist[errno]);
if (referenced_file_is_newer (aux_info_p, aux_info_mtime))
{
free (aux_info_base);
- if (unlink (aux_info_filename) == -1)
+ if (my_unlink (aux_info_filename) == -1)
{
fprintf (stderr, "%s: error: can't delete file `%s': %s\n",
pname, shortpath (NULL, aux_info_filename),
function implements the -C option. */
static void
-rename_c_file (const hash_table_entry *hp)
+rename_c_file (hp)
+ const hash_table_entry *hp;
{
const char *filename = hp->symbol;
int last_char_index = strlen (filename) - 1;
strcpy (new_filename, filename);
new_filename[last_char_index] = 'C';
- if (link (filename, new_filename) == -1)
+ if (my_link (filename, new_filename) == -1)
{
fprintf (stderr, "%s: warning: can't link file `%s' to `%s': %s\n",
pname, shortpath (NULL, filename),
return;
}
- if (unlink (filename) == -1)
+ if (my_unlink (filename) == -1)
{
fprintf (stderr, "%s: warning: can't delete file `%s': %s\n",
pname, shortpath (NULL, filename), sys_errlist[errno]);
order here. */
static void
-reverse_def_dec_list (const hash_table_entry *hp)
+reverse_def_dec_list (hp)
+ const hash_table_entry *hp;
{
file_info *file_p = hp->fip;
const def_dec_info *prev = NULL;
contains all of the correct prototypes for system functions. */
static const def_dec_info *
-find_extern_def (const def_dec_info *head, const def_dec_info *user)
+find_extern_def (head, user)
+ const def_dec_info *head;
+ const def_dec_info *user;
{
const def_dec_info *dd_p;
const def_dec_info *extern_def_p = NULL;
{
/* Why copy this string into `needed' at all?
Why not just use user->ansi_decl without copying? */
- char needed[strlen (user->ansi_decl) + 1];
+ char *needed = (char *) alloca (strlen (user->ansi_decl) + 1);
char *p;
strcpy (needed, user->ansi_decl);
p = (NONCONST char *) substr (needed, user->hash_entry->symbol)
+ strlen (user->hash_entry->symbol) + 2;
- strcpy (p, "???);");
+ strcpy (p, "??\?);");
fprintf (stderr, "%s: %d: `%s' used but missing from SYSCALLS\n",
shortpath (NULL, file), user->line,
from the def_dec_info record pointer which is passed in. */
static const def_dec_info *
-find_static_definition (const def_dec_info *user)
+find_static_definition (user)
+ const def_dec_info *user;
{
const def_dec_info *head = user->hash_entry->ddip;
const def_dec_info *dd_p;
more details. */
static void
-connect_defs_and_decs (const hash_table_entry *hp)
+connect_defs_and_decs (hp)
+ const hash_table_entry *hp;
{
const def_dec_info *dd_p;
const def_dec_info *extern_def_p = NULL;
original source line number that the given pointer points into. */
static int
-identify_lineno (const char *clean_p)
+identify_lineno (clean_p)
+ const char *clean_p;
{
int line_num = 1;
const char *scan_p;
/* Issue an error message and give up on doing this particular edit. */
static void
-declare_source_confusing (const char *clean_p)
+declare_source_confusing (clean_p)
+ const char *clean_p;
{
if (!quiet_flag)
{
code is in fact true. If not, issue an error message and give up on
converting this particular source file. */
-inline static void
-check_source (int cond, const char *clean_p)
+static void
+check_source (cond, clean_p)
+ int cond;
+ const char *clean_p;
{
if (!cond)
declare_source_confusing (clean_p);
of the in-core cleaned buffer again. */
static const char *
-seek_to_line (int n)
+seek_to_line (n)
+ int n;
{
if (n < last_known_line_number)
abort ();
to the next non-whitepace character which follows it. */
static const char *
-forward_to_next_token_char (const char *ptr)
+forward_to_next_token_char (ptr)
+ const char *ptr;
{
for (++ptr; isspace (*ptr); check_source (++ptr < clean_text_limit, 0))
continue;
buffer ultimately go through here. */
static void
-output_bytes (const char *str, size_t len)
+output_bytes (str, len)
+ const char *str;
+ size_t len;
{
if ((repl_write_ptr + 1) + len >= repl_text_limit)
{
the current output buffer. */
static void
-output_string (const char *str)
+output_string (str)
+ const char *str;
{
output_bytes (str, strlen (str));
}
byte pointed to by the argument pointer `p'. */
static void
-output_up_to (const char *p)
+output_up_to (p)
+ const char *p;
{
size_t copy_length = (size_t) (p - clean_read_ptr);
const char *copy_start = orig_text_base+(clean_read_ptr-clean_text_base)+1;
otherwise. */
static int
-other_variable_style_function (const char *ansi_header)
+other_variable_style_function (ansi_header)
+ const char *ansi_header;
{
#ifdef UNPROTOIZE
below. */
static void
-edit_fn_declaration (const def_dec_info *def_dec_p,
- const char *volatile clean_text_p)
+edit_fn_declaration (def_dec_p, clean_text_p)
+ const def_dec_info *def_dec_p;
+ const char *VOLATILE clean_text_p;
{
const char *start_formals;
const char *end_formals;
function doesn't match the one expected). */
static int
-edit_formals_lists (const char *end_formals, unsigned f_list_count, const def_dec_info *def_dec_p)
+edit_formals_lists (end_formals, f_list_count, def_dec_p)
+ const char *end_formals;
+ unsigned int f_list_count;
+ const def_dec_info *def_dec_p;
{
const char *start_formals;
int depth;
*/
static const char *
-find_rightmost_formals_list (const char *clean_text_p)
+find_rightmost_formals_list (clean_text_p)
+ const char *clean_text_p;
{
const char *end_formals;
continue;
end_formals--;
+#ifdef UNPROTOIZE
+
/* Now scan backwards while looking for the right end of the rightmost
formals list associated with this function definition. */
- for (;;)
+ {
+ char ch;
+ const char *l_brace_p;
+
+ /* Look leftward and try to find a right-paren. */
+
+ while (*end_formals != ')')
+ {
+ if (isspace (*end_formals))
+ while (isspace (*end_formals))
+ check_source (--end_formals > clean_read_ptr, 0);
+ else
+ check_source (--end_formals > clean_read_ptr, 0);
+ }
+
+ ch = *(l_brace_p = forward_to_next_token_char (end_formals));
+ /* Since we are unprotoizing an ANSI-style (prototyped) function
+ definition, there had better not be anything (except whitespace)
+ between the end of the ANSI formals list and the beginning of the
+ function body (i.e. the '{'). */
+
+ check_source (ch == '{', l_brace_p);
+ }
+
+#else /* !defined(UNPROTOIZE) */
+
+ /* Now scan backwards while looking for the right end of the rightmost
+ formals list associated with this function definition. */
+
+ while (1)
{
char ch;
const char *l_brace_p;
ch = *(l_brace_p = forward_to_next_token_char (end_formals));
-#ifdef UNPROTOIZE
-
- /* Since we are unprotoizing an ANSI-style (prototyped) function
- definition, there had better not be anything (except whitespace)
- between the end of the ANSI formals list and the beginning of the
- function body (i.e. the '{'). */
-
- check_source (ch == '{', l_brace_p);
- break;
-
-#else /* !defined(UNPROTOIZE) */
-
/* Since it is possible that we found a right paren before the starting
'{' of the body which IS NOT the one at the end of the real K&R
formals list (say for instance, we found one embedded inside one of
looking. */
check_source (--end_formals > clean_read_ptr, 0);
+ }
#endif /* !defined(UNPROTOIZE) */
- }
-
return end_formals;
}
parameter type checking. */
static void
-add_local_decl (const def_dec_info *def_dec_p, const char *clean_text_p)
+add_local_decl (def_dec_p, clean_text_p)
+ const def_dec_info *def_dec_p;
+ const char *clean_text_p;
{
const char *start_of_block;
const char *function_to_edit = def_dec_p->hash_entry->symbol;
and then insert the new explicit declaration at that point in the file. */
static void
-add_global_decls (const file_info *file_p, const char *clean_text_p)
+add_global_decls (file_p, clean_text_p)
+ const file_info *file_p;
+ const char *clean_text_p;
{
const def_dec_info *dd_p;
const char *scan_p;
separate routine above. */
static void
-edit_fn_definition (const def_dec_info *def_dec_p, const char *clean_text_p)
+edit_fn_definition (def_dec_p, clean_text_p)
+ const def_dec_info *def_dec_p;
+ const char *clean_text_p;
{
const char *end_formals;
const char *function_to_edit = def_dec_p->hash_entry->symbol;
into whitespace. Also, whiteout string and character literals. */
static void
-do_cleaning (char *new_clean_text_base, char *new_clean_text_limit)
+do_cleaning (new_clean_text_base, new_clean_text_limit)
+ char *new_clean_text_base;
+ char *new_clean_text_limit;
{
char *scan_p;
int non_whitespace_since_newline = 0;
and return a pointer to it. */
static const char *
-careful_find_l_paren (const char *p)
+careful_find_l_paren (p)
+ const char *p;
{
const char *q;
int paren_depth;
I will probably try to do this in a later version though. */
static void
-scan_for_missed_items (const file_info *file_p)
+scan_for_missed_items (file_p)
+ const file_info *file_p;
{
static const char *scan_p;
const char *limit = clean_text_limit - 3;
goto not_missed;
{
- char func_name[id_length + 1];
+ char *func_name = (char *) alloca (id_length + 1);
static const char * const stmt_keywords[]
= { "if", "while", "for", "switch", "return", 0 };
const char * const *stmt_keyword;
preprocessor directives make the editing a whole lot easier. */
static void
-edit_file (const hash_table_entry *hp)
+edit_file (hp)
+ const hash_table_entry *hp;
{
struct stat stat_buf;
const file_info *file_p = hp->fip;
/* Let the user know what we are up to. */
if (nochange_flag)
- puts (shortpath (NULL, convert_filename));
+ fprintf (stderr, "%s: would convert file `%s'\n",
+ pname, shortpath (NULL, convert_filename));
else
- {
- fprintf (stderr, "%s: converting file `%s'\n",
- pname, shortpath (NULL, convert_filename));
- fflush (stderr);
- }
+ fprintf (stderr, "%s: converting file `%s'\n",
+ pname, shortpath (NULL, convert_filename));
+ fflush (stderr);
/* Find out the size (in bytes) of the original file. */
/* The cast avoids an erroneous warning on AIX. */
- if (stat ((char *)convert_filename, &stat_buf) == -1)
+ if (my_stat ((char *)convert_filename, &stat_buf) == -1)
{
fprintf (stderr, "%s: error: can't get status for file `%s': %s\n",
pname, shortpath (NULL, convert_filename), sys_errlist[errno]);
/* Open the file to be converted in READ ONLY mode. */
- if ((input_file = open (convert_filename, O_RDONLY, 0444)) == -1)
+ if ((input_file = my_open (convert_filename, O_RDONLY, 0444)) == -1)
{
fprintf (stderr, "%s: error: can't open file `%s' for reading: %s\n",
pname, shortpath (NULL, convert_filename),
strcpy (new_filename, convert_filename);
strcat (new_filename, save_suffix);
- if (link (convert_filename, new_filename) == -1)
+ if (my_link (convert_filename, new_filename) == -1)
{
if (errno == EEXIST)
{
}
}
- if (unlink (convert_filename) == -1)
+ if (my_unlink (convert_filename) == -1)
{
fprintf (stderr, "%s: error: can't delete file `%s': %s\n",
pname, shortpath (NULL, convert_filename), sys_errlist[errno]);
/* Change the mode of the output file to match the original file. */
/* The cast avoids an erroneous warning on AIX. */
- if (chmod ((char *)convert_filename, stat_buf.st_mode) == -1)
+ if (my_chmod ((char *)convert_filename, stat_buf.st_mode) == -1)
fprintf (stderr, "%s: error: can't change mode of file `%s': %s\n",
pname, shortpath (NULL, convert_filename), sys_errlist[errno]);
in the command line. */
static void
-do_processing (void)
+do_processing ()
{
const char * const *base_pp;
const char * const * const end_pps
{
syscalls_absolute_filename
= (char *) xmalloc (strlen (nondefault_syscalls_dir)
- + strlen (syscalls_filename) + 1);
+ + strlen (syscalls_filename) + 2);
strcpy (syscalls_absolute_filename, nondefault_syscalls_dir);
}
else
{
syscalls_absolute_filename
= (char *) xmalloc (strlen (default_syscalls_dir)
- + strlen (syscalls_filename) + 1);
+ + strlen (syscalls_filename) + 2);
strcpy (syscalls_absolute_filename, default_syscalls_dir);
}
- syscalls_len = strlen (syscalls_filename);
+ syscalls_len = strlen (syscalls_absolute_filename);
if (*(syscalls_absolute_filename + syscalls_len - 1) != '/')
{
*(syscalls_absolute_filename + syscalls_len++) = '/';
};
int
-main (int argc, char **const argv)
+main (argc, argv)
+ int argc;
+ char **const argv;
{
int longind;
int c;
pname = pname ? pname+1 : argv[0];
/* Read the working directory, avoiding arbitrary limit. */
- size = 100;
+ size = GUESSPATHLEN;
while (1)
{
char *value;