Skip to content

Commit

Permalink
#169 sync with latest v0.1.2 version of MIR
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed Jan 13, 2023
1 parent 2862027 commit f36430d
Show file tree
Hide file tree
Showing 76 changed files with 234 additions and 147 deletions.
2 changes: 1 addition & 1 deletion mir/c2mir/aarch64/caarch64-ABI-code.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2018-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2018-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
aarch64 call ABI target specific code.
*/

Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/aarch64/caarch64-code.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

#include "../mirc.h"
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/aarch64/caarch64.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

#include <stdint.h>
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/aarch64/mirc_aarch64_float.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See C11 5.2.4.2.2 */
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/aarch64/mirc_aarch64_limits.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See 5.2.4.2 */
Expand Down
13 changes: 12 additions & 1 deletion mir/c2mir/aarch64/mirc_aarch64_linux.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

static char aarch64_mirc[]
Expand Down Expand Up @@ -117,6 +117,17 @@ static char aarch64_mirc[]
"#define linux 1\n"
"#define __unix 1\n"
"#define __unix__ 1\n"
#ifndef __GNU_LIBRARY__
"typedef struct {\n"
" void *__stack;\n"
" void *__gr_top;\n"
" void *__vr_top;\n"
" int __gr_offs;\n"
" int __vr_offs;\n"
"} __builtin_va_list[1];\n"
"typedef __builtin_va_list va_list;\n"
"#define __DEFINED_va_list\n"
#endif
#elif defined(__APPLE__)
"#define __APPLE__ 1\n"
"#define __arm64__\n"
Expand Down
4 changes: 2 additions & 2 deletions mir/c2mir/aarch64/mirc_aarch64_stdarg.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

static char stdarg_str[]
Expand All @@ -8,7 +8,7 @@ static char stdarg_str[]
"\n"
#if defined(__APPLE__)
"typedef __darwin_va_list va_list;\n"
#else
#elif defined(__GNU_LIBRARY__)
"typedef struct {\n"
" void *__stack;\n"
" void *__gr_top;\n"
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/aarch64/mirc_aarch64_stddef.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See C11 7.19 */
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/aarch64/mirc_aarch64_stdint.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See C11 7.20 */
Expand Down
45 changes: 28 additions & 17 deletions mir/c2mir/c2mir.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2018-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2018-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* C to MIR compiler. It is a four pass compiler:
Expand Down Expand Up @@ -1702,7 +1702,7 @@ static token_t get_next_pptoken_1 (c2m_ctx_t c2m_ctx, int header_p) {
} else {
VARR_PUSH (char, symbol_text, curr_c);
VARR_PUSH (char, symbol_text, '\0');
return new_token_wo_uniq_repr (c2m_ctx, pos, VARR_ADDR (char, symbol_text), curr_c,
return new_token_wo_uniq_repr (c2m_ctx, cs->pos, VARR_ADDR (char, symbol_text), curr_c,
N_IGNORE);
}
}
Expand Down Expand Up @@ -5914,7 +5914,12 @@ static int basic_type_size (enum basic_type bt) {
}
}

static int basic_type_align (enum basic_type bt) { return basic_type_size (bt); }
static int basic_type_align (enum basic_type bt) {
#ifdef MIR_LDOUBLE_ALIGN
if (bt == TP_LDOUBLE) return MIR_LDOUBLE_ALIGN;
#endif
return basic_type_size (bt);
}

static int type_align (struct type *type) {
assert (type->align >= 0);
Expand Down Expand Up @@ -8250,9 +8255,15 @@ static void process_func_decls_for_allocation (c2m_ctx_t c2m_ctx) {
}
}

#define BUILTIN_VA_START "__builtin_va_start"
#define BUILTIN_VA_ARG "__builtin_va_arg"
#define ALLOCA "alloca"
#define BUILTIN_VA_START (const char *[]){"__builtin_va_start", NULL}
#define BUILTIN_VA_ARG (const char *[]){"__builtin_va_arg", NULL}
#define ALLOCA (const char *[]){"alloca", "__builtin_alloca", NULL}

static int str_eq_p (const char *str, const char *v[]) {
for (int i = 0; v[i] != NULL; i++)
if (strcmp (v[i], str) == 0) return TRUE;
return FALSE;
}

