Skip to content
← Back

src/semantic/target_profile.ghul

1
namespace Semantic is
2
use Collections.Iterable
3
4
/// What the front end and driver need to know about a build target,
5
/// asked of the target rather than read off its name, so that targets
6
/// sharing a behaviour share the answer.
7
trait TargetProfile is
8
/// Whether the core types are declared in a library compiled from
9
/// source, rather than reflected from referenced assemblies. Such a
10
/// target loads no assemblies and constructs its built-in types.
11
has_source_core_library: bool
12
13
/// Whether the program's entry point is called with its command
14
/// line arguments and environment.
15
entry_takes_arguments: bool
16
17
/// Whether the compiler can generate code for the target. A build
18
/// for one that cannot runs the front end and then reports that
19
/// code generation is not supported.
20
has_code_generation: bool
21
22
/// The `@IF` names the target turns on. A name another target
23
/// turns on is off for this one.
24
conditions: Iterable[string]
25
26
/// What the target's back end can consume.
27
capabilities: TargetCapabilities
28
si
29
30
/// The .NET target.
31
class DOTNET_TARGET_PROFILE: TargetProfile is
32
init() is
33
si
34
35
has_source_core_library: bool => false
36
entry_takes_arguments: bool => true
37
has_code_generation: bool => true
38
conditions: Iterable[string] => ["dotnet"]
39
capabilities: TargetCapabilities => DOTNET_TARGET_CAPABILITIES()
40
si
41
42
/// The WebAssembly target.
43
class WASM_TARGET_PROFILE: TargetProfile is
44
init() is
45
si
46
47
has_source_core_library: bool => true
48
entry_takes_arguments: bool => false
49
has_code_generation: bool => true
50
conditions: Iterable[string] => ["wasm", "source_core"]
51
capabilities: TargetCapabilities => WASM_TARGET_CAPABILITIES()
52
si
53
54
/// The LLVM target, a native executable.
55
class LLVM_TARGET_PROFILE: TargetProfile is
56
init() is
57
si
58
59
has_source_core_library: bool => true
60
entry_takes_arguments: bool => true
61
has_code_generation: bool => true
62
conditions: Iterable[string] => ["llvm", "source_core"]
63
capabilities: TargetCapabilities => LLVM_TARGET_CAPABILITIES()
64
si
65
66
/// The profile of every target.
67
class TARGET_PROFILES is
68
/// Every target's profile.
69
all: Iterable[TargetProfile] static =>
70
[DOTNET_TARGET_PROFILE(), WASM_TARGET_PROFILE(), LLVM_TARGET_PROFILE()]
71
72
/// The profile of `target`.
73
///
74
/// - target: the target to describe
75
for_target(target: Compiler.Target) -> TargetProfile static =>
76
case target
77
when Compiler.Target.DOTNET then DOTNET_TARGET_PROFILE()
78
when Compiler.Target.WASM then WASM_TARGET_PROFILE()
79
when Compiler.Target.LLVM then LLVM_TARGET_PROFILE()
80
esac
81
si
82
si