Exemplo n.º 1
0
def dump_to_p4_P4HeaderType(self, hlir):
    layout = OrderedDict()
    attributes = OrderedDict()
    total_length = 0
    flex_width = False
    for field, width, attrs in self.layout:
        attributes[field] = set()
        for attr in attrs:
            if attr == "signed":
                attributes[field].add(P4_SIGNED)
            elif attr == "saturating":
                attributes[field].add(P4_SATURATING)
            else:
                assert False
        if width == "*":
            layout[field] = P4_AUTO_WIDTH
            flex_width = True
        else:
            layout[field] = width.i
            total_length += width.i
    optional_attributes = {}
    if self.max_length:
        max_length = self.max_length.dump_to_p4(hlir)
    if self.length:
        length = self.length.dump_to_p4(hlir)
    if not flex_width and total_length % 8 != 0:
        print "Header type %s not byte-aligned, adding padding" % self.name
        layout["_padding"] = 8 - (total_length % 8)
        attributes["_padding"] = set()
        total_length += layout["_padding"]
        # TODO later
        assert not self.length and not self.max_length
    if not self.length:
        length = total_length / 8
    if not self.max_length:
        max_length = total_length / 8
    g_header = p4_header(
        hlir,
        self.name,
        layout=layout,
        attributes=attributes,
        filename=self.filename,
        lineno=self.lineno,
        length=length,
        max_length=max_length,
    )
    g_header._pragmas = self._pragmas.copy()
Exemplo n.º 2
0
def dump_to_p4_P4HeaderType(self, hlir):
    layout = OrderedDict()
    attributes = OrderedDict()
    total_length = 0
    flex_width = False
    for field, width, attrs in self.layout:
        attributes[field] = set()
        for attr in attrs:
            if attr == "signed":
                attributes[field].add(P4_SIGNED)
            elif attr == "saturating":
                attributes[field].add(P4_SATURATING)
            else:
                assert (False)
        if width == "*":
            layout[field] = P4_AUTO_WIDTH
            flex_width = True
        else:
            layout[field] = width.i
            total_length += width.i
    optional_attributes = {}
    if self.max_length:
        max_length = self.max_length.dump_to_p4(hlir)
    if self.length:
        length = self.length.dump_to_p4(hlir)
    if not flex_width and total_length % 8 != 0:
        print "Header type %s not byte-aligned, adding padding" % self.name
        layout["_padding"] = 8 - (total_length % 8)
        attributes["_padding"] = set()
        total_length += layout["_padding"]
        # TODO later
        assert (not self.length and not self.max_length)
    if not self.length:
        length = total_length / 8
    if not self.max_length:
        max_length = total_length / 8
    g_header = p4_header(hlir,
                         self.name,
                         layout=layout,
                         attributes=attributes,
                         filename=self.filename,
                         lineno=self.lineno,
                         length=length,
                         max_length=max_length)
    g_header._pragmas = self._pragmas.copy()