[Spice-devel] [PATCH v2 30/43] Generate code to output parse structure

Frediano Ziglio fziglio at redhat.com
Wed Jul 8 06:54:03 PDT 2015


Write a function and call it to be able to reuse it.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 codegen/check_dissector     |  2 ++
 codegen/out_struct1.txt     |  7 +++++++
 codegen/test.proto          |  9 +++++++++
 python_modules/dissector.py | 20 ++++++++++++++++++++
 4 files changed, 38 insertions(+)
 create mode 100644 codegen/out_struct1.txt

diff --git a/codegen/check_dissector b/codegen/check_dissector
index bff3853..767ee9d 100755
--- a/codegen/check_dissector
+++ b/codegen/check_dissector
@@ -54,4 +54,6 @@ fi
 # check just base types
 check data_base1 1 1 out_base1.txt
 
+check data_base1 1 1 out_struct1.txt --client
+
 exit 0
diff --git a/codegen/out_struct1.txt b/codegen/out_struct1.txt
new file mode 100644
index 0000000..a1d429c
--- /dev/null
+++ b/codegen/out_struct1.txt
@@ -0,0 +1,7 @@
+--- tree
+    --- item
+    Text: 33154 (0x8182)
+    Name: dummy
+    Abbrev: spice2.auto.Dummy_dummy
+    Type: FT_UINT16
+    Base: BASE_DEC
diff --git a/codegen/test.proto b/codegen/test.proto
index 28d7769..06fa303 100644
--- a/codegen/test.proto
+++ b/codegen/test.proto
@@ -30,6 +30,10 @@ flags32 F32 {
 	N, O, P, Q
 };
 
+struct Dummy {
+    uint16 dummy;
+};
+
 channel BaseChannel {
   server:
     message {
@@ -49,6 +53,11 @@ channel BaseChannel {
 	F32 f32;
     } Base1 = 1;
     Empty empty = 100;
+
+  client:
+    message {
+        Dummy struct;
+    } Struct1 = 1;
 };
 
 protocol Spice {
diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index aa71615..edc6dc3 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -307,9 +307,29 @@ def write_array(writer, container, member, nelements, array, dest, scope):
 def write_pointer(writer, container, member, t, dest, scope):
     assert(t.is_pointer())
 
+
+def write_struct_func(writer, t, func_name, index):
+    func_name = 'dissect_spice_struct_' + t.name
+
+    if writer.is_generated("struct", t.name):
+        return
+    writer.set_is_generated("struct", t.name)
+
+    writer = writer.function_helper()
+    scope = writer.function(func_name, "guint32", "GlobalInfo *glb _U_, proto_tree *tree _U_, guint32 offset, gint32 index _U_", True)
+    dest = RootDestination(scope)
+    write_container_parser(writer, t, dest)
+    writer.statement('return offset')
+    writer.end_block()
+
+
 def write_struct(writer, member, t, index, dest, scope):
     assert(t.is_struct())
 
+    func_name = 'dissect_spice_struct_' + t.name
+    write_struct_func(writer, t, func_name, index)
+    writer.assign('offset', '%s(glb, %s, offset, %s)' % (func_name, dest.level.tree, index))
+
 def write_member_primitive(writer, container, member, t, dest, scope):
     assert(t.is_primitive())
 
-- 
2.1.0



More information about the Spice-devel mailing list