[Spice-devel] [PATCH 24/33] Generate code to output parse structure

Frediano Ziglio fziglio at redhat.com
Wed Jul 1 10:10:16 PDT 2015


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

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 python_modules/dissector.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index 4db2f3c..c9331cd 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -230,9 +230,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 *tree0 _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, tree%d, offset, %s)' % (func_name, dest.level, 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