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
11 changes: 10 additions & 1 deletion src/sail_json_backend/json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,16 @@ let parse_funcl fcl =
end
| _ -> debug_print "FCL_funcl other"

let map_arg_to_mnemonic arg id = None
let map_arg_to_mnemonic arg id =
List.find_map
(fun (enum, mnemonic) ->
if List.hd enum = arg then (
debug_print ("Matched " ^ List.hd enum ^ " with mnemonic: " ^ List.hd mnemonic);
Some (List.hd mnemonic)
)
else None
)
(Hashtbl.find_all mappings (String.lowercase_ascii (id ^ "_mnemonic")))
Copy link
Owner

Choose a reason for hiding this comment

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

This is relying on a convention used to identify mappings for mnemonics in the Sail code. Since this is not guaranteed, please add a comment indicating assumptions you are making here.

Also, I see similar conventions which likely violate the assumptions, like:

mapping f_madd_type_mnemonic_D : f_madd_op_D <-> string = {
    FMADD_D  <-> "fmadd.d",
    FMSUB_D  <-> "fmsub.d",
    FNMSUB_D <-> "fnmsub.d",
    FNMADD_D <-> "fnmadd.d"
}

Would it work to use all entries in the "mappings" table?

Copy link
Author

Choose a reason for hiding this comment

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

Decided to go the all entries route for this


let get_index elem lst =
List.find_map (fun (i, x) -> if x = elem then Some i else None) (List.mapi (fun i x -> (i, x)) lst)
Expand Down
Loading