From 7f3249fbf88943e7a69cca216dcc1b9abc610bcb Mon Sep 17 00:00:00 2001 From: rina Date: Fri, 9 Feb 2024 14:33:23 +1000 Subject: [PATCH] add :aslt command for writing raw semantics --- bin/asli.ml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bin/asli.ml b/bin/asli.ml index 75bbd807..d306b234 100644 --- a/bin/asli.ml +++ b/bin/asli.ml @@ -40,6 +40,7 @@ let help_msg = [ {|:elf Load an ELF file|}; {|:opcode Decode and execute opcode|}; {|:sem Decode and print opcode semantics|}; + {|:ast Decode and write opcode semantics to a file, in a structured ast format|}; {|:project Execute ASLi commands in |}; {|:q :quit Exit the interpreter|}; {|:run Execute instructions|}; @@ -195,6 +196,14 @@ 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; fname] -> + 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 + let chan = open_out fname in + List.iter + (fun s -> Printf.fprintf chan "%s\n" (Utils.to_string (PP.pp_raw_stmt s))) + (Dis.dis_decode_entry cpu.env cpu.denv decoder op); + close_out chan | ":dump" :: iset :: opcode :: rest -> let fname = (match rest with