shithub: spirva

ref: a0d30aba763788d63e47878756cbd4e5cc6f6798
dir: spirva/ops.c

View raw version
#include <u.h>
#include <libc.h>
#include "ops.h"

Ops ops[] = {
	{ "OpNop", 0 },
	{ "OpUndef", 1 },
	{ "OpSizeOf", 321 },
	{ "OpSource", 3 },
	{ "OpSourceExtension", 4 },
	{ "OpName", 5 },
	{ "OpMemberName", 6 },
	
	{ "OpEntryPoint", 15 },
	
	{ "OpTypeVoid", 19 },
	{ "OpTypeBool", 20 },
	{ "OpTypeInt", 21 },
	{ "OpTypeFloat", 22 },
	{ "OpTypeVector", 23 },
	{ "OpTypeMatrix", 24 },
	{ "OpTypeArray", 28 },
	{ "OpTypeRuntimeArray", 29 },
	{ "OpTypeStruct", 30 },
	{ "OpTypeOpaque", 31 },
	{ "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)
{
	Ops *o;
	
	for (o = ops; o->opname; o++) {
		if (strcmp(o->opname, n) == 0) {
			return o->op;
		}
	}
	return 0;
}

char*
o_find(uint op)
{
	Ops *o;
	
	for (o = ops; o->opname; o++) {
		if (o->op == op) {
			return o->opname;
		}
	}
	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;
}