aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-01-16 12:11:49 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-02-17 11:07:25 +0100
commit48bda757364b7a2e3b767b401525c94a0cc7b8fa (patch)
treeec5c2d03f3f68e7b11c2686c2e96a98c572fa915
parent87d5acde0ae24d56524ffbc52a008f7a763fbcc8 (diff)
downloadsparse-dev-48bda757364b7a2e3b767b401525c94a0cc7b8fa.tar.gz
let struct access_data use a single type
'struct access_data' has two members for the type of the access: 'result_type' & 'source_type', the second being the application of base_type() on the first. These two names are not very self-explained and are confusing when trying to know which one must be used for loads vs stores. Also, the distinction between these two types only exists for bitfields. Simplify things by using a single type, and use base_type() when doing the linearization of bitfield accesses. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--linearize.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/linearize.c b/linearize.c
index 4995d06e..6f9300e7 100644
--- a/linearize.c
+++ b/linearize.c
@@ -873,8 +873,7 @@ pseudo_t alloc_phi(struct basic_block *source, pseudo_t pseudo, struct symbol *t
* information in one place.
*/
struct access_data {
- struct symbol *result_type; // result ctype
- struct symbol *source_type; // source ctype
+ struct symbol *type; // ctype
pseudo_t address; // pseudo containing address ..
unsigned int offset; // byte offset
struct position pos;
@@ -927,8 +926,7 @@ static int linearize_address_gen(struct entrypoint *ep,
if (!ctype)
return 0;
ad->pos = expr->pos;
- ad->result_type = ctype;
- ad->source_type = base_type(ctype);
+ ad->type = ctype;
if (expr->type == EXPR_PREOP && expr->op == '*')
return linearize_simple_address(ep, expr->unop, ad);
@@ -938,10 +936,11 @@ static int linearize_address_gen(struct entrypoint *ep,
static pseudo_t add_load(struct entrypoint *ep, struct access_data *ad)
{
+ struct symbol *btype = base_type(ad->type);
struct instruction *insn;
pseudo_t new;
- insn = alloc_typed_instruction(OP_LOAD, ad->source_type);
+ insn = alloc_typed_instruction(OP_LOAD, btype);
new = alloc_pseudo(insn);
insn->target = new;
@@ -956,7 +955,8 @@ static void add_store(struct entrypoint *ep, struct access_data *ad, pseudo_t va
struct basic_block *bb = ep->active;
if (bb_reachable(bb)) {
- struct instruction *store = alloc_typed_instruction(OP_STORE, ad->source_type);
+ struct symbol *btype = base_type(ad->type);
+ struct instruction *store = alloc_typed_instruction(OP_STORE, btype);
store->offset = ad->offset;
use_pseudo(store, value, &store->target);
use_pseudo(store, ad->address, &store->src);
@@ -968,21 +968,22 @@ static pseudo_t linearize_store_gen(struct entrypoint *ep,
pseudo_t value,
struct access_data *ad)
{
+ struct symbol *ctype = ad->type;
+ struct symbol *btype = base_type(ctype);
pseudo_t store = value;
- if (type_size(ad->source_type) != type_size(ad->result_type)) {
- struct symbol *ctype = ad->result_type;
+ if (type_size(btype) != type_size(ctype)) {
unsigned int shift = ctype->bit_offset;
unsigned int size = ctype->bit_size;
pseudo_t orig = add_load(ep, ad);
unsigned long long mask = (1ULL << size) - 1;
if (shift) {
- store = add_binary_op(ep, ad->source_type, OP_SHL, value, value_pseudo(shift));
+ store = add_binary_op(ep, btype, OP_SHL, value, value_pseudo(shift));
mask <<= shift;
}
- orig = add_binary_op(ep, ad->source_type, OP_AND, orig, value_pseudo(~mask));
- store = add_binary_op(ep, ad->source_type, OP_OR, orig, store);
+ orig = add_binary_op(ep, btype, OP_AND, orig, value_pseudo(~mask));
+ store = add_binary_op(ep, btype, OP_OR, orig, store);
}
add_store(ep, ad, store);
return value;
@@ -1032,16 +1033,17 @@ static pseudo_t add_symbol_address(struct entrypoint *ep, struct symbol *sym)
static pseudo_t linearize_load_gen(struct entrypoint *ep, struct access_data *ad)
{
- struct symbol *ctype = ad->result_type;
+ struct symbol *ctype = ad->type;
+ struct symbol *btype = base_type(ctype);
pseudo_t new = add_load(ep, ad);
if (ctype->bit_offset) {
pseudo_t shift = value_pseudo(ctype->bit_offset);
- pseudo_t newval = add_binary_op(ep, ad->source_type, OP_LSR, new, shift);
+ pseudo_t newval = add_binary_op(ep, btype, OP_LSR, new, shift);
new = newval;
}
- if (ctype->bit_size != type_size(ad->source_type))
- new = cast_pseudo(ep, new, ad->source_type, ad->result_type);
+ if (ctype->bit_size != type_size(btype))
+ new = cast_pseudo(ep, new, btype, ctype);
return new;
}
@@ -1565,8 +1567,7 @@ static pseudo_t linearize_position(struct entrypoint *ep, struct expression *pos
struct expression *init_expr = pos->init_expr;
ad->offset = pos->init_offset;
- ad->source_type = base_type(init_expr->ctype);
- ad->result_type = init_expr->ctype;
+ ad->type = init_expr->ctype;
return linearize_initializer(ep, init_expr, ad);
}
@@ -1585,8 +1586,7 @@ static pseudo_t linearize_initializer(struct entrypoint *ep, struct expression *
break;
default: {
pseudo_t value = linearize_expression(ep, initializer);
- ad->source_type = base_type(initializer->ctype);
- ad->result_type = initializer->ctype;
+ ad->type = initializer->ctype;
linearize_store_gen(ep, value, ad);
return value;
}
@@ -1599,8 +1599,7 @@ static void linearize_argument(struct entrypoint *ep, struct symbol *arg, int nr
{
struct access_data ad = { NULL, };
- ad.source_type = arg;
- ad.result_type = arg;
+ ad.type = arg;
ad.address = symbol_pseudo(ep, arg);
linearize_store_gen(ep, argument_pseudo(ep, nr), &ad);
finish_address_gen(ep, &ad);
@@ -1709,8 +1708,7 @@ static pseudo_t linearize_one_symbol(struct entrypoint *ep, struct symbol *sym)
// all fields arelater explicitely initialized.
struct expression *expr = sym->initializer;
ad.pos = expr->pos;
- ad.result_type = sym;
- ad.source_type = base_type(sym);
+ ad.type = sym;
ad.address = symbol_pseudo(ep, sym);
linearize_store_gen(ep, value_pseudo(0), &ad);
}