From f3372f4560faafbbe871efeeb7bf872bac6eeb31 Mon Sep 17 00:00:00 2001 From: Teddy Date: Sat, 3 May 2014 07:58:13 +0800 Subject: fix struct bug --- ssa.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'ssa.c') diff --git a/ssa.c b/ssa.c index 7c6945d..5c6ce82 100644 --- a/ssa.c +++ b/ssa.c @@ -333,6 +333,20 @@ void ssa_generate() { } } +#define POINTER_CONV(inst) \ +do { \ + if (rt->type == CARR || rt->type == CSTRUCT || rt->type == CUNION) \ + { \ + /* convert to pointer type */ \ + CType_t a = ctype_create("", CPTR, p); \ + a->rec.ref = rt->rec.arr.elem; \ + (inst)->op = ADD; \ + (inst)->dest->type = a; \ + } \ + else (inst)->op = ARR; \ +} while (0) + + COpr_t ssa_exp_(CNode *p, CBlock_t *, CInst_t, CBlock_t); COpr_t ssa_postfix(CNode *p, CBlock_t *cur, CInst_t lval, CBlock_t succ) { CNode *post = p->chd->next; @@ -360,16 +374,7 @@ COpr_t ssa_postfix(CNode *p, CBlock_t *cur, CInst_t lval, CBlock_t succ) { base->dest->type = rt; base->src1 = ssa_exp_(p->chd, cur, NULL, succ); base->src2 = off->dest; - if (rt->type == CARR || rt->type == CSTRUCT || rt->type == CUNION) - { - /* convert to pointer type */ - CType_t a = ctype_create("", CPTR, p); - a->rec.ref = rt->rec.arr.elem; - base->op = ADD; - base->dest->type = a; - } - else - base->op = ARR; + POINTER_CONV(base); } break; case POSTFIX_DOT: @@ -378,11 +383,11 @@ COpr_t ssa_postfix(CNode *p, CBlock_t *cur, CInst_t lval, CBlock_t succ) { base->dest->kind = TMP; base->dest->info.var = ctmp_create(); base->dest->type = rt; - base->op = ARR; base->src1 = ssa_exp_(p->chd, cur, NULL, succ); base->src2 = copr_create(); base->src2->kind = IMM; base->src2->info.imm = p->ext.offset; + POINTER_CONV(base); } break; case POSTFIX_PTR: @@ -391,11 +396,11 @@ COpr_t ssa_postfix(CNode *p, CBlock_t *cur, CInst_t lval, CBlock_t succ) { base->dest->kind = TMP; base->dest->info.var = ctmp_create(); base->dest->type = rt; - base->op = ARR; base->src1 = ssa_exp_(p->chd, cur, NULL, succ); base->src2 = copr_create(); base->src2->kind = IMM; base->src2->info.imm = p->ext.offset; + POINTER_CONV(base); } break; case POSTFIX_CALL: @@ -591,16 +596,7 @@ COpr_t ssa_exp_(CNode *p, CBlock_t *cur, CInst_t lval, CBlock_t succ) { inst->dest->kind = TMP; inst->dest->info.var = ctmp_create(); inst->dest->type = rt; - if (rt->type == CARR || rt->type == CSTRUCT || rt->type == CUNION) - { - /* convert to pointer type */ - CType_t a = ctype_create("", CPTR, p); - a->rec.ref = rt->rec.arr.elem; - inst->op = ADD; - inst->dest->type = a; - } - else - inst->op = ARR; + POINTER_CONV(inst); cblock_append(*cur, inst); return inst->dest; } -- cgit v1.2.3