#pragma once #include "dvec.h" #include "hmap.h" #include "maxint.h" enum { ICC_RUN, ICC_INPUT, ICC_OUTPUT, ICC_HALT }; enum { ICC_OK, ICC_INV_INST, ICC_OOB_WRITE, ICC_OOB_READ, }; enum { ICC_PARAM_POS = 0, ICC_PARAM_IMM = 1, ICC_PARAM_REL = 2 }; enum { ICC_INST_ADD = 1, ICC_INST_MULT = 2, ICC_INST_STORE = 3, ICC_INST_LOAD = 4, ICC_INST_JMPT = 5, ICC_INST_JMPF = 6, ICC_INST_TLT = 7, ICC_INST_TEQ = 8, ICC_INST_BASE = 9, ICC_INST_HALT = 99 }; struct icc { int state; struct maxint in, out; struct maxint read_addr; struct maxint write_addr; bool abort_on_err; bool debug; /* general purpose registers */ struct maxint r1, r2, r3, r4, tmp; bool line_terminated; struct maxint rip, base; struct hmap instructions; }; extern const char *icc_err[]; void icc_init(struct icc *icc); void icc_deinit(struct icc *icc); void icc_copy(struct icc *dst, struct icc *src); void icc_reset(struct icc *icc, struct hmap *inst); void icc_parse_inst(struct icc *icc, const char *str, size_t len); int icc_step_inst(struct icc *icc); struct hmap_link *icc_write_any(struct icc *icc, struct maxint *addr, struct maxint *in); int icc_write(struct icc *icc, struct maxint *addr, struct maxint *in); int icc_read(struct icc *icc, struct maxint *addr, struct maxint **out); const char *icc_literal_str(struct icc *icc, struct maxint *addr, size_t zfill); const char *icc_value_str(struct icc *icc, struct maxint *addr, size_t zfill); int icc_param_mode(int inst, int param); int icc_get_param(struct icc *icc, struct maxint *tmp, int param, struct maxint *out); int icc_get_dest(struct icc *icc, struct maxint *tmp, int param, struct maxint *out); void icc_debug_print(struct icc *icc, struct maxint *addr);