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

asli :ast command for dumping semantics AST #2

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
23 changes: 15 additions & 8 deletions bin/asli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ let help_msg = [
{|:elf <file> Load an ELF file|};
{|:opcode <instr-set> <int> Decode and execute opcode|};
{|:sem <instr-set> <int> Decode and print opcode semantics|};
{|:ast <instr-set> <int> <file> Decode and write opcode semantics to a file, in a structured ast format|};
{|:project <file> Execute ASLi commands in <file>|};
{|:q :quit Exit the interpreter|};
{|:run Execute instructions|};
Expand Down Expand Up @@ -195,11 +196,17 @@ let rec process_command (tcenv: TC.Env.t) (cpu: Cpu.cpu) (fname: string) (input0
let op = Z.of_string opcode in
Printf.printf "Decoding instruction %s %s\n" iset (Z.format "%x" op);
cpu'.sem iset op
| [":ast"; iset; opcode] ->
let op = Value.VBits (Primops.prim_cvt_int_bits (Z.of_int 32) (Z.of_string opcode)) in
let decoder = Eval.Env.getDecoder cpu.env (Ident iset) in
List.iter
(fun s -> Printf.printf "%s\n" (Utils.to_string (PP.pp_raw_stmt s)))
(Dis.dis_decode_entry cpu.env cpu.denv decoder op);
| ":dump" :: iset :: opcode :: rest ->
let fname =
(match rest with
let fname =
(match rest with
| [] -> "sem.aslb"
| [x] -> x
| [x] -> x
| _ -> invalid_arg "expected at most 3 arguments to :dump")
in
let cpu' = Cpu.mkCPU (Eval.Env.copy cpu.env) cpu.denv in
Expand Down Expand Up @@ -320,15 +327,15 @@ let _ =

let main () =
if !opt_print_version then Printf.printf "%s\n" version
else if !opt_print_aarch64_dir then
match aarch64_asl_dir with
else if !opt_print_aarch64_dir then
match aarch64_asl_dir with
| Some d -> Printf.printf "%s\n" d
| None -> (Printf.eprintf "Unable to retrieve installed asl directory\n"; exit 1)
else begin
if !opt_verbose then List.iter print_endline banner;
if !opt_verbose then print_endline "\nType :? for help";
let env_opt =
if (!opt_no_default_aarch64)
if (!opt_no_default_aarch64)
then evaluation_environment !opt_prelude !opt_filenames !opt_verbose
else begin
if List.length (!opt_filenames) != 0 then
Expand All @@ -338,7 +345,7 @@ let main () =
else ();
aarch64_evaluation_environment ~verbose:!opt_verbose ();
end in
let env = (match env_opt with
let env = (match env_opt with
| Some e -> e
| None -> failwith "Unable to build evaluation environment.") in
if not !opt_no_default_aarch64 then
Expand All @@ -348,7 +355,7 @@ let main () =

LNoise.history_load ~filename:"asl_history" |> ignore;
LNoise.history_set ~max_length:100 |> ignore;

let denv = Dis.build_env env in
let prj_files = List.filter (fun f -> Utils.endswith f ".prj") !opt_filenames in
let tcenv = TC.Env.mkEnv TC.env0 and cpu = Cpu.mkCPU env denv in
Expand Down
7 changes: 3 additions & 4 deletions libASL/asl.ott
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,11 @@ stmts :: 'Stmts_' ::=

indented_block :: 'Block_' ::=
{{ phantom }} {{ ocaml stmt list }}
{{ pp-raw x = (nest 4 (lbracket
{{ pp-raw x = (nest 4 (lbrace
^^ hardline
^^ (separate hardline (List.map pp_raw_stmt x))))
^^ hardline
^^ rbracket
^^ rbrace
}}
{{ pp x = (nest 4 (lbrace
^^ hardline
Expand Down Expand Up @@ -630,8 +630,7 @@ s_elsif :: 'S_Elsif_' ::=

optional_else :: 'S_Else' ::=
{{ phantom }} {{ ocaml stmt list }}
{{ pp-raw x = match x with [] -> string ""
| ys -> string "(else " ^^ separate (string "\n") (List.map pp_raw_stmt ys) ^^ string ")" }}
{{ pp-raw x = pp_raw_indented_block x }}
{{ pp x = match x with [] -> string ""
| ys -> string "else {" ^^ hardline
^^ (nest 4 (separate (string "\n") (List.map pp_stmt ys @ [string "}"])))
Expand Down
Loading