aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYannis Huber <[email protected]>2020-06-08 16:50:39 +0200
committerGitHub <[email protected]>2020-06-08 16:50:39 +0200
commitd3f5b51cd8cfe91fae69e198bd3e5a0c45638608 (patch)
tree166bc0c943f8b8cc87afbbc66a58d4ea81b0386a
parent2396c22658275c3df83ac24453e81fb5d252f5e6 (diff)
downloadtinygo-d3f5b51cd8cfe91fae69e198bd3e5a0c45638608.tar.gz
tinygo-d3f5b51cd8cfe91fae69e198bd3e5a0c45638608.zip
compiler: add support for custom code model
-rw-r--r--compileopts/config.go9
-rw-r--r--compileopts/target.go4
-rw-r--r--compiler/compiler.go20
3 files changed, 32 insertions, 1 deletions
diff --git a/compileopts/config.go b/compileopts/config.go
index f9fc01fe4..24a12a9f3 100644
--- a/compileopts/config.go
+++ b/compileopts/config.go
@@ -272,6 +272,15 @@ func (c *Config) OpenOCDConfiguration() (args []string, err error) {
return args, nil
}
+// CodeModel returns the code model used on this platform.
+func (c *Config) CodeModel() string {
+ if c.Target.CodeModel != "" {
+ return c.Target.CodeModel
+ }
+
+ return "default"
+}
+
type TestConfig struct {
CompileTestBinary bool
// TODO: Filter the test functions to run, include verbose flag, etc
diff --git a/compileopts/target.go b/compileopts/target.go
index 2071c73a5..5d5e2f1b3 100644
--- a/compileopts/target.go
+++ b/compileopts/target.go
@@ -49,6 +49,7 @@ type TargetSpec struct {
OpenOCDTarget string `json:"openocd-target"`
OpenOCDTransport string `json:"openocd-transport"`
JLinkDevice string `json:"jlink-device"`
+ CodeModel string `json:"code-model"`
}
// copyProperties copies all properties that are set in spec2 into itself.
@@ -130,6 +131,9 @@ func (spec *TargetSpec) copyProperties(spec2 *TargetSpec) {
if spec2.JLinkDevice != "" {
spec.JLinkDevice = spec2.JLinkDevice
}
+ if spec2.CodeModel != "" {
+ spec.CodeModel = spec2.CodeModel
+ }
}
// load reads a target specification from the JSON in the given io.Reader. It
diff --git a/compiler/compiler.go b/compiler/compiler.go
index d977e1a06..677128d0e 100644
--- a/compiler/compiler.go
+++ b/compiler/compiler.go
@@ -91,7 +91,25 @@ func NewTargetMachine(config *compileopts.Config) (llvm.TargetMachine, error) {
return llvm.TargetMachine{}, err
}
features := strings.Join(config.Features(), ",")
- machine := target.CreateTargetMachine(config.Triple(), config.CPU(), features, llvm.CodeGenLevelDefault, llvm.RelocStatic, llvm.CodeModelDefault)
+
+ var codeModel llvm.CodeModel
+
+ switch config.CodeModel() {
+ case "default":
+ codeModel = llvm.CodeModelDefault
+ case "tiny":
+ codeModel = llvm.CodeModelTiny
+ case "small":
+ codeModel = llvm.CodeModelSmall
+ case "kernel":
+ codeModel = llvm.CodeModelKernel
+ case "medium":
+ codeModel = llvm.CodeModelMedium
+ case "large":
+ codeModel = llvm.CodeModelLarge
+ }
+
+ machine := target.CreateTargetMachine(config.Triple(), config.CPU(), features, llvm.CodeGenLevelDefault, llvm.RelocStatic, codeModel)
return machine, nil
}