diff --git a/compiler/compiler.go b/compiler/compiler.go index bb2ddc61..4834c19c 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -31,6 +31,7 @@ func init() { // Configure the compiler. type Config struct { Triple string // LLVM target triple, e.g. x86_64-unknown-linux-gnu (empty string means default) + CPU string // LLVM CPU name, e.g. atmega328p (empty string means default) GC string // garbage collection strategy CFlags []string // cflags to pass to cgo LDFlags []string // ldflags to pass to cgo @@ -108,7 +109,7 @@ func NewCompiler(pkgName string, config Config) (*Compiler, error) { if err != nil { return nil, err } - c.machine = target.CreateTargetMachine(config.Triple, "", "", llvm.CodeGenLevelDefault, llvm.RelocStatic, llvm.CodeModelDefault) + c.machine = target.CreateTargetMachine(config.Triple, config.CPU, "", llvm.CodeGenLevelDefault, llvm.RelocStatic, llvm.CodeModelDefault) c.targetData = c.machine.CreateTargetData() c.ctx = llvm.NewContext() diff --git a/main.go b/main.go index 6ae18248..c66ec838 100644 --- a/main.go +++ b/main.go @@ -51,6 +51,7 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act compilerConfig := compiler.Config{ Triple: spec.Triple, + CPU: spec.CPU, GC: config.gc, CFlags: spec.CFlags, LDFlags: spec.LDFlags, diff --git a/target.go b/target.go index 21286c3a..898646c4 100644 --- a/target.go +++ b/target.go @@ -20,6 +20,7 @@ import ( type TargetSpec struct { Inherits []string `json:"inherits"` Triple string `json:"llvm-target"` + CPU string `json:"cpu"` BuildTags []string `json:"build-tags"` GC string `json:"gc"` Compiler string `json:"compiler"` @@ -44,6 +45,9 @@ func (spec *TargetSpec) copyProperties(spec2 *TargetSpec) { if spec2.Triple != "" { spec.Triple = spec2.Triple } + if spec2.CPU != "" { + spec.CPU = spec2.CPU + } spec.BuildTags = append(spec.BuildTags, spec2.BuildTags...) if spec2.GC != "" { spec.GC = spec2.GC diff --git a/targets/arduino.json b/targets/arduino.json index 20e592be..f26fcc0e 100644 --- a/targets/arduino.json +++ b/targets/arduino.json @@ -1,6 +1,7 @@ { "inherits": ["avr"], "llvm-target": "avr-atmel-none", + "cpu": "atmega328p", "build-tags": ["arduino", "atmega328p", "atmega", "avr5"], "cflags": [ "-mmcu=atmega328p" diff --git a/targets/digispark.json b/targets/digispark.json index 6c198f4f..290f1649 100644 --- a/targets/digispark.json +++ b/targets/digispark.json @@ -1,6 +1,7 @@ { "inherits": ["avr"], "llvm-target": "avr-atmel-none", + "cpu": "attiny85", "build-tags": ["digispark", "attiny85", "attiny", "avr2", "avr25"], "cflags": [ "-mmcu=attiny85"