History

arm-asm: Implement asm_parse_regvar and asm_clobber

Danny Milosavljevic committed 5 years ago

Commit f88ded61 parent 4a6fb474 files · +65 −4Browse files

Unified · Split

4 files
  1. Makefile +1 −1
  2. arm-asm.c +32 −3
  3. arm-tok.h +29 −0
  4. tcctok.h +3 −0
Makefile+1−1
@@ -179,7 +179,7 @@ i386-win32_FILES = $(i386_FILES) tccpe.c · 178 unmodified lines
179179 x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
180180 x86_64-win32_FILES = $(x86_64_FILES) tccpe.c
181181 x86_64-osx_FILES = $(x86_64_FILES) tccmacho.c
182−arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c
182+arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c arm-tok.h
183183 arm-wince_FILES = $(arm_FILES) tccpe.c
184184 arm-eabihf_FILES = $(arm_FILES)
185185 arm-fpa_FILES = $(arm_FILES)
arm-asm.c+32−3
@@ -81,13 +81,42 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands, · 80 unmodified lines
8181
8282 ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
8383 {
84− asm_error();
84+ int reg;
85+ TokenSym *ts;
86+
87+ if (!strcmp(str, "memory") ||
88+ !strcmp(str, "cc") ||
89+ !strcmp(str, "flags"))
90+ return;
91+ ts = tok_alloc(str, strlen(str));
92+ reg = asm_parse_regvar(ts->tok);
93+ if (reg == -1) {
94+ tcc_error("invalid clobber register '%s'", str);
95+ }
96+ clobber_regs[reg] = 1;
8597 }
8698
99+/* If T refers to a register then return the register number and type.
100+ Otherwise return -1. */
87101 ST_FUNC int asm_parse_regvar (int t)
88102 {
89− asm_error();
90− return -1;
103+ if (t >= TOK_ASM_r0 && t <= TOK_ASM_pc) { /* register name */
104+ switch (t) {
105+ case TOK_ASM_fp:
106+ return TOK_ASM_r11 - TOK_ASM_r0;
107+ case TOK_ASM_ip:
108+ return TOK_ASM_r12 - TOK_ASM_r0;
109+ case TOK_ASM_sp:
110+ return TOK_ASM_r13 - TOK_ASM_r0;
111+ case TOK_ASM_lr:
112+ return TOK_ASM_r14 - TOK_ASM_r0;
113+ case TOK_ASM_pc:
114+ return TOK_ASM_r15 - TOK_ASM_r0;
115+ default:
116+ return t - TOK_ASM_r0;
117+ }
118+ } else
119+ return -1;
91120 }
92121
93122 /*************************************************************/
arm-tok.h+29−0
@@ -0,0 +1,29 @@
1+/* ------------------------------------------------------------------ */
2+/* WARNING: relative order of tokens is important. */
3+
4+/* register */
5+
6+ DEF_ASM(r0)
7+ DEF_ASM(r1)
8+ DEF_ASM(r2)
9+ DEF_ASM(r3)
10+ DEF_ASM(r4)
11+ DEF_ASM(r5)
12+ DEF_ASM(r6)
13+ DEF_ASM(r7)
14+ DEF_ASM(r8)
15+ DEF_ASM(r9)
16+ DEF_ASM(r10)
17+ DEF_ASM(r11) /* fp */
18+ DEF_ASM(r12) /* ip[c] */
19+ DEF_ASM(r13) /* sp */
20+ DEF_ASM(r14) /* lr */
21+ DEF_ASM(r15) /* pc */
22+
23+/* register macros */
24+
25+ DEF_ASM(fp) /* alias for r11 */
26+ DEF_ASM(ip) /* alias for r12 */
27+ DEF_ASM(sp) /* alias for r13 */
28+ DEF_ASM(lr) /* alias for r14 */
29+ DEF_ASM(pc) /* alias for r15 */
tcctok.h+3−0
@@ -370,3 +370,6 @@ · 369 unmodified lines
370370 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
371371 #include "i386-tok.h"
372372 #endif
373+#if defined TCC_TARGET_ARM
374+#include "arm-tok.h"
375+#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t