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