Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

another parser bug #140

Closed
jnfoster opened this issue Nov 8, 2016 · 1 comment
Closed

another parser bug #140

jnfoster opened this issue Nov 8, 2016 · 1 comment

Comments

@jnfoster
Copy link
Contributor

jnfoster commented Nov 8, 2016

Compiling the following program,

#include <v1model.p4>

struct h { }

struct m { }

parser MyParser(packet_in b, out h hdr, inout m meta, inout standard_metadata_t std) {
  bit<16> counter;
  state start {
    counter = 0;
    transition accept;
  }
}

control MyVerifyChecksum(in h hdr, inout m meta) {
  apply {}
}
control MyIngress(inout h hdr, inout m meta, inout standard_metadata_t std) {
  apply { }
}
control MyEgress(inout h hdr, inout m meta, inout standard_metadata_t std) {
  apply { }
}

control MyComputeChecksum(inout h hdr, inout m meta) {
  apply {}
}
control MyDeparser(packet_out b, in h hdr) {
  apply { }
}

V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main;

produces an error:

vagrant@vagrant-ubuntu-trusty-64:~$ p4test --p4-16 min.p4
min.p4(10):syntax error, unexpected '='
    counter =
            ^
error: 1 errors encountered, aborting compilation

But if I rename the local variable counter to something else, it works fine:

#include <v1model.p4>

struct h { }

struct m { }

parser MyParser(packet_in b, out h hdr, inout m meta, inout standard_metadata_t std) {
  bit<16> i;
  state start {
    i = 0;
    transition accept;
  }
}

control MyVerifyChecksum(in h hdr, inout m meta) {
  apply {}
}
control MyIngress(inout h hdr, inout m meta, inout standard_metadata_t std) {
  apply { }
}
control MyEgress(inout h hdr, inout m meta, inout standard_metadata_t std) {
  apply { }
}

control MyComputeChecksum(inout h hdr, inout m meta) {
  apply {}
}
control MyDeparser(packet_out b, in h hdr) {
  apply { }
}

V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main;

Should the parser update structure when a new variable is declared? It currently doesn't:

variableDeclaration
    : annotations typeRef name optInitializer ';'
                                     { auto ann = new IR::Annotations(@1, $1);
                                       $$ = new IR::Declaration_Variable(@1+@4, *$3, ann, $2, $4); }
    | typeRef name optInitializer ';'
                                     { $$ = new IR::Declaration_Variable(
                                         @1+@4, *$2, IR::Annotations::empty, $1, $3);}
    ;
@jnfoster
Copy link
Contributor Author

Looks good to me. Closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant