Skip to content

Commit 8f355cd

Browse files
authored
fix lookahead byte order issue (#579)
1 parent 79ead8c commit 8f355cd

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

midend/expandLookahead.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ const IR::Expression* DoExpandLookahead::expand(
5454
} else if (type->is<IR::Type_Bits>() || type->is<IR::Type_Boolean>()) {
5555
unsigned size = type->width_bits();
5656
BUG_CHECK(size > 0, "%1%: unexpected size %2%", type, size);
57-
auto expression = new IR::Slice(base->clone(), *offset + size - 1, *offset);
58-
*offset += size;
57+
auto expression = new IR::Slice(base->clone(), *offset - 1, *offset - size);
58+
*offset -= size;
5959
return expression;
6060
} else {
6161
::error("%1%: unexpected type in lookahead argument", type);
@@ -104,7 +104,7 @@ const IR::Node* DoExpandLookahead::postorder(IR::AssignmentStatement* statement)
104104
auto lookupCall = new IR::AssignmentStatement(statement->srcInfo, pathe, mc);
105105
result->push_back(lookupCall);
106106

107-
unsigned offset = 0;
107+
unsigned offset = width;
108108
expandSetValid(statement->left->clone(), typearg, &result->components);
109109
auto init = expand(pathe->clone(), typearg, &offset);
110110
if (init == nullptr)

testdata/p4_16_samples_outputs/issue355-bmv2-midend.p4

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ parser parserI(packet_in pkt, out H hdr, inout M meta, inout standard_metadata_t
2424
state start {
2525
tmp = pkt.lookahead<bit<112>>();
2626
tmp_0.setValid();
27-
tmp_0.dstAddr = tmp[47:0];
28-
tmp_0.srcAddr = tmp[95:48];
29-
tmp_0.etherType = tmp[111:96];
27+
tmp_0.dstAddr = tmp[111:64];
28+
tmp_0.srcAddr = tmp[63:16];
29+
tmp_0.etherType = tmp[15:0];
3030
transition select(tmp_0.etherType) {
3131
16w0x1000 &&& 16w0x1000: accept;
3232
default: noMatch;

0 commit comments

Comments
 (0)