p4lang / pna

Portable NIC Architecture
Apache License 2.0
54 stars 21 forks source link

How to pass an extern object instance of type X as a parameter to a method call that is a method of type X #124

Open jafingerhut opened 9 months ago

jafingerhut commented 9 months ago

See the example program attached to this comment: https://github.com/p4lang/p4-spec/issues/1262#issuecomment-1775914075

jafingerhut commented 9 months ago

This is related to a question raised by Mahesh Shirshyad's proposal for a PNA IP checksum extern object that could have a method, perhaps called something like add_dependency, where you could have multiple instance of the IP checksum extern object, and make explicit method calls in the P4 source code that declared data dependencies between these objects, e.g. you could do something like this:

    PNA_IPChecksum c1();
    PNA_IPChecksum c2();

    apply {

        // other code here to set up parameters for c1 and c2, e.g. perhaps start offset and length parameters.

        // in the case that the checksum for c1 included the result of checksum calculation for c2 as part of c1's input data
        // we would like to tell the compiler explicitly in code that this was the case, perhaps with a call like this:
        c1.add_dependency(c2);
        // meaning that c2's result should be calculated first, before c1's checksum calculation could finish.

    }