diff options
author | Teddy <[email protected]> | 2014-05-03 07:58:13 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2014-05-03 07:58:13 +0800 |
commit | f3372f4560faafbbe871efeeb7bf872bac6eeb31 (patch) | |
tree | 9a8cb00c29a7fb38d6d576b85cd2e726a1264cbd | |
parent | 605a03dfbdf2d018f91a29dad8145a9647e1b10f (diff) |
fix struct bug
-rw-r--r-- | semantics.c | 1 | ||||
-rw-r--r-- | ssa.c | 40 |
2 files changed, 19 insertions, 22 deletions
diff --git a/semantics.c b/semantics.c index 83e4744..75ee872 100644 --- a/semantics.c +++ b/semantics.c @@ -1135,6 +1135,7 @@ ExpType exp_check_postfix(CNode *p, CScope_t scope) { if (!(t1 == CSTRUCT || t1 == CUNION)) ERROR((p, "request for the member in something not a structure or union")); { + calc_size(op1.type); CVar_t fv = ctable_lookup(op1.type->rec.st.fields, post->chd->rec.strval); if (!fv) @@ -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; } |