File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -263,6 +263,20 @@ namespace zasm
263
263
// / <returns>Node for which the label is bound to or null if the label is invalid or not bound</returns>
264
264
Node* getNodeForLabel (const Label& label);
265
265
266
+ // / <summary>
267
+ // / Returns the current assigned label name, returns nullptr if the label is invalid or has no name.
268
+ // / </summary>
269
+ // / <param name="label">Label</param>
270
+ // / <returns>Label name or nullptr</returns>
271
+ const char * getLabelName (const Label& label) const noexcept ;
272
+
273
+ // / <summary>
274
+ // / Assigns a name to a label.
275
+ // / </summary>
276
+ // / <param name="label">Label</param>
277
+ // / <param name="name">The new name, pasing nullptr will clear the name</param>
278
+ void setLabelName (const Label& label, const char * name);
279
+
266
280
public:
267
281
// / <summary>
268
282
// / Creates a new section that can be used to segment code and data.
Original file line number Diff line number Diff line change @@ -110,6 +110,54 @@ namespace zasm
110
110
return entry.node ;
111
111
}
112
112
113
+ const char * Program::getLabelName (const Label& label) const noexcept
114
+ {
115
+ if (!label.isValid ())
116
+ {
117
+ return nullptr ;
118
+ }
119
+
120
+ const auto entryIdx = static_cast <std::size_t >(label.getId ());
121
+ if (entryIdx >= _state->labels .size ())
122
+ {
123
+ return nullptr ;
124
+ }
125
+
126
+ auto & entry = _state->labels [entryIdx];
127
+ if (entry.nameId != StringPool::Id::Invalid)
128
+ {
129
+ return _state->symbolNames .get (entry.nameId );
130
+ }
131
+
132
+ return nullptr ;
133
+ }
134
+
135
+ void Program::setLabelName (const Label& label, const char * name)
136
+ {
137
+ if (!label.isValid ())
138
+ {
139
+ return ;
140
+ }
141
+
142
+ const auto entryIdx = static_cast <std::size_t >(label.getId ());
143
+ if (entryIdx >= _state->labels .size ())
144
+ {
145
+ return ;
146
+ }
147
+
148
+ auto & entry = _state->labels [entryIdx];
149
+ if (entry.nameId != StringPool::Id::Invalid)
150
+ {
151
+ _state->symbolNames .release (entry.nameId );
152
+ entry.nameId = StringPool::Id::Invalid;
153
+ }
154
+
155
+ if (name != nullptr )
156
+ {
157
+ entry.nameId = _state->symbolNames .aquire (name);
158
+ }
159
+ }
160
+
113
161
Node* Program::getNodeForSection (const Section& section)
114
162
{
115
163
if (!section.isValid ())
You can’t perform that action at this time.
0 commit comments