Created
August 8, 2017 19:30
-
-
Save SeijiEmery/5492096eb47a43ae978df50e18e5424d to your computer and use it in GitHub Desktop.
assembler stuff (TBD)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bool p_stmt (SExpr s) { | |
| if (s[0] == "proc") return p_proc(s[1], s[2..$]); | |
| if (s[0] == "enum") return p_enum(s[1], s[2..$]); | |
| if (s[0] == "struct") return p_struct(s[1], s[2..$]); | |
| if (p_data(s)) return true; | |
| return false; | |
| } | |
| bool p_data (SExpr s) { | |
| if (s[0] == "data-string") {} | |
| if (s[0] == "data-array") {} | |
| } | |
| struct Assembler { | |
| enum Reg { | |
| // Registers are setup so that unique registers are at 0x00-0x3F, aliased registers by setting higher bits. | |
| // Because ah / al both need to alias rax, values go over 0x100, unfortunately. | |
| // The one exception is the AVX mask registers k0-k7, which are aliased to mm0-mm7 but do NOT overlap. | |
| // User code will should never be mixing these in the same proc (AVX + MMX / x87-FP), so this is probably fine... | |
| // Base register set | |
| rax = 0x00, rbx, rcx, rdx, rsp, rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15, | |
| rip = 0x10, rflags, | |
| mm0 = 0x18, mm1, mm2, mm3, mm4, mm5, mm6, mm7 | |
| xmm0 = 0x20, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, | |
| xmm16 = 0x30, xmm17, xmm18, xmm19, xmm20, xmm21, xmm22, xmm23, xmm24, xmm25, xmm26, xmm27, xmm28, xmm29, xmm30, xmm31, | |
| // Secondary register set | |
| eax = 0x40, ebx, ecx, edx, esp, ebp, esi, edi, r8d, r9d, r10d, r11d, r12d, r13d, r14d, r15d, | |
| eip = 0x50, eflags, | |
| fp0 = 0x58, fp1, fp2, fp3, fp4, fp5, fp6, fp7 | |
| ymm0 = 0x60, ymm1, ymm2, ymm3, ymm4, ymm5, ymm6, ymm7, ymm8, ymm9, ymm10, ymm11, ymm12, ymm13, ymm14, ymm15, | |
| ymm16 = 0x70, ymm17, ymm18, ymm19, ymm20, ymm21, ymm22, ymm23, ymm24, ymm25, ymm26, ymm27, ymm28, ymm29, ymm30, ymm31, | |
| // Tertiary register set | |
| ax = 0x80, bx, cx, dx, sp, bp, si, di, r8w, r9w, r10w, r11w, r12w, r13w, r14w, r15w, | |
| ip = 0x90, flags, | |
| k0 = 0x98, k1, k2, k3, k4, k5, k6, k7, // special mask registers - note: NOT aliased to mm / fp registers | |
| zmm0 = 0xA0, zmm1, zmm2, zmm3, zmm4, zmm5, zmm6, zmm7, zmm8, zmm9, zmm10, zmm11, zmm12, zmm13, zmm14, zmm15, | |
| zmm16 = 0xB0, zmm17, zmm18, zmm19, zmm20, zmm21, zmm22, zmm23, zmm24, zmm25, zmm26, zmm27, zmm28, zmm29, zmm30, zmm31, | |
| // etc... | |
| al = 0xC0, bl, cl, dl, spl, bpl, sil, dil, r8b, r9b, r10b, r11b, r12b, r13b, r14b, r15b, | |
| ah = 0x100, bh, ch, dh, sph, bph, sih, dih | |
| } | |
| struct StackVar { | |
| size_t offset; | |
| size_t type_size; | |
| size_t count = 1; | |
| size_t size_bytes () { return type_size * count; } | |
| } | |
| struct LinkEntity { | |
| size_t index; | |
| } | |
| struct Proc { | |
| string name; | |
| Reg[string] inputVars; | |
| Reg[string] outputVars; | |
| Reg[string] localVars; | |
| StackVar[string] stackVars; | |
| size_t stackSize = 0; | |
| Bytecode[] code; | |
| size_t[string] labels; | |
| LinkEntity[] linkage; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment