-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
external-linker-interface.spice
82 lines (69 loc) · 2.11 KB
/
external-linker-interface.spice
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Std imports
import "std/data/vector";
import "std/io/filepath";
// Own imports
import "../driver";
public type ExternalLinkerInterface struct {
CliOptions& cliOptions
public FilePath outputPath
Vector<string> objectFilePaths
Vector<string> linkerFlags
}
public p ExternalLinkerInterface.ctor(const CliOptions& cliOptions) {
this.cliOptions = cliOptions;
this.outputPath = cliOptions.outputPath;
}
public p ExternalLinkerInterface.prepare() {
// Set target to linker
this.addLinkerFlag("--target=" + this.cliOptions.targetTriple);
// Static linking
if this.cliOptions.staticLinking {
this.addLinkerFlag("-static");
}
// Stripping symbols
if !this.cliOptions.generateDebugInfo {
this.addLinkerFlag("-Wl,-s");
}
// Web Assembly
if this.cliOptions.targetArch == TARGET_WASM32 || this.cliOptions.targetArch == TARGET_WASM64 {
this.addLinkerFlag("-nostdlib");
this.addLinkerFlag("-Wl,--no-entry");
this.addLinkerFlag("-Wl,--export-all");
}
}
/**
* Start the linking process
*/
public p ExternalLinkerInterface.link() {
assert !this.outputPath.isEmpty();
// ToDo
}
/**
* Add another object file to be linked when calling 'link()'
*
* @param objectFilePath Path to the object file
*/
public p ExternalLinkerInterface.addObjectFilePath(string objectFilePath) {
this.objectFilePaths.pushBack(objectFilePath);
}
/**
* Add another linker flag for the call to the linker executable
*
* @param linkerFlag Linker flag
*/
public p ExternalLinkerInterface.addLinkerFlag(string linkerFlag) {
this.linkerFlags.pushBack(linkerFlag);
}
/**
* Add another source file to compile and link in (C or C++)
*
* @param additionalSource Additional source file
*/
public p ExternalLinkerInterface.addAdditionalSourcePath(FilePath additionalSource) {
// Check if the file exists
if !additionalSource.exists() {
panic(Error("The additional source file '" + additionalSource.toGenericString() + "' does not exist"));
}
// Add the file to the linker
this.addObjectFilePath(additionalSource.toNativeString());
}