Previously, the C code generation for the pipeline was hidden under
the hood; now, we make this an explicit API operation. Besides the
functions for the pipeline actions and the pipeline instructions,
the generated C source code now includes the pipeline specification
structure required for the pipeline configuration operations.
Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Kamalakannan R. <kamalakannan.r@intel.com>
---
lib/pipeline/rte_swx_pipeline.c | 94 +++++++++++++++++++++++++++++++++
lib/pipeline/rte_swx_pipeline.h | 25 +++++++++
lib/pipeline/version.map | 1 +
3 files changed, 120 insertions(+)
@@ -20,6 +20,7 @@
#include <rte_swx_table_wm.h>
#include "rte_swx_pipeline_internal.h"
+#include "rte_swx_pipeline_spec.h"
#define CHECK(condition, err_code) \
do { \
@@ -13581,3 +13582,96 @@ pipeline_compile(struct rte_swx_pipeline *p)
return status;
}
+
+int
+rte_swx_pipeline_codegen(FILE *spec_file,
+ FILE *code_file,
+ uint32_t *err_line,
+ const char **err_msg)
+
+{
+ struct rte_swx_pipeline *p = NULL;
+ struct pipeline_spec *s = NULL;
+ struct instruction_group_list *igl = NULL;
+ struct action *a;
+ int status = 0;
+
+ /* Check input arguments. */
+ if (!spec_file || !code_file) {
+ if (err_line)
+ *err_line = 0;
+ if (err_msg)
+ *err_msg = "Invalid input argument.";
+ status = -EINVAL;
+ goto free;
+ }
+
+ /* Pipeline configuration. */
+ s = pipeline_spec_parse(spec_file, err_line, err_msg);
+ if (!s) {
+ status = -EINVAL;
+ goto free;
+ }
+
+ status = rte_swx_pipeline_config(&p, NULL, 0);
+ if (status) {
+ if (err_line)
+ *err_line = 0;
+ if (err_msg)
+ *err_msg = "Pipeline configuration error.";
+ goto free;
+ }
+
+ status = pipeline_spec_configure(p, s, err_msg);
+ if (status) {
+ if (err_line)
+ *err_line = 0;
+ goto free;
+ }
+
+ /*
+ * Pipeline code generation.
+ */
+
+ /* Instruction Group List (IGL) computation: the pipeline configuration must be done first,
+ * but there is no need for the pipeline build to be done as well.
+ */
+ igl = instruction_group_list_create(p);
+ if (!igl) {
+ if (err_line)
+ *err_line = 0;
+ if (err_msg)
+ *err_msg = "Memory allocation failed.";
+ status = -ENOMEM;
+ goto free;
+ }
+
+ /* Header file inclusion. */
+ fprintf(code_file, "#include \"rte_swx_pipeline_internal.h\"\n");
+ fprintf(code_file, "#include \"rte_swx_pipeline_spec.h\"\n\n");
+
+ /* Code generation for the pipeline specification. */
+ pipeline_spec_codegen(code_file, s);
+ fprintf(code_file, "\n");
+
+ /* Code generation for the action instructions. */
+ TAILQ_FOREACH(a, &p->actions, node) {
+ fprintf(code_file, "/**\n * Action %s\n */\n\n", a->name);
+
+ action_data_codegen(a, code_file);
+ fprintf(code_file, "\n");
+
+ action_instr_codegen(a, code_file);
+ fprintf(code_file, "\n");
+ }
+
+ /* Code generation for the pipeline instructions. */
+ instruction_group_list_codegen(igl, p, code_file);
+
+free:
+ instruction_group_list_free(igl);
+ rte_swx_pipeline_free(p);
+ pipeline_spec_free(s);
+
+ return status;
+}
@@ -957,6 +957,31 @@ __rte_experimental
int
rte_swx_pipeline_build(struct rte_swx_pipeline *p);
+/**
+ * Pipeline C code generate based on input specification file
+ *
+ * @param[in] spec_file
+ * Pipeline specification file (.spec) provided as input.
+ * @param[in] code_file
+ * Pipeline C language file (.c) to be generated.
+ * @param[out] err_line
+ * In case of error and non-NULL, the line number within the *spec* file where
+ * the error occurred. The first line number in the file is 1.
+ * @param[out] err_msg
+ * In case of error and non-NULL, the error message.
+ * @return
+ * 0 on success or the following error codes otherwise:
+ * -EINVAL: Invalid argument;
+ * -ENOMEM: Not enough space/cannot allocate memory;
+ * -EEXIST: Resource with the same name already exists.
+ */
+__rte_experimental
+int
+rte_swx_pipeline_codegen(FILE *spec_file,
+ FILE *code_file,
+ uint32_t *err_line,
+ const char **err_msg);
+
/**
* Pipeline build from specification file
*
@@ -148,5 +148,6 @@ EXPERIMENTAL {
#added in 22.11
rte_swx_ctl_pipeline_find;
+ rte_swx_pipeline_codegen;
rte_swx_pipeline_find;
};