oxidecomputer / p4

A P4 compiler
Mozilla Public License 2.0
112 stars 5 forks source link

Global `const` symbols not resolved within action/parser bodies #31

Open FelixMcFelix opened 1 year ago

FelixMcFelix commented 1 year ago

const symbols defined in the global scope do not seem to be usable for reads/writes within parser bodies or actions, as below:

const bit<16> GENEVE_OPT_CLASS_OXIDE = 16w0x0129;

control x (
    /* ... */
) {
    action y (
        inout headers_t hdr,
        /* ... */
    ) {
        hdr.ox_external_tag.class = GENEVE_OPT_CLASS_OXIDE;
    }

    /* ... */
}

This produces the following error message:

error: could not resolve lvalue: GENEVE_OPT_CLASS_OXIDE
    GENEVE_OPT_CLASS_OXIDE not found
[361:37] sidecar-lite.p4

          hdr.ox_external_tag.class = GENEVE_OPT_CLASS_OXIDE;
                                      ^^^^^^^^^^^^^^^^^^^^^^

From my testing, this also applies to use of constants within expressions in parser states.