static void check (c2m_ctx_t c2m_ctx, node_t r, node_t context) {
check_ctx_t check_ctx = c2m_ctx->check_ctx;
Expand Down Expand Up @@ -8969,10 +8980,10 @@ static void check (c2m_ctx_t c2m_ctx, node_t r, node_t context) {
int builtin_call_p, alloca_p, va_arg_p = FALSE, va_start_p = FALSE;

op1 = NL_HEAD (r->u.ops);
alloca_p = op1->code == N_ID && strcmp (op1->u.s.s, ALLOCA) == 0;
alloca_p = op1->code == N_ID && str_eq_p (op1->u.s.s, ALLOCA);
if (op1->code == N_ID && find_def (c2m_ctx, S_REGULAR, op1, curr_scope, NULL) == NULL) {
va_arg_p = strcmp (op1->u.s.s, BUILTIN_VA_ARG) == 0;
va_start_p = strcmp (op1->u.s.s, BUILTIN_VA_START) == 0;
va_arg_p = str_eq_p (op1->u.s.s, BUILTIN_VA_ARG);
va_start_p = str_eq_p (op1->u.s.s, BUILTIN_VA_START);
if (!va_arg_p && !va_start_p && !alloca_p) {
/* N_SPEC_DECL (N_SHARE (N_LIST (N_INT)), N_DECL (N_ID, N_FUNC (N_LIST)), N_IGNORE) */
spec_list = new_node (c2m_ctx, N_LIST);
Expand Down Expand Up @@ -9010,11 +9021,11 @@ static void check (c2m_ctx_t c2m_ctx, node_t r, node_t context) {
}
ret_type = &res_type;
if (va_start_p && NL_LENGTH (arg_list->u.ops) != 1) {
error (c2m_ctx, POS (op1), "wrong number of arguments in %s call", BUILTIN_VA_START);
error (c2m_ctx, POS (op1), "wrong number of arguments in %s call", op1->u.s.s);
} else if (alloca_p && NL_LENGTH (arg_list->u.ops) != 1) {
error (c2m_ctx, POS (op1), "wrong number of arguments in %s call", ALLOCA);
error (c2m_ctx, POS (op1), "wrong number of arguments in %s call", op1->u.s.s);
} else if (va_arg_p && NL_LENGTH (arg_list->u.ops) != 2) {
error (c2m_ctx, POS (op1), "wrong number of arguments in %s call", BUILTIN_VA_ARG);
error (c2m_ctx, POS (op1), "wrong number of arguments in %s call", op1->u.s.s);
} else {
/* first argument type ??? */
if (va_arg_p) {
Expand Down Expand Up @@ -9258,8 +9269,8 @@ static void check (c2m_ctx_t c2m_ctx, node_t r, node_t context) {
symbol_t sym;
struct node_scope *ns;

if (strcmp (id->u.s.s, ALLOCA) == 0 || strcmp (id->u.s.s, BUILTIN_VA_START) == 0
|| strcmp (id->u.s.s, BUILTIN_VA_ARG) == 0) {
if (str_eq_p (id->u.s.s, ALLOCA) || str_eq_p (id->u.s.s, BUILTIN_VA_START)
|| str_eq_p (id->u.s.s, BUILTIN_VA_ARG)) {
error (c2m_ctx, POS (id), "%s is a builtin function", id->u.s.s);
break;
}
Expand Down Expand Up @@ -12129,9 +12140,9 @@ static op_t gen (c2m_ctx_t c2m_ctx, node_t r, MIR_label_t true_label, MIR_label_
MIR_item_t proto_item;
MIR_insn_t call_insn;
mir_size_t saved_call_arg_area_offset_before_args, arg_area_offset;
int va_arg_p = call_expr->builtin_call_p && strcmp (func->u.s.s, BUILTIN_VA_ARG) == 0;
int va_start_p = call_expr->builtin_call_p && strcmp (func->u.s.s, BUILTIN_VA_START) == 0;
int alloca_p = call_expr->builtin_call_p && strcmp (func->u.s.s, ALLOCA) == 0;
int va_arg_p = call_expr->builtin_call_p && str_eq_p (func->u.s.s, BUILTIN_VA_ARG);
int va_start_p = call_expr->builtin_call_p && str_eq_p (func->u.s.s, BUILTIN_VA_START);
int alloca_p = call_expr->builtin_call_p && str_eq_p (func->u.s.s, ALLOCA);
int builtin_call_p = alloca_p || va_arg_p || va_start_p, inline_p = FALSE;
node_t block = NL_EL (curr_func_def->u.ops, 3);
struct node_scope *ns = block->attr;
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/c2mir.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

#ifndef C2MIR_H
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/mirc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

static const char mirc[]
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/mirc_iso646.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See C11 7.9 */
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/mirc_stdalign.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See C11 7.15 */
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/mirc_stdbool.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See C11 7.18 */
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/mirc_stdnoreturn.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See C11 7.23 */
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/ppc64/cppc64-ABI-code.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2018-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2018-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
ppc64 call ABI target specific code.
*/

Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/ppc64/cppc64-code.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

#include "../mirc.h"
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/ppc64/cppc64.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

#include <stdint.h>
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/ppc64/mirc_ppc64_float.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See C11 5.2.4.2.2 */
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/ppc64/mirc_ppc64_limits.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See 5.2.4.2 */
Expand Down
7 changes: 6 additions & 1 deletion mir/c2mir/ppc64/mirc_ppc64_linux.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

static char ppc64_mirc[]
Expand Down Expand Up @@ -113,6 +113,11 @@ static char ppc64_mirc[]
"#define linux 1\n"
"#define __unix 1\n"
"#define __unix__ 1\n"
#ifndef __GNU_LIBRARY__
"typedef void *__builtin_va_list[1];\n"
"typedef __builtin_va_list va_list;\n"
"#define __DEFINED_va_list\n"
#endif
#endif
"\n"
"void *alloca (unsigned long);\n";
4 changes: 3 additions & 1 deletion mir/c2mir/ppc64/mirc_ppc64_stdarg.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

static char stdarg_str[]
= "#ifndef __STDARG_H\n"
"#define __STDARG_H\n"
"\n"
#if defined(__GNU_LIBRARY__)
"typedef void *va_list[1];\n"
"\n"
#endif
"#define va_start(ap, param) __builtin_va_start (ap)\n"
"#define va_arg(ap, type) __builtin_va_arg(ap, (type *) 0)\n"
"#define va_end(ap) 0\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
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See C11 7.19 */
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/ppc64/mirc_ppc64_stdint.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See C11 7.20 */
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/riscv64/criscv64-ABI-code.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2018-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2018-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
riscv64 call ABI target specific code.
*/

Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/riscv64/criscv64-code.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

#include "../mirc.h"
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/riscv64/criscv64.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

#include <stdint.h>
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/riscv64/mirc_riscv64_float.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See C11 5.2.4.2.2 */
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/riscv64/mirc_riscv64_limits.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See 5.2.4.2 */
Expand Down
9 changes: 8 additions & 1 deletion mir/c2mir/riscv64/mirc_riscv64_linux.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

static char riscv64_mirc[]
Expand Down Expand Up @@ -109,5 +109,12 @@ static char riscv64_mirc[]
"#define linux 1\n"
"#define __unix 1\n"
"#define __unix__ 1\n"
#ifndef __GNU_LIBRARY__
"typedef struct {\n"
" void *arg_area;\n"
"} __builtin_va_list;\n"
"typedef __builtin_va_list va_list;\n"
"#define __DEFINED_va_list\n"
#endif
"\n"
"void *alloca (unsigned long);\n";
4 changes: 3 additions & 1 deletion mir/c2mir/riscv64/mirc_riscv64_stdarg.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

static char stdarg_str[]
= "#ifndef __STDARG_H\n"
"#define __STDARG_H\n"
"\n"
#if defined(__GNU_LIBRARY__)
"typedef struct {\n"
" void *arg_area;\n"
"} va_list;\n"
"\n"
#endif
"#define va_start(ap, param) __builtin_va_start (ap)\n"
"#define va_arg(ap, type) __builtin_va_arg(ap, (type *) 0)\n"
"#define va_end(ap) 0\n"
Expand Down
2 changes: 1 addition & 1 deletion mir/c2mir/riscv64/mirc_riscv64_stddef.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020-2023 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

/* See C11 7.19 */
Expand Down
Loading

0 comments on commit f36430d

Please sign in to comment.