ref: b7ecf84c597a332ae0c1bb1534b61cfed573c92c
parent: 8a6851fa526de6f5dcf5ddabb5609f3a85929e6f
author: sirjofri <sirjofri@sirjofri.de>
date: Sat Feb 17 15:34:26 EST 2024
adds rudimentary (and buggy) support for OpEntryPoint and a few other important instructions
--- a/dops.c
+++ b/dops.c
@@ -6,6 +6,38 @@
extern int debug;
+char *executionmodel[] = {
+ "Vertex",
+ "TessellationControl",
+ "TessellationEvaluation",
+ "Geometry",
+ "Fragment",
+ "GLCompute",
+ "Kernel",
+ nil
+};
+
+char*
+getexecutionmodel(u32int i)
+{
+ if (i >= sizeof(executionmodel))
+ return nil;
+ return executionmodel[i];
+}
+
+char*
+getfunctioncontrol(u32int i)
+{
+ switch (i) {
+ case 0x0: return "None";
+ case 0x2: return "DontInline";
+ case 0x4: return "Pure";
+ case 0x8: return "Const";
+ case 0x10000: return "OptNoneINTEL";
+ }
+ return nil;
+}
+
void
printresult(int should, uint varid)
{
@@ -15,7 +47,7 @@
print("%10s ", " ");
return;
}
- s = smprint("$%d", varid);
+ s = smprint("%%%d", varid);
print("%10s = ", s);
free(s);
}
@@ -66,7 +98,7 @@
u32int tlen = f->pc[3];
printresult(1, varid);
- print("OpTypeFloat $%d %d\n", ttype, tlen);
+ print("OpTypeFloat %%%d %d\n", ttype, tlen);
}
void
@@ -77,7 +109,7 @@
u32int tlen = f->pc[3];
printresult(1, varid);
- print("OpTypeFloat $%d %d\n", ctype, tlen);
+ print("OpTypeFloat %%%d %d\n", ctype, tlen);
}
void
@@ -89,7 +121,7 @@
nameadd(varid, varname);
printresult(0, 0);
- print("OpName $%d \"%s\"\n", varid, varname);
+ print("OpName %%%d \"%s\"\n", varid, varname);
}
void
@@ -135,30 +167,85 @@
u32int varid = f->pc[1];
u32int rettype = f->pc[2];
u32int* argv = &f->pc[3];
- u32int argc = len - 2;
+ u32int argc = len - 3;
printresult(1, varid);
- print("OpTypeFunction $%d", rettype);
+ print("OpTypeFunction %%%d", rettype);
for (int i = 0; i < argc; i++) {
u32int v = argv[i];
- print(" $%d", v);
+ print(" %%%d", v);
}
print("\n");
}
+void
+OpEntryPoint(Frame *f, u32int len)
+{
+ u32int emodel = f->pc[1];
+ u32int epoint = f->pc[2];
+ char *name = (char*)&f->pc[3];
+ int l = strlen(name)+1;
+ l = (l%4 == 0 ? l/4 : l/4+1);
+ u32int *argv = &f->pc[l+3];
+ u32int argc = len - (l+2);
+
+ printresult(0, 0);
+ print("OpEntryPoint %s %%%d \"%s\"", getexecutionmodel(emodel), epoint, name);
+
+ for (int i = 0; i < argc; i++) {
+ u32int v = argv[i];
+ print(" %%%d", v);
+ }
+ print("\n");
+}
+
+void
+OpFunction(Frame *f, u32int)
+{
+ u32int result = f->pc[1];
+ u32int retvar = f->pc[2];
+ u32int fctl = f->pc[3];
+ u32int ftype = f->pc[4];
+
+ printresult(1, result);
+ print("OpFunction %%%d %s %%%d\n",
+ retvar,
+ getfunctioncontrol(fctl),
+ ftype);
+}
+
+void
+OpFunctionEnd(Frame*, u32int)
+{
+ printresult(0, 0);
+ print("OpFunctionEnd\n");
+}
+
+void
+OpLabel(Frame *f, u32int)
+{
+ u32int retvar = f->pc[1];
+ printresult(1, retvar);
+ print("OpLabel\n");
+}
+
Op oplist[] = {
- { 1, OpUndef },
- { 3, OpSource },
- { 5, OpName },
- { 19, OpTypeVoid },
- { 20, OpTypeBool },
- { 21, OpTypeInt },
- { 22, OpTypeFloat },
- { 23, OpTypeVector },
- { 24, OpTypeMatrix },
- { 33, OpTypeFunction },
- { nil, OpNop },
+ { 1, OpUndef },
+ { 3, OpSource },
+ { 5, OpName },
+ { 15, OpEntryPoint },
+ { 19, OpTypeVoid },
+ { 20, OpTypeBool },
+ { 21, OpTypeInt },
+ { 22, OpTypeFloat },
+ { 23, OpTypeVector },
+ { 24, OpTypeMatrix },
+ { 33, OpTypeFunction },
+ { 54, OpFunction },
+ { 56, OpFunctionEnd },
+ { 248, OpLabel },
+ { nil, OpNop },
};
int