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

preproc define #18

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
**/.DS_Store
**/.DS_Store
grammar.js
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ time = "0.3.20"
tokio = { version = "1.28.2", features = ["full"] }
tower-lsp = "0.19.0"
tree-sitter = "0.20.9"
tree-sitter-p4 = {git = "https://github.com/ace-design/tree-sitter-p4"}
tree-sitter-p4 = { git = "https://github.com/ace-design/tree-sitter-p4" }
# { git = "https://github.com/ace-design/tree-sitter-p4"}
# { path = "/home/mc/Documents/tree-sitter-p4" }
31 changes: 28 additions & 3 deletions examples/basic.p4
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
/* -*- P4_16 -*- */
#include <core.p4>
#include <v1model.p4>
#include "v1model.p4"

const bit<16> TYPE_IPV4 = 0x800;

/*************************************************************************
*********************** H E A D E R S ***********************************
*************************************************************************/

typedef bit<9> egressSpec_t;
#define KEY 12
#define KEY4 ( 12 / 2 + 3*(3-4*5+4)-3+KEY + TYPE_IPV4(KEY,KEY))
#define KEY1 ("aaa")
#define KEY0 (0)
#define KEY2 (u8'afdsfds')
#define KEY3

typedef bit<48> macAddr_t;
typedef bit<32> ip4Addr_t;
typedef bit<KEY> egressSpec_t;
typedef bit<KEY0> ip4Addr_t;

header ethernet_t {
macAddr_t dstAddr;
Expand All @@ -31,6 +38,7 @@ header ipv4_t {
bit<16> hdrChecksum;
ip4Addr_t srcAddr;
ip4Addr_t dstAddr;
#define KEY23 12
}

struct metadata {
Expand All @@ -49,11 +57,13 @@ struct headers {
parser MyParser(packet_in packet,
out headers hdr,
inout metadata meta,
#define KEY4
inout standard_metadata_t standard_metadata) {
bit<16> test = TYPE_IPV4;
egressSpec_t test2 = 1;
bit<16> test3 = 0x80;
bit<16> test4 = 0x50;
#define KEY64

state start {
transition parse_ethernet;
Expand All @@ -63,6 +73,7 @@ parser MyParser(packet_in packet,
packet.extract(hdr.ethernet);
transition select(hdr.ethernet.etherType) {
TYPE_IPV4: parse_ipv4;
#define KEY641
default: accept;
}
}
Expand All @@ -81,7 +92,17 @@ parser MyParser(packet_in packet,
control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
apply { }
}
// expand key decrypt
#define get_exp_key(ROUND) action get_exp_key_r##ROUND##(){ \
t0_inv = meta.aes.expandkey_r##ROUND##[127:96]; \
t1_inv = meta.aes.expandkey_r##ROUND##[95:64]; \
t2_inv = meta.aes.expandkey_r##ROUND##[63:32]; \
t3_inv = meta.aes.expandkey_r##ROUND##[31:0]; \
}

#define dsgdsgsd 24

#define afsfds

/*************************************************************************
************** I N G R E S S P R O C E S S I N G *******************
Expand Down Expand Up @@ -111,10 +132,12 @@ control MyIngress(inout headers hdr,
key = {
hdr.ipv4.dstAddr: lpm;
}
#define KEY64
actions = {
ipv4_forward;
drop;
NoAction;
#define KEY64
}
size = 1024;
default_action = drop();
Expand Down Expand Up @@ -181,6 +204,8 @@ MyParser(),
MyVerifyChecksum(),
MyIngress(),
MyEgress(),

#define KEY64
MyComputeChecksum(),
MyDeparser()
) main;
Loading