shithub: spirva

Download patch

ref: ca99199e72dc182d2801eb591cdf470c707c1e6c
parent: 3140d118dfeda8577a1c9d51b6d5646943f26277
author: sirjofri <[email protected]>
date: Sat Feb 17 15:31:04 EST 2024

adds keyword support and basic (but buggy) support for OpEntryPoint and a few other important instructions

--- a/asm.c
+++ b/asm.c
@@ -193,3 +193,12 @@
 	a.str = str;
 	arg(a);
 }
+
+void
+a_keyword(char *str)
+{
+	Inst a;
+	a.type = INT;
+	a.i = 0;
+	arg(a);
+}
--- a/asm.h
+++ b/asm.h
@@ -18,6 +18,7 @@
 void a_float(double f);
 void a_int(int i);
 void a_str(char *str);
+void a_keyword(char *str);
 
 void a_init(void);
 void assemble(void);
--- a/ops.c
+++ b/ops.c
@@ -11,6 +11,8 @@
 	{ "OpName", 5 },
 	{ "OpMemberName", 6 },
 	
+	{ "OpEntryPoint", 15 },
+	
 	{ "OpTypeVoid", 19 },
 	{ "OpTypeBool", 20 },
 	{ "OpTypeInt", 21 },
@@ -24,9 +26,36 @@
 	{ "OpTypePointer", 32 },
 	{ "OpTypeFunction", 33 },
 	
+	{ "OpFunction", 54 },
+	{ "OpFunctionParameter", 55 },
+	{ "OpFunctionEnd", 56 },
+	
+	{ "OpLabel", 248 },
+	{ "OpBranch", 249 },
+	
 	{ nil, nil },
 };
 
+Keyword keywords[] = {
+	{ "None", 0x0 },
+	{ "Inline", 0x1 },
+	{ "DontInline", 0x2 },
+	{ "Pure", 0x4 },
+	{ "Const", 0x8 },
+	{ "OptNoneINTEL", 0x10000 }, // reserved
+	
+	{ "Vertex", 0 },
+	{ "TessellationControl", 1 },
+	{ "TessellationEvaluation", 2 },
+	{ "Geometry", 3 },
+	{ "Fragment", 4 },
+	{ "GLCompute", 5 },
+	{ "Kernel", 6 },
+	// more
+
+	{ nil, nil },
+};
+
 uint
 o_lookup(char *n)
 {
@@ -51,4 +80,17 @@
 		}
 	}
 	return nil;
+}
+
+uint
+k_lookup(char *n)
+{
+	Keyword *k;
+	
+	for (k = keywords; k->keyword; k++) {
+		if (strcmp(k->keyword, n) == 0) {
+			return k->i;
+		}
+	}
+	return 0;
 }
--- a/ops.h
+++ b/ops.h
@@ -4,5 +4,13 @@
 	uint op;
 };
 
+typedef struct Keyword Keyword;
+struct Keyword {
+	char *keyword;
+	uint i;
+};
+
 uint o_lookup(char *n);
 char *o_find(uint op);
+
+uint k_lookup(char *n);
--- a/spirva.l
+++ b/spirva.l
@@ -18,7 +18,7 @@
 	return OP;
 }
 
-\${ANUM}+ {
+\%{ANUM}+ {
 	yylval.sym = symfind(strdup(yytext));
 	return SYM;
 }
--- a/spirva.y
+++ b/spirva.y
@@ -39,6 +39,7 @@
 	| INT { a_int($1); }
 	| FLOAT { a_float($1); }
 	| str
+	| STR { a_keyword($1); }
 	;
 
 str: '"' STR '"' { a_str($2); }