]> git.sur5r.net Git - cc65/blob - src/cc65/codeseg.c
Several bug fixes
[cc65] / src / cc65 / codeseg.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 codeseg.c                                 */
4 /*                                                                           */
5 /*                          Code segment structure                           */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include <string.h>
37 #include <ctype.h>
38
39 /* common */
40 #include "chartype.h"
41 #include "check.h"
42 #include "hashstr.h"
43 #include "strutil.h"
44 #include "xmalloc.h"
45 #include "xsprintf.h"
46
47 /* cc65 */
48 #include "asmlabel.h"
49 #include "codeent.h"
50 #include "codeinfo.h"
51 #include "error.h"
52 #include "codeseg.h"
53
54
55
56 /*****************************************************************************/
57 /*                             Helper functions                              */
58 /*****************************************************************************/
59
60
61
62 static void MoveLabelsToPool (CodeSeg* S, CodeEntry* E)
63 /* Move the labels of the code entry E to the label pool of the code segment */
64 {
65     unsigned LabelCount = GetCodeLabelCount (E);
66     while (LabelCount--) {
67         CodeLabel* L = GetCodeLabel (E, LabelCount);
68         L->Flags &= ~LF_DEF;
69         L->Owner = 0;
70         CollAppend (&S->Labels, L);
71     }
72     CollDeleteAll (&E->Labels);
73 }
74
75
76
77 static CodeLabel* FindCodeLabel (CodeSeg* S, const char* Name, unsigned Hash)
78 /* Find the label with the given name. Return the label or NULL if not found */
79 {
80     /* Get the first hash chain entry */
81     CodeLabel* L = S->LabelHash[Hash];
82
83     /* Search the list */
84     while (L) {
85         if (strcmp (Name, L->Name) == 0) {
86             /* Found */
87             break;
88         }
89         L = L->Next;
90     }
91     return L;
92 }
93
94
95
96 static CodeLabel* NewCodeSegLabel (CodeSeg* S, const char* Name, unsigned Hash)
97 /* Create a new label and insert it into the label hash table */
98 {
99     /* Not found - create a new one */
100     CodeLabel* L = NewCodeLabel (Name, Hash);
101
102     /* Enter the label into the hash table */
103     L->Next = S->LabelHash[L->Hash];
104     S->LabelHash[L->Hash] = L;
105
106     /* Return the new label */
107     return L;
108 }
109
110
111
112 static void RemoveLabelFromHash (CodeSeg* S, CodeLabel* L)
113 /* Remove the given code label from the hash list */
114 {
115     /* Get the first entry in the hash chain */
116     CodeLabel* List = S->LabelHash[L->Hash];
117     CHECK (List != 0);
118
119     /* First, remove the label from the hash chain */
120     if (List == L) {
121         /* First entry in hash chain */
122         S->LabelHash[L->Hash] = L->Next;
123     } else {
124         /* Must search through the chain */
125         while (List->Next != L) {
126             /* If we've reached the end of the chain, something is *really* wrong */
127             CHECK (List->Next != 0);
128             /* Next entry */
129             List = List->Next;
130         }
131         /* The next entry is the one, we have been searching for */
132         List->Next = L->Next;
133     }
134 }
135
136
137
138 /*****************************************************************************/
139 /*                    Functions for parsing instructions                     */
140 /*****************************************************************************/
141
142
143
144 static const char* SkipSpace (const char* S)
145 /* Skip white space and return an updated pointer */
146 {
147     while (IsSpace (*S)) {
148         ++S;
149     }
150     return S;
151 }
152
153
154
155 static const char* ReadToken (const char* L, const char* Term,
156                               char* Buf, unsigned BufSize)
157 /* Read the next token into Buf, return the updated line pointer. The
158  * token is terminated by one of the characters given in term.
159  */
160 {
161     /* Read/copy the token */
162     unsigned I = 0;
163     unsigned ParenCount = 0;
164     while (*L && (ParenCount > 0 || strchr (Term, *L) == 0)) {
165         if (I < BufSize-1) {
166             Buf[I++] = *L;
167         }
168         if (*L == ')') {
169             --ParenCount;
170         } else if (*L == '(') {
171             ++ParenCount;
172         }
173         ++L;
174     }
175
176     /* Terminate the buffer contents */
177     Buf[I] = '\0';
178
179     /* Return the updated line pointer */
180     return L;
181 }
182
183
184
185 static CodeEntry* ParseInsn (CodeSeg* S, const char* L)
186 /* Parse an instruction nnd generate a code entry from it. If the line contains
187  * errors, output an error message and return NULL.
188  * For simplicity, we don't accept the broad range of input a "real" assembler
189  * does. The instruction and the argument are expected to be separated by
190  * white space, for example.
191  */
192 {
193     char                Mnemo[16];
194     const OPCDesc*      OPC;
195     am_t                AM = 0;         /* Initialize to keep gcc silent */
196     char                Arg[64];
197     char                Reg;
198     CodeEntry*          E;
199     CodeLabel*          Label;
200
201     /* Mnemonic */
202     L = ReadToken (L, " \t", Mnemo, sizeof (Mnemo));
203
204     /* Try to find the opcode description for the mnemonic */
205     OPC = FindOpcode (Mnemo);
206
207     /* If we didn't find the opcode, print an error and bail out */
208     if (OPC == 0) {
209         Error ("ASM code error: %s is not a valid mnemonic", Mnemo);
210         return 0;
211     }
212
213     /* Skip separator white space */
214     L = SkipSpace (L);
215
216     /* Get the addressing mode */
217     Arg[0] = '\0';
218     switch (*L) {
219
220         case '\0':
221             /* Implicit */
222             AM = AM_IMP;
223             break;
224
225         case '#':
226             /* Immidiate */
227             StrCopy (Arg, sizeof (Arg), L+1);
228             AM = AM_IMM;
229             break;
230
231         case '(':
232             /* Indirect */
233             L = ReadToken (L+1, ",)", Arg, sizeof (Arg));
234
235             /* Check for errors */
236             if (*L == '\0') {
237                 Error ("ASM code error: syntax error");
238                 return 0;
239             }
240
241             /* Check the different indirect modes */
242             if (*L == ',') {
243                 /* Expect zp x indirect */
244                 L = SkipSpace (L+1);
245                 if (toupper (*L) != 'X') {
246                     Error ("ASM code error: `X' expected");
247                     return 0;
248                 }
249                 L = SkipSpace (L+1);
250                 if (*L != ')') {
251                     Error ("ASM code error: `)' expected");
252                     return 0;
253                 }
254                 L = SkipSpace (L+1);
255                 if (*L != '\0') {
256                     Error ("ASM code error: syntax error");
257                     return 0;
258                 }
259                 AM = AM_ZPX_IND;
260             } else if (*L == ')') {
261                 /* zp indirect or zp indirect, y */
262                 L = SkipSpace (L+1);
263                 if (*L == ',') {
264                     L = SkipSpace (L+1);
265                     if (toupper (*L) != 'Y') {
266                         Error ("ASM code error: `Y' expected");
267                         return 0;
268                     }
269                     L = SkipSpace (L+1);
270                     if (*L != '\0') {
271                         Error ("ASM code error: syntax error");
272                         return 0;
273                     }
274                     AM = AM_ZP_INDY;
275                 } else if (*L == '\0') {
276                     AM = AM_ZP_IND;
277                 } else {
278                     Error ("ASM code error: syntax error");
279                     return 0;
280                 }
281             }
282             break;
283
284         case 'a':
285         case 'A':
286             /* Accumulator? */
287             if (L[1] == '\0') {
288                 AM = AM_ACC;
289                 break;
290             }
291             /* FALLTHROUGH */
292
293         default:
294             /* Absolute, maybe indexed */
295             L = ReadToken (L, ",", Arg, sizeof (Arg));
296             if (*L == '\0') {
297                 /* Assume absolute */
298                 AM = AM_ABS;
299             } else if (*L == ',') {
300                 /* Indexed */
301                 L = SkipSpace (L+1);
302                 if (*L == '\0') {
303                     Error ("ASM code error: syntax error");
304                     return 0;
305                 } else {
306                     Reg = toupper (*L);
307                     L = SkipSpace (L+1);
308                     if (Reg == 'X') {
309                         AM = AM_ABSX;
310                     } else if (Reg == 'Y') {
311                         AM = AM_ABSY;
312                     } else {
313                         Error ("ASM code error: syntax error");
314                         return 0;
315                     }
316                     if (*L != '\0') {
317                         Error ("ASM code error: syntax error");
318                         return 0;
319                     }
320                 }
321             }
322             break;
323
324     }
325
326     /* If the instruction is a branch, check for the label and generate it
327      * if it does not exist. Ignore anything but local labels here.
328      */
329     Label = 0;
330     if ((OPC->Info & OF_BRA) != 0 && Arg[0] == 'L') {
331
332         unsigned Hash;
333
334         /* Addressing mode must be alsobute or something is really wrong */
335         CHECK (AM == AM_ABS);
336
337         /* Addressing mode is a branch/jump */
338         AM = AM_BRA;
339
340         /* Generate the hash over the label, then search for the label */
341         Hash = HashStr (Arg) % CS_LABEL_HASH_SIZE;
342         Label = FindCodeLabel (S, Arg, Hash);
343
344         /* If we don't have the label, it's a forward ref - create it */
345         if (Label == 0) {
346             /* Generate a new label */
347             Label = NewCodeSegLabel (S, Arg, Hash);
348         }
349     }
350
351     /* We do now have the addressing mode in AM. Allocate a new CodeEntry
352      * structure and initialize it.
353      */
354     E = NewCodeEntry (OPC, AM, Arg, Label);
355
356     /* Return the new code entry */
357     return E;
358 }
359
360
361
362 /*****************************************************************************/
363 /*                                   Code                                    */
364 /*****************************************************************************/
365
366
367
368 CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func)
369 /* Create a new code segment, initialize and return it */
370 {
371     unsigned I;
372
373     /* Allocate memory */
374     CodeSeg* S = xmalloc (sizeof (CodeSeg));
375
376     /* Initialize the fields */
377     S->SegName  = xstrdup (SegName);
378     S->Func     = Func;
379     InitCollection (&S->Entries);
380     InitCollection (&S->Labels);
381     for (I = 0; I < sizeof(S->LabelHash) / sizeof(S->LabelHash[0]); ++I) {
382         S->LabelHash[I] = 0;
383     }
384
385     /* Return the new struct */
386     return S;
387 }
388
389
390
391 void AddCodeEntry (CodeSeg* S, const char* Format, va_list ap)
392 /* Add a line to the given code segment */
393 {
394     const char* L;
395     CodeEntry*  E;
396     char        Token[64];
397
398     /* Format the line */
399     char Buf [256];
400     xvsprintf (Buf, sizeof (Buf), Format, ap);
401
402     /* Skip whitespace */
403     L = SkipSpace (Buf);
404
405     /* Check which type of instruction we have */
406     E = 0;      /* Assume no insn created */
407     switch (*L) {
408
409         case '\0':
410             /* Empty line, just ignore it */
411             break;
412
413         case ';':
414             /* Comment or hint, ignore it for now */
415             break;
416
417         case '.':
418             /* Control instruction */
419             ReadToken (L, " \t", Token, sizeof (Token));
420             Error ("ASM code error: Pseudo instruction `%s' not supported", Token);
421             break;
422
423         default:
424             E = ParseInsn (S, L);
425             break;
426     }
427
428     /* If we have a code entry, transfer the labels and insert it */
429     if (E) {
430
431         /* Transfer the labels if we have any */
432         unsigned I;
433         unsigned LabelCount = CollCount (&S->Labels);
434         for (I = 0; I < LabelCount; ++I) {
435
436             /* Get the label */
437             CodeLabel* L = CollAt (&S->Labels, I);
438
439             /* Attach it to the entry */
440             AttachCodeLabel (E, L);
441         }
442
443         /* Delete the transfered labels */
444         CollDeleteAll (&S->Labels);
445
446         /* Add the entry to the list of code entries in this segment */
447         CollAppend (&S->Entries, E);
448
449     }
450 }
451
452
453
454 void DelCodeEntry (CodeSeg* S, unsigned Index)
455 /* Delete an entry from the code segment. This includes moving any associated
456  * labels, removing references to labels and even removing the referenced labels
457  * if the reference count drops to zero.
458  */
459 {
460     /* Get the code entry for the given index */
461     CodeEntry* E = GetCodeEntry (S, Index);
462
463     /* If the entry has a labels, we have to move this label to the next insn.
464      * If there is no next insn, move the label into the code segement label
465      * pool. The operation is further complicated by the fact that the next
466      * insn may already have a label. In that case change all reference to
467      * this label and delete the label instead of moving it.
468      */
469     unsigned Count = GetCodeLabelCount (E);
470     if (Count > 0) {
471
472         /* The instruction has labels attached. Check if there is a next
473          * instruction.
474          */
475         if (Index == GetCodeEntryCount (S)-1) {
476
477             /* No next instruction, move to the codeseg label pool */
478             MoveLabelsToPool (S, E);
479
480         } else {
481
482             /* There is a next insn, get it */
483             CodeEntry* N = GetCodeEntry (S, Index+1);
484
485             /* Move labels to the next entry */
486             MoveCodeLabels (S, E, N);
487
488         }
489     }
490
491     /* If this insn references a label, remove the reference. And, if the
492      * the reference count for this label drops to zero, remove this label.
493      */
494     if (E->JumpTo) {
495         /* Remove the reference */
496         RemoveCodeLabelRef (S, E);
497     }
498
499     /* Delete the pointer to the insn */
500     CollDelete (&S->Entries, Index);
501
502     /* Delete the instruction itself */
503     FreeCodeEntry (E);
504 }
505
506
507
508 struct CodeEntry* GetCodeEntry (CodeSeg* S, unsigned Index)
509 /* Get an entry from the given code segment */
510 {
511     return CollAt (&S->Entries, Index);
512 }
513
514
515
516 unsigned GetCodeEntryIndex (CodeSeg* S, struct CodeEntry* E)
517 /* Return the index of a code entry */
518 {
519     int Index = CollIndex (&S->Entries, E);
520     CHECK (Index >= 0);
521     return Index;
522 }
523
524
525
526 void AddCodeLabel (CodeSeg* S, const char* Name)
527 /* Add a code label for the next instruction to follow */
528 {
529     /* Calculate the hash from the name */
530     unsigned Hash = HashStr (Name) % CS_LABEL_HASH_SIZE;
531
532     /* Try to find the code label if it does already exist */
533     CodeLabel* L = FindCodeLabel (S, Name, Hash);
534
535     /* Did we find it? */
536     if (L) {
537         /* We found it - be sure it does not already have an owner */
538         CHECK (L->Owner == 0);
539     } else {
540         /* Not found - create a new one */
541         L = NewCodeSegLabel (S, Name, Hash);
542     }
543
544     /* Safety. This call is quite costly, but safety is better */
545     if (CollIndex (&S->Labels, L) >= 0) {
546         Internal ("AddCodeLabel: Label `%s' already defined", Name);
547     }
548
549     /* We do now have a valid label. Remember it for later */
550     CollAppend (&S->Labels, L);
551 }
552
553
554
555 CodeLabel* GenCodeLabel (CodeSeg* S, struct CodeEntry* E)
556 /* If the code entry E does already have a label, return it. Otherwise
557  * create a new label, attach it to E and return it.
558  */
559 {
560     CodeLabel* L;
561
562     if (CodeEntryHasLabel (E)) {
563
564         /* Get the label from this entry */
565         L = GetCodeLabel (E, 0);
566
567     } else {
568
569         /* Get a new name */
570         const char* Name = LocalLabelName (GetLocalLabel ());
571
572         /* Generate the hash over the name */
573         unsigned Hash = HashStr (Name) % CS_LABEL_HASH_SIZE;
574
575         /* Create a new label */
576         L = NewCodeSegLabel (S, Name, Hash);
577
578         /* Attach this label to the code entry */
579         AttachCodeLabel (E, L);
580
581     }
582
583     /* Return the label */
584     return L;
585 }
586
587
588
589 void DelCodeLabel (CodeSeg* S, CodeLabel* L)
590 /* Remove references from this label and delete it. */
591 {
592     unsigned Count, I;
593
594     /* First, remove the label from the hash chain */
595     RemoveLabelFromHash (S, L);
596
597     /* Remove references from insns jumping to this label */
598     Count = CollCount (&L->JumpFrom);
599     for (I = 0; I < Count; ++I) {
600         /* Get the insn referencing this label */
601         CodeEntry* E = CollAt (&L->JumpFrom, I);
602         /* Remove the reference */
603         E->JumpTo = 0;
604     }
605     CollDeleteAll (&L->JumpFrom);
606
607     /* Remove the reference to the owning instruction if it has one. The
608      * function may be called for a label without an owner when deleting
609      * unfinished parts of the code. This is unfortunate since it allows
610      * errors to slip through.
611      */
612     if (L->Owner) {
613         CollDeleteItem (&L->Owner->Labels, L);
614     }
615
616     /* All references removed, delete the label itself */
617     FreeCodeLabel (L);
618 }
619
620
621
622 void MergeCodeLabels (CodeSeg* S)
623 /* Merge code labels. That means: For each instruction, remove all labels but
624  * one and adjust references accordingly.
625  */
626 {
627     unsigned I;
628
629     /* Walk over all code entries */
630     unsigned EntryCount = GetCodeEntryCount (S);
631     for (I = 0; I < EntryCount; ++I) {
632
633         CodeLabel* RefLab;
634         unsigned   J;
635
636         /* Get a pointer to the next entry */
637         CodeEntry* E = GetCodeEntry (S, I);
638
639         /* If this entry has zero labels, continue with the next one */
640         unsigned LabelCount = GetCodeLabelCount (E);
641         if (LabelCount == 0) {
642             continue;
643         }
644
645         /* We have at least one label. Use the first one as reference label. */
646         RefLab = GetCodeLabel (E, 0);
647
648         /* Walk through the remaining labels and change references to these
649          * labels to a reference to the one and only label. Delete the labels
650          * that are no longer used. To increase performance, walk backwards
651          * through the list.
652          */
653         for (J = LabelCount-1; J >= 1; --J) {
654
655             /* Get the next label */
656             CodeLabel* L = GetCodeLabel (E, J);
657
658             /* Move all references from this label to the reference label */
659             MoveLabelRefs (L, RefLab);
660
661             /* Remove the label completely. */
662             DelCodeLabel (S, L);
663         }
664
665         /* The reference label is the only remaining label. Check if there
666          * are any references to this label, and delete it if this is not
667          * the case.
668          */
669         if (CollCount (&RefLab->JumpFrom) == 0) {
670             /* Delete the label */
671             DelCodeLabel (S, RefLab);
672         }
673     }
674 }
675
676
677
678 void MoveCodeLabels (CodeSeg* S, struct CodeEntry* Old, struct CodeEntry* New)
679 /* Move all labels from Old to New. The routine will move the labels itself
680  * if New does not have any labels, and move references if there is at least
681  * a label for new. If references are moved, the old label is deleted
682  * afterwards.
683  */
684 {
685     /* Get the number of labels to move */
686     unsigned OldLabelCount = GetCodeLabelCount (Old);
687
688     /* Does the new entry have itself a label? */
689     if (CodeEntryHasLabel (New)) {
690
691         /* The new entry does already have a label - move references */
692         CodeLabel* NewLabel = GetCodeLabel (New, 0);
693         while (OldLabelCount--) {
694
695             /* Get the next label */
696             CodeLabel* OldLabel = GetCodeLabel (Old, OldLabelCount);
697
698             /* Move references */
699             MoveLabelRefs (OldLabel, NewLabel);
700
701             /* Delete the label */
702             DelCodeLabel (S, OldLabel);
703
704         }
705
706     } else {
707
708         /* The new entry does not have a label, just move them */
709         while (OldLabelCount--) {
710
711             /* Move the label to the new entry */
712             MoveCodeLabel (GetCodeLabel (Old, OldLabelCount), New);
713
714         }
715
716     }
717 }
718
719
720
721 void RemoveCodeLabelRef (CodeSeg* S, struct CodeEntry* E)
722 /* Remove the reference between E and the label it jumps to. The reference
723  * will be removed on both sides and E->JumpTo will be 0 after that. If
724  * the reference was the only one for the label, the label will get
725  * deleted.
726  */
727 {
728     /* Get a pointer to the label and make sure it exists */
729     CodeLabel* L = E->JumpTo;
730     CHECK (L != 0);
731
732     /* Delete the entry from the label */
733     CollDeleteItem (&L->JumpFrom, E);
734
735     /* The entry jumps no longer to L */
736     E->JumpTo = 0;
737
738     /* If there are no more references, delete the label */
739     if (CollCount (&L->JumpFrom) == 0) {
740         DelCodeLabel (S, L);
741     }
742 }
743
744
745
746 void MoveCodeLabelRef (CodeSeg* S, struct CodeEntry* E, CodeLabel* L)
747 /* Change the reference of E to L instead of the current one. If this
748  * was the only reference to the old label, the old label will get
749  * deleted.
750  */
751 {
752     /* Get the old label */
753     CodeLabel* OldLabel = E->JumpTo;
754
755     /* Be sure that code entry references a label */
756     PRECONDITION (OldLabel != 0);
757
758     /* Remove the reference to our label */
759     RemoveCodeLabelRef (S, E);
760
761     /* Use the new label */
762     AddLabelRef (L, E);
763 }
764
765
766
767 void AddCodeSegHint (CodeSeg* S, unsigned Hint)
768 /* Add a hint for the preceeding instruction */
769 {
770     CodeEntry* E;
771
772     /* Get the number of entries in this segment */
773     unsigned EntryCount = GetCodeEntryCount (S);
774
775     /* Must have at least one entry */
776     CHECK (EntryCount > 0);
777
778     /* Get the last entry */
779     E = GetCodeEntry (S, EntryCount-1);
780
781     /* Add the hint */
782     E->Hints |= Hint;
783 }
784
785
786
787 void DelCodeSegAfter (CodeSeg* S, unsigned Last)
788 /* Delete all entries including the given one */
789 {
790     /* Get the number of entries in this segment */
791     unsigned Count = GetCodeEntryCount (S);
792
793     /* Check if we have to delete anything */
794     if (Last < Count) {
795
796         /* Remove all entries after the given one */
797         while (Last < Count--) {
798
799             /* Get the next entry */
800             CodeEntry* E = GetCodeEntry (S, Count);
801
802             /* If the code entry has labels, delete them */
803             while (CodeEntryHasLabel (E)) {
804
805                 /* Get the label */
806                 CodeLabel* L = GetCodeLabel (E, 0);
807
808                 /* Delete it */
809                 DelCodeLabel (S, L);
810
811             }
812
813             /* Delete the entry itself */
814             DelCodeEntry (S, Count);
815         }
816     }
817 }
818
819
820
821 void OutputCodeSeg (const CodeSeg* S, FILE* F)
822 /* Output the code segment data to a file */
823 {
824     unsigned I;
825
826     /* Get the number of entries in this segment */
827     unsigned Count = GetCodeEntryCount (S);
828
829     /* If the code segment is empty, bail out here */
830     if (Count == 0) {
831         return;
832     }
833
834     /* Output the segment directive */
835     fprintf (F, ".segment\t\"%s\"\n\n", S->SegName);
836
837     /* If this is a segment for a function, enter a function */
838     if (S->Func) {
839         fprintf (F, ".proc\t_%s\n\n", S->Func->Name);
840     }
841
842     /* Output all entries */
843     for (I = 0; I < Count; ++I) {
844         OutputCodeEntry (CollConstAt (&S->Entries, I), F);
845     }
846
847     /* If this is a segment for a function, leave the function */
848     if (S->Func) {
849         fprintf (F, "\n.endproc\n\n");
850     }
851 }
852
853
854
855 unsigned GetCodeEntryCount (const CodeSeg* S)
856 /* Return the number of entries for the given code segment */
857 {
858     return CollCount (&S->Entries);
859 }
860
861
862
863