translator: plain function call fix; minor fixes

This commit is contained in:
e5l
2016-07-13 14:14:45 +03:00
parent 8e03cebe9b
commit d54ef1d3c5
5 changed files with 51 additions and 86 deletions
-82
View File
@@ -1,82 +0,0 @@
BIN_DIR=$(PWD)/bin
SRC_DIR=$(PWD)/src
LIB_DIR=$(SRC_DIR)/lib
OS_ARCH=linux-arm
LIB_CMSIS_DIR=$(LIB_DIR)/cmsis
LIB_STDPERIPH_DIR=$(LIB_DIR)/stdperiph
LIB_STM32F4D_DIR=$(LIB_DIR)/stm32f4d
LIB_CMSIS_OBJ=$(BIN_DIR)/libcmsis.o
LIB_STDPERIPH_OBJ=$(BIN_DIR)/libstdperiph.o
LIB_STM32F4D_OBJ=$(BIN_DIR)/libstm32f4d.o
CAR_FMW_OBJ=$(BIN_DIR)/car_fmw.o
CAR_FMW_ELF=$(BIN_DIR)/car_fmw.elf
CAR_FMW_BIN=$(BIN_DIR)/car_fmw.bin
ST_DIR=$(SRC_DIR)/../../devloader/data/$(OS_ARCH)
LIB_KOTLIN=$(PWD)/bin/kotlib.o
CC=arm-none-eabi-gcc
AS=arm-none-eabi-as
LD=arm-none-eabi-ld
OBJ_COPY=arm-none-eabi-objcopy
GDB=arm-none-eabi-gdb
INCLUDES=-I$(LIB_CMSIS_DIR) \
-I$(LIB_STDPERIPH_DIR) \
-I$(LIB_STM32F4D_DIR) \
-I$(SRC_DIR)
DEFINES=-DUSE_STM32_DISCOVERY=1 -DUSE_STDPERIPH_DRIVER=1 -DSTM32F4XX=1 -DHSE_VALUE=8000000
CFLAGS=-g -nostdlib -ffreestanding -O0 \
-mcpu=cortex-m3 -mfloat-abi=soft -mthumb \
$(DEFINES)
ASMFLAGS=-g -mthumb
LD_ALL_DEPS=$(LD) -r $(filter %.o,$^) -o $@
CC_ALL_DEPS=$(CC) $(CFLAGS) -c $(INCLUDES) $(filter %.c,$^) -o $@
AS_ALL_DEPS=$(AS) $(ASMFLAGS) $(filter %.s,$^) -o $@
dirhs=$(wildcard $(1)/*.h)
dircs=$(wildcard $(1)/*.c)
dircs_to_prefxd_objs=\
$(patsubst $(1)/%.c,$(BIN_DIR)/$(2)%.o,$(call dircs,$1))
$(CAR_FMW_BIN): $(CAR_FMW_ELF) $(BIN_DIR)
$(OBJ_COPY) -O binary $< $@
$(CAR_FMW_ELF): $(CAR_FMW_OBJ) $(LIB_STM32F4D_OBJ) \
$(LIB_CMSIS_OBJ) $(LIB_STDPERIPH_OBJ)
make -C kotlib
$(CC) $(CFLAGS) $^ $(LIB_KOTLIN) -T $(SRC_DIR)/stm32_flash.ld -o $@
CAR_OBJ_PREFIX=car_
$(CAR_FMW_OBJ): \
$(call dircs_to_prefxd_objs,$(SRC_DIR),$(CAR_OBJ_PREFIX))
$(LD_ALL_DEPS)
$(BIN_DIR)/$(CAR_OBJ_PREFIX)%.o: $(SRC_DIR)/%.c \
$(call dirhs,$(SRC_DIR))
$(CC_ALL_DEPS)
$(BIN_DIR):
mkdir -p $(BIN_DIR)
flash: $(CAR_FMW_BIN)
$(ST_DIR)/st-flash write $(CAR_FMW_BIN) 0x8000000
debug:
-killall st-util
(setsid $(ST_DIR)/st-util 2>/dev/null 1>&2)&
$(GDB) $(CAR_FMW_ELF) -x $(ST_DIR)/../gdb.cmds
clean:
rm -rf bin/*
tags:
ctags -R *
include $(LIB_DIR)/**/Makefile
.PHONY: clean debug flash tags
+36 -1
View File
@@ -1,6 +1,41 @@
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1)
attributes #0 = { nounwind "stack-protector-buffer-size"="8" "target-cpu"="cortex-m3" "target-features"="+hwdiv,+strict-align" }
define void @kotlin_main() #0
declare void @wait(i32 %loops) #0
define void @program_forward() #0
{
call void @engine_forward()
call void @wait(i32 10)
ret void
}
declare void @leds_init() #0
declare void @engine_init() #0
define void @program_backward() #0
{
call void @engine_backward()
call void @wait(i32 10)
ret void
}
declare void @engine_backward() #0
define void @program_rotation_left() #0
{
call void @engine_turn_left()
call void @wait(i32 10)
ret void
}
define void @kotlin_main() #0
{
call void @leds_init()
call void @engine_init()
ret void
}
declare void @engine_stop() #0
declare void @engine_forward() #0
define void @program_rotation_right() #0
{
call void @engine_turn_right()
call void @wait(i32 10)
ret void
}
declare void @engine_turn_left() #0
declare void @engine_turn_right() #0
+8
View File
@@ -1,5 +1,13 @@
#include <stddef.h>
#include "car_leds.h"
#include "car_engine.h"
#include "car_user_btn.h"
#include "wait.h"
extern void kotlin_main();
int main(void)
{
kotlin_main();
}
@@ -37,7 +37,7 @@ class FunctionCodegen(val state: TranslationState, val function: KtNamedFunction
codeBuilder.addStartExpression()
generateLoadArguments()
evaluateCodeBlock(function.bodyExpression, startLabel = null, finishLabel = null, scopeDepth = 0)
evaluateCodeBlock(function.bodyExpression)
if (returnType is LLVMVoidType) {
@@ -72,7 +72,7 @@ class FunctionCodegen(val state: TranslationState, val function: KtNamedFunction
}
}
private fun evaluateCodeBlock(expr: PsiElement?, startLabel: LLVMLabel?, finishLabel: LLVMLabel?, scopeDepth: Int) {
private fun evaluateCodeBlock(expr: PsiElement?, startLabel: LLVMLabel? = null, finishLabel: LLVMLabel? = null, scopeDepth: Int = 0) {
codeBuilder.markWithLabel(startLabel)
expressionWalker(expr, scopeDepth)
codeBuilder.addUnconditionJump(finishLabel ?: return)
@@ -83,6 +83,10 @@ class FunctionCodegen(val state: TranslationState, val function: KtNamedFunction
is KtBlockExpression -> expressionWalker(expr.firstChild, scopeDepth + 1)
is KtProperty -> evaluateLeafPsiElement(expr.firstChild as LeafPsiElement, scopeDepth)
is KtBinaryExpression -> evaluateBinaryExpression(expr, scopeDepth)
is KtCallExpression -> {
val expression = evaluateCallExpression(expr) as LLVMCall
codeBuilder.addLLVMCode(expression.toString())
}
is PsiElement -> evaluateExpression(expr.firstChild, scopeDepth + 1)
null -> {
variableManager.pullUpwardsLevel(scopeDepth)
@@ -7,7 +7,7 @@ fun LLVMFunctionDescriptor(name: String, argTypes: List<LLVMVariable>?, returnTy
"${if (declare) "declare" else "define"} $returnType @$name(${
argTypes?.mapIndexed { i: Int, s: LLVMVariable ->
"${s.getType()} %${s.label}"
}?.joinToString() }) ${ if (arm) "#0 " else ""}"
}?.joinToString() }) ${ if (arm) "#0" else ""}"
fun LLVMMapStandardType(type: String): LLVMType = when (type) {
"Int" -> LLVMIntType()