]> Shamusworld >> Repos - rmac/blob - procln.c
Multiple fixes for 020+ mode, including:
[rmac] / procln.c
1 //
2 // RMAC - Reboot's Macro Assembler for all Atari computers
3 // PROCLN.C - Line Processing
4 // Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends
5 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
6 // Source utilised with the kind permission of Landon Dyer
7 //
8
9 #include "procln.h"
10 #include "6502.h"
11 #include "amode.h"
12 #include "direct.h"
13 #include "error.h"
14 #include "expr.h"
15 #include "listing.h"
16 #include "mach.h"
17 #include "macro.h"
18 #include "riscasm.h"
19 #include "sect.h"
20 #include "symbol.h"
21
22 #define DEF_KW                                  // Declare keyword values
23 #include "kwtab.h"                              // Incl generated keyword tables & defs
24
25 #define DEF_MN                                  // Incl 68k keyword definitions
26 #define DECL_MN                                 // Incl 68k keyword state machine tables
27 #include "mntab.h"
28
29 #define DEF_MR
30 #define DECL_MR
31 #include "risckw.h"
32
33 #define DEF_MP                                  // Include 6502 keyword definitions
34 #define DECL_MP                                 // Include 6502 keyword state machine tables
35 #include "6502kw.h"
36
37 IFENT * ifent;                                  // Current ifent
38 static IFENT ifent0;                    // Root ifent
39 IFENT * f_ifent;                                // Freelist of ifents
40 int disabled;                                   // Assembly conditionally disabled
41 int just_bss;                                   // 1, ds.b in microprocessor mode
42 VALUE pcloc;                                    // Value of "PC" at beginning of line
43 SYM * lab_sym;                                  // Label on line (or NULL)
44
45 const char extra_stuff[] = "extra (unexpected) text found after addressing mode";
46 const char comma_error[] = "missing comma";
47 const char syntax_error[] = "syntax error";
48 const char locgl_error[] = "cannot GLOBL local symbol";
49 const char lab_ignored[] = "label ignored";
50
51 // Table to convert an addressing-mode number to a bitmask.
52 LONG amsktab[0124] = {
53         M_DREG, M_DREG, M_DREG, M_DREG,
54         M_DREG, M_DREG, M_DREG, M_DREG,
55
56         M_AREG, M_AREG, M_AREG, M_AREG,
57         M_AREG, M_AREG, M_AREG, M_AREG,
58
59         M_AIND, M_AIND, M_AIND, M_AIND,
60         M_AIND, M_AIND, M_AIND, M_AIND,
61
62         M_APOSTINC, M_APOSTINC, M_APOSTINC, M_APOSTINC,
63         M_APOSTINC, M_APOSTINC, M_APOSTINC, M_APOSTINC,
64
65         M_APREDEC, M_APREDEC, M_APREDEC, M_APREDEC,
66         M_APREDEC, M_APREDEC, M_APREDEC, M_APREDEC,
67
68         M_ADISP, M_ADISP, M_ADISP, M_ADISP,
69         M_ADISP, M_ADISP, M_ADISP, M_ADISP,
70
71         M_AINDEXED, M_AINDEXED, M_AINDEXED, M_AINDEXED,
72         M_AINDEXED, M_AINDEXED, M_AINDEXED, M_AINDEXED,
73
74         M_ABSW,                 // 070
75         M_ABSL,                 // 071
76         M_PCDISP,               // 072
77         M_PCINDEXED,    // 073
78         M_IMMED,                // 074
79         0L,                             // 075
80         0L,                             // 076
81         0L,                             // 077
82         M_ABASE,                // 0100
83         M_MEMPOST,              // 0101
84         M_MEMPRE,               // 0102
85         M_PCBASE,               // 0103
86         M_PCMPOST,              // 0104
87         M_PCMPRE,               // 0105
88         M_AM_USP,               // 0106
89         M_AM_SR,                // 0107
90         M_AM_CCR,               // 0110
91         M_AM_NONE,              // 0111
92         0x30,                   // 0112
93         0x30,                   // 0113
94         0L,                             // 0114
95         0L,                             // 0115
96         0L,                             // 0116
97         0L,                             // 0117
98     M_CACHE40,                                                                      // 0120
99         M_CREG,                 // 0121
100         M_FREG,                 // 0122
101         M_FPSCR                 // 0123
102 };                                      // 0123 length
103
104
105 // Function prototypes
106 int HandleLabel(char *, int);
107
108
109 //
110 // Initialize line processor
111 //
112 void InitLineProcessor(void)
113 {
114         disabled = 0;
115         ifent = &ifent0;
116         f_ifent = ifent0.if_prev = NULL;
117         ifent0.if_state = 0;
118 }
119
120
121 //
122 // Line processor
123 //
124 void Assemble(void)
125 {
126         int state;                                      // Keyword machine state (output)
127         int j;                                          // Random int, must be fast
128         char * p;                                       // Random char ptr, must be fast
129         TOKEN * tk;                                     // First token in line
130         char * label;                           // Symbol (or NULL)
131         char * equate;                          // Symbol (or NULL)
132         int labtyp = 0;                         // Label type (':', DCOLON)
133         int equtyp = 0;                         // Equ type ('=', DEQUALS)
134         VALUE eval;                                     // Expression value
135         WORD eattr;                                     // Expression attributes
136         SYM * esym;                                     // External symbol involved in expr.
137         WORD siz = 0;                           // Size suffix to mnem/diretve/macro
138         LONG amsk0, amsk1;                      // Address-type masks for ea0, ea1
139         MNTAB * m;                                      // Code generation table pointer
140         SYM * sy, * sy2;                        // Symbol (temp usage)
141         char * opname = NULL;           // Name of dirctve/mnemonic/macro
142         int listflag;                           // 0: Don't call listeol()
143         WORD rmask;                                     // Register list, for REG
144         int registerbank;                       // RISC register bank
145         int riscreg;                            // RISC register
146         listflag = 0;                           // Initialise listing flag
147
148 loop:                                                   // Line processing loop label
149
150         // Get another line of tokens
151         if (TokenizeLine() == TKEOF)
152         {
153 DEBUG { printf("Assemble: Found TKEOF flag...\n"); }
154                 if (list_flag && listflag)                      // Flush last line of source
155                         listeol();
156
157                 if (ifent->if_prev != NULL)                     // Check conditional token
158                         error("hit EOF without finding matching .endif");
159
160                 return;
161         }
162
163         DEBUG { DumpTokenBuffer(); }
164
165         if (list_flag)
166         {
167                 if (listflag && listing > 0)
168                         listeol();                                              // Tell listing generator about EOL
169
170                 lstout((char)(disabled ? '-' : lntag)); // Prepare new line for listing
171                 listflag = 1;                                           // OK to call `listeol' now
172                 just_bss = 0;                                           // Reset just_bss mode
173         }
174
175         state = -3;                                                             // No keyword (just EOL)
176         label = NULL;                                                   // No label
177         lab_sym = NULL;                                                 // No (exported) label
178         equate = NULL;                                                  // No equate
179         tk = tok;                                                               // Save first token in line
180         pcloc = (VALUE)sloc;                                    // Set beginning-of-line PC
181
182 loop1:                                                                          // Internal line processing loop
183
184         if (*tok == EOL)                                                // Restart loop if end-of-line
185                 goto loop;
186
187         // First token MUST be a symbol (Shamus: not sure why :-/)
188         if (*tok != SYMBOL)
189         {
190                 if ((*tok >= KW_D0) && (*tok <= KW_R31))
191                         error("cannot use reserved keyword as label name or .equ");
192                 else
193                         error("syntax error; expected symbol");
194
195                 goto loop;
196         }
197
198         j = (int)tok[2];                                                // Skip equates (normal statements)
199
200         if (j == '=' || j == DEQUALS || j == SET || j == REG || j == EQUREG || j == CCDEF)
201         {
202                 equate = string[tok[1]];
203                 equtyp = j;
204                 tok += 3;
205                 goto normal;
206         }
207
208         // Skip past label (but record it)
209         if (j == ':' || j == DCOLON)
210         {
211 as68label:
212                 label = string[tok[1]];                         // Get label name
213                 labtyp = tok[2];                                        // Get label type
214                 tok += 3;                                                       // Go to next line token
215
216                 // AS68 MODE:
217                 // Looks like another label follows the previous one, so handle
218                 // the previous one until there aren't any more
219                 if (as68_flag && (*tok == SYMBOL && tok[2] == ':'))
220                 {
221                         if (HandleLabel(label, labtyp) != 0)
222                                 goto loop;
223
224                         goto as68label;
225                 }
226         }
227
228         // EOL is legal here...
229         if (*tok == EOL)
230                 goto normal;
231
232         // Next token MUST be a symbol
233         if (*tok++ != SYMBOL)
234         {
235                 error("syntax error; expected symbol");
236                 goto loop;
237         }
238
239         opname = p = string[*tok++];
240
241         // Check to see if the SYMBOL is a keyword (a mnemonic or directive).
242         // On output, `state' will have one of the values:
243         //    -3          there was no symbol (EOL)
244         //    -2..-1      the symbol didn't match any keyword
245         //    0..499      vanilla directives (dc, ds, etc.)
246         //    500..999    electric directives (macro, rept, etc.)
247         //    1000..+     mnemonics (move, lsr, etc.)
248         for(state=0; state>=0;)
249         {
250                 j = mnbase[state] + (int)tolowertab[*p];
251
252                 // Reject, character doesn't match
253                 if (mncheck[j] != state)
254                 {
255                         state = -1;                                             // No match
256                         break;
257                 }
258
259                 // Must accept or reject at EOS
260                 if (!*++p)
261                 {
262                         state = mnaccept[j];                    // (-1 on no terminal match)
263                         break;
264                 }
265
266                 state = mntab[j];
267         }
268
269         // Check for ".b" ".w" ".l" after directive, macro or mnemonic.
270         siz = SIZN;
271
272     switch (*tok)
273     {
274     case DOTW: siz = SIZW, tok++; break;
275     case DOTL: siz = SIZL, tok++; break;
276     case DOTB: siz = SIZB, tok++; break;
277     case DOTD: siz = SIZD, tok++; break;
278     case DOTP: siz = SIZP, tok++; break;
279     case DOTQ: siz = SIZQ, tok++; break;
280     case DOTS: siz = SIZS, tok++; break;
281     case DOTX: siz = SIZX, tok++; break;
282     }
283
284
285         // Do special directives (500..999) (These must be handled in "real time")
286         if (state >= 500 && state < 1000)
287         {
288                 switch (state)
289                 {
290                 case MN_IF:
291                         d_if();
292                         goto loop;
293
294                 case MN_ELSE:
295                         d_else();
296                         goto loop;
297
298                 case MN_ENDIF:
299                         d_endif();
300                         goto loop;
301
302                 case MN_IIF:                                            // .iif --- immediate if
303                         if (disabled || expr(exprbuf, &eval, &eattr, &esym) != OK)
304                                 goto loop;
305
306                         if (!(eattr & DEFINED))
307                         {
308                                 error(undef_error);
309                                 goto loop;
310                         }
311
312                         if (*tok++ != ',')
313                         {
314                                 error(comma_error);
315                                 goto loop;
316                         }
317
318                         if (eval == 0)
319                                 goto loop;
320
321                         goto loop1;
322
323                 case MN_MACRO:                                          // .macro --- macro definition
324                         if (!disabled)
325                         {
326                                 // Label on a macro definition is bad mojo... Warn the user
327                                 if (label != NULL)
328                                         warn(lab_ignored);
329
330                                 DefineMacro();
331                         }
332
333                         goto loop;
334
335                 case MN_EXITM:                                          // .exitm --- exit macro
336                 case MN_ENDM:                                           // .endm --- same as .exitm
337                         if (!disabled)
338                         {
339                                 if (label != NULL)
340                                         warn(lab_ignored);
341
342                                 ExitMacro();
343                         }
344
345                         goto loop;
346
347                 case MN_REPT:
348                         if (!disabled)
349                         {
350                                 // Handle labels on REPT directive lines...
351                                 if (label)
352                                 {
353                                         if (HandleLabel(label, labtyp) != 0)
354                                                 goto loop;
355                                 }
356
357                                 HandleRept();
358                         }
359
360                         goto loop;
361
362                 case MN_ENDR:
363                         if (!disabled)
364                                 error("mis-nested .endr");
365
366                         goto loop;
367                 }
368         }
369
370 normal:
371         if (disabled)                                                   // Conditionally disabled code
372                 goto loop;
373
374         // Do equates
375         if (equate != NULL)
376         {
377                 // Pick global or local symbol enviroment
378                 j = (*equate == '.' ? curenv : 0);
379                 sy = lookup(equate, LABEL, j);
380
381                 if (sy == NULL)
382                 {
383                         sy = NewSymbol(equate, LABEL, j);
384                         sy->sattr = 0;
385
386                         if (equtyp == DEQUALS)
387                         {
388                                 // Can't GLOBAL a local symbol
389                                 if (j)
390                                 {
391                                         error(locgl_error);
392                                         goto loop;
393                                 }
394
395                                 sy->sattr = GLOBAL;
396                         }
397                 }
398                 else if ((sy->sattr & DEFINED) && equtyp != SET)
399                 {
400                         if ((equtyp == EQUREG) && (sy->sattre & UNDEF_EQUR))
401                         {
402 //REALLY?                               sy->sattre |= ~UNDEF_EQUR;
403                                 sy->sattre &= ~UNDEF_EQUR;
404                                 sy->svalue = 0;
405                         }
406                         else if ((equtyp == CCDEF) && (sy->sattre & UNDEF_CC))
407                         {
408 //REALLY?                               sy->sattre |= ~UNDEF_CC;
409                                 sy->sattre &= ~UNDEF_CC;
410                                 sy->svalue = 0;
411                         }
412                         else
413                         {
414                                 error("multiple equate to '%s'", sy->sname);
415                                 goto loop;
416                         }
417                 }
418
419                 // Put symbol in "order of definition" list if it's not already there
420                 AddToSymbolDeclarationList(sy);
421
422                 // Parse value to equate symbol to;
423                 // o  .equr
424                 // o  .reg
425                 // o  everything else
426                 if (equtyp == EQUREG)
427                 {
428 //Linko's request to issue a warning on labels that equated to the same
429 //register would go here. Not sure how to implement it though. :-/
430 /*
431 Maybe like this way:
432 have an array of bools with 64 entries. Whenever a register is equated, set the
433 corresponding register bool to true. Whenever it's undef'ed, set it to false.
434 When checking to see if it's already been equated, issue a warning.
435 */
436                         // Check that we are in a RISC section
437                         if (!rgpu && !rdsp)
438                         {
439                                 error(".equr/.regequ must be defined in .gpu/.dsp section");
440                                 goto loop;
441                         }
442
443                         // Check for register to equate to
444                         if ((*tok >= KW_R0) && (*tok <= KW_R31))
445                         {
446 //                              sy->sattre  = EQUATEDREG | RISCSYM;     // Mark as equated register
447                                 sy->sattre  = EQUATEDREG;       // Mark as equated register
448                                 riscreg = (*tok - KW_R0);
449 //is there any reason to do this, since we're putting this in svalue?
450 //i'm thinking, no. Let's test that out! :-D
451 //                              sy->sattre |= (riscreg << 8);           // Store register number
452 //everything seems to build fine without it... We'll leave it here Just In Case(tm)
453
454 #define DEBODGE_REGBANK
455 #ifdef DEBODGE_REGBANK
456                                 // Default is current state of "regbank"
457                                 registerbank = regbank;
458 #else
459                                 // Default is no register bank specified
460                                 registerbank = BANK_N;
461 #endif
462
463                                 // Check for ",<bank #>" override notation
464                                 if ((tok[1] == ',') && (tok[2] == CONST))
465                                 {
466                                         // Advance token pointer to the constant
467                                         tok += 3;
468
469                                         // Anything other than a 0 or a 1 will result in "No Bank"
470                                         if (*tok == 0)
471                                                 registerbank = BANK_0;
472                                         else if (*tok == 1)
473                                                 registerbank = BANK_1;
474                                 }
475
476 #ifdef DEBODGE_REGBANK
477                                 sy->sattre |= registerbank;     // Store register bank
478 #else
479 // What needs to happen here is to prime registerbank with regbank, then use
480 // registerbank down below for the bank marking.
481 #warning "!!! regbank <-> registerbank confusion here !!!"
482 // The question here is why, if we're allowed to override the ".regbankN" rules
483 // above, then why is it using the one set by the directive in the extended
484 // attributes and not in what ends up in symbol->svalue?
485 // ".regbankN" is not an original Madmac directive, so it's suspect
486                                 sy->sattre |= regbank;          // Store register bank
487 #endif
488                                 eattr = ABS | DEFINED | GLOBAL;
489 // & what does this $80000080 constant mean???
490 //                              eval = 0x80000080 + (riscreg) + (registerbank << 8);
491                                 eval = riscreg;
492                                 tok++;
493                         }
494                         // Checking for a register symbol
495                         else if (tok[0] == SYMBOL)
496                         {
497                                 sy2 = lookup(string[tok[1]], LABEL, j);
498
499                                 // Make sure symbol is a valid equreg
500                                 if (!sy2 || !(sy2->sattre & EQUATEDREG))
501                                 {
502                                         error("invalid GPU/DSP .equr/.regequ definition");
503                                         goto loop;
504                                 }
505                                 else
506                                 {
507                                         eattr = ABS | DEFINED | GLOBAL; // Copy symbols attributes
508                                         sy->sattre = sy2->sattre;
509                                         eval = (sy2->svalue & 0xFFFFF0FF);
510                                         tok += 2;
511                                 }
512                         }
513                         else
514                         {
515                                 error("invalid GPU/DSP .equr/.regequ definition");
516                                 goto loop;
517                         }
518                 }
519                 else if (equtyp == REG)
520                 {
521                         if (reglist(&rmask) < 0)
522                                 goto loop;
523
524                         eval = (VALUE)rmask;
525                         eattr = ABS | DEFINED;
526                 }
527                 else if (equtyp == CCDEF)
528                 {
529                         sy->sattre |= EQUATEDCC;
530                         eattr = ABS | DEFINED | GLOBAL;
531
532                         if (tok[0] == SYMBOL)
533                         {
534                                 sy2 = lookup(string[tok[1]], LABEL, j);
535
536                                 if (!sy2 || !(sy2->sattre & EQUATEDCC))
537                                 {
538                                         error("invalid gpu/dsp .ccdef definition");
539                                         goto loop;
540                                 }
541                                 else
542                                 {
543                                         eattr = ABS | DEFINED | GLOBAL;
544                                         sy->sattre = sy2->sattre;
545                                         eval = sy2->svalue;
546                                         tok += 2;
547                                 }
548                         }
549                         else if (expr(exprbuf, &eval, &eattr, &esym) != OK)
550                                 goto loop;
551                 }
552                 //equ a equr
553                 else if (*tok == SYMBOL)
554                 {
555                         sy2 = lookup(string[tok[1]], LABEL, j);
556
557                         if (sy2 && (sy2->sattre & EQUATEDREG))
558                         {
559                                 sy->stype = sy2->stype;
560                                 sy->sattr = sy2->sattr;
561                                 sy->sattre = sy2->sattre;
562 //ICK                           sy->svalue = (sy2->svalue & 0xFFFFF0FF);
563                                 sy->svalue = sy2->svalue;
564                                 goto loop;
565                         }
566                         else if (expr(exprbuf, &eval, &eattr, &esym) != OK)
567                                 goto loop;
568                 }
569                 else if (expr(exprbuf, &eval, &eattr, &esym) != OK)
570                         goto loop;
571
572                 if (!(eattr & DEFINED))
573                 {
574                         error(undef_error);
575                         goto loop;
576                 }
577
578                 sy->sattr |= eattr | EQUATED;   // Symbol inherits value and attributes
579                 sy->svalue = eval;
580
581                 if (list_flag)                                  // Put value in listing
582                         listvalue(eval);
583
584                 at_eol();                                               // Must be at EOL now
585                 goto loop;
586         }
587
588         // Do labels
589         if (label != NULL)
590         {
591                 // Non-zero == error occurred
592                 if (HandleLabel(label, labtyp) != 0)
593                         goto loop;
594         }
595
596         // Punt on EOL
597         if (state == -3)
598                 goto loop;
599
600         // If we're in 6502 mode and are still in need of a mnemonic, then search
601         // for valid 6502 mnemonic.
602         if (m6502 && (state < 0 || state >= 1000))
603         {
604 #ifdef ST
605                 state = kmatch(opname, mpbase, mpcheck, mptab, mpaccept);
606 #else
607                 for(state=0, p=opname; state>= 0; )
608                 {
609                         j = mpbase[state] + tolowertab[*p];
610
611                         if (mpcheck[j] != state)        // Reject, character doesn't match
612                         {
613                                 state = -1;             // No match
614                                 break;
615                         }
616
617                         if (!*++p)
618                         {                       // Must accept or reject at EOS
619                                 state = mpaccept[j];    // (-1 on no terminal match)
620                                 break;
621                         }
622
623                         state = mptab[j];
624                 }
625 #endif
626
627                 // Call 6502 code generator if we found a mnemonic
628                 if (state >= 2000)
629                 {
630                         m6502cg(state - 2000);
631                         goto loop;
632                 }
633         }
634
635         // If we are in GPU or DSP mode and still in need of a mnemonic then search
636         // for one
637         if ((rgpu || rdsp) && (state < 0 || state >= 1000))
638         {
639                 for(state=0, p=opname; state>=0;)
640                 {
641                         j = mrbase[state] + (int)tolowertab[*p];
642
643                         // Reject, character doesn't match
644                         if (mrcheck[j] != state)
645                         {
646                                 state = -1;                                     // No match
647                                 break;
648                         }
649
650                         // Must accept or reject at EOS
651                         if (!*++p)
652                         {
653                                 state = mraccept[j];            // (-1 on no terminal match)
654                                 break;
655                         }
656
657                         state = mrtab[j];
658                 }
659
660                 // Call RISC code generator if we found a mnemonic
661                 if (state >= 3000)
662                 {
663                         GenerateRISCCode(state);
664                         goto loop;
665                 }
666         }
667
668         // Invoke macro or complain about bad mnemonic
669         if (state < 0)
670         {
671                 if ((sy = lookup(opname, MACRO, 0)) != NULL)
672                         InvokeMacro(sy, siz);
673                 else
674                         error("unknown op '%s'", opname);
675
676                 goto loop;
677         }
678
679         // Call directive handlers
680         if (state < 500)
681         {
682                 (*dirtab[state])(siz);
683                 goto loop;
684         }
685
686         // Do mnemonics
687         //  o  can't deposit instrs in BSS or ABS
688         //  o  do automatic .EVEN for instrs
689         //  o  allocate space for largest possible instr
690         //  o  can't do ".b" operations with an address register
691         if (scattr & SBSS)
692         {
693                 error("cannot initialize non-storage (BSS) section");
694                 goto loop;
695         }
696
697         if (sloc & 1)                                   // Automatic .even
698                 auto_even();
699
700         if (challoc - ch_size < 18)             // Make sure have space in current chunk
701                 chcheck(0);
702
703         m = &machtab[state - 1000];
704
705         // Call special-mode handler
706         if (m->mnattr & CGSPECIAL)
707         {
708                 (*m->mnfunc)(m->mninst, siz);
709                 goto loop;
710         }
711
712         if (amode(1) < 0)                               // Parse 0, 1 or 2 addr modes
713                 goto loop;
714
715         if (*tok != EOL)
716                 error(extra_stuff);
717
718         amsk0 = amsktab[am0];
719         amsk1 = amsktab[am1];
720
721         // Catch attempts to use ".B" with an address register (yes, this check
722         // does work at this level)
723         if (siz == SIZB && (am0 == AREG || am1 == AREG))
724         {
725                 error("cannot use '.b' with an address register");
726                 goto loop;
727         }
728
729         // Keep a backup of chptr (used for optimisations during codegen)
730         chptr_opcode = chptr;
731
732         for(;;)
733         {
734                 if ((m->mnattr & siz) && (amsk0 & m->mn0) != 0 && (amsk1 & m->mn1) != 0)
735                 {
736                         (*m->mnfunc)(m->mninst, siz);
737                         goto loop;
738                 }
739
740                 m = &machtab[m->mncont];
741         }
742 }
743
744
745 //
746 // Handle the creation of labels
747 //
748 int HandleLabel(char * label, int labelType)
749 {
750         // Check for dot in front of label; means this is a local label if present
751         int environment = (*label == '.' ? curenv : 0);
752         SYM * symbol = lookup(label, LABEL, environment);
753
754         if (symbol == NULL)
755         {
756                 symbol = NewSymbol(label, LABEL, environment);
757                 symbol->sattr = 0;
758 //              symbol->sattre = RISCSYM;
759                 symbol->sattre = 0;
760         }
761         else if (symbol->sattr & DEFINED)
762                 return error("multiply-defined label '%s'", label);
763
764         // Put symbol in "order of definition" list if it's not already in it
765         AddToSymbolDeclarationList(symbol);
766
767         if (orgactive)
768         {
769                 symbol->svalue = orgaddr;
770                 symbol->sattr |= ABS | DEFINED | EQUATED;
771         }
772         else
773         {
774                 symbol->svalue = sloc;
775                 symbol->sattr |= DEFINED | cursect;
776         }
777
778         lab_sym = symbol;
779
780         // Yes, our CS professors told us to write checks for equality this way,
781         // but damn, it hurts my brain every time I look at it. :-/
782         if (0 == environment)
783                 curenv++;
784
785         // Make label global if it has a double colon
786         if (labelType == DCOLON)
787         {
788                 if (environment != 0)
789                         return error(locgl_error);
790
791                 symbol->sattr |= GLOBAL;
792         }
793
794         return 0;
795 }
796
797