-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasmlabel.c
More file actions
173 lines (148 loc) · 5.2 KB
/
asmlabel.c
File metadata and controls
173 lines (148 loc) · 5.2 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* asmlabel.c */
/*****************************************************************************/
/* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only */
/* */
/* AS Port */
/* */
/* Handle Label on Source Line */
/* */
/*****************************************************************************/
/* ------------------------------------------------------------------------
* Includes
* ------------------------------------------------------------------------ */
#include "stdinc.h"
#include <string.h>
#include "asmdef.h"
#include "asmsub.h"
#include "asmpars.h"
#include "asmstructs.h"
#include "strcomp.h"
#include "asmlabel.h"
/* ------------------------------------------------------------------------
* Local Variables
* ------------------------------------------------------------------------ */
static PStructElem pLabelElement;
static struct sSymbolEntry *pLabelEntry;
static LargeWord LabelValue;
/* ------------------------------------------------------------------------
* Global Functions
* ------------------------------------------------------------------------ */
/*!------------------------------------------------------------------------
* \fn LabelReset(void)
* \brief reset state about most recent label
* ------------------------------------------------------------------------ */
void LabelReset(void)
{
pLabelElement = NULL;
pLabelEntry = NULL;
LabelValue = (LargeWord)-1;
}
/*!------------------------------------------------------------------------
* \fn LabelPresent(void)
* \brief check whether line contains a label
* \return True if label is present
* ------------------------------------------------------------------------ */
Boolean LabelPresent(void)
{
if (!*LabPart.str.p_str)
return False;
if (IsDef())
return False;
switch (*OpPart.str.p_str)
{
case '=':
return !Memo("=");
case ':':
return !Memo(":=");
case '.':
return !Memo(".SET") && !Memo(".EQU");
case 'M':
return !Memo("MACRO");
case 'F':
return !Memo("FUNCTION");
case 'L':
return !Memo("LABEL");
case 'S':
return !memo_set_pseudo() && (!(Memo("STRUCT") || Memo("STRUC")));
case 'E':
if (Memo("EQU") || Memo("ENDSTRUCT") || Memo("ENDS") || Memo("ENDSTRUC") || Memo("ENDUNION"))
return False;
return !Memo("EVAL");
case 'U':
return !Memo("UNION");
default:
return True;
}
}
/*!------------------------------------------------------------------------
* \fn LabelHandle(const tStrComp *pName, LargeWord Value, Boolean ForceGlobal)
* \brief process new label
* \param pName label's name
* \param Value label's value
* \param ForceGlobal force visibility outside macro body
* ------------------------------------------------------------------------ */
void LabelHandle(const tStrComp *pName, LargeWord Value, Boolean ForceGlobal)
{
pLabelElement = NULL;
pLabelEntry = NULL;
/* structure element ? */
if (pInnermostNamedStruct)
{
pLabelElement = CreateStructElem(pName);
if (!pLabelElement)
return;
pLabelElement->Offset = Value;
if (AddStructElem(pInnermostNamedStruct->StructRec, pLabelElement))
AddStructSymbol(pLabelElement->pElemName, Value);
}
/* normal label */
else
{
if (ForceGlobal)
PushLocHandle(-1);
if (RelSegs)
pLabelEntry = EnterRelSymbol(pName, Value, (as_addrspace_t)ActPC, False);
else
{
pLabelEntry = EnterIntSymbolWithFlags(pName, Value, (as_addrspace_t)ActPC, False,
eSymbolFlag_Label |
(Value == AfterBSRAddr ? eSymbolFlag_NextLabelAfterBSR : eSymbolFlag_None));
}
if (ForceGlobal)
PopLocHandle();
}
LabelValue = Value;
}
/*!------------------------------------------------------------------------
* \fn LabelModify(LargeWord OldValue, LargeWord NewValue)
* \brief change value of current label
* \param OldValue current value to check consistency
* \param NewValue new value to assign
* ------------------------------------------------------------------------ */
void LabelModify(LargeWord OldValue, LargeWord NewValue)
{
if (OldValue == LabelValue)
{
if (pLabelElement)
pLabelElement->Offset = NewValue;
if (pLabelEntry)
ChangeSymbol(pLabelEntry, NewValue);
LabelValue = NewValue;
}
}
/*!------------------------------------------------------------------------
* \fn AsmLabelPassInit(void)
* \brief Initializations before passing through sources
* ------------------------------------------------------------------------ */
void AsmLabelPassInit(void)
{
LabelReset();
}
/*!------------------------------------------------------------------------
* \fn asmlabel_init(void)
* \brief Initializations once at startup
* ------------------------------------------------------------------------ */
void asmlabel_init(void)
{
LabelReset();
}