1 % (c) 2009-2024 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
2 % Heinrich Heine Universitaet Duesseldorf
3 % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
4
5 :- module(tools_platform, [
6 platform_is_64_bit/0,
7 max_tagged_integer/1,
8 max_tagged_pow2/1,
9 is_tagged_integer/1,
10 host_platform/1,
11 map_host_platform/2,
12 host_processor/1,
13 map_host_processor/2
14 ]).
15
16 :- use_module(module_information).
17
18 :- module_info(group, infrastructure).
19 :- module_info(description, 'Utilities for getting information about the platform/OS, seperated out from tools.pl to avoid cyclic module dependencies.').
20
21 % declare these predicates before imports so that we can use them in compile-time directives
22
23 platform_is_64_bit :-
24 max_tagged_pow2(Exp),
25 Exp > 32.
26
27 % On SICStus, max_tagged_integer equals:
28 % * 268435455 on 32-bit systems, i.e. 1<<28 - 1
29 % * 1152921504606846975 on 64-bit systems, i.e. 1<<60 - 1
30 max_tagged_integer(X) :- current_prolog_flag(max_tagged_integer,X).
31
32 max_tagged_pow2(Exp) :-
33 current_prolog_flag(max_tagged_integer,X),
34 Exp is msb(X) + 1.
35
36 is_tagged_integer(X) :- current_prolog_flag(max_tagged_integer,Lim), X =< Lim,
37 current_prolog_flag(min_tagged_integer,Low), X >= Low.
38
39 host_platform(Res) :-
40 current_prolog_flag(host_type,HostType),
41 atom_codes(HostType,AsciiList),
42 map_host_platform(AsciiList,Res),!.
43
44 map_host_platform(HT,Platform) :-
45 % Split at first '-' to remove the architecture prefix
46 append(_,[0'-|HT2],HT),
47 !,
48 (phrase(map_host_platform1(Platform),HT2,_) -> true ; Platform = unknown).
49
50 map_host_platform1(darwin) --> "darwin".
51 map_host_platform1(windows) --> "win".
52 map_host_platform1(linux) --> "linux".
53
54 % on Windows XP: 'x86-win32-nt-4'
55 % on MacPro: 'x86_64-darwin-10.6.0'
56 % on Linux: 'x86-linux-glibc2.7'
57
58 host_processor(Res) :-
59 current_prolog_flag(host_type,HostType),
60 atom_codes(HostType,AsciiList),
61 map_host_processor(AsciiList,Res),!.
62
63 map_host_processor(HT,Processor) :-
64 % Split at first '-' to remove the platform/os sufffix
65 append(HT1,[0'-|_],HT),
66 !,
67 ? (phrase(map_host_proc1(Processor),HT1,_) -> true ; Processor = unknown).
68
69 map_host_proc1(aarch64) --> "arm64".
70 map_host_proc1(aarch64) --> "aarch64".
71 map_host_proc1(x86_64) --> "x64".
72 map_host_proc1(x86_64) --> "x86_64", !.
73 map_host_proc1(x86) --> "x86".
74 map_host_proc1(x86) --> "i386".
75
76 % Tests for these predicates are placed in tools.pl to avoid module load order issues
77 % (especially on SWI, because pathes.pl must define its library(avl) term expansion before any modules that use library(avl)).