From 1c1a9da7a4f9c4c1990192e14763ebf423d812a9 Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Wed, 7 Jun 2023 16:54:53 +0200 Subject: seitan, cooker: refactor op_return Refactor OP_RETURN: - merged OP_BLOCK and OP_CONT into OP_RETURN - add desc field for op_return - updated the demo files --- cooker/emit.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'cooker/emit.c') diff --git a/cooker/emit.c b/cooker/emit.c index 7b1b14d..506a561 100644 --- a/cooker/emit.c +++ b/cooker/emit.c @@ -304,36 +304,32 @@ void emit_cmp_field(struct gluten_ctx *g, enum op_cmp_type cmp, /** * emit_return() - Emit OP_RETURN instruction: return value * @g: gluten context - * @v: Pointer to return value + * @v: offset of the return value + * @error: error value + * @cont if the filtered syscall needs to be executed */ -void emit_return(struct gluten_ctx *g, struct gluten_offset v) +void emit_return(struct gluten_ctx *g, struct gluten_offset v, int32_t error, + bool cont) { struct op *op = (struct op *)gluten_ptr(&g->g, g->ip); struct op_return *ret = &op->op.ret; + struct gluten_offset o; + struct return_desc *desc; op->type = OP_RETURN; - ret->val = v; - - debug(" %i: OP_RETURN:", g->ip.offset); - if (++g->ip.offset > INST_MAX) - die("Too many instructions"); -} + o = gluten_ro_alloc(g, sizeof(struct return_desc)); + desc = (struct return_desc *)gluten_ptr(&g->g, o); -/** - * emit_block() - Emit OP_BLOCK instruction: return error value - * @g: gluten context - * @error: Error value - */ -void emit_block(struct gluten_ctx *g, int32_t error) -{ - struct op *op = (struct op *)gluten_ptr(&g->g, g->ip); - struct op_block *block = &op->op.block; + desc->val = v; + desc->error = error; + desc->cont = cont; - op->type = OP_BLOCK; - block->error = error; + ret->desc = o; - debug(" %i: OP_BLOCK: %d", g->ip.offset, error); + debug(" %i: OP_RETURN:", g->ip.offset); + debug(" \t val=(%s %d) errno=%d cont=%s", gluten_offset_name[v.type], + v.offset, error, cont ? "true" : "false"); if (++g->ip.offset > INST_MAX) die("Too many instructions"); -- cgit v1.2.3