From 76870f18321d4352d2a6a6522acca035552087c7 Mon Sep 17 00:00:00 2001 From: zapashcanon Date: Sat, 15 Jun 2024 23:32:08 +0200 Subject: [PATCH] remove useless c_processing module, better organisation of src/ folder --- dune-project | 2 +- src/{ => ast}/compile.ml | 0 src/{ => ast}/compile.mli | 0 src/c_processing/c_share.ml | 27 --------------------- src/c_processing/c_share.mli | 11 --------- src/cmd/cmd_c.ml | 29 +++++++++++++++++++++-- src/dune | 1 - src/{ => utils}/result.ml | 0 src/{ => utils}/result.mli | 0 src/{ => utils}/tracing.ml | 0 src/{ => utils}/tracing.mli | 0 src/{check => validate}/check.ml | 0 src/{check => validate}/check.mli | 0 src/{typecheck => validate}/typecheck.ml | 0 src/{typecheck => validate}/typecheck.mli | 0 test/script/gc.t | 2 +- 16 files changed, 29 insertions(+), 43 deletions(-) rename src/{ => ast}/compile.ml (100%) rename src/{ => ast}/compile.mli (100%) delete mode 100644 src/c_processing/c_share.ml delete mode 100644 src/c_processing/c_share.mli rename src/{ => utils}/result.ml (100%) rename src/{ => utils}/result.mli (100%) rename src/{ => utils}/tracing.ml (100%) rename src/{ => utils}/tracing.mli (100%) rename src/{check => validate}/check.ml (100%) rename src/{check => validate}/check.mli (100%) rename src/{typecheck => validate}/typecheck.ml (100%) rename src/{typecheck => validate}/typecheck.mli (100%) diff --git a/dune-project b/dune-project index 4143eb440..f9402e043 100644 --- a/dune-project +++ b/dune-project @@ -75,4 +75,4 @@ xmlm (hc (>= 0.3)) dune-site) - (sites (share pyc) (share binc) (share libc))) + (sites (share binc) (share libc))) diff --git a/src/compile.ml b/src/ast/compile.ml similarity index 100% rename from src/compile.ml rename to src/ast/compile.ml diff --git a/src/compile.mli b/src/ast/compile.mli similarity index 100% rename from src/compile.mli rename to src/ast/compile.mli diff --git a/src/c_processing/c_share.ml b/src/c_processing/c_share.ml deleted file mode 100644 index 01649399a..000000000 --- a/src/c_processing/c_share.ml +++ /dev/null @@ -1,27 +0,0 @@ -(* SPDX-License-Identifier: AGPL-3.0-or-later *) -(* Copyright © 2021-2024 OCamlPro *) -(* Written by the Owi programmers *) - -open Syntax - -let py_location = List.map Fpath.v C_share_site.Sites.pyc - -let bin_location = List.map Fpath.v C_share_site.Sites.binc - -let lib_location = List.map Fpath.v C_share_site.Sites.libc - -let find location file = - let* l = - list_map - (fun dir -> - let filename = Fpath.append dir file in - match Bos.OS.File.exists filename with - | Ok true -> Ok (Some filename) - | Ok false -> Ok None - | Error (`Msg msg) -> Error (`Msg msg) ) - location - in - Ok (List.find (function None -> false | Some _filename -> true) l) - -let libc = - Option.get @@ Result.get_ok @@ find bin_location (Fpath.v "libc.wasm") diff --git a/src/c_processing/c_share.mli b/src/c_processing/c_share.mli deleted file mode 100644 index 73706b9c3..000000000 --- a/src/c_processing/c_share.mli +++ /dev/null @@ -1,11 +0,0 @@ -(* SPDX-License-Identifier: AGPL-3.0-or-later *) -(* Copyright © 2021-2024 OCamlPro *) -(* Written by the Owi programmers *) - -val py_location : Fpath.t list - -val bin_location : Fpath.t list - -val lib_location : Fpath.t list - -val libc : Fpath.t diff --git a/src/cmd/cmd_c.ml b/src/cmd/cmd_c.ml index f35b4ac08..77b4a265c 100644 --- a/src/cmd/cmd_c.ml +++ b/src/cmd/cmd_c.ml @@ -11,6 +11,28 @@ type metadata = ; files : Fpath.t list } +let binc_location = List.map Fpath.v C_share_site.Sites.binc + +let libc_location = List.map Fpath.v C_share_site.Sites.libc + +let find location file : Fpath.t Result.t = + let* l = + list_map + (fun dir -> + let filename = Fpath.append dir file in + match Bos.OS.File.exists filename with + | Ok true -> Ok (Some filename) + | Ok false -> Ok None + | Error (`Msg msg) -> Error (`Msg msg) ) + location + in + let rec loop = function + | [] -> Error (`Msg (Format.asprintf "can't find file %a" Fpath.pp file)) + | None :: tl -> loop tl + | Some file :: _tl -> Ok file + in + loop l + let compile ~includes ~opt_lvl (files : Fpath.t list) : Fpath.t Result.t = let flags = let stack_size = 8 * 1024 * 1024 |> string_of_int in @@ -37,7 +59,10 @@ let compile ~includes ~opt_lvl (files : Fpath.t list) : Fpath.t Result.t = let* clang_bin = OS.Cmd.resolve @@ Cmd.v "clang" in let out = Fpath.(v "a.out.wasm") in - let files = Cmd.of_list (List.map Fpath.to_string (C_share.libc :: files)) in + + let* libc = find binc_location (Fpath.v "libc.wasm") in + + let files = Cmd.of_list (List.map Fpath.to_string (libc :: files)) in let clang : Bos.Cmd.t = Cmd.(clang_bin %% flags % "-o" % p out %% files) in let+ () = OS.Cmd.run clang in @@ -98,7 +123,7 @@ let cmd debug arch property _testcomp workspace workers opt_lvl includes files deterministic_result_order concolic solver : unit Result.t = if debug then Logs.set_level (Some Debug); let workspace = Fpath.v workspace in - let includes = C_share.lib_location @ includes in + let includes = libc_location @ includes in let* (_exists : bool) = OS.Dir.create ~path:true workspace in let* modul = compile ~includes ~opt_lvl files in let* () = metadata ~workspace arch property files in diff --git a/src/dune b/src/dune index ac901250b..e61447aaa 100644 --- a/src/dune +++ b/src/dune @@ -8,7 +8,6 @@ binary_parser binary_to_text binary_types - c_share c_share_site check choice_intf diff --git a/src/result.ml b/src/utils/result.ml similarity index 100% rename from src/result.ml rename to src/utils/result.ml diff --git a/src/result.mli b/src/utils/result.mli similarity index 100% rename from src/result.mli rename to src/utils/result.mli diff --git a/src/tracing.ml b/src/utils/tracing.ml similarity index 100% rename from src/tracing.ml rename to src/utils/tracing.ml diff --git a/src/tracing.mli b/src/utils/tracing.mli similarity index 100% rename from src/tracing.mli rename to src/utils/tracing.mli diff --git a/src/check/check.ml b/src/validate/check.ml similarity index 100% rename from src/check/check.ml rename to src/validate/check.ml diff --git a/src/check/check.mli b/src/validate/check.mli similarity index 100% rename from src/check/check.mli rename to src/validate/check.mli diff --git a/src/typecheck/typecheck.ml b/src/validate/typecheck.ml similarity index 100% rename from src/typecheck/typecheck.ml rename to src/validate/typecheck.ml diff --git a/src/typecheck/typecheck.mli b/src/validate/typecheck.mli similarity index 100% rename from src/typecheck/typecheck.mli rename to src/validate/typecheck.mli diff --git a/test/script/gc.t b/test/script/gc.t index 0ca295179..63ccb8c89 100644 --- a/test/script/gc.t +++ b/test/script/gc.t @@ -21,7 +21,7 @@ [23] $ owi script --no-exhaustion reference/proposals/gc/ref_eq.wast owi: internal error, uncaught exception: - File "src/typecheck/typecheck.ml", line 478, characters 4-10: Assertion failed + File "src/validate/typecheck.ml", line 478, characters 4-10: Assertion failed [125] $ owi script --no-exhaustion reference/proposals/gc/ref_test.wast