diff --git a/ir.c b/ir.c index 6c1c4e0..8d0379e 100644 --- a/ir.c +++ b/ir.c @@ -28,6 +28,7 @@ #include "ir.h" #include "ir_private.h" +#include #include #ifdef HAVE_VALGRIND @@ -70,13 +71,13 @@ const char *ir_op_name[IR_LAST_OP] = { void ir_print_const(const ir_ctx *ctx, const ir_insn *insn, FILE *f, bool quoted) { if (insn->op == IR_FUNC || insn->op == IR_SYM) { - fprintf(f, "%s", ir_get_str(ctx, insn->val.i32)); + fprintf(f, "%s", ir_get_str(ctx, insn->val.name)); return; } else if (insn->op == IR_STR) { if (quoted) { - fprintf(f, "\"%s\"", ir_get_str(ctx, insn->val.i32)); + fprintf(f, "\"%s\"", ir_get_str(ctx, insn->val.str)); } else { - fprintf(f, "%s", ir_get_str(ctx, insn->val.i32)); + fprintf(f, "%s", ir_get_str(ctx, insn->val.str)); } return; } @@ -217,6 +218,7 @@ void ir_print_const(const ir_ctx *ctx, const ir_insn *insn, FILE *f, bool quoted #define ir_op_kind_var IR_OPND_DATA #define ir_op_kind_prb IR_OPND_PROB #define ir_op_kind_opt IR_OPND_PROB +#define ir_op_kind_pro IR_OPND_PROTO #define _IR_OP_FLAGS(name, flags, op1, op2, op3) \ IR_OP_FLAGS(ir_op_flag_ ## flags, ir_op_kind_ ## op1, ir_op_kind_ ## op2, ir_op_kind_ ## op3), @@ -562,34 +564,36 @@ ir_ref ir_const_addr(ir_ctx *ctx, uintptr_t c) return ir_const(ctx, val, IR_ADDR); } -ir_ref ir_const_func_addr(ir_ctx *ctx, uintptr_t c, uint16_t flags) +ir_ref ir_const_func_addr(ir_ctx *ctx, uintptr_t c, ir_ref proto) { if (c == 0) { return IR_NULL; } ir_val val; val.u64 = c; - return ir_const_ex(ctx, val, IR_ADDR, IR_OPTX(IR_FUNC_ADDR, IR_ADDR, flags)); + IR_ASSERT(proto >= 0 && proto < 0xffff); + return ir_const_ex(ctx, val, IR_ADDR, IR_OPTX(IR_FUNC_ADDR, IR_ADDR, proto)); } -ir_ref ir_const_func(ir_ctx *ctx, ir_ref str, uint16_t flags) +ir_ref ir_const_func(ir_ctx *ctx, ir_ref str, ir_ref proto) { ir_val val; - val.addr = str; - return ir_const_ex(ctx, val, IR_ADDR, IR_OPTX(IR_FUNC, IR_ADDR, flags)); + val.u64 = str; + IR_ASSERT(proto >= 0 && proto < 0xffff); + return ir_const_ex(ctx, val, IR_ADDR, IR_OPTX(IR_FUNC, IR_ADDR, proto)); } ir_ref ir_const_sym(ir_ctx *ctx, ir_ref str) { ir_val val; - val.addr = str; + val.u64 = str; return ir_const_ex(ctx, val, IR_ADDR, IR_OPTX(IR_SYM, IR_ADDR, 0)); } ir_ref ir_const_str(ir_ctx *ctx, ir_ref str) { ir_val val; - val.addr = str; + val.u64 = str; return ir_const_ex(ctx, val, IR_ADDR, IR_OPTX(IR_STR, IR_ADDR, 0)); } @@ -620,6 +624,101 @@ const char *ir_get_str(const ir_ctx *ctx, ir_ref idx) return ir_strtab_str(&ctx->strtab, idx - 1); } +const char *ir_get_strl(const ir_ctx *ctx, ir_ref idx, size_t *len) +{ + IR_ASSERT(ctx->strtab.data); + return ir_strtab_strl(&ctx->strtab, idx - 1, len); +} + +ir_ref ir_proto_0(ir_ctx *ctx, uint8_t flags, ir_type ret_type) +{ + ir_proto_t proto; + + proto.flags = flags; + proto.ret_type = ret_type; + proto.params_count = 0; + return ir_strl(ctx, (const char *)&proto, offsetof(ir_proto_t, param_types) + 0); +} + +ir_ref ir_proto_1(ir_ctx *ctx, uint8_t flags, ir_type ret_type, ir_type t1) +{ + ir_proto_t proto; + + proto.flags = flags; + proto.ret_type = ret_type; + proto.params_count = 1; + proto.param_types[0] = t1; + return ir_strl(ctx, (const char *)&proto, offsetof(ir_proto_t, param_types) + 1); +} + +ir_ref ir_proto_2(ir_ctx *ctx, uint8_t flags, ir_type ret_type, ir_type t1, ir_type t2) +{ + ir_proto_t proto; + + proto.flags = flags; + proto.ret_type = ret_type; + proto.params_count = 2; + proto.param_types[0] = t1; + proto.param_types[1] = t2; + return ir_strl(ctx, (const char *)&proto, offsetof(ir_proto_t, param_types) + 2); +} + +ir_ref ir_proto_3(ir_ctx *ctx, uint8_t flags, ir_type ret_type, ir_type t1, ir_type t2, ir_type t3) +{ + ir_proto_t proto; + + proto.flags = flags; + proto.ret_type = ret_type; + proto.params_count = 3; + proto.param_types[0] = t1; + proto.param_types[1] = t2; + proto.param_types[2] = t3; + return ir_strl(ctx, (const char *)&proto, offsetof(ir_proto_t, param_types) + 3); +} + +ir_ref ir_proto_4(ir_ctx *ctx, uint8_t flags, ir_type ret_type, ir_type t1, ir_type t2, ir_type t3, + ir_type t4) +{ + ir_proto_t proto; + + proto.flags = flags; + proto.ret_type = ret_type; + proto.params_count = 4; + proto.param_types[0] = t1; + proto.param_types[1] = t2; + proto.param_types[2] = t3; + proto.param_types[3] = t4; + return ir_strl(ctx, (const char *)&proto, offsetof(ir_proto_t, param_types) + 4); +} + +ir_ref ir_proto_5(ir_ctx *ctx, uint8_t flags, ir_type ret_type, ir_type t1, ir_type t2, ir_type t3, + ir_type t4, ir_type t5) +{ + ir_proto_t proto; + + proto.flags = flags; + proto.ret_type = ret_type; + proto.params_count = 5; + proto.param_types[0] = t1; + proto.param_types[1] = t2; + proto.param_types[2] = t3; + proto.param_types[3] = t4; + proto.param_types[4] = t5; + return ir_strl(ctx, (const char *)&proto, offsetof(ir_proto_t, param_types) + 5); +} + +ir_ref ir_proto(ir_ctx *ctx, uint8_t flags, ir_type ret_type, uint32_t params_count, uint8_t *param_types) +{ + ir_proto_t *proto = alloca(offsetof(ir_proto_t, param_types) + params_count); + + IR_ASSERT(params_count <= IR_MAX_PROTO_PARAMS); + proto->flags = flags; + proto->ret_type = ret_type; + proto->params_count = params_count; + memcpy(proto->param_types, param_types, params_count); + return ir_strl(ctx, (const char *)proto, offsetof(ir_proto_t, param_types) + params_count); +} + /* IR construction */ ir_ref ir_emit(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3) { diff --git a/ir.g b/ir.g index 2e04bab..94d124d 100644 --- a/ir.g +++ b/ir.g @@ -132,7 +132,7 @@ ir(ir_loader *loader): {uint32_t flags = 0;} {size_t size;} {uint32_t params_count;} - {ir_type param_types[256];} + {uint8_t param_types[256];} {p.ctx = &ctx;} ( ( @@ -149,7 +149,8 @@ ir(ir_loader *loader): } | {flags = 0;} - ir_func_prototype(&p, name, &flags, &ret_type, ¶ms_count, param_types) + ir_func_name(name) + ir_func_proto(&p, &flags, &ret_type, ¶ms_count, param_types) ";" { if (loader->external_func_dcl @@ -187,7 +188,8 @@ ir(ir_loader *loader): } ) | - ir_func_prototype(&p, name, &flags, &ret_type, ¶ms_count, param_types) + ir_func_name(name) + ir_func_proto(&p, &flags, &ret_type, ¶ms_count, param_types) ( ";" { @@ -296,15 +298,18 @@ ir_func(ir_parser_ctx *p): {ir_strtab_free(&p->var_tab);} ; -ir_func_prototype(ir_parser_ctx *p, char *buf, uint32_t *flags, uint8_t *ret_type, uint32_t *params_count, ir_type *param_types): +ir_func_name(char *buf): {const char *name;} {size_t len;} - {uint8_t t = 0;} - {uint32_t n = 0;} "func" ID(&name, &len) {if (len > 255) yy_error("name too long");} {memcpy(buf, name, len);} {buf[len] = 0;} +; + +ir_func_proto(ir_parser_ctx *p, uint32_t *flags, uint8_t *ret_type, uint32_t *params_count, uint8_t *param_types): + {uint8_t t = 0;} + {uint32_t n = 0;} "(" ( "void" @@ -336,6 +341,10 @@ ir_func_prototype(ir_parser_ctx *p, char *buf, uint32_t *flags, uint8_t *ret_typ "void" {*ret_type = IR_VOID;} ) + ( + "__fastcall" + {*flags |= IR_FASTCALL_FUNC;} + )? {*params_count = n;} ; @@ -350,8 +359,11 @@ ir_insn(ir_parser_ctx *p): {ir_ref ref;} {ir_val val;} {ir_val count;} - {ir_val flags;} {int32_t n;} + {uint8_t ret_type;} + {uint32_t flags;} + {uint32_t params_count;} + {uint8_t param_types[256];} ( type(&t) ID(&str, &len) @@ -366,25 +378,23 @@ ir_insn(ir_parser_ctx *p): ( {val.u64 = 0;} const(t, &val) {ref = ir_const(p->ctx, val, t);} - | "func" "(" ID(&func, &func_len) - {flags.u64 = 0;} - ( "," - DECNUMBER(IR_U16, &flags) - )? - ")" - {ref = ir_const_func(p->ctx, ir_strl(p->ctx, func, func_len), flags.u16);} + | "func" + ( ID(&func, &func_len) + {flags = 0;} + ir_func_proto(p, &flags, &ret_type, ¶ms_count, param_types) + {ref = ir_proto(p->ctx, flags, ret_type, params_count, param_types);} + {ref = ir_const_func(p->ctx, ir_strl(p->ctx, func, func_len), ref);} + | "*" + ( DECNUMBER(IR_ADDR, &val) + | HEXNUMBER(IR_ADDR, &val) + ) + {flags = 0;} + ir_func_proto(p, &flags, &ret_type, ¶ms_count, param_types) + {ref = ir_proto(p->ctx, flags, ret_type, params_count, param_types);} + {ref = ir_const_func_addr(p->ctx, val.addr, ref);} + ) | "sym" "(" ID(&func, &func_len) ")" {ref = ir_const_sym(p->ctx, ir_strl(p->ctx, func, func_len));} - | "func_addr" "(" - ( DECNUMBER(IR_ADDR, &val) - | HEXNUMBER(IR_ADDR, &val) - ) - {flags.u64 = 0;} - ( "," - DECNUMBER(IR_U16, &flags) - )? - ")" - {ref = ir_const_func_addr(p->ctx, val.addr, flags.u16);} | STRING(&func, &func_len) {ref = ir_const_str(p->ctx, ir_strl(p->ctx, func, func_len));} | func(&op) @@ -475,6 +485,10 @@ val(ir_parser_ctx *p, uint8_t op, uint32_t n, ir_ref *ref): {size_t len;} {ir_val val;} {uint32_t kind = IR_OPND_KIND(ir_op_flags[op], n);} + {uint8_t ret_type;} + {uint32_t flags;} + {uint32_t params_count;} + {uint8_t param_types[256];} ( ID(&str, &len) {if (!IR_IS_REF_OPND_KIND(kind)) yy_error("unexpected reference");} {*ref = ir_use_var(p, n, str, len);} @@ -487,6 +501,11 @@ val(ir_parser_ctx *p, uint8_t op, uint32_t n, ir_ref *ref): {*ref = val.i32;} | "null" {*ref = IR_UNUSED;} + | "func" + {if (kind != IR_OPND_PROTO) yy_error("unexpected function prototype");} + {flags = 0;} + ir_func_proto(p, &flags, &ret_type, ¶ms_count, param_types) + {*ref = ir_proto(p->ctx, flags, ret_type, params_count, param_types);} ) ; diff --git a/ir.h b/ir.h index 669f94e..7b5d4f8 100644 --- a/ir.h +++ b/ir.h @@ -186,6 +186,7 @@ typedef enum _ir_type { * num - number: argument number (PARAM) * prb - branch probability 1-99 (0 - unspecified): (IF_TRUE, IF_FALSE, CASE_VAL, CASE_DEFAULT) * opt - optional number + * pro - function prototype * * The order of IR opcodes is carefully selected for efficient folding. * - foldable instruction go first @@ -246,6 +247,7 @@ typedef enum _ir_type { _(INT2FP, d1, def, ___, ___) /* int to float conversion */ \ _(FP2INT, d1, def, ___, ___) /* float to int conversion */ \ _(FP2FP, d1, def, ___, ___) /* float to float conversion */ \ + _(PROTO, d1X1, def, pro, ___) /* apply function prototype */ \ \ /* overflow-check */ \ _(ADD_OV, d2C, def, def, ___) /* addition */ \ @@ -376,7 +378,6 @@ typedef int32_t ir_ref; #define IR_CONSTS_LIMIT_MIN (-(IR_TRUE - 1)) #define IR_INSNS_LIMIT_MIN (IR_UNUSED + 1) - #ifndef IR_64 # define ADDR_MEMBER uintptr_t addr; #else @@ -395,6 +396,8 @@ typedef union _ir_val { int32_t i32; float f; ADDR_MEMBER + ir_ref name; + ir_ref str; IR_STRUCT_LOHI( union { uint16_t u16; @@ -412,17 +415,11 @@ typedef union _ir_val { uint16_t u16_hi ); }, - uint32_t u32_hi + uint32_t u32_hi; ); } ir_val; #undef ADDR_MEMBER -/* IR constant flags */ -#define IR_CONST_EMIT (1<<0) -#define IR_CONST_FASTCALL_FUNC (1<<1) -#define IR_CONST_VARARG_FUNC (1<<2) -#define IR_CONST_BUILTIN_FUNC (1<<3) - /* IR Instruction */ typedef struct _ir_insn { IR_STRUCT_LOHI( @@ -438,7 +435,7 @@ typedef struct _ir_insn { union { uint16_t inputs_count; /* number of input control edges for MERGE, PHI, CALL, TAILCALL */ uint16_t prev_insn_offset; /* 16-bit backward offset from current instruction for CSE */ - uint16_t const_flags; /* flag to emit constant in rodat section */ + uint16_t proto; } ); uint32_t optx; @@ -482,6 +479,7 @@ ir_ref ir_strtab_lookup(ir_strtab *strtab, const char *str, uint32_t len, ir_ref ir_ref ir_strtab_find(const ir_strtab *strtab, const char *str, uint32_t len); ir_ref ir_strtab_update(ir_strtab *strtab, const char *str, uint32_t len, ir_ref val); const char *ir_strtab_str(const ir_strtab *strtab, ir_ref idx); +const char *ir_strtab_strl(const ir_strtab *strtab, ir_ref idx, size_t *len); void ir_strtab_apply(const ir_strtab *strtab, ir_strtab_apply_t func); void ir_strtab_free(ir_strtab *strtab); @@ -489,31 +487,32 @@ void ir_strtab_free(ir_strtab *strtab); #define IR_FUNCTION (1<<0) /* Generate a function. */ #define IR_FASTCALL_FUNC (1<<1) /* Generate a function with fastcall calling convention, x86 32-bit only. */ #define IR_VARARG_FUNC (1<<2) -#define IR_STATIC (1<<3) -#define IR_EXTERN (1<<4) -#define IR_CONST (1<<5) +#define IR_BUILTIN_FUNC (1<<3) +#define IR_STATIC (1<<4) +#define IR_EXTERN (1<<5) +#define IR_CONST (1<<6) -#define IR_SKIP_PROLOGUE (1<<6) /* Don't generate function prologue. */ -#define IR_USE_FRAME_POINTER (1<<7) -#define IR_PREALLOCATED_STACK (1<<8) -#define IR_NO_STACK_COMBINE (1<<9) -#define IR_START_BR_TARGET (1<<10) -#define IR_ENTRY_BR_TARGET (1<<11) -#define IR_GEN_ENDBR (1<<12) -#define IR_MERGE_EMPTY_ENTRIES (1<<13) +#define IR_SKIP_PROLOGUE (1<<8) /* Don't generate function prologue. */ +#define IR_USE_FRAME_POINTER (1<<9) +#define IR_PREALLOCATED_STACK (1<<10) +#define IR_NO_STACK_COMBINE (1<<11) +#define IR_START_BR_TARGET (1<<12) +#define IR_ENTRY_BR_TARGET (1<<13) +#define IR_GEN_ENDBR (1<<14) +#define IR_MERGE_EMPTY_ENTRIES (1<<15) -#define IR_OPT_FOLDING (1<<18) -#define IR_OPT_CFG (1<<19) /* merge BBs, by remove END->BEGIN nodes during CFG construction */ -#define IR_OPT_CODEGEN (1<<20) -#define IR_GEN_NATIVE (1<<23) -#define IR_GEN_CODE (1<<24) /* C or LLVM */ +#define IR_OPT_FOLDING (1<<16) +#define IR_OPT_CFG (1<<17) /* merge BBs, by remove END->BEGIN nodes during CFG construction */ +#define IR_OPT_CODEGEN (1<<18) +#define IR_GEN_NATIVE (1<<19) +#define IR_GEN_CODE (1<<20) /* C or LLVM */ /* debug related */ #ifdef IR_DEBUG -# define IR_DEBUG_SCCP (1<<27) -# define IR_DEBUG_GCM (1<<28) -# define IR_DEBUG_SCHEDULE (1<<29) -# define IR_DEBUG_RA (1<<30) +# define IR_DEBUG_SCCP (1<<27) +# define IR_DEBUG_GCM (1<<28) +# define IR_DEBUG_SCHEDULE (1<<29) +# define IR_DEBUG_RA (1<<30) #endif typedef struct _ir_ctx ir_ctx; @@ -627,9 +626,9 @@ ir_ref ir_const_char(ir_ctx *ctx, char c); ir_ref ir_const_float(ir_ctx *ctx, float c); ir_ref ir_const_double(ir_ctx *ctx, double c); ir_ref ir_const_addr(ir_ctx *ctx, uintptr_t c); -ir_ref ir_const_func_addr(ir_ctx *ctx, uintptr_t c, uint16_t flags); -ir_ref ir_const_func(ir_ctx *ctx, ir_ref str, uint16_t flags); +ir_ref ir_const_func_addr(ir_ctx *ctx, uintptr_t c, ir_ref proto); +ir_ref ir_const_func(ir_ctx *ctx, ir_ref str, ir_ref proto); ir_ref ir_const_sym(ir_ctx *ctx, ir_ref str); ir_ref ir_const_str(ir_ctx *ctx, ir_ref str); @@ -640,6 +639,26 @@ void ir_print_const(const ir_ctx *ctx, const ir_insn *insn, FILE *f, bool quoted ir_ref ir_str(ir_ctx *ctx, const char *s); ir_ref ir_strl(ir_ctx *ctx, const char *s, size_t len); const char *ir_get_str(const ir_ctx *ctx, ir_ref idx); +const char *ir_get_strl(const ir_ctx *ctx, ir_ref idx, size_t *len); + +#define IR_MAX_PROTO_PARAMS 255 + +typedef struct _ir_proto_t { + uint8_t flags; + uint8_t ret_type; + uint8_t params_count; + uint8_t param_types[5]; +} ir_proto_t; + +ir_ref ir_proto_0(ir_ctx *ctx, uint8_t flags, ir_type ret_type); +ir_ref ir_proto_1(ir_ctx *ctx, uint8_t flags, ir_type ret_type, ir_type t1); +ir_ref ir_proto_2(ir_ctx *ctx, uint8_t flags, ir_type ret_type, ir_type t1, ir_type t2); +ir_ref ir_proto_3(ir_ctx *ctx, uint8_t flags, ir_type ret_type, ir_type t1, ir_type t2, ir_type t3); +ir_ref ir_proto_4(ir_ctx *ctx, uint8_t flags, ir_type ret_type, ir_type t1, ir_type t2, ir_type t3, + ir_type t4); +ir_ref ir_proto_5(ir_ctx *ctx, uint8_t flags, ir_type ret_type, ir_type t1, ir_type t2, ir_type t3, + ir_type t4, ir_type t5); +ir_ref ir_proto(ir_ctx *ctx, uint8_t flags, ir_type ret_type, uint32_t params_counts, uint8_t *param_types); ir_ref ir_emit(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3); @@ -768,9 +787,9 @@ struct _ir_loader { bool (*init_module) (ir_loader *loader, const char *name, const char *filename, const char *target); bool (*external_sym_dcl) (ir_loader *loader, const char *name, uint32_t flags); bool (*external_func_dcl) (ir_loader *loader, const char *name, - uint32_t flags, ir_type ret_type, uint32_t params_count, ir_type *param_types); + uint32_t flags, ir_type ret_type, uint32_t params_count, const uint8_t *param_types); bool (*forward_func_dcl) (ir_loader *loader, const char *name, - uint32_t flags, ir_type ret_type, uint32_t params_count, ir_type *param_types); + uint32_t flags, ir_type ret_type, uint32_t params_count, const uint8_t *param_types); bool (*sym_dcl) (ir_loader *loader, const char *name, uint32_t flags, size_t size, bool has_data); bool (*sym_data) (ir_loader *loader, ir_type type, uint32_t count, const void *data); bool (*sym_data_ref) (ir_loader *loader, ir_op op, const char *ref); @@ -789,6 +808,7 @@ int ir_load_llvm_bitcode(ir_loader *loader, const char *filename); int ir_load_llvm_asm(ir_loader *loader, const char *filename); /* IR save API (implementation in ir_save.c) */ +void ir_print_proto(const ir_ctx *ctx, ir_ref proto, FILE *f); void ir_save(const ir_ctx *ctx, FILE *f); /* IR debug dump API (implementation in ir_dump.c) */ @@ -802,11 +822,11 @@ void ir_dump_codegen(const ir_ctx *ctx, FILE *f); /* IR to C conversion (implementation in ir_emit_c.c) */ int ir_emit_c(ir_ctx *ctx, const char *name, FILE *f); -void ir_emit_c_func_decl(const char *name, uint32_t flags, ir_type ret_type, uint32_t params_count, ir_type *param_types, FILE *f); +void ir_emit_c_func_decl(const char *name, uint32_t flags, ir_type ret_type, uint32_t params_count, const uint8_t *param_types, FILE *f); /* IR to LLVM conversion (implementation in ir_emit_llvm.c) */ int ir_emit_llvm(ir_ctx *ctx, const char *name, FILE *f); -void ir_emit_llvm_func_decl(const char *name, uint32_t flags, ir_type ret_type, uint32_t params_count, ir_type *param_types, FILE *f); +void ir_emit_llvm_func_decl(const char *name, uint32_t flags, ir_type ret_type, uint32_t params_count, const uint8_t *param_types, FILE *f); /* IR verification API (implementation in ir_check.c) */ bool ir_check(const ir_ctx *ctx); diff --git a/ir_aarch64.dasc b/ir_aarch64.dasc index 709b7af..e5b17c6 100644 --- a/ir_aarch64.dasc +++ b/ir_aarch64.dasc @@ -159,6 +159,7 @@ typedef struct _ir_backend_data { ir_reg_alloc_data ra_data; uint32_t dessa_from_block; dasm_State *dasm_state; + ir_bitset emit_constants; int rodata_label, jmp_table_label; } ir_backend_data; @@ -506,6 +507,7 @@ int ir_get_target_constraints(const ir_ctx *ctx, ir_ref ref, ir_target_constrain break; case IR_TRUNC: case IR_BITCAST: + case IR_PROTO: flags = IR_USE_MUST_BE_IN_REG | IR_OP1_SHOULD_BE_IN_REG; break; case IR_RSTORE: @@ -1126,7 +1128,7 @@ static void ir_emit_load_imm_fp(ir_ctx *ctx, ir_type type, ir_reg reg, ir_ref sr | fmov Rd(reg-IR_REG_FP_FIRST), xzr } else { label = ctx->cfg_blocks_count - src; - insn->const_flags |= IR_CONST_EMIT; + ir_bitset_incl(data->emit_constants, -src); if (type == IR_DOUBLE) { | ldr Rd(reg-IR_REG_FP_FIRST), =>label } else { @@ -4268,13 +4270,13 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg if (val_insn->op == IR_STR) { int label = ctx->cfg_blocks_count - arg; - val_insn->const_flags |= IR_CONST_EMIT; + ir_bitset_incl(data->emit_constants, -arg); | adr Rx(dst_reg), =>label continue; } else if (val_insn->op == IR_SYM || val_insn->op == IR_FUNC) { void *addr = (ctx->loader && ctx->loader->resolve_sym_name) ? - ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, val_insn->val.i32)) : - ir_resolve_sym_name(ir_get_str(ctx, val_insn->val.i32)); + ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, val_insn->val.name)) : + ir_resolve_sym_name(ir_get_str(ctx, val_insn->val.name)); ir_emit_load_imm_int(ctx, IR_ADDR, dst_reg, (intptr_t)addr); continue; } @@ -4296,14 +4298,14 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg if (val_insn->op == IR_STR) { int label = ctx->cfg_blocks_count - arg; - val_insn->const_flags |= IR_CONST_EMIT; + ir_bitset_incl(data->emit_constants, -arg); IR_ASSERT(tmp_reg != IR_REG_NONE); | adr Rx(tmp_reg), =>label | str Rx(tmp_reg), [sp, #stack_offset] } else if (val_insn->op == IR_FUNC || val_insn->op == IR_SYM) { void *addr = (ctx->loader && ctx->loader->resolve_sym_name) ? - ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, val_insn->val.i32)) : - ir_resolve_sym_name(ir_get_str(ctx, val_insn->val.i32)); + ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, val_insn->val.name)) : + ir_resolve_sym_name(ir_get_str(ctx, val_insn->val.name)); ir_emit_load_imm_int(ctx, IR_ADDR, tmp_reg, (intptr_t)addr); | str Rx(tmp_reg), [sp, #stack_offset] } else { @@ -4355,8 +4357,8 @@ static void ir_emit_call(ir_ctx *ctx, ir_ref def, ir_insn *insn) IR_ASSERT(addr_insn->type == IR_ADDR); if (addr_insn->op == IR_FUNC) { addr = (ctx->loader && ctx->loader->resolve_sym_name) ? - ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, addr_insn->val.i32)) : - ir_resolve_sym_name(ir_get_str(ctx, addr_insn->val.i32)); + ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, addr_insn->val.name)) : + ir_resolve_sym_name(ir_get_str(ctx, addr_insn->val.name)); } else { IR_ASSERT(addr_insn->op == IR_ADDR || addr_insn->op == IR_FUNC_ADDR); addr = (void*)addr_insn->val.addr; @@ -4434,8 +4436,8 @@ static void ir_emit_tailcall(ir_ctx *ctx, ir_ref def, ir_insn *insn) IR_ASSERT(addr_insn->type == IR_ADDR); if (addr_insn->op == IR_FUNC) { addr = (ctx->loader && ctx->loader->resolve_sym_name) ? - ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, addr_insn->val.i32)) : - ir_resolve_sym_name(ir_get_str(ctx, addr_insn->val.i32)); + ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, addr_insn->val.name)) : + ir_resolve_sym_name(ir_get_str(ctx, addr_insn->val.name)); } else { IR_ASSERT(addr_insn->op == IR_ADDR || addr_insn->op == IR_FUNC_ADDR); addr = (void*)addr_insn->val.addr; @@ -4817,8 +4819,8 @@ static void ir_emit_exitcall(ir_ctx *ctx, ir_ref def, ir_insn *insn) IR_ASSERT(addr_insn->type == IR_ADDR); if (addr_insn->op == IR_FUNC) { addr = (ctx->loader && ctx->loader->resolve_sym_name) ? - ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, addr_insn->val.i32)) : - ir_resolve_sym_name(ir_get_str(ctx, addr_insn->val.i32)); + ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, addr_insn->val.name)) : + ir_resolve_sym_name(ir_get_str(ctx, addr_insn->val.name)); } else { IR_ASSERT(addr_insn->op == IR_ADDR || addr_insn->op == IR_FUNC_ADDR); addr = (void*)addr_insn->val.addr; @@ -5372,6 +5374,7 @@ void *ir_emit_code(ir_ctx *ctx, size_t *size_ptr) dasm_setup(&data.dasm_state, dasm_actions); /* labels for each block + for each constant + rodata label + jmp_table label + for each entry */ dasm_growpc(&data.dasm_state, ctx->cfg_blocks_count + 1 + ctx->consts_count + 1 + 1 + 1 + ctx->entries_count); + data.emit_constants = ir_bitset_malloc(ctx->consts_count); if (!(ctx->flags & IR_SKIP_PROLOGUE)) { ir_emit_prologue(ctx); @@ -5455,6 +5458,7 @@ void *ir_emit_code(ir_ctx *ctx, size_t *size_ptr) ir_emit_trunc(ctx, i, insn); break; case IR_BITCAST: + case IR_PROTO: ir_emit_bitcast(ctx, i, insn); break; case IR_INT2FP: @@ -5612,6 +5616,7 @@ void *ir_emit_code(ir_ctx *ctx, size_t *size_ptr) break; default: IR_ASSERT(0 && "NIY rule/instruction"); + ir_mem_free(data.emit_constants); dasm_free(&data.dasm_state); ctx->data = NULL; ctx->status = IR_ERROR_UNSUPPORTED_CODE_RULE; @@ -5639,105 +5644,105 @@ void *ir_emit_code(ir_ctx *ctx, size_t *size_ptr) if (data.rodata_label) { |.rodata } - for (i = IR_UNUSED + 1, insn = ctx->ir_base - i; i < ctx->consts_count; i++, insn--) { - if (insn->const_flags & IR_CONST_EMIT) { - if (IR_IS_TYPE_FP(insn->type)) { - int label = ctx->cfg_blocks_count + i; + IR_BITSET_FOREACH(data.emit_constants, ir_bitset_len(ctx->consts_count), i) { + insn = &ctx->ir_base[-i]; + if (IR_IS_TYPE_FP(insn->type)) { + int label = ctx->cfg_blocks_count + i; - if (!data.rodata_label) { - data.rodata_label = ctx->cfg_blocks_count + ctx->consts_count + 2; + if (!data.rodata_label) { + data.rodata_label = ctx->cfg_blocks_count + ctx->consts_count + 2; - |.rodata - |=>data.rodata_label: - } - if (insn->type == IR_DOUBLE) { - |.align 8 - |=>label: - |.long insn->val.u32, insn->val.u32_hi - } else { - IR_ASSERT(insn->type == IR_FLOAT); - |.align 4 - |=>label: - |.long insn->val.u32 - } - } else if (insn->op == IR_STR) { - int label = ctx->cfg_blocks_count + i; - const char *str = ir_get_str(ctx, insn->val.i32); - int i = 0; - - if (!data.rodata_label) { - data.rodata_label = ctx->cfg_blocks_count + ctx->consts_count + 2; - - |.rodata - |=>data.rodata_label: - } + |.rodata + |=>data.rodata_label: + } + if (insn->type == IR_DOUBLE) { |.align 8 |=>label: - while (1) { - char c; - uint32_t w = 0; - int j; + |.long insn->val.u32, insn->val.u32_hi + } else { + IR_ASSERT(insn->type == IR_FLOAT); + |.align 4 + |=>label: + |.long insn->val.u32 + } + } else if (insn->op == IR_STR) { + int label = ctx->cfg_blocks_count + i; + const char *str = ir_get_str(ctx, insn->val.str); + int i = 0; - for (j = 0; j < 4; j++) { - c = str[i]; - if (!c) { - break; - } else if (c == '\\') { - if (str[i+1] == '\\') { - i++; - c = '\\'; - } else if (str[i+1] == '\'') { - i++; - c = '\''; - } else if (str[i+1] == '"') { - i++; - c = '"'; - } else if (str[i+1] == 'a') { - i++; - c = '\a'; - } else if (str[i+1] == 'b') { - i++; - c = '\b'; - } else if (str[i+1] == 'e') { - i++; - c = 27; /* '\e'; */ - } else if (str[i+1] == 'f') { - i++; - c = '\f'; - } else if (str[i+1] == 'n') { - i++; - c = '\n'; - } else if (str[i+1] == 'r') { - i++; - c = '\r'; - } else if (str[i+1] == 't') { - i++; - c = '\t'; - } else if (str[i+1] == 'v') { - i++; - c = '\v'; - } else if (str[i+1] == '?') { - i++; - c = 0x3f; - } - } - w |= c << (8 * j); - i++; - } - | .long w + if (!data.rodata_label) { + data.rodata_label = ctx->cfg_blocks_count + ctx->consts_count + 2; + + |.rodata + |=>data.rodata_label: + } + |.align 8 + |=>label: + while (1) { + char c; + uint32_t w = 0; + int j; + + for (j = 0; j < 4; j++) { + c = str[i]; if (!c) { break; + } else if (c == '\\') { + if (str[i+1] == '\\') { + i++; + c = '\\'; + } else if (str[i+1] == '\'') { + i++; + c = '\''; + } else if (str[i+1] == '"') { + i++; + c = '"'; + } else if (str[i+1] == 'a') { + i++; + c = '\a'; + } else if (str[i+1] == 'b') { + i++; + c = '\b'; + } else if (str[i+1] == 'e') { + i++; + c = 27; /* '\e'; */ + } else if (str[i+1] == 'f') { + i++; + c = '\f'; + } else if (str[i+1] == 'n') { + i++; + c = '\n'; + } else if (str[i+1] == 'r') { + i++; + c = '\r'; + } else if (str[i+1] == 't') { + i++; + c = '\t'; + } else if (str[i+1] == 'v') { + i++; + c = '\v'; + } else if (str[i+1] == '?') { + i++; + c = 0x3f; + } } + w |= c << (8 * j); + i++; + } + | .long w + if (!c) { + break; } - - } else { - IR_ASSERT(0); } + + } else { + IR_ASSERT(0); } - } + } IR_BITSET_FOREACH_END(); if (data.rodata_label) { |.code } + ir_mem_free(data.emit_constants); if (ctx->status) { dasm_free(&data.dasm_state); diff --git a/ir_dump.c b/ir_dump.c index cfd8b81..d1d601b 100644 --- a/ir_dump.c +++ b/ir_dump.c @@ -458,20 +458,14 @@ void ir_dump_codegen(const ir_ctx *ctx, FILE *f) for (i = IR_UNUSED + 1, insn = ctx->ir_base - i; i < ctx->consts_count; i++, insn--) { fprintf(f, "\t%s c_%d = ", ir_type_cname[insn->type], i); if (insn->op == IR_FUNC) { - if (!insn->const_flags) { - fprintf(f, "func(%s)", ir_get_str(ctx, insn->val.i32)); - } else { - fprintf(f, "func(%s, %d)", ir_get_str(ctx, insn->val.i32), insn->const_flags); - } + fprintf(f, "func %s", ir_get_str(ctx, insn->val.name)); + ir_print_proto(ctx, insn->proto, f); } else if (insn->op == IR_SYM) { - fprintf(f, "sym(%s)", ir_get_str(ctx, insn->val.i32)); + fprintf(f, "sym(%s)", ir_get_str(ctx, insn->val.name)); } else if (insn->op == IR_FUNC_ADDR) { - fprintf(f, "func_addr("); + fprintf(f, "func *"); ir_print_const(ctx, insn, f, true); - if (insn->const_flags) { - fprintf(f, ", %d", insn->const_flags); - } - fprintf(f, ")"); + ir_print_proto(ctx, insn->proto, f); } else { ir_print_const(ctx, insn, f, true); } @@ -564,6 +558,10 @@ void ir_dump_codegen(const ir_ctx *ctx, FILE *f) fprintf(f, "%s\"%s\"", first ? "(" : ", ", ir_get_str(ctx, ref)); first = 0; break; + case IR_OPND_PROTO: + fprintf(f, "%sfunc ", first ? "(" : ", "); + ir_print_proto(ctx, ref, f); + break; case IR_OPND_PROB: if (ref == 0) { break; diff --git a/ir_emit.c b/ir_emit.c index d6de65c..d4e3ad0 100644 --- a/ir_emit.c +++ b/ir_emit.c @@ -74,9 +74,19 @@ bool ir_is_fastcall(const ir_ctx *ctx, const ir_insn *insn) { if (sizeof(void*) == 4) { if (IR_IS_CONST_REF(insn->op2)) { - return (ctx->ir_base[insn->op2].const_flags & IR_CONST_FASTCALL_FUNC) != 0; - } else if (ctx->ir_base[insn->op2].op == IR_BITCAST) { - return (ctx->ir_base[insn->op2].op2 & IR_CONST_FASTCALL_FUNC) != 0; + const ir_insn *func = &ctx->ir_base[insn->op2]; + + if (func->op == IR_FUNC || func->op == IR_FUNC_ADDR) { + if (func->proto) { + const ir_proto_t *proto = (const ir_proto_t *)ir_get_str(ctx, func->proto); + + return (proto->flags & IR_FASTCALL_FUNC) != 0; + } + } + } else if (ctx->ir_base[insn->op2].op == IR_PROTO) { + const ir_proto_t *proto = (const ir_proto_t *)ir_get_str(ctx, ctx->ir_base[insn->op2].op2); + + return (proto->flags & IR_FASTCALL_FUNC) != 0; } return 0; } @@ -92,9 +102,19 @@ bool ir_is_fastcall(const ir_ctx *ctx, const ir_insn *insn) bool ir_is_vararg(const ir_ctx *ctx, ir_insn *insn) { if (IR_IS_CONST_REF(insn->op2)) { - return (ctx->ir_base[insn->op2].const_flags & IR_CONST_VARARG_FUNC) != 0; - } else if (ctx->ir_base[insn->op2].op == IR_BITCAST) { - return (ctx->ir_base[insn->op2].op2 & IR_CONST_VARARG_FUNC) != 0; + const ir_insn *func = &ctx->ir_base[insn->op2]; + + if (func->op == IR_FUNC || func->op == IR_FUNC_ADDR) { + if (func->proto) { + const ir_proto_t *proto = (const ir_proto_t *)ir_get_str(ctx, func->proto); + + return (proto->flags & IR_VARARG_FUNC) != 0; + } + } + } else if (ctx->ir_base[insn->op2].op == IR_PROTO) { + const ir_proto_t *proto = (const ir_proto_t *)ir_get_str(ctx, ctx->ir_base[insn->op2].op2); + + return (proto->flags & IR_VARARG_FUNC) != 0; } return 0; } @@ -309,8 +329,8 @@ static void *ir_jmp_addr(ir_ctx *ctx, ir_insn *insn, ir_insn *addr_insn) IR_ASSERT(addr_insn->type == IR_ADDR); if (addr_insn->op == IR_FUNC) { addr = (ctx->loader && ctx->loader->resolve_sym_name) ? - ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, addr_insn->val.i32)) : - ir_resolve_sym_name(ir_get_str(ctx, addr_insn->val.i32)); + ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, addr_insn->val.name)) : + ir_resolve_sym_name(ir_get_str(ctx, addr_insn->val.name)); } else { IR_ASSERT(addr_insn->op == IR_ADDR || addr_insn->op == IR_FUNC_ADDR); addr = (void*)addr_insn->val.addr; diff --git a/ir_emit_c.c b/ir_emit_c.c index 6e5683c..626fab2 100644 --- a/ir_emit_c.c +++ b/ir_emit_c.c @@ -580,7 +580,8 @@ static void ir_emit_call(ir_ctx *ctx, FILE *f, ir_ref def, ir_insn *insn) fprintf(f, "\t"); } if (IR_IS_CONST_REF(insn->op2)) { - fprintf(f, "%s", ir_get_str(ctx, ctx->ir_base[insn->op2].val.i32)); + IR_ASSERT(ctx->ir_base[insn->op2].op == IR_FUNC); + fprintf(f, "%s", ir_get_str(ctx, ctx->ir_base[insn->op2].val.name)); } else { ir_emit_ref(ctx, f, insn->op2); } @@ -605,7 +606,8 @@ static void ir_emit_tailcall(ir_ctx *ctx, FILE *f, ir_insn *insn) fprintf(f, "\t"); } if (IR_IS_CONST_REF(insn->op2)) { - fprintf(f, "%s", ir_get_str(ctx, ctx->ir_base[insn->op2].val.i32)); + IR_ASSERT(ctx->ir_base[insn->op2].op == IR_FUNC); + fprintf(f, "%s", ir_get_str(ctx, ctx->ir_base[insn->op2].val.name)); } else { ir_emit_ref(ctx, f, insn->op2); } @@ -712,7 +714,8 @@ static int ir_emit_func(ir_ctx *ctx, const char *name, FILE *f) if (ctx->flags & IR_STATIC) { fprintf(f, "static "); } - fprintf(f, "%s %s(", ir_type_cname[ctx->ret_type != (ir_type)-1 ? ctx->ret_type : IR_VOID], name); + fprintf(f, "%s %s%s(", ir_type_cname[ctx->ret_type != (ir_type)-1 ? ctx->ret_type : IR_VOID], + (ctx->flags & IR_FASTCALL_FUNC) ? "__fastcall " : "", name); use_list = &ctx->use_lists[1]; n = use_list->count; first = 1; @@ -922,6 +925,7 @@ static int ir_emit_func(ir_ctx *ctx, const char *name, FILE *f) ir_emit_trunc(ctx, f, i, insn); break; case IR_BITCAST: + case IR_PROTO: ir_emit_bitcast(ctx, f, i, insn); break; case IR_INT2FP: @@ -1047,16 +1051,20 @@ int ir_emit_c(ir_ctx *ctx, const char *name, FILE *f) return ir_emit_func(ctx, name, f); } -void ir_emit_c_func_decl(const char *name, uint32_t flags, ir_type ret_type, uint32_t params_count, ir_type *param_types, FILE *f) +void ir_emit_c_func_decl(const char *name, uint32_t flags, ir_type ret_type, uint32_t params_count, const uint8_t *param_types, FILE *f) { if (flags & IR_EXTERN) { fprintf(f, "extern "); } else if (flags & IR_STATIC) { fprintf(f, "static "); } - fprintf(f, "%s %s(", ir_type_cname[ret_type], name); + fprintf(f, "%s ", ir_type_cname[ret_type]); + if (flags & IR_FASTCALL_FUNC) { + fprintf(f, "__fastcall "); + } + fprintf(f, "%s(", name); if (params_count) { - ir_type *p = param_types; + const uint8_t *p = param_types; fprintf(f, "%s", ir_type_cname[*p]); p++; diff --git a/ir_emit_llvm.c b/ir_emit_llvm.c index 87ab107..67ab7d9 100644 --- a/ir_emit_llvm.c +++ b/ir_emit_llvm.c @@ -32,7 +32,7 @@ static void ir_emit_ref(ir_ctx *ctx, FILE *f, ir_ref ref) if (IR_IS_CONST_REF(ref)) { ir_insn *insn = &ctx->ir_base[ref]; if (insn->op == IR_FUNC || insn->op == IR_SYM) { - fprintf(f, "@%s", ir_get_str(ctx, insn->val.i32)); + fprintf(f, "@%s", ir_get_str(ctx, insn->val.name)); } else if (insn->op == IR_STR) { fprintf(f, "@.str%d", -ref); } else if (insn->op == IR_ADDR) { @@ -533,9 +533,17 @@ static void ir_emit_call(ir_ctx *ctx, FILE *f, ir_ref def, ir_insn *insn) // TODO: function prototype ??? if (IR_IS_CONST_REF(insn->op2)) { - const char *name = ir_get_str(ctx, ctx->ir_base[insn->op2].val.i32); - if (ctx->ir_base[insn->op2].const_flags & IR_CONST_BUILTIN_FUNC) { - name = ir_builtin_func_name(name, &last_arg); + const ir_insn *func = &ctx->ir_base[insn->op2]; + const char *name; + + IR_ASSERT(func->op == IR_FUNC); + name = ir_get_str(ctx, func->val.name); + if (func->proto) { + const ir_proto_t *proto = (const ir_proto_t *)ir_get_str(ctx, func->proto); + + if (proto->flags & IR_BUILTIN_FUNC) { + name = ir_builtin_func_name(name, &last_arg); + } } fprintf(f, "@%s", name); } else { @@ -651,7 +659,7 @@ static int ir_emit_func(ir_ctx *ctx, const char *name, FILE *f) fprintf(f, "internal "); } if (ctx->flags & IR_FASTCALL_FUNC) { - // TODO: + fprintf(f, "x86_fastcallcc "); } fprintf(f, "%s", ir_type_llvm_name[ctx->ret_type != (ir_type)-1 ? ctx->ret_type : IR_VOID]); fprintf(f, " @%s(", name); @@ -840,6 +848,9 @@ static int ir_emit_func(ir_ctx *ctx, const char *name, FILE *f) ir_emit_conv(ctx, f, i, insn, "bitcast"); } break; + case IR_PROTO: + ir_emit_conv(ctx, f, i, insn, "bitcast"); + break; case IR_INT2FP: IR_ASSERT(IR_IS_TYPE_FP(insn->type)); IR_ASSERT(IR_IS_TYPE_INT(ctx->ir_base[insn->op1].type)); @@ -973,19 +984,26 @@ static int ir_emit_func(ir_ctx *ctx, const char *name, FILE *f) for (i = IR_UNUSED + 1, insn = ctx->ir_base - i; i < ctx->consts_count; i++, insn--) { if (insn->op == IR_FUNC) { - const char *name = ir_get_str(ctx, insn->val.i32); - if (insn->const_flags & IR_CONST_BUILTIN_FUNC) { + const char *name; + + name = ir_get_str(ctx, insn->val.name); + if (insn->proto) { + const ir_proto_t *proto = (const ir_proto_t *)ir_get_str(ctx, insn->proto); ir_ref dummy; - name = ir_builtin_func_name(name, &dummy); + + if (proto->flags & IR_BUILTIN_FUNC) { + name = ir_builtin_func_name(name, &dummy); + } + ir_emit_llvm_func_decl(name, proto->flags, proto->ret_type, proto->params_count, proto->param_types, f); + } else { + fprintf(f, "declare void @%s()\n", name); } - // TODO: function prototype ??? - fprintf(f, "declare void @%s()\n", name); } else if (insn->op == IR_SYM) { // TODO: symbol "global" or "constant" ??? // TODO: symbol type ??? - fprintf(f, "@%s = external global ptr\n", ir_get_str(ctx, insn->val.i32)); + fprintf(f, "@%s = external global ptr\n", ir_get_str(ctx, insn->val.name)); } else if (insn->op == IR_STR) { - const char *str = ir_get_str(ctx, insn->val.i32); + const char *str = ir_get_str(ctx, insn->val.str); // TODO: strlen != size ??? int len = strlen(str); int j; @@ -1055,11 +1073,13 @@ int ir_emit_llvm(ir_ctx *ctx, const char *name, FILE *f) return ir_emit_func(ctx, name, f); } -void ir_emit_llvm_func_decl(const char *name, uint32_t flags, ir_type ret_type, uint32_t params_count, ir_type *param_types, FILE *f) +void ir_emit_llvm_func_decl(const char *name, uint32_t flags, ir_type ret_type, uint32_t params_count, const uint8_t *param_types, FILE *f) { - fprintf(f, "declare %s @%s(", ir_type_llvm_name[ret_type], name); + fprintf(f, "declare %s%s @%s(", + (flags & IR_FASTCALL_FUNC) ? "x86_fastcallcc ": "", + ir_type_llvm_name[ret_type], name); if (params_count) { - ir_type *p = param_types; + const uint8_t *p = param_types; fprintf(f, "%s", ir_type_llvm_name[*p]); p++; diff --git a/ir_gcm.c b/ir_gcm.c index 6161426..54f46de 100644 --- a/ir_gcm.c +++ b/ir_gcm.c @@ -722,8 +722,21 @@ restart: memcpy(new_insn, insn, sizeof(ir_insn) * (IR_TRUE - ref)); if (ctx->strtab.data) { while (ref != IR_TRUE) { - if (new_insn->op == IR_FUNC || new_insn->op == IR_SYM || new_insn->op == IR_STR) { - new_insn->val.addr = ir_str(&new_ctx, ir_get_str(ctx, new_insn->val.i32)); + if (new_insn->op == IR_FUNC_ADDR) { + if (new_insn->proto) { + size_t len; + const char *proto = ir_get_strl(ctx, new_insn->proto, &len); + new_insn->proto = ir_strl(&new_ctx, proto, len); + } + } else if (new_insn->op == IR_FUNC) { + new_insn->val.u64 = ir_str(&new_ctx, ir_get_str(ctx, new_insn->val.name)); + if (new_insn->proto) { + size_t len; + const char *proto = ir_get_strl(ctx, new_insn->proto, &len); + new_insn->proto = ir_strl(&new_ctx, proto, len); + } + } else if (new_insn->op == IR_SYM || new_insn->op == IR_STR) { + new_insn->val.u64 = ir_str(&new_ctx, ir_get_str(ctx, new_insn->val.name)); } new_insn++; ref++; @@ -738,8 +751,26 @@ restart: } new_insn->optx = insn->optx; new_insn->prev_const = 0; - if (insn->op == IR_FUNC || insn->op == IR_SYM || insn->op == IR_STR) { - new_insn->val.addr = ir_str(&new_ctx, ir_get_str(ctx, insn->val.i32)); + if (insn->op == IR_FUNC_ADDR) { + new_insn->val.u64 = insn->val.u64; + if (insn->proto) { + size_t len; + const char *proto = ir_get_strl(ctx, insn->proto, &len); + new_insn->proto = ir_strl(&new_ctx, proto, len); + } else { + new_insn->proto = 0; + } + } else if (insn->op == IR_FUNC) { + new_insn->val.u64 = ir_str(&new_ctx, ir_get_str(ctx, insn->val.name)); + if (insn->proto) { + size_t len; + const char *proto = ir_get_strl(ctx, insn->proto, &len); + new_insn->proto = ir_strl(&new_ctx, proto, len); + } else { + new_insn->proto = 0; + } + } else if (insn->op == IR_SYM || insn->op == IR_STR) { + new_insn->val.u64 = ir_str(&new_ctx, ir_get_str(ctx, insn->val.name)); } else { new_insn->val.u64 = insn->val.u64; } @@ -806,6 +837,10 @@ restart: new_insn->op1 = _xlat[insn->op1]; if (new_insn->op == IR_PARAM || insn->op == IR_VAR) { new_insn->op2 = ir_str(&new_ctx, ir_get_str(ctx, insn->op2)); + } else if (new_insn->op == IR_PROTO) { + size_t len; + const char *proto = ir_get_strl(ctx, insn->op2, &len); + new_insn->op2 = ir_strl(&new_ctx, proto, len); } else { new_insn->op2 = insn->op2; } diff --git a/ir_load.c b/ir_load.c index c9091cf..5114e3a 100644 --- a/ir_load.c +++ b/ir_load.c @@ -126,22 +126,23 @@ static void yy_error_str(const char *msg, const char *str); #define YY_VOID 16 #define YY__POINT_POINT_POINT 17 #define YY__COLON 18 -#define YY_FUNC_ADDR 19 -#define YY__SLASH 20 -#define YY_NULL 21 -#define YY_INF 22 -#define YY_NAN 23 -#define YY__MINUS 24 -#define YY_ID 25 -#define YY_DECNUMBER 26 -#define YY_HEXNUMBER 27 -#define YY_FLOATNUMBER 28 -#define YY_CHARACTER 29 -#define YY_STRING 30 -#define YY_EOL 31 -#define YY_WS 32 -#define YY_ONE_LINE_COMMENT 33 -#define YY_COMMENT 34 +#define YY___FASTCALL 19 +#define YY__STAR 20 +#define YY__SLASH 21 +#define YY_NULL 22 +#define YY_INF 23 +#define YY_NAN 24 +#define YY__MINUS 25 +#define YY_ID 26 +#define YY_DECNUMBER 27 +#define YY_HEXNUMBER 28 +#define YY_FLOATNUMBER 29 +#define YY_CHARACTER 30 +#define YY_STRING 31 +#define YY_EOL 32 +#define YY_WS 33 +#define YY_ONE_LINE_COMMENT 34 +#define YY_COMMENT 35 static const char * sym_name[] = { "", @@ -163,7 +164,8 @@ static const char * sym_name[] = { "void", "...", ":", - "func_addr", + "__fastcall", + "*", "/", "null", "inf", @@ -252,7 +254,8 @@ static int parse_ir_sym(int sym, char *buf, uint32_t *flags); static int parse_ir_sym_size(int sym, size_t *size); static int parse_ir_sym_data(int sym, ir_loader *loader); static int parse_ir_func(int sym, ir_parser_ctx *p); -static int parse_ir_func_prototype(int sym, ir_parser_ctx *p, char *buf, uint32_t *flags, uint8_t *ret_type, uint32_t *params_count, ir_type *param_types); +static int parse_ir_func_name(int sym, char *buf); +static int parse_ir_func_proto(int sym, ir_parser_ctx *p, uint32_t *flags, uint8_t *ret_type, uint32_t *params_count, uint8_t *param_types); static int parse_ir_insn(int sym, ir_parser_ctx *p); static int parse_type(int sym, uint8_t *t); static int parse_func(int sym, uint8_t *op); @@ -290,21 +293,21 @@ _yy_state_start: ch = *++YYPOS; if (ch != 'n') goto _yy_tunnel_4; ret = YY_EXTERN; - goto _yy_state_103; + goto _yy_state_109; case 'v': ch = *++YYPOS; if (ch == 'a') { ch = *++YYPOS; if (ch != 'r') goto _yy_tunnel_4; ret = YY_VAR; - goto _yy_state_103; + goto _yy_state_109; } else if (ch == 'o') { ch = *++YYPOS; if (ch != 'i') goto _yy_tunnel_4; ch = *++YYPOS; if (ch != 'd') goto _yy_tunnel_4; ret = YY_VOID; - goto _yy_state_103; + goto _yy_state_109; } else { goto _yy_tunnel_4; } @@ -318,7 +321,7 @@ _yy_state_start: ch = *++YYPOS; if (ch != 't') goto _yy_tunnel_4; ret = YY_CONST; - goto _yy_state_103; + goto _yy_state_109; case 'A': case 'B': case 'C': @@ -364,7 +367,6 @@ _yy_state_start: case 'x': case 'y': case 'z': - case '_': goto _yy_state_4; case 'f': ch = *++YYPOS; @@ -373,39 +375,29 @@ _yy_state_start: if (ch != 'n') goto _yy_tunnel_4; ch = *++YYPOS; if (ch != 'c') goto _yy_tunnel_4; - ch = *++YYPOS; - if (ch != '_') {ret = YY_FUNC; goto _yy_tunnel_103;} - ch = *++YYPOS; - if (ch != 'a') goto _yy_tunnel_4; - ch = *++YYPOS; - if (ch != 'd') goto _yy_tunnel_4; - ch = *++YYPOS; - if (ch != 'd') goto _yy_tunnel_4; - ch = *++YYPOS; - if (ch != 'r') goto _yy_tunnel_4; - ret = YY_FUNC_ADDR; - goto _yy_state_103; + ret = YY_FUNC; + goto _yy_state_109; case 'i': ch = *++YYPOS; if (ch != 'n') goto _yy_tunnel_4; ch = *++YYPOS; if (ch != 'f') goto _yy_tunnel_4; ret = YY_INF; - goto _yy_state_103; + goto _yy_state_109; case 'n': ch = *++YYPOS; if (ch == 'a') { ch = *++YYPOS; if (ch != 'n') goto _yy_tunnel_4; ret = YY_NAN; - goto _yy_state_103; + goto _yy_state_109; } else if (ch == 'u') { ch = *++YYPOS; if (ch != 'l') goto _yy_tunnel_4; ch = *++YYPOS; if (ch != 'l') goto _yy_tunnel_4; ret = YY_NULL; - goto _yy_state_103; + goto _yy_state_109; } else { goto _yy_tunnel_4; } @@ -421,15 +413,36 @@ _yy_state_start: ch = *++YYPOS; if (ch != 'c') goto _yy_tunnel_4; ret = YY_STATIC; - goto _yy_state_103; + goto _yy_state_109; } else if (ch == 'y') { ch = *++YYPOS; if (ch != 'm') goto _yy_tunnel_4; ret = YY_SYM; - goto _yy_state_103; + goto _yy_state_109; } else { goto _yy_tunnel_4; } + case '_': + ch = *++YYPOS; + if (ch != '_') goto _yy_tunnel_4; + ch = *++YYPOS; + if (ch != 'f') goto _yy_tunnel_4; + ch = *++YYPOS; + if (ch != 'a') goto _yy_tunnel_4; + ch = *++YYPOS; + if (ch != 's') goto _yy_tunnel_4; + ch = *++YYPOS; + if (ch != 't') goto _yy_tunnel_4; + ch = *++YYPOS; + if (ch != 'c') goto _yy_tunnel_4; + ch = *++YYPOS; + if (ch != 'a') goto _yy_tunnel_4; + ch = *++YYPOS; + if (ch != 'l') goto _yy_tunnel_4; + ch = *++YYPOS; + if (ch != 'l') goto _yy_tunnel_4; + ret = YY___FASTCALL; + goto _yy_state_109; case ';': YYPOS++; ret = YY__SEMICOLON; @@ -450,7 +463,7 @@ _yy_state_start: goto _yy_state_error; } } else if ((ch >= '0' && ch <= '9')) { - goto _yy_state_43; + goto _yy_state_46; } else { goto _yy_state_error; } @@ -475,11 +488,11 @@ _yy_state_start: accept = YY__MINUS; accept_pos = yy_pos; if ((ch >= '0' && ch <= '9')) { - goto _yy_state_18; + goto _yy_state_19; } else if (ch == '.') { ch = *++YYPOS; if ((ch >= '0' && ch <= '9')) { - goto _yy_state_43; + goto _yy_state_46; } else { goto _yy_state_error; } @@ -489,10 +502,10 @@ _yy_state_start: } case '0': ch = *++YYPOS; - if (ch != 'x') goto _yy_tunnel_18; + if (ch != 'x') goto _yy_tunnel_19; ch = *++YYPOS; if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) { - goto _yy_state_72; + goto _yy_state_76; } else { goto _yy_state_error; } @@ -505,7 +518,7 @@ _yy_state_start: case '7': case '8': case '9': - goto _yy_state_18; + goto _yy_state_19; case ']': YYPOS++; ret = YY__RBRACK; @@ -519,21 +532,25 @@ _yy_state_start: ret = YY__LBRACE; goto _yy_fin; case '\'': - goto _yy_state_22; + goto _yy_state_23; case '}': YYPOS++; ret = YY__RBRACE; goto _yy_fin; + case '*': + YYPOS++; + ret = YY__STAR; + goto _yy_fin; case '"': - goto _yy_state_24; + goto _yy_state_26; case '/': ch = *++YYPOS; accept = YY__SLASH; accept_pos = yy_pos; if (ch == '*') { - goto _yy_state_55; + goto _yy_state_58; } else if (ch == '/') { - goto _yy_state_29; + goto _yy_state_31; } else { ret = YY__SLASH; goto _yy_fin; @@ -558,9 +575,9 @@ _yy_state_start: case '\t': case '\f': case '\v': - goto _yy_state_28; + goto _yy_state_30; case '#': - goto _yy_state_29; + goto _yy_state_31; case '\0': if (ch == 0 && YYPOS < YYEND) goto _yy_state_error; YYPOS++; @@ -578,22 +595,22 @@ _yy_tunnel_4: ret = YY_ID; goto _yy_fin; } -_yy_state_18: +_yy_state_19: ch = *++YYPOS; -_yy_tunnel_18: +_yy_tunnel_19: accept = YY_DECNUMBER; accept_pos = yy_pos; if ((ch >= '0' && ch <= '9')) { - goto _yy_state_18; + goto _yy_state_19; } else if (ch == 'E' || ch == 'e') { - goto _yy_state_47; + goto _yy_state_50; } else if (ch == '.') { - goto _yy_state_43; + goto _yy_state_46; } else { ret = YY_DECNUMBER; goto _yy_fin; } -_yy_state_22: +_yy_state_23: ch = *++YYPOS; if (ch == '\\') { ch = *++YYPOS; @@ -601,7 +618,7 @@ _yy_state_22: if (ch == '\n') { yy_line++; } - goto _yy_state_22; + goto _yy_state_23; } else { goto _yy_state_error; } @@ -613,11 +630,11 @@ _yy_state_22: if (ch == '\n') { yy_line++; } - goto _yy_state_22; + goto _yy_state_23; } else { goto _yy_state_error; } -_yy_state_24: +_yy_state_26: ch = *++YYPOS; if (ch == '\\') { ch = *++YYPOS; @@ -625,7 +642,7 @@ _yy_state_24: if (ch == '\n') { yy_line++; } - goto _yy_state_24; + goto _yy_state_26; } else { goto _yy_state_error; } @@ -637,19 +654,19 @@ _yy_state_24: if (ch == '\n') { yy_line++; } - goto _yy_state_24; + goto _yy_state_26; } else { goto _yy_state_error; } -_yy_state_28: +_yy_state_30: ch = *++YYPOS; if (ch == '\t' || ch == '\v' || ch == '\f' || ch == ' ') { - goto _yy_state_28; + goto _yy_state_30; } else { ret = YY_WS; goto _yy_fin; } -_yy_state_29: +_yy_state_31: ch = *++YYPOS; if (ch == '\r') { ch = *++YYPOS; @@ -668,42 +685,42 @@ _yy_state_29: ret = YY_ONE_LINE_COMMENT; goto _yy_fin; } else if (YYPOS < YYEND && (ch <= '\t' || ch == '\v' || ch == '\f' || ch >= '\016')) { - goto _yy_state_29; + goto _yy_state_31; } else { goto _yy_state_error; } -_yy_state_43: +_yy_state_46: ch = *++YYPOS; accept = YY_FLOATNUMBER; accept_pos = yy_pos; if ((ch >= '0' && ch <= '9')) { - goto _yy_state_43; + goto _yy_state_46; } else if (ch == 'E' || ch == 'e') { - goto _yy_state_47; + goto _yy_state_50; } else { ret = YY_FLOATNUMBER; goto _yy_fin; } -_yy_state_47: +_yy_state_50: ch = *++YYPOS; if (ch == '+' || ch == '-') { ch = *++YYPOS; if ((ch >= '0' && ch <= '9')) { - goto _yy_state_75; + goto _yy_state_79; } else { goto _yy_state_error; } } else if ((ch >= '0' && ch <= '9')) { - goto _yy_state_75; + goto _yy_state_79; } else { goto _yy_state_error; } -_yy_state_55: +_yy_state_58: ch = *++YYPOS; -_yy_tunnel_55: +_yy_tunnel_58: if (ch == '*') { ch = *++YYPOS; - if (ch != '/') goto _yy_tunnel_55; + if (ch != '/') goto _yy_tunnel_58; YYPOS++; ret = YY_COMMENT; goto _yy_fin; @@ -711,29 +728,28 @@ _yy_tunnel_55: if (ch == '\n') { yy_line++; } - goto _yy_state_55; + goto _yy_state_58; } else { goto _yy_state_error; } -_yy_state_72: +_yy_state_76: ch = *++YYPOS; if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) { - goto _yy_state_72; + goto _yy_state_76; } else { ret = YY_HEXNUMBER; goto _yy_fin; } -_yy_state_75: +_yy_state_79: ch = *++YYPOS; if ((ch >= '0' && ch <= '9')) { - goto _yy_state_75; + goto _yy_state_79; } else { ret = YY_FLOATNUMBER; goto _yy_fin; } -_yy_state_103: +_yy_state_109: ch = *++YYPOS; -_yy_tunnel_103: if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'z')) { goto _yy_state_4; } else { @@ -812,7 +828,7 @@ static int parse_ir(int sym, ir_loader *loader) { const unsigned char *save_pos; const unsigned char *save_text; int save_line; - int alt12; + int alt13; ir_parser_ctx p; ir_ctx ctx; uint8_t ret_type; @@ -820,7 +836,7 @@ static int parse_ir(int sym, ir_loader *loader) { uint32_t flags = 0; size_t size; uint32_t params_count; - ir_type param_types[256]; + uint8_t param_types[256]; p.ctx = &ctx; if (YY_IN_SET(sym, (YY_EXTERN,YY_STATIC,YY_VAR,YY_CONST,YY_FUNC), "\012\203\000\000\000")) { do { @@ -839,7 +855,8 @@ static int parse_ir(int sym, ir_loader *loader) { } } else if (sym == YY_FUNC) { flags = 0; - sym = parse_ir_func_prototype(sym, &p, name, &flags, &ret_type, ¶ms_count, param_types); + sym = parse_ir_func_name(sym, name); + sym = parse_ir_func_proto(sym, &p, &flags, &ret_type, ¶ms_count, param_types); if (sym != YY__SEMICOLON) { yy_error_sym("';' expected, got", sym); } @@ -879,38 +896,38 @@ static int parse_ir(int sym, ir_loader *loader) { save_pos = yy_pos; save_text = yy_text; save_line = yy_line; - alt12 = -2; + alt13 = -2; sym2 = sym; if (sym2 == YY__COMMA) { sym2 = get_sym(); - goto _yy_state_12_1; + goto _yy_state_13_1; } else if (sym2 == YY__RBRACE) { - alt12 = 16; - goto _yy_state_12; + alt13 = 17; + goto _yy_state_13; } else { yy_error_sym("unexpected", sym2); } -_yy_state_12_1: +_yy_state_13_1: if (sym2 == YY_ID) { - alt12 = 13; - goto _yy_state_12; + alt13 = 14; + goto _yy_state_13; } else if (sym2 == YY__RBRACE) { - alt12 = 15; - goto _yy_state_12; + alt13 = 16; + goto _yy_state_13; } else { yy_error_sym("unexpected", sym2); } -_yy_state_12: +_yy_state_13: yy_pos = save_pos; yy_text = save_text; yy_line = save_line; - if (alt12 != 13) { + if (alt13 != 14) { break; } sym = get_sym(); sym = parse_ir_sym_data(sym, loader); } - if (alt12 == 15) { + if (alt13 == 16) { sym = get_sym(); } if (sym != YY__RBRACE) { @@ -928,7 +945,8 @@ _yy_state_12: yy_error_sym("unexpected", sym); } } else if (sym == YY_FUNC) { - sym = parse_ir_func_prototype(sym, &p, name, &flags, &ret_type, ¶ms_count, param_types); + sym = parse_ir_func_name(sym, name); + sym = parse_ir_func_proto(sym, &p, &flags, &ret_type, ¶ms_count, param_types); if (sym == YY__SEMICOLON) { sym = get_sym(); if (loader->forward_func_dcl @@ -1043,7 +1061,7 @@ static int parse_ir_sym_data(int sym, ir_loader *loader) { yy_error("sym_data_ref error"); } } - } else if (YY_IN_SET(sym, (YY_DECNUMBER,YY_HEXNUMBER,YY_FLOATNUMBER,YY_CHARACTER,YY_INF,YY_NAN,YY__MINUS), "\000\000\300\075\000")) { + } else if (YY_IN_SET(sym, (YY_DECNUMBER,YY_HEXNUMBER,YY_FLOATNUMBER,YY_CHARACTER,YY_INF,YY_NAN,YY__MINUS), "\000\000\200\173\000")) { sym = parse_const(sym, t, &val); if (loader->sym_data) { switch (ir_type_size[t]) { @@ -1088,16 +1106,9 @@ static int parse_ir_func(int sym, ir_parser_ctx *p) { return sym; } -static int parse_ir_func_prototype(int sym, ir_parser_ctx *p, char *buf, uint32_t *flags, uint8_t *ret_type, uint32_t *params_count, ir_type *param_types) { - int sym2; - const unsigned char *save_pos; - const unsigned char *save_text; - int save_line; - int alt63; +static int parse_ir_func_name(int sym, char *buf) { const char *name; size_t len; - uint8_t t = 0; - uint32_t n = 0; if (sym != YY_FUNC) { yy_error_sym("'func' expected, got", sym); } @@ -1106,6 +1117,17 @@ static int parse_ir_func_prototype(int sym, ir_parser_ctx *p, char *buf, uint32_ if (len > 255) yy_error("name too long"); memcpy(buf, name, len); buf[len] = 0; + return sym; +} + +static int parse_ir_func_proto(int sym, ir_parser_ctx *p, uint32_t *flags, uint8_t *ret_type, uint32_t *params_count, uint8_t *param_types) { + int sym2; + const unsigned char *save_pos; + const unsigned char *save_text; + int save_line; + int alt63; + uint8_t t = 0; + uint32_t n = 0; if (sym != YY__LPAREN) { yy_error_sym("'(' expected, got", sym); } @@ -1182,6 +1204,10 @@ _yy_state_63: } else { yy_error_sym("unexpected", sym); } + if (sym == YY___FASTCALL) { + sym = get_sym(); + *flags |= IR_FASTCALL_FUNC; + } *params_count = n; return sym; } @@ -1191,7 +1217,7 @@ static int parse_ir_insn(int sym, ir_parser_ctx *p) { const unsigned char *save_pos; const unsigned char *save_text; int save_line; - int alt72; + int alt73; const char *str, *str2 = NULL, *func; size_t len, len2 = 0, func_len; uint8_t op; @@ -1202,41 +1228,44 @@ static int parse_ir_insn(int sym, ir_parser_ctx *p) { ir_ref ref; ir_val val; ir_val count; - ir_val flags; int32_t n; + uint8_t ret_type; + uint32_t flags; + uint32_t params_count; + uint8_t param_types[256]; save_pos = yy_pos; save_text = yy_text; save_line = yy_line; - alt72 = -2; + alt73 = -2; sym2 = sym; if (sym2 == YY_ID) { sym2 = get_sym(); - goto _yy_state_72_1; + goto _yy_state_73_1; } else { yy_error_sym("unexpected", sym2); } -_yy_state_72_1: +_yy_state_73_1: if (sym2 == YY_ID) { - alt72 = 73; - goto _yy_state_72; + alt73 = 74; + goto _yy_state_73; } else if (sym2 == YY__EQUAL) { - alt72 = 77; - goto _yy_state_72; + alt73 = 78; + goto _yy_state_73; } else { yy_error_sym("unexpected", sym2); } -_yy_state_72: +_yy_state_73: yy_pos = save_pos; yy_text = save_text; yy_line = save_line; - if (alt72 == 73) { + if (alt73 == 74) { sym = parse_type(sym, &t); sym = parse_ID(sym, &str, &len); if (sym == YY__COMMA) { sym = get_sym(); sym = parse_ID(sym, &str2, &len2); } - } else if (alt72 == 77) { + } else if (alt73 == 78) { sym = parse_ID(sym, &str, &len); } else { yy_error_sym("unexpected", sym); @@ -1259,21 +1288,28 @@ _yy_state_72: break; case YY_FUNC: sym = get_sym(); - if (sym != YY__LPAREN) { - yy_error_sym("'(' expected, got", sym); - } - sym = get_sym(); - sym = parse_ID(sym, &func, &func_len); - flags.u64 = 0; - if (sym == YY__COMMA) { + if (sym == YY_ID) { + sym = parse_ID(sym, &func, &func_len); + flags = 0; + sym = parse_ir_func_proto(sym, p, &flags, &ret_type, ¶ms_count, param_types); + ref = ir_proto(p->ctx, flags, ret_type, params_count, param_types); + ref = ir_const_func(p->ctx, ir_strl(p->ctx, func, func_len), ref); + } else if (sym == YY__STAR) { sym = get_sym(); - sym = parse_DECNUMBER(sym, IR_U16, &flags); + if (sym == YY_DECNUMBER) { + sym = parse_DECNUMBER(sym, IR_ADDR, &val); + } else if (sym == YY_HEXNUMBER) { + sym = parse_HEXNUMBER(sym, IR_ADDR, &val); + } else { + yy_error_sym("unexpected", sym); + } + flags = 0; + sym = parse_ir_func_proto(sym, p, &flags, &ret_type, ¶ms_count, param_types); + ref = ir_proto(p->ctx, flags, ret_type, params_count, param_types); + ref = ir_const_func_addr(p->ctx, val.addr, ref); + } else { + yy_error_sym("unexpected", sym); } - if (sym != YY__RPAREN) { - yy_error_sym("')' expected, got", sym); - } - sym = get_sym(); - ref = ir_const_func(p->ctx, ir_strl(p->ctx, func, func_len), flags.u16); break; case YY_SYM: sym = get_sym(); @@ -1288,30 +1324,6 @@ _yy_state_72: sym = get_sym(); ref = ir_const_sym(p->ctx, ir_strl(p->ctx, func, func_len)); break; - case YY_FUNC_ADDR: - sym = get_sym(); - if (sym != YY__LPAREN) { - yy_error_sym("'(' expected, got", sym); - } - sym = get_sym(); - if (sym == YY_DECNUMBER) { - sym = parse_DECNUMBER(sym, IR_ADDR, &val); - } else if (sym == YY_HEXNUMBER) { - sym = parse_HEXNUMBER(sym, IR_ADDR, &val); - } else { - yy_error_sym("unexpected", sym); - } - flags.u64 = 0; - if (sym == YY__COMMA) { - sym = get_sym(); - sym = parse_DECNUMBER(sym, IR_U16, &flags); - } - if (sym != YY__RPAREN) { - yy_error_sym("')' expected, got", sym); - } - sym = get_sym(); - ref = ir_const_func_addr(p->ctx, val.addr, flags.u16); - break; case YY_STRING: sym = parse_STRING(sym, &func, &func_len); ref = ir_const_str(p->ctx, ir_strl(p->ctx, func, func_len)); @@ -1327,7 +1339,7 @@ _yy_state_72: ref = ir_emit_N(p->ctx, IR_OPT(op, t), count.i32); if (sym == YY__LPAREN) { sym = get_sym(); - if (sym == YY_ID || sym == YY_STRING || sym == YY_DECNUMBER || sym == YY_NULL) { + if (YY_IN_SET(sym, (YY_ID,YY_STRING,YY_DECNUMBER,YY_NULL,YY_FUNC), "\000\200\100\214\000")) { sym = parse_val(sym, p, op, 1, &op1); n = 1; if (n > count.i32) yy_error("too many operands"); @@ -1349,7 +1361,7 @@ _yy_state_72: n = 0; if (sym == YY__LPAREN) { sym = get_sym(); - if (sym == YY_ID || sym == YY_STRING || sym == YY_DECNUMBER || sym == YY_NULL) { + if (YY_IN_SET(sym, (YY_ID,YY_STRING,YY_DECNUMBER,YY_NULL,YY_FUNC), "\000\200\100\214\000")) { sym = parse_val(sym, p, op, 1, &op1); n = 1; if (sym == YY__COMMA) { @@ -1424,24 +1436,40 @@ static int parse_val(int sym, ir_parser_ctx *p, uint8_t op, uint32_t n, ir_ref * size_t len; ir_val val; uint32_t kind = IR_OPND_KIND(ir_op_flags[op], n); - if (sym == YY_ID) { - sym = parse_ID(sym, &str, &len); - if (!IR_IS_REF_OPND_KIND(kind)) yy_error("unexpected reference"); - *ref = ir_use_var(p, n, str, len); - } else if (sym == YY_STRING) { - sym = parse_STRING(sym, &str, &len); - if (kind != IR_OPND_STR) yy_error("unexpected string"); - *ref = ir_strl(p->ctx, str, len); - } else if (sym == YY_DECNUMBER) { - sym = parse_DECNUMBER(sym, IR_I32, &val); - if (kind != IR_OPND_NUM && kind != IR_OPND_PROB) yy_error("unexpected number"); - if (val.i64 < 0 || val.i64 > 0x7fffffff) yy_error("number out of range"); - *ref = val.i32; - } else if (sym == YY_NULL) { - sym = get_sym(); - *ref = IR_UNUSED; - } else { - yy_error_sym("unexpected", sym); + uint8_t ret_type; + uint32_t flags; + uint32_t params_count; + uint8_t param_types[256]; + switch (sym) { + case YY_ID: + sym = parse_ID(sym, &str, &len); + if (!IR_IS_REF_OPND_KIND(kind)) yy_error("unexpected reference"); + *ref = ir_use_var(p, n, str, len); + break; + case YY_STRING: + sym = parse_STRING(sym, &str, &len); + if (kind != IR_OPND_STR) yy_error("unexpected string"); + *ref = ir_strl(p->ctx, str, len); + break; + case YY_DECNUMBER: + sym = parse_DECNUMBER(sym, IR_I32, &val); + if (kind != IR_OPND_NUM && kind != IR_OPND_PROB) yy_error("unexpected number"); + if (val.i64 < 0 || val.i64 > 0x7fffffff) yy_error("number out of range"); + *ref = val.i32; + break; + case YY_NULL: + sym = get_sym(); + *ref = IR_UNUSED; + break; + case YY_FUNC: + sym = get_sym(); + if (kind != IR_OPND_PROTO) yy_error("unexpected function prototype"); + flags = 0; + sym = parse_ir_func_proto(sym, p, &flags, &ret_type, ¶ms_count, param_types); + *ref = ir_proto(p->ctx, flags, ret_type, params_count, param_types); + break; + default: + yy_error_sym("unexpected", sym); } return sym; } diff --git a/ir_load_llvm.c b/ir_load_llvm.c index 6fd3987..09eb518 100644 --- a/ir_load_llvm.c +++ b/ir_load_llvm.c @@ -16,11 +16,18 @@ #define IR_BAD_TYPE IR_LAST_TYPE -#define BUILTIN_FUNC(name) \ - ir_const_func(ctx, ir_strl(ctx, name, strlen(name)), IR_CONST_BUILTIN_FUNC) - -#define BUILTIN_FP_FUNC(type, dname, fname) \ - ((type == IR_DOUBLE) ? BUILTIN_FUNC(dname) : BUILTIN_FUNC(fname)) +#define BUILTIN_FUNC_1(name, ret_type, arg1_type) \ + ir_const_func(ctx, \ + ir_strl(ctx, name, strlen(name)), \ + ir_proto_1(ctx, IR_BUILTIN_FUNC, ret_type, arg1_type)) +#define BUILTIN_FUNC_2(name, ret_type, arg1_type, arg2_type) \ + ir_const_func(ctx, \ + ir_strl(ctx, name, strlen(name)), \ + ir_proto_2(ctx, IR_BUILTIN_FUNC, ret_type, arg1_type, arg2_type)) +#define BUILTIN_FUNC_3(name, ret_type, arg1_type, arg2_type, arg3_type) \ + ir_const_func(ctx, \ + ir_strl(ctx, name, strlen(name)), \ + ir_proto_3(ctx, IR_BUILTIN_FUNC, ret_type, arg1_type, arg2_type, arg3_type)) static ir_ref llvm2ir_const_expr(ir_ctx *ctx, LLVMValueRef expr); static ir_ref llvm2ir_auto_cast(ir_ctx *ctx, ir_ref ref, ir_type src_type, ir_type type); @@ -105,13 +112,44 @@ static const char *llvm2ir_sym_name(char *buf, const char *name, size_t name_len return buf; } +static ir_ref llvm2ir_proto(ir_ctx *ctx, uint32_t cconv, LLVMTypeRef ftype) +{ + uint8_t flags = 0; + ir_type ret_type; + uint8_t *arg_types; + uint32_t i, num_args; + LLVMTypeRef *types; + + if (cconv == LLVMCCallConv || cconv == LLVMFastCallConv) { + /* skip */ + } else if (cconv == LLVMX86FastcallCallConv) { + flags |= IR_FASTCALL_FUNC; + } else { + fprintf(stderr, "Unsupported Calling Convention: %d\n", cconv); + IR_ASSERT(0); + return 0; + } + if (LLVMIsFunctionVarArg(ftype)) { + flags |= IR_VARARG_FUNC; + } + ret_type = llvm2ir_type(LLVMGetReturnType(ftype)); + num_args = LLVMCountParamTypes(ftype); + types = alloca(sizeof(LLVMTypeRef) * num_args); + arg_types = alloca(num_args); + LLVMGetParamTypes(ftype, types); + for (i = 0; i < num_args; i++) { + arg_types[i] = llvm2ir_type(types[i]); + } + return ir_proto(ctx, flags, ret_type, num_args, arg_types); +} + static ir_ref llvm2ir_op(ir_ctx *ctx, LLVMValueRef op, ir_type type) { ir_ref ref; LLVMBool lose; const char *name; size_t name_len; - uint32_t cconv, flags; + ir_ref proto; ir_val val; char buf[256]; @@ -158,24 +196,10 @@ static ir_ref llvm2ir_op(ir_ctx *ctx, LLVMValueRef op, ir_type type) } return ir_const_sym(ctx, ir_strl(ctx, name, name_len)); case LLVMFunctionValueKind: - // TODO: function prototype // TODO: resolve function address - flags = 0; - cconv = LLVMGetFunctionCallConv(op); - if (cconv == LLVMCCallConv || cconv == LLVMFastCallConv) { - /* skip */ - } else if (cconv == LLVMX86FastcallCallConv) { - flags |= IR_CONST_FASTCALL_FUNC; - } else { - fprintf(stderr, "Unsupported Calling Convention: %d\n", cconv); - IR_ASSERT(0); - return 0; - } - if (LLVMIsFunctionVarArg(LLVMTypeOf(op))) { - flags |= IR_CONST_VARARG_FUNC; - } + proto = llvm2ir_proto(ctx, LLVMGetFunctionCallConv(op), LLVMGlobalGetValueType(op)); name = LLVMGetValueName2(op, &name_len); - return ir_const_func(ctx, ir_strl(ctx, name, name_len), flags); + return ir_const_func(ctx, ir_strl(ctx, name, name_len), proto); case LLVMUndefValueValueKind: val.u64 = 0; return ir_const(ctx, val, type); @@ -314,7 +338,11 @@ static ir_ref llvm2ir_fcmp_op_isnan(ir_ctx *ctx, LLVMValueRef expr, ir_type type { ir_ref func, ref; - func = BUILTIN_FP_FUNC(type, "isnan", "isnanf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("isnan", IR_BOOL, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("isnanf", IR_BOOL, IR_FLOAT); + } if (LLVMGetValueKind(op1) == LLVMConstantIntValueKind) { ref = ir_CALL_1(IR_BOOL, func, llvm2ir_op(ctx, op0, type)); } else { @@ -790,21 +818,21 @@ static ir_ref llvm2ir_intrinsic(ir_ctx *ctx, LLVMValueRef insn, LLVMTypeRef ftyp return ir_CTTZ(type, llvm2ir_op(ctx, op0, type)); } else if (STR_START(name, name_len, "llvm.memset.")) { IR_ASSERT(count == 3 || count == 4); - func = BUILTIN_FUNC("memset"); + func = BUILTIN_FUNC_3("memset", IR_ADDR, IR_ADDR, IR_I32, IR_SIZE_T); return ir_CALL_3(IR_VOID, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), IR_ADDR), llvm2ir_op(ctx, LLVMGetOperand(insn, 1), IR_I8), llvm2ir_op(ctx, LLVMGetOperand(insn, 2), IR_SIZE_T)); } else if (STR_START(name, name_len, "llvm.memcpy.")) { IR_ASSERT(count == 3 || count == 4); - func = BUILTIN_FUNC("memcpy"); + func = BUILTIN_FUNC_3("memcpy", IR_ADDR, IR_ADDR, IR_ADDR, IR_SIZE_T); return ir_CALL_3(IR_VOID, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), IR_ADDR), llvm2ir_op(ctx, LLVMGetOperand(insn, 1), IR_ADDR), llvm2ir_op(ctx, LLVMGetOperand(insn, 2), IR_SIZE_T)); } else if (STR_START(name, name_len, "llvm.memmove.")) { IR_ASSERT(count == 3 || count == 4); - func = BUILTIN_FUNC("memmove"); + func = BUILTIN_FUNC_3("memmove", IR_ADDR, IR_ADDR, IR_ADDR, IR_SIZE_T); return ir_CALL_3(IR_VOID, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), IR_ADDR), llvm2ir_op(ctx, LLVMGetOperand(insn, 1), IR_ADDR), @@ -820,107 +848,175 @@ static ir_ref llvm2ir_intrinsic(ir_ctx *ctx, LLVMValueRef insn, LLVMTypeRef ftyp IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "sqrt", "sqrtf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("sqrt", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("sqrtf", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.sin.")) { IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "sin", "sinf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("sin", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("sinf", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.cos.")) { IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "cos", "cosf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("cos", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("cosf", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.pow.")) { IR_ASSERT(count == 2); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "pow", "powf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("pow", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("powf", IR_FLOAT, IR_FLOAT); + } return ir_CALL_2(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type), llvm2ir_op(ctx, LLVMGetOperand(insn, 1), type)); } else if (STR_START(name, name_len, "llvm.exp.")) { IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "exp", "expf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("exp", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("expf", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.exp2.")) { IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "exp2", "exp2f"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("exp2", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("exp2f", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.exp10.")) { IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "exp10", "exp10f"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("exp10", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("exp10f", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.ldexp.")) { IR_ASSERT(count == 2); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "ldexp", "ldexpf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_2("ldexp", IR_DOUBLE, IR_DOUBLE, IR_I32); + } else { + func = BUILTIN_FUNC_2("ldexpf", IR_FLOAT, IR_FLOAT, IR_I32); + } return ir_CALL_2(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type), llvm2ir_op(ctx, LLVMGetOperand(insn, 1), IR_I32)); } else if (STR_START(name, name_len, "llvm.frexp.")) { IR_ASSERT(count == 2); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "frexp", "frexpf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_2("frexp", IR_DOUBLE, IR_DOUBLE, IR_ADDR); + } else { + func = BUILTIN_FUNC_2("frexpf", IR_FLOAT, IR_FLOAT, IR_ADDR); + } return ir_CALL_2(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type), llvm2ir_op(ctx, LLVMGetOperand(insn, 1), IR_ADDR)); } else if (STR_START(name, name_len, "llvm.log.")) { IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "log", "logf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("log", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("logf", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.log2.")) { IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "log2", "log2f"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("log2", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("log2f", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.log10.")) { IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "log10", "log10f"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("log10", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("log10f", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.copysign.")) { IR_ASSERT(count == 2); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "copysign", "copysignf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_2("copysign", IR_DOUBLE, IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_2("copysignf", IR_FLOAT, IR_FLOAT, IR_FLOAT); + } return ir_CALL_2(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type), llvm2ir_op(ctx, LLVMGetOperand(insn, 1), type)); } else if (STR_START(name, name_len, "llvm.floor.")) { IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "floor", "floorf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("floor", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("floorf", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.ceil.")) { IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "ceil", "ceilf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("ceil", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("ceilf", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.trunc.")) { IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "trunc", "truncf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("trunc", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("truncf", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.round.")) { IR_ASSERT(count == 1); type = llvm2ir_type(LLVMGetReturnType(ftype)); IR_ASSERT(IR_IS_TYPE_FP(type)); - func = BUILTIN_FP_FUNC(type, "round", "roundf"); + if (type == IR_DOUBLE) { + func = BUILTIN_FUNC_1("round", IR_DOUBLE, IR_DOUBLE); + } else { + func = BUILTIN_FUNC_1("roundf", IR_FLOAT, IR_FLOAT); + } return ir_CALL_1(type, func, llvm2ir_op(ctx, LLVMGetOperand(insn, 0), type)); } else if (STR_START(name, name_len, "llvm.fmuladd.") || STR_START(name, name_len, "llvm.fma.")) { @@ -1782,9 +1878,9 @@ static int llvm2ir_external_func(ir_loader *loader, const char *name, LLVMValueR { uint32_t i, count, cconv, flags = 0; LLVMTypeRef ftype; - ir_type ret_type, *param_types; + ir_type ret_type; + uint8_t *param_types; - // TODO: function prototype ftype = LLVMGlobalGetValueType(func); cconv = LLVMGetFunctionCallConv(func); if (cconv == LLVMCCallConv || cconv == LLVMFastCallConv) { @@ -1814,9 +1910,9 @@ static int llvm2ir_forward_func(ir_loader *loader, const char *name, LLVMValueRe { uint32_t i, count, cconv, flags = 0; LLVMTypeRef ftype; - ir_type ret_type, *param_types; + ir_type ret_type; + uint8_t *param_types; - // TODO: function prototype ftype = LLVMGlobalGetValueType(func); cconv = LLVMGetFunctionCallConv(func); if (cconv == LLVMCCallConv || cconv == LLVMFastCallConv) { diff --git a/ir_main.c b/ir_main.c index 2025b06..f442989 100644 --- a/ir_main.c +++ b/ir_main.c @@ -306,7 +306,7 @@ static bool ir_loader_external_sym_dcl(ir_loader *loader, const char *name, uint return 1; } -static void ir_dump_func_dcl(const char *name, uint32_t flags, ir_type ret_type, uint32_t params_count, ir_type *param_types, FILE *f) +static void ir_dump_func_dcl(const char *name, uint32_t flags, ir_type ret_type, uint32_t params_count, const uint8_t *param_types, FILE *f) { if (flags & IR_EXTERN) { fprintf(f, "extern "); @@ -315,7 +315,7 @@ static void ir_dump_func_dcl(const char *name, uint32_t flags, ir_type ret_type, } fprintf(f, "func %s(", name); if (params_count) { - ir_type *p = param_types; + const uint8_t *p = param_types; fprintf(f, "%s", ir_type_cname[*p]); p++; @@ -328,14 +328,16 @@ static void ir_dump_func_dcl(const char *name, uint32_t flags, ir_type ret_type, } } else if (flags & IR_VARARG_FUNC) { fprintf(f, "..."); - } else { - fprintf(f, "void"); } - fprintf(f, "): %s;\n", ir_type_cname[ret_type]); + fprintf(f, "): %s", ir_type_cname[ret_type]); + if (flags & IR_FASTCALL_FUNC) { + fprintf(f, " __fastcall"); + } + fprintf(f, ";\n"); } -static bool ir_loader_external_func_dcl(ir_loader *loader, const char *name, - uint32_t flags, ir_type ret_type, uint32_t params_count, ir_type *param_types) +static bool ir_loader_external_func_dcl(ir_loader *loader, const char *name, uint32_t flags, + ir_type ret_type, uint32_t params_count, const uint8_t *param_types) { ir_main_loader *l = (ir_main_loader*) loader; @@ -361,8 +363,8 @@ static bool ir_loader_external_func_dcl(ir_loader *loader, const char *name, return 1; } -static bool ir_loader_forward_func_dcl(ir_loader *loader, const char *name, - uint32_t flags, ir_type ret_type, uint32_t params_count, ir_type *param_types) +static bool ir_loader_forward_func_dcl(ir_loader *loader, const char *name, uint32_t flags, + ir_type ret_type, uint32_t params_count, const uint8_t *param_types) { ir_main_loader *l = (ir_main_loader*) loader; @@ -554,10 +556,12 @@ static bool ir_loader_func_process(ir_loader *loader, ir_ctx *ctx, const char *n } } else if (ctx->flags & IR_VARARG_FUNC) { fprintf(l->dump_file, "..."); - } else { - fprintf(l->dump_file, "void"); } - fprintf(l->dump_file, "): %s\n", ir_type_cname[ctx->ret_type != (ir_type)-1 ? ctx->ret_type : IR_VOID]); + fprintf(l->dump_file, "): %s", ir_type_cname[ctx->ret_type != (ir_type)-1 ? ctx->ret_type : IR_VOID]); + if (ctx->flags & IR_FASTCALL_FUNC) { + fprintf(l->dump_file, " __fastcall"); + } + fprintf(l->dump_file, "\n"); } if (!ir_compile_func(ctx, l->opt_level, l->dump, l->dump_file, name)) { @@ -620,7 +624,7 @@ static bool ir_loader_func_process(ir_loader *loader, ir_ctx *ctx, const char *n for (i = IR_UNUSED + 1, insn = ctx->ir_base - i; i < ctx->consts_count; i++, insn--) { if (insn->op == IR_FUNC) { - const char *name = ir_get_str(ctx, insn->val.i32); + const char *name = ir_get_str(ctx, insn->val.name); void *addr = ir_loader_resolve_sym_name(loader, name); ir_disasm_add_symbol(name, (uintptr_t)addr, sizeof(void*)); diff --git a/ir_private.h b/ir_private.h index d8dfe3f..804da3d 100644 --- a/ir_private.h +++ b/ir_private.h @@ -828,6 +828,7 @@ IR_ALWAYS_INLINE bool ir_ref_is_true(ir_ctx *ctx, ir_ref ref) #define IR_OPND_STR 0x5 #define IR_OPND_NUM 0x6 #define IR_OPND_PROB 0x7 +#define IR_OPND_PROTO 0x8 #define IR_OP_FLAGS(op_flags, op1_flags, op2_flags, op3_flags) \ ((op_flags) | ((op1_flags) << 20) | ((op2_flags) << 24) | ((op3_flags) << 28)) diff --git a/ir_save.c b/ir_save.c index 68d8aba..049e583 100644 --- a/ir_save.c +++ b/ir_save.c @@ -8,6 +8,34 @@ #include "ir.h" #include "ir_private.h" +void ir_print_proto(const ir_ctx *ctx, ir_ref func_proto, FILE *f) +{ + ir_ref j; + + if (func_proto) { + const ir_proto_t *proto = (const ir_proto_t *)ir_get_str(ctx, func_proto); + + fprintf(f, "("); + if (proto->params_count > 0) { + fprintf(f, "%s", ir_type_cname[proto->param_types[0]]); + for (j = 1; j < proto->params_count; j++) { + fprintf(f, ", %s", ir_type_cname[proto->param_types[j]]); + } + if (proto->flags & IR_VARARG_FUNC) { + fprintf(f, ", ..."); + } + } else if (proto->flags & IR_VARARG_FUNC) { + fprintf(f, "..."); + } + fprintf(f, "): %s", ir_type_cname[proto->ret_type]); + if (proto->flags & IR_FASTCALL_FUNC) { + fprintf(f, " __fastcall"); + } + } else { + fprintf(f, "(): int32_t"); + } +} + void ir_save(const ir_ctx *ctx, FILE *f) { ir_ref i, j, n, ref, *p; @@ -19,20 +47,14 @@ void ir_save(const ir_ctx *ctx, FILE *f) for (i = IR_UNUSED + 1, insn = ctx->ir_base - i; i < ctx->consts_count; i++, insn--) { fprintf(f, "\t%s c_%d = ", ir_type_cname[insn->type], i); if (insn->op == IR_FUNC) { - if (!insn->const_flags) { - fprintf(f, "func(%s)", ir_get_str(ctx, insn->val.i32)); - } else { - fprintf(f, "func(%s, %d)", ir_get_str(ctx, insn->val.i32), insn->const_flags); - } + fprintf(f, "func %s", ir_get_str(ctx, insn->val.name)); + ir_print_proto(ctx, insn->proto, f); } else if (insn->op == IR_SYM) { - fprintf(f, "sym(%s)", ir_get_str(ctx, insn->val.i32)); + fprintf(f, "sym(%s)", ir_get_str(ctx, insn->val.name)); } else if (insn->op == IR_FUNC_ADDR) { - fprintf(f, "func_addr("); + fprintf(f, "func *"); ir_print_const(ctx, insn, f, true); - if (insn->const_flags) { - fprintf(f, ", %d", insn->const_flags); - } - fprintf(f, ")"); + ir_print_proto(ctx, insn->proto, f); } else { ir_print_const(ctx, insn, f, true); } @@ -89,6 +111,10 @@ void ir_save(const ir_ctx *ctx, FILE *f) fprintf(f, "%s\"%s\"", first ? "(" : ", ", ir_get_str(ctx, ref)); first = 0; break; + case IR_OPND_PROTO: + fprintf(f, "%sfunc ", first ? "(" : ", "); + ir_print_proto(ctx, ref, f); + break; case IR_OPND_PROB: if (ref == 0) { break; diff --git a/ir_strtab.c b/ir_strtab.c index c5115e5..646b5aa 100644 --- a/ir_strtab.c +++ b/ir_strtab.c @@ -204,6 +204,14 @@ const char *ir_strtab_str(const ir_strtab *strtab, ir_ref idx) return ((const ir_strtab_bucket*)strtab->data)[idx].str; } +const char *ir_strtab_strl(const ir_strtab *strtab, ir_ref idx, size_t *len) +{ + const ir_strtab_bucket *b = ((const ir_strtab_bucket*)strtab->data) + idx; + IR_ASSERT(idx >= 0 && (uint32_t)idx < strtab->count); + *len = b->len; + return b->str; +} + void ir_strtab_free(ir_strtab *strtab) { uint32_t hash_size = (uint32_t)(-(int32_t)strtab->mask); diff --git a/ir_x86.dasc b/ir_x86.dasc index 7e7eeab..3a5b9a2 100644 --- a/ir_x86.dasc +++ b/ir_x86.dasc @@ -364,6 +364,7 @@ typedef struct _ir_backend_data { ir_reg_alloc_data ra_data; uint32_t dessa_from_block; dasm_State *dasm_state; + ir_bitset emit_constants; int rodata_label, jmp_table_label; bool double_neg_const; bool float_neg_const; @@ -1927,6 +1928,7 @@ store_int: case IR_INT2FP: case IR_FP2INT: case IR_FP2FP: + case IR_PROTO: ir_match_fuse_load(ctx, insn->op1, ref); return insn->op; case IR_CTLZ: @@ -2117,7 +2119,7 @@ static void ir_emit_load_imm_fp(ir_ctx *ctx, ir_type type, ir_reg reg, ir_ref sr } } else { label = ctx->cfg_blocks_count - src; - insn->const_flags |= IR_CONST_EMIT; + ir_bitset_incl(data->emit_constants, -src); | ASM_FP_REG_MEM_OP movss, movsd, vmovss, vmovsd, type, reg, [=>label] } } @@ -2310,10 +2312,10 @@ static void ir_emit_prologue(ir_ctx *ctx) } } if ((ctx->flags & IR_VARARG_FUNC) && (ctx->flags2 & IR_HAS_VA_START)) { +#if defined(_WIN64) ir_reg fp; int offset; -#if defined(_WIN64) if (ctx->flags & IR_USE_FRAME_POINTER) { fp = IR_REG_FRAME_POINTER; offset = sizeof(void*) * 2; @@ -2330,6 +2332,8 @@ static void ir_emit_prologue(ir_ctx *ctx) const int8_t *int_reg_params = _ir_int_reg_params; const int8_t *fp_reg_params = _ir_fp_reg_params; uint32_t i; + ir_reg fp; + int offset; if (ctx->flags & IR_USE_FRAME_POINTER) { fp = IR_REG_FRAME_POINTER; @@ -4046,10 +4050,9 @@ static void ir_emit_binop_sse2(ir_ctx *ctx, ir_ref def, ir_insn *insn) break; } } else if (IR_IS_CONST_REF(op2)) { - ir_insn *val_insn = &ctx->ir_base[op2]; int label = ctx->cfg_blocks_count - op2; - val_insn->const_flags |= IR_CONST_EMIT; + ir_bitset_incl(data->emit_constants, -op2); switch (insn->op) { default: IR_ASSERT(0 && "NIY binary op"); @@ -4155,10 +4158,9 @@ static void ir_emit_binop_avx(ir_ctx *ctx, ir_ref def, ir_insn *insn) break; } } else if (IR_IS_CONST_REF(op2)) { - ir_insn *val_insn = &ctx->ir_base[op2]; int label = ctx->cfg_blocks_count - op2; - val_insn->const_flags |= IR_CONST_EMIT; + ir_bitset_incl(data->emit_constants, -op2); switch (insn->op) { default: IR_ASSERT(0 && "NIY binary op"); @@ -4528,10 +4530,9 @@ static ir_op ir_emit_cmp_fp_common(ir_ctx *ctx, ir_ref cmp_ref, ir_insn *cmp_ins } | ASM_FP_REG_REG_OP ucomiss, ucomisd, vucomiss, vucomisd, type, op1_reg, op2_reg } else if (IR_IS_CONST_REF(op2)) { - ir_insn *val_insn = &ctx->ir_base[op2]; int label = ctx->cfg_blocks_count - op2; - val_insn->const_flags |= IR_CONST_EMIT; + ir_bitset_incl(data->emit_constants, -op2); | ASM_FP_REG_MEM_OP ucomiss, ucomisd, vucomiss, vucomisd, type, op1_reg, [=>label] } else { int32_t offset = 0; @@ -5448,10 +5449,9 @@ static void ir_emit_bitcast(ir_ctx *ctx, ir_ref def, ir_insn *insn) } } } else if (IR_IS_CONST_REF(insn->op1)) { - ir_insn *val_insn = &ctx->ir_base[insn->op1]; int label = ctx->cfg_blocks_count - insn->op1; - val_insn->const_flags |= IR_CONST_EMIT; + ir_bitset_incl(data->emit_constants, -insn->op1); | ASM_FP_REG_MEM_OP movss, movsd, vmovss, vmovsd, dst_type, def_reg, [=>label] } else { int32_t offset = 0; @@ -5648,10 +5648,9 @@ static void ir_emit_fp2int(ir_ctx *ctx, ir_ref def, ir_insn *insn) |.endif } } else if (IR_IS_CONST_REF(insn->op1)) { - ir_insn *_insn = &ctx->ir_base[insn->op1]; int label = ctx->cfg_blocks_count - insn->op1; - _insn->const_flags |= IR_CONST_EMIT; + ir_bitset_incl(data->emit_constants, -insn->op1); if (!dst64) { if (src_type == IR_DOUBLE) { if (ctx->mflags & IR_X86_AVX) { @@ -5771,10 +5770,9 @@ static void ir_emit_fp2fp(ir_ctx *ctx, ir_ref def, ir_insn *insn) } } } else if (IR_IS_CONST_REF(insn->op1)) { - ir_insn *_insn = &ctx->ir_base[insn->op1]; int label = ctx->cfg_blocks_count - insn->op1; - _insn->const_flags |= IR_CONST_EMIT; + ir_bitset_incl(data->emit_constants, -insn->op1); if (src_type == IR_DOUBLE) { if (ctx->mflags & IR_X86_AVX) { | vcvtsd2ss xmm(def_reg-IR_REG_FP_FIRST), xmm(def_reg-IR_REG_FP_FIRST), qword [=>label] @@ -7149,13 +7147,13 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg if (val_insn->op == IR_STR) { int label = ctx->cfg_blocks_count - arg; - val_insn->const_flags |= IR_CONST_EMIT; + ir_bitset_incl(data->emit_constants, -arg); | lea Ra(dst_reg), aword [=>label] continue; } else if (val_insn->op == IR_SYM || val_insn->op == IR_FUNC) { void *addr = (ctx->loader && ctx->loader->resolve_sym_name) ? - ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, val_insn->val.i32)) : - ir_resolve_sym_name(ir_get_str(ctx, val_insn->val.i32)); + ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, val_insn->val.name)) : + ir_resolve_sym_name(ir_get_str(ctx, val_insn->val.name)); if (sizeof(void*) == 4 || IR_IS_SIGNED_32BIT(addr)) { | mov Ra(dst_reg), ((ptrdiff_t)addr) } else { @@ -7222,7 +7220,7 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg if (val_insn->op == IR_STR) { int label = ctx->cfg_blocks_count - arg; - val_insn->const_flags |= IR_CONST_EMIT; + ir_bitset_incl(data->emit_constants, -arg); IR_ASSERT(tmp_reg != IR_REG_NONE); |.if X64 | lea Ra(tmp_reg), aword [=>label] @@ -7232,8 +7230,8 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg |.endif } else if (val_insn->op == IR_FUNC || val_insn->op == IR_SYM) { void *addr = (ctx->loader && ctx->loader->resolve_sym_name) ? - ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, val_insn->val.i32)) : - ir_resolve_sym_name(ir_get_str(ctx, val_insn->val.i32)); + ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, val_insn->val.name)) : + ir_resolve_sym_name(ir_get_str(ctx, val_insn->val.name)); if (sizeof(void*) == 4) { | mov aword [Ra(IR_REG_RSP)+stack_offset], ((ptrdiff_t)addr) |.if X64 @@ -7352,8 +7350,8 @@ static void ir_emit_call(ir_ctx *ctx, ir_ref def, ir_insn *insn) IR_ASSERT(addr_insn->type == IR_ADDR); if (addr_insn->op == IR_FUNC) { addr = (ctx->loader && ctx->loader->resolve_sym_name) ? - ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, addr_insn->val.i32)) : - ir_resolve_sym_name(ir_get_str(ctx, addr_insn->val.i32)); + ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, addr_insn->val.name)) : + ir_resolve_sym_name(ir_get_str(ctx, addr_insn->val.name)); } else { IR_ASSERT(addr_insn->op == IR_ADDR || addr_insn->op == IR_FUNC_ADDR); addr = (void*)addr_insn->val.addr; @@ -7501,8 +7499,8 @@ static void ir_emit_tailcall(ir_ctx *ctx, ir_ref def, ir_insn *insn) IR_ASSERT(addr_insn->type == IR_ADDR); if (addr_insn->op == IR_FUNC) { addr = (ctx->loader && ctx->loader->resolve_sym_name) ? - ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, addr_insn->val.i32)) : - ir_resolve_sym_name(ir_get_str(ctx, addr_insn->val.i32)); + ctx->loader->resolve_sym_name(ctx->loader, ir_get_str(ctx, addr_insn->val.name)) : + ir_resolve_sym_name(ir_get_str(ctx, addr_insn->val.name)); } else { IR_ASSERT(addr_insn->op == IR_ADDR || addr_insn->op == IR_FUNC_ADDR); addr = (void*)addr_insn->val.addr; @@ -8941,6 +8939,7 @@ void *ir_emit_code(ir_ctx *ctx, size_t *size_ptr) dasm_setup(&data.dasm_state, dasm_actions); /* labels for each block + for each constant + rodata label + jmp_table label + for each entry */ dasm_growpc(&data.dasm_state, ctx->cfg_blocks_count + 1 + ctx->consts_count + 1 + 1 + 1 + ctx->entries_count); + data.emit_constants = ir_bitset_malloc(ctx->consts_count); if ((ctx->flags & IR_GEN_ENDBR) && (ctx->flags & IR_START_BR_TARGET)) { |.if X64 @@ -9319,6 +9318,7 @@ void *ir_emit_code(ir_ctx *ctx, size_t *size_ptr) ir_emit_trunc(ctx, i, insn); break; case IR_BITCAST: + case IR_PROTO: ir_emit_bitcast(ctx, i, insn); break; case IR_INT2FP: @@ -9536,6 +9536,7 @@ void *ir_emit_code(ir_ctx *ctx, size_t *size_ptr) break; default: IR_ASSERT(0 && "NIY rule/instruction"); + ir_mem_free(data.emit_constants); dasm_free(&data.dasm_state); ctx->data = NULL; ctx->status = IR_ERROR_UNSUPPORTED_CODE_RULE; @@ -9552,95 +9553,95 @@ next_block:; if (data.rodata_label) { |.rodata } - for (i = IR_UNUSED + 1, insn = ctx->ir_base - i; i < ctx->consts_count; i++, insn--) { - if (insn->const_flags & IR_CONST_EMIT) { - if (IR_IS_TYPE_FP(insn->type)) { - int label = ctx->cfg_blocks_count + i; + IR_BITSET_FOREACH(data.emit_constants, ir_bitset_len(ctx->consts_count), i) { + insn = &ctx->ir_base[-i]; + if (IR_IS_TYPE_FP(insn->type)) { + int label = ctx->cfg_blocks_count + i; - if (!data.rodata_label) { - data.rodata_label = ctx->cfg_blocks_count + ctx->consts_count + 2; + if (!data.rodata_label) { + data.rodata_label = ctx->cfg_blocks_count + ctx->consts_count + 2; - |.rodata - |=>data.rodata_label: - } - if (insn->type == IR_DOUBLE) { - |.align 8 - |=>label: - |.dword insn->val.u32, insn->val.u32_hi - } else { - IR_ASSERT(insn->type == IR_FLOAT); - |.align 4 - |=>label: - |.dword insn->val.u32 - } - } else if (insn->op == IR_STR) { - int label = ctx->cfg_blocks_count + i; - const char *str = ir_get_str(ctx, insn->val.i32); - int i = 0; - - if (!data.rodata_label) { - data.rodata_label = ctx->cfg_blocks_count + ctx->consts_count + 2; - - |.rodata - |=>data.rodata_label: - } + |.rodata + |=>data.rodata_label: + } + if (insn->type == IR_DOUBLE) { |.align 8 |=>label: - while (str[i]) { - char c = str[i]; - - if (c == '\\') { - if (str[i+1] == '\\') { - i++; - c = '\\'; - } else if (str[i+1] == '\'') { - i++; - c = '\''; - } else if (str[i+1] == '"') { - i++; - c = '"'; - } else if (str[i+1] == 'a') { - i++; - c = '\a'; - } else if (str[i+1] == 'b') { - i++; - c = '\b'; - } else if (str[i+1] == 'e') { - i++; - c = 27; /* '\e'; */ - } else if (str[i+1] == 'f') { - i++; - c = '\f'; - } else if (str[i+1] == 'n') { - i++; - c = '\n'; - } else if (str[i+1] == 'r') { - i++; - c = '\r'; - } else if (str[i+1] == 't') { - i++; - c = '\t'; - } else if (str[i+1] == 'v') { - i++; - c = '\v'; - } else if (str[i+1] == '?') { - i++; - c = 0x3f; - } - } - |.byte c - i++; - } - |.byte 0 - + |.dword insn->val.u32, insn->val.u32_hi } else { - IR_ASSERT(0); + IR_ASSERT(insn->type == IR_FLOAT); + |.align 4 + |=>label: + |.dword insn->val.u32 } + } else if (insn->op == IR_STR) { + int label = ctx->cfg_blocks_count + i; + const char *str = ir_get_str(ctx, insn->val.str); + int i = 0; + + if (!data.rodata_label) { + data.rodata_label = ctx->cfg_blocks_count + ctx->consts_count + 2; + + |.rodata + |=>data.rodata_label: + } + |.align 8 + |=>label: + while (str[i]) { + char c = str[i]; + + if (c == '\\') { + if (str[i+1] == '\\') { + i++; + c = '\\'; + } else if (str[i+1] == '\'') { + i++; + c = '\''; + } else if (str[i+1] == '"') { + i++; + c = '"'; + } else if (str[i+1] == 'a') { + i++; + c = '\a'; + } else if (str[i+1] == 'b') { + i++; + c = '\b'; + } else if (str[i+1] == 'e') { + i++; + c = 27; /* '\e'; */ + } else if (str[i+1] == 'f') { + i++; + c = '\f'; + } else if (str[i+1] == 'n') { + i++; + c = '\n'; + } else if (str[i+1] == 'r') { + i++; + c = '\r'; + } else if (str[i+1] == 't') { + i++; + c = '\t'; + } else if (str[i+1] == 'v') { + i++; + c = '\v'; + } else if (str[i+1] == '?') { + i++; + c = 0x3f; + } + } + |.byte c + i++; + } + |.byte 0 + + } else { + IR_ASSERT(0); } - } + } IR_BITSET_FOREACH_END(); if (data.rodata_label) { |.code } + ir_mem_free(data.emit_constants); if (ctx->status) { dasm_free(&data.dasm_state); @@ -9660,7 +9661,6 @@ next_block:; if (ctx->code_buffer != NULL) { if (IR_ALIGNED_SIZE(size, 16) > ctx->code_buffer_size) { - dasm_free(&data.dasm_state); ctx->data = NULL; ctx->status = IR_ERROR_CODE_MEM_OVERFLOW; return NULL; diff --git a/tests/debug.Windows-x86_64/args_001.irt b/tests/debug.Windows-x86_64/args_001.irt index 009b35a..45eb35f 100755 --- a/tests/debug.Windows-x86_64/args_001.irt +++ b/tests/debug.Windows-x86_64/args_001.irt @@ -16,7 +16,7 @@ Windows-x86_64 uint32_t c_8 = 8; int64_t c_9 = 9; int64_t c_10 = 0x100000000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t fmt = "%d %d %d %lld 0x%llx %d %d %d %lld 0x%llx\n"; l_1 = START(l_3); int32_t d_2, l_2 = CALL/11(l_1, f, fmt, c_1, c_2, c_3, c_4, c_5, c_6, c_7, c_8, c_9, c_10); diff --git a/tests/debug.Windows-x86_64/args_002.irt b/tests/debug.Windows-x86_64/args_002.irt index 6c3e447..08baaa8 100755 --- a/tests/debug.Windows-x86_64/args_002.irt +++ b/tests/debug.Windows-x86_64/args_002.irt @@ -16,7 +16,7 @@ Windows-x86_64 double c_8 = 0.8; double c_9 = 0.9; double c_10 = 0.0; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t fmt = "%g %g %g %g %g %g %g %g %g %g\n"; l_1 = START(l_3); int32_t d_2, l_2 = CALL/11(l_1, f, fmt, c_1, c_2, c_3, c_4, c_5, c_6, c_7, c_8, c_9, c_10); diff --git a/tests/debug.Windows-x86_64/call-O0.irt b/tests/debug.Windows-x86_64/call-O0.irt index a0a59ca..fb72493 100755 --- a/tests/debug.Windows-x86_64/call-O0.irt +++ b/tests/debug.Windows-x86_64/call-O0.irt @@ -10,7 +10,7 @@ Windows-x86_64 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t d_2, l_2 = CALL/2(l_1, c_5, c_6, c_4); diff --git a/tests/debug.Windows-x86_64/call.irt b/tests/debug.Windows-x86_64/call.irt index 79f1f07..efd0271 100755 --- a/tests/debug.Windows-x86_64/call.irt +++ b/tests/debug.Windows-x86_64/call.irt @@ -10,7 +10,7 @@ Windows-x86_64 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t d_2, l_2 = CALL/2(l_1, c_5, c_6, c_4); diff --git a/tests/debug.Windows-x86_64/call2.irt b/tests/debug.Windows-x86_64/call2.irt index 2dfd18d..d88a8b1 100755 --- a/tests/debug.Windows-x86_64/call2.irt +++ b/tests/debug.Windows-x86_64/call2.irt @@ -10,7 +10,7 @@ Windows-x86_64 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t p_1 = PARAM(l_1, "p1", 1); diff --git a/tests/debug.Windows-x86_64/call_alloca.irt b/tests/debug.Windows-x86_64/call_alloca.irt index 5234036..71d00d4 100755 --- a/tests/debug.Windows-x86_64/call_alloca.irt +++ b/tests/debug.Windows-x86_64/call_alloca.irt @@ -19,7 +19,7 @@ Windows-x86_64 char zero = 0; uint32_t len = 7; uintptr_t one = 1; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; l_1 = START(l_4); uintptr_t a_0, s_0 = ALLOCA(l_1, len); s_1 = STORE(s_0, a_0, h); diff --git a/tests/debug.Windows-x86_64/call_vaddr.irt b/tests/debug.Windows-x86_64/call_vaddr.irt index f4d2ac8..fa217cf 100755 --- a/tests/debug.Windows-x86_64/call_vaddr.irt +++ b/tests/debug.Windows-x86_64/call_vaddr.irt @@ -18,7 +18,7 @@ Windows-x86_64 char nl = '\n'; char zero = 0; uintptr_t one = 1; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; l_1 = START(l_4); uint64_t var_1 = VAR(l_1, "str"); uintptr_t a_0 = VADDR(var_1); diff --git a/tests/debug.Windows-x86_64/params_003.irt b/tests/debug.Windows-x86_64/params_003.irt index 01e374e..65f31f2 100755 --- a/tests/debug.Windows-x86_64/params_003.irt +++ b/tests/debug.Windows-x86_64/params_003.irt @@ -6,7 +6,7 @@ Windows-x86_64 -S --CODE-- { - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t fmt = "%d %d %d %d %d %d %d %d %d %d\n"; l_1 = START(l_3); int32_t p_1 = PARAM(l_1, "p_1", 1); diff --git a/tests/debug.Windows-x86_64/regset-fib.irt b/tests/debug.Windows-x86_64/regset-fib.irt index 9a6d4b7..03c8a49 100755 --- a/tests/debug.Windows-x86_64/regset-fib.irt +++ b/tests/debug.Windows-x86_64/regset-fib.irt @@ -10,7 +10,7 @@ Windows-x86_64 double c_0 = 0; double c_1 = 1; double c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%g\n"; l_1 = START(l_6); double lo_1 = COPY(c_0); @@ -40,7 +40,7 @@ Windows-x86_64 double c_5 = 0; double c_6 = 1; double c_7 = 10000; - uintptr_t c_8 = func(printf, 4); + uintptr_t c_8 = func printf(uintptr_t, ...): int32_t; uintptr_t c_9 = "%g\n"; l_1 = START(l_15); l_2 = END(l_1); diff --git a/tests/debug.Windows-x86_64/regset-fib2.irt b/tests/debug.Windows-x86_64/regset-fib2.irt index 47a3200..a3a3414 100755 --- a/tests/debug.Windows-x86_64/regset-fib2.irt +++ b/tests/debug.Windows-x86_64/regset-fib2.irt @@ -10,7 +10,7 @@ Windows-x86_64 double c_0 = 0; double c_1 = 1; double c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%g\n"; l_1 = START(l_6); double lo_1 = COPY(c_0); @@ -39,7 +39,7 @@ Windows-x86_64 double c_5 = 0; double c_6 = 1; double c_7 = 10000; - uintptr_t c_8 = func(printf, 4); + uintptr_t c_8 = func printf(uintptr_t, ...): int32_t; uintptr_t c_9 = "%g\n"; l_1 = START(l_17); l_2 = END(l_1); diff --git a/tests/debug.Windows-x86_64/regset-fibi.irt b/tests/debug.Windows-x86_64/regset-fibi.irt index cd8685b..4da6ee7 100755 --- a/tests/debug.Windows-x86_64/regset-fibi.irt +++ b/tests/debug.Windows-x86_64/regset-fibi.irt @@ -9,7 +9,7 @@ Windows-x86_64 int32_t c_0 = 0; int32_t c_1 = 1; int32_t c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%d\n"; l_1 = START(l_6); int32_t lo_1 = COPY(c_0); @@ -36,7 +36,7 @@ Windows-x86_64 int32_t c_4 = 0; int32_t c_5 = 1; int32_t c_6 = 10000; - uintptr_t c_7 = func(printf, 4); + uintptr_t c_7 = func printf(uintptr_t, ...): int32_t; uintptr_t c_8 = "%d\n"; l_1 = START(l_14); l_2 = END(l_1); diff --git a/tests/debug.Windows-x86_64/tailcall_001.irt b/tests/debug.Windows-x86_64/tailcall_001.irt index 8a72d5f..1965f64 100755 --- a/tests/debug.Windows-x86_64/tailcall_001.irt +++ b/tests/debug.Windows-x86_64/tailcall_001.irt @@ -10,7 +10,7 @@ Windows-x86_64 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); char d_2, l_2 = TAILCALL/2(l_1, c_5, c_6, c_4); diff --git a/tests/debug.aarch64/args_001.irt b/tests/debug.aarch64/args_001.irt index d58725b..38d90b9 100644 --- a/tests/debug.aarch64/args_001.irt +++ b/tests/debug.aarch64/args_001.irt @@ -16,7 +16,7 @@ aarch64 uint32_t c_8 = 8; int64_t c_9 = 9; int64_t c_10 = 0x100000000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t fmt = "%d %d %d %lld 0x%llx %d %d %d %lld 0x%llx\n"; l_1 = START(l_3); int32_t d_2, l_2 = CALL/11(l_1, f, fmt, c_1, c_2, c_3, c_4, c_5, c_6, c_7, c_8, c_9, c_10); diff --git a/tests/debug.aarch64/args_002.irt b/tests/debug.aarch64/args_002.irt index d5a385f..a2d8345 100644 --- a/tests/debug.aarch64/args_002.irt +++ b/tests/debug.aarch64/args_002.irt @@ -16,7 +16,7 @@ aarch64 double c_8 = 0.8; double c_9 = 0.9; double c_10 = 0.0; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t fmt = "%g %g %g %g %g %g %g %g %g %g\n"; l_1 = START(l_3); int32_t d_2, l_2 = CALL/11(l_1, f, fmt, c_1, c_2, c_3, c_4, c_5, c_6, c_7, c_8, c_9, c_10); diff --git a/tests/debug.aarch64/call-O0.irt b/tests/debug.aarch64/call-O0.irt index 22a6050..b057ea9 100644 --- a/tests/debug.aarch64/call-O0.irt +++ b/tests/debug.aarch64/call-O0.irt @@ -10,7 +10,7 @@ aarch64 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t d_2, l_2 = CALL/2(l_1, c_5, c_6, c_4); diff --git a/tests/debug.aarch64/call.irt b/tests/debug.aarch64/call.irt index 1a54fdc..c35a90e 100644 --- a/tests/debug.aarch64/call.irt +++ b/tests/debug.aarch64/call.irt @@ -10,7 +10,7 @@ aarch64 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t d_2, l_2 = CALL/2(l_1, c_5, c_6, c_4); diff --git a/tests/debug.aarch64/call2.irt b/tests/debug.aarch64/call2.irt index b455373..5c157a9 100644 --- a/tests/debug.aarch64/call2.irt +++ b/tests/debug.aarch64/call2.irt @@ -10,7 +10,7 @@ aarch64 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t p_1 = PARAM(l_1, "p1", 1); diff --git a/tests/debug.aarch64/call_alloca.irt b/tests/debug.aarch64/call_alloca.irt index f1d4b97..10f5c19 100644 --- a/tests/debug.aarch64/call_alloca.irt +++ b/tests/debug.aarch64/call_alloca.irt @@ -19,7 +19,7 @@ aarch64 char zero = 0; uint32_t len = 7; uintptr_t one = 1; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; l_1 = START(l_4); uintptr_t a_0, s_0 = ALLOCA(l_1, len); s_1 = STORE(s_0, a_0, h); diff --git a/tests/debug.aarch64/call_vaddr.irt b/tests/debug.aarch64/call_vaddr.irt index f3ce9fa..7e948d9 100644 --- a/tests/debug.aarch64/call_vaddr.irt +++ b/tests/debug.aarch64/call_vaddr.irt @@ -18,7 +18,7 @@ aarch64 char nl = '\n'; char zero = 0; uintptr_t one = 1; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; l_1 = START(l_4); uint64_t var_1 = VAR(l_1, "str"); uintptr_t a_0 = VADDR(var_1); diff --git a/tests/debug.aarch64/params_003.irt b/tests/debug.aarch64/params_003.irt index 573da71..e9b7325 100644 --- a/tests/debug.aarch64/params_003.irt +++ b/tests/debug.aarch64/params_003.irt @@ -6,7 +6,7 @@ aarch64 -S --CODE-- { - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t fmt = "%d %d %d %d %d %d %d %d %d %d\n"; l_1 = START(l_3); int32_t p_1 = PARAM(l_1, "p_1", 1); diff --git a/tests/debug.aarch64/regset-fib.irt b/tests/debug.aarch64/regset-fib.irt index 79fe8c3..ed249a3 100644 --- a/tests/debug.aarch64/regset-fib.irt +++ b/tests/debug.aarch64/regset-fib.irt @@ -10,7 +10,7 @@ aarch64 double c_0 = 0; double c_1 = 1; double c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%g\n"; l_1 = START(l_6); double lo_1 = COPY(c_0); @@ -40,7 +40,7 @@ aarch64 double c_5 = 0; double c_6 = 1; double c_7 = 10000; - uintptr_t c_8 = func(printf, 4); + uintptr_t c_8 = func printf(uintptr_t, ...): int32_t; uintptr_t c_9 = "%g\n"; l_1 = START(l_15); l_2 = END(l_1); diff --git a/tests/debug.aarch64/regset-fib2.irt b/tests/debug.aarch64/regset-fib2.irt index 8b01655..b836689 100644 --- a/tests/debug.aarch64/regset-fib2.irt +++ b/tests/debug.aarch64/regset-fib2.irt @@ -10,7 +10,7 @@ aarch64 double c_0 = 0; double c_1 = 1; double c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%g\n"; l_1 = START(l_6); double lo_1 = COPY(c_0); @@ -39,7 +39,7 @@ aarch64 double c_5 = 0; double c_6 = 1; double c_7 = 10000; - uintptr_t c_8 = func(printf, 4); + uintptr_t c_8 = func printf(uintptr_t, ...): int32_t; uintptr_t c_9 = "%g\n"; l_1 = START(l_17); l_2 = END(l_1); diff --git a/tests/debug.aarch64/regset-fibi.irt b/tests/debug.aarch64/regset-fibi.irt index e7f40d6..4f25831 100644 --- a/tests/debug.aarch64/regset-fibi.irt +++ b/tests/debug.aarch64/regset-fibi.irt @@ -9,7 +9,7 @@ aarch64 int32_t c_0 = 0; int32_t c_1 = 1; int32_t c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%d\n"; l_1 = START(l_6); int32_t lo_1 = COPY(c_0); @@ -36,7 +36,7 @@ aarch64 int32_t c_4 = 0; int32_t c_5 = 1; int32_t c_6 = 10000; - uintptr_t c_7 = func(printf, 4); + uintptr_t c_7 = func printf(uintptr_t, ...): int32_t; uintptr_t c_8 = "%d\n"; l_1 = START(l_14); l_2 = END(l_1); diff --git a/tests/debug.aarch64/tailcall_001.irt b/tests/debug.aarch64/tailcall_001.irt index 27352a3..b410424 100644 --- a/tests/debug.aarch64/tailcall_001.irt +++ b/tests/debug.aarch64/tailcall_001.irt @@ -10,7 +10,7 @@ aarch64 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); char d_2, l_2 = TAILCALL/2(l_1, c_5, c_6, c_4); diff --git a/tests/debug.x86/args_001.irt b/tests/debug.x86/args_001.irt index 5a07d31..8be0e35 100644 --- a/tests/debug.x86/args_001.irt +++ b/tests/debug.x86/args_001.irt @@ -16,7 +16,7 @@ x86 uint32_t c_8 = 8; int32_t c_9 = 9; int32_t c_10 = 10; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t fmt = "%d %d %d %d %d %d %d %d %d %d\n"; l_1 = START(l_3); int32_t d_2, l_2 = CALL/11(l_1, f, fmt, c_1, c_2, c_3, c_4, c_5, c_6, c_7, c_8, c_9, c_10); diff --git a/tests/debug.x86/args_002.irt b/tests/debug.x86/args_002.irt index d5360ea..811dd71 100644 --- a/tests/debug.x86/args_002.irt +++ b/tests/debug.x86/args_002.irt @@ -16,7 +16,7 @@ x86 double c_8 = 0.8; double c_9 = 0.9; double c_10 = 0.0; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t fmt = "%g %g %g %g %g %g %g %g %g %g\n"; l_1 = START(l_3); int32_t d_2, l_2 = CALL/11(l_1, f, fmt, c_1, c_2, c_3, c_4, c_5, c_6, c_7, c_8, c_9, c_10); diff --git a/tests/debug.x86/call-O0.irt b/tests/debug.x86/call-O0.irt index f0b23b0..ac8d4db 100644 --- a/tests/debug.x86/call-O0.irt +++ b/tests/debug.x86/call-O0.irt @@ -10,7 +10,7 @@ x86 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t d_2, l_2 = CALL/2(l_1, c_5, c_6, c_4); diff --git a/tests/debug.x86/call.irt b/tests/debug.x86/call.irt index a9a5527..544676e 100644 --- a/tests/debug.x86/call.irt +++ b/tests/debug.x86/call.irt @@ -10,7 +10,7 @@ x86 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t d_2, l_2 = CALL/2(l_1, c_5, c_6, c_4); diff --git a/tests/debug.x86/call2.irt b/tests/debug.x86/call2.irt index fd6c821..dec0c15 100644 --- a/tests/debug.x86/call2.irt +++ b/tests/debug.x86/call2.irt @@ -10,7 +10,7 @@ x86 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t p_1 = PARAM(l_1, "p1", 1); diff --git a/tests/debug.x86/call_alloca.irt b/tests/debug.x86/call_alloca.irt index 1b19e3a..85424fa 100644 --- a/tests/debug.x86/call_alloca.irt +++ b/tests/debug.x86/call_alloca.irt @@ -19,7 +19,7 @@ x86 char zero = 0; uint32_t len = 7; uintptr_t one = 1; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; l_1 = START(l_4); uintptr_t a_0, s_0 = ALLOCA(l_1, len); s_1 = STORE(s_0, a_0, h); diff --git a/tests/debug.x86/call_vaddr.irt b/tests/debug.x86/call_vaddr.irt index 69ec6df..fae4574 100644 --- a/tests/debug.x86/call_vaddr.irt +++ b/tests/debug.x86/call_vaddr.irt @@ -18,7 +18,7 @@ x86 char nl = '\n'; char zero = 0; uintptr_t one = 1; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; l_1 = START(l_4); uint64_t var_1 = VAR(l_1, "str"); uintptr_t a_0 = VADDR(var_1); diff --git a/tests/debug.x86/params_003.irt b/tests/debug.x86/params_003.irt index 46a69c9..aacac48 100644 --- a/tests/debug.x86/params_003.irt +++ b/tests/debug.x86/params_003.irt @@ -6,7 +6,7 @@ x86 -S --CODE-- { - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t fmt = "%d %d %d %d %d %d %d %d %d %d\n"; l_1 = START(l_3); int32_t p_1 = PARAM(l_1, "p_1", 1); diff --git a/tests/debug.x86/regset-fib.irt b/tests/debug.x86/regset-fib.irt index efc29a4..a93d671 100644 --- a/tests/debug.x86/regset-fib.irt +++ b/tests/debug.x86/regset-fib.irt @@ -10,7 +10,7 @@ x86 double c_0 = 0; double c_1 = 1; double c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%g\n"; l_1 = START(l_6); double lo_1 = COPY(c_0); @@ -40,7 +40,7 @@ x86 double c_5 = 0; double c_6 = 1; double c_7 = 10000; - uintptr_t c_8 = func(printf, 4); + uintptr_t c_8 = func printf(uintptr_t, ...): int32_t; uintptr_t c_9 = "%g\n"; l_1 = START(l_15); l_2 = END(l_1); diff --git a/tests/debug.x86/regset-fib2.irt b/tests/debug.x86/regset-fib2.irt index b39e7e8..3ef41fe 100644 --- a/tests/debug.x86/regset-fib2.irt +++ b/tests/debug.x86/regset-fib2.irt @@ -10,7 +10,7 @@ x86 double c_0 = 0; double c_1 = 1; double c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%g\n"; l_1 = START(l_6); double lo_1 = COPY(c_0); @@ -39,7 +39,7 @@ x86 double c_5 = 0; double c_6 = 1; double c_7 = 10000; - uintptr_t c_8 = func(printf, 4); + uintptr_t c_8 = func printf(uintptr_t, ...): int32_t; uintptr_t c_9 = "%g\n"; l_1 = START(l_17); l_2 = END(l_1); diff --git a/tests/debug.x86/regset-fibi.irt b/tests/debug.x86/regset-fibi.irt index 508e376..086c77f 100644 --- a/tests/debug.x86/regset-fibi.irt +++ b/tests/debug.x86/regset-fibi.irt @@ -9,7 +9,7 @@ x86 int32_t c_0 = 0; int32_t c_1 = 1; int32_t c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%d\n"; l_1 = START(l_6); int32_t lo_1 = COPY(c_0); @@ -36,7 +36,7 @@ x86 int32_t c_4 = 0; int32_t c_5 = 1; int32_t c_6 = 10000; - uintptr_t c_7 = func(printf, 4); + uintptr_t c_7 = func printf(uintptr_t, ...): int32_t; uintptr_t c_8 = "%d\n"; l_1 = START(l_14); l_2 = END(l_1); diff --git a/tests/debug.x86/tailcall_001.irt b/tests/debug.x86/tailcall_001.irt index 1362618..f596c7f 100644 --- a/tests/debug.x86/tailcall_001.irt +++ b/tests/debug.x86/tailcall_001.irt @@ -12,7 +12,7 @@ TAILCALL for functions with stack argumnts is not implemented bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); char d_2, l_2 = TAILCALL/2(l_1, c_5, c_6, c_4); diff --git a/tests/debug/args_001.irt b/tests/debug/args_001.irt index dd8a6f7..96d1742 100644 --- a/tests/debug/args_001.irt +++ b/tests/debug/args_001.irt @@ -16,7 +16,7 @@ x86_64 uint32_t c_8 = 8; int64_t c_9 = 9; int64_t c_10 = 0x100000000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t fmt = "%d %d %d %lld 0x%llx %d %d %d %lld 0x%llx\n"; l_1 = START(l_3); int32_t d_2, l_2 = CALL/11(l_1, f, fmt, c_1, c_2, c_3, c_4, c_5, c_6, c_7, c_8, c_9, c_10); diff --git a/tests/debug/args_002.irt b/tests/debug/args_002.irt index df911b5..6421991 100644 --- a/tests/debug/args_002.irt +++ b/tests/debug/args_002.irt @@ -16,7 +16,7 @@ x86_64 double c_8 = 0.8; double c_9 = 0.9; double c_10 = 0.0; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t fmt = "%g %g %g %g %g %g %g %g %g %g\n"; l_1 = START(l_3); int32_t d_2, l_2 = CALL/11(l_1, f, fmt, c_1, c_2, c_3, c_4, c_5, c_6, c_7, c_8, c_9, c_10); diff --git a/tests/debug/call-O0.irt b/tests/debug/call-O0.irt index 8811ddb..3f1365d 100644 --- a/tests/debug/call-O0.irt +++ b/tests/debug/call-O0.irt @@ -10,7 +10,7 @@ x86_64 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t d_2, l_2 = CALL/2(l_1, c_5, c_6, c_4); diff --git a/tests/debug/call.irt b/tests/debug/call.irt index dce7707..5d23b4e 100644 --- a/tests/debug/call.irt +++ b/tests/debug/call.irt @@ -10,7 +10,7 @@ x86_64 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t d_2, l_2 = CALL/2(l_1, c_5, c_6, c_4); diff --git a/tests/debug/call2.irt b/tests/debug/call2.irt index 0775301..6105b8a 100644 --- a/tests/debug/call2.irt +++ b/tests/debug/call2.irt @@ -10,7 +10,7 @@ x86_64 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t p_1 = PARAM(l_1, "p1", 1); diff --git a/tests/debug/call_003.irt b/tests/debug/call_003.irt index 1e3f4cc..0d96373 100644 --- a/tests/debug/call_003.irt +++ b/tests/debug/call_003.irt @@ -9,7 +9,7 @@ x86_64 uintptr_t c_1 = 0; bool c_2 = 0; bool c_3 = 1; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d %d!\n"; l_1 = START(l_4); int32_t p_1 = PARAM(l_1, "x", 0); diff --git a/tests/debug/call_alloca.irt b/tests/debug/call_alloca.irt index d81d281..214c458 100644 --- a/tests/debug/call_alloca.irt +++ b/tests/debug/call_alloca.irt @@ -19,7 +19,7 @@ x86_64 char zero = 0; uint32_t len = 7; uintptr_t one = 1; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; l_1 = START(l_4); uintptr_t a_0, s_0 = ALLOCA(l_1, len); s_1 = STORE(s_0, a_0, h); diff --git a/tests/debug/call_vaddr.irt b/tests/debug/call_vaddr.irt index 1b7a17b..2485c27 100644 --- a/tests/debug/call_vaddr.irt +++ b/tests/debug/call_vaddr.irt @@ -18,7 +18,7 @@ x86_64 char nl = '\n'; char zero = 0; uintptr_t one = 1; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; l_1 = START(l_4); uint64_t var_1 = VAR(l_1, "str"); uintptr_t a_0 = VADDR(var_1); diff --git a/tests/debug/params_003.irt b/tests/debug/params_003.irt index 4615fb4..4dec88b 100644 --- a/tests/debug/params_003.irt +++ b/tests/debug/params_003.irt @@ -6,7 +6,7 @@ x86_64 -S --CODE-- { - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t fmt = "%d %d %d %d %d %d %d %d %d %d\n"; l_1 = START(l_3); int32_t p_1 = PARAM(l_1, "p_1", 1); diff --git a/tests/debug/ra_002.irt b/tests/debug/ra_002.irt index dd7d30c..183ab98 100644 --- a/tests/debug/ra_002.irt +++ b/tests/debug/ra_002.irt @@ -6,7 +6,7 @@ x86_64 -S --CODE-- { - uintptr_t fn = func(printf, 4); + uintptr_t fn = func printf(uintptr_t, ...): int32_t; uintptr_t format = "hello\n"; l_1 = START(l_3); double x = PARAM(l_1, "x", 1); diff --git a/tests/debug/ra_003.irt b/tests/debug/ra_003.irt index 5570c36..8ace149 100644 --- a/tests/debug/ra_003.irt +++ b/tests/debug/ra_003.irt @@ -6,7 +6,7 @@ x86_64 -S --CODE-- { - uintptr_t fn = func(printf, 4); + uintptr_t fn = func printf(uintptr_t, ...): int32_t; uintptr_t format = "hello\n"; l_1 = START(l_3); double x = PARAM(l_1, "x", 1); diff --git a/tests/debug/regset-fib.irt b/tests/debug/regset-fib.irt index 861ec9e..701c9d3 100644 --- a/tests/debug/regset-fib.irt +++ b/tests/debug/regset-fib.irt @@ -10,7 +10,7 @@ x86_64 double c_0 = 0; double c_1 = 1; double c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%g\n"; l_1 = START(l_6); double lo_1 = COPY(c_0); @@ -40,7 +40,7 @@ x86_64 double c_5 = 0; double c_6 = 1; double c_7 = 10000; - uintptr_t c_8 = func(printf, 4); + uintptr_t c_8 = func printf(uintptr_t, ...): int32_t; uintptr_t c_9 = "%g\n"; l_1 = START(l_15); l_2 = END(l_1); diff --git a/tests/debug/regset-fib2.irt b/tests/debug/regset-fib2.irt index a06739b..a7fd054 100644 --- a/tests/debug/regset-fib2.irt +++ b/tests/debug/regset-fib2.irt @@ -10,7 +10,7 @@ x86_64 double c_0 = 0; double c_1 = 1; double c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%g\n"; l_1 = START(l_6); double lo_1 = COPY(c_0); @@ -39,7 +39,7 @@ x86_64 double c_5 = 0; double c_6 = 1; double c_7 = 10000; - uintptr_t c_8 = func(printf, 4); + uintptr_t c_8 = func printf(uintptr_t, ...): int32_t; uintptr_t c_9 = "%g\n"; l_1 = START(l_17); l_2 = END(l_1); diff --git a/tests/debug/regset-fibi.irt b/tests/debug/regset-fibi.irt index ea70779..b475283 100644 --- a/tests/debug/regset-fibi.irt +++ b/tests/debug/regset-fibi.irt @@ -9,7 +9,7 @@ x86_64 int32_t c_0 = 0; int32_t c_1 = 1; int32_t c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%d\n"; l_1 = START(l_6); int32_t lo_1 = COPY(c_0); @@ -36,7 +36,7 @@ x86_64 int32_t c_4 = 0; int32_t c_5 = 1; int32_t c_6 = 10000; - uintptr_t c_7 = func(printf, 4); + uintptr_t c_7 = func printf(uintptr_t, ...): int32_t; uintptr_t c_8 = "%d\n"; l_1 = START(l_14); l_2 = END(l_1); diff --git a/tests/debug/tailcall_001.irt b/tests/debug/tailcall_001.irt index b468a65..f7ea28e 100644 --- a/tests/debug/tailcall_001.irt +++ b/tests/debug/tailcall_001.irt @@ -10,7 +10,7 @@ x86_64 bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); char d_2, l_2 = TAILCALL/2(l_1, c_5, c_6, c_4); diff --git a/tests/fibi_min.irt b/tests/fibi_min.irt index 503cb21..6414098 100644 --- a/tests/fibi_min.irt +++ b/tests/fibi_min.irt @@ -8,7 +8,7 @@ FibI int32_t c_1 = 1; int32_t c_100 = 100; int32_t c_10000 = 10000; - uintptr_t f = func(printf, 4); + uintptr_t f = func printf(uintptr_t, ...): int32_t; uintptr_t format = "%d\n"; l_1 = START(l_6); int32_t lo_1 = COPY(c_0); diff --git a/tests/fp_const.irt b/tests/fp_const.irt index df6c7df..1b94ceb 100644 --- a/tests/fp_const.irt +++ b/tests/fp_const.irt @@ -4,7 +4,7 @@ Floating point constants --save --CODE-- { - uintptr_t c_1 = func(printf, 4); + uintptr_t c_1 = func printf(uintptr_t, ...): int32_t; uintptr_t c_2 = "fmt\n"; double c_3 = 16.5; float c_4 = 13.4; @@ -23,7 +23,7 @@ Floating point constants uintptr_t c_1 = 0; bool c_2 = 0; bool c_3 = 1; - uintptr_t c_4 = func(printf, 4); + uintptr_t c_4 = func printf(uintptr_t, ...): int32_t; uintptr_t c_5 = "fmt\n"; double c_6 = 16.5; float c_7 = 13.4; diff --git a/tests/llvm/call_001.irt b/tests/llvm/call_001.irt index 7d2ac16..c4b5f01 100644 --- a/tests/llvm/call_001.irt +++ b/tests/llvm/call_001.irt @@ -8,7 +8,7 @@ Simple CALL bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); int32_t d_2, l_2 = CALL/2(l_1, c_5, c_6, c_4); @@ -20,5 +20,5 @@ define i32 @test() %d2 = call i32 (...) @printf(ptr @.str6, i32 42) ret i32 %d2 } -declare void @printf() +declare i32 @printf(ptr, ...) @.str6 = private unnamed_addr constant [12 x i8] c"hello %d!\0A\00" diff --git a/tests/llvm/tailcall_001.irt b/tests/llvm/tailcall_001.irt index 22d76ac..aab2351 100644 --- a/tests/llvm/tailcall_001.irt +++ b/tests/llvm/tailcall_001.irt @@ -8,7 +8,7 @@ Simple TAILCALL bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 42; - uintptr_t c_5 = func(printf, 4); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; uintptr_t c_6 = "hello %d!\n"; l_1 = START(l_4); char d_2, l_2 = TAILCALL/2(l_1, c_5, c_6, c_4); @@ -20,5 +20,5 @@ define i8 @test() %d2 = tail call i8 (...) @printf(ptr @.str6, i32 42) ret i8 %d2 } -declare void @printf() +declare i32 @printf(ptr, ...) @.str6 = private unnamed_addr constant [12 x i8] c"hello %d!\0A\00" diff --git a/tests/run/ctlz_001.irt b/tests/run/ctlz_001.irt index e17515a..bba23d5 100644 --- a/tests/run/ctlz_001.irt +++ b/tests/run/ctlz_001.irt @@ -41,23 +41,23 @@ func main(void): int32_t bool c_2 = 0; bool c_3 = 1; int8_t c_4 = 1; - uintptr_t c_5 = func(ctlz8); + uintptr_t c_5 = func ctlz8(int8_t): int32_t; int8_t c_6 = 96; int8_t c_7 = -128; uintptr_t c_8 = "u8 : %2d %2d %2d\n"; - uintptr_t c_9 = func(printf); + uintptr_t c_9 = func printf(uintptr_t, ...): int32_t; int16_t c_10 = 1; - uintptr_t c_11 = func(ctlz16); + uintptr_t c_11 = func ctlz16(int16_t): int32_t; int16_t c_12 = 1536; int16_t c_13 = -32768; uintptr_t c_14 = "u16: %2d %2d %2d\n"; int32_t c_15 = 1; - uintptr_t c_16 = func(ctlz32); + uintptr_t c_16 = func ctlz32(int32_t): int32_t; int32_t c_17 = 393216; int32_t c_18 = -2147483648; uintptr_t c_19 = "u32: %2d %2d %2d\n"; int64_t c_20 = 1; - uintptr_t c_21 = func(ctlz64); + uintptr_t c_21 = func ctlz64(int64_t): int32_t; int64_t c_22 = 25769803776; int64_t c_23 = -9223372036854775808; uintptr_t c_24 = "u64: %2d %2d %2d\n"; diff --git a/tests/run/ctlz_002.irt b/tests/run/ctlz_002.irt index ecb8b36..5f41689 100644 --- a/tests/run/ctlz_002.irt +++ b/tests/run/ctlz_002.irt @@ -43,23 +43,23 @@ func main(void): int32_t bool c_2 = 0; bool c_3 = 1; int8_t c_4 = 1; - uintptr_t c_5 = func(ctlz8); + uintptr_t c_5 = func ctlz8(int8_t): int32_t; int8_t c_6 = 96; int8_t c_7 = -128; uintptr_t c_8 = "u8 : %2d %2d %2d\n"; - uintptr_t c_9 = func(printf); + uintptr_t c_9 = func printf(uintptr_t, ...): int32_t; int16_t c_10 = 1; - uintptr_t c_11 = func(ctlz16); + uintptr_t c_11 = func ctlz16(int16_t): int32_t; int16_t c_12 = 1536; int16_t c_13 = -32768; uintptr_t c_14 = "u16: %2d %2d %2d\n"; int32_t c_15 = 1; - uintptr_t c_16 = func(ctlz32); + uintptr_t c_16 = func ctlz32(int32_t): int32_t; int32_t c_17 = 393216; int32_t c_18 = -2147483648; uintptr_t c_19 = "u32: %2d %2d %2d\n"; int64_t c_20 = 1; - uintptr_t c_21 = func(ctlz64); + uintptr_t c_21 = func ctlz64(int64_t): int32_t; int64_t c_22 = 25769803776; int64_t c_23 = -9223372036854775808; uintptr_t c_24 = "u64: %2d %2d %2d\n"; diff --git a/tests/run/ctpop_001.irt b/tests/run/ctpop_001.irt index fdc9d4c..7d1d3d1 100644 --- a/tests/run/ctpop_001.irt +++ b/tests/run/ctpop_001.irt @@ -41,23 +41,23 @@ func main(void): int32_t bool c_2 = 0; bool c_3 = 1; int8_t c_4 = 0; - uintptr_t c_5 = func(ctpop8); + uintptr_t c_5 = func ctpop8(int8_t): int32_t; int8_t c_6 = 85; int8_t c_7 = -1; uintptr_t c_8 = "u8 : %2d %2d %2d\n"; - uintptr_t c_9 = func(printf); + uintptr_t c_9 = func printf(uintptr_t, ...): int32_t; int16_t c_10 = 0; - uintptr_t c_11 = func(ctpop16); + uintptr_t c_11 = func ctpop16(int16_t): int32_t; int16_t c_12 = 21845; int16_t c_13 = -1; uintptr_t c_14 = "u16: %2d %2d %2d\n"; int32_t c_15 = 0; - uintptr_t c_16 = func(ctpop32); + uintptr_t c_16 = func ctpop32(int32_t): int32_t; int32_t c_17 = 1431655765; int32_t c_18 = -1; uintptr_t c_19 = "u32: %2d %2d %2d\n"; int64_t c_20 = 0; - uintptr_t c_21 = func(ctpop64); + uintptr_t c_21 = func ctpop64(int64_t): int32_t; int64_t c_22 = 6148914691236517205; int64_t c_23 = -1; uintptr_t c_24 = "u64: %2d %2d %2d\n"; diff --git a/tests/run/ctpop_002.irt b/tests/run/ctpop_002.irt index b5ad0dc..65f0846 100644 --- a/tests/run/ctpop_002.irt +++ b/tests/run/ctpop_002.irt @@ -43,23 +43,23 @@ func main(void): int32_t bool c_2 = 0; bool c_3 = 1; int8_t c_4 = 0; - uintptr_t c_5 = func(ctpop8); + uintptr_t c_5 = func ctpop8(int8_t): int32_t; int8_t c_6 = 85; int8_t c_7 = -1; uintptr_t c_8 = "u8 : %2d %2d %2d\n"; - uintptr_t c_9 = func(printf); + uintptr_t c_9 = func printf(uintptr_t, ...): int32_t; int16_t c_10 = 0; - uintptr_t c_11 = func(ctpop16); + uintptr_t c_11 = func ctpop16(int16_t): int32_t; int16_t c_12 = 21845; int16_t c_13 = -1; uintptr_t c_14 = "u16: %2d %2d %2d\n"; int32_t c_15 = 0; - uintptr_t c_16 = func(ctpop32); + uintptr_t c_16 = func ctpop32(int32_t): int32_t; int32_t c_17 = 1431655765; int32_t c_18 = -1; uintptr_t c_19 = "u32: %2d %2d %2d\n"; int64_t c_20 = 0; - uintptr_t c_21 = func(ctpop64); + uintptr_t c_21 = func ctpop64(int64_t): int32_t; int64_t c_22 = 6148914691236517205; int64_t c_23 = -1; uintptr_t c_24 = "u64: %2d %2d %2d\n"; diff --git a/tests/run/cttz_001.irt b/tests/run/cttz_001.irt index 911d97a..75a00ef 100644 --- a/tests/run/cttz_001.irt +++ b/tests/run/cttz_001.irt @@ -41,23 +41,23 @@ func main(void): int32_t bool c_2 = 0; bool c_3 = 1; int8_t c_4 = 1; - uintptr_t c_5 = func(cttz8); + uintptr_t c_5 = func cttz8(int8_t): int32_t; int8_t c_6 = 96; int8_t c_7 = -128; uintptr_t c_8 = "u8 : %2d %2d %2d\n"; - uintptr_t c_9 = func(printf); + uintptr_t c_9 = func printf(uintptr_t, ...): int32_t; int16_t c_10 = 1; - uintptr_t c_11 = func(cttz16); + uintptr_t c_11 = func cttz16(int16_t): int32_t; int16_t c_12 = 1536; int16_t c_13 = -32768; uintptr_t c_14 = "u16: %2d %2d %2d\n"; int32_t c_15 = 1; - uintptr_t c_16 = func(cttz32); + uintptr_t c_16 = func cttz32(int32_t): int32_t; int32_t c_17 = 393216; int32_t c_18 = -2147483648; uintptr_t c_19 = "u32: %2d %2d %2d\n"; int64_t c_20 = 1; - uintptr_t c_21 = func(cttz64); + uintptr_t c_21 = func cttz64(int64_t): int32_t; int64_t c_22 = 25769803776; int64_t c_23 = -9223372036854775808; uintptr_t c_24 = "u64: %2d %2d %2d\n"; diff --git a/tests/run/cttz_002.irt b/tests/run/cttz_002.irt index b2921d4..5c205c1 100644 --- a/tests/run/cttz_002.irt +++ b/tests/run/cttz_002.irt @@ -43,23 +43,23 @@ func main(void): int32_t bool c_2 = 0; bool c_3 = 1; int8_t c_4 = 1; - uintptr_t c_5 = func(cttz8); + uintptr_t c_5 = func cttz8(int8_t): int32_t; int8_t c_6 = 96; int8_t c_7 = -128; uintptr_t c_8 = "u8 : %2d %2d %2d\n"; - uintptr_t c_9 = func(printf); + uintptr_t c_9 = func printf(uintptr_t, ...): int32_t; int16_t c_10 = 1; - uintptr_t c_11 = func(cttz16); + uintptr_t c_11 = func cttz16(int16_t): int32_t; int16_t c_12 = 1536; int16_t c_13 = -32768; uintptr_t c_14 = "u16: %2d %2d %2d\n"; int32_t c_15 = 1; - uintptr_t c_16 = func(cttz32); + uintptr_t c_16 = func cttz32(int32_t): int32_t; int32_t c_17 = 393216; int32_t c_18 = -2147483648; uintptr_t c_19 = "u32: %2d %2d %2d\n"; int64_t c_20 = 1; - uintptr_t c_21 = func(cttz64); + uintptr_t c_21 = func cttz64(int64_t): int32_t; int64_t c_22 = 25769803776; int64_t c_23 = -9223372036854775808; uintptr_t c_24 = "u64: %2d %2d %2d\n"; diff --git a/tests/run/fcmp_001.irt b/tests/run/fcmp_001.irt index 8198e16..d62ea2b 100644 --- a/tests/run/fcmp_001.irt +++ b/tests/run/fcmp_001.irt @@ -155,39 +155,39 @@ func main(void): int32_t bool c_2 = 0; bool c_3 = 1; uintptr_t c_4 = "eq: "; - uintptr_t c_5 = func(printf); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; double c_6 = -inf; - uintptr_t c_7 = func(eq); + uintptr_t c_7 = func eq(double, double): int32_t; uintptr_t c_8 = "%d"; double c_9 = 0; double c_10 = 10.5; double c_11 = inf; double c_12 = nan; int32_t c_13 = 95; - uintptr_t c_14 = func(putchar); + uintptr_t c_14 = func putchar(int32_t): int32_t; int32_t c_15 = 10; uintptr_t c_16 = "ueq: "; - uintptr_t c_17 = func(ueq); + uintptr_t c_17 = func ueq(double, double): int32_t; uintptr_t c_18 = "ne: "; - uintptr_t c_19 = func(ne); + uintptr_t c_19 = func ne(double, double): int32_t; uintptr_t c_20 = "une: "; - uintptr_t c_21 = func(une); + uintptr_t c_21 = func une(double, double): int32_t; uintptr_t c_22 = "gt: "; - uintptr_t c_23 = func(gt); + uintptr_t c_23 = func gt(double, double): int32_t; uintptr_t c_24 = "ugt: "; - uintptr_t c_25 = func(ugt); + uintptr_t c_25 = func ugt(double, double): int32_t; uintptr_t c_26 = "ge: "; - uintptr_t c_27 = func(ge); + uintptr_t c_27 = func ge(double, double): int32_t; uintptr_t c_28 = "uge: "; - uintptr_t c_29 = func(uge); + uintptr_t c_29 = func uge(double, double): int32_t; uintptr_t c_30 = "lt: "; - uintptr_t c_31 = func(lt); + uintptr_t c_31 = func lt(double, double): int32_t; uintptr_t c_32 = "ult: "; - uintptr_t c_33 = func(ult); + uintptr_t c_33 = func ult(double, double): int32_t; uintptr_t c_34 = "le: "; - uintptr_t c_35 = func(le); + uintptr_t c_35 = func le(double, double): int32_t; uintptr_t c_36 = "ule: "; - uintptr_t c_37 = func(ule); + uintptr_t c_37 = func ule(double, double): int32_t; int32_t c_38 = 0; l_1 = START(l_1274); int32_t d_2, l_2 = CALL/1(l_1, c_5, c_4); diff --git a/tests/run/fcmp_002.irt b/tests/run/fcmp_002.irt index 5de667e..5103ec1 100644 --- a/tests/run/fcmp_002.irt +++ b/tests/run/fcmp_002.irt @@ -179,39 +179,39 @@ func main(void): int32_t bool c_2 = 0; bool c_3 = 1; uintptr_t c_4 = "eq: "; - uintptr_t c_5 = func(printf); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; double c_6 = -inf; - uintptr_t c_7 = func(eq); + uintptr_t c_7 = func eq(double, double): int32_t; uintptr_t c_8 = "%d"; double c_9 = 0; double c_10 = 10.5; double c_11 = inf; double c_12 = nan; int32_t c_13 = 95; - uintptr_t c_14 = func(putchar); + uintptr_t c_14 = func putchar(int32_t): int32_t; int32_t c_15 = 10; uintptr_t c_16 = "ueq: "; - uintptr_t c_17 = func(ueq); + uintptr_t c_17 = func ueq(double, double): int32_t; uintptr_t c_18 = "ne: "; - uintptr_t c_19 = func(ne); + uintptr_t c_19 = func ne(double, double): int32_t; uintptr_t c_20 = "une: "; - uintptr_t c_21 = func(une); + uintptr_t c_21 = func une(double, double): int32_t; uintptr_t c_22 = "gt: "; - uintptr_t c_23 = func(gt); + uintptr_t c_23 = func gt(double, double): int32_t; uintptr_t c_24 = "ugt: "; - uintptr_t c_25 = func(ugt); + uintptr_t c_25 = func ugt(double, double): int32_t; uintptr_t c_26 = "ge: "; - uintptr_t c_27 = func(ge); + uintptr_t c_27 = func ge(double, double): int32_t; uintptr_t c_28 = "uge: "; - uintptr_t c_29 = func(uge); + uintptr_t c_29 = func uge(double, double): int32_t; uintptr_t c_30 = "lt: "; - uintptr_t c_31 = func(lt); + uintptr_t c_31 = func lt(double, double): int32_t; uintptr_t c_32 = "ult: "; - uintptr_t c_33 = func(ult); + uintptr_t c_33 = func ult(double, double): int32_t; uintptr_t c_34 = "le: "; - uintptr_t c_35 = func(le); + uintptr_t c_35 = func le(double, double): int32_t; uintptr_t c_36 = "ule: "; - uintptr_t c_37 = func(ule); + uintptr_t c_37 = func ule(double, double): int32_t; int32_t c_38 = 0; l_1 = START(l_1274); int32_t d_2, l_2 = CALL/1(l_1, c_5, c_4); diff --git a/tests/run/fcmp_003.irt b/tests/run/fcmp_003.irt index 66018b9..c7623f1 100644 --- a/tests/run/fcmp_003.irt +++ b/tests/run/fcmp_003.irt @@ -11,7 +11,7 @@ func eq(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -34,7 +34,7 @@ func ueq(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -57,7 +57,7 @@ func ne(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -80,7 +80,7 @@ func une(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -103,7 +103,7 @@ func gt(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -126,7 +126,7 @@ func ugt(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -149,7 +149,7 @@ func ge(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -172,7 +172,7 @@ func uge(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -195,7 +195,7 @@ func lt(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -218,7 +218,7 @@ func ult(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -241,7 +241,7 @@ func le(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -264,7 +264,7 @@ func ule(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -287,12 +287,12 @@ func main(void): int32_t bool c_2 = 0; bool c_3 = 1; uintptr_t c_4 = "eq: "; - uintptr_t c_5 = func(printf); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; double c_6 = -inf; - uintptr_t c_7 = func(eq); + uintptr_t c_7 = func eq(double, double): int32_t; int32_t c_8 = 0; int32_t c_9 = 48; - uintptr_t c_10 = func(putchar); + uintptr_t c_10 = func putchar(int32_t): int32_t; double c_11 = 0; double c_12 = 10.5; double c_13 = inf; @@ -300,27 +300,27 @@ func main(void): int32_t int32_t c_15 = 95; int32_t c_16 = 10; uintptr_t c_17 = "ueq: "; - uintptr_t c_18 = func(ueq); + uintptr_t c_18 = func ueq(double, double): int32_t; uintptr_t c_19 = "ne: "; - uintptr_t c_20 = func(ne); + uintptr_t c_20 = func ne(double, double): int32_t; uintptr_t c_21 = "une: "; - uintptr_t c_22 = func(une); + uintptr_t c_22 = func une(double, double): int32_t; uintptr_t c_23 = "gt: "; - uintptr_t c_24 = func(gt); + uintptr_t c_24 = func gt(double, double): int32_t; uintptr_t c_25 = "ugt: "; - uintptr_t c_26 = func(ugt); + uintptr_t c_26 = func ugt(double, double): int32_t; uintptr_t c_27 = "ge: "; - uintptr_t c_28 = func(ge); + uintptr_t c_28 = func ge(double, double): int32_t; uintptr_t c_29 = "uge: "; - uintptr_t c_30 = func(uge); + uintptr_t c_30 = func uge(double, double): int32_t; uintptr_t c_31 = "lt: "; - uintptr_t c_32 = func(lt); + uintptr_t c_32 = func lt(double, double): int32_t; uintptr_t c_33 = "ult: "; - uintptr_t c_34 = func(ult); + uintptr_t c_34 = func ult(double, double): int32_t; uintptr_t c_35 = "le: "; - uintptr_t c_36 = func(le); + uintptr_t c_36 = func le(double, double): int32_t; uintptr_t c_37 = "ule: "; - uintptr_t c_38 = func(ule); + uintptr_t c_38 = func ule(double, double): int32_t; l_1 = START(l_3074); int32_t d_2, l_2 = CALL/1(l_1, c_5, c_4); int32_t d_3, l_3 = CALL/2(l_2, c_7, c_6, c_6); diff --git a/tests/run/fcmp_004.irt b/tests/run/fcmp_004.irt index babd9c6..0053cd4 100644 --- a/tests/run/fcmp_004.irt +++ b/tests/run/fcmp_004.irt @@ -11,7 +11,7 @@ func eq(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -34,7 +34,7 @@ func ueq(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -57,7 +57,7 @@ func ne(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -80,7 +80,7 @@ func une(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -103,7 +103,7 @@ func gt(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -126,7 +126,7 @@ func ugt(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -149,7 +149,7 @@ func ge(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -172,7 +172,7 @@ func uge(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -195,7 +195,7 @@ func lt(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -218,7 +218,7 @@ func ult(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -241,7 +241,7 @@ func le(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -264,7 +264,7 @@ func ule(double, double): int32_t bool c_2 = 0; bool c_3 = 1; int32_t c_4 = 51; - uintptr_t c_5 = func(putchar); + uintptr_t c_5 = func putchar(int32_t): int32_t; int32_t c_6 = 1; int32_t c_7 = 0; l_1 = START(l_13); @@ -287,12 +287,12 @@ func main(void): int32_t bool c_2 = 0; bool c_3 = 1; uintptr_t c_4 = "eq: "; - uintptr_t c_5 = func(printf); + uintptr_t c_5 = func printf(uintptr_t, ...): int32_t; double c_6 = -inf; - uintptr_t c_7 = func(eq); + uintptr_t c_7 = func eq(double, double): int32_t; int32_t c_8 = 0; int32_t c_9 = 48; - uintptr_t c_10 = func(putchar); + uintptr_t c_10 = func putchar(int32_t): int32_t; double c_11 = 0; double c_12 = 10.5; double c_13 = inf; @@ -300,27 +300,27 @@ func main(void): int32_t int32_t c_15 = 95; int32_t c_16 = 10; uintptr_t c_17 = "ueq: "; - uintptr_t c_18 = func(ueq); + uintptr_t c_18 = func ueq(double, double): int32_t; uintptr_t c_19 = "ne: "; - uintptr_t c_20 = func(ne); + uintptr_t c_20 = func ne(double, double): int32_t; uintptr_t c_21 = "une: "; - uintptr_t c_22 = func(une); + uintptr_t c_22 = func une(double, double): int32_t; uintptr_t c_23 = "gt: "; - uintptr_t c_24 = func(gt); + uintptr_t c_24 = func gt(double, double): int32_t; uintptr_t c_25 = "ugt: "; - uintptr_t c_26 = func(ugt); + uintptr_t c_26 = func ugt(double, double): int32_t; uintptr_t c_27 = "ge: "; - uintptr_t c_28 = func(ge); + uintptr_t c_28 = func ge(double, double): int32_t; uintptr_t c_29 = "uge: "; - uintptr_t c_30 = func(uge); + uintptr_t c_30 = func uge(double, double): int32_t; uintptr_t c_31 = "lt: "; - uintptr_t c_32 = func(lt); + uintptr_t c_32 = func lt(double, double): int32_t; uintptr_t c_33 = "ult: "; - uintptr_t c_34 = func(ult); + uintptr_t c_34 = func ult(double, double): int32_t; uintptr_t c_35 = "le: "; - uintptr_t c_36 = func(le); + uintptr_t c_36 = func le(double, double): int32_t; uintptr_t c_37 = "ule: "; - uintptr_t c_38 = func(ule); + uintptr_t c_38 = func ule(double, double): int32_t; l_1 = START(l_3074); int32_t d_2, l_2 = CALL/1(l_1, c_5, c_4); int32_t d_3, l_3 = CALL/2(l_2, c_7, c_6, c_6); diff --git a/tests/run/vaarg_001.irt b/tests/run/vaarg_001.irt index 059783a..c3f6640 100644 --- a/tests/run/vaarg_001.irt +++ b/tests/run/vaarg_001.irt @@ -44,9 +44,9 @@ func main(void): int32_t int32_t c_8 = 4; int32_t c_9 = 5; int32_t c_10 = 6; - uintptr_t c_11 = func(sum, 4); + uintptr_t c_11 = func sum(int32_t, ...): int32_t; uintptr_t c_12 = "sum %d\n"; - uintptr_t c_13 = func(printf, 4); + uintptr_t c_13 = func printf(uintptr_t, ...): int32_t; int32_t c_14 = 0; int32_t c_15 = 8; int32_t c_16 = 9; diff --git a/tests/run/vaarg_002.irt b/tests/run/vaarg_002.irt index e1cc734..3199fbf 100644 --- a/tests/run/vaarg_002.irt +++ b/tests/run/vaarg_002.irt @@ -49,9 +49,9 @@ func main(void): int32_t double c_12 = 8.0; double c_13 = 9.0; double c_14 = 10.0; - uintptr_t sum = func(sum, 4); + uintptr_t sum = func sum(int32_t, ...): double; uintptr_t str = "sum %g\n"; - uintptr_t printf = func(printf, 4); + uintptr_t printf = func printf(uintptr_t, ...): int32_t; int32_t ret = 0; l_1 = START(l_7); double d_2, l_2 = CALL/11(l_1, sum, c_4, c_5, c_6, c_7, c_8, c_9, c_10, c_11, c_12, c_13, c_14); diff --git a/tests/run/vaarg_003.irt b/tests/run/vaarg_003.irt index e5a3a56..e601e68 100644 --- a/tests/run/vaarg_003.irt +++ b/tests/run/vaarg_003.irt @@ -49,9 +49,9 @@ func main(void): int32_t float c_12 = 8.0; float c_13 = 9.0; float c_14 = 10.0; - uintptr_t sum = func(sum, 4); + uintptr_t sum = func sum(int32_t, ...): float; uintptr_t str = "sum %g\n"; - uintptr_t printf = func(printf, 4); + uintptr_t printf = func printf(uintptr_t, ...): int32_t; int32_t ret = 0; l_1 = START(l_8); float d_2, l_2 = CALL/11(l_1, sum, c_4, c_5, c_6, c_7, c_8, c_9, c_10, c_11, c_12, c_13, c_14); diff --git a/tests/run/vaarg_004_aarch64.irt b/tests/run/vaarg_004_aarch64.irt index 32e0434..898b658 100644 --- a/tests/run/vaarg_004_aarch64.irt +++ b/tests/run/vaarg_004_aarch64.irt @@ -89,9 +89,9 @@ func main(void): int32_t int32_t c_8 = 4; int32_t c_9 = 5; int32_t c_10 = 6; - uintptr_t c_11 = func(sum, 4); + uintptr_t c_11 = func sum(int32_t, ...): int32_t; uintptr_t c_12 = "sum %d\n"; - uintptr_t c_13 = func(printf, 4); + uintptr_t c_13 = func printf(uintptr_t, ...): int32_t; int32_t c_14 = 0; int32_t c_15 = 8; int32_t c_16 = 9; diff --git a/tests/run/vaarg_004_x86.irt b/tests/run/vaarg_004_x86.irt index 9f5a83a..9bdfb35 100644 --- a/tests/run/vaarg_004_x86.irt +++ b/tests/run/vaarg_004_x86.irt @@ -109,9 +109,9 @@ func main(void): int32_t int32_t c_8 = 4; int32_t c_9 = 5; int32_t c_10 = 6; - uintptr_t c_11 = func(sum, 4); + uintptr_t c_11 = func sum(int32_t, ...): int32_t; uintptr_t c_12 = "sum %d\n"; - uintptr_t c_13 = func(printf, 4); + uintptr_t c_13 = func printf(uintptr_t, ...): int32_t; int32_t c_14 = 0; int32_t c_15 = 8; int32_t c_16 = 9; diff --git a/tests/run/vaarg_004_x86_64.irt b/tests/run/vaarg_004_x86_64.irt index c389eef..f63172a 100644 --- a/tests/run/vaarg_004_x86_64.irt +++ b/tests/run/vaarg_004_x86_64.irt @@ -134,9 +134,9 @@ func main(void): int32_t int32_t c_8 = 4; int32_t c_9 = 5; int32_t c_10 = 6; - uintptr_t c_11 = func(sum, 4); + uintptr_t c_11 = func sum(int32_t, ...): double; uintptr_t c_12 = "sum %d\n"; - uintptr_t c_13 = func(printf, 4); + uintptr_t c_13 = func printf(uintptr_t, ...): int32_t; int32_t c_14 = 0; int32_t c_15 = 8; int32_t c_16 = 9;