Skip to content

Commit

Permalink
CN: more steps towards handling GCC builtins
Browse files Browse the repository at this point in the history
This is so far work in progress.

This config ought to permit core-peval to unfold some of the proxy
wrappers in the core stdlib, but it doesn't seem to be working yet.
  • Loading branch information
talsewell committed Aug 16, 2023
1 parent 1dc6cf8 commit 07d4c4b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/cn/core_to_mucore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ let normalise_file (markers_env, ail_prog) file =

let env = List.fold_left register_glob env globs in

Print.debug 3 (lazy (Print.item "stdlib symbols" (Print.list Sym.pp
Print.debug 3 (lazy (Print.item "stdlib symbols" (Print.list Sym.pp_debug
(List.map fst (Pmap.bindings_list file.mi_stdlib)))));

Print.debug 3 (lazy (Print.item "stdlib symbols in fmap" (Print.list Sym.pp
Expand Down
1 change: 1 addition & 0 deletions backend/cn/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ let frontend incl_dirs incl_files astprints filename state_file =
Cerb_global.set_cerb_conf "Cn" false Random false Basic false false false false false;
Ocaml_implementation.set Ocaml_implementation.HafniumImpl.impl;
Switches.set ["inner_arg_temps"; "at_magic_comments"; "warn_mismatched_magic_comments"];
Core_peval.config_unfold_stdlib := Sym.has_id_with Setup.unfold_stdlib_name;
let@ stdlib = load_core_stdlib () in
let@ impl = load_core_impl stdlib impl_name in
let conf = Setup.conf incl_dirs incl_files astprints in
Expand Down
8 changes: 8 additions & 0 deletions backend/cn/setup.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
open Cerb_backend.Pipeline
module StringSet = Set.Make(String)


let io = default_io_helpers
Expand Down Expand Up @@ -52,3 +53,10 @@ let conf incl_dirs incl_files astprints =
; cpp_cmd = with_cn_keywords (cpp_str incl_dirs incl_files)
; cpp_stderr = true
}

let unfold_proxies = StringSet.of_list [
"ffs_proxy"; "ffsl_proxy"; "ffsll_proxy"; "ctz_proxy";
]

let unfold_stdlib_name s = StringSet.mem s unfold_proxies

4 changes: 4 additions & 0 deletions backend/cn/sym.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ let has_id = function
| _ ->
None

let has_id_with f sym = match has_id sym with
| None -> false
| Some str -> f str


module StringHash =
Hashtbl.Make(struct
Expand Down
2 changes: 1 addition & 1 deletion runtime/libcore/std_inner_arg_temps.core
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ builtin bswap16 (integer): eff loaded integer
builtin bswap32 (integer): eff loaded integer
builtin bswap64 (integer): eff loaded integer

proc [ailname = " "] ctz_proxy (n_: loaded integer): eff loaded integer :=
proc [ailname = "__builtin_ctz"] ctz_proxy (n_: loaded integer): eff loaded integer :=
case n_ of
| Specified (n: integer) =>
if n = 0 then
Expand Down
1 change: 1 addition & 0 deletions tests/cn/builtin_ctz.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ f (unsigned int x) {
unsigned int y;

y = __builtin_ctz(x);
y = __builtin_ffs(x);

if (y < 10) {
return 1;
Expand Down

0 comments on commit 07d4c4b

Please sign in to comment.