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

Scala backend & lifter-optimiser bdd copyprop #102

Merged
merged 53 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d1d981c
Add scala backend for BASIL
ailrst Apr 2, 2024
55cab3c
Add lifttime PC variable
ncough Apr 5, 2024
66e5df5
Remove problematic list, add missing variables
ncough Apr 5, 2024
1f0cf05
Optional pass to remove unsupported globals
ncough Apr 5, 2024
badae88
Whitespace in transforms
ncough Apr 5, 2024
4a45e3b
Re-enable case simp for offline
ncough Apr 8, 2024
943b598
Decoder cleanup and sanity checks
ncough Apr 8, 2024
256213d
Simplify reachability based on enc
ncough Apr 22, 2024
9b78682
Add lifttime PC variable
ncough Apr 5, 2024
6d41bd0
Remove problematic list, add missing variables
ncough Apr 5, 2024
d9fac78
Optional pass to remove unsupported globals
ncough Apr 5, 2024
529e4d6
Whitespace in transforms
ncough Apr 5, 2024
1b1e68c
Re-enable case simp for offline
ncough Apr 8, 2024
a6f0cf5
Decoder cleanup and sanity checks
ncough Apr 8, 2024
c9d28d0
Simplify reachability based on enc
ncough Apr 22, 2024
2257e8d
wip rt copyprop
ailrst May 3, 2024
4cbba1f
use bdd lattice for clobbered & read
ailrst May 7, 2024
861df19
refac
ailrst May 8, 2024
ca20b60
untested xform to ternary
ailrst May 8, 2024
2a5f3c0
not working
ailrst May 8, 2024
38b3863
refactor so analysis and transform both called into from bdd AI walk
ailrst May 9, 2024
510fa72
fix anlaysis a bit and add bvadd
ailrst May 10, 2024
1a124a2
cleanup bvops
ailrst May 10, 2024
3e0f2d0
Eliminate comparisons during IntToBits
ncough Mar 28, 2024
ed09cb9
fix rebuild expr
ailrst May 20, 2024
8296797
Merge branch 'rt_pc' into scala-backend-pc
ailrst May 20, 2024
253fbd8
Merge branch 'rt_pc' into rt-copyprop
ailrst May 20, 2024
aa07c66
passing cov disabled
ailrst May 21, 2024
e7b760f
test and fix bdd sle/slt
ailrst May 21, 2024
4899c72
Merged backends (#80)
ailrst May 22, 2024
a59eab8
progress
ailrst May 22, 2024
6ec5295
possibly working
ailrst May 22, 2024
366ac3f
build standalone
ailrst May 23, 2024
f19b1ed
print lifted semantics
ailrst May 23, 2024
9b01077
readme
ailrst May 23, 2024
644380b
add mill script
ailrst May 23, 2024
a72373f
add generic lifter interface
ailrst Jul 19, 2024
3746ea6
Merge remote-tracking branch 'origin/scala-backend-pc' into scala-gen…
ailrst Jul 22, 2024
a8d0864
delete old utils
ailrst Jul 22, 2024
c2d0399
generate separate scala assembly file
ailrst Jul 22, 2024
2ad2660
cleanup
ailrst Jul 22, 2024
40d2e07
Merge branch 'partial_eval' into scala-generic
ailrst Jul 24, 2024
7ee3e4b
Merge branch 'partial_eval' into scala-generic
ailrst Jul 24, 2024
9ed5776
Merge branch 'rt-copyprop' into scala-generic
ailrst Jul 24, 2024
eb17f82
update tests
ailrst Jul 24, 2024
8a50ec0
marshall offline lifter
ailrst Jul 24, 2024
e473055
fix symbolic lifter merge
ailrst Jul 24, 2024
ef6e8d5
update action
ailrst Jul 24, 2024
117be11
update cpp lifter
ailrst Jul 24, 2024
d454645
cpp: allow llvm 18
katrinafyi Jul 24, 2024
a3632b6
cpp: clean up offlineASL-cpp folder
katrinafyi Jul 24, 2024
9916a0b
Merge branch 'partial_eval' into scala-generic
katrinafyi Jul 24, 2024
fabcd54
Merge remote-tracking branch 'origin/partial_eval' into scala-generic
katrinafyi Sep 2, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- run: echo 'preparing nix shell environment'

- run: dune build --profile release -j4
- run: echo ':gen A64 aarch64_* ocaml offlineASL' | OCAMLRUNPARAM=b dune exec asli
- run: echo ':gen A64 aarch64_* ocaml false offlineASL' | OCAMLRUNPARAM=b dune exec asli

- run: dune build offlineASL -j4

Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ scripts/total.txt
build/

offlineASL/aarch64_*
offlineASL-cpp/subprojects/aslp-lifter/src/generated/*
offlineASL-cpp/subprojects/aslp-lifter/include/aslp/generated/*



1 change: 1 addition & 0 deletions asli.opam
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ depends: [
"lwt"
"cohttp-lwt-unix"
"yojson"
"mlbdd"
"odoc" {with-doc}
]
build: [
Expand Down
22 changes: 16 additions & 6 deletions bin/asli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ let opt_export_aarch64_dir = ref ""
let opt_verbose = ref false


let () = Printexc.register_printer

let () =
Printexc.record_backtrace true ;
Printexc.register_printer
(function
| Value.EvalError (loc, msg) ->
Some (Printf.sprintf "EvalError at %s: %s" (pp_loc loc) msg)
Expand All @@ -40,7 +43,7 @@ let help_msg = [
{|:sem <instr-set> <int> Decode and print opcode semantics|};
{|:ast <instr-set> <int> [file] Decode and write opcode semantics to stdout or a file, in a structured ast format|};
{|:gen <instr-set> <regex> Generate an offline lifter using the given backend|};
{| [backend] [dir]|};
{| [pc-option] [backend] [dir]|};
{|:project <file> Execute ASLi commands in <file>|};
{|:q :quit Exit the interpreter|};
{|:run Execute instructions|};
Expand All @@ -56,6 +59,7 @@ let help_msg = [

(** supported backends for :gen and their default output directories *)
let gen_backends = [
("scala", (Cpu.Scala, "offlineASL-scala/lifter/src/generated"));
("ocaml", (Cpu.Ocaml, "offlineASL"));
("cpp", (Cpu.Cpp, "offlineASL-cpp/subprojects/aslp-lifter"));
]
Expand Down Expand Up @@ -197,18 +201,24 @@ let rec process_command (tcenv: TC.Env.t) (cpu: Cpu.cpu) (fname: string) (input0
(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);
Option.iter close_out chan_opt
| ":gen" :: iset :: id :: rest when List.length rest <= 2 ->
| ":gen" :: iset :: id :: rest when List.length rest <= 3 ->
let pc_option = Option.value List.(nth_opt rest 1) ~default:"false" in
let backend_str = Option.value List.(nth_opt rest 0) ~default:"ocaml" in
Printf.printf "Generating lifter for %s %s using %s backend\n" iset id backend_str;
Printf.printf "Generating lifter for %s %s with pc option %s using %s backend\n" iset id pc_option backend_str;

let pc_option = match String.lowercase_ascii pc_option with
| "false" -> false
| "true" -> true
| _ -> invalid_arg @@ Printf.sprintf "unkown pc option %s (expected: true, false)" pc_option in

let (backend, default_dir) = match List.assoc_opt backend_str gen_backends with
| Some x -> x
| None -> invalid_arg @@ Printf.sprintf "unknown backend %s (supported: %s)"
backend_str (String.concat ", " List.(map fst gen_backends)) in

let dir = Option.value List.(nth_opt rest 1) ~default:default_dir in
let dir = Option.value List.(nth_opt rest 2) ~default:default_dir in
let cpu' = Cpu.mkCPU cpu.env cpu.denv in
cpu'.gen iset id backend dir;
cpu'.gen iset id pc_option backend dir;
Printf.printf "Done generating %s lifter into '%s'.\n" backend_str dir;
| ":dump" :: iset :: opcode :: rest ->
let fname =
Expand Down
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"lwt"
"cohttp-lwt-unix"
"yojson"
"mlbdd"
)
)

Expand Down
29 changes: 29 additions & 0 deletions libASL/asl_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,35 @@ let masklength (x: string): int =
String.iter (function ' ' -> () | _ -> r := !r + 1) x;
!r

(* Location of a statement *)
let get_loc s =
match s with
| Stmt_If(_, _, _, _, loc)
| Stmt_VarDeclsNoInit(_, _, loc)
| Stmt_VarDecl(_, _, _, loc)
| Stmt_ConstDecl(_, _, _, loc)
| Stmt_Assign(_,_,loc)
| Stmt_FunReturn(_,loc)
| Stmt_ProcReturn(loc)
| Stmt_Assert(_, loc)
| Stmt_Unpred loc
| Stmt_ConstrainedUnpred loc
| Stmt_ImpDef (_, loc)
| Stmt_Undefined loc
| Stmt_ExceptionTaken loc
| Stmt_Dep_Unpred loc
| Stmt_Dep_Undefined loc
| Stmt_See (_,loc)
| Stmt_Throw (_, loc)
| Stmt_DecodeExecute (_, _, loc)
| Stmt_TCall (_, _, _, loc)
| Stmt_Case (_, _, _, loc)
| Stmt_For (_, _, _, _, _, loc)
| Stmt_While (_, _, loc)
| Stmt_Repeat (_, _, loc)
| Stmt_Try (_, _, _, _, loc)
| Stmt_Dep_ImpDef (_, loc) -> loc

(****************************************************************)
(** {2 Function signature accessors} *)
(****************************************************************)
Expand Down
1 change: 1 addition & 0 deletions libASL/cpp_backend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ let rec prints_expr e st =
| Expr_LitString s -> "\"" ^ s ^ "\""
| Expr_Tuple(es) -> "std::make_tuple(" ^ (String.concat "," (List.map (fun e -> prints_expr e st) es)) ^ ")"
| Expr_Unknown(ty) -> default_value ty st
| Expr_If(_, c, t, [], e) -> Printf.sprintf "((%s) ? (%s) : (%s))" (prints_expr c st) (prints_expr t st) (prints_expr e st)

| _ -> failwith @@ "prints_expr: " ^ pp_expr e

Expand Down
11 changes: 7 additions & 4 deletions libASL/cpu.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ open Asl_utils
type gen_backend =
| Ocaml
| Cpp
| Scala

type gen_function = AST.ident -> Eval.fun_sig -> Eval.fun_sig Bindings.t -> Eval.fun_sig Bindings.t -> string -> unit

Expand All @@ -25,7 +26,7 @@ type cpu = {
elfwrite : Int64.t -> char -> unit;
opcode : string -> Primops.bigint -> unit;
sem : string -> Primops.bigint -> unit;
gen : string -> string -> gen_backend -> string -> unit;
gen : string -> string -> bool -> gen_backend -> string -> unit;
}

let mkCPU (env : Eval.Env.t) (denv: Dis.env): cpu =
Expand Down Expand Up @@ -60,16 +61,18 @@ let mkCPU (env : Eval.Env.t) (denv: Dis.env): cpu =
(fun s -> Printf.printf "%s\n" (pp_stmt s))
(Dis.dis_decode_entry env denv decoder opcode)

and gen (iset: string) (pat: string) (backend: gen_backend) (dir: string): unit =
and gen (iset: string) (pat: string) (include_pc: bool) (backend: gen_backend) (dir: string): unit =
if not (Sys.file_exists dir) then failwith ("Can't find target dir " ^ dir);

(* Build the symbolic lifter *)
let (decoder_id,decoder_fnsig,tests,instrs) = Symbolic_lifter.run iset pat env in
let (decoder_id,decoder_fnsig,tests,instrs) = Symbolic_lifter.run_marshal include_pc iset pat env in

let run_gen_backend : gen_function =
match backend with
| Ocaml -> Ocaml_backend.run
| Cpp -> Cpp_backend.run in
| Cpp -> Cpp_backend.run
| Scala -> Scala_backend.run
in

(* Build backend program *)
run_gen_backend decoder_id decoder_fnsig tests instrs dir
Expand Down
3 changes: 2 additions & 1 deletion libASL/cpu.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
type gen_backend =
| Ocaml
| Cpp
| Scala

type gen_function = Asl_ast.ident -> Eval.fun_sig -> Eval.fun_sig Asl_utils.Bindings.t -> Eval.fun_sig Asl_utils.Bindings.t -> string -> unit

Expand All @@ -21,7 +22,7 @@ type cpu = {
elfwrite : Int64.t -> char -> unit;
opcode : string -> Primops.bigint -> unit;
sem : string -> Primops.bigint -> unit;
gen : string -> string -> gen_backend -> string -> unit;
gen : string -> string -> bool -> gen_backend -> string -> unit;
}

val mkCPU : Eval.Env.t -> Dis.env -> cpu
Expand Down
Loading