1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#pragma once
#include "dvec.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_IMM,
ICC_PARAM_POS,
ICC_PARAM_REL
};
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;
int in, out;
int read_addr;
int write_addr;
bool abort_on_err;
bool debug;
bool line_terminated;
int rip, base;
struct dvec 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 dvec *inst);
void icc_parse_inst(struct icc *icc, const char *str, size_t len);
int icc_step_inst(struct icc *icc);
int icc_set_inst(struct icc *icc, int addr, int in);
int icc_get_inst(struct icc *icc, int addr, int *out);
int icc_param_mode(int inst, int param);
int icc_get_param(struct icc *icc, int param, int *out);
int icc_get_dest(struct icc *icc, int param, int *out);
void icc_debug_dump(struct icc *icc, struct dvec *inst);
|