Browse code

Sublabels add refs to root labels in uxnasm

neauoire authored on 16/09/2021 16:11:53
Showing 2 changed files
... ...
@@ -33,7 +33,6 @@
33 33
 
34 34
 @last-note   $1
35 35
 @octave      $1
36
-@color       $1
37 36
 @pointer     [ &x $2 &y $2 ]
38 37
 @center      [ &x $2 &y $2 ]
39 38
 @adsr-view   [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
... ...
@@ -46,6 +46,7 @@ static char ops[][4] = {
46 46
 	"ADD", "SUB", "MUL", "DIV", "AND", "ORA", "EOR", "SFT"
47 47
 };
48 48
 
49
+static int   cpos(char *s, char a){ int i = 0; char c; while((c = s[i++])) if(c == a) return i; return -1; }
49 50
 static int   scmp(char *a, char *b, int len) { int i = 0; while(a[i] == b[i]) if(!a[i] || ++i >= len) return 1; return 0; } /* string compare */
50 51
 static int   sihx(char *s) { int i = 0; char c; while((c = s[i++])) if(!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f')) return 0; return i > 1; } /* string is hexadecimal */
51 52
 static int   shex(char *s) { int n = 0, i = 0; char c; while((c = s[i++])) if(c >= '0' && c <= '9') n = n * 16 + (c - '0'); else if(c >= 'a' && c <= 'f') n = n * 16 + 10 + (c - 'a'); return n; } /* string to num */
... ...
@@ -183,6 +184,18 @@ makelabel(char *name)
183 184
 	return 1;
184 185
 }
185 186
 
187
+static int
188
+addref(Label *l)
189
+{
190
+	int pos = cpos(l->name, '/');
191
+	if(pos != -1) {
192
+		char root[64];
193
+		Label *rl = findlabel(scpy(l->name, root, pos));
194
+		++rl->refs;
195
+	}
196
+	return ++l->refs;
197
+}
198
+
186 199
 static int
187 200
 skipblock(char *w, int *cap, char a, char b)
188 201
 {
... ...
@@ -231,19 +244,19 @@ parsetoken(char *w)
231 244
 		if(l->addr > 0xff)
232 245
 			return error("Address is not in zero page", w);
233 246
 		pushbyte(l->addr, 1);
234
-		return ++l->refs;
247
+		return addref(l);
235 248
 	} else if(w[0] == ',' && (l = findlabel(w + 1))) { /* relative */
236 249
 		int off = l->addr - p.ptr - 3;
237 250
 		if(off < -126 || off > 126)
238 251
 			return error("Address is too far", w);
239 252
 		pushbyte((Sint8)off, 1);
240
-		return ++l->refs;
253
+		return addref(l);
241 254
 	} else if(w[0] == ':' && (l = findlabel(w + 1))) { /* raw */
242 255
 		pushshort(l->addr, 0);
243
-		return ++l->refs;
256
+		return addref(l);
244 257
 	} else if(w[0] == ';' && (l = findlabel(w + 1))) { /* absolute */
245 258
 		pushshort(l->addr, 1);
246
-		return ++l->refs;
259
+		return addref(l);
247 260
 	} else if(findopcode(w) || scmp(w, "BRK", 4)) { /* opcode */
248 261
 		pushbyte(findopcode(w), 0);
249 262
 		return 1;