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

Extracting Depedent functions #20

Merged
merged 2 commits into from
May 31, 2024
Merged
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
36 changes: 26 additions & 10 deletions src/sail_json_backend/json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ let operands = Hashtbl.create 997
let encodings = Hashtbl.create 997
let assembly = Hashtbl.create 997
let assembly_clean = Hashtbl.create 997
let executes = Hashtbl.create 997
let functions = Hashtbl.create 997
let op_functions = Hashtbl.create 997
let formats = Hashtbl.create 997
Expand Down Expand Up @@ -333,16 +334,22 @@ let extract_source_code l =
| None -> "Error - couldn't locate func"

let parse_funcl fcl = match fcl with
FCL_aux ( FCL_funcl ( Id_aux (Id "execute", _), Pat_aux ( (
Pat_exp ( P_aux ( P_app (i, pl), _ ) , e )
| Pat_when ( P_aux ( P_app (i, pl), _ ) , e, _ )
), _ ) ), _ ) ->
| FCL_aux (FCL_funcl (Id_aux (Id id, _), Pat_aux ( ( pat ) , _) ), _) ->
begin
debug_print ("FCL_funcl execute " ^ string_of_id i);
let operandl = (List.concat (List.map string_list_of_pat pl)) in
if not (String.equal (List.hd operandl) "()") then
Hashtbl.add operands (string_of_id i) operandl;
Hashtbl.add functions (string_of_id i) (extract_source_code (Ast_util.exp_loc e))
match pat with
| Pat_exp (P_aux (P_tuple pl, _), e)
| Pat_when (P_aux (P_tuple pl, _), e, _) ->
debug_print ("id_of_dependent: " ^ id);
let source_code = extract_source_code (Ast_util.exp_loc e) in
Hashtbl.add functions id source_code;
| Pat_exp (P_aux (P_app (i, pl), _), e)
| Pat_when (P_aux (P_app (i, pl), _), e, _) ->
debug_print ("FCL_funcl execute " ^ string_of_id i);
let operandl = List.concat (List.map string_list_of_pat pl) in
if not (String.equal (List.hd operandl) "()") then
Hashtbl.add operands (string_of_id i) operandl;
Hashtbl.add executes (string_of_id i) (extract_source_code (Ast_util.exp_loc e))
| _ -> ();
end
| _ -> debug_print "FCL_funcl other"

Expand Down Expand Up @@ -584,7 +591,7 @@ let json_of_fields k =
| Some (fields) -> String.concat ", " (List.map (fun f -> json_of_field k f) fields)

let json_of_function k =
let fspec = match Hashtbl.find_opt functions k with
let fspec = match Hashtbl.find_opt executes k with
None -> ""
| Some (f) -> String.escaped f
in "\"" ^ fspec ^ "\""
Expand Down Expand Up @@ -705,6 +712,8 @@ let defs { defs; _ } =
Hashtbl.iter (fun k v -> debug_print (k ^ ":" ^ Util.string_of_list ", " (fun x -> x) v)) encodings;
debug_print "ASSEMBLY";
Hashtbl.iter (fun k v -> debug_print (k ^ ":" ^ Util.string_of_list ", " (fun x -> x) v)) assembly;
debug_print "EXECUTES";
Hashtbl.iter (fun k v -> debug_print (k ^ ":" ^ v)) executes;
debug_print "FUNCTIONS";
Hashtbl.iter (fun k v -> debug_print (k ^ ":" ^ v)) functions;
debug_print "OP_FUNCTIONS";
Expand Down Expand Up @@ -747,5 +756,12 @@ let defs { defs; _ } =
print_endline " \"extensions\": [";
let extension_list = Hashtbl.fold (fun k v accum -> v :: accum) extensions [] in
print_endline (String.concat ",\n" (List.sort_uniq String.compare (List.concat extension_list)));
print_endline " ],";

print_endline " \"functions\": [";
Hashtbl.iter (fun name source ->
print_endline (" {\n \"name\": \"" ^ name ^ "\",");
print_endline (" \"source\": \"" ^ String.escaped source ^ "\"\n },")
) functions;
print_endline " ]";
print_endline "}";
Loading