From c3f10f0908acb129dba4c07331a5cb5442b3f166 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Tue, 25 Jul 2023 19:59:53 +0800 Subject: [PATCH] ses_ctx_t --- ses_core.h | 19 ++++++++----------- ses_step_battery.c | 2 +- ses_step_dc_diode.c | 2 +- ses_step_dc_input.c | 2 +- ses_step_dc_transistor.c | 2 +- ses_step_output.c | 7 ++++++- ses_step_simplify.c | 2 +- ses_step_va.c | 2 +- ses_step_va_balance.c | 7 ++++++- ses_steps.c | 35 ++++++++++++++++++++++++++++++++++- 10 files changed, 60 insertions(+), 20 deletions(-) diff --git a/ses_core.h b/ses_core.h index 08364c4..7841e47 100644 --- a/ses_core.h +++ b/ses_core.h @@ -5,9 +5,8 @@ #include"scf_vector.h" typedef struct ses_step_s ses_step_t; -typedef struct ses_loop_s ses_loop_t; typedef struct ses_edge_s ses_edge_t; -typedef struct ses_pin_s ses_pin_t; +typedef struct ses_ctx_s ses_ctx_t; struct ses_edge_s { @@ -19,27 +18,25 @@ struct ses_edge_s ScfEpin* p1; }; -struct ses_pin_s +struct ses_ctx_s { - ScfEcomponent* c; - ScfEpin* p; -}; - -struct ses_loop_s -{ - scf_vector_t* pins; + scf_vector_t* paths; }; struct ses_step_s { const char* name; - int (*handler)(ScfEfunction* f, int64_t ns, int64_t count); + int (*handler)(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx); void* priv; }; +ses_ctx_t* ses_ctx_alloc(); +void ses_ctx_free (ses_ctx_t* ctx); + + int ses_layout_board (ScfEboard* b); int ses_loop_function(ScfEfunction* f, scf_vector_t* loops); int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count); diff --git a/ses_step_battery.c b/ses_step_battery.c index 11d5144..6f3c617 100644 --- a/ses_step_battery.c +++ b/ses_step_battery.c @@ -1,6 +1,6 @@ #include"ses_core.h" -static int _battery_handler(ScfEfunction* f, int64_t ns, int64_t count) +static int _battery_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) { ScfEcomponent* c; ScfEline* el; diff --git a/ses_step_dc_diode.c b/ses_step_dc_diode.c index 4d4e233..795826f 100644 --- a/ses_step_dc_diode.c +++ b/ses_step_dc_diode.c @@ -1,6 +1,6 @@ #include"ses_core.h" -static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count) +static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) { ScfEcomponent* c; ScfEcomponent* B; diff --git a/ses_step_dc_input.c b/ses_step_dc_input.c index 4e59bd1..aad832c 100644 --- a/ses_step_dc_input.c +++ b/ses_step_dc_input.c @@ -1,6 +1,6 @@ #include"ses_core.h" -static int _dc_input_handler(ScfEfunction* f, int64_t ns, int64_t count) +static int _dc_input_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) { ScfEcomponent* B; ScfEline* el; diff --git a/ses_step_dc_transistor.c b/ses_step_dc_transistor.c index 8c88ec7..3dc6af2 100644 --- a/ses_step_dc_transistor.c +++ b/ses_step_dc_transistor.c @@ -1,6 +1,6 @@ #include"ses_core.h" -static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count) +static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) { ScfEcomponent* c; ScfEcomponent* B; diff --git a/ses_step_output.c b/ses_step_output.c index 9fea167..4448353 100644 --- a/ses_step_output.c +++ b/ses_step_output.c @@ -1,8 +1,13 @@ #include"ses_core.h" +static int _output_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) +{ + return 0; +} ses_step_t ses_step_output = { - .name = "output", + .name = "output", + .handler = _output_handler, }; diff --git a/ses_step_simplify.c b/ses_step_simplify.c index 598380d..9947b13 100644 --- a/ses_step_simplify.c +++ b/ses_step_simplify.c @@ -219,7 +219,7 @@ static int _simplify_draw(ScfEfunction* f, uint32_t bx, uint32_t by, uint32_t bw return 0; } -static int _simplify_handler(ScfEfunction* f, int64_t ns, int64_t count) +static int _simplify_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) { ScfEcomponent* c; ScfEcomponent* B; diff --git a/ses_step_va.c b/ses_step_va.c index cde11fd..aa90f19 100644 --- a/ses_step_va.c +++ b/ses_step_va.c @@ -64,7 +64,7 @@ static int __dfs_route(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp) return 0; } -static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count) +static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) { ScfEcomponent* c; ScfEcomponent* B; diff --git a/ses_step_va_balance.c b/ses_step_va_balance.c index 47d64b9..17b736e 100644 --- a/ses_step_va_balance.c +++ b/ses_step_va_balance.c @@ -1,8 +1,13 @@ #include"ses_core.h" +static int _va_balance_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) +{ + return 0; +} ses_step_t ses_step_va_balance = { - .name = "va_balance", + .name = "va_balance", + .handler = _va_balance_handler, }; diff --git a/ses_steps.c b/ses_steps.c index 05ae5bc..7e19bb8 100644 --- a/ses_steps.c +++ b/ses_steps.c @@ -33,6 +33,32 @@ static ses_step_t* ses_steps[] = &ses_step_output, }; +ses_ctx_t* ses_ctx_alloc() +{ + ses_ctx_t* ctx = calloc(1, sizeof(ses_ctx_t)); + if (!ctx) + return NULL; + + ctx->paths = scf_vector_alloc(); + if (!ctx->paths) { + free(ctx); + return NULL; + } + + return ctx; +} + +void ses_ctx_free(ses_ctx_t* ctx) +{ + if (ctx) { + if (ctx->paths) { + scf_vector_clear(ctx->paths, ( void (*)(void*) )scf_vector_free); + scf_vector_free (ctx->paths); + } + + free(ctx); + } +} int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count) { @@ -40,6 +66,10 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count) return -EINVAL; ses_step_t* s; + ses_ctx_t* ctx = ses_ctx_alloc(); + + if (!ctx) + return -ENOMEM; int64_t i; int64_t j; @@ -52,13 +82,16 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count) if (!s || !s->handler) continue; - int ret = s->handler(f, ns, i); + int ret = s->handler(f, ns, i, ctx); if (ret < 0) { scf_loge("analysis step '%s' ret: %d\n", s->name, ret); + + ses_ctx_free(ctx); return ret; } } } + ses_ctx_free(ctx); return 0; } -- 2.25.1