Reduce code size for AVR (#116)
* all: add support for specifying target CPU in target config * avr: specify the chip name in the target CPU This reduces code size by a large margin. For examples/blinky, it reduces code size from 1360 to 1266 when compiling for the Arduino Uno (94 bytes, or ~7%).
Этот коммит содержится в:
родитель
a8dd82538e
коммит
873c1c3b4d
5 изменённых файлов: 9 добавлений и 1 удалений
|
@ -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()
|
||||
|
|
1
main.go
1
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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"inherits": ["avr"],
|
||||
"llvm-target": "avr-atmel-none",
|
||||
"cpu": "atmega328p",
|
||||
"build-tags": ["arduino", "atmega328p", "atmega", "avr5"],
|
||||
"cflags": [
|
||||
"-mmcu=atmega328p"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"inherits": ["avr"],
|
||||
"llvm-target": "avr-atmel-none",
|
||||
"cpu": "attiny85",
|
||||
"build-tags": ["digispark", "attiny85", "attiny", "avr2", "avr25"],
|
||||
"cflags": [
|
||||
"-mmcu=attiny85"
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче