-
Notifications
You must be signed in to change notification settings - Fork 0
/
operationEncoder.h
157 lines (134 loc) · 4.88 KB
/
operationEncoder.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
#ifndef OPERATIONENCODER_H_
#define OPERATIONENCODER_H_
#include <stdbool.h>
#include "structs.h"
/*
* Description: Initializes the operation list used for encoding
* Output: Did the initialization end
*/
bool init_operation_list();
/*
* Description: Adds an operation into the list
* Input: 1. Operation name
* 2. Op code
* 3. Number of operands
* Output: Did add successfully
*/
bool add_operation_to_list(char* name, unsigned int code, int operands);
/*
* Description: Free memory list
*/
void free_operation_list();
/*
* Description: Get all data of operation in line
* Input: 1. Line information
* 2. Can use copy previous address method
* 3. Previous address method
* Output: Operation data
*/
decoded_operation* get_decoded_operation(transition_data* transition);
/*
* Description: Gets the operation name from the line
* Input: Line information
* Output: Operation name
*/
char* get_operation_name(transition_data* transition);
/*
* Description: Searches for an operation name in a pre-defined list of valid operations
* Input: Operation name
* Output: If found returns machine operation information, otherwise NULL
*/
machine_operation_definition* search_machine_operation_in_list(char* operation);
/*
* Description: Reads the operands from the line
* Input: 1. Current transition data
* 2. Number of operands to read
* 3. Returned source operand
* 4. Returned target operand
* Output: Are operands valid
*/
bool get_operands(transition_data* transition, int operands_count, char** source_operand, char** target_operand);
/*
* Description: Reads the next operand from the line
* Input: Current transition
* Output: Operand
*/
char* get_next_operand(transition_data* transition);
/*
* Description: Gets the address method according to the operand
* Input: 1. Current transition
* 2. Current operand
* Output: Address method
*/
ADDRESS_METHOD get_address_method(transition_data* transition, char* operand);
/*
* Description: Checks whether the address methods used in the operation are authorized
* Input: Current decoded operation
* Output: Is authorized
*/
bool are_operand_methods_allowed_in_operation(decoded_operation* current_operation);
/*
* Description: Calculates how many memory words are used to encode the operation
* Input: 1. Current transition data
* 2. Decoded operation
* Output: How many memory words should be used to encode the operation
*/
int calculate_operation_size(transition_data* transition, decoded_operation* current_operation);
/*
* Description: Encodes an operation into its output file
* Input: 1. Current transition data
* 2. Decoded operation
* 3. Output files
* Output: Was the operation encoded successfully
*/
bool encode_operation(transition_data* transition, decoded_operation* p_decoded_operation,
compiler_output_files* output_files);
/*
* Description: Encodes operands into output files
* Input: 1. Current transition data
* 2. Decoded operation
* 3. Output files
* Output: Were operands encoded successfully
*/
bool encode_operands(transition_data* transition, decoded_operation* p_decoded_operation, compiler_output_files* output_files);
/*
* Description: Encodes register operands
* Input: 1. Current transition
* 2. Source register
* 3. Target register
* 3. Output file
* Output: Were operands encoded successfully
*/
bool encode_registers(transition_data* transition, char* source_register, char* target_register, FILE* p_file);
/*
* Description: Encodes a immediate number
* Input: 1. Current transition
* 2. Immediate operand
* 3. Output file
* Output: Was operand encoded successfully
*/
bool encode_immediate(transition_data* transition, char* operand, FILE* p_file);
/*
* Description: Encodes a direct operand
* Input: 1. Current transition
* 2. Direct operand
* 3. Output files
* Output: Was operand encoded successfully
*/
bool encode_direct(transition_data* transition, char* operand, compiler_output_files* output_files);
void create_extern_output_file_if_needed(compiler_output_files* output_files, char* file_name_without_extension);
/*
* Description: Process an operation line on first transition
* Input: 1. Current transition data
* 2. Label value (NULL if doesn't exist)
* 3. Does label exist
*/
void first_transition_process_operation(transition_data* transition, char* label, bool is_symbol);
/*
*
* Description: Process an operation line on second transition
* Input: 1. Current transition data
* 2. Output files
*/
void second_transition_process_operation(transition_data* transition, compiler_output_files* p_output_files);
#endif /* OPERATIONENCODER_H_ */