Skip to content

Commit

Permalink
#169 update MIR to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed Dec 20, 2021
1 parent 0d82f26 commit 69ac558
Show file tree
Hide file tree
Showing 35 changed files with 1,038 additions and 808 deletions.
1 change: 0 additions & 1 deletion mir/c2mir/aarch64/caarch64-ABI-code.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ static int reg_aggregate_size (c2m_ctx_t c2m_ctx, struct type *type) {
static void target_add_res_proto (c2m_ctx_t c2m_ctx, struct type *ret_type,
target_arg_info_t *arg_info, VARR (MIR_type_t) * res_types,
VARR (MIR_var_t) * arg_vars) {
MIR_var_t var;
int size;

if ((size = reg_aggregate_size (c2m_ctx, ret_type)) < 0) {
Expand Down
6 changes: 6 additions & 0 deletions mir/c2mir/aarch64/mirc_aarch64_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ static char aarch64_mirc[]
"#define __UINT16_MAX__ (__INT16_MAX__ * 2u + 1u)\n"
"#define __UINT32_MAX__ (__INT32_MAX__ * 2u + 1u)\n"
"#define __UINT64_MAX__ (__INT64_MAX__ * 2u + 1u)\n"
#if defined(__linux__)
"#define __WCHAR_MAX__ 0x7fffffff\n"
#else
"#define __WCHAR_MAX__ 2147483647\n"
#endif
"#define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)\n"
"#define __SCHAR_MAX__ __INT8_MAX__\n"
"#define __SHRT_MAX__ __INT16_MAX__\n"
"#define __INT_MAX__ __INT32_MAX__\n"
Expand Down
4 changes: 0 additions & 4 deletions mir/c2mir/aarch64/mirc_aarch64_stddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ static char stddef_str[]
"typedef long ptrdiff_t;\n"
"typedef unsigned long size_t;\n"
"typedef long double max_align_t;\n"
#if defined(__APPLE__)
"typedef int wchar_t;\n"
#else
"typedef unsigned int wchar_t;\n"
#endif
"\n"
"#define NULL ((void *) 0)\n"
"\n"
Expand Down
9 changes: 6 additions & 3 deletions mir/c2mir/aarch64/mirc_aarch64_stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ static char stdint_str[]
"\n"
"#define SIZE_MAX (18446744073709551615UL)\n"
"\n"
"/* For signed wchar_t and wint_t: */\n"
"#define WCHAR_MIN INT32_MIN\n"
"#define WCHAR_MAX INT32_MAX\n"
"#ifndef WCHAR_MAX\n"
"#define WCHAR_MAX __WCHAR_MAX__\n"
"#endif\n"
"#ifndef WCHAR_MIN\n"
"#define WCHAR_MIN __WCHAR_MIN__\n"
"#endif\n"
"#define WINT_MIN WCHAR_MIN\n"
"#define WINT_MAX WCHAR_MAX\n"
"\n"
Expand Down
779 changes: 410 additions & 369 deletions mir/c2mir/c2mir.c

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions mir/c2mir/ppc64/cppc64-ABI-code.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ static MIR_type_t fp_homogeneous_type (c2m_ctx_t c2m_ctx, struct type *param_typ
#else
static MIR_type_t fp_homogeneous_type_1 (c2m_ctx_t c2m_ctx, MIR_type_t curr_type, struct type *type,
int *num) {
gen_ctx_t gen_ctx = c2m_ctx->gen_ctx;
int n;
MIR_type_t t;

Expand Down Expand Up @@ -186,7 +185,7 @@ static void target_add_ret_ops (c2m_ctx_t c2m_ctx, struct type *ret_type, op_t r
MIR_insn_t insn;
MIR_reg_t ret_addr_reg;
op_t temp, var;
int i, n, size;
int n, size;

if (void_type_p (ret_type)) return;
if (((type = fp_homogeneous_type (c2m_ctx, ret_type, &n)) == MIR_T_F || type == MIR_T_D)
Expand Down Expand Up @@ -251,7 +250,6 @@ static void target_add_call_arg_op (c2m_ctx_t c2m_ctx, struct type *arg_type,
target_arg_info_t *arg_info, op_t arg) {
gen_ctx_t gen_ctx = c2m_ctx->gen_ctx;
MIR_context_t ctx = c2m_ctx->ctx;
MIR_var_t var;
MIR_type_t type;
op_t temp;
int n;
Expand Down Expand Up @@ -285,7 +283,6 @@ static int target_gen_gather_arg (c2m_ctx_t c2m_ctx, const char *name, struct ty
decl_t param_decl, target_arg_info_t *arg_info) {
gen_ctx_t gen_ctx = c2m_ctx->gen_ctx;
MIR_context_t ctx = c2m_ctx->ctx;
MIR_var_t var;
MIR_type_t type;
reg_var_t reg_var;
int i, n;
Expand Down
2 changes: 2 additions & 0 deletions mir/c2mir/ppc64/mirc_ppc64_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ static char ppc64_mirc[]
"#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 __WCHAR_MAX__ 0x7fffffff\n"
"#define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)\n"
"#define __SCHAR_MAX__ __INT8_MAX__\n"
"#define __SHRT_MAX__ __INT16_MAX__\n"
"#define __INT_MAX__ __INT32_MAX__\n"
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/ppc64/mirc_ppc64_stddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static char stddef_str[]
"typedef long ptrdiff_t;\n"
"typedef unsigned long size_t;\n"
"typedef long double max_align_t;\n"
"typedef unsigned int wchar_t;\n"
"typedef int wchar_t;\n"
"\n"
"#define NULL ((void *) 0)\n"
"\n"
Expand Down
9 changes: 6 additions & 3 deletions mir/c2mir/ppc64/mirc_ppc64_stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ static char stdint_str[]
"\n"
"#define SIZE_MAX (18446744073709551615UL)\n"
"\n"
"/* For signed wchar_t and wint_t: */\n"
"#define WCHAR_MIN INT32_MIN\n"
"#define WCHAR_MAX INT32_MAX\n"
"#ifndef WCHAR_MAX\n"
"#define WCHAR_MAX __WCHAR_MAX__\n"
"#endif\n"
"#ifndef WCHAR_MIN\n"
"#define WCHAR_MIN __WCHAR_MIN__\n"
"#endif\n"
"#define WINT_MIN WCHAR_MIN\n"
"#define WINT_MAX WCHAR_MAX\n"
"\n"
Expand Down
2 changes: 2 additions & 0 deletions mir/c2mir/riscv64/mirc_riscv64_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ static char riscv64_mirc[]
"#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 __WCHAR_MAX__ 0x7fffffff\n"
"#define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)\n"
"#define __SCHAR_MAX__ __INT8_MAX__\n"
"#define __SHRT_MAX__ __INT16_MAX__\n"
"#define __INT_MAX__ __INT32_MAX__\n"
Expand Down
9 changes: 6 additions & 3 deletions mir/c2mir/riscv64/mirc_riscv64_stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ static char stdint_str[]
"\n"
"#define SIZE_MAX (18446744073709551615UL)\n"
"\n"
"/* For signed wchar_t and wint_t: */\n"
"#define WCHAR_MIN INT32_MIN\n"
"#define WCHAR_MAX INT32_MAX\n"
"#ifndef WCHAR_MAX\n"
"#define WCHAR_MAX __WCHAR_MAX__\n"
"#endif\n"
"#ifndef WCHAR_MIN\n"
"#define WCHAR_MIN __WCHAR_MIN__\n"
"#endif\n"
"#define WINT_MIN WCHAR_MIN\n"
"#define WINT_MAX WCHAR_MAX\n"
"\n"
Expand Down
1 change: 0 additions & 1 deletion mir/c2mir/s390x/cs390x-ABI-code.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ static int target_gen_gather_arg (c2m_ctx_t c2m_ctx, const char *name, struct ty
decl_t param_decl, target_arg_info_t *arg_info) {
gen_ctx_t gen_ctx = c2m_ctx->gen_ctx;
MIR_context_t ctx = c2m_ctx->ctx;
MIR_type_t type;
MIR_op_t param_op;
reg_var_t reg_var;

Expand Down
2 changes: 2 additions & 0 deletions mir/c2mir/s390x/mirc_s390x_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ static char s390x_mirc[]
"#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 __WCHAR_MAX__ 0x7fffffff\n"
"#define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)\n"
"#define __SCHAR_MAX__ __INT8_MAX__\n"
"#define __SHRT_MAX__ __INT16_MAX__\n"
"#define __INT_MAX__ __INT32_MAX__\n"
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/s390x/mirc_s390x_stddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static char stddef_str[]
"typedef long ptrdiff_t;\n"
"typedef unsigned long size_t;\n"
"typedef long double max_align_t;\n"
"typedef unsigned int wchar_t;\n"
"typedef int wchar_t;\n"
"\n"
"#define NULL ((void *) 0)\n"
"\n"
Expand Down
9 changes: 6 additions & 3 deletions mir/c2mir/s390x/mirc_s390x_stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ static char stdint_str[]
"\n"
"#define SIZE_MAX (18446744073709551615UL)\n"
"\n"
"/* For signed wchar_t and wint_t: */\n"
"#define WCHAR_MIN INT32_MIN\n"
"#define WCHAR_MAX INT32_MAX\n"
"#ifndef WCHAR_MAX\n"
"#define WCHAR_MAX __WCHAR_MAX__\n"
"#endif\n"
"#ifndef WCHAR_MIN\n"
"#define WCHAR_MIN __WCHAR_MIN__\n"
"#endif\n"
"#define WINT_MIN WCHAR_MIN\n"
"#define WINT_MAX WCHAR_MAX\n"
"\n"
Expand Down
6 changes: 6 additions & 0 deletions mir/c2mir/x86_64/mirc_x86_64_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ static char x86_64_mirc[]
"#define __UINT16_MAX__ (__INT16_MAX__ * 2u + 1u)\n"
"#define __UINT32_MAX__ (__INT32_MAX__ * 2u + 1u)\n"
"#define __UINT64_MAX__ (__INT64_MAX__ * 2u + 1u)\n"
#if defined(__linux__)
"#define __WCHAR_MAX__ 0x7fffffff\n"
#else
"#define __WCHAR_MAX__ 2147483647\n"
#endif
"#define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)\n"
"#define __SCHAR_MAX__ __INT8_MAX__\n"
"#define __SHRT_MAX__ __INT16_MAX__\n"
"#define __INT_MAX__ __INT32_MAX__\n"
Expand Down
6 changes: 2 additions & 4 deletions mir/c2mir/x86_64/mirc_x86_64_stddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ static char stddef_str[]
"typedef unsigned long size_t;\n"
#endif
"typedef long double max_align_t;\n"
#if defined(__APPLE__)
"typedef int wchar_t;\n"
#elif defined(_WIN32)
#if defined(_WIN32)
"typedef unsigned short wchar_t;\n"
#else
"typedef unsigned int wchar_t;\n"
"typedef int wchar_t;\n"
#endif
"\n"
#if !defined(__APPLE__) && !defined(_WIN32)
Expand Down
9 changes: 6 additions & 3 deletions mir/c2mir/x86_64/mirc_x86_64_stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ static char stdint_str[]
"\n"
"#define SIZE_MAX (18446744073709551615UL)\n"
"\n"
"/* For signed wchar_t and wint_t: */\n"
"#define WCHAR_MIN INT32_MIN\n"
"#define WCHAR_MAX INT32_MAX\n"
"#ifndef WCHAR_MAX\n"
"#define WCHAR_MAX __WCHAR_MAX__\n"
"#endif\n"
"#ifndef WCHAR_MIN\n"
"#define WCHAR_MIN __WCHAR_MIN__\n"
"#endif\n"
"#define WINT_MIN WCHAR_MIN\n"
"#define WINT_MAX WCHAR_MAX\n"
"\n"
Expand Down
27 changes: 13 additions & 14 deletions mir/mir-aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/* Any small BLK type (less or equal to two quadwords) args are passed in
*fully* regs or on stack (w/o address), otherwise it is put
somehwere on stack and its address passed instead. First RBLK arg
somewhere on stack and its address passed instead. First RBLK arg
is passed in r8. Other RBLK independently of size is always passed
by address as an usual argument. */

Expand Down Expand Up @@ -66,7 +66,6 @@ struct aarch64_va_list {
void *va_arg_builtin (void *p, uint64_t t) {
struct aarch64_va_list *va = p;
MIR_type_t type = t;
int fp_p = type == MIR_T_F || type == MIR_T_D || type == MIR_T_LD;
#if defined(__APPLE__)
void *a = va->arg_area;

Expand All @@ -79,6 +78,7 @@ void *va_arg_builtin (void *p, uint64_t t) {
if (type == MIR_T_F || type == MIR_T_I32) a = (char *) a + 4; /* 2nd word of doubleword */
#endif
#else
int fp_p = type == MIR_T_F || type == MIR_T_D || type == MIR_T_LD;
void *a;

if (fp_p && va->__vr_offs < 0) {
Expand Down Expand Up @@ -318,7 +318,6 @@ void *_MIR_get_ff_call (MIR_context_t ctx, size_t nres, MIR_type_t *res_types, s
MIR_type_t type;
uint32_t n_xregs = 0, n_vregs = 0, sp_offset = 0, blk_offset = 0, pat, offset_imm, scale;
uint32_t sp = 31, addr_reg, qwords;
uint32_t *addr;
const uint32_t temp_reg = 10; /* x10 */
VARR (uint8_t) * code;
void *res;
Expand Down Expand Up @@ -460,15 +459,7 @@ void *_MIR_get_ff_call (MIR_context_t ctx, size_t nres, MIR_type_t *res_types, s
/* Transform C call to call of void handler (MIR_context_t ctx, MIR_item_t func_item,
va_list va, MIR_val_t *results) */
void *_MIR_get_interp_shim (MIR_context_t ctx, MIR_item_t func_item, void *handler) {
static const uint32_t temp_reg = 10; /* x10 */
static const uint32_t save_x19_pat = 0xf81f0ff3; /* str x19, [sp,-16]! */
static const uint32_t add_x2_sp = 0x910003e2; /* add x2, sp, X*/
static const uint32_t set_gr_offs = 0x128007e9; /* mov w9, #-64 # gr_offs */
static const uint32_t set_x8_gr_offs = 0x128008e9; /* mov w9, #-72 # gr_offs */
static const uint32_t arg_mov_start_pat[] = {
0x910003e9, /* mov x9,sp */
0xd10003ff, /* sub sp, sp, <frame size:10-21> # non-varg */
};
static const uint32_t save_x19_pat = 0xf81f0ff3; /* str x19, [sp,-16]! */
static const uint32_t prepare_pat[] = {
#if !defined(__APPLE__)
0xd10083ff, /* sub sp, sp, 32 # allocate va_list */
Expand Down Expand Up @@ -509,17 +500,22 @@ void *_MIR_get_interp_shim (MIR_context_t ctx, MIR_item_t func_item, void *handl
uint32_t pat, imm, n_xregs, n_vregs, offset, offset_imm;
MIR_func_t func = func_item->u.func;
uint32_t nres = func->nres;
int x8_res_p = func->nargs != 0 && VARR_GET (MIR_var_t, func->vars, 0).type == MIR_T_RBLK;
MIR_type_t *results = func->res_types;
VARR (uint8_t) * code;
void *res;
uint32_t base_reg_mask = ~(uint32_t) (0x3f << 5);

VARR_CREATE (uint8_t, code, 128);
#if defined(__APPLE__)
int stack_arg_sp_offset, sp_offset, scale;
uint32_t qwords, sp = 31;
uint32_t base_reg_mask = ~(uint32_t) (0x3f << 5);
static const uint32_t temp_reg = 10; /* x10 */
MIR_type_t type;
static const uint32_t add_x2_sp = 0x910003e2; /* add x2, sp, X*/
static const uint32_t arg_mov_start_pat[] = {
0x910003e9, /* mov x9,sp */
0xd10003ff, /* sub sp, sp, <frame size:10-21> # non-varg */
};

assert (__SIZEOF_LONG_DOUBLE__ == 8);
push_insns (code, arg_mov_start_pat, sizeof (arg_mov_start_pat));
Expand Down Expand Up @@ -605,6 +601,9 @@ void *_MIR_get_interp_shim (MIR_context_t ctx, MIR_item_t func_item, void *handl
((uint32_t *) VARR_ADDR (uint8_t, code))[1] |= sp_offset << 10;
push_insns (code, &save_x19_pat, sizeof (save_x19_pat));
#else
static const uint32_t set_gr_offs = 0x128007e9; /* mov w9, #-64 # gr_offs */
static const uint32_t set_x8_gr_offs = 0x128008e9; /* mov w9, #-72 # gr_offs */
int x8_res_p = func->nargs != 0 && VARR_GET (MIR_var_t, func->vars, 0).type == MIR_T_RBLK;
push_insns (code, &save_x19_pat, sizeof (save_x19_pat));
push_insns (code, save_insns, sizeof (save_insns));
if (x8_res_p)
Expand Down
Loading

0 comments on commit 69ac558

Please sign in to comment.