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