Repository navigation
Expand file tree
/
Copy pathcodeSeg.h
More file actions
110 lines (101 loc) · 4.41 KB
/
Copy pathcodeSeg.h
File metadata and controls
110 lines (101 loc) · 4.41 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
/***************************************************************************
codeSeg code Module
***************************************************************************/
/*=========================================================================
DECLARATIOCS
=========================================================================*/
/*-------------------------------------------------------------------------
codeSeg code RECORD
-------------------------------------------------------------------------*/
struct codeSeg {
char* label;
char* op;
char* p1;
char* p2;
char* p3;
char* prefix;
struct codeSeg* next;
};
/*-------------------------------------------------------------------------
codeSeg code ENTRY
-------------------------------------------------------------------------*/
struct codeSeg* CStop = (struct codeSeg*) 0;
struct codeSeg* CSbottom = (struct codeSeg*) 0;
/*-------------------------------------------------------------------------
codeSeg code
Implementation: a chain of records.
------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------
initialization
------------------------------------------------------------------------*/
/*========================================================================
Operations: push, pop, isEmpty.
========================================================================*/
void CSPush(char* label, char* op, char* p1, char* p2, char* p3, char* prefix){
struct codeSeg* newBottom = (struct codeSeg* ) malloc(sizeof(struct codeSeg));
newBottom->label = (char *) malloc(strlen(label) + 1);
strcpy(newBottom->label, label);
newBottom->op = (char *) malloc(strlen(op) + 1);
strcpy(newBottom->op, op);
newBottom->p1 = (char *) malloc(strlen(p1) + 1);
strcpy(newBottom->p1, p1);
newBottom->p2 = (char *) malloc(strlen(p2) + 1);
strcpy(newBottom->p2, p2);
newBottom->p3 = (char *) malloc(strlen(p3) + 1);
strcpy(newBottom->p3, p3);
newBottom->prefix = (char *) malloc(strlen(prefix) + 1);
strcpy(newBottom->prefix, prefix);
if(CSbottom == (struct codeSeg*) 0){
CSbottom = newBottom;
CStop = CSbottom;
}
else{
CSbottom->next = newBottom;
}
newBottom->next = (struct codeSeg*) 0;
CSbottom = newBottom;
}
int CSIsEmpty(){
return CStop == (struct codeSeg*) 0;
}
void printCS(){
struct codeSeg* ptr = CStop;
printf(".text\n");
while(ptr != (struct codeSeg*) 0){
if(strcmp(ptr->label, "") != 0 && strcmp(ptr->prefix, "") != 0) printf("%s:\t%s\t%s\t%s\t%s.%s\t\n", ptr->label, ptr->op, ptr->p1, ptr->p2, ptr->prefix, ptr->p3);
else if(strcmp(ptr->label, "") != 0) printf("%s:\t%s\t%s\t%s\t%s%s\t\n", ptr->label, ptr->op, ptr->p1, ptr->p2, ptr->prefix, ptr->p3);
else if(strcmp(ptr->prefix, "") != 0) printf("%s\t%s\t%s\t%s\t%s.%s\t\n", ptr->label, ptr->op, ptr->p1, ptr->p2, ptr->prefix, ptr->p3);
else printf("%s\t%s\t%s\t%s\t%s%s\t\n", ptr->label, ptr->op, ptr->p1, ptr->p2, ptr->prefix, ptr->p3);
ptr = ptr->next;
}
}
void outputCS(){
struct codeSeg* ptr = CStop;
fprintf(yyout,".text\n");
while(ptr != (struct codeSeg*) 0){
if(strcmp(ptr->label, "") != 0 && strcmp(ptr->prefix, "") != 0) fprintf(yyout,"%s:\t%s\t%s\t%s\t%s.%s\t\n", ptr->label, ptr->op, ptr->p1, ptr->p2, ptr->prefix, ptr->p3);
else if(strcmp(ptr->label, "") != 0) fprintf(yyout,"%s:\t%s\t%s\t%s\t%s%s\t\n", ptr->label, ptr->op, ptr->p1, ptr->p2, ptr->prefix, ptr->p3);
else if(strcmp(ptr->prefix, "") != 0) fprintf(yyout,"%s\t%s\t%s\t%s\t%s.%s\t\n", ptr->label, ptr->op, ptr->p1, ptr->p2, ptr->prefix, ptr->p3);
else fprintf(yyout,"%s\t%s\t%s\t%s\t%s%s\t\n", ptr->label, ptr->op, ptr->p1, ptr->p2, ptr->prefix, ptr->p3);
ptr = ptr->next;
}
}
// struct codeSeg* findCodeInst(char *id, char *prefix){
// struct codeSeg* ptr = CStop;
// while(ptr != (struct codeSeg*) 0){
// if(strcmp(ptr->id, id) == 0 && strcmp(ptr->prefix, prefix) == 0){
// return ptr;
// }
// ptr = ptr->next;
// }
// return 0;
// }
// struct CSData* CSPop(){
// if(CSIsEmpty()) return 0;
// struct CSData* temp = CStop->data;
// struct codeSeg* tempTop = CStop->next;
// // free(CStop);
// CStop = tempTop;
// return temp;
// }
/************************** End codeSeg code **************************/