-
Notifications
You must be signed in to change notification settings - Fork 0
/
secondpass.h
146 lines (133 loc) · 6.11 KB
/
secondpass.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
#include "shared_fp_sp.h"
enum SecondpassErrors {Extern_Declared = 0, Entry_Not_Declared, Unknown_Label};
/**
* This function invokes the second pass of the assembly process, updating data labels' addresses,
* completing extent data, mapping entry labels, and writing the output files if no errors are found.
*
* @param dcImage Pointer to the data counter image.
* @param icImage Pointer to the instruction counter image.
* @param labelTable Pointer to the label table.
* @param head Pointer to the extent label linked list.
* @param mapHead Pointer to the maplabel linked list.
* @param filename Name of the source file.
* @param labelCount Number of labels in the label table.
* @param dc Data counter value.
* @param ic Instruction counter value.
* @param fpf Pointer to the number of fully processed files.
* @return The success status of invoking the second pass.
*/
int invoke_secondpass(char*** dcImage, char*** icImage, label* labelTable, extentlabel* head, maplabel* mapHead, char* filename, int labelCount, int dc, int ic, int* fpf);
/**
* This function maps entry labels to their corresponding address in the instruction counter image.
*
* @param icImage Pointer to the instruction counter image.
* @param labelTable Pointer to the label table.
* @param head Pointer to the extent label linked list.
* @param mapHead Pointer to the maplabel linked list.
* @param ic Instruction counter value.
* @param labelCount Number of labels in the label table.
* @return The success status of mapping entry labels.
*/
int map_entry_labels(char*** icImage, label* labelTable, extentlabel* head, maplabel* mapHead, int ic, int labelCount);
/**
* This function writes the output object file containing the encoded instruction and data words.
*
* @param icArray Pointer to the instruction counter image.
* @param dcArray Pointer to the data counter image.
* @param filename Name of the source file.
* @param ic Instruction counter value.
* @param dc Data counter value.
* @return The success status of writing the object file.
*/
int write_ob_file(char** icArray, char** dcArray, char* filename, int ic, int dc);
/**
* This function opens a file and assigns it to a file pointer if not already opened.
*
* @param filePtr Pointer to the file pointer.
* @param filename Name of the file.
* @param extention File extension.
* @param flag Flag indicating whether the file is already opened.
* @return The success status of opening the file.
*/
int get_file_and_flag(FILE** filePtr, char* filename, char* extention, int* flag);
/**
* This function writes extent and entry data to the corresponding .ext and .ent files.
*
* @param labelTable Pointer to the label table.
* @param head Pointer to the extent label linked list.
* @param filename Name of the source file.
* @param labelCount Number of labels in the label table.
* @return The success status of writing the extent and entry files.
*/
int write_extent_file(label* labelTable, extentlabel* head, char* filename, int labelCount);
/**
* This function prints extent label information to the external file.
*
* @param head Pointer to the extent label linked list.
* @param extFile Pointer to the external file.
* @return The success status of printing extent label information.
*/
int print_extern(extentlabel head, FILE* extFile);
/**
* This function completes extent data by updating the addresses of extent labels and handling .entry labels.
*
* @param icImage Pointer to the instruction counter image.
* @param labelTable Pointer to the label table.
* @param head Pointer to the extent label linked list.
* @param ic Instruction counter value.
* @param labelCount Number of labels in the label table.
* @return The success status of completing extent data.
*/
int complete_extent_data(char*** icImage, label* labelTable, extentlabel* head, int ic, int labelCount);
/**
* This function gets the address of an entry label from the label table and updates the extent label's address.
*
* @param labelTable Pointer to the label table.
* @param head Pointer to the extent label linked list.
* @param labelCount Number of labels in the label table.
* @return The success status of getting entry label data.
*/
int get_data_entry(label* labelTable, extentlabel* head, int labelCount);
/**
* This function gets the address of an extern label from the instruction counter image and updates the extent label's address.
*
* @param icImage Pointer to the instruction counter image.
* @param head Pointer to the extent label linked list.
* @param ic Instruction counter value.
* @return The success status of getting extern label data.
*/
int get_data_extern(char*** icImage, extentlabel* head, int ic);
/**
* This function converts a binary string to a base64 character using a base64Table.
*
* @param base64Table Base64 encoding table.
* @param binary Binary string to convert.
* @param start Start index of the binary string.
* @return The base64 character.
*/
char binary_to_base64(char* base64Table, char* binary, int start);
/**
* This function updates the addresses of data labels in the label table by adding the final value of ic.
*
* @param labelTable Pointer to the label table.
* @param labelCount Number of labels in the label table.
* @param ic Instruction counter value.
* @return The success status of updating data label addresses.
*/
int update_datalabels_addr(label* labelTable, int labelCount, int ic);
/**
* This function handles and reports errors specific to the second pass, setting the sp_status flag accordingly.
*
* @param errorCode Error code indicating the type of error.
* @param lineNum Line number where the error occurred.
* @return The status indicating whether an error occurred.
*/
int sp_error_handler(int errorCode, int lineNum);
/**
* This function finds a label in the maplabel linked list.
*
* @param head Pointer to the maplabel linked list.
* @param icAddress Address of the label to find.
* @return Pointer to the maplabel node containing the label.
*/
maplabel* find_maplabel(maplabel* head, int icAddress);