1 /*-----------------------------------------------------------------*/
2 /* SDCCmem.c - 8051 memory management routines */
3 /*-----------------------------------------------------------------*/
6 #include "dbuf_string.h"
9 memmap *xstack = NULL; /* xternal stack data */
10 memmap *istack = NULL; /* internal stack */
11 memmap *code = NULL; /* code segment */
12 memmap *data = NULL; /* internal data upto 128 */
13 memmap *pdata = NULL; /* paged external data */
14 memmap *xdata = NULL; /* external data */
15 memmap *xidata = NULL; /* the initialized xdata */
16 memmap *xinit = NULL; /* the initializers for xidata */
17 memmap *idata = NULL; /* internal data upto 256 */
18 memmap *bit = NULL; /* bit addressable space */
19 memmap *statsg = NULL; /* the constant data segment */
20 memmap *c_abs = NULL; /* constant absolute data */
21 memmap *x_abs = NULL; /* absolute xdata/pdata */
22 memmap *i_abs = NULL; /* absolute idata upto 256 */
23 memmap *d_abs = NULL; /* absolute data upto 128 */
24 memmap *sfr = NULL; /* register space */
25 memmap *reg = NULL; /* register space */
26 memmap *sfrbit = NULL; /* sfr bit space */
27 memmap *generic = NULL; /* is a generic pointer */
28 memmap *overlay = NULL; /* overlay segment */
29 memmap *eeprom = NULL; /* eeprom location */
30 memmap *home = NULL; /* Unswitchable code bank */
32 /* this is a set of sets each set containing
33 symbols in a single overlay */
34 set *ovrSetSets = NULL;
37 int fatalError = 0; /* fatal error flag */
39 /*-----------------------------------------------------------------*/
40 /* allocMap - allocates a memory map */
41 /*-----------------------------------------------------------------*/
43 allocMap (char rspace, /* sfr space */
44 char farmap, /* far or near segment */
45 char paged, /* can this segment be paged */
46 char direct, /* directly addressable */
47 char bitaddr, /* bit addressable space */
48 char codemap, /* this is code space */
49 unsigned sloc, /* starting location */
50 const char *name, /* 2 character name */
51 char dbName, /* debug name */
52 int ptrType /* pointer type for this space */
57 if (!(map = Safe_alloc (sizeof (memmap))))
59 werror (E_OUT_OF_MEM, __FILE__, sizeof (memmap));
63 memset (map, ZERO, sizeof (memmap));
69 map->codesp = codemap;
73 map->ptrType = ptrType;
76 dbuf_init(&map->oBuf, 4096);
81 /*-----------------------------------------------------------------*/
82 /* initMem - allocates and initializes all the segments */
83 /*-----------------------------------------------------------------*/
87 /* allocate all the segments */
88 /* xternal stack segment ;
96 POINTER-TYPE - FPOINTER
98 xstack = allocMap (0, 1, 1, 0, 0, 0, options.xstack_loc, XSTACK_NAME, 'A', PPOINTER);
100 /* internal stack segment ;
108 POINTER-TYPE - POINTER
112 istack = allocMap (0, 0, 0, 0, 0, 0, options.stack_loc, ISTACK_NAME, 'B', POINTER);
127 POINTER-TYPE - CPOINTER
129 code = allocMap (0, 1, 0, 0, 0, 1, options.code_loc, CODE_NAME, 'C', CPOINTER);
139 POINTER-TYPE - CPOINTER
141 home = allocMap (0, 1, 0, 0, 0, 1, options.code_loc, HOME_NAME, 'C', CPOINTER);
143 /* Static segment (code for variables );
151 POINTER-TYPE - CPOINTER
153 statsg = allocMap (0, 1, 0, 0, 0, 1, 0, STATIC_NAME, 'D', CPOINTER);
155 /* Constant Absolute Data segment (for variables );
163 POINTER-TYPE - CPOINTER
165 c_abs = allocMap (0, 1, 0, 0, 0, 1, 0, CABS_NAME, 'D', CPOINTER);
167 /* Data segment - internal storage segment ;
175 POINTER-TYPE - POINTER
177 data = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME, 'E', POINTER);
179 /* Absolute internal storage segment ;
187 POINTER-TYPE - POINTER
191 d_abs = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, IABS_NAME, 'E', POINTER);
198 /* overlay segment - same as internal storage segment ;
206 POINTER-TYPE - POINTER
210 overlay = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME, 'E', POINTER);
217 /* Xternal paged segment ;
225 POINTER-TYPE - PPOINTER
229 pdata = allocMap (0, 0, 1, 0, 0, 0, options.xstack_loc, PDATA_NAME, 'P', PPOINTER);
236 /* Xternal Data segment -
244 POINTER-TYPE - FPOINTER
246 xdata = allocMap (0, 1, 0, 0, 0, 0, options.xdata_loc, XDATA_NAME, 'F', FPOINTER);
247 xidata = allocMap (0, 1, 0, 0, 0, 0, 0, XIDATA_NAME, 'F', FPOINTER);
248 xinit = allocMap (0, 1, 0, 0, 0, 1, 0, XINIT_NAME, 'C', CPOINTER);
250 /* Absolute external storage segment ;
258 POINTER-TYPE - FPOINTER
262 x_abs = allocMap (0, 1, 0, 0, 0, 0, options.xdata_loc, XABS_NAME, 'F', FPOINTER);
269 /* Indirectly addressed internal data segment
277 POINTER-TYPE - IPOINTER
281 idata = allocMap (0, 0, 0, 0, 0, 0, options.idata_loc, IDATA_NAME, 'G', IPOINTER);
288 /* Indirectly addressed absolute internal segment
296 POINTER-TYPE - IPOINTER
300 i_abs = allocMap (0, 0, 0, 0, 0, 0, options.data_loc, IABS_NAME, 'E', IPOINTER);
315 POINTER-TYPE - _NONE_
317 bit = allocMap (0, 0, 0, 1, 1, 0, 0, BIT_NAME, 'H', 0);
319 /* Special function register space :-
327 POINTER-TYPE - _NONE_
329 sfr = allocMap (1, 0, 0, 1, 0, 0, 0, REG_NAME, 'I', 0);
339 POINTER-TYPE - _NONE_
341 reg = allocMap (1, 0, 0, 0, 0, 0, 0, REG_NAME, ' ', 0);
351 POINTER-TYPE - _NONE_
353 sfrbit = allocMap (1, 0, 0, 1, 1, 0, 0, REG_NAME, 'J', 0);
363 POINTER-TYPE - EEPPOINTER
365 eeprom = allocMap (0, 1, 0, 0, 0, 0, 0, REG_NAME, 'K', EEPPOINTER);
367 /* the unknown map */
368 generic = allocMap (1, 0, 0, 1, 1, 0, 0, REG_NAME, ' ', GPOINTER);
372 /*-----------------------------------------------------------------*/
373 /* allocIntoSeg - puts a symbol into a memory segment */
374 /*-----------------------------------------------------------------*/
376 allocIntoSeg (symbol * sym)
378 memmap *segment = SPEC_OCLS (sym->etype);
379 addSet (&segment->syms, sym);
380 if (segment == pdata)
384 /*-----------------------------------------------------------------*/
385 /* deleteFromSeg - deletes a symbol from segment used when a var */
386 /* first declared as "extern" then no extern */
387 /*-----------------------------------------------------------------*/
388 void deleteFromSeg(symbol *sym)
390 if (SPEC_OCLS(sym->etype)) {
391 memmap *segment = SPEC_OCLS (sym->etype);
392 deleteSetItem(&segment->syms,sym);
396 /*-----------------------------------------------------------------*/
397 /* allocDefault - assigns the output segment based on SCLASS */
398 /*-----------------------------------------------------------------*/
400 allocDefault (symbol * sym)
402 switch (SPEC_SCLS (sym->etype))
405 SPEC_OCLS (sym->etype) = sfr;
408 SPEC_OCLS (sym->etype) = sfrbit;
413 /* if code change to constant */
414 if (sym->ival && (sym->level==0) && SPEC_ABSA (sym->etype))
416 SPEC_OCLS(sym->etype) = c_abs;
420 SPEC_OCLS (sym->etype) = statsg;
424 /* absolute initialized global */
425 if (sym->ival && (sym->level==0) && SPEC_ABSA (sym->etype))
427 SPEC_OCLS(sym->etype) = x_abs;
429 /* or should we move this to the initialized data segment? */
430 else if (port->genXINIT && sym->ival && (sym->level==0))
432 SPEC_OCLS(sym->etype) = xidata;
436 SPEC_OCLS (sym->etype) = xdata;
440 /* absolute initialized global */
441 if (sym->ival && (sym->level==0) && SPEC_ABSA (sym->etype))
443 SPEC_OCLS(sym->etype) = d_abs;
447 SPEC_OCLS (sym->etype) = data;
451 /* absolute initialized global */
452 if (sym->ival && (sym->level==0) && SPEC_ABSA (sym->etype))
454 SPEC_OCLS(sym->etype) = i_abs;
458 SPEC_OCLS (sym->etype) = idata;
463 SPEC_OCLS (sym->etype) = pdata;
467 SPEC_OCLS (sym->etype) = bit;
470 SPEC_OCLS (sym->etype) = eeprom;
479 /*-----------------------------------------------------------------*/
480 /* allocGlobal - assigns the output segment to a global var */
481 /*-----------------------------------------------------------------*/
483 allocGlobal (symbol * sym)
486 /* symbol name is internal name */
487 if (!sym->level) /* local statics can come here */
488 SNPRINTF (sym->rname, sizeof(sym->rname),
489 "%s%s", port->fun_prefix, sym->name);
491 /* add it to the operandKey reset */
492 if (!isinSet (operKeyReset, sym)) {
493 addSet(&operKeyReset, sym);
496 /* if this is a literal e.g. enumerated type */
497 /* put it in the data segment & do nothing */
498 if (IS_LITERAL (sym->etype))
500 SPEC_OCLS (sym->etype) = data;
504 /* if this is a function then assign code space */
505 if (IS_FUNC (sym->type))
507 SPEC_OCLS (sym->etype) = code;
508 /* if this is an interrupt service routine
509 then put it in the interrupt service array */
510 if (FUNC_ISISR (sym->type) && !options.noiv
511 && (FUNC_INTNO (sym->type) != INTNO_UNSPEC))
513 if (interrupts[FUNC_INTNO (sym->type)])
514 werror (E_INT_DEFINED,
515 FUNC_INTNO (sym->type),
516 interrupts[FUNC_INTNO (sym->type)]->name);
518 interrupts[FUNC_INTNO (sym->type)] = sym;
520 /* automagically extend the maximum interrupts */
521 if (FUNC_INTNO (sym->type) >= maxInterrupts)
522 maxInterrupts = FUNC_INTNO (sym->type) + 1;
524 /* if it is not compiler defined */
531 /* if this is a bit variable and no storage class */
532 if (IS_SPEC(sym->type) && SPEC_NOUN (sym->type) == V_BIT)
533 /*&& SPEC_SCLS (sym->etype) == S_BIT*/
535 SPEC_OCLS (sym->type) = bit;
540 if(!TARGET_IS_PIC16 || (TARGET_IS_PIC16 && sym->level))
541 /* register storage class ignored changed to FIXED */
542 if (SPEC_SCLS (sym->etype) == S_REGISTER)
543 SPEC_SCLS (sym->etype) = S_FIXED;
545 /* if it is fixed, then allocate depending on the */
546 /* current memory model, same for automatics */
547 if (SPEC_SCLS (sym->etype) == S_FIXED ||
548 (TARGET_IS_PIC16 && (SPEC_SCLS (sym->etype) == S_REGISTER) && (sym->level==0)) ||
549 SPEC_SCLS (sym->etype) == S_AUTO) {
550 if (port->mem.default_globl_map != xdata) {
551 /* set the output class */
552 SPEC_OCLS (sym->etype) = port->mem.default_globl_map;
553 /* generate the symbol */
557 SPEC_SCLS (sym->etype) = S_XDATA;
565 /*-----------------------------------------------------------------*/
566 /* allocParms - parameters are always passed on stack */
567 /*-----------------------------------------------------------------*/
569 allocParms (value * val)
574 for (lval = val; lval; lval = lval->next, pNum++)
576 /* check the declaration */
577 checkDecl (lval->sym, 0);
579 /* if this a register parm then allocate
580 it as a local variable by adding it
581 to the first block we see in the body */
582 if (IS_REGPARM (lval->etype))
585 /* mark it as my parameter */
586 lval->sym->ismyparm = 1;
587 lval->sym->localof = currFunc;
589 /* if automatic variables r 2b stacked */
590 if (options.stackAuto || IFFUNC_ISREENT (currFunc->type))
593 lval->sym->onStack = 1;
595 /* choose which stack 2 use */
596 /* use xternal stack */
597 if (options.useXstack)
599 /* PENDING: stack direction support */
600 SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) = xstack;
601 SPEC_STAK (lval->etype) = SPEC_STAK (lval->sym->etype) = lval->sym->stack =
602 xstackPtr - getSize (lval->type);
603 xstackPtr -= getSize (lval->type);
606 { /* use internal stack */
607 SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) = istack;
608 if (port->stack.direction > 0)
610 SPEC_STAK (lval->etype) = SPEC_STAK (lval->sym->etype) = lval->sym->stack =
611 stackPtr - (FUNC_REGBANK (currFunc->type) ? port->stack.bank_overhead : 0) -
612 getSize (lval->type) -
613 (FUNC_ISISR (currFunc->type) ? port->stack.isr_overhead : 0);
614 stackPtr -= getSize (lval->type);
618 /* This looks like the wrong order but it turns out OK... */
619 /* PENDING: isr, bank overhead, ... */
620 SPEC_STAK (lval->etype) = SPEC_STAK (lval->sym->etype) = lval->sym->stack =
622 ((IFFUNC_ISBANKEDCALL (currFunc->type) && !SPEC_STAT(getSpec(currFunc->etype)))? port->stack.banked_overhead : 0) +
623 (FUNC_ISISR (currFunc->type) ? port->stack.isr_overhead : 0) +
625 stackPtr += getSize (lval->type);
628 allocIntoSeg (lval->sym);
631 { /* allocate them in the automatic space */
632 /* generate a unique name */
633 SNPRINTF (lval->sym->rname, sizeof(lval->sym->rname),
634 "%s%s_PARM_%d", port->fun_prefix, currFunc->name, pNum);
635 strncpyz (lval->name, lval->sym->rname, sizeof(lval->name));
637 /* if declared in specific storage */
638 if (allocDefault (lval->sym))
640 SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype);
644 /* otherwise depending on the memory model */
645 SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) =
646 port->mem.default_local_map;
647 if (options.model == MODEL_SMALL)
649 /* note here that we put it into the overlay segment
650 first, we will remove it from the overlay segment
651 after the overlay determination has been done */
652 if (!options.noOverlay)
654 SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) =
658 else if (options.model == MODEL_MEDIUM)
660 SPEC_SCLS (lval->etype) = S_PDATA;
664 SPEC_SCLS (lval->etype) = S_XDATA;
666 allocIntoSeg (lval->sym);
672 /*-----------------------------------------------------------------*/
673 /* deallocParms - parameters are always passed on stack */
674 /*-----------------------------------------------------------------*/
676 deallocParms (value * val)
680 for (lval = val; lval; lval = lval->next)
682 /* unmark is myparm */
683 lval->sym->ismyparm = 0;
685 /* delete it from the symbol table */
686 deleteSym (SymbolTab, lval->sym, lval->sym->name);
688 if (!lval->sym->isref)
690 lval->sym->allocreq = 0;
691 werror (W_NO_REFERENCE,
692 currFunc ? currFunc->name : "(unknown)",
693 "function argument", lval->sym->name);
696 /* move the rname if any to the name for both val & sym */
697 /* and leave a copy of it in the symbol table */
698 if (lval->sym->rname[0])
700 char buffer[SDCC_NAME_MAX];
701 strncpyz (buffer, lval->sym->rname, sizeof(buffer));
702 lval->sym = copySymbol (lval->sym);
703 strncpyz (lval->sym->rname, buffer, sizeof(lval->sym->rname));
704 strncpyz (lval->sym->name, buffer, sizeof(lval->sym->name));
705 strncpyz (lval->name, buffer, sizeof(lval->name));
706 addSym (SymbolTab, lval->sym, lval->sym->name,
707 lval->sym->level, lval->sym->block, 1);
708 lval->sym->_isparm = 1;
709 if (!isinSet (operKeyReset, lval->sym))
711 addSet(&operKeyReset, lval->sym);
718 /*-----------------------------------------------------------------*/
719 /* allocLocal - allocate local variables */
720 /*-----------------------------------------------------------------*/
722 allocLocal (symbol * sym)
724 /* generate an unique name */
725 SNPRINTF (sym->rname, sizeof(sym->rname),
728 currFunc->name, sym->name, sym->level, sym->block);
731 sym->localof = currFunc;
733 /* if this is a static variable */
734 if (IS_STATIC (sym->etype))
741 /* if volatile then */
742 if (IS_VOLATILE (sym->etype))
745 /* this is automatic */
747 /* if it's to be placed on the stack */
748 if (options.stackAuto || reentrant) {
750 if (options.useXstack) {
751 /* PENDING: stack direction for xstack */
752 SPEC_OCLS (sym->etype) = xstack;
753 SPEC_STAK (sym->etype) = sym->stack = (xstackPtr + 1);
754 xstackPtr += getSize (sym->type);
756 SPEC_OCLS (sym->etype) = istack;
757 if (port->stack.direction > 0) {
758 SPEC_STAK (sym->etype) = sym->stack = (stackPtr + 1);
759 stackPtr += getSize (sym->type);
761 stackPtr -= getSize (sym->type);
762 SPEC_STAK (sym->etype) = sym->stack = stackPtr;
769 /* else depending on the storage class specified */
771 /* if this is a function then assign code space */
772 if (IS_FUNC (sym->type))
774 SPEC_OCLS (sym->etype) = code;
778 /* if this is a bit variable and no storage class */
779 if (IS_SPEC(sym->type) && SPEC_NOUN (sym->type) == V_BIT)
781 SPEC_SCLS (sym->type) = S_BIT;
782 SPEC_OCLS (sym->type) = bit;
787 if ((SPEC_SCLS (sym->etype) == S_DATA) || (SPEC_SCLS (sym->etype) == S_REGISTER))
789 SPEC_OCLS (sym->etype) = (options.noOverlay ? data : overlay);
794 if (allocDefault (sym))
799 /* again note that we have put it into the overlay segment
800 will remove and put into the 'data' segment if required after
801 overlay analysis has been done */
802 if (options.model == MODEL_SMALL) {
803 SPEC_OCLS (sym->etype) =
804 (options.noOverlay ? port->mem.default_local_map : overlay);
806 SPEC_OCLS (sym->etype) = port->mem.default_local_map;
811 /*-----------------------------------------------------------------*/
812 /* deallocLocal - deallocates the local variables */
813 /*-----------------------------------------------------------------*/
815 deallocLocal (symbol * csym)
819 for (sym = csym; sym; sym = sym->next)
824 /* if it is on the stack */
827 if (options.useXstack)
828 xstackPtr -= getSize (sym->type);
830 stackPtr -= getSize (sym->type);
832 /* if not used give a warning */
833 if (!sym->isref && !IS_STATIC (sym->etype))
834 werror (W_NO_REFERENCE,
835 currFunc ? currFunc->name : "(unknown)",
836 "local variable", sym->name);
837 /* now delete it from the symbol table */
838 deleteSym (SymbolTab, sym, sym->name);
842 /*-----------------------------------------------------------------*/
843 /* overlay2data - moves declarations from the overlay seg to data */
844 /*-----------------------------------------------------------------*/
850 for (sym = setFirstItem (overlay->syms); sym;
851 sym = setNextItem (overlay->syms))
854 SPEC_OCLS (sym->etype) = data;
858 setToNull ((void *) &overlay->syms);
862 /*-----------------------------------------------------------------*/
863 /* overlay2Set - will add all symbols from the overlay segment to */
864 /* the set of sets containing the overlable symbols */
865 /*-----------------------------------------------------------------*/
872 for (sym = setFirstItem (overlay->syms); sym;
873 sym = setNextItem (overlay->syms))
879 setToNull ((void *) &overlay->syms);
880 addSet (&ovrSetSets, oset);
884 /*-----------------------------------------------------------------*/
885 /* allocVariables - creates decl & assign storage class for a v */
886 /*-----------------------------------------------------------------*/
888 allocVariables (symbol * symChain)
895 /* go thru the symbol chain */
896 for (sym = symChain; sym; sym = sym->next)
899 /* if this is a typedef then add it */
900 /* to the typedef table */
901 if (IS_TYPEDEF (sym->etype))
903 /* check if the typedef already exists */
904 csym = findSym (TypedefTab, NULL, sym->name);
905 if (csym && csym->level == sym->level)
906 werror (E_DUPLICATE_TYPEDEF, sym->name);
908 SPEC_EXTR (sym->etype) = 0;
909 addSym (TypedefTab, sym, sym->name, sym->level, sym->block, 0);
910 continue; /* go to the next one */
912 /* make sure it already exist */
913 csym = findSymWithLevel (SymbolTab, sym);
914 if (!csym || (csym && csym->level != sym->level))
917 /* check the declaration */
920 /* if this is a function or a pointer to function */
921 /* then args processing */
922 if (funcInChain (csym->type))
924 processFuncArgs (csym);
926 /* if register bank specified then update maxRegBank */
927 if (maxRegBank < FUNC_REGBANK (csym->type))
928 maxRegBank = FUNC_REGBANK (csym->type);
929 /*JCF: Mark the register bank as used*/
930 RegBankUsed[FUNC_REGBANK(csym->type)]=1;
933 /* if this is a extern variable then change the */
934 /* level to zero temporarily */
935 if (IS_EXTERN (csym->etype) || IS_FUNC (csym->type))
937 saveLevel = csym->level;
941 /* if this is a literal then it is an enumerated */
942 /* type so need not allocate it space for it */
943 if (IS_LITERAL (sym->etype))
946 /* generate the actual declaration */
951 stack += getSize (csym->type);
956 /* restore the level */
957 if (IS_EXTERN (csym->etype) || IS_FUNC (csym->type))
958 csym->level = saveLevel;
964 /*-----------------------------------------------------------------*/
965 /* redoStackOffsets :- will reassign the values for stack offsets */
966 /*-----------------------------------------------------------------*/
968 redoStackOffsets (void)
974 /* after register allocation is complete we know
975 which variables will need to be assigned space
976 on the stack. We will eliminate those variables
977 which do not have the allocReq flag thus reducing
979 for (sym = setFirstItem (istack->syms); sym;
980 sym = setNextItem (istack->syms))
983 int size = getSize (sym->type);
984 /* nothing to do with parameters so continue */
985 if ((sym->_isparm && !IS_REGPARM (sym->etype)))
988 if (IS_AGGREGATE (sym->type))
990 if (port->stack.direction > 0)
992 SPEC_STAK (sym->etype) = sym->stack = (sPtr + 1);
998 SPEC_STAK (sym->etype) = sym->stack = sPtr;
1003 /* if allocation not required then subtract
1004 size from overall stack size & continue */
1007 currFunc->stack -= size;
1008 SPEC_STAK (currFunc->etype) -= size;
1012 if (port->stack.direction > 0)
1014 SPEC_STAK (sym->etype) = sym->stack = (sPtr + 1);
1020 SPEC_STAK (sym->etype) = sym->stack = sPtr;
1024 /* do the same for the external stack */
1026 for (sym = setFirstItem (xstack->syms); sym;
1027 sym = setNextItem (xstack->syms))
1030 int size = getSize (sym->type);
1031 /* nothing to do with parameters so continue */
1032 if ((sym->_isparm && !IS_REGPARM (sym->etype)))
1035 if (IS_AGGREGATE (sym->type))
1037 SPEC_STAK (sym->etype) = sym->stack = (xsPtr + 1);
1042 /* if allocation not required then subtract
1043 size from overall stack size & continue */
1046 currFunc->xstack -= size;
1047 SPEC_STAK (currFunc->etype) -= size;
1051 SPEC_STAK (sym->etype) = sym->stack = (xsPtr + 1);
1057 /*-----------------------------------------------------------------*/
1058 /* printAllocInfoSeg- print the allocation for a given section */
1059 /*-----------------------------------------------------------------*/
1061 printAllocInfoSeg (memmap * map, symbol * func, struct dbuf_s *oBuf)
1070 for (sym = setFirstItem (map->syms); sym;
1071 sym = setNextItem (map->syms))
1074 if (sym->level == 0)
1076 if (sym->localof != func)
1079 dbuf_printf (oBuf, ";%-25s Allocated ", sym->name);
1081 /* if assigned to registers */
1082 if (!sym->allocreq && sym->reqv)
1086 sym = OP_SYMBOL (sym->reqv);
1087 if (!sym->isspilt || sym->remat)
1089 dbuf_append_str (oBuf, "to registers ");
1090 for (i = 0; i < 4 && sym->regs[i]; i++)
1091 dbuf_printf (oBuf, "%s ", port->getRegName (sym->regs[i]));
1092 dbuf_append_char (oBuf, '\n');
1097 sym = sym->usl.spillLoc;
1104 dbuf_printf (oBuf, "to stack - offset %d\n", sym->stack);
1108 /* otherwise give rname */
1109 dbuf_printf (oBuf, "with name '%s'\n", sym->rname);
1113 /*-----------------------------------------------------------------*/
1114 /* canOverlayLocals - returns true if the local variables can overlayed */
1115 /*-----------------------------------------------------------------*/
1117 canOverlayLocals (eBBlock ** ebbs, int count)
1120 /* if staticAuto is in effect or the current function
1121 being compiled is reentrant or the overlay segment
1122 is empty or no overlay option is in effect then */
1123 if (options.noOverlay ||
1124 options.stackAuto ||
1126 (IFFUNC_ISREENT (currFunc->type) ||
1127 FUNC_ISISR (currFunc->type))) ||
1128 elementsInSet (overlay->syms) == 0)
1132 /* if this is a forces overlay */
1133 if (IFFUNC_ISOVERLAY(currFunc->type)) return TRUE;
1135 /* otherwise do thru the blocks and see if there
1136 any function calls if found then return false */
1137 for (i = 0; i < count; i++)
1141 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1143 if (ic->op == CALL) {
1144 sym_link *ftype = operandType(IC_LEFT(ic));
1145 /* builtins only can use overlays */
1146 if (!IFFUNC_ISBUILTIN(ftype)) return FALSE;
1147 } else if (ic->op == PCALL) return FALSE;
1151 /* no function calls found return TRUE */
1155 /*-----------------------------------------------------------------*/
1156 /* doOverlays - move the overlay segment to appropriate location */
1157 /*-----------------------------------------------------------------*/
1159 doOverlays (eBBlock ** ebbs, int count)
1165 /* check if the parameters and local variables
1166 of this function can be put in the overlay segment
1167 This check is essentially to see if the function
1168 calls any other functions if yes then we cannot
1170 if (canOverlayLocals (ebbs, count))
1171 /* if we can then put the parameters &
1172 local variables in the overlay set */
1175 /* otherwise put them into data where
1180 /*-----------------------------------------------------------------*/
1181 /* printAllocInfo - prints allocation information for a function */
1182 /*-----------------------------------------------------------------*/
1184 printAllocInfo (symbol * func, struct dbuf_s * oBuf)
1189 /* must be called after register allocation is complete */
1190 dbuf_append_str (oBuf, ";------------------------------------------------------------\n");
1191 dbuf_printf (oBuf, ";Allocation info for local variables in function '%s'\n", func->name);
1192 dbuf_append_str (oBuf, ";------------------------------------------------------------\n");
1194 printAllocInfoSeg (xstack, func, oBuf);
1195 printAllocInfoSeg (istack, func, oBuf);
1196 printAllocInfoSeg (code, func, oBuf);
1197 printAllocInfoSeg (data, func, oBuf);
1198 printAllocInfoSeg (xdata, func, oBuf);
1199 printAllocInfoSeg (idata, func, oBuf);
1200 printAllocInfoSeg (sfr, func, oBuf);
1201 printAllocInfoSeg (sfrbit, func, oBuf);
1205 set *tempOverlaySyms = overlay->syms;
1207 /* search the set of overlay sets for local variables/parameters */
1208 for (ovrset = setFirstItem (ovrSetSets); ovrset;
1209 ovrset = setNextItem (ovrSetSets))
1211 overlay->syms = ovrset;
1212 printAllocInfoSeg (overlay, func, oBuf);
1214 overlay->syms = tempOverlaySyms;
1217 dbuf_append_str (oBuf, ";------------------------------------------------------------\n");