~lbnz/xr0

561c2cb5b5158a824820f6f9dfc1f525da1e4ac1 — Amisi Kiarie 30 days ago 4659918 path/overspecify
checkpoint
6 files changed, 26 insertions(+), 36 deletions(-)

M src/state/block.c
M src/state/block.h
M src/state/heap.c
M src/state/heap.h
M src/state/location.c
M src/state/state.c
M src/state/block.c => src/state/block.c +14 -22
@@ 377,28 377,6 @@ permutation_create(struct int_arr *arr)
}

struct permutation *
permutation_inverse_create(struct int_arr *arr)
{
	/* 1, 2, 0 should give 0->2, 1->0, 2->1 */
	/* 1->0, 2->1, 0->2 */

	int len = int_arr_len(arr);
	int *order = int_arr_arr(arr);

	int *map = malloc(sizeof(int) * len);
	for (long i = 0; i < len; i++) {
		map[order[i]] = i;
	}

	struct permutation *p = malloc(sizeof(struct permutation));
	p->arr = int_arr_create();
	for (int i = 0; i < len; i++) {
		int_arr_append(p->arr, map[i]);
	}
	return p;
}

struct permutation *
permutation_copy(struct permutation *old)
{
	struct permutation *new = malloc(sizeof(struct permutation));


@@ 425,6 403,20 @@ permutation_apply(struct permutation *p, int i)
	return int_arr_arr(p->arr)[i];
}

int
permutation_applyinverse(struct permutation *p, int i)
{
	int len = int_arr_len(p->arr);
	int *perm = int_arr_arr(p->arr);
	assert(i < len);
	for (int j = 0; j < len; j++) {
		if (perm[j] == i) {
			return j;
		}
	}
	assert(false);
}

char *
permutation_str(struct permutation *p)
{

M src/state/block.h => src/state/block.h +3 -0
@@ 104,4 104,7 @@ permutation_str(struct permutation *);
int
permutation_apply(struct permutation *, int);

int
permutation_applyinverse(struct permutation *, int);

#endif

M src/state/heap.c => src/state/heap.c +3 -4
@@ 86,8 86,7 @@ printdelim(struct heap *h, int start)


struct heap *
heap_permute(struct heap *old, struct permutation *p_heap,
		struct permutation *p_rest)
heap_permute(struct heap *old, struct permutation *p)
{
	struct heap *new = malloc(sizeof(struct heap));
	int n = block_arr_nblocks(old->blocks);


@@ 95,10 94,10 @@ heap_permute(struct heap *old, struct permutation *p_heap,
	new->blocks = block_arr_create();
	new->freed = malloc(sizeof(bool) * n);
	for (int i = 0; i < n; i++) {
		int perm_i = permutation_apply(p_heap, i);
		int perm_i = permutation_apply(p, i);
		new->freed[i] = old->freed[perm_i];
		block_arr_append(
			new->blocks, block_permuteheaplocs(b[perm_i], p_rest)
			new->blocks, block_permuteheaplocs(b[perm_i], p)
		);
	}
	return new;

M src/state/heap.h => src/state/heap.h +1 -1
@@ 23,7 23,7 @@ struct permutation *
heap_transposezero(struct heap *, int block);

struct heap *
heap_permute(struct heap *, struct permutation *p_heap, struct permutation *p_rest);
heap_permute(struct heap *, struct permutation *p);

struct location_arr;


M src/state/location.c => src/state/location.c +1 -1
@@ 104,7 104,7 @@ location_permuteheap(struct location *loc, struct permutation *p)
{
	assert(loc->type == LOCATION_DYNAMIC);
	return location_create_dynamic(
		permutation_apply(p, loc->block), ast_expr_copy(loc->offset)
		permutation_applyinverse(p, loc->block), ast_expr_copy(loc->offset)
	);
}


M src/state/state.c => src/state/state.c +4 -8
@@ 712,14 712,10 @@ state_permuteheap(struct state *s, struct int_arr *arr)
	/* XXX: only permuting heap and return register; clump later */
	assert(s->reg);

	struct permutation *p_heap = permutation_create(arr),
			   *p_rest = permutation_inverse_create(arr);

	s->heap = heap_permute(s->heap, p_heap, p_rest);
	s->reg = value_permuteheaplocs(s->reg, p_rest);

	permutation_destroy(p_rest);
	permutation_destroy(p_heap);
	struct permutation *p = permutation_create(arr);
	s->heap = heap_permute(s->heap, p);
	s->reg = value_permuteheaplocs(s->reg, p);
	permutation_destroy(p);
}

static void