diff options
| author | Andrew Chambers <[email protected]> | 2021-10-13 16:40:38 +1300 |
|---|---|---|
| committer | Andrew Chambers <[email protected]> | 2021-10-13 16:40:38 +1300 |
| commit | 92c7930bf2f2cfeea51991524384bf6ce226bd7a (patch) | |
| tree | a3e659fd80b183d2e44075fc1668bcb7fb72414f | |
| parent | 7bce4e2fda947c9503cf74dc0446170aa976cb41 (diff) | |
Remove padding from some structs, add comment to cache.
| -rw-r--r-- | minias.h | 42 | ||||
| -rw-r--r-- | parse.c | 15 |
2 files changed, 33 insertions, 24 deletions
@@ -203,21 +203,21 @@ typedef enum { typedef union Parsev Parsev; -typedef struct { +typedef struct Label { AsmKind kind; const char *name; } Label; -typedef struct { +typedef struct Globl { AsmKind kind; const char *name; } Globl; -typedef struct { +typedef struct DirSection { AsmKind kind; + int32_t type; const char *name; const char *flags; - int type; } DirSection; typedef struct { @@ -225,53 +225,53 @@ typedef struct { const char *l; } Value; -typedef struct { +typedef struct Byte { AsmKind kind; Value value; } Byte; -typedef struct { +typedef struct Short { AsmKind kind; Value value; } Short; -typedef struct { +typedef struct Int { AsmKind kind; Value value; } Int; -typedef struct { +typedef struct Quad { AsmKind kind; Value value; } Quad; -typedef struct { +typedef struct Balign { AsmKind kind; uint64_t align; } Balign; -typedef struct { +typedef struct Fill { AsmKind kind; int32_t size; int32_t repeat; int64_t value; } Fill; -typedef struct { +typedef struct Imm { AsmKind kind; - uint8_t nbytes; + uint32_t nbytes; Value v; } Imm; -typedef struct { +typedef struct Memarg { AsmKind kind; AsmKind base; AsmKind index; - uint8_t scale; + uint32_t scale; Value disp; } Memarg; -typedef struct { +typedef struct String { AsmKind kind; size_t len; uint8_t *data; @@ -279,24 +279,24 @@ typedef struct { typedef String Ascii; typedef String Asciiz; -typedef struct { +typedef struct Call { AsmKind kind; - uint8_t indirect; + uint32_t indirect; union { const Parsev *indirect; Value direct; } target; } Call; -typedef struct { +typedef struct Jmp { AsmKind kind; - uint8_t variant; + uint32_t variant; const char *target; } Jmp; -typedef struct { +typedef struct Instr { AsmKind kind; - uint8_t variant; + uint32_t variant; const Parsev *arg1; const Parsev *arg2; const Parsev *arg3; @@ -2,9 +2,18 @@ /* Maintain a direct mapped cache of Parsev*. */ static const Parsev *internparsev(Parsev *p) { - /* An extremely simple direct mapped cache of *Parsev, - It relies on direct pointer comparison, which - itself only works because our pointers are interned. */ + /* + A simple direct mapped cache that prevents our parser + from allocating duplicate values. Note that it uses memcmp + for equality, even on pointer values, this works because the + pointers themselves are also interned. + + This simplicity somes with one big cost - Parsev variants with padding + can trigger a false positive on valgrind. It should still safe + because reading these undefined bytes do not change the behavior of the + program. The best fix is still to avoid the padding bytes in the Parsev + variant layout using a tool such as 'pahole'. + */ size_t idx; const Parsev *interned; static const Parsev *cache[4096] = {0}; |
