Skip to content

Commit

Permalink
Merge branch 'slice'
Browse files Browse the repository at this point in the history
* slice: small reorg of OP_SLICE in preparation for some incoming changes
  • Loading branch information
lucvoo committed Mar 5, 2021
2 parents 4122236 + 778de2b commit e0f9048
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Documentation/IR.rst
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ Others
Extract a "slice" from an aggregate.

* .base: (pseudo_t) aggregate (alias .src)
* .from, .len: offet & size of the "slice" within the aggregate
* .from: offset of the "slice" within the aggregate
* .target: result
* .type: type of .target

Expand Down
1 change: 0 additions & 1 deletion evaluate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,6 @@ static struct symbol *evaluate_member_dereference(struct expression *expr)
}
expr->r_bitpos += bytes_to_bits(offset);
expr->type = EXPR_SLICE;
expr->r_nrbits = member->bit_size;
expr->r_bitpos += member->bit_offset;
expr->ctype = member;
return member;
Expand Down
2 changes: 1 addition & 1 deletion expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ struct expression {
// EXPR_SLICE
struct /* slice */ {
struct expression *base;
unsigned r_bitpos, r_nrbits;
unsigned r_bitpos;
};
// EXPR_CAST, EXPR_FORCE_CAST, EXPR_IMPLIED_CAST,
// EXPR_SIZEOF, EXPR_ALIGNOF and EXPR_PTRSIZEOF
Expand Down
6 changes: 3 additions & 3 deletions linearize.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ const char *show_instruction(struct instruction *insn)
break;

case OP_SLICE:
buf += sprintf(buf, "%s <- %s, %d, %d", show_pseudo(insn->target), show_pseudo(insn->base), insn->from, insn->len);
buf += sprintf(buf, "%s <- (%d) %s, %d", show_pseudo(insn->target), type_size(insn->orig_type), show_pseudo(insn->src), insn->from);
break;

case OP_NOT: case OP_NEG:
Expand Down Expand Up @@ -1239,8 +1239,8 @@ static pseudo_t linearize_slice(struct entrypoint *ep, struct expression *expr)

insn->target = new;
insn->from = expr->r_bitpos;
insn->len = expr->r_nrbits;
use_pseudo(insn, pre, &insn->base);
insn->orig_type = expr->base->ctype;
use_pseudo(insn, pre, &insn->src);
add_one_insn(ep, insn);
return new;
}
Expand Down
5 changes: 1 addition & 4 deletions linearize.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct instruction {
};
struct /* unops */ {
pseudo_t src;
unsigned from; /* slice */
struct symbol *orig_type; /* casts */
};
struct /* memops */ {
Expand All @@ -127,10 +128,6 @@ struct instruction {
pseudo_t _src1, _src2; // alias .src[12]
struct symbol *itype; // input operands' type
};
struct /* slice */ {
pseudo_t base;
unsigned from, len;
};
struct /* setval */ {
struct expression *val;
};
Expand Down
7 changes: 2 additions & 5 deletions liveness.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ static void track_instruction_usage(struct basic_block *bb, struct instruction *
/* Uni */
case OP_UNOP ... OP_UNOP_END:
case OP_SYMADDR:
USES(src1); DEFINES(target);
case OP_SLICE:
USES(src); DEFINES(target);
break;

case OP_SEL:
Expand Down Expand Up @@ -121,10 +122,6 @@ static void track_instruction_usage(struct basic_block *bb, struct instruction *
} END_FOR_EACH_PTR(pseudo);
break;

case OP_SLICE:
USES(base); DEFINES(target);
break;

case OP_ASM:
asm_liveness(bb, insn, def, use);
break;
Expand Down
2 changes: 1 addition & 1 deletion show-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ static int show_slice(struct expression *expr)
{
int target = show_expression(expr->base);
int new = new_pseudo();
printf("\tslice.%d\t\tv%d,v%d,%d\n", expr->r_nrbits, target, new, expr->r_bitpos);
printf("\tslice.%d\t\tv%d,v%d,%d\n", expr->ctype->bit_size, target, new, expr->r_bitpos);
return new;
}

Expand Down

0 comments on commit e0f9048

Please sign in to comment.