From d50be7265bebcf36ffe6b47a5a1a25536ceec0d6 Mon Sep 17 00:00:00 2001 From: cetio Date: Tue, 21 May 2024 12:29:31 -0400 Subject: [PATCH 1/2] add a global glob, improve instruction generation, add some instructions --- source/fnc/emission/ir.d | 42 ++++++++- source/fnc/emission/x86.d | 192 +++++++++++++++++++++++++++++++++++++- source/fnc/symbols.d | 26 +++++- 3 files changed, 253 insertions(+), 7 deletions(-) diff --git a/source/fnc/emission/ir.d b/source/fnc/emission/ir.d index f272a0d..f360955 100644 --- a/source/fnc/emission/ir.d +++ b/source/fnc/emission/ir.d @@ -1004,8 +1004,48 @@ final: return true; } - this(OpCode opcode, Symbol[] operands...) + this(ARGS...)(OpCode opcode, ARGS args) { + Symbol[] operands; + foreach (arg; args) + { + static if (is(typeof(arg) == Symbol)) + operands ~= arg; + else + { + SymAttr attr = SymAttr.LITERAL; + // We don't check for if its a vector, but this shouldn't matter. + static if (is(typeof(arg) == string)) + attr |= SymAttr.STRING; + else static if (is(typeof(arg) == ubyte) || is(typeof(arg) == byte)) + attr |= SymAttr.BYTE; + else static if (is(typeof(arg) == ushort) || is(typeof(arg) == short)) + attr |= SymAttr.WORD; + else static if (is(typeof(arg) == uint) || is(typeof(arg) == int)) + attr |= SymAttr.DWORD; + else static if (is(typeof(arg) == ulong) || is(typeof(arg) == long)) + attr |= SymAttr.QWORD; + else static if (is(typeof(arg) == float)) + attr |= SymAttr.FLOAT; + else static if (is(typeof(arg) == double)) + attr |= SymAttr.DOUBLE; + else static if (isArray!(typeof(arg))) + attr |= SymAttr.ARRAY; + + static if (isStaticArray!(typeof(arg))) + attr |= SymAttr.FIXARRAY; + else static if (isAssociativeArray!(typeof(arg))) + attr |= SymAttr.ASOARRAY; + else static if (isDynamicArray!(typeof(arg))) + attr |= SymAttr.DYNARRAY; + + static if (isSigned!(typeof(arg))) + attr |= SymAttr.SIGNED; + + operands ~= new Symbol(glob, attr, null, null, null, null, Marker(arg)); + } + } + Details detail(string fmt) pure { Details ret; diff --git a/source/fnc/emission/x86.d b/source/fnc/emission/x86.d index fdb9927..a20b532 100644 --- a/source/fnc/emission/x86.d +++ b/source/fnc/emission/x86.d @@ -581,16 +581,198 @@ final: } ptrdiff_t label(string name) => labels[name] = buffer.length; - - // These categories are intended to separate instructions based on their corresponding flag, - // however, they do not accurately reflect this and are more whimsical than logical. - - /* ====== PSEUDO/CUSTOM ====== */ size_t stage(Instruction instr) { with (OpCode) switch (instr.opcode) { + case CRIDVME: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.VME)); + case CRIDPVI: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.PVI)); + case CRIDTSD: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.TSD)); + case CRIDDE: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.DE)); + case CRIDPSE: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.PSE)); + case CRIDPAE: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.PAE)); + case CRIDMCE: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.MCE)); + case CRIDPGE: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.PGE)); + case CRIDPCE: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.PCE)); + case CRIDOSFXSR: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.OSFXSR)); + case CRIDOSXMMEXCPT: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.OSXMMEXCPT)); + case CRIDUMIP: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.UMIP)); + case CRIDVMXE: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.VMXE)); + case CRIDSMXE: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.SMXE)); + case CRIDFSGSBASE: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.FSGSBASE)); + case CRIDPCIDE: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.PCIDE)); + case CRIDOSXSAVE: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.OSXSAVE)); + case CRIDSMEP: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.SMEP)); + case CRIDSMAP: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.SMAP)); + case CRIDPKE: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.PKE)); + case CRIDCET: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.CET)); + case CRIDPKS: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.PKS)); + case CRIDUINTR: + return stage(Instruction(OpCode.MOV, instr.operands[0], cr4)) + + stage(Instruction(OpCode.AND, instr.operands[0], 1 << CRID.UINTR)); + + case IDAVX512VL: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.AVX512VL)) + + // NOTE: This would have problems depending on what marker is the first operand. + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDAVX512BW: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.AVX512BW)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDSHA: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.SHA)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDAVX512CD: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.AVX512CD)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDAVX512ER: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.AVX512ER)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDAVX512PF: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.AVX512PF)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDPT: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.PT)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDCLWB: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.CLWB)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDCLFLUSHOPT: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.CLFLUSHOPT)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDPCOMMIT: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.PCOMMIT)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDAVX512IFMA: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.AVX512IFMA)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDSMAP: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.SMAP)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDADX: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.ADX)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDRDSEED: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.RDSEED)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDAVX512DQ: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.AVX512DQ)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDAVX512F: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.AVX512F)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDPQE: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.PQE)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDRTM: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.RTM)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDINVPCID: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.INVPCID)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDERMS: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.ERMS)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDBMI2: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.BMI2)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDSMEP: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.SMEP)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDFPDP: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.FPDP)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDAVX2: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.AVX2)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDHLE: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.HLE)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDBMI1: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.BMI1)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDSGX: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.SGX)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDTSCADJ: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.TSC_ADJUST)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + case IDFSGSBASE: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.FSGSBASE)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); default: assert(0, "Invalid instruction staging!"); } diff --git a/source/fnc/symbols.d b/source/fnc/symbols.d index 1d4a822..69c9eb8 100644 --- a/source/fnc/symbols.d +++ b/source/fnc/symbols.d @@ -6,7 +6,15 @@ import tern.state; import tern.algorithm.mutation : insert, alienate; import tern.algorithm.searching : contains, indexOf; -// All symbols may have their children accessed at comptime using `->` followed by the Child name, alignment is internally align and marker is not visible. +// All symbols may have their children accessed at comptime using `->` followed by the child name, alignment is internally align and marker is not visible. + +/// The global glob from which all symbols should originate. +public static Glob glob; + +shared static this() +{ + glob = new Glob(); +} public enum SymAttr : ulong { @@ -112,6 +120,22 @@ final: return ret~name; } + this() + { + // stupid ass language forces an explicit default constructor to be written + } + + this(Glob glob, SymAttr symattr, string name, Symbol[] parents, Symbol[] children, Symbol[string] attributes, Marker marker) + { + this.glob = glob; + this.symattr = symattr; + this.name = name; + this.parents = parents; + this.children = children; + this.attributes = attributes; + this.marker = marker; + } + bool isType() => (symattr & SymAttr.TYPE) != 0; bool isClass() => (symattr & SymAttr.CLASS) != 0; bool isStruct() => (symattr & SymAttr.STRUCT) != 0; From 4aafd619994cdc51563025fc8649c6d0c548ec49 Mon Sep 17 00:00:00 2001 From: cetio Date: Tue, 21 May 2024 17:17:46 -0400 Subject: [PATCH 2/2] add cache and stuff --- source/arbore/cache.d | 28 ++++ source/fnc/emission/ir.d | 4 +- source/fnc/emission/x86.d | 289 +++++++++++++++++++------------------- source/fnc/symbols.d | 7 +- 4 files changed, 183 insertions(+), 145 deletions(-) create mode 100644 source/arbore/cache.d diff --git a/source/arbore/cache.d b/source/arbore/cache.d new file mode 100644 index 0000000..427623e --- /dev/null +++ b/source/arbore/cache.d @@ -0,0 +1,28 @@ +module arbore.cache; + +import fnc.symbols; +import std.stdio; + +public: +void store() +{ + string[Module] caches; + foreach (symbol; glob.symbols.byValue) + { + if (!symbol.evaluated) + continue; + + if (symbol._module !in caches) + caches[symbol._module] = null; + + if (!symbol.isAliasSeq) + caches[symbol._module] ~= "alias "~symbol.identifier~" = "~(cast(Alias)symbol).single.identifier~";"; + else + { + caches[symbol._module] ~= "alias[] "~symbol.identifier~" = ["; + foreach (sym; (cast(Alias)symbol).many) + caches[symbol._module] ~= sym.identifier~", "; + caches[symbol._module] = caches[symbol._module][0..$-2]~"];"; + } + } +} \ No newline at end of file diff --git a/source/fnc/emission/ir.d b/source/fnc/emission/ir.d index f360955..0be32f2 100644 --- a/source/fnc/emission/ir.d +++ b/source/fnc/emission/ir.d @@ -1009,8 +1009,8 @@ final: Symbol[] operands; foreach (arg; args) { - static if (is(typeof(arg) == Symbol)) - operands ~= arg; + static if (is(Unqual!(typeof(arg)) == Symbol)) + operands ~= cast(Symbol)arg; else { SymAttr attr = SymAttr.LITERAL; diff --git a/source/fnc/emission/x86.d b/source/fnc/emission/x86.d index a20b532..2485ca5 100644 --- a/source/fnc/emission/x86.d +++ b/source/fnc/emission/x86.d @@ -8,159 +8,159 @@ import fnc.symbols; import std.traits; public: -enum cr0 = Marker(-1, 0, false); -enum cr2 = Marker(-1, 2, false); -enum cr3 = Marker(-1, 3, false); -enum cr4 = Marker(-1, 4, false); +static const cr0 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-1, 0, false)); +static const cr2 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-1, 2, false)); +static const cr3 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-1, 3, false)); +static const cr4 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-1, 4, false)); -enum dr0 = Marker(-2, 0, false); -enum dr1 = Marker(-2, 1, false); -enum dr2 = Marker(-2, 2, false); -enum dr3 = Marker(-2, 3, false); -enum dr6 = Marker(-2, 6, false); -enum dr7 = Marker(-2, 7, false); +static const dr0 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-2, 0, false)); +static const dr1 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-2, 1, false)); +static const dr2 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-2, 2, false)); +static const dr3 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-2, 3, false)); +static const dr6 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-2, 6, false)); +static const dr7 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-2, 7, false)); -enum st0 = Marker(-3, 0, false); -enum st1 = Marker(-3, 1, false); -enum st2 = Marker(-3, 2, false); -enum st3 = Marker(-3, 3, false); -enum st4 = Marker(-3, 4, false); -enum st5 = Marker(-3, 5, false); -enum st6 = Marker(-3, 6, false); -enum st7 = Marker(-3, 7, false); +static const st0 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-3, 0, false)); +static const st1 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-3, 1, false)); +static const st2 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-3, 2, false)); +static const st3 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-3, 3, false)); +static const st4 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-3, 4, false)); +static const st5 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-3, 5, false)); +static const st6 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-3, 6, false)); +static const st7 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(-3, 7, false)); -enum al = Marker(8, 0, false); -enum cl = Marker(8, 1, false); -enum dl = Marker(8, 2, false); -enum bl = Marker(8, 3, false); -enum ah = Marker(8, 4, false); -enum ch = Marker(8, 5, false); -enum dh = Marker(8, 6, false); -enum bh = Marker(8, 7, false); -enum spl = Marker(8, 4, true); -enum bpl = Marker(8, 5, true); -enum sil = Marker(8, 6, true); -enum dil = Marker(8, 7, true); -enum r8b = Marker(8, 8, false); -enum r9b = Marker(8, 9, false); -enum r10b = Marker(8, 10, false); -enum r11b = Marker(8, 11, false); -enum r12b = Marker(8, 12, false); -enum r13b = Marker(8, 13, false); -enum r14b = Marker(8, 14, false); -enum r15b = Marker(8, 15, false); +static const al = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 0, false)); +static const cl = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 1, false)); +static const dl = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 2, false)); +static const bl = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 3, false)); +static const ah = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 4, false)); +static const ch = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 5, false)); +static const dh = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 6, false)); +static const bh = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 7, false)); +static const spl = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 4, true)); +static const bpl = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 5, true)); +static const sil = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 6, true)); +static const dil = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 7, true)); +static const r8b = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 8, false)); +static const r9b = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 9, false)); +static const r10b = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 10, false)); +static const r11b = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 11, false)); +static const r12b = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 12, false)); +static const r13b = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 13, false)); +static const r14b = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 14, false)); +static const r15b = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(8, 15, false)); -enum ax = Marker(16, 0, false); -enum cx = Marker(16, 1, false); -enum dx = Marker(16, 2, false); -enum bx = Marker(16, 3, false); -enum sp = Marker(16, 4, false); -enum bp = Marker(16, 5, false); -enum si = Marker(16, 6, false); -enum di = Marker(16, 7, false); -enum r8w = Marker(16, 8, false); -enum r9w = Marker(16, 9, false); -enum r10w = Marker(16, 10, false); -enum r11w = Marker(16, 11, false); -enum r12w = Marker(16, 12, false); -enum r13w = Marker(16, 13, false); -enum r14w = Marker(16, 14, false); -enum r15w = Marker(16, 15, false); +static const ax = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 0, false)); +static const cx = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 1, false)); +static const dx = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 2, false)); +static const bx = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 3, false)); +static const sp = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 4, false)); +static const bp = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 5, false)); +static const si = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 6, false)); +static const di = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 7, false)); +static const r8w = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 8, false)); +static const r9w = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 9, false)); +static const r10w = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 10, false)); +static const r11w = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 11, false)); +static const r12w = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 12, false)); +static const r13w = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 13, false)); +static const r14w = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 14, false)); +static const r15w = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(16, 15, false)); -enum eax = Marker(32, 0, false); -enum ecx = Marker(32, 1, false); -enum edx = Marker(32, 2, false); -enum ebx = Marker(32, 3, false); -enum esp = Marker(32, 4, false); -enum ebp = Marker(32, 5, false); -enum esi = Marker(32, 6, false); -enum edi = Marker(32, 7, false); -enum r8d = Marker(32, 8, false); -enum r9d = Marker(32, 9, false); -enum r10d = Marker(32, 10, false); -enum r11d = Marker(32, 11, false); -enum r12d = Marker(32, 12, false); -enum r13d = Marker(32, 13, false); -enum r14d = Marker(32, 14, false); -enum r15d = Marker(32, 15, false); +static const eax = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 0, false)); +static const ecx = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 1, false)); +static const edx = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 2, false)); +static const ebx = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 3, false)); +static const esp = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 4, false)); +static const ebp = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 5, false)); +static const esi = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 6, false)); +static const edi = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 7, false)); +static const r8d = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 8, false)); +static const r9d = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 9, false)); +static const r10d = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 10, false)); +static const r11d = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 11, false)); +static const r12d = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 12, false)); +static const r13d = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 13, false)); +static const r14d = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 14, false)); +static const r15d = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(32, 15, false)); -enum rax = Marker(64, 0, false); -enum rcx = Marker(64, 1, false); -enum rdx = Marker(64, 2, false); -enum rbx = Marker(64, 3, false); -enum rsp = Marker(64, 4, false); -enum rbp = Marker(64, 5, false); -enum rsi = Marker(64, 6, false); -enum rdi = Marker(64, 7, false); -enum r8 = Marker(64, 8, false); -enum r9 = Marker(64, 9, false); -enum r10 = Marker(64, 10, false); -enum r11 = Marker(64, 11, false); -enum r12 = Marker(64, 12, false); -enum r13 = Marker(64, 13, false); -enum r14 = Marker(64, 14, false); -enum r15 = Marker(64, 15, false); +static const rax = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 0, false)); +static const rcx = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 1, false)); +static const rdx = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 2, false)); +static const rbx = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 3, false)); +static const rsp = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 4, false)); +static const rbp = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 5, false)); +static const rsi = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 6, false)); +static const rdi = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 7, false)); +static const r8 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 8, false)); +static const r9 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 9, false)); +static const r10 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 10, false)); +static const r11 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 11, false)); +static const r12 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 12, false)); +static const r13 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 13, false)); +static const r14 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 14, false)); +static const r15 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 15, false)); // TODO: MM and first 8 R64 can be used interchangably, this is bad! -enum mm0 = Marker(64, 0, false); -enum mm1 = Marker(64, 1, false); -enum mm2 = Marker(64, 2, false); -enum mm3 = Marker(64, 3, false); -enum mm4 = Marker(64, 4, false); -enum mm5 = Marker(64, 5, false); -enum mm6 = Marker(64, 6, false); -enum mm7 = Marker(64, 7, false); +static const mm0 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 0, false)); +static const mm1 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 1, false)); +static const mm2 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 2, false)); +static const mm3 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 3, false)); +static const mm4 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 4, false)); +static const mm5 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 5, false)); +static const mm6 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 6, false)); +static const mm7 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(64, 7, false)); -enum xmm0 = Marker(128, 0, false); -enum xmm1 = Marker(128, 1, false); -enum xmm2 = Marker(128, 2, false); -enum xmm3 = Marker(128, 3, false); -enum xmm4 = Marker(128, 4, false); -enum xmm5 = Marker(128, 5, false); -enum xmm6 = Marker(128, 6, false); -enum xmm7 = Marker(128, 7, false); -enum xmm8 = Marker(128, 8, false); -enum xmm9 = Marker(128, 9, false); -enum xmm10 = Marker(128, 10, false); -enum xmm11 = Marker(128, 11, false); -enum xmm12 = Marker(128, 12, false); -enum xmm13 = Marker(128, 13, false); -enum xmm14 = Marker(128, 14, false); -enum xmm15 = Marker(128, 15, false); +static const xmm0 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 0, false)); +static const xmm1 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 1, false)); +static const xmm2 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 2, false)); +static const xmm3 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 3, false)); +static const xmm4 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 4, false)); +static const xmm5 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 5, false)); +static const xmm6 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 6, false)); +static const xmm7 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 7, false)); +static const xmm8 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 8, false)); +static const xmm9 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 9, false)); +static const xmm10 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 10, false)); +static const xmm11 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 11, false)); +static const xmm12 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 12, false)); +static const xmm13 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 13, false)); +static const xmm14 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 14, false)); +static const xmm15 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(128, 15, false)); -enum ymm0 = Marker(256, 0, false); -enum ymm1 = Marker(256, 1, false); -enum ymm2 = Marker(256, 2, false); -enum ymm3 = Marker(256, 3, false); -enum ymm4 = Marker(256, 4, false); -enum ymm5 = Marker(256, 5, false); -enum ymm6 = Marker(256, 6, false); -enum ymm7 = Marker(256, 7, false); -enum ymm8 = Marker(256, 8, false); -enum ymm9 = Marker(256, 9, false); -enum ymm10 = Marker(256, 10, false); -enum ymm11 = Marker(256, 11, false); -enum ymm12 = Marker(256, 12, false); -enum ymm13 = Marker(256, 13, false); -enum ymm14 = Marker(256, 14, false); -enum ymm15 = Marker(256, 15, false); +static const ymm0 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 0, false)); +static const ymm1 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 1, false)); +static const ymm2 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 2, false)); +static const ymm3 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 3, false)); +static const ymm4 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 4, false)); +static const ymm5 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 5, false)); +static const ymm6 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 6, false)); +static const ymm7 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 7, false)); +static const ymm8 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 8, false)); +static const ymm9 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 9, false)); +static const ymm10 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 10, false)); +static const ymm11 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 11, false)); +static const ymm12 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 12, false)); +static const ymm13 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 13, false)); +static const ymm14 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 14, false)); +static const ymm15 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(256, 15, false)); -enum zmm0 = Marker(512, 0, false); -enum zmm1 = Marker(512, 1, false); -enum zmm2 = Marker(512, 2, false); -enum zmm3 = Marker(512, 3, false); -enum zmm4 = Marker(512, 4, false); -enum zmm5 = Marker(512, 5, false); -enum zmm6 = Marker(512, 6, false); -enum zmm7 = Marker(512, 7, false); -enum zmm8 = Marker(512, 8, false); -enum zmm9 = Marker(512, 9, false); -enum zmm10 = Marker(512, 10, false); -enum zmm11 = Marker(512, 11, false); -enum zmm12 = Marker(512, 12, false); -enum zmm13 = Marker(512, 13, false); -enum zmm14 = Marker(512, 14, false); -enum zmm15 = Marker(512, 15, false); +static const zmm0 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 0, false)); +static const zmm1 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 1, false)); +static const zmm2 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 2, false)); +static const zmm3 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 3, false)); +static const zmm4 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 4, false)); +static const zmm5 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 5, false)); +static const zmm6 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 6, false)); +static const zmm7 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 7, false)); +static const zmm8 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 8, false)); +static const zmm9 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 9, false)); +static const zmm10 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 10, false)); +static const zmm11 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 11, false)); +static const zmm12 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 12, false)); +static const zmm13 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 13, false)); +static const zmm14 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 14, false)); +static const zmm15 = new Symbol(null, SymAttr.LOCAL, null, null, null, null, Marker(512, 15, false)); enum ubyte es = 0x26; enum ubyte cs = 0x2e; @@ -773,6 +773,11 @@ final: return stage(Instruction(OpCode.CPUID, 7)) + stage(Instruction(OpCode.AND, ebx, 1 << CPUID7_EBX.FSGSBASE)) + stage(Instruction(OpCode.MOV, instr.operands[0], ebx)); + + case IDPREFETCHWT1: + return stage(Instruction(OpCode.CPUID, 7)) + + stage(Instruction(OpCode.AND, ecx, 1 << CPUID7_ECX.PREFETCHWT1)) + + stage(Instruction(OpCode.MOV, instr.operands[0], ecx)); default: assert(0, "Invalid instruction staging!"); } diff --git a/source/fnc/symbols.d b/source/fnc/symbols.d index 69c9eb8..e98d381 100644 --- a/source/fnc/symbols.d +++ b/source/fnc/symbols.d @@ -109,6 +109,8 @@ final: Symbol[string] attributes; // This is not front-facing! Marker marker; + size_t refcount; + bool evaluated; alias marker this; @@ -454,7 +456,10 @@ final: string type() { - return "alias"; + if (isAliasSeq) + return "alias[]"; + else + return "alias"; } }