icc.h (1226B)
1#pragma once 2 3#include "dvec.h" 4 5enum { 6 ICC_RUN, 7 ICC_INPUT, 8 ICC_OUTPUT, 9 ICC_HALT 10}; 11 12enum { 13 ICC_OK, 14 ICC_INV_INST, 15 ICC_OOB_WRITE, 16 ICC_OOB_READ, 17}; 18 19enum { 20 ICC_PARAM_IMM, 21 ICC_PARAM_POS, 22 ICC_PARAM_REL 23}; 24 25enum { 26 ICC_INST_ADD = 1, 27 ICC_INST_MULT = 2, 28 ICC_INST_STORE = 3, 29 ICC_INST_LOAD = 4, 30 ICC_INST_JMPT = 5, 31 ICC_INST_JMPF = 6, 32 ICC_INST_TLT = 7, 33 ICC_INST_TEQ = 8, 34 ICC_INST_BASE = 9, 35 36 ICC_INST_HALT = 99 37}; 38 39struct icc { 40 int state; 41 int in, out; 42 43 int read_addr; 44 int write_addr; 45 bool abort_on_err; 46 47 bool debug; 48 49 bool line_terminated; 50 51 int rip, base; 52 struct dvec instructions; 53}; 54 55extern const char *icc_err[]; 56 57void icc_init(struct icc *icc); 58void icc_deinit(struct icc *icc); 59void icc_copy(struct icc *dst, struct icc *src); 60void icc_reset(struct icc *icc, struct dvec *inst); 61 62void icc_parse_inst(struct icc *icc, const char *str, size_t len); 63int icc_step_inst(struct icc *icc); 64 65int icc_set_inst(struct icc *icc, int addr, int in); 66int icc_get_inst(struct icc *icc, int addr, int *out); 67 68int icc_param_mode(int inst, int param); 69int icc_get_param(struct icc *icc, int param, int *out); 70int icc_get_dest(struct icc *icc, int param, int *out); 71 72void icc_debug_dump(struct icc *icc, struct dvec *inst);