def _update_layout_with_field_attributes(self, layout, attributes): """Modifies a given layout with the given field attributes. Args: layout: an object representing a layout. attributes: a list of objects representing field attributes. """ attributes_alignment = self._compound_type_bit_alignment() for attribute in attributes: if parsers.attribute_name_match(attribute.name, 'packed'): layout.bit_alignment = self._compound_type_bit_alignment() elif parsers.attribute_name_match(attribute.name, 'aligned'): byte_alignment = self.type_manager.evaluate( expression=attribute.parameters[0], ) attributes_alignment = self._lcm( attributes_alignment, 8 * byte_alignment, ) layout.bit_alignment = self._lcm( layout.bit_alignment, attributes_alignment, )
def _get_attributes_alignment(self, attributes): bit_alignment = self._base_alignment() for attribute in attributes: if parsers.attribute_name_match(attribute.name, 'aligned'): expression = attribute.parameters[0] byte_alignment = int(self.type_manager.evaluate(expression)) bit_alignment = self._lcm(bit_alignment, 8 * byte_alignment) return bit_alignment
def visit_c_typedef(self, typedef): layout = typedef.type_definition.accept(self) for attribute in typedef.attributes: if parsers.attribute_name_match(attribute.name, 'aligned'): expression = attribute.parameters[0] byte_alignment = self.type_manager.evaluate(expression) layout.bit_alignment = 8 * byte_alignment return layout
def _get_attributes_alignment(self, attributes): bit_alignment = self._base_alignment() for attribute in attributes: if parsers.attribute_name_match(attribute.name, 'aligned'): expression = attribute.parameters[0] byte_alignment = int(self.type_manager.evaluate( expression)) bit_alignment = self._lcm(bit_alignment, 8 * byte_alignment) return bit_alignment
def visit_c_typedef(self, typedef): layout = typedef.type_definition.accept(self) for attribute in typedef.attributes: if parsers.attribute_name_match(attribute.name, 'aligned'): expression = attribute.parameters[0] byte_alignment = self.type_manager.evaluate( expression) layout.bit_alignment = 8 * byte_alignment return layout
def _is_alignment_overriden(self, type_definition): if hasattr(type_definition, 'attributes'): for attribute in type_definition.attributes: if parsers.attribute_name_match(attribute.name, 'aligned'): return True return False
def _is_packed(self, attributes): for attribute in attributes: if parsers.attribute_name_match(attribute.name, 'packed'): return True return False