-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSemantics.h
More file actions
158 lines (142 loc) · 4.77 KB
/
Copy pathSemantics.h
File metadata and controls
158 lines (142 loc) · 4.77 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
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
#pragma once
#include "SymTab.h"
#include "CodeGen.h"
/**
* @brief Defines a type name and its array dimensionality and size.
*/
struct type_desc_t
{
/**
* @brief Type name of the described variable "datatype."
*/
char *name;
/**
* @brief Count of dimensions of the array (e.g., 1D or 3D).
*
*/
int arr_dim_c;
/**
* @brief Array of integers containing the array size in every dimension.
*/
int *arr_dim;
/**
* @brief Whether this type is a pointer or an actual value.
*/
int is_reference;
};
typedef struct type_desc_t type_desc_t;
/**
* @brief Contains sequence of commands for and the index of the register
* holding results of an operation.
*/
struct expr_res_t
{
/**
* @brief Register holding expression result's value after excecution.
*/
int reg;
/**
* @brief First node of the linked sequence of assembly instructions used to
* perform the expression calculation.
*/
struct instr_t *body;
/**
* @brief Optional label field; I do not use this value for any purpose.
*/
char *label;
/**
* @brief Field for storing resolved variable type definitions.
*/
type_desc_t *type;
/**
* @brief Marks something as an array pass-by-value expression.
*/
int is_array_by_val;
};
typedef struct expr_res_t expr_res_t;
/**
* @brief Collection of expression results for indexing into a multi-dimensional
* array datatype during runtime.
*/
struct arr_expr_t
{
/**
* @brief Count of dimensions of the array (e.g., 1D or 3D).
*/
int arr_dim_c;
/**
* @brief Array of expression result structs for the array indices.
*/
struct expr_res_t **arr_dim;
};
typedef struct arr_expr_t arr_expr_t;
// Mappings for generating integer expression sequences
expr_res_t *do_int_lit(char *digits);
expr_res_t *do_add(expr_res_t *l, expr_res_t *r);
expr_res_t *do_mult(expr_res_t *l, expr_res_t *r);
expr_res_t *do_sub(expr_res_t *l, expr_res_t *r);
expr_res_t *do_div(expr_res_t *l, expr_res_t *r);
expr_res_t *do_modulo(expr_res_t *l, expr_res_t *r);
expr_res_t *do_negate(expr_res_t *expr);
expr_res_t *do_pow(expr_res_t *l, expr_res_t *r);
// Mappings for performing comparisons and logic
expr_res_t *do_compare(expr_res_t *l, expr_res_t *r);
expr_res_t *do_less_than(expr_res_t *l, expr_res_t *r);
expr_res_t *do_less_than_e(expr_res_t *l, expr_res_t *r);
expr_res_t *do_greater_than(expr_res_t *l, expr_res_t *r);
expr_res_t *do_greater_than_e(expr_res_t *l, expr_res_t *r);
expr_res_t *do_and(expr_res_t *l, expr_res_t *r);
expr_res_t *do_or(expr_res_t *l, expr_res_t *r);
expr_res_t *do_not_eq(expr_res_t *l, expr_res_t *r);
expr_res_t *do_not(expr_res_t *expr);
// Mappings for generating memory load/store operations
expr_res_t *do_load(expr_res_t *var, arr_expr_t *arr);
instr_t *do_store(expr_res_t *var, arr_expr_t *arr, expr_res_t *expr);
// Mappings for generating I/O operations and syscalls
instr_t *do_print(expr_res_t *expr);
instr_t *do_read(char *name);
instr_t *do_print_l(expr_res_t *expr);
instr_t *do_print_s(expr_res_t *expr);
char *do_str_lit(char *chars);
instr_t *do_print_str(char *label);
// Mappings for generating control structures and loops
instr_t *do_if(expr_res_t *expr, instr_t *body);
instr_t *do_if_else(expr_res_t *expr, instr_t *body, instr_t *b_else);
instr_t *do_while(expr_res_t *expr, instr_t *body);
instr_t *do_for(instr_t *pre, expr_res_t *expr, instr_t *post, instr_t *body);
// Mappings for types and multi-dimensional array index operators
type_desc_t *do_type_desc(char *name, int dims, int *sizes, int is_reference);
type_desc_t *do_arr_seq(type_desc_t *l, type_desc_t *r, int size);
arr_expr_t *do_arr_expr(arr_expr_t *l, arr_expr_t *r, expr_res_t *size);
// Final accept state action to print out the final sequence
void accept_body(instr_t *Code);
// Mappings for generating method bodies
instr_t *do_func(char *name, instr_t *decl, type_desc_t *type, instr_t *body);
/**
* @brief Stores global variables and their type descriptors for reference.
*/
extern SymTab *table;
/**
* @brief Contains string literals for the data section during acceptance.
*/
extern SymTab *str_lits;
/**
* @brief Stack for tracking variable scopes
*/
extern variable_t scope_stack[];
/**
* @brief Index of the active stack frame in the scope stack.
*/
extern int scope_index;
// Mappings for operating the scope stack for scoped bodies of code
instr_t *declare(char *name, type_desc_t *type);
void push();
expr_res_t *alloc_expr();
instr_t *peek();
instr_t *pop();
expr_res_t *resolve(char *name);
expr_res_t *do_invoke(instr_t *s_s, char *name, instr_t *args);
instr_t *do_call_expr(expr_res_t *expr);
instr_t *do_return(expr_res_t *expr);
extern unsigned int incidental_offset;
extern char *return_label;