diff --git a/.depend b/.depend index 1439efedcb41..53be86fe14ca 100644 --- a/.depend +++ b/.depend @@ -130,6 +130,15 @@ utils/strongly_connected_components.cmx : \ utils/strongly_connected_components.cmi utils/strongly_connected_components.cmi : \ utils/identifiable.cmi +utils/target_system.cmo : \ + utils/misc.cmi \ + utils/config.cmi \ + utils/target_system.cmi +utils/target_system.cmx : \ + utils/misc.cmx \ + utils/config.cmx \ + utils/target_system.cmi +utils/target_system.cmi : utils/targetint.cmo : \ utils/misc.cmi \ utils/targetint.cmi diff --git a/compilerlibs/Makefile.compilerlibs b/compilerlibs/Makefile.compilerlibs index 6133898cbce5..801912fefc25 100644 --- a/compilerlibs/Makefile.compilerlibs +++ b/compilerlibs/Makefile.compilerlibs @@ -31,7 +31,7 @@ UTILS=utils/config.cmo utils/build_path_prefix_map.cmo utils/misc.cmo \ utils/terminfo.cmo utils/ccomp.cmo utils/warnings.cmo \ utils/consistbl.cmo utils/strongly_connected_components.cmo \ utils/targetint.cmo utils/int_replace_polymorphic_compare.cmo \ - utils/domainstate.cmo utils/binutils.cmo + utils/domainstate.cmo utils/binutils.cmo utils/target_system.cmo UTILS_CMI= PARSING=parsing/location.cmo parsing/longident.cmo \ diff --git a/dune b/dune index 51eda3c485f1..e5baab266ee7 100644 --- a/dune +++ b/dune @@ -49,7 +49,7 @@ config build_path_prefix_map misc identifiable numbers arg_helper clflags profile terminfo ccomp warnings consistbl strongly_connected_components targetint load_path int_replace_polymorphic_compare domainstate binutils - local_store + local_store target_system ;; PARSING location longident docstrings syntaxerr ast_helper camlinternalMenhirLib @@ -290,6 +290,7 @@ (consistbl.mli as compiler-libs/consistbl.mli) (strongly_connected_components.mli as compiler-libs/strongly_connected_components.mli) (targetint.mli as compiler-libs/targetint.mli) + (target_system.mli as compiler-libs/target_system.mli) (load_path.mli as compiler-libs/load_path.mli) (int_replace_polymorphic_compare.mli as compiler-libs/int_replace_polymorphic_compare.mli) (location.mli as compiler-libs/location.mli) @@ -714,6 +715,10 @@ (.ocamlcommon.objs/byte/targetint.cmo as compiler-libs/targetint.cmo) (.ocamlcommon.objs/byte/targetint.cmt as compiler-libs/targetint.cmt) (.ocamlcommon.objs/byte/targetint.cmti as compiler-libs/targetint.cmti) + (.ocamlcommon.objs/byte/target_system.cmi as compiler-libs/target_system.cmi) + (.ocamlcommon.objs/byte/target_system.cmo as compiler-libs/target_system.cmo) + (.ocamlcommon.objs/byte/target_system.cmt as compiler-libs/target_system.cmt) + (.ocamlcommon.objs/byte/target_system.cmti as compiler-libs/target_system.cmti) (.ocamlcommon.objs/byte/tast_iterator.cmi as compiler-libs/tast_iterator.cmi) (.ocamlcommon.objs/byte/tast_iterator.cmo as compiler-libs/tast_iterator.cmo) (.ocamlcommon.objs/byte/tast_iterator.cmt as compiler-libs/tast_iterator.cmt) @@ -893,6 +898,7 @@ (.ocamlcommon.objs/native/symtable.cmx as compiler-libs/symtable.cmx) (.ocamlcommon.objs/native/syntaxerr.cmx as compiler-libs/syntaxerr.cmx) (.ocamlcommon.objs/native/targetint.cmx as compiler-libs/targetint.cmx) + (.ocamlcommon.objs/native/target_system.cmx as compiler-libs/target_system.cmx) (.ocamlcommon.objs/native/tast_iterator.cmx as compiler-libs/tast_iterator.cmx) (.ocamlcommon.objs/native/tast_mapper.cmx as compiler-libs/tast_mapper.cmx) (.ocamlcommon.objs/native/terminfo.cmx as compiler-libs/terminfo.cmx) diff --git a/utils/target_system.ml b/utils/target_system.ml new file mode 100644 index 000000000000..d9afee0c87e7 --- /dev/null +++ b/utils/target_system.ml @@ -0,0 +1,110 @@ +[@@@ocaml.warning "+a-4-30-40-41-42"] + +type architecture = + | IA32 + | X86_64 + | ARM + | AArch64 + | POWER + | Z + | Riscv + +let architecture () : architecture = + match Config.architecture with + | "i386" -> IA32 + | "amd64" -> X86_64 + | "arm" -> ARM + | "arm64" -> AArch64 + | "power" -> POWER + | "s390x" -> Z + | "riscv" -> Riscv + | arch -> Misc.fatal_errorf "Unknown architecture `%s'" arch + +type derived_system = + | Linux + | MinGW_32 + | MinGW_64 + | Win32 + | Win64 + | Cygwin + | MacOS_like + | FreeBSD + | NetBSD + | OpenBSD + | Generic_BSD + | Solaris + | Dragonfly + | GNU + | BeOS + | Unknown + +let derived_system () : derived_system = + (* Derived from [configure.ac] *) + match architecture (), Config.model, Config.system with + | IA32, _, "linux_elf" -> Linux + | IA32, _, "bsd_elf" -> Generic_BSD + | IA32, _, "beos" -> BeOS + | IA32, _, "cygwin" -> Cygwin + | IA32, _, "gnu" -> GNU + | IA32, _, "mingw" -> MinGW_32 + | IA32, _, "win32" -> Win32 + | X86_64, _, "win64" -> Win64 + | POWER, "ppc64le", "elf" -> Linux + | POWER, "ppc64", "elf" -> Linux + | POWER, "ppc", "elf" -> Linux + | Z, "z10", "elf" -> Linux + | ARM, "armv6", "linux_eabihf" -> Linux + | ARM, "armv7", "linux_eabihf" -> Linux + | ARM, "armv8", "linux_eabihf" -> Linux + | ARM, "armv8", "linux_eabi" -> Linux + | ARM, "armv7", "linux_eabi" -> Linux + | ARM, "armv6t2", "linux_eabi" -> Linux + | ARM, "armv6", "linux_eabi" -> Linux + | ARM, "armv6", "freebsd" -> FreeBSD + | ARM, "armv6", "netbsd" -> NetBSD + | ARM, "armv7", "netbsd" -> NetBSD + | ARM, "armv5te", "linux_eabi" -> Linux + | ARM, "armv5", "linux_eabi" -> Linux + | ARM, _, "linux_eabihf" -> Linux + | ARM, _, "linux_eabi" -> Linux + | ARM, _, "bsd" -> OpenBSD + | X86_64, _, "linux" -> Linux + | X86_64, _, "gnu" -> GNU + | X86_64, _, "dragonfly" -> Dragonfly + | X86_64, _, "solaris" -> Solaris + | X86_64, _, "freebsd" -> FreeBSD + | X86_64, _, "netbsd" -> NetBSD + | X86_64, _, "openbsd" -> OpenBSD + | AArch64, _, "macosx" -> MacOS_like + | X86_64, _, "macosx" -> MacOS_like + | X86_64, _, "mingw64" -> MinGW_64 + | AArch64, _, "linux" -> Linux + | AArch64, _, "freebsd" -> FreeBSD + | X86_64, _, "cygwin" -> Cygwin + | Riscv, "riscv64", "linux" -> Linux + | _, _, "unknown" -> Unknown + | _, _, _ -> + Misc.fatal_errorf + "Cannot determine system type (model %s, system %s): ensure \ + `target_system.ml' matches `configure'" + Config.model Config.system + +let is_windows () = + match derived_system () with + | Linux | MacOS_like | FreeBSD | NetBSD | OpenBSD | Generic_BSD | Solaris + | Dragonfly | GNU | BeOS | Unknown -> + false + | MinGW_32 | MinGW_64 | Win32 | Win64 | Cygwin -> true + +type assembler = + | GAS_like + | MacOS + | MASM + +let assembler () = + match derived_system () with + | Win32 | Win64 -> MASM + | MacOS_like -> MacOS + | MinGW_32 | MinGW_64 | Cygwin | Linux | FreeBSD | NetBSD | OpenBSD + | Generic_BSD | Solaris | GNU | Dragonfly | BeOS | Unknown -> + GAS_like diff --git a/utils/target_system.mli b/utils/target_system.mli new file mode 100644 index 000000000000..458fded09139 --- /dev/null +++ b/utils/target_system.mli @@ -0,0 +1,39 @@ +type architecture = + | IA32 + | X86_64 + | ARM + | AArch64 + | POWER + | Z + | Riscv + +val architecture : unit -> architecture + +type derived_system = + | Linux + | MinGW_32 + | MinGW_64 + | Win32 + | Win64 + | Cygwin + | MacOS_like + | FreeBSD + | NetBSD + | OpenBSD + | Generic_BSD + | Solaris + | Dragonfly + | GNU + | BeOS + | Unknown + +val derived_system : unit -> derived_system + +val is_windows : unit -> bool + +type assembler = + | GAS_like + | MacOS + | MASM + +val assembler : unit -> assembler