Skip to content

Commit 681eb4c

Browse files
Preliminary sketch on importing top-level externs
1 parent eada832 commit 681eb4c

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

hol/p4_from_json/petr4_to_hol4p4Script.sml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3649,6 +3649,42 @@ Definition petr4_get_arch_block_pbls_def:
36493649
| NONE => NONE)
36503650
End
36513651

3652+
(*
3653+
{"tags":["missing_info",""]
3654+
"annotations":[]
3655+
"type":["specialized",
3656+
{"tags":["missing_info",""],
3657+
"base":["name",{"tags":["missing_info",""],
3658+
"name":["BareName",{"tags":["missing_info",""],
3659+
"name":{"tags":["missing_info",""],"string":"register"}}]}],
3660+
"args":[["bit",{"tags":["missing_info",""],
3661+
"expr":["int",
3662+
{"tags":["missing_info",""],
3663+
"x":{"tags":["missing_info",""],
3664+
"value":"16","width_signed":null}}]}]]}],
3665+
"args":[["Expression",{"tags":["missing_info",""],"value":["int",{"tags":["missing_info",""],"x":{"tags":["missing_info",""],"value":"1","width_signed":null}}]}]],
3666+
"name":{"tags":["missing_info",""],"string":"r"},
3667+
"init":null}
3668+
3669+
use petr4_parse_ptype on list under "args". Expect p_tau_bit n.
3670+
3671+
*)
3672+
3673+
Definition petr4_parse_register_def:
3674+
petr4_parse_register (tyenv, bltymap, ptymap) type name =
3675+
case petr4_parse_name name of
3676+
| SOME name_string =>
3677+
(case json_dest_arr type of
3678+
| SOME [type_str; spec_obj] =>
3679+
(case json_parse_obj ["tags"; "base"; "name"; "args"] spec_obj of
3680+
| SOME [tags; base; spec_name; args] =>
3681+
petr4_parse_ptype T tyenv args
3682+
| NONE => NONE)
3683+
| NONE => NONE
3684+
)
3685+
| NONE => NONE
3686+
End
3687+
36523688
(* TODO: This should also parse top-level instantiation of externs *)
36533689
Definition petr4_parse_top_level_inst_def:
36543690
petr4_parse_top_level_inst (tyenv, bltymap, ptymap) inst =
@@ -3669,7 +3705,15 @@ Definition petr4_parse_top_level_inst_def:
36693705
| NONE => get_error_msg "Could not parse top-level instantiation arguments: " (Array args))
36703706
| NONE => get_error_msg "Unknown package type: " type)
36713707
| SOME (p_tau_ext ext_name) =>
3672-
(get_error_msg "Top-level extern instantiations currently unsupported by HOL4P4: " inst)
3708+
(*
3709+
type -> args -> (parse blob as constant, gives width)
3710+
name -> string, (object name)
3711+
*)
3712+
(* TODO: Check arch also *)
3713+
if ext_name = "register"
3714+
then petr4_parse_register (tyenv, bltymap, ptymap) type name
3715+
else
3716+
(get_error_msg "Top-level extern instantiations currently unsupported by HOL4P4: " inst)
36733717
| _ => get_error_msg "Unknown type of top-level instantiation: " inst)
36743718
| NONE => get_error_msg "Could not parse type name (may be top-level extern instantiation): " type)
36753719
| _ => get_error_msg "Unknown JSON format of instantiation: " inst

0 commit comments

Comments
 (0)