diff options
author | Frediano Ziglio <freddy77@gmail.com> | 2020-09-18 15:01:57 +0100 |
---|---|---|
committer | Frediano Ziglio <freddy77@gmail.com> | 2020-10-06 13:09:56 +0100 |
commit | d8fe0cbb842e19aeeb8894fa59161dfd9e182cec (patch) | |
tree | d24e9dce2e2f2a37e7eb9d779797fe05623a9524 /python_modules | |
parent | d589542e0492888ac1b300200c7c6cb4eaf88cb0 (diff) |
codegen: Remove bytes array length support
This syntax was only used in protocol 1 which has been removed
time ago.
Beside not being used it's confusing and prone to errors,
array size is specified using 2 identifiers, one reporting
bytes and the other number of items, one used for marshalling,
the other for demarshalling.
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Diffstat (limited to 'python_modules')
-rw-r--r-- | python_modules/demarshal.py | 39 | ||||
-rw-r--r-- | python_modules/marshal.py | 14 | ||||
-rw-r--r-- | python_modules/ptypes.py | 5 | ||||
-rw-r--r-- | python_modules/spice_parser.py | 4 |
4 files changed, 5 insertions, 57 deletions
diff --git a/python_modules/demarshal.py b/python_modules/demarshal.py index b27eb75..efc4c99 100644 --- a/python_modules/demarshal.py +++ b/python_modules/demarshal.py @@ -317,15 +317,8 @@ def write_validate_array_item(writer, container, item, scope, parent_scope, star array = item.type if item.member: array.check_valid(item.member) - is_byte_size = False element_type = array.element_type - if array.is_bytes_length(): - nelements = "%s__nbytes" %(item.prefix) - real_nelements = "%s__nelements" %(item.prefix) - if not parent_scope.variable_defined(real_nelements): - parent_scope.variable_def("uint64_t", real_nelements) - else: - nelements = "%s__nelements" %(item.prefix) + nelements = "%s__nelements" %(item.prefix) if not parent_scope.variable_defined(nelements): parent_scope.variable_def("uint64_t", nelements) @@ -355,11 +348,6 @@ def write_validate_array_item(writer, container, item, scope, parent_scope, star writer.assign(nelements, "(((uint64_t) %s + 7U) / 8U ) * %s" % (width_v, rows_v)) else: writer.assign(nelements, "((%sU * (uint64_t) %s + 7U) / 8U ) * %s" % (bpp, width_v, rows_v)) - elif array.is_bytes_length(): - is_byte_size = True - v = write_read_primitive(writer, start, container, array.size[1], scope) - writer.assign(nelements, v) - writer.assign(real_nelements, 0) elif array.is_cstring_length(): writer.todo("cstring array size type not handled yet") else: @@ -371,10 +359,6 @@ def write_validate_array_item(writer, container, item, scope, parent_scope, star mem_size = item.mem_size() extra_size = item.extra_size() - if is_byte_size and want_nw_size: - writer.assign(nw_size, nelements) - want_nw_size = False - if element_type.is_fixed_nw_size() and want_nw_size: element_size = element_type.get_fixed_nw_size() # TODO: Overflow check the multiplication @@ -396,7 +380,7 @@ def write_validate_array_item(writer, container, item, scope, parent_scope, star writer.assign(extra_size, "sizeof(SpiceChunks) + sizeof(SpiceChunk)") want_extra_size = False - if element_type.is_fixed_sizeof() and want_mem_size and not is_byte_size: + if element_type.is_fixed_sizeof() and want_mem_size: # TODO: Overflow check the multiplication if array.has_attr("ptr_array"): writer.assign(mem_size, "sizeof(void *) + SPICE_ALIGN(%s * %s, 4)" % (element_type.sizeof(), nelements)) @@ -413,9 +397,6 @@ def write_validate_array_item(writer, container, item, scope, parent_scope, star start2 = codegen.increment_identifier(start) scope.variable_def("uint8_t *", "%s = %s" % (start2, item.get_position())) - if is_byte_size: - start2_end = "%s_array_end" % start2 - scope.variable_def("uint8_t *", start2_end) element_item = ItemInfo(element_type, "%s__element" % item.prefix, start2) @@ -441,13 +422,8 @@ def write_validate_array_item(writer, container, item, scope, parent_scope, star want_element_nw_size = True start_increment = element_nw_size - if is_byte_size: - writer.assign(start2_end, "%s + %s" % (start2, nelements)) - - with writer.index(no_block = is_byte_size) as index: - with writer.while_loop("%s < %s" % (start2, start2_end) ) if is_byte_size else writer.for_loop(index, nelements) as scope: - if is_byte_size: - writer.increment(real_nelements, 1) + with writer.index() as index: + with writer.for_loop(index, nelements) as scope: write_validate_item(writer, container, element_item, scope, parent_scope, start2, want_element_nw_size, want_mem_size, want_extra_size) @@ -462,9 +438,6 @@ def write_validate_array_item(writer, container, item, scope, parent_scope, star writer.increment(extra_size, element_extra_size) writer.increment(start2, start_increment) - if is_byte_size: - writer.error_check("%s != %s" % (start2, start2_end)) - write_write_primitive(writer, start, container, array.size[1], real_nelements) def write_validate_struct_item(writer, container, item, scope, parent_scope, start, want_nw_size, want_mem_size, want_extra_size): @@ -699,8 +672,6 @@ def read_array_len(writer, prefix, array, dest, scope, is_ptr): writer.assign(nelements, "(((uint64_t) %s + 7U) / 8U ) * %s" % (width_v, rows_v)) else: writer.assign(nelements, "((%sU * (uint64_t) %s + 7U) / 8U ) * %s" % (bpp, width_v, rows_v)) - elif array.is_bytes_length(): - writer.assign(nelements, dest.get_ref(array.size[2])) else: raise NotImplementedError("TODO array size type not handled yet") return nelements @@ -801,8 +772,6 @@ def write_parse_ptr_function(writer, target_type): return parse_function def write_array_parser(writer, member, nelements, array, dest, scope): - is_byte_size = array.is_bytes_length() - element_type = array.element_type if member: array_start = dest.get_ref(member.name) diff --git a/python_modules/marshal.py b/python_modules/marshal.py index 269dadf..e2a370b 100644 --- a/python_modules/marshal.py +++ b/python_modules/marshal.py @@ -179,8 +179,6 @@ def get_array_size(array, container_src): return "((((uint64_t) %s + 7U) / 8U ) * %s)" % (width_v, rows_v) else: return "((((uint64_t) %s * %s + 7U) / 8U ) * %s)" % (bpp, width_v, rows_v) - elif array.is_bytes_length(): - return container_src.get_ref(array.size[2]) else: raise NotImplementedError("TODO array size type not handled yet: %s" % array) @@ -192,7 +190,6 @@ def write_array_marshaller(writer, member, array, container_src, scope): return nelements = get_array_size(array, container_src) - is_byte_size = array.is_bytes_length() element = "%s__element" % member.name @@ -208,11 +205,6 @@ def write_array_marshaller(writer, member, array, container_src, scope): writer.assign(element_array, container_src.get_ref(member.name)) - if is_byte_size: - size_start_var = "%s__size_start" % member.name - scope.variable_def("size_t", size_start_var) - writer.assign(size_start_var, "spice_marshaller_get_size(m)") - with writer.index() as index: with writer.for_loop(index, nelements) as array_scope: if element_type.is_primitive(): @@ -226,12 +218,6 @@ def write_array_marshaller(writer, member, array, container_src, scope): writer.statement("%s++" % element_array) - if is_byte_size: - size_var = member.container.lookup_member(array.size[1]) - size_var_type = size_var.member_type - var = "%s__ref" % array.size[1] - writer.statement("spice_marshaller_set_%s(m, %s, spice_marshaller_get_size(m) - %s)" % (size_var_type.primitive_type(), var, size_start_var)) - def write_pointer_marshaller(writer, member, src): t = member.member_type ptr_func = write_marshal_ptr_function(writer, t.target_type) diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py index 7b4146d..eba26a6 100644 --- a/python_modules/ptypes.py +++ b/python_modules/ptypes.py @@ -448,11 +448,6 @@ class ArrayType(Type): return False return self.size[0] == "image_size" - def is_bytes_length(self): - if isinstance(self.size, int) or isinstance(self.size, str): - return False - return self.size[0] == "bytes" - def is_cstring_length(self): if isinstance(self.size, int) or isinstance(self.size, str): return False diff --git a/python_modules/spice_parser.py b/python_modules/spice_parser.py index 6fa3fc8..4d753cb 100644 --- a/python_modules/spice_parser.py +++ b/python_modules/spice_parser.py @@ -73,7 +73,6 @@ def SPICE_BNF(): struct_ = Keyword("struct") message_ = Keyword("message") image_size_ = Keyword("image_size") - bytes_ = Keyword("bytes") cstring_ = Keyword("cstring") switch_ = Keyword("switch") default_ = Keyword("default") @@ -94,9 +93,8 @@ def SPICE_BNF(): attribute = Group(Combine ("@" + identifier) + Optional(lparen + delimitedList(attributeValue) + rparen)) attributes = Group(ZeroOrMore(attribute)) arraySizeSpecImage = Group(image_size_ + lparen + integer + comma + identifier + comma + identifier + rparen) - arraySizeSpecBytes = Group(bytes_ + lparen + identifier + comma + identifier + rparen) arraySizeSpecCString = Group(cstring_ + lparen + rparen) - arraySizeSpec = lbrack + Optional(identifier ^ integer ^ arraySizeSpecImage ^ arraySizeSpecBytes ^arraySizeSpecCString, default="") + rbrack + arraySizeSpec = lbrack + Optional(identifier ^ integer ^ arraySizeSpecImage ^ arraySizeSpecCString, default="") + rbrack variableDef = Group(typeSpec + Optional("*", default=None) + identifier + Optional(arraySizeSpec, default=None) + attributes - semi) \ .setParseAction(parseVariableDef) |