Skip to content

Commit b52f368

Browse files
Variable-length bit string operations in Ott
1 parent bc2786a commit b52f368

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

ott/p4.ott

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ bitv :: bitv_ ::=
9393
| bl n :: M :: bl
9494
{{ hol ([[bl]], [[n]]) }}
9595

96+
varbitv :: varbitv_ ::=
97+
{{ hol (bl # num # num) }}
98+
{{ com variable-width bit-string }}
99+
| bl n n' :: M :: vbl
100+
{{ hol ([[bl]], [[n]], [[n']]) }}
101+
96102
%Fence so that ott does not put packet_in before boolv
97103
embed
98104
{{ hol
@@ -106,6 +112,8 @@ v :: v_ ::=
106112
{{ com boolean value }}
107113
| bitv :: :: bit
108114
{{ com bit-string }}
115+
| varbitv :: :: varbit
116+
{{ com variable-width bit-string }}
109117
| x :: :: str
110118
{{ com string literal }}
111119
| struct { x1 = v1 ; ... ; xn = vn } :: :: struct
@@ -506,7 +514,10 @@ tau {{ tex \tau }} :: tau_ ::=
506514
{{ com boolean }}
507515
| bs num_exp :: :: bit
508516
{{ com bit-string }}
509-
{{ tex { { \mathbf{bs} }^{[[num_exp]]} } }}
517+
{{ tex { { \mathbf{bs} }^{[[num_exp]]} } }}
518+
| vbs num_exp num_exp' :: :: varbit
519+
{{ com variable-width bit-string }}
520+
{{ tex { { \mathbf{vbs} }^{[[num_exp]], [[num_exp']]} } }}
510521
| bot :: :: bot
511522
{{ com no value }}
512523
{{ tex \bot}}

ott/p4_sem.ott

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ formula :: formula_ ::=
147147
%TODO: Unify the below eq_ to equality over values?
148148
| bitv EQ bitv' = b :: M :: eq_word
149149
{{ hol (([[bitv]] = [[bitv']]) <=> [[b]]) }}
150+
| varbitv EQ varbitv' = b :: M :: eq_varword
151+
{{ hol (([[varbitv]] = [[varbitv']]) <=> [[b]]) }}
150152
| b EQ b' = b'' :: M :: eq_bool
151153
{{ hol ([[b]] = [[b']] <=> [[b'']]) }}
152154
| ( x EQ x' ) = b :: M :: eq_error
@@ -1938,15 +1940,33 @@ val copyin_def = Define `
19381940
* in the topmost scope where a is defined,
19391941
* written as ε[a -> v], colloquially known as assignment.
19401942
* Note that this function is used in the assignment and return rules *)
1943+
(* TODO: This does ridiculous duplication of work... *)
1944+
(* TODO: Varbit assignment was hacked into this, it could just as well be a separate rule *)
19411945
val assign_def = Define `
19421946
(assign ss v (lval_varname x) =
1943-
case find_topmost_map ss x of
1944-
| SOME (i, sc) =>
1945-
(case lookup_out ss x of
1946-
| SOME str_opt =>
1947-
SOME (LUPDATE (AUPDATE sc (x, (v, str_opt))) (i) ss)
1948-
| NONE => NONE)
1949-
| _ => NONE) /\
1947+
(case v of
1948+
| (v_varbit (bl, n, n_max)) =>
1949+
(case lookup_lval ss (lval_varname x) of
1950+
| SOME (v_varbit (bl', n', n_max')) =>
1951+
if n_max = n_max'
1952+
then
1953+
(case find_topmost_map ss x of
1954+
| SOME (i, sc) =>
1955+
(case lookup_out ss x of
1956+
| SOME str_opt =>
1957+
SOME (LUPDATE (AUPDATE sc (x, ((v_varbit (bl, n, n_max)), str_opt))) (i) ss)
1958+
| NONE => NONE)
1959+
| _ => NONE)
1960+
else NONE
1961+
| _ => NONE)
1962+
| _ =>
1963+
(case find_topmost_map ss x of
1964+
| SOME (i, sc) =>
1965+
(case lookup_out ss x of
1966+
| SOME str_opt =>
1967+
SOME (LUPDATE (AUPDATE sc (x, (v, str_opt))) (i) ss)
1968+
| NONE => NONE)
1969+
| _ => NONE))) /\
19501970
(assign ss v (lval_field lval f) =
19511971
case lookup_lval ss lval of
19521972
| SOME (v_struct f_v_l) =>
@@ -2591,6 +2611,10 @@ b EQ b' = b''
25912611
----------------------------------- :: eq_bool
25922612
ctx g_scope_list scope_list ( b EQ b' ) ~> ( b'' , empty )
25932613

2614+
varbitv EQ varbitv' = b
2615+
----------------------------------- :: eq_varbit
2616+
ctx g_scope_list scope_list ( varbitv EQ varbitv' ) ~> ( b , empty )
2617+
25942618

25952619
%%%%%%%%%%%%%
25962620
%Bitwise and

0 commit comments

Comments
 (0)