get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/76966/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 76966,
    "url": "http://patches.dpdk.org/api/patches/76966/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20200908201830.74206-33-cristian.dumitrescu@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20200908201830.74206-33-cristian.dumitrescu@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20200908201830.74206-33-cristian.dumitrescu@intel.com",
    "date": "2020-09-08T20:18:21",
    "name": "[v3,32/41] pipeline: add SWX pipeline specification file",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "9f69b051ac2712c97039f24c07e1b3a70b3b0787",
    "submitter": {
        "id": 19,
        "url": "http://patches.dpdk.org/api/people/19/?format=api",
        "name": "Cristian Dumitrescu",
        "email": "cristian.dumitrescu@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20200908201830.74206-33-cristian.dumitrescu@intel.com/mbox/",
    "series": [
        {
            "id": 12034,
            "url": "http://patches.dpdk.org/api/series/12034/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=12034",
            "date": "2020-09-08T20:17:52",
            "name": "Pipeline alignment with the P4 language",
            "version": 3,
            "mbox": "http://patches.dpdk.org/series/12034/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/76966/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/76966/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from dpdk.org (dpdk.org [92.243.14.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 96963A04B1;\n\tTue,  8 Sep 2020 22:24:21 +0200 (CEST)",
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 40C101C24A;\n\tTue,  8 Sep 2020 22:19:43 +0200 (CEST)",
            "from mga02.intel.com (mga02.intel.com [134.134.136.20])\n by dpdk.org (Postfix) with ESMTP id 38A511C124\n for <dev@dpdk.org>; Tue,  8 Sep 2020 22:19:05 +0200 (CEST)",
            "from fmsmga006.fm.intel.com ([10.253.24.20])\n by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 08 Sep 2020 13:19:04 -0700",
            "from silpixa00400573.ir.intel.com (HELO\n silpixa00400573.ger.corp.intel.com) ([10.237.223.107])\n by fmsmga006.fm.intel.com with ESMTP; 08 Sep 2020 13:19:02 -0700"
        ],
        "IronPort-SDR": [
            "\n hYGGi4f4BrmW+KGAiE0iYCflZ0A44M14J0Ngq2H85L6xGBm5zG3Rhj5C3f8BwtmrTgfpWZKkq8\n 7i6nBFSqYuTA==",
            "\n m9kSrOgrM4qLnaYDR0qBSy45W7F1eoYQL2nHxhXYUCNSQhwZ6kLwZHzS3iFK1EgzPl1ekuUho8\n MiwjoEh+G7KA=="
        ],
        "X-IronPort-AV": [
            "E=McAfee;i=\"6000,8403,9738\"; a=\"145939446\"",
            "E=Sophos;i=\"5.76,407,1592895600\"; d=\"scan'208\";a=\"145939446\"",
            "E=Sophos;i=\"5.76,406,1592895600\"; d=\"scan'208\";a=\"504493526\""
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "From": "Cristian Dumitrescu <cristian.dumitrescu@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Tue,  8 Sep 2020 21:18:21 +0100",
        "Message-Id": "<20200908201830.74206-33-cristian.dumitrescu@intel.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20200908201830.74206-1-cristian.dumitrescu@intel.com>",
        "References": "<20200907214032.95052-2-cristian.dumitrescu@intel.com>\n <20200908201830.74206-1-cristian.dumitrescu@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v3 32/41] pipeline: add SWX pipeline\n\tspecification file",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Add support for building the SWX pipeline based on specification file\nwith syntax aligned to the P4 language. The specification file may be\ngenerated by the P4C compiler in the future.\n\nSigned-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>\n---\n lib/librte_pipeline/meson.build              |    1 +\n lib/librte_pipeline/rte_pipeline_version.map |    1 +\n lib/librte_pipeline/rte_swx_pipeline.h       |   26 +\n lib/librte_pipeline/rte_swx_pipeline_spec.c  | 1439 ++++++++++++++++++\n 4 files changed, 1467 insertions(+)\n create mode 100644 lib/librte_pipeline/rte_swx_pipeline_spec.c",
    "diff": "diff --git a/lib/librte_pipeline/meson.build b/lib/librte_pipeline/meson.build\nindex be1d9c3a4..65c1a8d6a 100644\n--- a/lib/librte_pipeline/meson.build\n+++ b/lib/librte_pipeline/meson.build\n@@ -5,6 +5,7 @@ sources = files('rte_pipeline.c',\n \t'rte_port_in_action.c',\n \t'rte_table_action.c',\n \t'rte_swx_pipeline.c',\n+\t'rte_swx_pipeline_spec.c',\n \t'rte_swx_ctl.c',)\n headers = files('rte_pipeline.h',\n \t'rte_port_in_action.h',\ndiff --git a/lib/librte_pipeline/rte_pipeline_version.map b/lib/librte_pipeline/rte_pipeline_version.map\nindex ec38f0eef..2cb50d571 100644\n--- a/lib/librte_pipeline/rte_pipeline_version.map\n+++ b/lib/librte_pipeline/rte_pipeline_version.map\n@@ -72,6 +72,7 @@ EXPERIMENTAL {\n \trte_swx_pipeline_table_config;\n \trte_swx_pipeline_instructions_config;\n \trte_swx_pipeline_build;\n+\trte_swx_pipeline_build_from_spec;\n \trte_swx_pipeline_free;\n \trte_swx_pipeline_run;\n \trte_swx_pipeline_flush;\ndiff --git a/lib/librte_pipeline/rte_swx_pipeline.h b/lib/librte_pipeline/rte_swx_pipeline.h\nindex 6da5710af..6928e78b6 100644\n--- a/lib/librte_pipeline/rte_swx_pipeline.h\n+++ b/lib/librte_pipeline/rte_swx_pipeline.h\n@@ -643,6 +643,32 @@ __rte_experimental\n int\n rte_swx_pipeline_build(struct rte_swx_pipeline *p);\n \n+/**\n+ * Pipeline build from specification file\n+ *\n+ * @param[in] p\n+ *   Pipeline handle.\n+ * @param[in] spec\n+ *   Pipeline specification file.\n+ * @param[out] err_line\n+ *   In case of error and non-NULL, the line number within the *spec* file where\n+ *   the error occurred. The first line number in the file is 1.\n+ * @param[out] err_msg\n+ *   In case of error and non-NULL, the error message.\n+ * @return\n+ *   0 on success or the following error codes otherwise:\n+ *   -EINVAL: Invalid argument;\n+ *   -ENOMEM: Not enough space/cannot allocate memory;\n+ *   -EEXIST: Resource with the same name already exists;\n+ *   -ENODEV: Extern object or table creation error.\n+ */\n+__rte_experimental\n+int\n+rte_swx_pipeline_build_from_spec(struct rte_swx_pipeline *p,\n+\t\t\t\t FILE *spec,\n+\t\t\t\t uint32_t *err_line,\n+\t\t\t\t const char **err_msg);\n+\n /**\n  * Pipeline run\n  *\ndiff --git a/lib/librte_pipeline/rte_swx_pipeline_spec.c b/lib/librte_pipeline/rte_swx_pipeline_spec.c\nnew file mode 100644\nindex 000000000..d72badd03\n--- /dev/null\n+++ b/lib/librte_pipeline/rte_swx_pipeline_spec.c\n@@ -0,0 +1,1439 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2020 Intel Corporation\n+ */\n+#include <stdint.h>\n+#include <stdlib.h>\n+#include <stdio.h>\n+#include <string.h>\n+#include <errno.h>\n+\n+#include \"rte_swx_pipeline.h\"\n+#include \"rte_swx_ctl.h\"\n+\n+#define MAX_LINE_LENGTH 256\n+#define MAX_TOKENS 16\n+#define MAX_INSTRUCTION_LENGTH 256\n+\n+#define STRUCT_BLOCK 0\n+#define ACTION_BLOCK 1\n+#define TABLE_BLOCK 2\n+#define TABLE_KEY_BLOCK 3\n+#define TABLE_ACTIONS_BLOCK 4\n+#define APPLY_BLOCK 5\n+\n+/*\n+ * extobj.\n+ *\n+ * extobj OBJ_NAME instanceof OBJ_TYPE [ pragma OBJ_CREATE_ARGS ]\n+ */\n+struct extobj_spec {\n+\tchar *name;\n+\tchar *extern_type_name;\n+\tchar *pragma;\n+};\n+\n+static void\n+extobj_spec_free(struct extobj_spec *s)\n+{\n+\tfree(s->name);\n+\tfree(s->extern_type_name);\n+\tfree(s->pragma);\n+}\n+\n+static int\n+extobj_statement_parse(struct extobj_spec *s,\n+\t\t       char **tokens,\n+\t\t       uint32_t n_tokens,\n+\t\t       uint32_t n_lines,\n+\t\t       uint32_t *err_line,\n+\t\t       const char **err_msg)\n+{\n+\t/* Check format. */\n+\tif (((n_tokens != 4) && (n_tokens != 6)) ||\n+\t    ((n_tokens == 4) && strcmp(tokens[2], \"instanceof\")) ||\n+\t    ((n_tokens == 6) && (strcmp(tokens[2], \"instanceof\") ||\n+\t\t\t\t strcmp(tokens[4], \"pragma\")))) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid extobj statement.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* spec. */\n+\ts->name = strdup(tokens[1]);\n+\ts->extern_type_name = strdup(tokens[3]);\n+\ts->pragma = (n_tokens == 6) ? strdup(tokens[5]) : NULL;\n+\n+\tif (!s->name ||\n+\t    !s->extern_type_name ||\n+\t    ((n_tokens == 6) && !s->pragma)) {\n+\t\tfree(s->name);\n+\t\tfree(s->extern_type_name);\n+\t\tfree(s->pragma);\n+\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * struct.\n+ *\n+ * struct STRUCT_TYPE_NAME {\n+ *\tbit<SIZE> FIELD_NAME\n+ *\t...\n+ * }\n+ */\n+struct struct_spec {\n+\tchar *name;\n+\tstruct rte_swx_field_params *fields;\n+\tuint32_t n_fields;\n+};\n+\n+static void\n+struct_spec_free(struct struct_spec *s)\n+{\n+\tuint32_t i;\n+\n+\tif (!s)\n+\t\treturn;\n+\n+\tfree(s->name);\n+\ts->name = NULL;\n+\n+\tfor (i = 0; i < s->n_fields; i++) {\n+\t\tuintptr_t name = (uintptr_t)s->fields[i].name;\n+\n+\t\tfree((void *)name);\n+\t}\n+\n+\tfree(s->fields);\n+\ts->fields = NULL;\n+\n+\ts->n_fields = 0;\n+}\n+\n+static int\n+struct_statement_parse(struct struct_spec *s,\n+\t\t       uint32_t *block_mask,\n+\t\t       char **tokens,\n+\t\t       uint32_t n_tokens,\n+\t\t       uint32_t n_lines,\n+\t\t       uint32_t *err_line,\n+\t\t       const char **err_msg)\n+{\n+\t/* Check format. */\n+\tif ((n_tokens != 3) || strcmp(tokens[2], \"{\")) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid struct statement.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* spec. */\n+\ts->name = strdup(tokens[1]);\n+\tif (!s->name) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\t/* block_mask. */\n+\t*block_mask |= 1 << STRUCT_BLOCK;\n+\n+\treturn 0;\n+}\n+\n+static int\n+struct_block_parse(struct struct_spec *s,\n+\t\t   uint32_t *block_mask,\n+\t\t   char **tokens,\n+\t\t   uint32_t n_tokens,\n+\t\t   uint32_t n_lines,\n+\t\t   uint32_t *err_line,\n+\t\t   const char **err_msg)\n+{\n+\tstruct rte_swx_field_params *new_fields;\n+\tchar *p = tokens[0], *name;\n+\tuint32_t n_bits;\n+\n+\t/* Handle end of block. */\n+\tif ((n_tokens == 1) && !strcmp(tokens[0], \"}\")) {\n+\t\t*block_mask &= ~(1 << STRUCT_BLOCK);\n+\t\treturn 0;\n+\t}\n+\n+\t/* Check format. */\n+\tif ((n_tokens != 2) ||\n+\t    (strlen(p) < 6) ||\n+\t    (p[0] != 'b') ||\n+\t    (p[1] != 'i') ||\n+\t    (p[2] != 't') ||\n+\t    (p[3] != '<') ||\n+\t    (p[strlen(p) - 1] != '>')) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid struct field statement.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* Remove the \"bit<\" and \">\". */\n+\tp[strlen(p) - 1] = 0;\n+\tp += 4;\n+\n+\tn_bits = strtoul(p, &p, 0);\n+\tif ((p[0]) ||\n+\t    !n_bits ||\n+\t    (n_bits % 8) ||\n+\t    (n_bits > 64)) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid struct field size.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* spec. */\n+\tname = strdup(tokens[1]);\n+\tif (!name) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\tnew_fields = reallocarray(s->fields,\n+\t\t\t\t  s->n_fields + 1,\n+\t\t\t\t  sizeof(struct rte_swx_field_params));\n+\tif (!new_fields) {\n+\t\tfree(name);\n+\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\ts->fields = new_fields;\n+\ts->fields[s->n_fields].name = name;\n+\ts->fields[s->n_fields].n_bits = n_bits;\n+\ts->n_fields++;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * header.\n+ *\n+ * header HEADER_NAME instanceof STRUCT_TYPE_NAME\n+ */\n+struct header_spec {\n+\tchar *name;\n+\tchar *struct_type_name;\n+};\n+\n+static void\n+header_spec_free(struct header_spec *s)\n+{\n+\tfree(s->name);\n+\tfree(s->struct_type_name);\n+}\n+\n+static int\n+header_statement_parse(struct header_spec *s,\n+\t\t       char **tokens,\n+\t\t       uint32_t n_tokens,\n+\t\t       uint32_t n_lines,\n+\t\t       uint32_t *err_line,\n+\t\t       const char **err_msg)\n+{\n+\t/* Check format. */\n+\tif ((n_tokens != 4) || strcmp(tokens[2], \"instanceof\")) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid header statement.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* spec. */\n+\ts->name = strdup(tokens[1]);\n+\ts->struct_type_name = strdup(tokens[3]);\n+\n+\tif (!s->name || !s->struct_type_name) {\n+\t\tfree(s->name);\n+\t\tfree(s->struct_type_name);\n+\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * metadata.\n+ *\n+ * metadata instanceof STRUCT_TYPE_NAME\n+ */\n+struct metadata_spec {\n+\tchar *struct_type_name;\n+};\n+\n+static void\n+metadata_spec_free(struct metadata_spec *s)\n+{\n+\tfree(s->struct_type_name);\n+}\n+\n+static int\n+metadata_statement_parse(struct metadata_spec *s,\n+\t\t\t char **tokens,\n+\t\t\t uint32_t n_tokens,\n+\t\t\t uint32_t n_lines,\n+\t\t\t uint32_t *err_line,\n+\t\t\t const char **err_msg)\n+{\n+\t/* Check format. */\n+\tif ((n_tokens != 3) || strcmp(tokens[1], \"instanceof\")) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid metadata statement.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* spec. */\n+\ts->struct_type_name = strdup(tokens[2]);\n+\tif (!s->struct_type_name) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * action.\n+ *\n+ * action ACTION_NAME args none | instanceof STRUCT_TYPE_NAME {\n+ *\tINSTRUCTION\n+ *\t...\n+ * }\n+ */\n+struct action_spec {\n+\tchar *name;\n+\tchar *args_struct_type_name;\n+\tconst char **instructions;\n+\tuint32_t n_instructions;\n+};\n+\n+static void\n+action_spec_free(struct action_spec *s)\n+{\n+\tuint32_t i;\n+\n+\tif (!s)\n+\t\treturn;\n+\n+\tfree(s->name);\n+\ts->name = NULL;\n+\n+\tfree(s->args_struct_type_name);\n+\ts->args_struct_type_name = NULL;\n+\n+\tfor (i = 0; i < s->n_instructions; i++) {\n+\t\tuintptr_t instr = (uintptr_t)s->instructions[i];\n+\n+\t\tfree((void *)instr);\n+\t}\n+\n+\tfree(s->instructions);\n+\ts->instructions = NULL;\n+\n+\ts->n_instructions = 0;\n+}\n+\n+static int\n+action_statement_parse(struct action_spec *s,\n+\t\t       uint32_t *block_mask,\n+\t\t       char **tokens,\n+\t\t       uint32_t n_tokens,\n+\t\t       uint32_t n_lines,\n+\t\t       uint32_t *err_line,\n+\t\t       const char **err_msg)\n+{\n+\t/* Check format. */\n+\tif (((n_tokens != 5) && (n_tokens != 6)) ||\n+\t    ((n_tokens == 5) &&\n+\t     (strcmp(tokens[2], \"args\") ||\n+\t      strcmp(tokens[3], \"none\") ||\n+\t      strcmp(tokens[4], \"{\"))) ||\n+\t    ((n_tokens == 6) &&\n+\t     (strcmp(tokens[2], \"args\") ||\n+\t      strcmp(tokens[3], \"instanceof\") ||\n+\t      strcmp(tokens[5], \"{\")))) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid action statement.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* spec. */\n+\ts->name = strdup(tokens[1]);\n+\ts->args_struct_type_name = (n_tokens == 6) ? strdup(tokens[4]) : NULL;\n+\n+\tif ((!s->name) || ((n_tokens == 6) && !s->args_struct_type_name)) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\t/* block_mask. */\n+\t*block_mask |= 1 << ACTION_BLOCK;\n+\n+\treturn 0;\n+}\n+\n+static int\n+action_block_parse(struct action_spec *s,\n+\t\t   uint32_t *block_mask,\n+\t\t   char **tokens,\n+\t\t   uint32_t n_tokens,\n+\t\t   uint32_t n_lines,\n+\t\t   uint32_t *err_line,\n+\t\t   const char **err_msg)\n+{\n+\tchar buffer[MAX_INSTRUCTION_LENGTH], *instr;\n+\tconst char **new_instructions;\n+\tuint32_t i;\n+\n+\t/* Handle end of block. */\n+\tif ((n_tokens == 1) && !strcmp(tokens[0], \"}\")) {\n+\t\t*block_mask &= ~(1 << ACTION_BLOCK);\n+\t\treturn 0;\n+\t}\n+\n+\t/* spec. */\n+\tbuffer[0] = 0;\n+\tfor (i = 0; i < n_tokens; i++) {\n+\t\tif (i)\n+\t\t\tstrcat(buffer, \" \");\n+\t\tstrcat(buffer, tokens[i]);\n+\t}\n+\n+\tinstr = strdup(buffer);\n+\tif (!instr) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\tnew_instructions = reallocarray(s->instructions,\n+\t\t\t\t\ts->n_instructions + 1,\n+\t\t\t\t\tsizeof(char *));\n+\tif (!new_instructions) {\n+\t\tfree(instr);\n+\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\ts->instructions = new_instructions;\n+\ts->instructions[s->n_instructions] = instr;\n+\ts->n_instructions++;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * table.\n+ *\n+ * table {\n+ *\tkey {\n+ *\t\tMATCH_FIELD_NAME exact | wildcard | lpm\n+ *\t\t...\n+ *\t}\n+ *\tactions {\n+ *\t\tACTION_NAME\n+ *\t\t...\n+ *\t}\n+ *\tdefault_action ACTION_NAME args none | ARGS_BYTE_ARRAY [ const ]\n+ *\tinstanceof TABLE_TYPE_NAME\n+ *\tpragma ARGS\n+ *\tsize SIZE\n+ * }\n+ */\n+struct table_spec {\n+\tchar *name;\n+\tstruct rte_swx_pipeline_table_params params;\n+\tchar *recommended_table_type_name;\n+\tchar *args;\n+\tuint32_t size;\n+};\n+\n+static void\n+table_spec_free(struct table_spec *s)\n+{\n+\tuintptr_t default_action_name;\n+\tuint32_t i;\n+\n+\tif (!s)\n+\t\treturn;\n+\n+\tfree(s->name);\n+\ts->name = NULL;\n+\n+\tfor (i = 0; i < s->params.n_fields; i++) {\n+\t\tuintptr_t name = (uintptr_t)s->params.fields[i].name;\n+\n+\t\tfree((void *)name);\n+\t}\n+\n+\tfree(s->params.fields);\n+\ts->params.fields = NULL;\n+\n+\ts->params.n_fields = 0;\n+\n+\tfor (i = 0; i < s->params.n_actions; i++) {\n+\t\tuintptr_t name = (uintptr_t)s->params.action_names[i];\n+\n+\t\tfree((void *)name);\n+\t}\n+\n+\tfree(s->params.action_names);\n+\ts->params.action_names = NULL;\n+\n+\ts->params.n_actions = 0;\n+\n+\tdefault_action_name = (uintptr_t)s->params.default_action_name;\n+\tfree((void *)default_action_name);\n+\ts->params.default_action_name = NULL;\n+\n+\tfree(s->params.default_action_data);\n+\ts->params.default_action_data = NULL;\n+\n+\ts->params.default_action_is_const = 0;\n+\n+\tfree(s->recommended_table_type_name);\n+\ts->recommended_table_type_name = NULL;\n+\n+\tfree(s->args);\n+\ts->args = NULL;\n+\n+\ts->size = 0;\n+}\n+\n+static int\n+table_key_statement_parse(uint32_t *block_mask,\n+\t\t\t  char **tokens,\n+\t\t\t  uint32_t n_tokens,\n+\t\t\t  uint32_t n_lines,\n+\t\t\t  uint32_t *err_line,\n+\t\t\t  const char **err_msg)\n+{\n+\t/* Check format. */\n+\tif ((n_tokens != 2) || strcmp(tokens[1], \"{\")) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid key statement.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* block_mask. */\n+\t*block_mask |= 1 << TABLE_KEY_BLOCK;\n+\n+\treturn 0;\n+}\n+\n+static int\n+table_key_block_parse(struct table_spec *s,\n+\t\t      uint32_t *block_mask,\n+\t\t      char **tokens,\n+\t\t      uint32_t n_tokens,\n+\t\t      uint32_t n_lines,\n+\t\t      uint32_t *err_line,\n+\t\t      const char **err_msg)\n+{\n+\tstruct rte_swx_match_field_params *new_fields;\n+\tenum rte_swx_table_match_type match_type = RTE_SWX_TABLE_MATCH_WILDCARD;\n+\tchar *name;\n+\n+\t/* Handle end of block. */\n+\tif ((n_tokens == 1) && !strcmp(tokens[0], \"}\")) {\n+\t\t*block_mask &= ~(1 << TABLE_KEY_BLOCK);\n+\t\treturn 0;\n+\t}\n+\n+\t/* Check input arguments. */\n+\tif ((n_tokens != 2) ||\n+\t    (strcmp(tokens[1], \"exact\") &&\n+\t     strcmp(tokens[1], \"wildcard\") &&\n+\t     strcmp(tokens[1], \"lpm\"))) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid match field statement.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (!strcmp(tokens[1], \"wildcard\"))\n+\t\tmatch_type = RTE_SWX_TABLE_MATCH_WILDCARD;\n+\tif (!strcmp(tokens[1], \"lpm\"))\n+\t\tmatch_type = RTE_SWX_TABLE_MATCH_LPM;\n+\tif (!strcmp(tokens[1], \"exact\"))\n+\t\tmatch_type = RTE_SWX_TABLE_MATCH_EXACT;\n+\n+\tname = strdup(tokens[0]);\n+\tif (!name) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\tnew_fields = reallocarray(s->params.fields,\n+\t\t\t\t  s->params.n_fields + 1,\n+\t\t\t\t  sizeof(struct rte_swx_match_field_params));\n+\tif (!new_fields) {\n+\t\tfree(name);\n+\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\ts->params.fields = new_fields;\n+\ts->params.fields[s->params.n_fields].name = name;\n+\ts->params.fields[s->params.n_fields].match_type = match_type;\n+\ts->params.n_fields++;\n+\n+\treturn 0;\n+}\n+\n+static int\n+table_actions_statement_parse(uint32_t *block_mask,\n+\t\t\t      char **tokens,\n+\t\t\t      uint32_t n_tokens,\n+\t\t\t      uint32_t n_lines,\n+\t\t\t      uint32_t *err_line,\n+\t\t\t      const char **err_msg)\n+{\n+\t/* Check format. */\n+\tif ((n_tokens != 2) || strcmp(tokens[1], \"{\")) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid actions statement.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* block_mask. */\n+\t*block_mask |= 1 << TABLE_ACTIONS_BLOCK;\n+\n+\treturn 0;\n+}\n+\n+static int\n+table_actions_block_parse(struct table_spec *s,\n+\t\t\t  uint32_t *block_mask,\n+\t\t\t  char **tokens,\n+\t\t\t  uint32_t n_tokens,\n+\t\t\t  uint32_t n_lines,\n+\t\t\t  uint32_t *err_line,\n+\t\t\t  const char **err_msg)\n+{\n+\tconst char **new_action_names;\n+\tchar *name;\n+\n+\t/* Handle end of block. */\n+\tif ((n_tokens == 1) && !strcmp(tokens[0], \"}\")) {\n+\t\t*block_mask &= ~(1 << TABLE_ACTIONS_BLOCK);\n+\t\treturn 0;\n+\t}\n+\n+\t/* Check input arguments. */\n+\tif (n_tokens != 1) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid action name statement.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tname = strdup(tokens[0]);\n+\tif (!name) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\tnew_action_names = reallocarray(s->params.action_names,\n+\t\t\t\t\ts->params.n_actions + 1,\n+\t\t\t\t\tsizeof(char *));\n+\tif (!new_action_names) {\n+\t\tfree(name);\n+\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\ts->params.action_names = new_action_names;\n+\ts->params.action_names[s->params.n_actions] = name;\n+\ts->params.n_actions++;\n+\n+\treturn 0;\n+}\n+\n+static int\n+table_statement_parse(struct table_spec *s,\n+\t\t      uint32_t *block_mask,\n+\t\t      char **tokens,\n+\t\t      uint32_t n_tokens,\n+\t\t      uint32_t n_lines,\n+\t\t      uint32_t *err_line,\n+\t\t      const char **err_msg)\n+{\n+\t/* Check format. */\n+\tif ((n_tokens != 3) || strcmp(tokens[2], \"{\")) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid table statement.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* spec. */\n+\ts->name = strdup(tokens[1]);\n+\tif (!s->name) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\t/* block_mask. */\n+\t*block_mask |= 1 << TABLE_BLOCK;\n+\n+\treturn 0;\n+}\n+\n+static int\n+table_block_parse(struct table_spec *s,\n+\t\t  uint32_t *block_mask,\n+\t\t  char **tokens,\n+\t\t  uint32_t n_tokens,\n+\t\t  uint32_t n_lines,\n+\t\t  uint32_t *err_line,\n+\t\t  const char **err_msg)\n+{\n+\tif (*block_mask & (1 << TABLE_KEY_BLOCK))\n+\t\treturn table_key_block_parse(s,\n+\t\t\t\t\t     block_mask,\n+\t\t\t\t\t     tokens,\n+\t\t\t\t\t     n_tokens,\n+\t\t\t\t\t     n_lines,\n+\t\t\t\t\t     err_line,\n+\t\t\t\t\t     err_msg);\n+\n+\tif (*block_mask & (1 << TABLE_ACTIONS_BLOCK))\n+\t\treturn table_actions_block_parse(s,\n+\t\t\t\t\t\t block_mask,\n+\t\t\t\t\t\t tokens,\n+\t\t\t\t\t\t n_tokens,\n+\t\t\t\t\t\t n_lines,\n+\t\t\t\t\t\t err_line,\n+\t\t\t\t\t\t err_msg);\n+\n+\t/* Handle end of block. */\n+\tif ((n_tokens == 1) && !strcmp(tokens[0], \"}\")) {\n+\t\t*block_mask &= ~(1 << TABLE_BLOCK);\n+\t\treturn 0;\n+\t}\n+\n+\tif (!strcmp(tokens[0], \"key\"))\n+\t\treturn table_key_statement_parse(block_mask,\n+\t\t\t\t\t\t tokens,\n+\t\t\t\t\t\t n_tokens,\n+\t\t\t\t\t\t n_lines,\n+\t\t\t\t\t\t err_line,\n+\t\t\t\t\t\t err_msg);\n+\n+\tif (!strcmp(tokens[0], \"actions\"))\n+\t\treturn table_actions_statement_parse(block_mask,\n+\t\t\t\t\t\t     tokens,\n+\t\t\t\t\t\t     n_tokens,\n+\t\t\t\t\t\t     n_lines,\n+\t\t\t\t\t\t     err_line,\n+\t\t\t\t\t\t     err_msg);\n+\n+\tif (!strcmp(tokens[0], \"default_action\")) {\n+\t\tif (((n_tokens != 4) && (n_tokens != 5)) ||\n+\t\t    strcmp(tokens[2], \"args\") ||\n+\t\t    strcmp(tokens[3], \"none\") ||\n+\t\t    ((n_tokens == 5) && strcmp(tokens[4], \"const\"))) {\n+\t\t\tif (err_line)\n+\t\t\t\t*err_line = n_lines;\n+\t\t\tif (err_msg)\n+\t\t\t\t*err_msg = \"Invalid default_action statement.\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tif (s->params.default_action_name) {\n+\t\t\tif (err_line)\n+\t\t\t\t*err_line = n_lines;\n+\t\t\tif (err_msg)\n+\t\t\t\t*err_msg = \"Duplicate default_action stmt.\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\ts->params.default_action_name = strdup(tokens[1]);\n+\t\tif (!s->params.default_action_name) {\n+\t\t\tif (err_line)\n+\t\t\t\t*err_line = n_lines;\n+\t\t\tif (err_msg)\n+\t\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\t\treturn -ENOMEM;\n+\t\t}\n+\n+\t\tif (n_tokens == 5)\n+\t\t\ts->params.default_action_is_const = 1;\n+\n+\t\treturn 0;\n+\t}\n+\n+\tif (!strcmp(tokens[0], \"instanceof\")) {\n+\t\tif (n_tokens != 2) {\n+\t\t\tif (err_line)\n+\t\t\t\t*err_line = n_lines;\n+\t\t\tif (err_msg)\n+\t\t\t\t*err_msg = \"Invalid instanceof statement.\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tif (s->recommended_table_type_name) {\n+\t\t\tif (err_line)\n+\t\t\t\t*err_line = n_lines;\n+\t\t\tif (err_msg)\n+\t\t\t\t*err_msg = \"Duplicate instanceof statement.\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\ts->recommended_table_type_name = strdup(tokens[1]);\n+\t\tif (!s->recommended_table_type_name) {\n+\t\t\tif (err_line)\n+\t\t\t\t*err_line = n_lines;\n+\t\t\tif (err_msg)\n+\t\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\t\treturn -ENOMEM;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\tif (!strcmp(tokens[0], \"pragma\")) {\n+\t\tif (n_tokens != 2) {\n+\t\t\tif (err_line)\n+\t\t\t\t*err_line = n_lines;\n+\t\t\tif (err_msg)\n+\t\t\t\t*err_msg = \"Invalid pragma statement.\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tif (s->args) {\n+\t\t\tif (err_line)\n+\t\t\t\t*err_line = n_lines;\n+\t\t\tif (err_msg)\n+\t\t\t\t*err_msg = \"Duplicate pragma statement.\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\ts->args = strdup(tokens[1]);\n+\t\tif (!s->args) {\n+\t\t\tif (err_line)\n+\t\t\t\t*err_line = n_lines;\n+\t\t\tif (err_msg)\n+\t\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\t\treturn -ENOMEM;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\tif (!strcmp(tokens[0], \"size\")) {\n+\t\tchar *p = tokens[1];\n+\n+\t\tif (n_tokens != 2) {\n+\t\t\tif (err_line)\n+\t\t\t\t*err_line = n_lines;\n+\t\t\tif (err_msg)\n+\t\t\t\t*err_msg = \"Invalid pragma statement.\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\ts->size = strtoul(p, &p, 0);\n+\t\tif (p[0]) {\n+\t\t\tif (err_line)\n+\t\t\t\t*err_line = n_lines;\n+\t\t\tif (err_msg)\n+\t\t\t\t*err_msg = \"Invalid size argument.\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\t/* Anything else. */\n+\tif (err_line)\n+\t\t*err_line = n_lines;\n+\tif (err_msg)\n+\t\t*err_msg = \"Invalid statement.\";\n+\treturn -EINVAL;\n+}\n+\n+/*\n+ * apply.\n+ *\n+ * apply {\n+ *\tINSTRUCTION\n+ *\t...\n+ * }\n+ */\n+struct apply_spec {\n+\tconst char **instructions;\n+\tuint32_t n_instructions;\n+};\n+\n+static void\n+apply_spec_free(struct apply_spec *s)\n+{\n+\tuint32_t i;\n+\n+\tif (!s)\n+\t\treturn;\n+\n+\tfor (i = 0; i < s->n_instructions; i++) {\n+\t\tuintptr_t instr = (uintptr_t)s->instructions[i];\n+\n+\t\tfree((void *)instr);\n+\t}\n+\n+\tfree(s->instructions);\n+\ts->instructions = NULL;\n+\n+\ts->n_instructions = 0;\n+}\n+\n+static int\n+apply_statement_parse(uint32_t *block_mask,\n+\t\t      char **tokens,\n+\t\t      uint32_t n_tokens,\n+\t\t      uint32_t n_lines,\n+\t\t      uint32_t *err_line,\n+\t\t      const char **err_msg)\n+{\n+\t/* Check format. */\n+\tif ((n_tokens != 2) || strcmp(tokens[1], \"{\")) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Invalid apply statement.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* block_mask. */\n+\t*block_mask |= 1 << APPLY_BLOCK;\n+\n+\treturn 0;\n+}\n+\n+static int\n+apply_block_parse(struct apply_spec *s,\n+\t\t  uint32_t *block_mask,\n+\t\t  char **tokens,\n+\t\t  uint32_t n_tokens,\n+\t\t  uint32_t n_lines,\n+\t\t  uint32_t *err_line,\n+\t\t  const char **err_msg)\n+{\n+\tchar buffer[MAX_INSTRUCTION_LENGTH], *instr;\n+\tconst char **new_instructions;\n+\tuint32_t i;\n+\n+\t/* Handle end of block. */\n+\tif ((n_tokens == 1) && !strcmp(tokens[0], \"}\")) {\n+\t\t*block_mask &= ~(1 << APPLY_BLOCK);\n+\t\treturn 0;\n+\t}\n+\n+\t/* spec. */\n+\tbuffer[0] = 0;\n+\tfor (i = 0; i < n_tokens; i++) {\n+\t\tif (i)\n+\t\t\tstrcat(buffer, \" \");\n+\t\tstrcat(buffer, tokens[i]);\n+\t}\n+\n+\tinstr = strdup(buffer);\n+\tif (!instr) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\tnew_instructions = reallocarray(s->instructions,\n+\t\t\t\t\ts->n_instructions + 1,\n+\t\t\t\t\tsizeof(char *));\n+\tif (!new_instructions) {\n+\t\tfree(instr);\n+\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Memory allocation failed.\";\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\ts->instructions = new_instructions;\n+\ts->instructions[s->n_instructions] = instr;\n+\ts->n_instructions++;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Pipeline.\n+ */\n+int\n+rte_swx_pipeline_build_from_spec(struct rte_swx_pipeline *p,\n+\t\t\t\t FILE *spec,\n+\t\t\t\t uint32_t *err_line,\n+\t\t\t\t const char **err_msg)\n+{\n+\tstruct extobj_spec extobj_spec = {0};\n+\tstruct struct_spec struct_spec = {0};\n+\tstruct header_spec header_spec = {0};\n+\tstruct metadata_spec metadata_spec = {0};\n+\tstruct action_spec action_spec = {0};\n+\tstruct table_spec table_spec = {0};\n+\tstruct apply_spec apply_spec = {0};\n+\tuint32_t n_lines;\n+\tuint32_t block_mask = 0;\n+\tint status;\n+\n+\t/* Check the input arguments. */\n+\tif (!p) {\n+\t\tif (err_line)\n+\t\t\t*err_line = 0;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Null pipeline arument.\";\n+\t\tstatus = -EINVAL;\n+\t\tgoto error;\n+\t}\n+\n+\tif (!p) {\n+\t\tif (err_line)\n+\t\t\t*err_line = 0;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Null specification file argument.\";\n+\t\tstatus = -EINVAL;\n+\t\tgoto error;\n+\t}\n+\n+\tfor (n_lines = 1; ; n_lines++) {\n+\t\tchar line[MAX_LINE_LENGTH];\n+\t\tchar *tokens[MAX_TOKENS], *ptr = line;\n+\t\tuint32_t n_tokens = 0;\n+\n+\t\t/* Read next line. */\n+\t\tif (!fgets(line, sizeof(line), spec))\n+\t\t\tbreak;\n+\n+\t\t/* Parse the line into tokens. */\n+\t\tfor ( ; ; ) {\n+\t\t\tchar *token;\n+\n+\t\t\t/* Get token. */\n+\t\t\ttoken = strtok_r(ptr, \" \\f\\n\\r\\t\\v\", &ptr);\n+\t\t\tif (!token)\n+\t\t\t\tbreak;\n+\n+\t\t\t/* Handle comments. */\n+\t\t\tif ((token[0] == '#') ||\n+\t\t\t    (token[0] == ';') ||\n+\t\t\t    ((token[0] == '/') && (token[1] == '/'))) {\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\t/* Handle excessively long lines. */\n+\t\t\tif (n_tokens >= MAX_TOKENS) {\n+\t\t\t\tif (err_line)\n+\t\t\t\t\t*err_line = n_lines;\n+\t\t\t\tif (err_msg)\n+\t\t\t\t\t*err_msg = \"Too many tokens.\";\n+\t\t\t\tstatus = -EINVAL;\n+\t\t\t\tgoto error;\n+\t\t\t}\n+\n+\t\t\t/* Save token. */\n+\t\t\ttokens[n_tokens] = token;\n+\t\t\tn_tokens++;\n+\t\t}\n+\n+\t\t/* Handle empty lines. */\n+\t\tif (!n_tokens)\n+\t\t\tcontinue;\n+\n+\t\t/* struct block. */\n+\t\tif (block_mask & (1 << STRUCT_BLOCK)) {\n+\t\t\tstatus = struct_block_parse(&struct_spec,\n+\t\t\t\t\t\t    &block_mask,\n+\t\t\t\t\t\t    tokens,\n+\t\t\t\t\t\t    n_tokens,\n+\t\t\t\t\t\t    n_lines,\n+\t\t\t\t\t\t    err_line,\n+\t\t\t\t\t\t    err_msg);\n+\t\t\tif (status)\n+\t\t\t\tgoto error;\n+\n+\t\t\tif (block_mask & (1 << STRUCT_BLOCK))\n+\t\t\t\tcontinue;\n+\n+\t\t\t/* End of block. */\n+\t\t\tstatus = rte_swx_pipeline_struct_type_register(p,\n+\t\t\t\tstruct_spec.name,\n+\t\t\t\tstruct_spec.fields,\n+\t\t\t\tstruct_spec.n_fields);\n+\t\t\tif (status) {\n+\t\t\t\tif (err_line)\n+\t\t\t\t\t*err_line = n_lines;\n+\t\t\t\tif (err_msg)\n+\t\t\t\t\t*err_msg = \"Struct registration error.\";\n+\t\t\t\tgoto error;\n+\t\t\t}\n+\n+\t\t\tstruct_spec_free(&struct_spec);\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* action block. */\n+\t\tif (block_mask & (1 << ACTION_BLOCK)) {\n+\t\t\tstatus = action_block_parse(&action_spec,\n+\t\t\t\t\t\t    &block_mask,\n+\t\t\t\t\t\t    tokens,\n+\t\t\t\t\t\t    n_tokens,\n+\t\t\t\t\t\t    n_lines,\n+\t\t\t\t\t\t    err_line,\n+\t\t\t\t\t\t    err_msg);\n+\t\t\tif (status)\n+\t\t\t\tgoto error;\n+\n+\t\t\tif (block_mask & (1 << ACTION_BLOCK))\n+\t\t\t\tcontinue;\n+\n+\t\t\t/* End of block. */\n+\t\t\tstatus = rte_swx_pipeline_action_config(p,\n+\t\t\t\taction_spec.name,\n+\t\t\t\taction_spec.args_struct_type_name,\n+\t\t\t\taction_spec.instructions,\n+\t\t\t\taction_spec.n_instructions);\n+\t\t\tif (status) {\n+\t\t\t\tif (err_line)\n+\t\t\t\t\t*err_line = n_lines;\n+\t\t\t\tif (err_msg)\n+\t\t\t\t\t*err_msg = \"Action config error.\";\n+\t\t\t\tgoto error;\n+\t\t\t}\n+\n+\t\t\taction_spec_free(&action_spec);\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* table block. */\n+\t\tif (block_mask & (1 << TABLE_BLOCK)) {\n+\t\t\tstatus = table_block_parse(&table_spec,\n+\t\t\t\t\t\t   &block_mask,\n+\t\t\t\t\t\t   tokens,\n+\t\t\t\t\t\t   n_tokens,\n+\t\t\t\t\t\t   n_lines,\n+\t\t\t\t\t\t   err_line,\n+\t\t\t\t\t\t   err_msg);\n+\t\t\tif (status)\n+\t\t\t\tgoto error;\n+\n+\t\t\tif (block_mask & (1 << TABLE_BLOCK))\n+\t\t\t\tcontinue;\n+\n+\t\t\t/* End of block. */\n+\t\t\tstatus = rte_swx_pipeline_table_config(p,\n+\t\t\t\ttable_spec.name,\n+\t\t\t\t&table_spec.params,\n+\t\t\t\ttable_spec.recommended_table_type_name,\n+\t\t\t\ttable_spec.args,\n+\t\t\t\ttable_spec.size);\n+\t\t\tif (status) {\n+\t\t\t\tif (err_line)\n+\t\t\t\t\t*err_line = n_lines;\n+\t\t\t\tif (err_msg)\n+\t\t\t\t\t*err_msg = \"Table configuration error.\";\n+\t\t\t\tgoto error;\n+\t\t\t}\n+\n+\t\t\ttable_spec_free(&table_spec);\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* apply block. */\n+\t\tif (block_mask & (1 << APPLY_BLOCK)) {\n+\t\t\tstatus = apply_block_parse(&apply_spec,\n+\t\t\t\t\t\t   &block_mask,\n+\t\t\t\t\t\t   tokens,\n+\t\t\t\t\t\t   n_tokens,\n+\t\t\t\t\t\t   n_lines,\n+\t\t\t\t\t\t   err_line,\n+\t\t\t\t\t\t   err_msg);\n+\t\t\tif (status)\n+\t\t\t\tgoto error;\n+\n+\t\t\tif (block_mask & (1 << APPLY_BLOCK))\n+\t\t\t\tcontinue;\n+\n+\t\t\t/* End of block. */\n+\t\t\tstatus = rte_swx_pipeline_instructions_config(p,\n+\t\t\t\tapply_spec.instructions,\n+\t\t\t\tapply_spec.n_instructions);\n+\t\t\tif (status) {\n+\t\t\t\tif (err_line)\n+\t\t\t\t\t*err_line = n_lines;\n+\t\t\t\tif (err_msg)\n+\t\t\t\t\t*err_msg = \"Pipeline instructions err.\";\n+\t\t\t\tgoto error;\n+\t\t\t}\n+\n+\t\t\tapply_spec_free(&apply_spec);\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* extobj. */\n+\t\tif (!strcmp(tokens[0], \"extobj\")) {\n+\t\t\tstatus = extobj_statement_parse(&extobj_spec,\n+\t\t\t\t\t\t\ttokens,\n+\t\t\t\t\t\t\tn_tokens,\n+\t\t\t\t\t\t\tn_lines,\n+\t\t\t\t\t\t\terr_line,\n+\t\t\t\t\t\t\terr_msg);\n+\t\t\tif (status)\n+\t\t\t\tgoto error;\n+\n+\t\t\tstatus = rte_swx_pipeline_extern_object_config(p,\n+\t\t\t\textobj_spec.name,\n+\t\t\t\textobj_spec.extern_type_name,\n+\t\t\t\textobj_spec.pragma);\n+\t\t\tif (status) {\n+\t\t\t\tif (err_line)\n+\t\t\t\t\t*err_line = n_lines;\n+\t\t\t\tif (err_msg)\n+\t\t\t\t\t*err_msg = \"Extern object config err.\";\n+\t\t\t\tgoto error;\n+\t\t\t}\n+\n+\t\t\textobj_spec_free(&extobj_spec);\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* struct. */\n+\t\tif (!strcmp(tokens[0], \"struct\")) {\n+\t\t\tstatus = struct_statement_parse(&struct_spec,\n+\t\t\t\t\t\t\t&block_mask,\n+\t\t\t\t\t\t\ttokens,\n+\t\t\t\t\t\t\tn_tokens,\n+\t\t\t\t\t\t\tn_lines,\n+\t\t\t\t\t\t\terr_line,\n+\t\t\t\t\t\t\terr_msg);\n+\t\t\tif (status)\n+\t\t\t\tgoto error;\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* header. */\n+\t\tif (!strcmp(tokens[0], \"header\")) {\n+\t\t\tstatus = header_statement_parse(&header_spec,\n+\t\t\t\t\t\t\ttokens,\n+\t\t\t\t\t\t\tn_tokens,\n+\t\t\t\t\t\t\tn_lines,\n+\t\t\t\t\t\t\terr_line,\n+\t\t\t\t\t\t\terr_msg);\n+\t\t\tif (status)\n+\t\t\t\tgoto error;\n+\n+\t\t\tstatus = rte_swx_pipeline_packet_header_register(p,\n+\t\t\t\theader_spec.name,\n+\t\t\t\theader_spec.struct_type_name);\n+\t\t\tif (status) {\n+\t\t\t\tif (err_line)\n+\t\t\t\t\t*err_line = n_lines;\n+\t\t\t\tif (err_msg)\n+\t\t\t\t\t*err_msg = \"Header registration error.\";\n+\t\t\t\tgoto error;\n+\t\t\t}\n+\n+\t\t\theader_spec_free(&header_spec);\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* metadata. */\n+\t\tif (!strcmp(tokens[0], \"metadata\")) {\n+\t\t\tstatus = metadata_statement_parse(&metadata_spec,\n+\t\t\t\t\t\t\t  tokens,\n+\t\t\t\t\t\t\t  n_tokens,\n+\t\t\t\t\t\t\t  n_lines,\n+\t\t\t\t\t\t\t  err_line,\n+\t\t\t\t\t\t\t  err_msg);\n+\t\t\tif (status)\n+\t\t\t\tgoto error;\n+\n+\t\t\tstatus = rte_swx_pipeline_packet_metadata_register(p,\n+\t\t\t\tmetadata_spec.struct_type_name);\n+\t\t\tif (status) {\n+\t\t\t\tif (err_line)\n+\t\t\t\t\t*err_line = n_lines;\n+\t\t\t\tif (err_msg)\n+\t\t\t\t\t*err_msg = \"Meta-data reg err.\";\n+\t\t\t\tgoto error;\n+\t\t\t}\n+\n+\t\t\tmetadata_spec_free(&metadata_spec);\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* action. */\n+\t\tif (!strcmp(tokens[0], \"action\")) {\n+\t\t\tstatus = action_statement_parse(&action_spec,\n+\t\t\t\t\t\t\t&block_mask,\n+\t\t\t\t\t\t\ttokens,\n+\t\t\t\t\t\t\tn_tokens,\n+\t\t\t\t\t\t\tn_lines,\n+\t\t\t\t\t\t\terr_line,\n+\t\t\t\t\t\t\terr_msg);\n+\t\t\tif (status)\n+\t\t\t\tgoto error;\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* table. */\n+\t\tif (!strcmp(tokens[0], \"table\")) {\n+\t\t\tstatus = table_statement_parse(&table_spec,\n+\t\t\t\t\t\t       &block_mask,\n+\t\t\t\t\t\t       tokens,\n+\t\t\t\t\t\t       n_tokens,\n+\t\t\t\t\t\t       n_lines,\n+\t\t\t\t\t\t       err_line,\n+\t\t\t\t\t\t       err_msg);\n+\t\t\tif (status)\n+\t\t\t\tgoto error;\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* apply. */\n+\t\tif (!strcmp(tokens[0], \"apply\")) {\n+\t\t\tstatus = apply_statement_parse(&block_mask,\n+\t\t\t\t\t\t       tokens,\n+\t\t\t\t\t\t       n_tokens,\n+\t\t\t\t\t\t       n_lines,\n+\t\t\t\t\t\t       err_line,\n+\t\t\t\t\t\t       err_msg);\n+\t\t\tif (status)\n+\t\t\t\tgoto error;\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* Anything else. */\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Unknown statement.\";\n+\t\tstatus = -EINVAL;\n+\t\tgoto error;\n+\t}\n+\n+\t/* Handle unfinished block. */\n+\tif (block_mask) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Missing }.\";\n+\t\tstatus = -EINVAL;\n+\t\tgoto error;\n+\t}\n+\n+\t/* Pipeline build. */\n+\tstatus = rte_swx_pipeline_build(p);\n+\tif (status) {\n+\t\tif (err_line)\n+\t\t\t*err_line = n_lines;\n+\t\tif (err_msg)\n+\t\t\t*err_msg = \"Pipeline build error.\";\n+\t\tgoto error;\n+\t}\n+\n+\treturn 0;\n+\n+error:\n+\textobj_spec_free(&extobj_spec);\n+\tstruct_spec_free(&struct_spec);\n+\theader_spec_free(&header_spec);\n+\tmetadata_spec_free(&metadata_spec);\n+\taction_spec_free(&action_spec);\n+\ttable_spec_free(&table_spec);\n+\tapply_spec_free(&apply_spec);\n+\treturn status;\n+}\n",
    "prefixes": [
        "v3",
        "32/41"
    ]
}