aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Chambers <[email protected]>2021-10-19 14:03:50 +1300
committerAndrew Chambers <[email protected]>2021-10-19 14:03:50 +1300
commit56e797b4845e436a198cc8bbd1bbdf393cd71b13 (patch)
tree2a01c237f7030eee43aa98a3be9da2593bc7195f
parent960773e6ad79ccc9fc8dfb1aee835239731a3b2a (diff)
Minor refactor and tidy.
-rw-r--r--asm.peg66
-rw-r--r--main.c9
-rw-r--r--parse.c1
3 files changed, 35 insertions, 41 deletions
diff --git a/asm.peg b/asm.peg
index e922a83..f5abbfb 100644
--- a/asm.peg
+++ b/asm.peg
@@ -97,38 +97,40 @@ instr =
| i:cltd { $$ = i; }
| i:cqto { $$ = i; }))
| (& 's'
- (
- i:set { $$ = i; }
- | i:sub { $$ = i; }
- | i:sal { $$ = i; }
- | i:sar { $$ = i; }
- | i:shl { $$ = i; }
- | i:shr { $$ = i; }
- | i:subsd { $$ = i; }
- | i:subss { $$ = i; }))
- | i:or { $$ = i; }
- | i:leave { $$ = i; }
- | i:ret { $$ = i; }
- | i:push { $$ = i; }
- | i:pop { $$ = i; }
- | i:jmp { $$ = i; }
- | i:div { $$ = i; }
- | i:idiv { $$ = i; }
- | i:lea { $$ = i; }
- | i:imul { $$ = i; }
- | i:neg { $$ = i; }
- | i:test { $$ = i; }
- | i:xchg { $$ = i; }
- | i:xor { $$ = i; }
- # Floating point is less common, so check last.
- | i:divss { $$ = i; }
- | i:divsd { $$ = i; }
- | i:pxor { $$ = i; }
- | i:xorpd { $$ = i; }
- | i:xorps { $$ = i; }
- | i:ucomisd { $$ = i; }
- | i:ucomiss { $$ = i; }
- | i:nop { $$ = i; }
+ (
+ i:set { $$ = i; }
+ | i:sub { $$ = i; }
+ | i:sal { $$ = i; }
+ | i:sar { $$ = i; }
+ | i:shl { $$ = i; }
+ | i:shr { $$ = i; }
+ | i:subsd { $$ = i; }
+ | i:subss { $$ = i; }))
+ | (& 'x'
+ (
+ i:xchg { $$ = i; }
+ | i:xor { $$ = i; }
+ | i:xorpd { $$ = i; }
+ | i:xorps { $$ = i; } ))
+ | i:or { $$ = i; }
+ | i:leave { $$ = i; }
+ | i:ret { $$ = i; }
+ | i:push { $$ = i; }
+ | i:pop { $$ = i; }
+ | i:jmp { $$ = i; }
+ | i:div { $$ = i; }
+ | i:idiv { $$ = i; }
+ | i:lea { $$ = i; }
+ | i:imul { $$ = i; }
+ | i:neg { $$ = i; }
+ | i:test { $$ = i; }
+ # Floating point is less common, so check last.
+ | i:divss { $$ = i; }
+ | i:divsd { $$ = i; }
+ | i:pxor { $$ = i; }
+ | i:ucomisd { $$ = i; }
+ | i:ucomiss { $$ = i; }
+ | i:nop { $$ = i; }
call = "call" 'q'? ws (
'*' t:mem
diff --git a/main.c b/main.c
index 3bd0e47..255b9a0 100644
--- a/main.c
+++ b/main.c
@@ -172,11 +172,6 @@ static Relocation *newreloc() {
static void sb(uint8_t b) { secaddbyte(cursection, b); }
-static void sb2(uint8_t b1, uint8_t b2) {
- uint8_t buf[2] = {b1, b2};
- secaddbytes(cursection, buf, sizeof(buf));
-}
-
static void sbn(uint8_t *bytes, size_t n) { secaddbytes(cursection, bytes, n); }
static void su16(uint16_t w) {
@@ -211,8 +206,6 @@ static void su64(uint64_t l) {
/* Convert an AsmKind to register bits in reg/rm style. */
static uint8_t regbits(AsmKind k) { return (k - (ASM_REG_BEGIN + 1)) % 16; }
-static uint8_t isreg64(AsmKind k) { return k >= ASM_RAX && k <= ASM_R15; }
-
/* Register that requires the use of a rex prefix. */
static uint8_t isrexreg(AsmKind k) {
return k > ASM_REG_BEGIN && k < ASM_REG_END &&
@@ -508,7 +501,7 @@ static void assembleinstr(const Instr *instr) {
Rex rex;
const Memarg *memarg;
const Imm *imm;
- uint8_t mod, reg, rm;
+ uint8_t reg, rm;
switch (instr->encoder) {
case ENCODER_OP:
diff --git a/parse.c b/parse.c
index 3be60a2..33a8b66 100644
--- a/parse.c
+++ b/parse.c
@@ -44,7 +44,6 @@ const char *internstring(const char *s) {
}
static String decodestring(char *s) {
- int i;
char *end;
size_t len = 0;
size_t cap = 0;