Skip to content

Commit

Permalink
feat(cerisier): tweak UI
Browse files Browse the repository at this point in the history
  • Loading branch information
JuneRousseau committed Nov 3, 2024
1 parent ce44e1c commit ff40d14
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
38 changes: 25 additions & 13 deletions lib/interactive_ui.ml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ module MkUi (Cfg : MachineConfig) : Ui = struct

module Identity = struct
let width = 1 + int_of_float (floor @@ (log (float max_int) /. log 16.))
let ui ?(attr = A.empty) z = I.hsnap ~align:`Right width (I.string attr (Int.ui width z))
let ui ?(attr = A.empty) z = I.hsnap ~align:`Left width (I.string attr (Int.ui width z))
end

module ETable_panel = struct
Expand All @@ -215,14 +215,24 @@ module MkUi (Cfg : MachineConfig) : Ui = struct
<eid>: <identity>
*)
let ui width (etbl : Machine.e_table) =
(* let eid_width = EC_counter.width + 2 + Identity.width +2 in *)
let render_etbl enclaves =
List.fold_left
(fun img (eid, (id, _)) ->
img <-> (I.empty <|> EC_counter.ui eid <|> I.string A.empty ": " <|> Identity.ui id))
I.empty enclaves
let nenclaves = 20. in
(* Arbitrary number *)
let eid_width = EC_counter.width + 2 + Identity.width + 2 in
let ncols = max 1 (width / eid_width) in
let nregs_per_col = nenclaves /. float ncols |> ceil |> int_of_float in
let rec loop fst_col etable =
if etable = [] then I.empty
else
let col, etable = CCList.take_drop nregs_per_col etable in
List.fold_left
(fun img (eid, (id, _)) ->
img
<-> ((if not fst_col then I.string A.empty " " else I.empty)
<|> EC_counter.ui eid <|> I.string A.empty ": " <|> Identity.ui id))
I.empty col
<|> loop false etable
in
render_etbl (Machine.ETableMap.to_seq etbl |> List.of_seq) |> I.hsnap ~align:`Left width
loop true (Machine.ETableMap.to_seq etbl |> List.of_seq) |> I.hsnap ~align:`Left width
end

module Instr = struct
Expand Down Expand Up @@ -352,10 +362,9 @@ module MkUi (Cfg : MachineConfig) : Ui = struct
let start_stk = upd_stk stk height start_stk 2 in

let img_of_dataline = render_prog width pc (addr_show start_prog) in
(* let img_of_stack = *)
(* if show_stack then render_stack width stk (addr_show start_stk) else I.empty *)
(* in *)
let img_of_stack = if show_stack then I.empty else I.empty in
let img_of_stack =
if show_stack then render_stack width stk (addr_show start_stk) else I.empty
in

(img_of_dataline </> img_of_stack, start_prog, start_stk)
end
Expand Down Expand Up @@ -400,7 +409,10 @@ module MkUi (Cfg : MachineConfig) : Ui = struct
I.hsnap ~align:`Right term_width
(I.string A.empty "machine state: " <|> Exec_state.ui (fst m))
in
let img = regs_img <-> mach_state_img <-> etbl_img <-> mem_img in
let img =
I.string A.empty "REGFILE:" <-> regs_img <-> I.string A.empty "ETABLE:" <-> etbl_img
<-> mach_state_img <-> mem_img
in
Term.image term img;
(* watch for a relevant event *)
let rec process_events () =
Expand Down
8 changes: 4 additions & 4 deletions lib/pretty_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ let string_of_machine_op (s : machine_op) : string =
| LoadU (r1, r2, c) -> "loadU" ^- string_of_rrc r1 r2 c
| StoreU (r, c1, c2) -> "storeU" ^- string_of_rcc r c1 c2
| PromoteU r -> "promoteU" ^- string_of_regname r
| EInit (r1, r2) -> "EInit" ^- string_of_rr r1 r2
| EDeInit (r1, r2) -> "EDeInit" ^- string_of_rr r1 r2
| EStoreId (r1, r2, r3) -> "EStoreId" ^- string_of_rrr r1 r2 r3
| IsUnique (r1, r2) -> "IsUnique" ^- string_of_rr r1 r2
| EInit (r1, r2) -> "einit" ^- string_of_rr r1 r2
| EDeInit (r1, r2) -> "edeinit" ^- string_of_rr r1 r2
| EStoreId (r1, r2, r3) -> "estoreid" ^- string_of_rrr r1 r2 r3
| IsUnique (r1, r2) -> "isunique" ^- string_of_rr r1 r2
| Fail -> "fail"
| Halt -> "halt"

Expand Down

0 comments on commit ff40d14

Please sign in to comment.