Skip to content

Commit

Permalink
cpp backend (#62)
Browse files Browse the repository at this point in the history
Offline lifter backend for C++, including IBI instantiation to emit LLVM IR

* offline-cpp: create directory.

* add boilerplate cpp files

* working on cpp backend.

to do: implement f_gen_* functions.

* stashing work to add types rt_expr and rt_label.

* stub all f_ functions.

* implement template-based generation

* update stubs with new interface

* fix some bigint/bits bugs and clean up includes.

* fix cmake, do not inherit.

* add gitignore for cpp

* fix bits/bigint oopsie

* stub v_ variables

* implement v_ variable prefixing (we compile now!!)

* use traits class

* temp

* stub implementations

* compiling fr now

* fix typo-ed names and change to _impl.hpp

* temporarily do the scoping thing :(

* disable scoping hack

* working on f_gen methods

* starting restructure for compile speed

* work on explicit instantiation

* refactor to cpp_fun_sig

* clean up and fix. split compilation working now!

* restore aslp_lifter_impl.hpp

* collate decode_tests and split llvm traits

* generating basic llvm?

* touch

* typename

* implement missing registers and intrinsics for non-float ops.

* fix with new branch intrinsics.

* restructure

* restructuring aslp-lifter-gen now works with pkg-config maybe

* meson build system

* merge to aslp-lifter project, distrubute src files, remove old cmakes

* compile speedups with clang+lld

* ci

* Update build.sh

* Update test.yml

* use absolute paths in ci CXX CXX_LD

* use llvm-15

* Update test.yml

* fix important warnings

* fix ci

nix overrides CXX variable when entering shell, predictably

* no ci

* fix uninit warnings

* add minimal cmakelists for non-installed use only

* update to generate in external repository

* copy support files when generating cpp lifter

this allows keeping versioning the lifter_interface alongside
the backend code which uses it.

* add cpp build files into repository

* do not copy headers and fix mkdir_p

* add warning to user to copy c++ build files.

* update cpp readme to suit in-repository location

* set default cpp gen dir to within subprojects

* generate meson file

* use %blob in cpp_backend

* update comment in cpp_backend

* add cpp build instructions to cpp readme

* add gitignore to offlineasl-cpp

* add check.py to perform syntax-checking of generated cpp

it would be nice to run this in ci. note llvm 17 dependency

* meson: restrict to llvm 17

* chdir in check.py
  • Loading branch information
katrinafyi authored Jul 24, 2024
1 parent eeb0ae8 commit a19d5ab
Show file tree
Hide file tree
Showing 35 changed files with 2,844 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ scripts/output.txt
scripts/cntlm.bir
scripts/total.txt

.cache/
build/

offlineASL/aarch64_*
13 changes: 7 additions & 6 deletions bin/asli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let help_msg = [
(** supported backends for :gen and their default output directories *)
let gen_backends = [
("ocaml", (Cpu.Ocaml, "offlineASL"));
("cpp", (Cpu.Cpp, "offlineASL-cpp"));
("cpp", (Cpu.Cpp, "offlineASL-cpp/subprojects/aslp-lifter"));
]

let () = Random.self_init ()
Expand Down Expand Up @@ -198,17 +198,18 @@ let rec process_command (tcenv: TC.Env.t) (cpu: Cpu.cpu) (fname: string) (input0
(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 ->
let backend = Option.value List.(nth_opt rest 0) ~default:"ocaml" in
Printf.printf "Generating lifter for %s %s using %s backend\n" iset id backend;
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;

let (backend, default_dir) = match List.assoc_opt backend gen_backends with
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 (String.concat ", " List.(map fst gen_backends)) in
backend_str (String.concat ", " List.(map fst gen_backends)) in

let dir = Option.value List.(nth_opt rest 1) ~default:default_dir in
let cpu' = Cpu.mkCPU cpu.env cpu.denv in
cpu'.gen iset id backend dir
cpu'.gen iset id backend dir;
Printf.printf "Done generating %s lifter into '%s'.\n" backend_str dir;
| ":dump" :: iset :: opcode :: rest ->
let fname =
(match rest with
Expand Down
Loading

0 comments on commit a19d5ab

Please sign in to comment.