-
Notifications
You must be signed in to change notification settings - Fork 1
/
ijvm-asm.h
158 lines (132 loc) · 3.14 KB
/
ijvm-asm.h
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#ifndef JASM_H
#define JASM_H
#include <stdio.h>
#include "ijvm-spec.h"
#include "ijvm-util.h"
#include "types.h"
typedef struct JasmMethod JasmMethod;
typedef struct JasmDir JasmDir;
typedef struct JasmOperand JasmOperand;
typedef enum JasmInsnKind JasmInsnKind;
typedef struct JasmInsn JasmInsn;
typedef struct JasmExpr JasmExpr;
typedef enum JasmExprKind JasmExprKind;
typedef struct JasmDefine JasmDefine;
typedef struct JasmCPool JasmCPool;
struct JasmMethod
{
char *name;
JasmExpr *args, *locals;
int size, address, index;
JasmDir *dirs;
JasmDefine *defines, *labels;
JasmInsn *insns;
JasmMethod *next;
};
JasmMethod *jasm_method_make (char *name, JasmDir *dirs, JasmInsn *insns);
typedef enum {
JASM_DIR_LOCALS,
JASM_DIR_ARGS,
JASM_DIR_DEFINE
} JasmDirKind;
struct JasmDir
{
JasmDirKind kind;
int line;
union
{
JasmExpr *locals;
JasmExpr *args;
struct { char *symbol; JasmExpr *expr; } define;
} u;
JasmDir *next;
};
JasmDir *jasm_dir_make_locals (JasmExpr *expr, int line_number);
JasmDir *jasm_dir_make_args (JasmExpr *expr, int line_number);
JasmDir *jasm_dir_make_define (char *symbol, JasmExpr *expr, int line_number);
struct JasmOperand {
JasmExpr *expr;
union {
int value;
char *label;
} u;
JasmOperand *next;
};
JasmOperand *jasm_operand_make (JasmExpr *expr, JasmOperand *next);
enum JasmInsnKind {
JASM_INSN_GENERIC,
JASM_INSN_LABEL
};
struct JasmInsn
{
JasmInsnKind kind;
union {
struct {
IJVMInsnTemplate *tmpl;
JasmOperand *operands;
} generic;
char *label;
} u;
int pc, line, wide;
JasmInsn *next;
};
JasmInsn *jasm_insn_make_generic (IJVMInsnTemplate *tmpl,
JasmOperand *operands,
int line_number);
JasmInsn *jasm_insn_make_label (char *label, int line_number);
enum JasmExprKind
{
JASM_EXPR_INTEGER,
JASM_EXPR_SYMBOL,
JASM_EXPR_PLUS,
JASM_EXPR_MINUS,
JASM_EXPR_NEG
};
struct JasmExpr
{
JasmExprKind kind;
int line;
int touch;
union
{
unsigned int integer;
char *symbol;
struct { JasmExpr *left, *right; } binop;
JasmExpr *neg;
} u;
};
JasmExpr *jasm_expr_make_integer (unsigned int value, int line_number);
JasmExpr *jasm_expr_make_symbol (char *value, int line_number);
JasmExpr *jasm_expr_make_binop (JasmExprKind kind,
JasmExpr *left, JasmExpr *right,
int line_number);
JasmExpr *jasm_expr_make_neg (JasmExpr *expr, int line_number);
struct JasmDefine
{
char *symbol;
union
{
JasmExpr *expr;
JasmInsn *label;
} u;
JasmDefine *next;
};
struct JasmCPool
{
int *consts;
int length, alloc;
};
JasmCPool *jasm_cpool_make (void);
int jasm_cpool_add (JasmCPool *cpool, int cnst);
void jasm_cpool_emit (JasmCPool *cpool);
int jasm_expr_eval (JasmExpr *expr, JasmMethod *method);
void jasm_abort (const char *fmt, ...);
void jasm_assert (int cond, const char *fmt, ...);
void jasm_warning (const char *fmt, ...);
char *jasm_strdup (const char *str);
int jasm_lex_current_line ();
int jasm_lex_parse_int (const char *token);
JasmMethod *jasm_parse ();
int jasm_method_check (JasmMethod *method, JasmCPool *cpool);
IJVMImage *jasm_emit (JasmMethod *methods, JasmCPool *cpool);
#endif