aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fortran/misc.c')
-rw-r--r--gcc/fortran/misc.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/gcc/fortran/misc.c b/gcc/fortran/misc.c
index 8e789e5..80d282e 100644
--- a/gcc/fortran/misc.c
+++ b/gcc/fortran/misc.c
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see
#include "coretypes.h"
#include "gfortran.h"
#include "spellcheck.h"
+#include "tree.h"
/* Initialize a typespec to unknown. */
@@ -321,3 +322,23 @@ gfc_closest_fuzzy_match (const char *typo, char **candidates)
}
return best;
}
+
+/* Convert between GMP integers (mpz_t) and HOST_WIDE_INT. */
+
+HOST_WIDE_INT
+gfc_mpz_get_hwi (mpz_t op)
+{
+ /* Using long_long_integer_type_node as that is the integer type
+ node that closest matches HOST_WIDE_INT; both are guaranteed to
+ be at least 64 bits. */
+ const wide_int w = wi::from_mpz (long_long_integer_type_node, op, true);
+ return w.to_shwi ();
+}
+
+
+void
+gfc_mpz_set_hwi (mpz_t rop, const HOST_WIDE_INT op)
+{
+ const wide_int w = wi::shwi (op, HOST_BITS_PER_WIDE_INT);
+ wi::to_mpz (w, rop, SIGNED);
+}