From f88ded6c2d771baa7322aaa597f0074b04eefa4d Mon Sep 17 00:00:00 2001 From: Danny Milosavljevic Date: Sat, 26 Dec 2020 16:21:58 +0100 Subject: [PATCH] arm-asm: Implement asm_parse_regvar and asm_clobber --- Makefile | 2 +- arm-asm.c | 35 ++++++++++++++++++++++++++++++++--- arm-tok.h | 29 +++++++++++++++++++++++++++++ tcctok.h | 3 +++ 4 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 arm-tok.h diff --git a/Makefile b/Makefile index 19530407..c0cca8c0 100644 --- a/Makefile +++ b/Makefile @@ -179,7 +179,7 @@ i386-win32_FILES = $(i386_FILES) tccpe.c x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h x86_64-win32_FILES = $(x86_64_FILES) tccpe.c x86_64-osx_FILES = $(x86_64_FILES) tccmacho.c -arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c +arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c arm-tok.h arm-wince_FILES = $(arm_FILES) tccpe.c arm-eabihf_FILES = $(arm_FILES) arm-fpa_FILES = $(arm_FILES) diff --git a/arm-asm.c b/arm-asm.c index f09f0032..6015d550 100644 --- a/arm-asm.c +++ b/arm-asm.c @@ -81,13 +81,42 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands, ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) { - asm_error(); + int reg; + TokenSym *ts; + + if (!strcmp(str, "memory") || + !strcmp(str, "cc") || + !strcmp(str, "flags")) + return; + ts = tok_alloc(str, strlen(str)); + reg = asm_parse_regvar(ts->tok); + if (reg == -1) { + tcc_error("invalid clobber register '%s'", str); + } + clobber_regs[reg] = 1; } +/* If T refers to a register then return the register number and type. + Otherwise return -1. */ ST_FUNC int asm_parse_regvar (int t) { - asm_error(); - return -1; + if (t >= TOK_ASM_r0 && t <= TOK_ASM_pc) { /* register name */ + switch (t) { + case TOK_ASM_fp: + return TOK_ASM_r11 - TOK_ASM_r0; + case TOK_ASM_ip: + return TOK_ASM_r12 - TOK_ASM_r0; + case TOK_ASM_sp: + return TOK_ASM_r13 - TOK_ASM_r0; + case TOK_ASM_lr: + return TOK_ASM_r14 - TOK_ASM_r0; + case TOK_ASM_pc: + return TOK_ASM_r15 - TOK_ASM_r0; + default: + return t - TOK_ASM_r0; + } + } else + return -1; } /*************************************************************/ diff --git a/arm-tok.h b/arm-tok.h new file mode 100644 index 00000000..55232997 --- /dev/null +++ b/arm-tok.h @@ -0,0 +1,29 @@ +/* ------------------------------------------------------------------ */ +/* WARNING: relative order of tokens is important. */ + +/* register */ + + DEF_ASM(r0) + DEF_ASM(r1) + DEF_ASM(r2) + DEF_ASM(r3) + DEF_ASM(r4) + DEF_ASM(r5) + DEF_ASM(r6) + DEF_ASM(r7) + DEF_ASM(r8) + DEF_ASM(r9) + DEF_ASM(r10) + DEF_ASM(r11) /* fp */ + DEF_ASM(r12) /* ip[c] */ + DEF_ASM(r13) /* sp */ + DEF_ASM(r14) /* lr */ + DEF_ASM(r15) /* pc */ + +/* register macros */ + + DEF_ASM(fp) /* alias for r11 */ + DEF_ASM(ip) /* alias for r12 */ + DEF_ASM(sp) /* alias for r13 */ + DEF_ASM(lr) /* alias for r14 */ + DEF_ASM(pc) /* alias for r15 */ diff --git a/tcctok.h b/tcctok.h index af8aa9b1..aeac1cd5 100644 --- a/tcctok.h +++ b/tcctok.h @@ -370,3 +370,6 @@ #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 #include "i386-tok.h" #endif +#if defined TCC_TARGET_ARM +#include "arm-tok.h" +#endif