The following exports the native_encode_real worker, and makes it
take a scalar float mode and REAL_VALUE_TYPE data instead of a tree
for use in the COBOL frontend, avoiding creating of a temporary tree.
Bootstrap / regtest in progress. Is this OK for the use in COBOL?
Thanks,
Richard.
* fold-const.h (native_encode_real): Export.
* fold-const.cc (native_encode_real): Change API to take
mode and REAL_VALUE_TYPE.
(native_encode_expr): Adjust.
---
gcc/fold-const.cc | 13 +++++++------
gcc/fold-const.h | 2 ++
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index fef7a6cc48e..a4fb0147a0b 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -7572,11 +7572,11 @@ native_encode_fixed (const_tree expr, unsigned char
*ptr, int len, int off)
Return the number of bytes placed in the buffer, or zero
upon failure. */
-static int
-native_encode_real (const_tree expr, unsigned char *ptr, int len, int off)
+int
+native_encode_real (scalar_float_mode mode, const REAL_VALUE_TYPE *val,
+ unsigned char *ptr, int len, int off)
{
- tree type = TREE_TYPE (expr);
- int total_bytes = GET_MODE_SIZE (SCALAR_FLOAT_TYPE_MODE (type));
+ int total_bytes = GET_MODE_SIZE (mode);
int byte, offset, word, words, bitpos;
unsigned char value;
@@ -7596,7 +7596,7 @@ native_encode_real (const_tree expr, unsigned char *ptr,
int len, int off)
words = (32 / BITS_PER_UNIT) / UNITS_PER_WORD;
- real_to_target (tmp, TREE_REAL_CST_PTR (expr), TYPE_MODE (type));
+ real_to_target (tmp, val, mode);
for (bitpos = 0; bitpos < total_bytes * BITS_PER_UNIT;
bitpos += BITS_PER_UNIT)
@@ -7836,7 +7836,8 @@ native_encode_expr (const_tree expr, unsigned char *ptr,
int len, int off)
return native_encode_int (expr, ptr, len, off);
case REAL_CST:
- return native_encode_real (expr, ptr, len, off);
+ return native_encode_real (SCALAR_FLOAT_TYPE_MODE (TREE_TYPE (expr)),
+ TREE_REAL_CST_PTR (expr), ptr, len, off);
case FIXED_CST:
return native_encode_fixed (expr, ptr, len, off);
diff --git a/gcc/fold-const.h b/gcc/fold-const.h
index f20fb58271d..43deea4d69c 100644
--- a/gcc/fold-const.h
+++ b/gcc/fold-const.h
@@ -35,6 +35,8 @@ extern bool folding_cxx_constexpr;
extern int native_encode_expr (const_tree, unsigned char *, int, int off = -1);
extern int native_encode_initializer (tree, unsigned char *, int,
int off = -1, unsigned char * = nullptr);
+extern int native_encode_real (scalar_float_mode, const REAL_VALUE_TYPE *,
+ unsigned char *, int, int off = -1);
extern tree native_interpret_expr (tree, const unsigned char *, int);
extern tree native_interpret_real (tree, const unsigned char *, int);
extern bool can_native_interpret_type_p (tree);
--
2.43.0