arm-asm: Implement asm_parse_regvar and asm_clobber

This commit is contained in:
Danny Milosavljevic 2020-12-26 16:21:58 +01:00
parent 4a6fb47b8d
commit f88ded6c2d
No known key found for this signature in database
GPG Key ID: E71A35542C30BAA5
4 changed files with 65 additions and 4 deletions

View File

@ -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)

View File

@ -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;
}
/*************************************************************/

29
arm-tok.h Normal file
View File

@ -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 */

View File

@ -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