aoc-2019-c

Advent of Code 2019 Solutions in C
git clone https://git.sinitax.com/sinitax/aoc-2019-c
Log | Files | Refs | README | sfeed.txt

iccmp.h (1738B)


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