-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast.h
More file actions
114 lines (104 loc) · 2.2 KB
/
Copy pathast.h
File metadata and controls
114 lines (104 loc) · 2.2 KB
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
#pragma once
#include <stddef.h>
#include <stdint.h>
typedef enum { POWER_SPRING, POWER_SUMMER, POWER_AUTUMN, POWER_WINTER, POWER_STRING, POWER_CHAR } kyou_power_t;
typedef enum { REG_FIRE, REG_WATER, REG_TREE, REG_METAL, REG_EARTH, REG_STORAGE, REG_STORAGE_BASE } kyou_register_t;
typedef enum {
MOVE_STATEMENT,
OPERATOR_STATEMENT,
LABEL,
BRANCH_STATEMENT,
PUSH_STATEMENT,
POP_STATEMENT,
CALL_STATEMENT,
RETURN_STATEMENT,
STORE,
TEMP_STR_PRINT
} AST_node_type;
typedef struct {
kyou_power_t power;
union {
int8_t as_int8;
int16_t as_int16;
int32_t as_int32;
int64_t as_int64;
const char* as_string;
char as_char;
};
} AST_value;
typedef struct {
enum { ADDRESS_LABEL, ADDRESS_IMMEDIATE, ADDRESS_REGISTER } type;
union {
const char* as_label;
size_t as_immediate;
kyou_register_t as_reg;
};
} AST_address;
typedef struct {
enum { SOURCE_REGISTER, SOURCE_IMMEDIATE, SOURCE_MEM, SOURCE_FD, SOURCE_LABEL } type;
kyou_power_t power;
union {
kyou_register_t as_reg;
int64_t as_immediate;
AST_address as_mem;
int as_fd;
const char* as_label;
};
} AST_source;
typedef struct {
enum { DESTINATION_REGISTER, DESTINATION_MEM, DESTINATION_FD } type;
kyou_power_t power;
union
{
kyou_register_t as_reg;
AST_address as_mem;
int as_fd;
};
} AST_destination;
typedef struct
{
AST_node_type type;
union {
struct {
AST_source move_src;
AST_destination move_dest;
};
struct {
kyou_register_t op_reg;
kyou_power_t op_power;
enum { OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_OR, OP_AND, OP_XOR } op_type;
AST_source op_src;
};
struct {
union {
const char* id;
size_t as_size_t;
};
};
struct {
enum { BRANCH_ALWAYS, BRANCH_GREATER, BRANCH_LESS, BRANCH_EQUALS, BRANCH_GREATER_OR_EQ, BRANCH_LESS_OR_EQ } branch_type;
AST_address branch_addr;
AST_source branch_a;
AST_source branch_b;
};
struct {
AST_source push_from;
};
struct {
AST_destination pop_to;
};
struct {
AST_address call_to;
};
struct {
AST_value value;
};
};
} AST_node;
typedef struct
{
AST_node* nodes;
size_t size;
} AST;
typedef enum { AST_SUCCESS, AST_ERROR } ast_result_t;
ast_result_t build_ast(AST* ast, unsigned char* data, size_t data_size);