Browse Source

all: remove last traces of the C runtime

This increases code size on the nrf, but it is a fixed increase and can
hopefully be reduced in the future.
The Makefile gets a lot smaller with this which is a huge advantage
(less build time complexity).
pull/6/head
Ayke van Laethem 6 years ago
parent
commit
8ce139284a
No known key found for this signature in database GPG Key ID: E97FF5335DFDFDED
  1. 29
      Makefile
  2. 2
      compiler.go
  3. 13
      src/runtime/runtime.h
  4. 3
      src/runtime/runtime.ll

29
Makefile

@ -5,17 +5,9 @@ tgo: build/tgo
.PHONY: all tgo run-test run-blinky run-blinky2 clean fmt gen-device gen-device-nrf
# Custom LLVM toolchain.
LLVM := $(shell go env GOPATH)/src/github.com/aykevl/llvm/bindings/go/llvm/workdir/llvm_build/bin/
LINK = $(LLVM)llvm-link
LLAS = $(LLVM)llvm-as
OPT = $(LLVM)opt
CFLAGS = -Wall -Werror -Os -fno-exceptions -flto -ffunction-sections -fdata-sections $(LLFLAGS)
CFLAGS = -Wall -Werror -Os -fno-exceptions -ffunction-sections -fdata-sections $(LLFLAGS)
CFLAGS += -fno-exceptions -fno-unwind-tables # Avoid .ARM.exidx etc.
RUNTIME_PARTS = build/runtime.bc
TARGET ?= unix
ifeq ($(TARGET),unix)
@ -30,13 +22,10 @@ SIZE = arm-none-eabi-size
OBJCOPY = arm-none-eabi-objcopy
LLFLAGS += -target armv7m-none-eabi
TGOFLAGS += -target $(TARGET)
CFLAGS += -I$(CURDIR)/src/runtime
CFLAGS += -I$(CURDIR)/lib/nrfx
CFLAGS += -I$(CURDIR)/lib/nrfx/mdk
CFLAGS += -I$(CURDIR)/lib/CMSIS/CMSIS/Include
CFLAGS += -DNRF52832_XXAA
CFLAGS += -Wno-uninitialized
RUNTIME_PARTS += build/nrfx_system_nrf52.bc
OBJ += build/nrfx_system_nrf52.o
OBJ += build/nrfx_startup_nrf51.o # TODO nrf52, see https://bugs.llvm.org/show_bug.cgi?id=31601
else ifeq ($(TARGET),arduino)
@ -94,15 +83,11 @@ build/tgo: *.go
go build -o build/tgo -i .
# Build IR with the Go compiler.
build/%.o: src/examples/% src/examples/%/*.go build/tgo src/runtime/*.go build/runtime-$(TARGET)-combined.bc
./build/tgo build $(TGOFLAGS) -runtime build/runtime-$(TARGET)-combined.bc -o $@ $(subst src/,,$<)
# Compile LLVM bitcode from LLVM source.
build/%.bc: src/runtime/%.ll
$(LLAS) -o $@ $<
build/%.o: src/examples/% src/examples/%/*.go build/tgo src/runtime/*.go
./build/tgo build $(TGOFLAGS) -o $@ $(subst src/,,$<)
# Compile system_* file for the nRF.
build/nrfx_%.bc: lib/nrfx/mdk/%.c
build/nrfx_%.o: lib/nrfx/mdk/%.c
@mkdir -p build
clang $(CFLAGS) -c -o $@ $^
@ -114,10 +99,6 @@ build/nrfx_%.o: lib/nrfx/mdk/gcc_%.S
build/%.o: %.S
$(AS) -o $@ $^
# Merge all runtime LLVM files together in a single bitcode file.
build/runtime-$(TARGET)-combined.bc: $(RUNTIME_PARTS)
$(LINK) -o $@ $^
# Generate output ELF executable.
build/%: build/%.o $(OBJ)
$(LD) -o $@ $^

2
compiler.go

@ -96,6 +96,8 @@ func NewCompiler(pkgName, triple string, dumpSSA bool) (*Compiler, error) {
c.targetData = c.machine.CreateTargetData()
c.mod = llvm.NewModule(pkgName)
c.mod.SetTarget(triple)
c.mod.SetDataLayout(c.targetData.String())
c.ctx = c.mod.Context()
c.builder = c.ctx.NewBuilder()
c.dibuilder = llvm.NewDIBuilder(c.mod)

13
src/runtime/runtime.h

@ -1,13 +0,0 @@
#pragma once
#include <stdint.h>
typedef struct {
uint32_t len; // TODO: size_t (or, let max string size depend on target/flag)
uint8_t *buf; // points to string buffer itself
} string_t;
typedef int32_t intgo_t; // may be 64-bit
int main();

3
src/runtime/runtime.ll

@ -1,3 +0,0 @@
source_filename = "runtime/runtime.ll"
; dummy file
Loading…
Cancel
Save