~pixelherodev/c3lib

ddd789667e0b3f1f92a636752601943924d590c9 — Noam Preil 3 months ago 25e027f tmp
tmp
2 files changed, 6 insertions(+), 23 deletions(-)

M sema/expr.c
M sema/usage.c
M sema/expr.c => sema/expr.c +5 -22
@@ 165,8 165,6 @@ s_call(uint32_t index)
		ERROR("TODO: explicit calling conventions", 0);
		return -1;
	}
	if(!stb_sb_push_u32(&kids, index))
		OOM();
	index = c3nodechild(*ctx.c3, tmp, 1);
	count = c3nodekids(*ctx.c3, index);
	for(i = 0; i < count; i += 1){


@@ 646,7 644,7 @@ l_fn(uint32_t index)
		ERROR("Failed to lower function block", 0);
		return -1;
	}
	index = c3append(ctx.c3, C3_IR_FN, 2, tmp, index);
	tmp = c3append(ctx.c3, C3_IR_FN, 2, c3nodechild(*ctx.c3, index, 0), tmp);
	if(!stb_sb_push_u32(&ctx.fn_map.irs, index))
		OOM();
	return index;


@@ 705,26 703,11 @@ int
expr_finish(void)
{
	uint32_t i;
	uint32_t index, rindex;
	uint16_t kids;
	uint32_t *fns = ctx.c3->analysis.fns;
	kids = stb_sb_count(fns);
	uint32_t index, old, ref;
	uint16_t kids = stb_sb_count(ctx.fn_refs);
	for(i = 0; i < kids; i += 1){
		index = fns[i];
		// Only map functions with bodies (non-external)
		if(c3nodechild(*ctx.c3, c3nodechild(*ctx.c3, index, 0), 1) == -1)
			continue;
		rindex = s_map(c3nodechild(*ctx.c3, index, 0));
		if(rindex == -1){
			ERROR("ICE: unable to map function from CFG to IR; index %u: %u", index, c3nodechild(*ctx.c3, index, 0));
			c3nodedump(*ctx.c3, rindex, 0, 1);
			return 0;
		}
		ctx.c3->ast.nodes[index + 1].node_index = rindex;
	}
	for(i = 0; i < stb_sb_count(ctx.fn_refs); i += 1){
		rindex = ctx.fn_refs[i];
		index = ctx.c3->ast.nodes[rindex].node_index;
		ref = ctx.fn_refs[i];
		index = ctx.c3->ast.nodes[ref].node_index;
		ctx.c3->ast.nodes[index].node_index = s_map(index);
		if(ctx.c3->ast.nodes[index].node_index == -1){
			ERROR("ICE: unable to map function from child index %d to IR", ctx.c3->ast.nodes[index]);

M sema/usage.c => sema/usage.c +1 -1
@@ 332,7 332,7 @@ u_test(uint32_t index)
	fntype = c3append(ctx.c3, C3_TYPE_FN, 3, rettype, param_list, callconv);
	if(fntype == -1)
		OOM();
	fn = c3append(ctx.c3, C3_VALUE_FN, 4, index, fntype, c3nodechild(*ctx.c3, index, 0), -1);
	fn = c3append(ctx.c3, C3_VALUE_FN, 4, fntype, c3nodechild(*ctx.c3, index, 0));
	if(fn == -1)
		OOM();
	ctx.c3->ast.nodes[index + 1].node_index = fn;