diff --git a/.gitignore b/.gitignore index 7d504ac..ae8f31e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ ir_fold_hash.h ir_emit_x86.h ir_emit_aarch64.h +ir_emit_riscv64.h minilua gen_ir_fold_hash ir_test diff --git a/Makefile b/Makefile index 8369954..769a6b6 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -# TRAGET may be "x86_64" or "x86" or "aarch64" -TARGET = x86_64 +# TRAGET may be "x86_64" or "x86" or "aarch64" or "riscv64" +TARGET = riscv64 # BUILD can be "debug" or "release" BUILD = debug BUILD_DIR = . @@ -40,6 +40,13 @@ ifeq (aarch64, $(TARGET)) DASM_FLAGS = endif +ifeq (riscv64, $(TARGET)) + CC= riscv64-linux-gnu-gcc --sysroot=$(HOME)/php/RISCV64 + CFLAGS += -DIR_TARGET_RISCV64 + DASM_ARCH = riscv64 + DASM_FLAGS = +endif + OBJS_COMMON = $(BUILD_DIR)/ir.o $(BUILD_DIR)/ir_strtab.o $(BUILD_DIR)/ir_cfg.o \ $(BUILD_DIR)/ir_sccp.o $(BUILD_DIR)/ir_gcm.o $(BUILD_DIR)/ir_ra.o $(BUILD_DIR)/ir_emit.o \ $(BUILD_DIR)/ir_load.o $(BUILD_DIR)/ir_save.o $(BUILD_DIR)/ir_emit_c.o $(BUILD_DIR)/ir_dump.o \ diff --git a/ir.h b/ir.h index 283c4f5..00ad0c9 100644 --- a/ir.h +++ b/ir.h @@ -46,6 +46,8 @@ extern "C" { # endif #elif defined(IR_TARGET_AARCH64) # define IR_TARGET "aarch64" +#elif defined(IR_TARGET_RISCV64) +# define IR_TARGET "riscv64" #else # error "Unknown IR target" #endif diff --git a/ir_emit.c b/ir_emit.c index 63ea4c6..f439729 100644 --- a/ir_emit.c +++ b/ir_emit.c @@ -11,6 +11,8 @@ # include "ir_x86.h" #elif defined(IR_TARGET_AARCH64) # include "ir_aarch64.h" +#elif defined(IR_TARGET_RISCV64) +# include "ir_riscv.h" #else # error "Unknown IR target" #endif @@ -326,6 +328,9 @@ static void *ir_jmp_addr(ir_ctx *ctx, ir_insn *insn, ir_insn *addr_insn) #elif defined(IR_TARGET_AARCH64) # include "dynasm/dasm_proto.h" # include "dynasm/dasm_arm64.h" +#elif defined(IR_TARGET_RISCV64) +# include "dynasm/dasm_proto.h" +# include "dynasm/dasm_riscv64.h" #else # error "Unknown IR target" #endif @@ -343,6 +348,8 @@ static void ir_emit_dessa_moves(ir_ctx *ctx, int b, ir_block *bb); # include "ir_emit_x86.h" #elif defined(IR_TARGET_AARCH64) # include "ir_emit_aarch64.h" +#elif defined(IR_TARGET_RISCV64) +# include "ir_emit_riscv64.h" #else # error "Unknown IR target" #endif diff --git a/ir_gdb.c b/ir_gdb.c index d83aee6..aa467b2 100644 --- a/ir_gdb.c +++ b/ir_gdb.c @@ -154,6 +154,8 @@ static const ir_elf_header ir_elfhdr_template = { .machine = 62, #elif defined(IR_TARGET_AARCH64) .machine = 183, +#elif defined(IR_TARGET_RISCV64) + .machine = 243, #else # error "Unsupported target architecture" #endif diff --git a/ir_ra.c b/ir_ra.c index 22fa88c..0f1e3d0 100644 --- a/ir_ra.c +++ b/ir_ra.c @@ -21,6 +21,8 @@ # include "ir_x86.h" #elif defined(IR_TARGET_AARCH64) # include "ir_aarch64.h" +#elif defined(IR_TARGET_RISCV64) +# include "ir_riscv64.h" #else # error "Unknown IR target" #endif