shithub: gpufs

ref: d53100c1bdfb9036a824fa60cd2dd58d02120210
dir: /cops.c/

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

extern int debug;
extern int compile;

void
printresult(int should, uint varid)
{
	char *s;
	
	if (!should) {
		print("%10s   ", " ");
		return;
	}
	s = smprint("$%d", varid);
	print("%10s = ", s);
	free(s);
}

void
OpTypeFloat(Frame *f, u32int)
{
	u32int varid = *(f->pc+1);
	u32int tlen = *(f->pc+2);
	
	if (compile) {
		printresult(1, varid);
		print("OpTypeFloat %d\n", tlen);
		return;
	}
}

void
OpTypeInt(Frame *f, u32int)
{
	u32int varid = *(f->pc+1);
	u32int tlen = *(f->pc+2);
	
	if (compile) {
		printresult(1, varid);
		print("OpTypeInt %d\n", tlen);
		return;
	}
}

void
OpName(Frame *f, u32int)
{
	u32int varid = *(f->pc+1);
	char *varname = (char*)(f->pc+2);
	
	nameadd(varid, varname);
	
	if (compile) {
		printresult(0, 0);
		print("OpName $%d \"%s\"\n", varid, varname);
		return;
	}
}

void
OpNop(Frame*, u32int)
{
	if (compile) {
		printresult(0, 0);
		print("OpNop\n");
	}
}

Op oplist[] = {
	{  5, OpName },
	{ 21, OpTypeInt },
	{ 22, OpTypeFloat },
	{ nil, OpNop },
};

int
oplookup(u32int code, void (**f)(Frame*,u32int))
{
	Op *o;
	u32int c = code & 0x0000ffff;
	if (c == 0) {
		*f = OpNop;
		return 1;
	}
	
	for (o = oplist; o->opcode; o++) {
		if (c == o->opcode) {
			*f = o->f;
			return 1;
		}
	}
	
	werrstr("operation (%d) not supported!", c);
	return 0;
}