Skip to content

Commit

Permalink
Merge branch 'main' into dsl+artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
polybeandip committed Aug 17, 2024
2 parents 669f17b + 5f5c77e commit d4f3e98
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 13 deletions.
27 changes: 14 additions & 13 deletions dsl/frontend/policy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,41 @@ type t =

exception UnboundVariable of Ast.var
exception UndeclaredClass of Ast.clss
exception DuplicateClass of Ast.clss

let lookup s x =
match List.assoc_opt x s with
| Some v -> v
| None -> raise (UnboundVariable x)

let rec sub cl st (p : Ast.policy) =
(* Helper function that evaluates a policy list. *)
let sub_plst cl st = List.map (sub cl st) in

(* Helper function that evaluates a weighted policy list. *)
let sub_weighted_plst cl st = List.map (fun (x, i) -> (sub cl st x, i)) in
let rec sub cl st (p : Ast.policy) used =
let sub_plst cl st = List.map (fun x -> sub cl st x used) in
let sub_weighted_plst cl st =
List.map (fun (x, i) -> (sub cl st x used, i))
in

match p with
| Class c -> if List.mem c cl then Class c else raise (UndeclaredClass c)
| Var x -> sub cl st (lookup st x)
| Class c ->
if List.mem c !used then raise (DuplicateClass c)
else if List.mem c cl then (
used := c :: !used;
(Class c : t))
else raise (UndeclaredClass c)
| Var x -> sub cl st (lookup st x) used
| Fifo plst -> Fifo (sub_plst cl st plst)
| RoundRobin plst -> RoundRobin (sub_plst cl st plst)
| Strict plst -> Strict (sub_plst cl st plst)
| WeightedFair wplst -> WeightedFair (sub_weighted_plst cl st wplst)
| _ -> failwith "ERROR: unsupported policy"

(* Look up any variables and substitute them in. *)
let of_program (cl, alst, ret) = sub cl alst ret
let of_program (cl, alst, ret) : t = sub cl alst ret (ref [])

let rec to_string p =
let sprintf = Printf.sprintf in

(* Helper function to compactly join policy lists by comma *)
let join lst =
sprintf "[%s]" (lst |> List.map to_string |> String.concat ", ")
in

(* Helper function to compactly join weighted policy lists by comma *)
let join_weighted lst =
sprintf "[%s]"
(lst
Expand Down
1 change: 1 addition & 0 deletions dsl/frontend/policy.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type t =

exception UnboundVariable of Ast.var
exception UndeclaredClass of Ast.clss
exception DuplicateClass of Ast.clss

val of_program : Ast.program -> t
val to_string : t -> string
4 changes: 4 additions & 0 deletions dsl/tests/parsing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ let error_tests =
make_error_test "unbound var in middle of list of assignments"
"progs/incorrect/unbound_var_hier.sched"
(Policy.UnboundVariable "r_polic");
make_error_test "class used twice in policy"
"progs/incorrect/duplicate_classes.sched" (Policy.DuplicateClass "B");
make_error_test "class used twice in one fifo"
"progs/incorrect/duplicate_samepol.sched" (Policy.DuplicateClass "A");
]

let suite = "parsing tests" >::: wc_tests @ error_tests (* @ nwc_tests *)
Expand Down
6 changes: 6 additions & 0 deletions progs/incorrect/duplicate_classes.sched
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
classes A, B;

var = rr[A, B];
final = fifo[var, B]; // B is used twice

return final
5 changes: 5 additions & 0 deletions progs/incorrect/duplicate_samepol.sched
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
classes A, B;

x = fifo[A, A];

return x
7 changes: 7 additions & 0 deletions progs/incorrect/unused_variable.sched
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
classes A, B, C;

pol_1 = rr[A, B];
pol_2 = rr[B, C];
ans = strict[pol_1, C];

return ans
Binary file added talks/packet_sched_calyx_plenary.key
Binary file not shown.
Binary file added talks/packet_sched_calyx_plenary.pdf
Binary file not shown.

0 comments on commit d4f3e98

Please sign in to comment.