issue #169 apply latest upstream changes

pull/212/head
Dibyendu Majumdar 3 years ago
parent 773ebd9d32
commit 56a59a1f31

@ -46,7 +46,10 @@
or IEEE quad precision FP values. If it is the same as double, the double type will be used instead.
So please don't expect machine-independence of MIR code working with long double values
* `MIR_T_P` -- pointer values. Depending on the target pointer value is actually 32-bit or 64-bit integer value
* `MIR_T_BLK` -- block data. This type can be used only for argument of function
* `MIR_T_BLK` .. `MIR_T_BLK + MIR_BLK_NUM - 1` -- block data with given case. This type can be used only
for argument of function. Different case numbers can denote different ways to pass the block data
on a particular target to implement the target call ABI. Currently there are 5 block
types (`MIR_BLK_NUM = 5`)
* `MIR_T_RBLK` -- return block data. This type can be used only for argument of function
* MIR textual representation of the types are correspondingly `i8`,
`u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `f`, `d`, `ld`, `p`,
@ -100,7 +103,8 @@
* A variable should have an unique name in the function
* A variable is represented by a structure of type `MIR_var_t`
* The structure contains variable name and its type
* The structure contains also type size for variable of `MIR_T_BLK` or `MIR_T_RBLK` type
* The structure contains also type size for variable of block types (`MIR_T_BLK`..`MIR_T_BLK + MIR_BLK_NUM - 1`)
or `MIR_T_RBLK` type
* MIR function with its arguments is created through API function `MIR_item_t MIR_new_func (MIR_context_t ctx, const
char *name, size_t nres, MIR_type_t *res_types, size_t nargs, ...)`
or function `MIR_item_t MIR_new_func_arr (MIR_context_t ctx, const char *name, size_t nres, MIR_type_t *res_types, size_t nargs, MIR_var_t *arg_vars)`
@ -408,8 +412,9 @@
* `MIR_VA_ARG` takes va_list and any memory operand and returns
address of the next argument in the 1st insn operand. The memory
operand type defines the type of the argument
* `MIR_VA_BLOCK_ARG` takes result address, va_list, and integer operand
and moves the next argument passed as block of give size to the result address
* `MIR_VA_BLOCK_ARG` takes result address, va_list address, integer operand (size),
and block type (case) number and moves the next argument passed as block of given
size and type to the result address
* va_list operand can be memory with undefined type. In this case
address of the va_list is not in the memory but is the
memory address

@ -2194,7 +2194,7 @@ static int replacement_eq_p (VARR (token_t) * r1, VARR (token_t) * r2) {
el1 = VARR_GET (token_t, r1, i);
el2 = VARR_GET (token_t, r2, i);
if (el1->code == ' ' && el2->code == ' ') return TRUE;
if (el1->code == ' ' && el2->code == ' ') continue;
if (el1->node_code != el2->node_code) return FALSE;
if (strcmp (el1->repr, el2->repr) != 0) return FALSE;
}
@ -2279,8 +2279,8 @@ static void define (c2m_ctx_t c2m_ctx) {
} else {
VARR (token_t) * temp;
warning (c2m_ctx, id->pos, "different macro redefinition of %s", name);
temp = m->params, m->params = params, params = temp;
temp = m->replacement, m->replacement = repl, repl = temp;
SWAP (m->params, params, temp);
SWAP (m->replacement, repl, temp);
}
}
VARR_DESTROY (token_t, repl);
@ -3752,6 +3752,7 @@ static void pre (c2m_ctx_t c2m_ctx, const char *start_source_name) {
typedef struct {
node_t id, scope;
int typedef_p;
} tpname_t;
DEF_HTAB (tpname_t);
@ -3849,12 +3850,13 @@ static int tpname_find (c2m_ctx_t c2m_ctx, node_t id, node_t scope, tpname_t *re
return found_p;
}
static tpname_t tpname_add (c2m_ctx_t c2m_ctx, node_t id, node_t scope) {
static tpname_t tpname_add (c2m_ctx_t c2m_ctx, node_t id, node_t scope, int typedef_p) {
parse_ctx_t parse_ctx = c2m_ctx->parse_ctx;
tpname_t el, tpname;
tpname.id = id;
tpname.scope = scope;
tpname.typedef_p = typedef_p;
if (HTAB_DO (tpname_t, tpname_tab, tpname, HTAB_FIND, el)) return el;
HTAB_DO (tpname_t, tpname_tab, tpname, HTAB_INSERT, el);
return el;
@ -4247,10 +4249,8 @@ D (declaration) {
decl = r;
last_pos = POS (decl);
assert (decl->code == N_DECL);
if (typedef_p) {
op = NL_HEAD (decl->u.ops);
tpname_add (c2m_ctx, op, curr_scope);
}
op = NL_HEAD (decl->u.ops);
tpname_add (c2m_ctx, op, curr_scope, typedef_p);
try_attr_spec (c2m_ctx, last_pos);
if (M ('=')) {
P (initializer);
@ -4862,10 +4862,14 @@ D (direct_abstract_declarator) {
D (typedef_name) {
parse_ctx_t parse_ctx = c2m_ctx->parse_ctx;
node_t scope, r;
tpname_t tpn;
PTN (T_ID);
for (scope = curr_scope;; scope = scope->attr) {
if (tpname_find (c2m_ctx, r, scope, NULL)) return r;
if (tpname_find (c2m_ctx, r, scope, &tpn)) {
if (!tpn.typedef_p) break;
return r;
}
if (scope == NULL) break;
}
return err_node;
@ -5151,7 +5155,7 @@ err0:
D (transl_unit) {
parse_ctx_t parse_ctx = c2m_ctx->parse_ctx;
node_t list, ds, d, dl, r;
node_t list, ds, d, dl, r, func, param_list, p, par_declarator, id;
// curr_token->code = ';'; /* for error recovery */
read_token (c2m_ctx);
@ -5170,6 +5174,18 @@ D (transl_unit) {
PE (declaration, decl_err);
op_flat_append (c2m_ctx, dl, r);
}
func = NL_HEAD (NL_EL (d->u.ops, 1)->u.ops);
assert (func != NULL && func->code == N_FUNC);
param_list = NL_HEAD (func->u.ops);
for (p = NL_HEAD (param_list->u.ops); p != NULL; p = NL_NEXT (p)) {
if (p->code == N_ID) {
tpname_add (c2m_ctx, p, curr_scope, FALSE);
} else if (p->code == N_SPEC_DECL) {
par_declarator = NL_EL (p->u.ops, 1);
id = NL_HEAD (par_declarator->u.ops);
tpname_add (c2m_ctx, id, curr_scope, FALSE);
}
}
P (compound_stmt);
r = new_pos_node4 (c2m_ctx, N_FUNC_DEF, POS (d), ds, d, dl, r);
curr_scope = d->attr;

@ -1,116 +1,116 @@
/* This file is a part of MIR project.
Copyright (C) 2019-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
static char x86_64_mirc[]
= "#define __amd64 1\n"
"#define __amd64__ 1\n"
"#define __x86_64 1\n"
"#define __x86_64__ 1\n"
"#define _M_AMD64 1\n"
"#define _M_X64 1\n"
"\n"
"#define __SIZEOF_DOUBLE__ 8\n"
"#define __SIZEOF_FLOAT__ 4\n"
"#define __SIZEOF_INT__ 4\n"
#if !defined(_WIN32) && __SIZEOF_LONG_DOUBLE__ == 16
"#define __SIZEOF_LONG_DOUBLE__ 16\n"
#else
"#define __SIZEOF_LONG_DOUBLE__ 8\n"
#endif
"#define __SIZEOF_LONG_LONG__ 8\n"
"#define __SIZEOF_LONG__ 4\n"
"#define __SIZEOF_POINTER__ 8\n"
"#define __SIZEOF_PTRDIFF_T__ 8\n"
"#define __SIZEOF_SHORT__ 2\n"
"#define __SIZEOF_SIZE_T__ 8\n"
"\n"
"#define __BYTE_ORDER__ 1234\n"
"#define __ORDER_LITTLE_ENDIAN__ 1234\n"
"#define __ORDER_BIG_ENDIAN__ 4321\n"
"\n"
"/* Some type macros: */\n"
"#define __SIZE_TYPE__ long long unsigned int\n"
"#define __PTRDIFF_TYPE__ long long int\n"
"#define __INTMAX_TYPE__ long long int\n"
"#define __UINTMAX_TYPE__ long long unsigned int\n"
"#define __INT8_TYPE__ signed char\n"
"#define __INT16_TYPE__ short\n"
"#define __INT32_TYPE__ int\n"
"#define __INT64_TYPE__ long long int\n"
"#define __UINT8_TYPE__ unsigned char\n"
"#define __UINT16_TYPE__ unsigned short\n"
"#define __UINT32_TYPE__ unsigned int\n"
"#define __UINT64_TYPE__ long long unsigned int\n"
"#define __INTPTR_TYPE__ long long int\n"
"#define __UINTPTR_TYPE__ long long unsigned int\n"
"\n"
"#define __int8 __INT8_TYPE__\n"
"#define __int16 __INT16_TYPE__\n"
"#define __int32 __INT32_TYPE__\n"
"#define __int64 __INT64_TYPE__\n"
"\n"
"#define __ptr32\n"
"#define __ptr64\n"
"#define __forceinline inline\n"
"#define __cdecl\n"
"#define __pragma(p)\n"
"#define __declspec(attr)\n"
"#define __unaligned\n"
"\n"
"#define __CHAR_BIT__ 8\n"
"#define __INT8_MAX__ 127\n"
"#define __INT16_MAX__ 32767\n"
"#define __INT32_MAX__ 2147483647\n"
"#define __INT64_MAX__ 9223372036854775807LL\n"
"#define __UINT8_MAX__ (__INT8_MAX__ * 2u + 1u)\n"
"#define __UINT16_MAX__ (__INT16_MAX__ * 2u + 1u)\n"
"#define __UINT32_MAX__ (__INT32_MAX__ * 2u + 1u)\n"
"#define __UINT64_MAX__ (__INT64_MAX__ * 2u + 1u)\n"
"#define __SCHAR_MAX__ __INT8_MAX__\n"
"#define __SHRT_MAX__ __INT16_MAX__\n"
"#define __INT_MAX__ __INT32_MAX__\n"
"#define __LONG_MAX__ __INT32_MAX__\n"
"#define __LONG_LONG_MAX__ __INT64_MAX__\n"
"#define __SIZE_MAX__ __UINT64_MAX__\n"
"#define __PTRDIFF_MAX__ __INT64_MAX__\n"
"#define __INTMAX_MAX__ __INT64_MAX__\n"
"#define __UINTMAX_MAX__ __UINT64_MAX__\n"
"#define __INTPTR_MAX__ __INT64_MAX__\n"
"#define __UINTPTR_MAX__ __UINT64_MAX__\n"
"\n"
"#define __FLT_MIN_EXP__ (-125)\n"
"#define __FLT_MAX_EXP__ 128\n"
"#define __FLT_DIG__ 6\n"
"#define __FLT_DECIMAL_DIG__ 9\n"
"#define __FLT_MANT_DIG__ 24\n"
"#define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F\n"
"#define __FLT_MAX__ 3.40282346638528859811704183484516925e+38F\n"
"#define __FLT_EPSILON__ 1.19209289550781250000000000000000000e-7F\n"
"\n"
"#define __DBL_MIN_EXP__ (-1021)\n"
"#define __DBL_MAX_EXP__ 1024\n"
"#define __DBL_DIG__ 15\n"
"#define __DBL_DECIMAL_DIG__ 17\n"
"#define __DBL_MANT_DIG__ 53\n"
"#define __DBL_MAX__ ((double) 1.79769313486231570814527423731704357e+308L)\n"
"#define __DBL_MIN__ ((double) 2.22507385850720138309023271733240406e-308L)\n"
"#define __DBL_EPSILON__ ((double) 2.22044604925031308084726333618164062e-16L)\n"
"\n"
"typedef unsigned short char16_t;\n"
"typedef unsigned int char32_t;\n"
"\n"
"#define WIN32 1\n"
"#define _WIN32 1\n"
"#define __WIN32 1\n"
"#define __WIN32__ 1\n"
"#define WIN64 1\n"
"#define _WIN64 1\n"
"#define __WIN64 1\n"
"#define __WIN64__ 1\n"
"#define WINNT 1\n"
"#define __WINNT 1\n"
"#define __WINNT__ 1\n"
"#define __MSVCRT__ 1\n"
"\n"
"void *alloca (long long unsigned);\n";
/* This file is a part of MIR project.
Copyright (C) 2019-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
static char x86_64_mirc[]
= "#define __amd64 1\n"
"#define __amd64__ 1\n"
"#define __x86_64 1\n"
"#define __x86_64__ 1\n"
"#define _M_AMD64 1\n"
"#define _M_X64 1\n"
"\n"
"#define __SIZEOF_DOUBLE__ 8\n"
"#define __SIZEOF_FLOAT__ 4\n"
"#define __SIZEOF_INT__ 4\n"
#if !defined(_WIN32) && __SIZEOF_LONG_DOUBLE__ == 16
"#define __SIZEOF_LONG_DOUBLE__ 16\n"
#else
"#define __SIZEOF_LONG_DOUBLE__ 8\n"
#endif
"#define __SIZEOF_LONG_LONG__ 8\n"
"#define __SIZEOF_LONG__ 4\n"
"#define __SIZEOF_POINTER__ 8\n"
"#define __SIZEOF_PTRDIFF_T__ 8\n"
"#define __SIZEOF_SHORT__ 2\n"
"#define __SIZEOF_SIZE_T__ 8\n"
"\n"
"#define __BYTE_ORDER__ 1234\n"
"#define __ORDER_LITTLE_ENDIAN__ 1234\n"
"#define __ORDER_BIG_ENDIAN__ 4321\n"
"\n"
"/* Some type macros: */\n"
"#define __SIZE_TYPE__ long long unsigned int\n"
"#define __PTRDIFF_TYPE__ long long int\n"
"#define __INTMAX_TYPE__ long long int\n"
"#define __UINTMAX_TYPE__ long long unsigned int\n"
"#define __INT8_TYPE__ signed char\n"
"#define __INT16_TYPE__ short\n"
"#define __INT32_TYPE__ int\n"
"#define __INT64_TYPE__ long long int\n"
"#define __UINT8_TYPE__ unsigned char\n"
"#define __UINT16_TYPE__ unsigned short\n"
"#define __UINT32_TYPE__ unsigned int\n"
"#define __UINT64_TYPE__ long long unsigned int\n"
"#define __INTPTR_TYPE__ long long int\n"
"#define __UINTPTR_TYPE__ long long unsigned int\n"
"\n"
"#define __int8 __INT8_TYPE__\n"
"#define __int16 __INT16_TYPE__\n"
"#define __int32 __INT32_TYPE__\n"
"#define __int64 __INT64_TYPE__\n"
"\n"
"#define __ptr32\n"
"#define __ptr64\n"
"#define __forceinline inline\n"
"#define __cdecl\n"
"#define __pragma(p)\n"
"#define __declspec(attr)\n"
"#define __unaligned\n"
"\n"
"#define __CHAR_BIT__ 8\n"
"#define __INT8_MAX__ 127\n"
"#define __INT16_MAX__ 32767\n"
"#define __INT32_MAX__ 2147483647\n"
"#define __INT64_MAX__ 9223372036854775807LL\n"
"#define __UINT8_MAX__ (__INT8_MAX__ * 2u + 1u)\n"
"#define __UINT16_MAX__ (__INT16_MAX__ * 2u + 1u)\n"
"#define __UINT32_MAX__ (__INT32_MAX__ * 2u + 1u)\n"
"#define __UINT64_MAX__ (__INT64_MAX__ * 2u + 1u)\n"
"#define __SCHAR_MAX__ __INT8_MAX__\n"
"#define __SHRT_MAX__ __INT16_MAX__\n"
"#define __INT_MAX__ __INT32_MAX__\n"
"#define __LONG_MAX__ __INT32_MAX__\n"
"#define __LONG_LONG_MAX__ __INT64_MAX__\n"
"#define __SIZE_MAX__ __UINT64_MAX__\n"
"#define __PTRDIFF_MAX__ __INT64_MAX__\n"
"#define __INTMAX_MAX__ __INT64_MAX__\n"
"#define __UINTMAX_MAX__ __UINT64_MAX__\n"
"#define __INTPTR_MAX__ __INT64_MAX__\n"
"#define __UINTPTR_MAX__ __UINT64_MAX__\n"
"\n"
"#define __FLT_MIN_EXP__ (-125)\n"
"#define __FLT_MAX_EXP__ 128\n"
"#define __FLT_DIG__ 6\n"
"#define __FLT_DECIMAL_DIG__ 9\n"
"#define __FLT_MANT_DIG__ 24\n"
"#define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F\n"
"#define __FLT_MAX__ 3.40282346638528859811704183484516925e+38F\n"
"#define __FLT_EPSILON__ 1.19209289550781250000000000000000000e-7F\n"
"\n"
"#define __DBL_MIN_EXP__ (-1021)\n"
"#define __DBL_MAX_EXP__ 1024\n"
"#define __DBL_DIG__ 15\n"
"#define __DBL_DECIMAL_DIG__ 17\n"
"#define __DBL_MANT_DIG__ 53\n"
"#define __DBL_MAX__ ((double) 1.79769313486231570814527423731704357e+308L)\n"
"#define __DBL_MIN__ ((double) 2.22507385850720138309023271733240406e-308L)\n"
"#define __DBL_EPSILON__ ((double) 2.22044604925031308084726333618164062e-16L)\n"
"\n"
"typedef unsigned short char16_t;\n"
"typedef unsigned int char32_t;\n"
"\n"
"#define WIN32 1\n"
"#define _WIN32 1\n"
"#define __WIN32 1\n"
"#define __WIN32__ 1\n"
"#define WIN64 1\n"
"#define _WIN64 1\n"
"#define __WIN64 1\n"
"#define __WIN64__ 1\n"
"#define WINNT 1\n"
"#define __WINNT 1\n"
"#define __WINNT__ 1\n"
"#define __MSVCRT__ 1\n"
"\n"
"void *alloca (long long unsigned);\n";

Loading…
Cancel
Save