-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecondpass.c
116 lines (104 loc) · 2.56 KB
/
secondpass.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
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
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "table.h"
#include "globals.h"
#include "secondpass.h"
#include "func.h"
bool process_line_spss(line_info line,Node** table,MachineNode** table2)
{
bool NO_ERROR=TRUE;
char tmp_istr[MAX_LINE_LENGTH];
char* token=NULL;
const char space[2]=" ";
Node* head=NULL;
bool entryFound = FALSE;
bool entryToken = FALSE;
int i=0;
SKIP_NEXT(line.content,i);
if(line.content[i]=='.')
{
strcpy(tmp_istr,line.content+i+1);
token = strtok(tmp_istr,space);
if(find_instruction_by_name(token)==ENTRY_INST)
{
token = strtok(NULL,space);
token = copyStringOnly(token);
if(token) entryToken=TRUE;
head = (*table);
while(head!=NULL)/*loop throw symbole table*/
{
if(!strcmp(head->key,token))/*entry found*/
{
entryFound=TRUE;
head->entry = ENTRY_INST; /*mark entry as entry in the node*/
}
head = head->next;
}
free(token);
token=NULL;
}
}
if(entryToken && !entryFound)
{
print_error(line,"Entry can't be found in file");
NO_ERROR=FALSE;
}
return NO_ERROR;
}
bool fillTable(Node** table,MachineNode** table2,long ICF,long DCF)
{
bool NO_ERROR = TRUE;
instruction InstrucationType=NONE_OPERAND;
MachineNode* head=NULL;
long value =0;
operandType opType = NONE_OPERAND;
if((*table2)==NULL)
return FALSE;
head=(*table2);
/*Loop throw all the table*/
while(head!=NULL)
{
if(head->label) /*if label saved at the machine word table*/
{
if(isLabelInTable((*table),head->label))/*if label in symbol table*/
{
InstrucationType = getLabelType((*table),head->label);
value = getLabelValue((*table),head->label);
opType = head->opType;
if(opType==DIR_OPERAND)
{
if(InstrucationType==DATA_INST || InstrucationType==STRING_INST)
{
head->machineWord = (int)ICF+(unsigned long)value;
head->are = R;
}else{
head->machineWord =(unsigned long)value;
if(InstrucationType==NONE_INST)
head->are = A;
else
head->are = E;
}
}
if(opType==REL_OPERAND)
{
if(InstrucationType==DATA_INST || InstrucationType==STRING_INST)
{
head->machineWord = (int)ICF+(unsigned long)value-((int)head->adress-1);
head->are = R;
}else{
head->machineWord = (unsigned long)value-((unsigned int)head->adress-1);
head->are = R;
}
}
}else
{
printf("the %s label haven't declred at code\n",head->label);
NO_ERROR=FALSE;
}
}
head=head->next;
}
return NO_ERROR;
}