diff --git a/Makefile b/Makefile index 619b708b..2bca9607 100644 --- a/Makefile +++ b/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 $@ $^ diff --git a/compiler.go b/compiler.go index 20a3dba9..12290c4e 100644 --- a/compiler.go +++ b/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) diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h deleted file mode 100644 index 21ea1ce7..00000000 --- a/src/runtime/runtime.h +++ /dev/null @@ -1,13 +0,0 @@ - -#pragma once - -#include - -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(); diff --git a/src/runtime/runtime.ll b/src/runtime/runtime.ll deleted file mode 100644 index 2770c174..00000000 --- a/src/runtime/runtime.ll +++ /dev/null @@ -1,3 +0,0 @@ -source_filename = "runtime/runtime.ll" - -; dummy file