Created
May 28, 2019 18:20
-
-
Save jtpaasch/c470f30866dbebce41c28c8f048979fd to your computer and use it in GitHub Desktop.
Example of a simple standalone Primus machine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(** MAKEFILE: | |
build = _build | |
exe = main.native | |
all: clean build | |
clean: | |
rm -rf $(exe) | |
rm -rf $(build) | |
build: | |
ocamlbuild -use-ocamlfind -pkgs bap-primus,bap,findlib.dynload $(exe) | |
*) | |
open Core_kernel | |
open Bap.Std | |
open Bap_primus.Std | |
open Bap_plugins.Std | |
open Monads.Std | |
include Self() | |
let get_filepath_arg = fun () -> | |
match (Array.length Sys.argv) > 1 with | |
| false -> raise (Failure "Specify /path/to/exe") | |
| true -> Sys.argv.(1) | |
let load_proj ?rooter:(r="internal") f = | |
ok_exn (Project.create ?rooter:(Rooter.Factory.find r) (Project.Input.file f)) | |
module Machine = struct | |
type 'a m = 'a | |
include Primus.Machine.Make(Monad.Ident) | |
end | |
module Main = Primus.Machine.Main(Machine) | |
let do_something = fun () -> | |
print_endline "Doing something..."; | |
Machine.return () | |
let main p = | |
Main.run p (do_something ()) | |
let () = | |
Plugins.run (); | |
let f = get_filepath_arg () in | |
let p = load_proj f in | |
main p; | |
print_endline "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment