@@ -46,6 +46,8 @@
#include "target.h"
#include "version.h"
+#define ULL_BITS (__CHAR_BIT__ * sizeof(unsigned long long))
+
int verbose, optimize_level, optimize_size, preprocessing;
int die_if_error = 0;
int has_error = 0;
@@ -1161,6 +1163,11 @@ static char **handle_switch(char *arg, char **next)
return next;
}
+static void predefined_type(const char *name, const char *type_str)
+{
+ add_pre_buffer("#weak_define __%s_TYPE__ %s\n", name, type_str);
+}
+
static void predefined_sizeof(const char *name, unsigned bits)
{
char buf[32];
@@ -1177,6 +1184,13 @@ static void predefined_width(const char *name, unsigned bits)
predefine(buf, 1, "%d", bits);
}
+static void predefined_umax(const char *name, const char *suffix, unsigned bits)
+{
+ unsigned long long max = (~0ULL) >> (ULL_BITS - bits);
+
+ add_pre_buffer("#weak_define __%s_MAX__ %#llx%s\n", name, max, suffix);
+}
+
static void predefined_max(const char *name, const char *suffix, unsigned bits)
{
unsigned long long max = (1ULL << (bits - 1 )) - 1;
@@ -1248,6 +1262,53 @@ static void predefined_macros(void)
predefined_type_size("LONG", "L", bits_in_long);
predefined_type_size("LONG_LONG", "LL", bits_in_longlong);
+ predefined_max("INT8", "", 8);
+ predefined_type("INT8", "signed char");
+ predefined_max("INT16", "", 16);
+ predefined_type("INT16", "short int");
+ predefined_max("INT32", "", 32);
+ predefined_type("INT32", "int");
+ predefined_umax("UINT8", "", 8);
+ predefined_type("UINT8", "unsigned char");
+ predefined_umax("UINT16", "", 16);
+ predefined_type("UINT16", "short unsigned int");
+ predefined_umax("UINT32", "U", 32);
+ predefined_type("UINT32", "unsigned int");
+
+ if (bits_in_pointer == 64) {
+ predefined_max("INT64", "L", 64);
+ predefined_type("INT64", "long int");
+ predefined_max("INTMAX", "L", 64);
+ predefined_type("INTMAX", "long int");
+ predefined_max("INTPTR", "L", 64);
+ predefined_type("INTPTR", "long int");
+ predefined_max("PTRDIFF", "L", 64);
+ predefined_type("PTRDIFF", "long int");
+ predefined_umax("UINT64", "UL", 64);
+ predefined_type("UINT64", "long unsigned int");
+ predefined_umax("UINTMAX", "UL", 64);
+ predefined_type("UINTMAX", "long unsigned int");
+ predefined_umax("UINTPTR", "UL", 64);
+ predefined_type("UINTPTR", "long unsigned int");
+ predefined_umax("SIZE", "UL", 64);
+ } else {
+ predefined_max("INT64", "LL", 64);
+ predefined_type("INT64", "long long int");
+ predefined_max("INTMAX", "LL", 64);
+ predefined_type("INTMAX", "long long int");
+ predefined_max("INTPTR", "", 32);
+ predefined_type("INTPTR", "int");
+ predefined_max("PTRDIFF", "", 32);
+ predefined_type("PTRDIFF", "int");
+ predefined_umax("UINT64", "ULL", 64);
+ predefined_type("UINT64", "long long unsigned int");
+ predefined_umax("UINTMAX", "ULL", 64);
+ predefined_type("UINTMAX", "long long unsigned int");
+ predefined_umax("UINTPTR", "U", 32);
+ predefined_type("UINTPTR", "unsigned int");
+ predefined_umax("SIZE", "U", 32);
+ }
+
predefined_sizeof("INT128", 128);
predefined_sizeof("SIZE_T", bits_in_pointer);
Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com> --- lib.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)