Consider the following code:
header H {
bit<8> s;
varbit<32> v;
}
header Same {
bit<8> same;
}
struct headers {
H h;
H[2] a;
Same same;
}
parser p(packet_in b,
out headers hdr,) {
state start {
b.extract(hdr.h, 32);
b.extract(hdr.a.next, 32);
b.extract(hdr.a.next, 32);
transition accept;
}
}
P4 spec says:
void packet_in.extract<T>(out T headerLValue) {
bitsToExtract = sizeofInBits(headerLValue);
lastBitNeeded = this.nextBitIndex + bitsToExtract;
ParserModel.verify(this.lengthInBits >= lastBitNeeded, error.PacketTooShort);
headerLValue = this.data.extractBits(this.nextBitIndex, bitsToExtract);
headerLValue.valid$ = true;
if headerLValue.isNext$ {
verify(headerLValue.nextIndex$ < headerLValue.size, error.StackOutOfBounds);
headerLValue.nextIndex$ = headerLValue.nextIndex$ + 1;
}
this.nextBitIndex += bitsToExtract;
}
Note the special case wrt header stacks – extraction also increments nextIndex and does verify. We'd need to to this during corelib dialect lowering.
Consider the following code:
P4 spec says:
Note the special case wrt header stacks – extraction also increments
nextIndexand doesverify. We'd need to to this during corelib dialect lowering.