Skip to content

Commit

Permalink
fix lookahead byte order issue (p4lang#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanw authored May 8, 2017
1 parent 79ead8c commit 8f355cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions midend/expandLookahead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ const IR::Expression* DoExpandLookahead::expand(
} else if (type->is<IR::Type_Bits>() || type->is<IR::Type_Boolean>()) {
unsigned size = type->width_bits();
BUG_CHECK(size > 0, "%1%: unexpected size %2%", type, size);
auto expression = new IR::Slice(base->clone(), *offset + size - 1, *offset);
*offset += size;
auto expression = new IR::Slice(base->clone(), *offset - 1, *offset - size);
*offset -= size;
return expression;
} else {
::error("%1%: unexpected type in lookahead argument", type);
Expand Down Expand Up @@ -104,7 +104,7 @@ const IR::Node* DoExpandLookahead::postorder(IR::AssignmentStatement* statement)
auto lookupCall = new IR::AssignmentStatement(statement->srcInfo, pathe, mc);
result->push_back(lookupCall);

unsigned offset = 0;
unsigned offset = width;
expandSetValid(statement->left->clone(), typearg, &result->components);
auto init = expand(pathe->clone(), typearg, &offset);
if (init == nullptr)
Expand Down
6 changes: 3 additions & 3 deletions testdata/p4_16_samples_outputs/issue355-bmv2-midend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ parser parserI(packet_in pkt, out H hdr, inout M meta, inout standard_metadata_t
state start {
tmp = pkt.lookahead<bit<112>>();
tmp_0.setValid();
tmp_0.dstAddr = tmp[47:0];
tmp_0.srcAddr = tmp[95:48];
tmp_0.etherType = tmp[111:96];
tmp_0.dstAddr = tmp[111:64];
tmp_0.srcAddr = tmp[63:16];
tmp_0.etherType = tmp[15:0];
transition select(tmp_0.etherType) {
16w0x1000 &&& 16w0x1000: accept;
default: noMatch;
Expand Down

0 comments on commit 8f355cd

Please sign in to comment.