icfp12/ovm/ovm.h

67 lines
1.2 KiB
C
Raw Normal View History

2009-06-26 21:13:17 +00:00
#ifndef OVM_OVM_H
#define OVM_OVM_H
#include "base.h"
typedef guint32 instruction_t;
typedef enum {
OP_STYPE = 0x0,
OP_ADD = 0x1,
OP_SUB = 0x2,
OP_MULT = 0x3,
OP_DIV = 0x4,
OP_OUT = 0x5,
OP_PHI = 0x6
} dop_t;
typedef enum {
SOP_NOOP = 0x0,
SOP_CMPZ = 0x1,
SOP_SQRT = 0x2,
SOP_COPY = 0x3,
SOP_IN = 0x4
} sop_t;
typedef enum {
CMP_LTZ = 0x0, /* < */
CMP_LEZ = 0x1, /* <= */
CMP_EQZ = 0x2, /* == */
CMP_GEZ = 0x3, /* >= */
CMP_GTZ = 0x4 /* > */
} cmp_t;
static inline dop_t instr_dop(instruction_t i) {
return i >> 28;
}
static inline sop_t instr_sop(instruction_t i) {
return i >> 24; /* upper bits are 0 */
}
static inline guint instr_dop_r1(instruction_t i) {
return (i >> 14) & 0x3FFF;
}
static inline guint instr_dop_r2(instruction_t i) {
return i & 0x3FFF;
}
static inline cmp_t instr_sop_cmp(instruction_t i) {
return (i >> 20) & 0xF;
}
static inline guint instr_sop_r1(instruction_t i) {
return i & 0x3FFF;
}
typedef struct {
gsize limit, used;
instruction_t *instructions;
gdouble *values;
guint32 pc;
} ovm_t;
void ovm_free(ovm_t *ovm);
ovm_t* ovm_load(const gchar *filename);
void ovm_print_c(ovm_t *ovm, const gchar *filename);
#endif