-
Notifications
You must be signed in to change notification settings - Fork 0
/
passManager.c
82 lines (72 loc) · 2.21 KB
/
passManager.c
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
/*
====================================================================================
Module: passManager
Description: manages data allocation and first and second passes
====================================================================================
*/
#include "header.h"
/*----------------------------------------------------------------------------*/
/*
* Description: manages the first and second pass, and file creation
* Input: pointer to the current file being read
* Output: 1 if successful, 0 otherwise
*/
/*----------------------------------------------------------------------------*/
int passManager(FILE *file, char *filename) {
/* create and initialize the data structures */
Data data;
initializeData(&data);
/* go over the code for the first time*/
firstPassManager(&data, file);
/* if there's an error, don't continue */
if (data.containError == TRUE) {
return 0;
}
return 1;
}
/*----------------------------------------------------------------------------*/
/*
* Description: initializes the variables in the Data struct
* Input: pointer to Data struct
* Output: nothing
*/
/*----------------------------------------------------------------------------*/
void initializeData(Data *data) {
int IC = 100;
int DC = 0;
/* initialize all the data in the data struct */
data->tc = 0;
data->lc = 0;
data->dc = DC;
data->ic = IC;
data->exc = 0;
data->enc = 0;
data->wc = 0;
/*
data->instArr = NULL;
data->wordArr = NULL;
*/
data->containError = FALSE;
data->tagArr = NULL;
data->directiveArr = NULL;
data->entryArr = NULL;
data->externArr = NULL;
}
/*----------------------------------------------------------------------------*/
/*
* Description: frees all the dynamically allocated memory in the Data struct
* Input: pointer to Data struct
* Output: nothing
*/
/*----------------------------------------------------------------------------*/
void setDataFree(Data * data){
/* free all the data in the data struct */
free(data->tagArr);
free(data->directiveArr);
free(data->externArr);
free(data->entryArr);
/*
free(data->instArr);
free(data->wordArr);
*/
}