Skip to content

Commit d3f5b51

Browse files
authored
compiler: add support for custom code model
1 parent 2396c22 commit d3f5b51

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

compileopts/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ func (c *Config) OpenOCDConfiguration() (args []string, err error) {
272272
return args, nil
273273
}
274274

275+
// CodeModel returns the code model used on this platform.
276+
func (c *Config) CodeModel() string {
277+
if c.Target.CodeModel != "" {
278+
return c.Target.CodeModel
279+
}
280+
281+
return "default"
282+
}
283+
275284
type TestConfig struct {
276285
CompileTestBinary bool
277286
// TODO: Filter the test functions to run, include verbose flag, etc

compileopts/target.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type TargetSpec struct {
4949
OpenOCDTarget string `json:"openocd-target"`
5050
OpenOCDTransport string `json:"openocd-transport"`
5151
JLinkDevice string `json:"jlink-device"`
52+
CodeModel string `json:"code-model"`
5253
}
5354

5455
// copyProperties copies all properties that are set in spec2 into itself.
@@ -130,6 +131,9 @@ func (spec *TargetSpec) copyProperties(spec2 *TargetSpec) {
130131
if spec2.JLinkDevice != "" {
131132
spec.JLinkDevice = spec2.JLinkDevice
132133
}
134+
if spec2.CodeModel != "" {
135+
spec.CodeModel = spec2.CodeModel
136+
}
133137
}
134138

135139
// load reads a target specification from the JSON in the given io.Reader. It

compiler/compiler.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,25 @@ func NewTargetMachine(config *compileopts.Config) (llvm.TargetMachine, error) {
9191
return llvm.TargetMachine{}, err
9292
}
9393
features := strings.Join(config.Features(), ",")
94-
machine := target.CreateTargetMachine(config.Triple(), config.CPU(), features, llvm.CodeGenLevelDefault, llvm.RelocStatic, llvm.CodeModelDefault)
94+
95+
var codeModel llvm.CodeModel
96+
97+
switch config.CodeModel() {
98+
case "default":
99+
codeModel = llvm.CodeModelDefault
100+
case "tiny":
101+
codeModel = llvm.CodeModelTiny
102+
case "small":
103+
codeModel = llvm.CodeModelSmall
104+
case "kernel":
105+
codeModel = llvm.CodeModelKernel
106+
case "medium":
107+
codeModel = llvm.CodeModelMedium
108+
case "large":
109+
codeModel = llvm.CodeModelLarge
110+
}
111+
112+
machine := target.CreateTargetMachine(config.Triple(), config.CPU(), features, llvm.CodeGenLevelDefault, llvm.RelocStatic, codeModel)
95113
return machine, nil
96114
}
97115

0 commit comments

Comments
 (0)