Skip to content

Commit dab7209

Browse files
authored
flambda-backend: Add Target_system to ocaml/utils (ocaml-flambda#542)
1 parent 82d5044 commit dab7209

File tree

5 files changed

+166
-2
lines changed

5 files changed

+166
-2
lines changed

.depend

+9
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ utils/strongly_connected_components.cmx : \
130130
utils/strongly_connected_components.cmi
131131
utils/strongly_connected_components.cmi : \
132132
utils/identifiable.cmi
133+
utils/target_system.cmo : \
134+
utils/misc.cmi \
135+
utils/config.cmi \
136+
utils/target_system.cmi
137+
utils/target_system.cmx : \
138+
utils/misc.cmx \
139+
utils/config.cmx \
140+
utils/target_system.cmi
141+
utils/target_system.cmi :
133142
utils/targetint.cmo : \
134143
utils/misc.cmi \
135144
utils/targetint.cmi

compilerlibs/Makefile.compilerlibs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ UTILS=utils/config.cmo utils/build_path_prefix_map.cmo utils/misc.cmo \
3131
utils/terminfo.cmo utils/ccomp.cmo utils/warnings.cmo \
3232
utils/consistbl.cmo utils/strongly_connected_components.cmo \
3333
utils/targetint.cmo utils/int_replace_polymorphic_compare.cmo \
34-
utils/domainstate.cmo utils/binutils.cmo
34+
utils/domainstate.cmo utils/binutils.cmo utils/target_system.cmo
3535
UTILS_CMI=
3636

3737
PARSING=parsing/location.cmo parsing/longident.cmo \

dune

+7-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
config build_path_prefix_map misc identifiable numbers arg_helper clflags
5050
profile terminfo ccomp warnings consistbl strongly_connected_components
5151
targetint load_path int_replace_polymorphic_compare domainstate binutils
52-
local_store
52+
local_store target_system
5353

5454
;; PARSING
5555
location longident docstrings syntaxerr ast_helper camlinternalMenhirLib
@@ -290,6 +290,7 @@
290290
(consistbl.mli as compiler-libs/consistbl.mli)
291291
(strongly_connected_components.mli as compiler-libs/strongly_connected_components.mli)
292292
(targetint.mli as compiler-libs/targetint.mli)
293+
(target_system.mli as compiler-libs/target_system.mli)
293294
(load_path.mli as compiler-libs/load_path.mli)
294295
(int_replace_polymorphic_compare.mli as compiler-libs/int_replace_polymorphic_compare.mli)
295296
(location.mli as compiler-libs/location.mli)
@@ -714,6 +715,10 @@
714715
(.ocamlcommon.objs/byte/targetint.cmo as compiler-libs/targetint.cmo)
715716
(.ocamlcommon.objs/byte/targetint.cmt as compiler-libs/targetint.cmt)
716717
(.ocamlcommon.objs/byte/targetint.cmti as compiler-libs/targetint.cmti)
718+
(.ocamlcommon.objs/byte/target_system.cmi as compiler-libs/target_system.cmi)
719+
(.ocamlcommon.objs/byte/target_system.cmo as compiler-libs/target_system.cmo)
720+
(.ocamlcommon.objs/byte/target_system.cmt as compiler-libs/target_system.cmt)
721+
(.ocamlcommon.objs/byte/target_system.cmti as compiler-libs/target_system.cmti)
717722
(.ocamlcommon.objs/byte/tast_iterator.cmi as compiler-libs/tast_iterator.cmi)
718723
(.ocamlcommon.objs/byte/tast_iterator.cmo as compiler-libs/tast_iterator.cmo)
719724
(.ocamlcommon.objs/byte/tast_iterator.cmt as compiler-libs/tast_iterator.cmt)
@@ -893,6 +898,7 @@
893898
(.ocamlcommon.objs/native/symtable.cmx as compiler-libs/symtable.cmx)
894899
(.ocamlcommon.objs/native/syntaxerr.cmx as compiler-libs/syntaxerr.cmx)
895900
(.ocamlcommon.objs/native/targetint.cmx as compiler-libs/targetint.cmx)
901+
(.ocamlcommon.objs/native/target_system.cmx as compiler-libs/target_system.cmx)
896902
(.ocamlcommon.objs/native/tast_iterator.cmx as compiler-libs/tast_iterator.cmx)
897903
(.ocamlcommon.objs/native/tast_mapper.cmx as compiler-libs/tast_mapper.cmx)
898904
(.ocamlcommon.objs/native/terminfo.cmx as compiler-libs/terminfo.cmx)

utils/target_system.ml

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
[@@@ocaml.warning "+a-4-30-40-41-42"]
2+
3+
type architecture =
4+
| IA32
5+
| X86_64
6+
| ARM
7+
| AArch64
8+
| POWER
9+
| Z
10+
| Riscv
11+
12+
let architecture () : architecture =
13+
match Config.architecture with
14+
| "i386" -> IA32
15+
| "amd64" -> X86_64
16+
| "arm" -> ARM
17+
| "arm64" -> AArch64
18+
| "power" -> POWER
19+
| "s390x" -> Z
20+
| "riscv" -> Riscv
21+
| arch -> Misc.fatal_errorf "Unknown architecture `%s'" arch
22+
23+
type derived_system =
24+
| Linux
25+
| MinGW_32
26+
| MinGW_64
27+
| Win32
28+
| Win64
29+
| Cygwin
30+
| MacOS_like
31+
| FreeBSD
32+
| NetBSD
33+
| OpenBSD
34+
| Generic_BSD
35+
| Solaris
36+
| Dragonfly
37+
| GNU
38+
| BeOS
39+
| Unknown
40+
41+
let derived_system () : derived_system =
42+
(* Derived from [configure.ac] *)
43+
match architecture (), Config.model, Config.system with
44+
| IA32, _, "linux_elf" -> Linux
45+
| IA32, _, "bsd_elf" -> Generic_BSD
46+
| IA32, _, "beos" -> BeOS
47+
| IA32, _, "cygwin" -> Cygwin
48+
| IA32, _, "gnu" -> GNU
49+
| IA32, _, "mingw" -> MinGW_32
50+
| IA32, _, "win32" -> Win32
51+
| X86_64, _, "win64" -> Win64
52+
| POWER, "ppc64le", "elf" -> Linux
53+
| POWER, "ppc64", "elf" -> Linux
54+
| POWER, "ppc", "elf" -> Linux
55+
| Z, "z10", "elf" -> Linux
56+
| ARM, "armv6", "linux_eabihf" -> Linux
57+
| ARM, "armv7", "linux_eabihf" -> Linux
58+
| ARM, "armv8", "linux_eabihf" -> Linux
59+
| ARM, "armv8", "linux_eabi" -> Linux
60+
| ARM, "armv7", "linux_eabi" -> Linux
61+
| ARM, "armv6t2", "linux_eabi" -> Linux
62+
| ARM, "armv6", "linux_eabi" -> Linux
63+
| ARM, "armv6", "freebsd" -> FreeBSD
64+
| ARM, "armv6", "netbsd" -> NetBSD
65+
| ARM, "armv7", "netbsd" -> NetBSD
66+
| ARM, "armv5te", "linux_eabi" -> Linux
67+
| ARM, "armv5", "linux_eabi" -> Linux
68+
| ARM, _, "linux_eabihf" -> Linux
69+
| ARM, _, "linux_eabi" -> Linux
70+
| ARM, _, "bsd" -> OpenBSD
71+
| X86_64, _, "linux" -> Linux
72+
| X86_64, _, "gnu" -> GNU
73+
| X86_64, _, "dragonfly" -> Dragonfly
74+
| X86_64, _, "solaris" -> Solaris
75+
| X86_64, _, "freebsd" -> FreeBSD
76+
| X86_64, _, "netbsd" -> NetBSD
77+
| X86_64, _, "openbsd" -> OpenBSD
78+
| AArch64, _, "macosx" -> MacOS_like
79+
| X86_64, _, "macosx" -> MacOS_like
80+
| X86_64, _, "mingw64" -> MinGW_64
81+
| AArch64, _, "linux" -> Linux
82+
| AArch64, _, "freebsd" -> FreeBSD
83+
| X86_64, _, "cygwin" -> Cygwin
84+
| Riscv, "riscv64", "linux" -> Linux
85+
| _, _, "unknown" -> Unknown
86+
| _, _, _ ->
87+
Misc.fatal_errorf
88+
"Cannot determine system type (model %s, system %s): ensure \
89+
`target_system.ml' matches `configure'"
90+
Config.model Config.system
91+
92+
let is_windows () =
93+
match derived_system () with
94+
| Linux | MacOS_like | FreeBSD | NetBSD | OpenBSD | Generic_BSD | Solaris
95+
| Dragonfly | GNU | BeOS | Unknown ->
96+
false
97+
| MinGW_32 | MinGW_64 | Win32 | Win64 | Cygwin -> true
98+
99+
type assembler =
100+
| GAS_like
101+
| MacOS
102+
| MASM
103+
104+
let assembler () =
105+
match derived_system () with
106+
| Win32 | Win64 -> MASM
107+
| MacOS_like -> MacOS
108+
| MinGW_32 | MinGW_64 | Cygwin | Linux | FreeBSD | NetBSD | OpenBSD
109+
| Generic_BSD | Solaris | GNU | Dragonfly | BeOS | Unknown ->
110+
GAS_like

utils/target_system.mli

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
type architecture =
2+
| IA32
3+
| X86_64
4+
| ARM
5+
| AArch64
6+
| POWER
7+
| Z
8+
| Riscv
9+
10+
val architecture : unit -> architecture
11+
12+
type derived_system =
13+
| Linux
14+
| MinGW_32
15+
| MinGW_64
16+
| Win32
17+
| Win64
18+
| Cygwin
19+
| MacOS_like
20+
| FreeBSD
21+
| NetBSD
22+
| OpenBSD
23+
| Generic_BSD
24+
| Solaris
25+
| Dragonfly
26+
| GNU
27+
| BeOS
28+
| Unknown
29+
30+
val derived_system : unit -> derived_system
31+
32+
val is_windows : unit -> bool
33+
34+
type assembler =
35+
| GAS_like
36+
| MacOS
37+
| MASM
38+
39+
val assembler : unit -> assembler

0 commit comments

Comments
 (0)