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
73
74
75
76
77
78
79
80
81
82
|
#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);
|