From 8755f18c2b0c11a51a81f60b5501d9d57d0c370e Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 23 Jun 2022 21:54:38 -0500 Subject: Correctly detect updated packets --- codegen/lib/code/packet.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'codegen/lib/code/packet.py') diff --git a/codegen/lib/code/packet.py b/codegen/lib/code/packet.py index 2aabf39a..7849b0b3 100644 --- a/codegen/lib/code/packet.py +++ b/codegen/lib/code/packet.py @@ -245,3 +245,28 @@ def remove_packet_ids(removing_packet_ids: list[int], direction: str, state: str new_packet_class_names.append(packet_class_name) set_packets(new_packet_ids, new_packet_class_names, direction, state) + + +def are_packet_instructions_identical(old_packet, new_packet): + old_packet = old_packet or [] + new_packet = new_packet or [] + + if len(old_packet) != len(new_packet): + return False + + for old_field, new_field in zip(old_packet, new_packet): + if old_field['operation'] != new_field['operation']: + return False + if new_field['operation'] == 'write': + if burger_type_to_rust_type(old_field.get('type')) != burger_type_to_rust_type(new_field.get('type')): + return False + else: + # comparing is too complicated here since it's possible the type has variables + # so we just don't + pass + + if 'instructions' in old_field and 'instructions' in new_field: + if not are_packet_instructions_identical(old_field['instructions'], new_field['instructions']): + return False + + return True -- cgit v1.2.3