[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] [PATCH 02/16] arm-asm: Implement asm_parse_regvar and asm
From: |
Danny Milosavljevic |
Subject: |
[Tinycc-devel] [PATCH 02/16] arm-asm: Implement asm_parse_regvar and asm_clobber |
Date: |
Sat, 26 Dec 2020 22:58:03 +0100 |
---
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 d41b81a..fcdc550 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 f09f003..6015d55 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 0000000..5523299
--- /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 af8aa9b..aeac1cd 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
- [Tinycc-devel] [PATCH 09/16] arm-asm: Add swi, (continued)
- [Tinycc-devel] [PATCH 09/16] arm-asm: Add swi, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 07/16] arm-asm: Add parse_operand, Operand, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 10/16] arm-asm: Add clz, sxtb, sxth, uxtb, uxth, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 12/16] arm-asm: Add stmda, ldmda, stm, ldm, stmia, ldmia, stmdb, ldmdb, stmib, ldmib, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 11/16] arm-asm: Add mul, mla, smull, umull, smlal, umlal, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 13/16] arm-asm: Add ldr, ldrb, str, strb, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 16/16] arm-asm: Optimize gen_le32, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 15/16] arm-asm: Add b, bl, bx, blx, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 14/16] arm-asm: Add and, eor, sub, rsb, add, adc, sbc, rsc, tst, teq, cmp, cmn, orr, mov, bic, mvn, Danny Milosavljevic, 2020/12/26
- Re: [Tinycc-devel] [PATCH 00/16] Add ARM inline assembler, Danny Milosavljevic, 2020/12/26
- [Tinycc-devel] [PATCH 02/16] arm-asm: Implement asm_parse_regvar and asm_clobber,
Danny Milosavljevic <=
- [Tinycc-devel] [PATCH 04/16] arm-asm: Remove asm_error, Danny Milosavljevic, 2020/12/26
- Re: [Tinycc-devel] [PATCH 00/16] Add ARM inline assembler, Jan Nieuwenhuizen, 2020/12/27
- Re: [Tinycc-devel] [PATCH 00/16] Add ARM inline assembler, Michael Matz, 2020/12/27