示例#1
0
    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,
        )
示例#2
0
 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
示例#3
0
 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
示例#4
0
 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
示例#5
0
 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
示例#6
0
 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
示例#7
0
 def _is_packed(self, attributes):
     for attribute in attributes:
         if parsers.attribute_name_match(attribute.name, 'packed'):
             return True
     return False
示例#8
0
 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
示例#9
0
 def _is_packed(self, attributes):
     for attribute in attributes:
         if parsers.attribute_name_match(attribute.name, 'packed'):
             return True
     return False