1 /*-------------------------------------------------------------------------
3 main.c - pic16 specific general functions.
5 Written by - Scott Dattalo scott@dattalo.com
6 Ported to PIC16 by - Martin Dubuc m.debuc@rogers.com
8 Note that mlh prepended _pic16_ on the static functions. Makes
9 it easier to set a breakpoint using the debugger.
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by the
14 Free Software Foundation; either version 2, or (at your option) any
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 -------------------------------------------------------------------------*/
37 static char _defaultRules[] =
42 /* list of key words used by pic16 */
43 static char *_pic16_keywords[] =
76 pic16_sectioninfo_t pic16_sectioninfo;
79 extern char *pic16_processor_base_name(void);
81 void pic16_pCodeInitRegisters(void);
83 void pic16_assignRegisters (eBBlock ** ebbs, int count);
85 static int regParmFlg = 0; /* determine if we can register a parameter */
87 pic16_options_t pic16_options;
89 extern set *includeDirsSet;
90 extern set *dataDirsSet;
91 extern set *libFilesSet;
93 /* Also defined in gen.h, but the #include is commented out */
94 /* for an unknowned reason. - EEP */
95 void pic16_emitDebuggerSymbol (char *);
97 extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
98 extern void pic16_emitConfigRegs(FILE *of);
99 extern void pic16_emitIDRegs(FILE *of);
106 asm_addTree (&asm_asxxxx_mapping);
107 pic16_pCodeInitRegisters();
112 _pic16_reset_regparm (void)
118 _pic16_regparm (sym_link * l)
120 /* force all parameters via SEND/RECEIVE */
121 if(0 /*pic16_options.ip_stack*/) {
122 /* for this processor it is simple
123 * can pass only the first parameter in a register */
124 if(regParmFlg)return 0;
126 return 1; //regParmFlg;
128 /* otherwise pass all arguments in registers via SEND/RECEIVE */
135 int initsfpnt=0; /* set to 1 if source provides a pragma for stack
136 * so glue() later emits code to initialize stack/frame pointers */
139 set *sectNames=NULL; /* list of section listed in pragma directives */
140 set *sectSyms=NULL; /* list of symbols set in a specific section */
141 set *wparamList=NULL;
143 set *asmInlineMap=NULL;
147 unsigned want_libc: 1;
148 unsigned want_libm: 1;
149 unsigned want_libio: 1;
150 unsigned want_libdebug: 1;
151 } libflags = { 0, 0, 0, 0, 0 };
155 _process_pragma(const char *sz)
157 static const char *WHITE = " \t\n";
158 static const char *WHITECOMMA = " \t\n,";
159 char *ptr = strtok((char *)sz, WHITE);
161 /* #pragma maxram [maxram] */
162 if (startsWith (ptr, "maxram")) {
163 char *maxRAM = strtok((char *)NULL, WHITE);
165 if (maxRAM != (char *)NULL) {
169 maxRAMVal = constVal(maxRAM);
170 maxRAMaddress = (int)floatFromVal(maxRAMVal);
171 pic16_setMaxRAM(maxRAMaddress);
177 /* #pragma stack [stack-position] [stack-len] */
178 if(startsWith(ptr, "stack")) {
179 char *stackPosS = strtok((char *)NULL, WHITE);
180 char *stackLenS = strtok((char *)NULL, WHITE);
186 stackPosVal = constVal( stackPosS );
187 stackPos = (unsigned int)floatFromVal( stackPosVal );
190 stackLenVal = constVal( stackLenS );
191 stackLen = (unsigned int)floatFromVal( stackLenVal );
196 fprintf(stderr, "%s:%d: warning: setting stack to default size %d (0x%04x)\n",
197 filename, lineno-1, stackLen, stackLen);
199 // fprintf(stderr, "%s:%d setting stack to default size %d\n", __FILE__, __LINE__, stackLen);
202 // fprintf(stderr, "Initializing stack pointer at 0x%x len 0x%x\n", stackPos, stackLen);
204 reg=newReg(REG_SFR, PO_SFR_REGISTER, stackPos, "_stack", stackLen-1, 0, NULL);
205 addSet(&pic16_fix_udata, reg);
207 reg = newReg(REG_SFR, PO_SFR_REGISTER, stackPos + stackLen-1, "_stack_end", 1, 0, NULL);
208 addSet(&pic16_fix_udata, reg);
210 sym = newSymbol("stack", 0);
211 sprintf(sym->rname, "_%s", sym->name);
212 addSet(&publics, sym);
214 sym = newSymbol("stack_end", 0);
215 sprintf(sym->rname, "_%s", sym->name);
216 addSet(&publics, sym);
218 initsfpnt = 1; // force glue() to initialize stack/frame pointers */
223 /* #pragma code [symbol] [location] */
224 if(startsWith(ptr, "code")) {
225 char *symname = strtok((char *)NULL, WHITE);
226 char *location = strtok((char *)NULL, WHITE);
230 absS = Safe_calloc(1, sizeof(absSym));
231 sprintf(absS->name, "_%s", symname);
233 addr = constVal( location );
234 absS->address = (unsigned int)floatFromVal( addr );
236 if((absS->address % 2) != 0) {
238 fprintf(stderr, "%s:%d: warning: code memory locations should be word aligned, will locate to 0x%06x instead\n",
239 filename, lineno-1, absS->address);
242 addSet(&absSymSet, absS);
243 // fprintf(stderr, "%s:%d symbol %s will be placed in location 0x%06x in code memory\n",
244 // __FILE__, __LINE__, symname, absS->address);
249 /* #pragma udata [section-name] [symbol] */
250 if(startsWith(ptr, "udata")) {
251 char *sectname = strtok((char *)NULL, WHITE);
252 char *symname = strtok((char *)NULL, WHITE);
259 ssym = Safe_calloc(1, sizeof(sectSym));
260 ssym->name = Safe_calloc(1, strlen(symname)+2);
261 sprintf(ssym->name, "_%s", symname);
264 addSet(§Syms, ssym);
266 nsym = newSymbol(symname, 0);
267 strcpy(nsym->rname, ssym->name);
270 checkAddSym(&publics, nsym);
274 for(snam=setFirstItem(sectNames);snam;snam=setNextItem(sectNames)) {
275 if(!strcmp(sectname, snam->name)){ found=1; break; }
279 snam = Safe_calloc(1, sizeof(sectName));
280 snam->name = Safe_strdup( sectname );
281 snam->regsSet = NULL;
283 addSet(§Names, snam);
286 ssym->section = snam;
289 fprintf(stderr, "%s:%d placing symbol %s at section %s (%p)\n", __FILE__, __LINE__,
290 ssym->name, snam->name, snam);
293 symname = strtok((char *)NULL, WHITE);
299 /* #pragma wparam function1[, function2[,...]] */
300 if(startsWith(ptr, "wparam")) {
301 char *fname = strtok((char *)NULL, WHITECOMMA);
305 fprintf(stderr, "PIC16 Warning: `%s' wparam pragma is obsolete. use function attribute `wparam' instead.\n", fname);
306 addSet(&wparamList, Safe_strdup(fname));
308 // debugf("passing with WREG to %s\n", fname);
309 fname = strtok((char *)NULL, WHITECOMMA);
315 /* #pragma library library_module */
316 if(startsWith(ptr, "library")) {
317 char *lmodule = strtok((char *)NULL, WHITE);
321 * c link the C library
322 * math link the math library
323 * io link the IO library
324 * debug link the debug libary
325 * anything else, will link as-is */
327 if(!strcmp(lmodule, "c"))libflags.want_libc = 1;
328 else if(!strcmp(lmodule, "math"))libflags.want_libm = 1;
329 else if(!strcmp(lmodule, "io"))libflags.want_libio = 1;
330 else if(!strcmp(lmodule, "debug"))libflags.want_libdebug = 1;
331 else if(!strcmp(lmodule, "ignore"))libflags.ignore = 1;
333 if(!libflags.ignore) {
334 fprintf(stderr, "link library %s\n", lmodule);
335 addSetHead(&libFilesSet, lmodule);
343 if(startsWith(ptr, "inline")) {
344 char *tmp = strtok((char *)NULL, WHITECOMMA);
347 addSet(&asmInlineMap, Safe_strdup( tmp ));
348 tmp = strtok((char *)NULL, WHITECOMMA);
354 for(s = setFirstItem(asmInlineMap); s ; s = setNextItem(asmInlineMap)) {
355 debugf("inline asm: `%s'\n", s);
365 #define REP_UDATA "--preplace-udata-with="
367 #define STACK_MODEL "--pstack-model="
368 #define OPT_BANKSEL "--obanksel="
370 #define ALT_ASM "--asm="
371 #define ALT_LINK "--link="
373 #define IVT_LOC "--ivt-loc="
374 #define NO_DEFLIBS "--nodefaultlibs"
375 #define MPLAB_COMPAT "--mplab-comp"
377 #define NL_OPT "--nl="
378 #define USE_CRT "--use-crt="
380 #define OFMSG_LRSUPPORT "--flr-support"
382 #define OPTIMIZE_GOTO "--optimize-goto"
383 #define OPTIMIZE_CMP "--optimize-cmp"
388 int pic16_mplab_comp=0;
389 extern int pic16_debug_verbose;
390 extern int pic16_ralloc_debug;
391 extern int pic16_pcode_verbose;
394 int pic16_enable_peeps=0;
395 int pic16_nl=0; /* 0 for LF, 1 for CRLF */
397 OPTION pic16_optionsTable[]= {
398 { 0, NO_DEFLIBS, &pic16_options.nodefaultlibs, "do not link default libraries when linking"},
399 { 0, "--pno-banksel", &pic16_options.no_banksel, "do not generate BANKSEL assembler directives"},
400 { 0, OPT_BANKSEL, NULL, "set banksel optimization level (default=0 no)"},
401 // { 0, "--pomit-config-words", &pic16_options.omit_configw, "omit the generation of configuration words"},
402 // { 0, "--pomit-ivt", &pic16_options.omit_ivt, "omit the generation of the Interrupt Vector Table"},
403 // { 0, "--pleave-reset-vector",&pic16_options.leave_reset, "when omitting IVT leave RESET vector"},
404 { 0, STACK_MODEL, NULL, "use stack model 'small' (default) or 'large'"},
406 { 0, "--debug-xtra", &pic16_debug_verbose, "show more debug info in assembly output"},
407 { 0, "--debug-ralloc", &pic16_ralloc_debug, "dump register allocator debug file *.d"},
408 { 0, "--pcode-verbose", &pic16_pcode_verbose, "dump pcode related info"},
410 { 0, REP_UDATA, NULL, "Place udata variables at another section: udata_acs, udata_ovr, udata_shr"},
412 { 0, ALT_ASM, NULL, "Use alternative assembler"},
413 { 0, ALT_LINK, NULL, "Use alternative linker"},
415 { 0, "--denable-peeps", &pic16_enable_peeps, "explicit enable of peepholes"},
416 { 0, IVT_LOC, NULL, "<nnnn> interrupt vector table location"},
417 { 0, "--calltree", &pic16_options.dumpcalltree, "dump call tree in .calltree file"},
418 { 0, MPLAB_COMPAT, &pic16_mplab_comp, "enable compatibility mode for MPLAB utilities (MPASM/MPLINK)"},
419 { 0, "--fstack", &pic16_fstack, "enable stack optimizations"},
420 { 0, NL_OPT, NULL, "new line, \"lf\" or \"crlf\""},
421 { 0, USE_CRT, NULL, "use <crt-o> run-time initialization module"},
422 { 0, "--no-crt", &pic16_options.no_crt, "do not link any default run-time initialization module"},
423 { 0, "--gstack", &pic16_options.gstack, "trace stack pointer push/pop to overflow"},
424 { 0, OPTIMIZE_GOTO, NULL, "try to use (conditional) BRA instead of GOTO"},
425 { 0, OPTIMIZE_CMP, NULL, "try to optimize some compares"},
426 { 0, NULL, NULL, NULL}
430 #define ISOPT(str) !strncmp(argv[ *i ], str, strlen(str) )
432 extern char *getStringArg(const char *, char **, int *, int);
433 extern int getIntArg(const char *, char **, int *, int);
436 _pic16_parseOptions (int *pargc, char **argv, int *i)
441 /* TODO: allow port-specific command line options to specify
442 * segment names here.
445 /* check for arguments that have associated an integer variable */
446 while(pic16_optionsTable[j].pparameter) {
447 if(ISOPT( pic16_optionsTable[j].longOpt )) {
448 (*pic16_optionsTable[j].pparameter)++;
454 if(ISOPT(STACK_MODEL)) {
455 stkmodel = getStringArg(STACK_MODEL, argv, i, *pargc);
456 if(!STRCASECMP(stkmodel, "small"))pic16_options.stack_model = 0;
457 else if(!STRCASECMP(stkmodel, "large"))pic16_options.stack_model = 1;
459 fprintf(stderr, "Unknown stack model: %s", stkmodel);
465 if(ISOPT(OPT_BANKSEL)) {
466 pic16_options.opt_banksel = getIntArg(OPT_BANKSEL, argv, i, *pargc);
470 if(ISOPT(REP_UDATA)) {
471 pic16_sectioninfo.at_udata = Safe_strdup(getStringArg(REP_UDATA, argv, i, *pargc));
476 alt_asm = Safe_strdup(getStringArg(ALT_ASM, argv, i, *pargc));
480 if(ISOPT(ALT_LINK)) {
481 alt_link = Safe_strdup(getStringArg(ALT_LINK, argv, i, *pargc));
486 pic16_options.ivt_loc = getIntArg(IVT_LOC, argv, i, *pargc);
487 fprintf(stderr, "%s:%d setting interrupt vector addresses 0x%x\n", __FILE__, __LINE__, pic16_options.ivt_loc);
494 tmp = Safe_strdup( getStringArg(NL_OPT, argv, i, *pargc) );
495 if(!STRCASECMP(tmp, "lf"))pic16_nl = 0;
496 else if(!STRCASECMP(tmp, "crlf"))pic16_nl = 1;
498 fprintf(stderr, "invalid termination character id\n");
505 pic16_options.no_crt = 0;
506 pic16_options.crt_name = Safe_strdup( getStringArg(USE_CRT, argv, i, *pargc) );
512 if(ISOPT(OFMSG_LRSUPPORT)) {
513 pic16_options.opt_flags |= OF_LR_SUPPORT;
518 if (ISOPT(OPTIMIZE_GOTO)) {
519 pic16_options.opt_flags |= OF_OPTIMIZE_GOTO;
523 if(ISOPT(OPTIMIZE_CMP)) {
524 pic16_options.opt_flags |= OF_OPTIMIZE_CMP;
532 extern set *userIncDirsSet;
534 static void _pic16_initPaths(void)
536 char pic16incDir[512];
537 char pic16libDir[512];
538 set *pic16incDirsSet=NULL;
539 set *pic16libDirsSet=NULL;
542 setMainValue("mcu", pic16->name[2] );
543 addSet(&preArgvSet, Safe_strdup("-D{mcu}"));
545 setMainValue("mcu1", pic16->name[1] );
546 addSet(&preArgvSet, Safe_strdup("-D__{mcu1}"));
548 sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
549 sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
552 if(!options.nostdinc) {
553 /* setup pic16 include directory */
554 pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir);
555 includeDirsSet = pic16incDirsSet;
556 // mergeSets(&includeDirsSet, pic16incDirsSet);
558 /* pic16 port should not search to the SDCC standard include directories,
559 * so add here the deleted include dirs that user has issued in command line */
560 mergeSets(&pic16incDirsSet, userIncDirsSet);
562 if(!options.nostdlib) {
563 /* setup pic16 library directory */
564 pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir);
565 libDirsSet = pic16libDirsSet;
566 // mergeSets(&libDirsSet, pic16libDirsSet);
569 if(!pic16_options.nodefaultlibs) {
570 /* now add the library for the device */
571 sprintf(devlib, "%s.lib", pic16->name[2]);
572 addSet(&libFilesSet, Safe_strdup(devlib));
574 /* add the internal SDCC library */
575 addSet(&libFilesSet, Safe_strdup( "libsdcc.lib" ));
579 extern set *linkOptionsSet;
580 char *msprintf(hTab *pvals, const char *pformat, ...);
581 int my_system(const char *cmd);
583 /* custom function to link objects */
584 static void _pic16_linkEdit(void)
586 hTab *linkValues=NULL;
594 * link command format:
595 * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
599 sprintf(lfrm, "{linker} {incdirs} {lflags} -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
601 shash_add(&linkValues, "linker", "gplink");
603 mergeSets(&tSet, libDirsSet);
604 mergeSets(&tSet, libPathsSet);
606 shash_add(&linkValues, "incdirs", joinStrSet( appendStrSet(tSet, "-I\"", "\"")));
607 shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet));
609 shash_add(&linkValues, "outfile", dstFileName);
611 if(fullSrcFileName) {
612 sprintf(temp, "%s.o", dstFileName);
613 // addSetHead(&relFilesSet, Safe_strdup(temp));
614 shash_add(&linkValues, "user_ofile", temp);
617 if(!pic16_options.no_crt)
618 shash_add(&linkValues, "spec_ofiles", pic16_options.crt_name);
620 shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
622 if(!libflags.ignore) {
623 if(libflags.want_libc)
624 addSet(&libFilesSet, Safe_strdup("libc18f.lib"));
626 if(libflags.want_libm)
627 addSet(&libFilesSet, Safe_strdup("libm18f.lib"));
629 if(libflags.want_libio) {
630 sprintf(temp, "libio%s.lib", pic16->name[1]); /* build libio18f452.lib name */
631 addSet(&libFilesSet, Safe_strdup(temp));
634 if(libflags.want_libdebug)
635 addSet(&libFilesSet, Safe_strdup("libdebug.lib"));
638 shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
640 lcmd = msprintf(linkValues, lfrm);
642 ret = my_system( lcmd );
651 /* forward declarations */
652 extern const char *pic16_linkCmd[];
653 extern const char *pic16_asmCmd[];
654 extern set *asmOptionsSet;
657 _pic16_finaliseOptions (void)
659 port->mem.default_local_map = data;
660 port->mem.default_globl_map = data;
662 /* peepholes are disabled for the time being */
665 /* explicit enable peepholes for testing */
666 if(pic16_enable_peeps)
669 options.all_callee_saves = 1; // always callee saves
672 options.float_rent = 1;
673 options.intlong_rent = 1;
677 if(alt_asm && strlen(alt_asm))
678 pic16_asmCmd[0] = alt_asm;
680 if(alt_link && strlen(alt_link))
681 pic16_linkCmd[0] = alt_link;
683 if(!pic16_options.no_crt) {
684 pic16_options.omit_ivt = 1;
685 pic16_options.leave_reset = 0;
688 if(options.model == MODEL_SMALL)
689 addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_SMALL"));
691 if(options.model == MODEL_LARGE)
692 addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_LARGE"));
697 sprintf(buf, "-D%s -D%s", pic16->name[2], pic16->name[1]);
698 *(strrchr(buf, 'f')) = 'F';
699 addSet(&asmOptionsSet, Safe_strdup( buf ));
703 if(STACK_MODEL_LARGE) {
704 addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
705 addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
707 addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_SMALL"));
708 addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_SMALL"));
714 if (options.model == MODEL_LARGE)
716 port->mem.default_local_map = xdata;
717 port->mem.default_globl_map = xdata;
721 port->mem.default_local_map = data;
722 port->mem.default_globl_map = data;
725 if (options.stack10bit)
727 if (options.model != MODEL_FLAT24)
730 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
731 fprintf (stderr, "\t10 bit stack mode disabled.\n");
732 options.stack10bit = 0;
736 /* Fixup the memory map for the stack; it is now in
737 * far space and requires a FPOINTER to access it.
740 istack->ptrType = FPOINTER;
747 _pic16_setDefaultOptions (void)
749 options.stackAuto = 0; /* implicit declaration */
750 /* port is not capable yet to allocate separate registers
751 * dedicated for passing certain parameters */
753 /* initialize to defaults section locations, names and addresses */
754 pic16_sectioninfo.at_udata = "udata";
756 /* set pic16 port options to defaults */
757 pic16_options.no_banksel = 0;
758 pic16_options.opt_banksel = 0;
759 pic16_options.omit_configw = 0;
760 pic16_options.omit_ivt = 0;
761 pic16_options.leave_reset = 0;
762 pic16_options.stack_model = 0; /* 0 for 'small', 1 for 'large' */
763 pic16_options.ivt_loc = 0x000000;
764 pic16_options.nodefaultlibs = 0;
765 pic16_options.dumpcalltree = 0;
766 pic16_options.crt_name = "crt0i.o"; /* the default crt to link */
767 pic16_options.no_crt = 0; /* use crt by default */
768 pic16_options.ip_stack = 1; /* set to 1 to enable ipop/ipush for stack */
769 pic16_options.gstack = 0;
770 pic16_options.debgen = 0;
774 _pic16_getRegName (struct regs *reg)
783 static char *_pic16_mangleFunctionName(char *sz)
785 // fprintf(stderr, "mangled function name: %s\n", sz);
793 _pic16_genAssemblerPreamble (FILE * of)
795 char *name = pic16_processor_base_name();
799 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
802 fprintf (of, "\tlist\tp=%s\n",&name[1]);
804 if(!pic16_options.omit_configw) {
805 pic16_emitConfigRegs(of);
807 pic16_emitIDRegs(of);
810 fprintf (of, "\tradix dec\n");
813 /* Generate interrupt vector table. */
815 _pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
818 /* PIC18F family has only two interrupts, the high and the low
819 * priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */
821 if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) {
822 fprintf(of, "; RESET vector\n");
823 fprintf(of, "\tgoto\t__sdcc_gsinit_startup\n");
826 if(!pic16_options.omit_ivt) {
827 fprintf(of, "\tres 4\n");
830 fprintf(of, "; High priority interrupt vector 0x0008\n");
832 fprintf(of, "\tgoto\t%s\n", interrupts[1]->rname);
833 fprintf(of, "\tres\t12\n");
835 fprintf(of, "\tretfie\n");
836 fprintf(of, "\tres\t14\n");
839 fprintf(of, "; Low priority interrupt vector 0x0018\n");
841 fprintf(of, "\tgoto\t%s\n", interrupts[2]->rname);
843 fprintf(of, "\tretfie\n");
850 /* return True if the port can handle the type,
851 * False to convert it to function call */
852 static bool _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
854 // fprintf(stderr,"checking for native mult for %c (size: %d)\n", ic->op, getSize(OP_SYMBOL(IC_RESULT(ic))->type));
857 /* multiplication is fixed */
858 /* support mul for char/int/long */
860 && (getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 2))return TRUE;
864 /* support div for char/int/long */
865 if((getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 0)
866 && (ic->op == '/'))return TRUE;
874 /* Do CSE estimation */
875 static bool cseCostEstimation (iCode *ic, iCode *pdic)
877 // operand *result = IC_RESULT(ic);
878 // sym_link *result_type = operandType(result);
881 /* VR -- this is an adhoc. Put here after conversation
882 * with Erik Epetrich */
886 || ic->op == EQ_OP) {
888 fprintf(stderr, "%d %s\n", __LINE__, __FUNCTION__);
893 /* if it is a pointer then return ok for now */
894 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
896 /* if bitwise | add & subtract then no since mcs51 is pretty good at it
897 so we will cse only if they are local (i.e. both ic & pdic belong to
898 the same basic block */
899 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
900 /* then if they are the same Basic block then ok */
901 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
906 /* for others it is cheaper to do the cse */
912 /* Indicate which extended bit operations this port supports */
914 hasExtBitOp (int op, int size)
918 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
925 /* Indicate the expense of an access to an output storage class */
927 oclsExpense (struct memmap *oclass)
929 /* The IN_FARSPACE test is compatible with historical behaviour, */
930 /* but I don't think it is applicable to PIC. If so, please feel */
931 /* free to remove this test -- EEP */
932 if (IN_FARSPACE(oclass))
938 /** $1 is the input object file (PIC16 specific) // >>always the basename<<.
939 $2 is always the output file.
940 $3 -L path and -l libraries
941 $l is the list of extra options that should be there somewhere...
942 MUST be terminated with a NULL.
944 const char *pic16_linkCmd[] =
946 "gplink", "$l", "-o \"$2\"", "\"$1\"","$3", NULL
951 /** $1 is always the basename.
952 $2 is always the output file.
953 $3 varies (nothing currently)
954 $l is the list of extra options that should be there somewhere...
955 MUST be terminated with a NULL.
957 const char *pic16_asmCmd[] =
959 "gpasm", "$l", "$3", "-c", "\"$1.asm\"", "-o \"$2\"", NULL
968 "MCU PIC16", /* Target name */
969 "p18f452", /* Processor */
972 TRUE, /* Emit glue around main */
973 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
977 pic16_asmCmd, /* assembler command and arguments */
978 NULL, /* alternate macro based form */
979 "-g", /* arguments for debug mode */
980 NULL, /* arguments for normal mode */
981 0, /* print externs as global */
982 ".asm", /* assembler file extension */
983 NULL /* no do_assemble function */
986 NULL, // pic16_linkCmd, /* linker command and arguments */
987 NULL, /* alternate macro based form */
988 _pic16_linkEdit, //NULL, /* no do_link function */
989 ".o", /* extension for object files */
990 0 /* no need for linker file */
1002 3, /* fptr, far pointers (see Microchip) */
1009 "XSEG (XDATA)", // xstack
1010 "STACK (DATA)", // istack
1011 "CSEG (CODE)", // code
1012 "DSEG (DATA)", // data
1013 "ISEG (DATA)", // idata
1014 "PSEG (DATA)", // pdata
1015 "XSEG (XDATA)", // xdata
1016 "BSEG (BIT)", // bit
1017 "RSEG (DATA)", // reg
1018 "GSINIT (CODE)", // static
1019 "OSEG (OVR,DATA)", // overlay
1020 "GSFINAL (CODE)", // post static
1021 "HOME (CODE)", // home
1024 NULL, // default location for auto vars
1025 NULL, // default location for global vars
1026 1 // code is read only 1=yes
1029 NULL, /* genExtraAreaDeclaration */
1030 NULL /* genExatrAreaLinkOptions */
1033 /* stack related information */
1034 -1, /* -1 stack grows downwards, +1 upwards */
1035 1, /* extra overhead when calling between banks */
1036 4, /* extra overhead when the function is an ISR */
1037 1, /* extra overhead for a function call */
1038 1, /* re-entrant space */
1039 0 /* 'banked' call overhead, mild overlap with bank_overhead */
1041 /* pic16 has an 8 bit mul */
1046 pic16_emitDebuggerSymbol
1049 255/3, /* maxCount */
1050 3, /* sizeofElement */
1051 /* The rest of these costs are bogus. They approximate */
1052 /* the behavior of src/SDCCicode.c 1.207 and earlier. */
1053 {4,4,4}, /* sizeofMatchJump[] */
1054 {0,0,0}, /* sizeofRangeCompare[] */
1055 0, /* sizeofSubtract */
1056 3, /* sizeofDispatch */
1060 _pic16_parseOptions,
1063 _pic16_finaliseOptions,
1064 _pic16_setDefaultOptions,
1065 pic16_assignRegisters,
1068 _pic16_genAssemblerPreamble,
1069 NULL, /* no genAssemblerEnd */
1071 NULL, // _pic16_genXINIT
1072 NULL, /* genInitStartup */
1073 _pic16_reset_regparm,
1075 _process_pragma, /* process a pragma */
1076 _pic16_mangleFunctionName, /* mangles function name */
1078 hasExtBitOp, /* hasExtBitOp */
1079 oclsExpense, /* oclsExpense */
1081 TRUE, /* little endian */
1084 1, /* transform <= to ! > */
1085 1, /* transform >= to ! < */
1086 1, /* transform != to !(a == b) */
1088 FALSE, /* No array initializer support. */
1089 0, //cseCostEstimation, /* !!!no CSE cost estimation yet */
1090 NULL, /* no builtin functions */
1091 GPOINTER, /* treat unqualified pointers as "generic" pointers */
1092 1, /* reset labelKey to 1 */
1093 1, /* globals & local static allowed */