mirror of
https://github.com/utmapp/spice.git
synced 2026-12-01 22:23:37 -10:00
codegen: No SPICE_ADDRESS types left, drop @c_ptr
This commit is contained in:
1 parent
31d2d6e4e4
commit
f0f623ddc0
4 files changed
+37
-44
No files matched your search
@@ -82,9 +82,8 @@ def write_parser_helpers(writer):
|
||||
writer.begin_block("struct PointerInfo")
|
||||
writer.variable_def("uint64_t", "offset")
|
||||
writer.variable_def("parse_func_t", "parse")
|
||||
writer.variable_def("void *", "dest")
|
||||
writer.variable_def("void **", "dest")
|
||||
writer.variable_def("uint32_t", "nelements")
|
||||
writer.variable_def("int", "is_ptr")
|
||||
writer.end_block(semicolon=True)
|
||||
|
||||
def write_read_primitive(writer, start, container, name, scope):
|
||||
@@ -195,7 +194,7 @@ def write_validate_struct_function(writer, struct):
|
||||
|
||||
writer.set_is_generated("validator", validate_function)
|
||||
writer = writer.function_helper()
|
||||
scope = writer.function(validate_function, "static intptr_t", "uint8_t *message_start, uint8_t *message_end, SPICE_ADDRESS offset, int minor")
|
||||
scope = writer.function(validate_function, "static intptr_t", "uint8_t *message_start, uint8_t *message_end, uint64_t offset, int minor")
|
||||
scope.variable_def("uint8_t *", "start = message_start + offset")
|
||||
scope.variable_def("SPICE_GNUC_UNUSED uint8_t *", "pos");
|
||||
scope.variable_def("size_t", "mem_size", "nw_size");
|
||||
@@ -809,16 +808,14 @@ def write_array_parser(writer, nelements, array, dest, scope):
|
||||
writer.assign("end", "(uint8_t *)SPICE_ALIGN((size_t)end, 4)")
|
||||
|
||||
def write_parse_pointer(writer, t, at_end, dest, member_name, scope):
|
||||
as_c_ptr = t.has_attr("c_ptr")
|
||||
target_type = t.target_type
|
||||
writer.assign("ptr_info[n_ptr].offset", "consume_%s(&in)" % t.primitive_type())
|
||||
writer.assign("ptr_info[n_ptr].parse", write_parse_ptr_function(writer, target_type))
|
||||
if at_end:
|
||||
writer.assign("ptr_info[n_ptr].dest", "end")
|
||||
writer.increment("end", "sizeof(void *)" if as_c_ptr else "sizeof(SPICE_ADDRESS)");
|
||||
writer.assign("ptr_info[n_ptr].dest", "(void **)end")
|
||||
writer.increment("end", "sizeof(void *)");
|
||||
else:
|
||||
writer.assign("ptr_info[n_ptr].dest", "&%s" % dest.get_ref(member_name))
|
||||
writer.assign("ptr_info[n_ptr].is_ptr", "1" if as_c_ptr else "0")
|
||||
writer.assign("ptr_info[n_ptr].dest", "(void **)&%s" % dest.get_ref(member_name))
|
||||
if target_type.is_array():
|
||||
nelements = read_array_len(writer, member_name, target_type, dest, scope)
|
||||
writer.assign("ptr_info[n_ptr].nelements", nelements)
|
||||
@@ -932,20 +929,13 @@ def write_ptr_info_check(writer):
|
||||
with writer.for_loop(index, "n_ptr") as scope:
|
||||
offset = "ptr_info[%s].offset" % index
|
||||
function = "ptr_info[%s].parse" % index
|
||||
is_ptr = "ptr_info[%s].is_ptr" % index
|
||||
dest = "ptr_info[%s].dest" % index
|
||||
with writer.if_block("%s == 0" % offset, newline=False):
|
||||
with writer.if_block(is_ptr, newline=False):
|
||||
writer.assign("*(void **)(%s)" % dest, "NULL")
|
||||
with writer.block(" else"):
|
||||
writer.assign("*(SPICE_ADDRESS *)(%s)" % dest, "0")
|
||||
writer.assign("*%s" % dest, "NULL")
|
||||
with writer.block(" else"):
|
||||
writer.comment("Align to 32 bit").newline()
|
||||
writer.assign("end", "(uint8_t *)SPICE_ALIGN((size_t)end, 4)")
|
||||
with writer.if_block(is_ptr, newline=False):
|
||||
writer.assign("*(void **)(%s)" % dest, "(void *)end")
|
||||
with writer.block(" else"):
|
||||
writer.assign("*(SPICE_ADDRESS *)(%s)" % dest, "(SPICE_ADDRESS)end")
|
||||
writer.assign("*%s" % dest, "(void *)end")
|
||||
writer.assign("end", "%s(message_start, message_end, end, &ptr_info[%s], minor)" % (function, index))
|
||||
writer.error_check("end == NULL")
|
||||
writer.newline()
|
||||
|
||||
@@ -60,7 +60,7 @@ class FixedSize:
|
||||
# only to attributes that affect pointer or array attributes, as these
|
||||
# are member local types, unlike e.g. a Struct that may be used by
|
||||
# other members
|
||||
propagated_attributes=["ptr_array", "c_ptr", "nonnull", "chunk"]
|
||||
propagated_attributes=["ptr_array", "nonnull", "chunk"]
|
||||
|
||||
class Type:
|
||||
def __init__(self):
|
||||
@@ -469,7 +469,10 @@ class PointerType(Type):
|
||||
return self.pointer_size
|
||||
|
||||
def c_type(self):
|
||||
return "SPICE_ADDRESS"
|
||||
if self.pointer_size == 4:
|
||||
return "uint32_t"
|
||||
else:
|
||||
return "uint64_t"
|
||||
|
||||
def has_pointer(self):
|
||||
return True
|
||||
|
||||
Reference in new issue
Block a user