Commit bbd21a73 authored by dbarbera's avatar dbarbera
Browse files

Added equal expression generation for complex types

parent 0549a4a8
...@@ -148,17 +148,25 @@ class Context(): ...@@ -148,17 +148,25 @@ class Context():
else: else:
struct = self.decl_struct(['arr'], [array_ty], name) struct = self.decl_struct(['arr'], [array_ty], name)
struct_ptr = core.Type.pointer(struct.ty)
self.decl_func("%s_Equal" % name, self.i1, [struct_ptr, struct_ptr])
return struct.ty return struct.ty
def _type_of_sequence(self, name, sequence_ty): def _type_of_sequence(self, name, sequence_ty):
''' Return the LL type of a Sequence ASN.1 type ''' ''' Return the LL type of a Sequence ASN.1 type '''
field_names = [] field_names = []
field_types = [] field_types = []
for field_name in Helper.sorted_fields(sequence_ty): for field_name in Helper.sorted_fields(sequence_ty):
field_names.append(field_name.replace('-', '_')) field_names.append(field_name.replace('-', '_'))
field_types.append(self.type_of(sequence_ty.Children[field_name].type)) field_types.append(self.type_of(sequence_ty.Children[field_name].type))
struct = self.decl_struct(field_names, field_types, name) struct = self.decl_struct(field_names, field_types, name)
struct_ptr = core.Type.pointer(struct.ty)
self.decl_func("%s_Equal" % name, self.i1, [struct_ptr, struct_ptr])
return struct.ty return struct.ty
def _type_of_choice(self, name, choice_ty): def _type_of_choice(self, name, choice_ty):
...@@ -174,6 +182,10 @@ class Context(): ...@@ -174,6 +182,10 @@ class Context():
field_types.append(self.type_of(choice_ty.Children[field_name].type)) field_types.append(self.type_of(choice_ty.Children[field_name].type))
union = self.decl_union(field_names, field_types, name) union = self.decl_union(field_names, field_types, name)
union_ptr = core.Type.pointer(union.ty)
self.decl_func("%s_Equal" % name, self.i1, [union_ptr, union_ptr])
return union.ty return union.ty
def _type_of_octetstring(self, name, octetstring_ty): def _type_of_octetstring(self, name, octetstring_ty):
...@@ -181,6 +193,10 @@ class Context(): ...@@ -181,6 +193,10 @@ class Context():
max_size = int(octetstring_ty.Max) max_size = int(octetstring_ty.Max)
arr_ty = core.Type.array(ctx.i8, max_size) arr_ty = core.Type.array(ctx.i8, max_size)
struct = self.decl_struct(['nCount', 'arr'], [ctx.i32, arr_ty], name) struct = self.decl_struct(['nCount', 'arr'], [ctx.i32, arr_ty], name)
struct_ptr = core.Type.pointer(struct.ty)
self.decl_func("%s_Equal" % name, self.i1, [struct_ptr, struct_ptr])
return struct.ty return struct.ty
def string_ptr(self, str): def string_ptr(self, str):
...@@ -934,6 +950,14 @@ def _basic(expr): ...@@ -934,6 +950,14 @@ def _basic(expr):
return ctx.builder.fcmp(core.FCMP_OGT, lefttmp, righttmp, 'gttmp') return ctx.builder.fcmp(core.FCMP_OGT, lefttmp, righttmp, 'gttmp')
else: else:
raise NotImplementedError raise NotImplementedError
elif is_struct_ptr(lefttmp):
if expr.operand in ['=', '/=']:
type_name = expr.left.exprType.ReferencedTypeName.replace('-', '_').lower()
func = ctx.funcs["%s_equal" % type_name]
res_val = ctx.builder.call(func, [lefttmp, righttmp])
return ctx.builder.not_(res_val) if expr.operand == '/=' else res_val
else:
raise NotImplementedError
else: else:
raise NotImplementedError raise NotImplementedError
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment