Commit Graph

69 Commits

Author SHA1 Message Date
Will Hawkins 97a672bd6d compiler: Type Check All Binary Operators
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-22 20:42:35 -04:00
Will Hawkins bc51b4e280 compiler: Reworked Preprocessor To Support Better Error Messages
Can now support showing the trail of includes in an error
message.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-22 20:41:43 -04:00
Will Hawkins 041009a22e compiler: Track/Report Relative Paths Names
Continuous Integration / Grammar Tests (push) Successful in 37s
Continuous Integration / Library Format Tests (push) Successful in 1m22s
Continuous Integration / Library Tests (push) Successful in 4m23s
When the user gives relative path names for p4 files, report
those in error messages (etc.). The SourceManager can/does
resolve those to absolute path names.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-22 04:27:37 -04:00
Will Hawkins e53c32f802 compiler, cli: Support Nice Compilation Error Messages
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-22 02:38:47 -04:00
Will Hawkins 5845cb75cc testing: Test For Controls Using Keys From Structs
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-22 02:35:34 -04:00
Will Hawkins 24b0f0284a language: Check For Incorrect Order For Action Parameters
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-22 02:34:51 -04:00
Will Hawkins a1908cc077 Make Formatter Happy
Continuous Integration / Library Tests (push) Successful in 4m8s
Continuous Integration / Grammar Tests (push) Successful in 36s
Continuous Integration / Library Format Tests (push) Failing after 1m12s
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-22 00:27:17 -04:00
Will Hawkins d60465e669 testing: Update CliTest Support.
And add tests for Cli preprocessing.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-21 22:41:00 -04:00
Will Hawkins 7a2c55cc51 testing: Implement Macros For Cli Testing
Continuous Integration / Grammar Tests (push) Successful in 4m5s
Continuous Integration / Library Tests (push) Failing after 8m19s
Continuous Integration / Cli Tests (push) Successful in 6m36s
Continuous Integration / Library Format Tests (push) Successful in 5m0s
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-20 17:53:31 -04:00
Will Hawkins a7d8fd1304 grammar,compiler: Add Support For Fixed-Width Integers
Continuous Integration / Grammar Tests (push) Successful in 4m13s
Continuous Integration / Library Format Tests (push) Successful in 5m17s
Continuous Integration / Library Tests (push) Failing after 8m34s
Continuous Integration / Cli Tests (push) Failing after 4m40s
Distinguishing between signed and unsigned fixed-width integer
types must still be done.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-18 06:53:22 -04:00
Will Hawkins 12fa43d9f9 common, codegen: Implement Visitor And Use For CodeGen
Continuous Integration / Grammar Tests (push) Successful in 4m6s
Continuous Integration / Library Format Tests (push) Successful in 5m5s
Continuous Integration / Library Tests (push) Successful in 9m0s
Continuous Integration / Cli Tests (push) Successful in 4m57s
Implement a generic visitor for components of a P4 program and use
it to start P4 code generation (according to the behavioral model).

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-15 08:14:24 -04:00
Will Hawkins 73b4f54bbe Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-11 07:37:23 -04:00
Will Hawkins 0e2b13be93 compiler: Support Querying For Files In Preprocessed Code
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-11 07:37:23 -04:00
Will Hawkins f0f7a660a6 compiler: Add Ability to Annotate Preprocessed Source
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-11 07:37:18 -04:00
Will Hawkins d28ccd79e4 common, compiler: Upgrade to SystemPackage
Continuous Integration / Grammar Tests (push) Successful in 35s
Continuous Integration / Library Format Tests (push) Successful in 1m16s
Continuous Integration / Library Tests (push) Successful in 4m11s
For cross-platform support.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-07 23:43:29 -04:00
Will Hawkins 754102d601 compiler: Add Preprocessor Support
TODO: Test that file names are properly tracked in included
files.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-07 23:06:41 -04:00
Will Hawkins 7a36ca32dd compiler, runtime: Support Formatted Error Messages
Make it possible to output formatted error messages using a
flexible API that includes an ability to specify styles and
formatters.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 22:24:28 -04:00
Will Hawkins 73779d8074 common, testing: Add Formatting of Error Messages
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 11:30:05 -04:00
Will Hawkins 168d48fa7c compiler, runtime: Refactor Errors
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 10:34:07 -04:00
Will Hawkins b49ec104e9 compiler, runtime: Make Default Values Optional
For types, make it optional to return a default value. While default
values for some types are meaningful, they are not meaningful for all
types (e.g., Action, Control, Parser, Parser state, etc.).

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 08:35:33 -04:00
Will Hawkins 5cfe5532a2 compiler, runtime: Refactor P4DataType to P4Type
Now that the old P4Type is a P4QualifiedType, it makes sense to
rename the data type back to just type.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 07:37:48 -04:00
Will Hawkins 7c660b2b0c compiler, runtime: Refactor P4Type to P4QualifiedType
Also, refer to the different pieces of the qualified type as
qualifiers and not attributes.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 07:29:51 -04:00
Will Hawkins ed976c7855 compiler, runtime: Initial Support For Calling Controls
Support calling (invoking) a Control. There is still plenty more to
do here, but we are off to a good start.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-30 18:39:52 -04:00
Will Hawkins bd262e5b73 runtime: Parameterize Runtime
Parameterize Runtime (nee ParserRuntime) so that it can run anything
that is LibraryCallable. TODO: Refactor its API -- left mostly as
it was because changing unit tests will be laborious.
2026-04-30 18:37:21 -04:00
Will Hawkins b97aa1af72 parser, compiler: Support Table Actions
Continuous Integration / Grammar Tests (push) Has been cancelled
Continuous Integration / Library Tests (push) Has been cancelled
Continuous Integration / Library Format Tests (push) Has been cancelled
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-30 05:38:29 -04:00
Will Hawkins 0f0662709e compiler, testing: Build System for Compilation
The compilation code was written as a precursor for implementation
with macros. The updates in this commit make the switch.

There is still plenty to do:

1. Comment Walker.
2. Comment Macros.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-27 08:39:40 -04:00
Will Hawkins f2bd53ce5f compiler, runtime, common: (Initial) Support For extern Declarations
Especially FFI

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-23 06:07:54 -04:00
Will Hawkins a24571222b runtime: Refactor Expression/Statement Evaluators
Allow the user to customize the evaluation/execution of expressions/
statements with something that implements functions that perform
those tasks. This additional functionality will make it possible for
the "classic" evaluator not to waste time checking for the presence
of interlopers and give implementers additional customization opportunities.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 16:28:07 -04:00
Will Hawkins d33066c543 compiler, runtime, testing, common: Centralize Execution/Evaluation
Centralize the execution of statements and evaluation of expressions
so that the user can specify a debugging "callback" after every
execution/evaluation.

The callback can be used for myriad things, but it seems likely that
it will be useful for implementing:
1. Testing
2. Debugger

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 05:53:43 -04:00
Will Hawkins c6f086f67f compiler, runtime: Control Declarations Have Apply Statements
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 03:35:55 -04:00
Will Hawkins 5bc9db9aca compiler, common, testing: Support For Checking For Invalid Statements
Add support functions to check whether a (block of) statement(s) contains
any statements that should not appear in that block (e.g., switch in
an action).

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 03:25:58 -04:00
Will Hawkins 82c125e4d1 compiler, runtime, common: Support (in)out Parameters
When a function is called, if there is an (in)out parameter,
make sure that updated values are propogated to the calling
function.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-16 06:58:45 -04:00
Will Hawkins 94086c8e17 compiler, runtime, common, documentation: Refactor Type System
The type system (and the value system) now include attributes
for each type (things like direction, const-ness).

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-14 20:25:11 -04:00
Will Hawkins 35b2537754 compiler, runtime, common, testing: Support Directions on Parameters and Attributed Types
Add support for directions on parameters and attributed types. The
latter is necessary to support the former, but is not limited to
the direction use case. An attributed type is a P4 type with attributes
(like its direction, whether it is read only, etc.) Other attributes
will be added in the future.

Changes necessary to support attributed types include:
1. Global instances tracked during compilation are not attributed
types and not simply types.
2. (future) Type checking will have to make sure that a types
attributes do not affect type compatibility.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-13 06:25:08 -04:00
Will Hawkins b687454389 Refactor Expected Types During Compilation
By adding an expected type to the compilation context, it is
now possible for type checking to occur on keyset expressions
and return statements at the moment that they are being compiled.

Previously, it was necessary to tentatively compile them and then
typecheck afterward.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-10 00:59:11 -04:00
Will Hawkins d39127ac17 Support Function Calls
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-09 23:16:27 -04:00
Will Hawkins 29dfa62472 Start Handling Control Blocks
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-06 08:49:28 -04:00
Will Hawkins 443b21b890 Initial Work on Compiling Function Declarations
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-02 02:49:04 -04:00
Will Hawkins 07f1943611 Fix Warnings In Tests
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-02 01:30:33 -04:00
Will Hawkins d971aab1fe Support Calling Parsers With Parameters
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-02 01:28:43 -04:00
Will Hawkins 8962235aca Support Parameters For Parsers
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-30 07:57:41 -04:00
Will Hawkins 744c375c5f Add Select Expression Ordering Test
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-30 05:18:36 -04:00
Will Hawkins 3b9c3a7076 Add Select Expression Tests
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-30 05:18:00 -04:00
Will Hawkins 7c9ecc2438 Refactor Parser States
Refactor the class hierarchy for parser states so that
there is a parser state that acts more like a type and
one that acts more like a value (the latter, then, serves
as the base class for the other instantiated parser states).

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-30 05:16:48 -04:00
Will Hawkins 4d787394cd Fix Bug In Struct Field Initialization
Fields were not given default values when a struct was declared
without initializers.

Also, cleanup code in the helper function for binary operations
on struct instances.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-27 03:54:44 -04:00
Will Hawkins cd26d1d22c Parse Struct Declarations
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-27 03:33:15 -04:00
Will Hawkins 99804e3053 Better Support For Keysets
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-27 01:36:38 -04:00
Will Hawkins fafc80553e Support Binary Math Operators
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-26 23:48:39 -04:00
Will Hawkins 0d1a0b11df Add Binary Operator and Grouping (in Expressions) Tests
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-23 07:55:37 -04:00
Will Hawkins aac007f1f2 Allow Declaring Instances of Structs
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-20 04:29:44 -04:00