From 283f4436153de93da70fb239f3cc874c6ab8c99f Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 29 May 2023 21:06:25 +0200 Subject: [PATCH] examples: Add some comments to example files Signed-off-by: Anatol Belski --- examples/0001-basic.c | 4 ++++ examples/0001-while.c | 3 +++ examples/0005-basic-runner-func.c | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/0001-basic.c b/examples/0001-basic.c index 558d5b1..c90f271 100644 --- a/examples/0001-basic.c +++ b/examples/0001-basic.c @@ -18,10 +18,14 @@ typedef int32_t (*myfunc_t)(int32_t, int32_t); void gen_myfunc(ir_ctx *ctx) { + /* Function entry start */ ir_START(); + /* Declare function parameters */ ir_ref x = ir_PARAM(IR_I32, "x", 1); ir_ref y = ir_PARAM(IR_I32, "y", 2); + /* Subtract y from x and save it into a new ref. */ ir_ref cr = ir_SUB_I32(x, y); + /* Function end */ ir_RETURN(cr); } diff --git a/examples/0001-while.c b/examples/0001-while.c index 302fb86..8de7ecc 100644 --- a/examples/0001-while.c +++ b/examples/0001-while.c @@ -20,7 +20,9 @@ typedef int32_t (*myfunc_t)(void); void gen_myfunc(ir_ctx *ctx) { + /* Function entry start */ ir_START(); + /* Declare loop counter. */ ir_ref i = ir_COPY_I32(ir_CONST_I32(0)); ir_ref loop = ir_LOOP_BEGIN(ir_END()); ir_ref phi_i_1 = ir_PHI_2(i, IR_UNUSED); @@ -32,6 +34,7 @@ void gen_myfunc(ir_ctx *ctx) ir_PHI_SET_OP(phi_i_1, 2, i_2); ir_IF_FALSE(cond); + /* Function end */ ir_RETURN(i_2); } diff --git a/examples/0005-basic-runner-func.c b/examples/0005-basic-runner-func.c index c6e0e3f..291eb85 100644 --- a/examples/0005-basic-runner-func.c +++ b/examples/0005-basic-runner-func.c @@ -18,14 +18,17 @@ typedef double (*myfunc_t)(double, double); void gen_myfunc(ir_ctx *ctx) { + /* Function entry start */ ir_START(); + /* Declare function parameters */ ir_ref x = ir_PARAM(IR_DOUBLE, "x", 1); ir_ref y = ir_PARAM(IR_DOUBLE, "y", 2); - ir_ref cr0 = ir_SUB_D(x, y); + ir_ref cr0 = ir_SUB_D(x, y); ir_ref cd = ir_CONST_DOUBLE(.3); cr0 = ir_ADD_D(cr0, cd); + /* Function end */ ir_RETURN(cr0); }