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

add owi c command and examples for all subcommands #100

Merged
merged 18 commits into from
Jan 16, 2024
Merged
19 changes: 13 additions & 6 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
(lang dune 3.0)

(using menhir 2.1)

(using dune_site 0.1)
(using mdx 0.2)
(using directory-targets 0.1)

(cram enable)

(generate_opam_files true)

(name owi)

(license AGPL-3.0-or-later)

(authors
"Léo Andrès <[email protected]>"
"Pierre Chambart <[email protected]>")
"Pierre Chambart <[email protected]>"
"Filipe Marques")

(maintainers "Léo Andrès <[email protected]>")

(source
(github ocamlpro/owi))

(generate_opam_files true)

(package
(name owi)
(synopsis
Expand Down Expand Up @@ -53,7 +55,7 @@
(>= "0.1")
:dev))
(odoc :with-doc)
(bos :with-test)
bos
(mdx
(and
:with-test
Expand All @@ -62,4 +64,9 @@
(graphics :dev)
(tiny_httpd :dev)
(encoding (>= 0.0.3))
xmlm))
sha
xmlm
pyml
re2
dune-site)
(sites (share pyc) (share binc) (share libc)))
12 changes: 11 additions & 1 deletion owi.opam
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ maintainer: ["Léo Andrès <[email protected]>"]
authors: [
"Léo Andrès <[email protected]>"
"Pierre Chambart <[email protected]>"
"Filipe Marques"
]
license: "AGPL-3.0-or-later"
tags: ["owi" "ocaml" "webassembly" "wasm" "interpreter" "compiler"]
Expand All @@ -25,13 +26,17 @@ depends: [
"bisect_ppx" {with-test & >= "2.5" & dev}
"ocb" {with-test & >= "0.1" & dev}
"odoc" {with-doc}
"bos" {with-test}
"bos"
"mdx" {with-test & >= "2.1"}
"crowbar" {with-test}
"graphics" {dev}
"tiny_httpd" {dev}
"encoding" {>= "0.0.3"}
"sha"
"xmlm"
"pyml"
"re2"
"dune-site"
]
build: [
["dune" "subst"] {dev}
Expand All @@ -42,10 +47,15 @@ build: [
name
"-j"
jobs
"--promote-install-files=false"
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
["dune" "install" "-p" name "--create-install-files" name]
]
dev-repo: "git+https://github.com/ocamlpro/owi.git"
available: (arch = "x86_32" | arch = "x86_64" | arch = "arm64") & os != "win32"
depexts: [
["llvm" "clang" "lld" "wabt"] {os-family = "debian"}
]
3 changes: 3 additions & 0 deletions owi.opam.template
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
available: (arch = "x86_32" | arch = "x86_64" | arch = "arm64") & os != "win32"
depexts: [
["llvm" "clang" "lld" "wabt"] {os-family = "debian"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
["llvm" "clang" "lld" "wabt"] {os-family = "debian"}
["llvm" "clang" "lld" "wabt"] {os-family = "debian"}
["llvm" "wabt"] {os-family = "osx"}

CI is failing, and it appears to be because we're not specifying the dependencies here. However, I'm not quite sure if these are the only packages required for macOS. Additionally, I couldn't find mentions of lld or clang in Homebrew packages, so I assume they must be included in llvm.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I added this line directly myself as running dune b owi.opam was needed to generate the new owi.opam file...

Let's see if this is enough 😅

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to have done nothing 😅

I was looking at the os-family available in here and perhaps wrongfully assumed osx would work. Inspecting the CI, it looks like it's looking for os-family = "homebrew"? I have no current way to test this tho, sorry.

...
# Detecting depexts using vars: arch=x86_64, os=macos, os-distribution=homebrew, os-family=homebrew
...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, still not. Let's merge as the CI is green on Linux. We'll fix macOS later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least it's installing wabt and llvm not. But it's still saying opt: command not found

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I saw... @krtab is going to have a look.

]
2 changes: 1 addition & 1 deletion src/bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
(modules owi)
(package owi)
(libraries sedlex owi cmdliner)
(instrumentation
(instrumentation
(backend bisect_ppx)))
51 changes: 45 additions & 6 deletions src/bin/owi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ let file =

let files =
let doc = "source files" in
let parse s = Ok s in
Cmdliner.Arg.(
value
& pos 0 (list ~sep:' ' (conv (parse, Format.pp_string))) [] (info [] ~doc) )
Cmdliner.Arg.(value & pos_all non_dir_file [] (info [] ~doc))

let no_exhaustion =
let doc = "no exhaustion tests" in
Expand All @@ -37,7 +34,10 @@ let unsafe =

let workers =
let doc = "number of workers for symbolic execution" in
Cmdliner.Arg.(value & opt int (Domain.recommended_domain_count ()) & info [ "workers"; "w" ] ~doc)
Cmdliner.Arg.(
value
& opt int (Domain.recommended_domain_count ())
& info [ "workers"; "w" ] ~doc )

let workspace =
let doc = "path to the workspace directory" in
Expand All @@ -52,6 +52,44 @@ let shared_man =

let version = "%%VERSION%%"

let c_cmd =
let open Cmdliner in
let info =
let doc =
"Compile a C file to Wasm and run the symbolic interpreter on it"
in
let man = [] @ shared_man in
Cmd.info "c" ~version ~doc ~sdocs ~man
in
let arch =
let doc = "data model" in
Arg.(value & opt int 32 & info [ "arch"; "m" ] ~doc)
in
let property =
let doc = "property file" in
Arg.(value & opt (some string) None & info [ "property"; "p" ] ~doc)
in
let includes =
let doc = "headers path" in
Arg.(value & opt_all dir [] & info [ "I" ] ~doc)
in
let opt_lvl =
let doc = "specify which optimization level to use" in
Arg.(value & opt string "0" & info [ "O" ] ~doc)
in
let testcomp =
let doc = "test-comp mode" in
Arg.(value & flag & info [ "testcomp" ] ~doc)
in
let output =
let doc = "write results to dir" in
Arg.(value & opt string "owi-out" & info [ "output"; "o" ] ~doc)
in
Cmd.v info
Term.(
const Cmd_c.cmd $ debug $ arch $ property $ testcomp $ output $ workers
$ opt_lvl $ includes $ files )

let fmt_cmd =
let open Cmdliner in
let info =
Expand Down Expand Up @@ -117,7 +155,8 @@ let cli =
Cmd.info "owi" ~version ~doc ~sdocs ~man
in
let default = Term.(ret (const (fun _ -> `Help (`Pager, None)) $ copts_t)) in
Cmd.group info ~default [ fmt_cmd; opt_cmd; run_cmd; script_cmd; sym_cmd ]
Cmd.group info ~default
[ c_cmd; fmt_cmd; opt_cmd; run_cmd; script_cmd; sym_cmd ]

let main () = exit @@ Cmdliner.Cmd.eval cli

Expand Down
12 changes: 12 additions & 0 deletions src/c_instrumentor.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let py_module = lazy (Py.Import.import_module "instrumentor")

let import_module () = Lazy.force py_module

let instrument file includes =
let callable = Py.Module.get (import_module ()) "instrument" in
let kwargs =
[ ("file", Py.String.of_string file)
; ("includes", Py.List.of_list @@ List.map Py.String.of_string includes)
]
in
ignore @@ Py.Callable.to_function_with_keywords callable [||] kwargs
1 change: 1 addition & 0 deletions src/c_instrumentor.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val instrument : string -> string list -> unit
14 changes: 14 additions & 0 deletions src/c_share.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
let py_location = C_share_site.Sites.pyc

let bin_location = C_share_site.Sites.binc

let lib_location = C_share_site.Sites.libc

let find location file =
List.find_map
(fun dir ->
let filename = Filename.concat dir file in
if Sys.file_exists filename then Some filename else None )
location

let get_libc () = find bin_location "libc.wasm"
7 changes: 7 additions & 0 deletions src/c_share.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
val py_location : string list

val bin_location : string list

val lib_location : string list

val get_libc : unit -> string option
Loading
Loading