mirror of
https://github.com/danog/ir.git
synced 2024-11-30 04:39:43 +01:00
Intoduce ir_emit.c that shuould keep common part for different targets
This commit is contained in:
parent
62c981a091
commit
1b84570aa3
4
.gitignore
vendored
4
.gitignore
vendored
@ -3,8 +3,8 @@
|
||||
*.dot
|
||||
*.pdf
|
||||
ir_fold_hash.h
|
||||
ir_x86.c
|
||||
ir_aarch64.c
|
||||
ir_emit_x86.h
|
||||
ir_emit_aarch64.h
|
||||
minilua
|
||||
gen_ir_fold_hash
|
||||
ir_test
|
||||
|
12
Makefile
12
Makefile
@ -41,13 +41,13 @@ endif
|
||||
all: $(BUILD_DIR)/ir $(BUILD_DIR)/ir_test
|
||||
|
||||
$(BUILD_DIR)/ir: $(BUILD_DIR)/ir_main.o $(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_$(DASM_ARCH).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 \
|
||||
$(BUILD_DIR)/ir_disasm.o $(BUILD_DIR)/ir_gdb.o $(BUILD_DIR)/ir_perf.o $(BUILD_DIR)/ir_check.o
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -lcapstone $^
|
||||
|
||||
$(BUILD_DIR)/ir_test: $(BUILD_DIR)/ir_test.o $(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_$(DASM_ARCH).o \
|
||||
$(BUILD_DIR)/ir_sccp.o $(BUILD_DIR)/ir_gcm.o $(BUILD_DIR)/ir_ra.o $(BUILD_DIR)/ir_emit.o \
|
||||
$(BUILD_DIR)/ir_save.o $(BUILD_DIR)/ir_dump.o $(BUILD_DIR)/ir_disasm.o $(BUILD_DIR)/ir_gdb.o \
|
||||
$(BUILD_DIR)/ir_perf.o $(BUILD_DIR)/ir_check.o
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -lcapstone $^
|
||||
@ -96,11 +96,11 @@ $(BUILD_DIR)/gen_ir_fold_hash: $(SRC_DIR)/gen_ir_fold_hash.c $(SRC_DIR)/ir_strta
|
||||
|
||||
$(BUILD_DIR)/minilua: $(SRC_DIR)/dynasm/minilua.c
|
||||
$(BUILD_CC) $(SRC_DIR)/dynasm/minilua.c -lm -o $@
|
||||
$(BUILD_DIR)/ir_$(DASM_ARCH).c: $(SRC_DIR)/ir_$(DASM_ARCH).dasc $(SRC_DIR)/dynasm/*.lua $(BUILD_DIR)/minilua
|
||||
$(BUILD_DIR)/ir_emit_$(DASM_ARCH).h: $(SRC_DIR)/ir_$(DASM_ARCH).dasc $(SRC_DIR)/dynasm/*.lua $(BUILD_DIR)/minilua
|
||||
$(BUILD_DIR)/minilua $(SRC_DIR)/dynasm/dynasm.lua $(DASM_FLAGS) -o $@ $(SRC_DIR)/ir_$(DASM_ARCH).dasc
|
||||
$(BUILD_DIR)/ir_$(DASM_ARCH).o: $(BUILD_DIR)/ir_$(DASM_ARCH).c $(SRC_DIR)/ir.h $(SRC_DIR)/ir_private.h \
|
||||
$(BUILD_DIR)/ir_emit.o: $(SRC_DIR)/ir_emit.c $(BUILD_DIR)/ir_emit_$(DASM_ARCH).h $(SRC_DIR)/ir.h $(SRC_DIR)/ir_private.h \
|
||||
$(SRC_DIR)/ir_$(DASM_ARCH).h
|
||||
$(CC) $(CFLAGS) -I$(SRC_DIR) -o $@ -c $<
|
||||
$(CC) $(CFLAGS) -I$(BUILD_DIR) -o $@ -c $<
|
||||
|
||||
test: $(BUILD_DIR)/ir
|
||||
$(BUILD_DIR)/ir $(SRC_DIR)/test.ir --dump --save 2>$(BUILD_DIR)/test.log
|
||||
@ -110,7 +110,7 @@ test: $(BUILD_DIR)/ir
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)/ir $(BUILD_DIR)/ir_test $(BUILD_DIR)/*.o \
|
||||
$(BUILD_DIR)/minilua $(BUILD_DIR)/ir_$(DASM_ARCH).c \
|
||||
$(BUILD_DIR)/minilua $(BUILD_DIR)/ir_emit_$(DASM_ARCH).h \
|
||||
$(BUILD_DIR)/ir_fold_hash.h $(BUILD_DIR)/gen_ir_fold_hash \
|
||||
$(BUILD_DIR)/ir.dot $(BUILD_DIR)/ir.pdf $(BUILD_DIR)/test.log
|
||||
find $(SRC_DIR)/tests -type f -name '*.diff' -delete
|
||||
|
@ -1,31 +1,3 @@
|
||||
#include "ir.h"
|
||||
#include "ir_aarch64.h"
|
||||
#include "ir_private.h"
|
||||
|
||||
#define DASM_M_GROW(ctx, t, p, sz, need) \
|
||||
do { \
|
||||
size_t _sz = (sz), _need = (need); \
|
||||
if (_sz < _need) { \
|
||||
if (_sz < 16) _sz = 16; \
|
||||
while (_sz < _need) _sz += _sz; \
|
||||
(p) = (t *)ir_mem_realloc((p), _sz); \
|
||||
(sz) = _sz; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define DASM_M_FREE(ctx, p, sz) ir_mem_free(p)
|
||||
|
||||
#if IR_DEBUG
|
||||
# define DASM_CHECKS
|
||||
#endif
|
||||
|
||||
#include "dynasm/dasm_proto.h"
|
||||
#include "dynasm/dasm_arm64.h"
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# pragma GCC diagnostic ignored "-Warray-bounds"
|
||||
#endif
|
||||
|
||||
|.arch arm64
|
||||
|
||||
|.actionlist dasm_actions
|
||||
|
38
ir_emit.c
Normal file
38
ir_emit.c
Normal file
@ -0,0 +1,38 @@
|
||||
#include "ir.h"
|
||||
|
||||
#define DASM_M_GROW(ctx, t, p, sz, need) \
|
||||
do { \
|
||||
size_t _sz = (sz), _need = (need); \
|
||||
if (_sz < _need) { \
|
||||
if (_sz < 16) _sz = 16; \
|
||||
while (_sz < _need) _sz += _sz; \
|
||||
(p) = (t *)ir_mem_realloc((p), _sz); \
|
||||
(sz) = _sz; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define DASM_M_FREE(ctx, p, sz) ir_mem_free(p)
|
||||
|
||||
#if IR_DEBUG
|
||||
# define DASM_CHECKS
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# pragma GCC diagnostic ignored "-Warray-bounds"
|
||||
#endif
|
||||
|
||||
#if defined(IR_TARGET_X86) || defined(IR_TARGET_X64)
|
||||
# include "ir_x86.h"
|
||||
# include "ir_private.h"
|
||||
# include "dynasm/dasm_proto.h"
|
||||
# include "dynasm/dasm_x86.h"
|
||||
# include "ir_emit_x86.h"
|
||||
#elif defined(IR_TARGET_AARCH64)
|
||||
# include "ir_aarch64.h"
|
||||
# include "ir_private.h"
|
||||
# include "dynasm/dasm_proto.h"
|
||||
# include "dynasm/dasm_arm64.h"
|
||||
# include "ir_emit_aarch64.h"
|
||||
#else
|
||||
# error "Unknown IR target"
|
||||
#endif
|
28
ir_x86.dasc
28
ir_x86.dasc
@ -1,31 +1,3 @@
|
||||
#include "ir.h"
|
||||
#include "ir_x86.h"
|
||||
#include "ir_private.h"
|
||||
|
||||
#define DASM_M_GROW(ctx, t, p, sz, need) \
|
||||
do { \
|
||||
size_t _sz = (sz), _need = (need); \
|
||||
if (_sz < _need) { \
|
||||
if (_sz < 16) _sz = 16; \
|
||||
while (_sz < _need) _sz += _sz; \
|
||||
(p) = (t *)ir_mem_realloc((p), _sz); \
|
||||
(sz) = _sz; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define DASM_M_FREE(ctx, p, sz) ir_mem_free(p)
|
||||
|
||||
#if IR_DEBUG
|
||||
# define DASM_CHECKS
|
||||
#endif
|
||||
|
||||
#include "dynasm/dasm_proto.h"
|
||||
#include "dynasm/dasm_x86.h"
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# pragma GCC diagnostic ignored "-Warray-bounds"
|
||||
#endif
|
||||
|
||||
|.if X64
|
||||
|.arch x64
|
||||
|.else
|
||||
|
Loading…
Reference in New Issue
Block a user