extern ses_step_t ses_step_output;
-static ses_step_t* ses_steps[] =
+static ses_step_t* ses_steps_0[] =
{
&ses_step_battery,
&ses_step_dc_input,
&ses_step_dc_diode,
&ses_step_dc_transistor,
+};
+static ses_step_t* ses_steps_1[] =
+{
&ses_step_simplify,
&ses_step_topo,
&ses_step_jr,
&ses_step_va,
&ses_step_va_balance,
+};
+static ses_step_t* ses_steps_2[] =
+{
&ses_step_output,
};
+static int __ses_steps_input(ScfEfunction* f, int64_t ns, int64_t i, ses_ctx_t* ctx)
+{
+ ses_step_t* s;
+
+ int64_t j;
+
+ for (j = 0; j < sizeof(ses_steps_0) / sizeof(ses_steps_0[0]); j++) {
+ s = ses_steps_0[j];
+
+ if (!s || !s->handler)
+ continue;
+
+ int ret = s->handler(f, ns, i, ctx);
+ if (ret < 0) {
+ scf_loge("analysis step '%s' ret: %d\n", s->name, ret);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static int __ses_steps_output(ScfEfunction* f, int64_t ns, int64_t i, ses_ctx_t* ctx)
+{
+ ses_step_t* s;
+
+ int64_t j;
+
+ for (j = 0; j < sizeof(ses_steps_2) / sizeof(ses_steps_2[0]); j++) {
+ s = ses_steps_2[j];
+
+ if (!s || !s->handler)
+ continue;
+
+ int ret = s->handler(f, ns, i, ctx);
+ if (ret < 0) {
+ scf_loge("analysis step '%s' ret: %d\n", s->name, ret);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static int __ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t i, ses_ctx_t* ctx)
+{
+ ses_step_t* s;
+
+ int64_t j;
+
+ for (j = 0; j < sizeof(ses_steps_1) / sizeof(ses_steps_1[0]); j++) {
+ s = ses_steps_1[j];
+
+ if (!s || !s->handler)
+ continue;
+
+ int ret = s->handler(f, ns, i, ctx);
+ if (ret < 0) {
+ scf_loge("analysis step '%s' ret: %d\n", s->name, ret);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count)
{
if (!f || ns <= 0 || count < 0)
return -EINVAL;
- ses_step_t* s;
- ses_ctx_t* ctx = ses_ctx_alloc();
-
+ ses_ctx_t* ctx = ses_ctx_alloc();
if (!ctx)
return -ENOMEM;
int64_t i;
- int64_t j;
for (i = 0; i < count; i++) {
- for (j = 0; j < sizeof(ses_steps) / sizeof(ses_steps[0]); j++) {
- s = ses_steps[j];
+ int ret = __ses_steps_input(f, ns, i, ctx);
+ if (ret < 0)
+ return ret;
+
+ while (1) {
+ ret = __ses_steps_analyse(f, ns, i, ctx);
- if (!s || !s->handler)
+ if (-EAGAIN == ret)
continue;
- int ret = s->handler(f, ns, i, ctx);
- if (ret < 0) {
- scf_loge("analysis step '%s' ret: %d\n", s->name, ret);
+ if (0 == ret)
+ break;
- ses_ctx_free(ctx);
+ if (ret < 0)
return ret;
- }
}
+
+ ret = __ses_steps_output(f, ns, i, ctx);
+ if (ret < 0)
+ return ret;
}
ses_ctx_free(ctx);