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

Add mnemonic mapping for pseudoinstructions #45

Draft
wants to merge 12 commits into
base: json
Choose a base branch
from
46 changes: 44 additions & 2 deletions src/sail_json_backend/json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ let formats = Hashtbl.create 997
let extensions = Hashtbl.create 997
let mappings = Hashtbl.create 997
let registers = Hashtbl.create 997
let base_instructions = Hashtbl.create 997

let debug_print ?(printer = prerr_endline) message = if debug_enabled then printer message else ()

Expand Down Expand Up @@ -433,10 +434,51 @@ let parse_funcl fcl =
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, _) ->
| 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 source_code = extract_source_code (Ast_util.exp_loc e) in
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this line down to just above Hashtbl.add executes below, since it's not used in the pseudo_of processing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThinkOpenly, I intended for the line you're suggesting to move to be part of pseudo_of processing. My thought process is that pat matches similar patterns with different id values: pseudo_of, execute, and pseudo_execute. That's why I nested the id matches within the pat match. Do you think this approach is flawed?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure we're talking about the same line, I was referring to:

  let source_code = extract_source_code (Ast_util.exp_loc e) in

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aah, okay... I had the wrong line. We're on the same page now : )

Hashtbl.add executes (string_of_id i) source_code
match id with
| "pseudo_of" -> (
debug_print ("FCL funcl pseudoinstruction " ^ string_of_id i);
match e with
| E_aux (E_list exp_list, _) ->
debug_print ("Exp el: " ^ String.concat ", " (List.map string_of_exp exp_list));
List.iter
(fun exp ->
match exp with
| E_aux (E_app (id, el), _) ->
List.iter
(fun inner_exp ->
match inner_exp with
| E_aux (E_app (id_inner, el_inner), _) ->
List.iteri
(fun index inner_value ->
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need List.iteri here? I don't see a use of index below.

match inner_value with
| E_aux (E_tuple tuple_list, _) ->
let args_inner_list = List.map string_of_exp tuple_list in
debug_print
("Adding to hashtable with key: " ^ string_of_id i ^ ", id_inner: "
^ string_of_id id_inner ^ ", args_inner_list: ["
^ String.concat ", " args_inner_list ^ "]"
);
Hashtbl.add base_instructions (string_of_id i)
(string_of_id id_inner, args_inner_list)
| _ -> ()
)
el_inner
| _ -> ()
)
el
| _ -> ()
)
exp_list
| _ -> ()
)
| "execute" | "pseudo_execute" ->
debug_print ("FCL_funcl execute " ^ string_of_id i);
Hashtbl.add executes (string_of_id i) source_code
| _ -> ()
)
| _ -> ()
end
| _ -> debug_print "FCL_funcl other"
Expand Down