]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Export native_encode_real operating on REAL_VALUE_TYPE
authorRichard Biener <rguenther@suse.de>
Fri, 21 Mar 2025 18:30:31 +0000 (19:30 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 28 Mar 2025 07:54:07 +0000 (08:54 +0100)
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.

* 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
gcc/fold-const.h

index fef7a6cc48eff55436f8687116d492ffefea3aff..a4fb0147a0b1b74de0fff3b04a9a99e7a3d2084d 100644 (file)
@@ -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);
index f20fb58271df127c2dfdedf8c26f715a7e9720ab..43deea4d69c5d97e6d5c3735efb733e0974bff7c 100644 (file)
@@ -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);