diff mbox series

[V3,19/24] pipeline: introduce pipeline compilation

Message ID 20210913164443.16875-19-cristian.dumitrescu@intel.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers show
Series [V3,01/24] pipeline: move data structures to internal header file | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Cristian Dumitrescu Sept. 13, 2021, 4:44 p.m. UTC
Lay the foundation to generate C code for the pipeline: C functions
for actions and custom instructions are generated, built as shared
object library and loaded into the pipeline.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_pipeline.c | 44 +++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
diff mbox series

Patch

diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index 9afe42ed25..392e2cf1bc 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -8977,6 +8977,9 @@  rte_swx_pipeline_instructions_config(struct rte_swx_pipeline *p,
 	return 0;
 }
 
+static int
+pipeline_compile(struct rte_swx_pipeline *p);
+
 int
 rte_swx_pipeline_build(struct rte_swx_pipeline *p)
 {
@@ -9046,6 +9049,9 @@  rte_swx_pipeline_build(struct rte_swx_pipeline *p)
 		goto error;
 
 	p->build_done = 1;
+
+	pipeline_compile(p);
+
 	return 0;
 
 error:
@@ -9789,3 +9795,41 @@  rte_swx_ctl_meter_stats_read(struct rte_swx_pipeline *p,
 
 	return 0;
 }
+
+/*
+ * Pipeline compilation.
+ */
+static int
+pipeline_codegen(struct rte_swx_pipeline *p)
+{
+	FILE *f = NULL;
+
+	if (!p)
+		return -EINVAL;
+
+	/* Create the .c file. */
+	f = fopen("/tmp/pipeline.c", "w");
+	if (!f)
+		return -EIO;
+
+	/* Include the .h file. */
+	fprintf(f, "#include \"rte_swx_pipeline_internal.h\"\n");
+
+	/* Close the .c file. */
+	fclose(f);
+
+	return 0;
+}
+
+static int
+pipeline_compile(struct rte_swx_pipeline *p)
+{
+	int status = 0;
+
+	/* Code generation. */
+	status = pipeline_codegen(p);
+	if (status)
+		return status;
+
+	return status;
+}