Various code cleanups, mainly to do with RISC assembly.
[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 char extra_stuff[] = "extra (unexpected) text found after addressing mode";
43 char * comma_error = "missing comma";
44 char * syntax_error = "syntax error";
45 char * locgl_error = "cannot GLOBL local symbol";
46 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 init_procln(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
131         listflag = 0;                           // Initialise listing flag
132
133 loop:                                                   // Line processing loop label
134
135         // Get another line of tokens
136         if (tokln() == TKEOF)
137         {
138 if (verb_flag) printf("Assemble: Found TKEOF flag...\n");
139                 if (list_flag && listflag)                      // Flush last line of source
140                         listeol();
141
142                 if (ifent->if_prev != NULL)                     // Check conditional token
143                         error("hit EOF without finding matching .endif");
144
145                 return;
146         }
147
148         DEBUG DumpTokenBuffer();
149
150         if (list_flag)
151         {
152                 if (listflag && listing > 0)
153                         listeol();                                              // Tell listing generator about EOL
154
155                 lstout((char)(disabled ? '-' : lntag)); // Prepare new line for listing
156                 listflag = 1;                                           // OK to call `listeol' now
157                 just_bss = 0;                                           // Reset just_bss mode
158         }
159
160         state = -3;                                                             // No keyword (just EOL)
161         label = NULL;                                                   // No label
162         lab_sym = NULL;                                                 // No (exported) label
163         equate = NULL;                                                  // No equate
164         tk = tok;                                                               // Save first token in line
165         pcloc = (VALUE)sloc;                                    // Set beginning-of-line PC
166
167 loop1:                                                                          // Internal line processing loop
168
169         if (*tok == EOL)                                                // Restart loop if end-of-line
170                 goto loop;
171
172         // First token MUST be a symbol
173         if (*tok != SYMBOL)
174         {
175                 error(syntax_error);
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         if (*tok == EOL)                                                // EOL is legal here...
213                 goto normal;
214
215         // Next token MUST be a symbol
216         if (*tok++ != SYMBOL)
217         {
218                 error(syntax_error);
219                 goto loop;
220         }
221
222 // This is the problem here: On 64-bit platforms, this cuts the native pointer
223 // in half. We need to figure out how to fix this.
224 //#warning "!!! Bad pointer !!!"
225 #if 0
226         opname = p = (char *)*tok++;                    // Store opcode name here
227 #else
228         opname = p = string[*tok++];
229 #endif
230
231         // Check to see if the SYMBOL is a keyword (a mnemonic or directive).
232         // On output, `state' will have one of the values:
233         //    -3          there was no symbol (EOL)
234         //    -2..-1      the symbol didn't match any keyword
235         //    0..499      vanilla directives (dc, ds, etc.)
236         //    500..999    electric directives (macro, rept, etc.)
237         //    1000..+     mnemonics (move, lsr, etc.)
238         for(state=0; state>=0;)
239         {
240                 j = mnbase[state] + (int)tolowertab[*p];
241
242                 // Reject, character doesn't match
243                 if (mncheck[j] != state)
244                 {
245                         state = -1;                                             // No match
246                         break;
247                 }
248
249                 // Must accept or reject at EOS
250                 if (!*++p)
251                 {
252                         state = mnaccept[j];                    // (-1 on no terminal match)
253                         break;
254                 }
255
256                 state = mntab[j];
257         }
258
259         // Check for ".b" ".w" ".l" after directive, macro or mnemonic.
260         siz = SIZN;
261
262         if (*tok == DOTW) 
263                 siz = SIZW, ++tok;
264         else if (*tok == DOTL)
265                 siz = SIZL, ++tok;
266         else if (*tok == DOTB)
267                 siz = SIZB, ++tok;
268
269         // Do special directives (500..999) (These must be handled in "real time")
270         if (state >= 500 && state < 1000)
271         {
272                 switch (state)
273                 {
274                 case MN_IF:
275                         d_if ();
276                 goto loop;
277                 case MN_ELSE:
278                         d_else();
279                         goto loop;
280                 case MN_ENDIF:
281                         d_endif ();
282                         goto loop;
283                 case MN_IIF:                                            // .iif --- immediate if
284                         if (disabled || expr(exprbuf, &eval, &eattr, &esym) != OK)
285                                 goto loop;
286
287                         if (!(eattr & DEFINED))
288                         {
289                                 error(undef_error);
290                                 goto loop;
291                         }
292
293                         if (*tok++ != ',')
294                         {
295                                 error(comma_error);
296                                 goto loop;
297                         }
298
299                         if (eval == 0)
300                                 goto loop;
301
302                         goto loop1;
303                 case MN_MACRO:                                          // .macro --- macro definition
304                         if (!disabled)
305                         {
306                                 if (label != NULL)
307                                         warn(lab_ignored);
308
309                                 DefineMacro();
310                         }
311
312                         goto loop;
313                 case MN_EXITM:                                          // .exitm --- exit macro
314                 case MN_ENDM:                                           // .endm --- same as .exitm
315                         if (!disabled)
316                         {
317                                 if (label != NULL)
318                                         warn(lab_ignored);
319
320                                 ExitMacro();
321                         }
322
323                         goto loop;
324                 case MN_REPT:
325                         if (!disabled)
326                         {
327                                 if (label != NULL)
328                                         warn(lab_ignored);
329
330                                 defrept();
331                         }
332
333                         goto loop;
334                 case MN_ENDR:
335                         if (!disabled)
336                                 error("mis-nested .endr");
337
338                         goto loop;
339                 }
340         }
341
342 normal:
343         if (disabled)                                                   // Conditionally disabled code
344                 goto loop;
345
346         // Do equates
347         if (equate != NULL)
348         {
349                 // Pick global or local symbol enviroment
350 #if 0
351                 j = 0;
352
353                 if (*equate == '.')
354                         j = curenv;
355 #else
356                 j = (*equate == '.' ? curenv : 0);
357 #endif
358                 sy = lookup(equate, LABEL, j);
359
360                 if (sy == NULL)
361                 {
362                         sy = NewSymbol(equate, LABEL, j);
363                         sy->sattr = 0;
364
365                         if (equtyp == DEQUALS)
366                         {
367                                 // Can't GLOBAL a local symbol
368                                 if (j)
369                                 {
370                                         error(locgl_error);
371                                         goto loop;
372                                 }
373
374                                 sy->sattr = GLOBAL;
375                         }
376                 }
377                 else if ((sy->sattr & DEFINED) && equtyp != SET)
378                 {
379                         if ((equtyp == EQUREG) && (sy->sattre & UNDEF_EQUR))
380                         {
381 //REALLY?                               sy->sattre |= ~UNDEF_EQUR; 
382                                 sy->sattre &= ~UNDEF_EQUR; 
383                                 sy->svalue  = 0;
384                         }
385                         else if ((equtyp == CCDEF) && (sy->sattre & UNDEF_CC))
386                         {
387 //REALLY?                               sy->sattre |= ~UNDEF_CC;
388                                 sy->sattre &= ~UNDEF_CC;
389                                 sy->svalue = 0;
390                         }
391                         else
392                         {
393                                 errors("multiple equate to '%s'", sy->sname);
394                                 goto loop;
395                         }
396                 }
397
398                 // Put symbol in "order of definition" list
399                 if (!(sy->sattr & SDECLLIST))
400                         sym_decl(sy);
401
402                 // Parse value to equate symbol to;
403                 // o  .equr
404                 // o  .reg
405                 // o  everything else
406                 if (equtyp == EQUREG)
407                 {
408 //Linko's request to issue a warning on labels that equated to the same register
409 //would go here. Not sure how to implement it though. :-/
410 /*
411 Maybe like this way:
412 have an array of bools with 64 entries. Whenever a register is equated, set the
413 corresponding register bool to true. Whenever it's undef'ed, set it to false. When
414 checking to see if it's already been equated, issue a warning.
415 */
416                         // Check that we are in a RISC section
417                         if (!rgpu && !rdsp)
418                         {
419                                 error(".equr/.regequ must be defined in .gpu/.dsp section");
420                                 goto loop;
421                         }
422
423                         // Check for register to equate to
424                         if ((*tok >= KW_R0) && (*tok <= KW_R31))
425                         {
426                                 sy->sattre  = EQUATEDREG | RISCSYM;     // Mark as equated register
427                                 riscreg = (*tok - KW_R0);
428 //is there any reason to do this, since we're putting this in svalue?
429                                 sy->sattre |= (riscreg << 8);           // Store register number
430
431                                 // Default is no register bank specified
432                                 registerbank = BANK_N;
433
434                                 // Check for ",<bank #>" 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 // What needs to happen here is to prime registerbank with regbank, then use
448 // registerbank down below for the bank marking.
449 #warning "!!! regbank <-> registerbank confusion here !!!"
450 // The question here is why, if we're allowed to override the ".regbankN" rules above,
451 // then why is it using the one set by the directive in the extended attributes and
452 // not in what ends up in symbol->svalue?
453 // ".regbankN" is not an original Madmac directive, so it's suspect
454                                 sy->sattre |= regbank;          // Store register bank
455                                 eattr = ABS | DEFINED | GLOBAL;
456 // & what does this $80000080 constant mean???
457 //                              eval = 0x80000080 + (riscreg) + (registerbank << 8);
458                                 eval = riscreg;
459                                 tok++;
460                         }
461                         // Checking for a register symbol
462                         else if (tok[0] == SYMBOL)
463                         {
464                                 sy2 = lookup(string[tok[1]], LABEL, j);
465
466                                 // Make sure symbol is a valid equreg
467                                 if (!sy2 || !(sy2->sattre & EQUATEDREG))
468                                 {
469                                         error("invalid GPU/DSP .equr/.regequ definition");
470                                         goto loop;
471                                 }
472                                 else
473                                 {
474                                         eattr = ABS | DEFINED | GLOBAL; // Copy symbols attributes
475                                         sy->sattre = sy2->sattre;
476                                         eval = (sy2->svalue & 0xFFFFF0FF);
477                                         tok += 2;
478                                 }
479                         }
480                         else
481                         {
482                                 error("invalid GPU/DSP .equr/.regequ definition");
483                                 goto loop;
484                         }
485                 }
486                 else if (equtyp == REG)
487                 {
488                         if (reglist(&rmask) < 0)
489                                 goto loop;
490
491                         eval = (VALUE)rmask;
492                         eattr = ABS | DEFINED;
493                 }
494                 else if (equtyp == CCDEF)
495                 {
496                         sy->sattre |= EQUATEDCC;
497                         eattr = ABS | DEFINED | GLOBAL;
498
499                         if (tok[0] == SYMBOL)
500                         {
501                                 sy2 = lookup(string[tok[1]], LABEL, j);
502
503                                 if (!sy2 || !(sy2->sattre & EQUATEDCC))
504                                 {
505                                         error("invalid gpu/dsp .ccdef definition");
506                                         goto loop;
507                                 }
508                                 else
509                                 {
510                                         eattr = ABS | DEFINED | GLOBAL;
511                                         sy->sattre = sy2->sattre;
512                                         eval = sy2->svalue;
513                                         tok += 2;
514                                 }
515                         }
516                         else if (expr(exprbuf, &eval, &eattr, &esym) != OK)
517                                 goto loop;
518                 }
519                 //equ a equr
520                 else if (*tok == SYMBOL)
521                 {
522                         sy2 = lookup(string[tok[1]], LABEL, j);
523
524                         if (sy2 && (sy2->sattre & EQUATEDREG))
525                         {
526                                 sy->stype = sy2->stype;
527                                 sy->sattr = sy2->sattr;
528                                 sy->sattre = sy2->sattre;
529                                 sy->svalue = (sy2->svalue & 0xFFFFF0FF);
530                                 goto loop;
531                         }
532                         else if (expr(exprbuf, &eval, &eattr, &esym) != OK)
533                                 goto loop;
534                 }
535                 else if (expr(exprbuf, &eval, &eattr, &esym) != OK)
536                         goto loop;
537
538                 if (!(eattr & DEFINED))
539                 {
540                         error(undef_error);
541                         goto loop;
542                 }
543
544                 sy->sattr |= eattr | EQUATED;           // Symbol inherits value and attributes
545                 sy->svalue = eval;
546
547                 if (list_flag)                                          // Put value in listing
548                         listvalue(eval);
549
550                 at_eol();                                                       // Must be at EOL now
551                 goto loop;
552         }
553
554         // Do labels
555         if (label != NULL)
556         {
557 do_label:
558                 // Check for dot in front of label; means this is a local label if present
559 #if 0
560                 j = 0;
561
562                 if (*label == '.')
563                         j = curenv;
564 #else
565                 j = (*label == '.' ? curenv : 0);
566 #endif
567
568                 sy = lookup(label, LABEL, j);
569
570                 if (sy == NULL)
571                 {
572                         sy = NewSymbol(label, LABEL, j);
573                         sy->sattr = 0;
574                         sy->sattre = RISCSYM;
575                 }
576                 else if (sy->sattr & DEFINED)
577                 {
578                         errors("multiply-defined label '%s'", label);
579                         goto loop;
580                 }
581
582                 // Put symbol in "order of definition" list
583                 if (!(sy->sattr & SDECLLIST))
584                         sym_decl(sy);
585
586                 if (orgactive)
587                 {
588                         sy->svalue = orgaddr;
589                         sy->sattr |= ABS | DEFINED | EQUATED;
590                 }
591                 else
592                 {
593                         sy->svalue = sloc;
594                         sy->sattr |= DEFINED | cursect;
595                 }
596
597                 lab_sym = sy;
598
599                 if (!j)
600                         curenv++;
601
602                 // Make label global
603                 if (labtyp == DCOLON)
604                 {
605                         if (j)
606                         {
607                                 error(locgl_error);
608                                 goto loop;
609                         }
610
611                         sy->sattr |= GLOBAL;
612                 }
613
614                 // If we're in as68 mode, and there's another label, go back and handle it
615                 if (as68_flag && as68mode)
616                         goto as68label;
617         }
618
619         // Punt on EOL
620         if (state == -3)
621                 goto loop;
622
623         // If we are in GPU or DSP mode and still in need of a mnemonic then search
624         // for one
625         if ((rgpu || rdsp) && (state < 0 || state >= 1000))
626         {
627                 for(state=0, p=opname; state>=0;)
628                 {
629                         j = mrbase[state] + (int)tolowertab[*p];
630
631                         // Reject, character doesn't match
632                         if (mrcheck[j] != state)
633                         {
634                                 state = -1;                                     // No match
635                                 break;
636                         }
637
638                         // Must accept or reject at EOS
639                         if (!*++p)
640                         {
641                                 state = mraccept[j];            // (-1 on no terminal match)
642                                 break;
643                         }
644
645                         state = mrtab[j];
646                 }
647
648                 // Call RISC code generator if we found a mnemonic
649                 if (state >= 3000)
650                 {
651                         GenerateRISCCode(state);
652                         goto loop;
653                 }
654         }
655
656         // Invoke macro or complain about bad mnemonic
657         if (state < 0)
658         {
659                 if ((sy = lookup(opname, MACRO, 0)) != NULL) 
660                         InvokeMacro(sy, siz);
661                 else
662                         errors("unknown op '%s'", opname);
663
664                 goto loop;
665         }
666
667         // Call directive handlers
668         if (state < 500)
669         {
670                 (*dirtab[state])(siz);
671                 goto loop;
672         }
673
674         // Do mnemonics
675         // o  can't deposit instrs in BSS or ABS
676         // o  do automatic .EVEN for instrs
677         // o  allocate space for largest possible instr
678         // o  can't do ".b" operations with an address register
679         if (scattr & SBSS)
680         {
681                 error("cannot initialize non-storage (BSS) section");
682                 goto loop;
683         }
684
685         if (sloc & 1)                                                   // Automatic .even
686                 auto_even();
687
688         if (challoc - ch_size < 18)                             // Make sure have space in current chunk
689                 chcheck(0);
690
691         m = &machtab[state - 1000];
692
693         // Call special-mode handler
694         if (m->mnattr & CGSPECIAL)
695         {
696                 (*m->mnfunc)(m->mninst, siz);
697                 goto loop;
698         }
699
700         if (amode(1) < 0)                                               // Parse 0, 1 or 2 addr modes
701                 goto loop;
702
703         if (*tok != EOL)
704                 error(extra_stuff);
705
706         amsk0 = amsktab[am0];
707         amsk1 = amsktab[am1];
708
709         // Catch attempts to use ".B" with an address register (yes, this check
710         // does work at this level)
711         if (siz == SIZB && (am0 == AREG || am1 == AREG))
712         {
713                 error("cannot use '.b' with an address register");
714                 goto loop;
715         }
716
717         for(;;)
718         {
719                 if ((m->mnattr & siz) && (amsk0 & m->mn0) != 0 && (amsk1 & m->mn1) != 0)
720                 {
721                         (*m->mnfunc)(m->mninst, siz);
722                         goto loop;
723                 }
724
725                 m = &machtab[m->mncont];
726         }
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 }