summaryrefslogtreecommitdiffstats
path: root/vppapigen
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-06-15 16:38:33 +0200
committerDave Wallace <dwallacelf@gmail.com>2016-06-24 13:23:16 +0000
commitfa42e25c4e498c57e15ebb0ded56502a61b7dc08 (patch)
treea6a79850ddab1e962c9f639050a09925fe57c9f0 /vppapigen
parent80ee21386cea217d0e9292d2a8b15ea88bf99d30 (diff)
VPP-118: add support for variable length arrays to jvpp
* extends VPP's message definition language with the following syntax: u32 count: u8 array[count]; which is traslated to: u32 count; u8 array[0]; but now, python API representation generated by vppapigen contains information about where the array length is stored. * modifies existing response messages to use the new syntax Change-Id: I68210bc7a3a755d03d067e9b79a567f40e2d31f3 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'vppapigen')
-rw-r--r--vppapigen/gram.y2
-rw-r--r--vppapigen/node.c21
-rw-r--r--vppapigen/node.h3
3 files changed, 24 insertions, 2 deletions
diff --git a/vppapigen/gram.y b/vppapigen/gram.y
index 09e20067..ccdcc8f2 100644
--- a/vppapigen/gram.y
+++ b/vppapigen/gram.y
@@ -31,6 +31,7 @@ void generate (YYSTYPE);
YYSTYPE add_union(YYSTYPE, YYSTYPE);
YYSTYPE add_scalar_vbl(YYSTYPE);
YYSTYPE add_vector_vbl(YYSTYPE, YYSTYPE);
+ YYSTYPE add_variable_length_vector_vbl(YYSTYPE, YYSTYPE);
YYSTYPE set_flags(YYSTYPE, YYSTYPE);
%}
@@ -86,4 +87,5 @@ onedef: PRIMTYPE vbl SEMI {$$ = add_primtype($1, $2, 0);}
vbl: NAME {$$ = add_scalar_vbl($1);}
| NAME LBRACK NUMBER RBRACK {$$ = add_vector_vbl($1, $3);}
+ | NAME LBRACK NAME RBRACK {$$ = add_variable_length_vector_vbl($1, $3);}
;
diff --git a/vppapigen/node.c b/vppapigen/node.c
index 2fb65c2d..30a3b017 100644
--- a/vppapigen/node.c
+++ b/vppapigen/node.c
@@ -1161,7 +1161,11 @@ void node_vector_generate (node_t *this, enum passid which, FILE *fp)
fprintf(fp, "}\n");
break;
case PYTHON_PASS:
- fprintf(fp, "'%s', '%d'),\n", CDATA0, IDATA1);
+ if (CDATA2 != 0) { // variable length vector
+ fprintf(fp, "'%s', '%d', '%s'),\n", CDATA0, IDATA1, CDATA2);
+ } else {
+ fprintf(fp, "'%s', '%d'),\n", CDATA0, IDATA1);
+ }
break;
default:
@@ -1461,6 +1465,21 @@ YYSTYPE add_vector_vbl (YYSTYPE a1, YYSTYPE a2)
}
/*
+ * add_vector_vbl (char *vector_name, char *vector_length_var)
+ */
+
+YYSTYPE add_variable_length_vector_vbl (YYSTYPE vector_name, YYSTYPE vector_length_var)
+{
+ node_t *np;
+
+ np = make_node(NODE_VECTOR);
+ np->data[0] = (void *) vector_name;
+ np->data[1] = (void *) 0; // vector size used for vpe.api.h generation (array of length zero)
+ np->data[2] = (void *) vector_length_var; // name of the variable that stores vector length
+ return ((YYSTYPE) np);
+}
+
+/*
* add_scalar_vbl (char *name)
*/
YYSTYPE add_scalar_vbl (YYSTYPE a1)
diff --git a/vppapigen/node.h b/vppapigen/node.h
index 1f5a153c..fc331507 100644
--- a/vppapigen/node.h
+++ b/vppapigen/node.h
@@ -73,12 +73,13 @@ typedef struct node_ {
struct node_ *peer;
struct node_ *deeper;
int flags;
- void *data[2];
+ void *data[3];
} node_t;
/* To shut up gcc-4.2.x warnings */
#define CDATA0 ((char *)(this->data[0]))
#define IDATA1 ((int)(uword)(this->data[1]))
+#define CDATA2 ((char *)(this->data[2]))
#define NODE_FLAG_MANUAL_PRINT (1<<0)
#define NODE_FLAG_MANUAL_ENDIAN (1<<1)