Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HeronErin committed Apr 19, 2024
2 parents ca73df6 + 9ae8fbe commit 17f824f
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dub.selections.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"fileVersion": 1,
"versions": {
"gallinule": "0.0.1",
"gallinule": "0.0.2",
"intel-intrinsics": "1.11.18",
"mir-linux-kernel": "1.0.1",
"tanya": "0.19.0",
Expand Down
108 changes: 108 additions & 0 deletions source/fern/intermediary.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
module fern.intermediary;

import gallinule.x86;

public enum OpCode
{
add,
sub,
mul,
div,
pow,
mod,
shl,
shr,
shls,
xor,
and,
or,
not,
neg,
por,
pand,
mref,
index,
slice,
move,
cmp,
jmp,
dcast,
pconv,
cmove,
concat,
call,
ret,
//contains
}

public enum Modifiers
{
FLOAT = 1 << 0,
POINTER = 1 << 1,
DYNAMIC_ARRAY = 1 << 2,
MEMORY_LITERAL = 1 << 3,
VALUE_LITERAL = 1 << 4,
}

public struct Function
{
public:
final:
Variable ret;
Variable[string] variables;
Instruction[] instrs;
}

public struct Instruction
{
public:
final:
OpCode opcode;
string[] operands;
}

public struct Type
{
public:
final:
size_t size;
Modifiers modifiers;
Variable[] fields;
}

public struct Variable
{
public:
final:
union
{
uint[] markers;
size_t offset;
}
Type type;

this(T)(T val)
{
static if (is(T : U*, U))
{
type = Type(0, Modifiers.MEMORY_LITERAL);
*cast(T*)&markers = val;
}
else
{
type = Type(T.sizeof, Modifiers.VALUE_LITERAL);
*cast(T*)&markers = val;
}
}
}

public:
static:
ST[] floats = [st0, st1, st2, st3, st4, st5, st6, st7];
R8[] bytes = [al, cl, dl, bl, ah, ch, dh, bh, spl, bpl, sil, dil, r8b, r9b, r10b, r11b, r12b, r13b, r14b, r15b];
R16[] words = [ax, cx, dx, bx, sp, bp, si, di, r8w, r9w, r10w, r11w, r12w, r13w, r14w, r15w];
R32[] dwords = [eax, ecx, edx, ebx, esp, ebp, esi, edi, r8d, r9d, r10d, r11d, r12d, r13d, r14d, r15d];
R64[] qwords = [rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15];
MMX[] mmx = [mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7];
XMM[] xmm = [xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15];
YMM[] ymm = [ymm0, ymm1, ymm2, ymm3, ymm4, ymm5, ymm6, ymm7, ymm8, ymm9, ymm10, ymm11, ymm12, ymm13, ymm14, ymm15];

0 comments on commit 17f824f

Please sign in to comment.