1 /*-------------------------------------------------------------------------
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 In other words, you are welcome to use, share and improve this program.
21 You are forbidden to forbid anyone else to use, share and improve
22 what you give them. Help stamp out software-hoarding!
23 -------------------------------------------------------------------------*/
32 #include "SDCCmacro.h"
34 #include "SDCCdebug.h"
45 extern int yyparse ();
47 FILE *srcFile; /* source file */
48 char *fullSrcFileName; /* full name for the source file; */
49 /* can be NULL while c1mode or linking without compiling */
50 char *fullDstFileName; /* full name for the output file; */
51 /* only given by -o, otherwise NULL */
52 char *dstFileName; /* destination file name without extension */
53 char *dstPath = ""; /* path for the output files; */
54 /* "" is equivalent with cwd */
55 char *moduleName; /* module name is source file without path and extension */
56 /* can be NULL while linking without compiling */
58 * in following definitions fixed length arrays are very dangerous!
59 * Sets should be used instead. See definition of asmOptions.
61 const char *preArgv[128]; /* pre-processor arguments */
63 int RegBankUsed[4]={1, 0, 0, 0}; /*JCF: Reg Bank 0 used by default*/
64 struct optimize optimize;
65 struct options options;
68 set *asmOptions = NULL; /* set of assembler options */
69 set /*char*/ *linkOptions=NULL; /* set of linker options [128]; */
77 /* uncomment JAMIN_DS390 to always override and use ds390 port
78 for mcs51 work. This is temporary, for compatibility testing. */
79 /* #define JAMIN_DS390 */
84 // Globally accessible scratch buffer for file names.
85 char scratchFileName[PATH_MAX];
86 char buffer[PATH_MAX * 2];
88 #define OPTION_HELP "-help"
90 #define LENGTH(_a) (sizeof(_a)/sizeof(*(_a)))
92 #define OPTION_STACK_8BIT "--stack-8bit"
93 #define OPTION_OUT_FMT_IHX "--out-fmt-ihx"
94 #define OPTION_LARGE_MODEL "--model-large"
95 #define OPTION_MEDIUM_MODEL "--model-medium"
96 #define OPTION_SMALL_MODEL "--model-small"
97 #define OPTION_FLAT24_MODEL "--model-flat24"
98 #define OPTION_DUMP_ALL "--dumpall"
99 #define OPTION_PEEP_FILE "--peep-file"
100 #define OPTION_LIB_PATH "--lib-path"
101 #define OPTION_XSTACK_LOC "--xstack-loc"
102 #define OPTION_CALLEE_SAVES "--callee-saves"
103 #define OPTION_STACK_LOC "--stack-loc"
104 #define OPTION_XRAM_LOC "--xram-loc"
105 #define OPTION_IRAM_SIZE "--iram-size"
106 #define OPTION_VERSION "--version"
107 #define OPTION_DATA_LOC "--data-loc"
108 #define OPTION_CODE_LOC "--code-loc"
109 #define OPTION_IDATA_LOC "--idata-loc"
110 #define OPTION_NO_LABEL_OPT "--nolabelopt"
111 #define OPTION_NO_LOOP_INV "--noinvariant"
112 #define OPTION_NO_LOOP_IND "--noinduction"
113 #define OPTION_LESS_PEDANTIC "--less-pedantic"
114 #define OPTION_NO_GCSE "--nogcse"
115 #define OPTION_SHORT_IS_8BITS "--short-is-8bits"
116 #define OPTION_TINI_LIBID "--tini-libid"
117 #define OPTION_NO_XINIT_OPT "--no-xinit-opt"
118 #define OPTION_XRAM_SIZE "--xram-size"
119 #define OPTION_CODE_SIZE "--code-size"
120 #define OPTION_NO_CCODE_IN_ASM "--no-c-code-in-asm"
121 #define OPTION_ICODE_IN_ASM "--i-code-in-asm"
122 #define OPTION_PRINT_SEARCH_DIRS "--print-search-dirs"
126 { 'm', NULL, NULL, "Set the port to use e.g. -mz80." },
127 { 'p', NULL, NULL, "Select port specific processor e.g. -mpic14 -p16f84" },
128 { 'd', NULL, NULL, NULL },
129 { 'D', NULL, NULL, "Define macro as in -Dmacro" },
130 { 'I', NULL, NULL, "Add to the include (*.h) path, as in -Ipath" },
131 { 'A', NULL, NULL, NULL },
132 { 'U', NULL, NULL, NULL },
133 { 'C', NULL, NULL, "Preprocessor option" },
134 { 'M', NULL, NULL, "Preprocessor option" },
135 { 'V', NULL, &options.verboseExec, "Execute verbosely. Show sub commands as they are run" },
136 { 'S', NULL, &noAssemble, "Compile only; do not assemble or link" },
137 { 'W', NULL, NULL, "Pass through options to the pre-processor (p), assembler (a) or linker (l)" },
138 { 'L', NULL, NULL, "Add the next field to the library search path" },
139 { 'l', NULL, NULL, "Include the given library in the link" },
140 { 0, OPTION_LARGE_MODEL, NULL, "external data space is used" },
141 { 0, OPTION_MEDIUM_MODEL, NULL, "not supported" },
142 { 0, OPTION_SMALL_MODEL, NULL, "internal data space is used (default)" },
143 #if !OPT_DISABLE_DS390
144 { 0, OPTION_FLAT24_MODEL, NULL, "use the flat24 model for the ds390 (default)" },
146 { 0, "--stack-auto", &options.stackAuto, "Stack automatic variables" },
147 #if !OPT_DISABLE_DS390
148 { 0, OPTION_STACK_8BIT, NULL, "use the 8bit stack for the ds390 (not supported yet)" },
149 { 0, "--stack-10bit", &options.stack10bit, "use the 10bit stack for ds390 (default)" },
151 { 0, "--xstack", &options.useXstack, "Use external stack" },
152 { 0, OPTION_NO_GCSE, NULL, "Disable the GCSE optimisation" },
153 { 0, OPTION_NO_LABEL_OPT, NULL, "Disable label optimisation" },
154 { 0, OPTION_NO_LOOP_INV, NULL, "Disable optimisation of invariants" },
155 { 0, OPTION_NO_LOOP_IND, NULL, NULL },
156 { 0, "--nojtbound", &optimize.noJTabBoundary, "Don't generate boundary check for jump tables" },
157 { 0, "--noloopreverse", &optimize.noLoopReverse, "Disable the loop reverse optimisation" },
158 { 'c', "--compile-only", &options.cc_only, "Compile and assemble, but do not link" },
159 { 'o', NULL, NULL, "Place the output into the given path resp. file" },
160 { 0, "--dumpraw", &options.dump_raw, "Dump the internal structure after the initial parse" },
161 { 0, "--dumpgcse", &options.dump_gcse, NULL },
162 { 0, "--dumploop", &options.dump_loop, NULL },
163 { 0, "--dumpdeadcode", &options.dump_kill, NULL },
164 { 0, "--dumpliverange", &options.dump_range, NULL },
165 { 0, "--dumpregpack", &options.dump_pack, NULL },
166 { 0, "--dumpregassign", &options.dump_rassgn, NULL },
167 { 0, "--dumptree", &options.dump_tree, "dump front-end AST before generating iCode" },
168 { 0, OPTION_DUMP_ALL, NULL, "Dump the internal structure at all stages" },
169 { 0, OPTION_XRAM_LOC, NULL, "<nnnn> External Ram start location" },
170 { 0, OPTION_XRAM_SIZE, NULL, "<nnnn> External Ram size" },
171 { 0, OPTION_IRAM_SIZE, NULL, "<nnnn> Internal Ram size" },
172 { 0, OPTION_XSTACK_LOC, NULL, "<nnnn> External Ram start location" },
173 { 0, OPTION_CODE_LOC, NULL, "<nnnn> Code Segment Location" },
174 { 0, OPTION_CODE_SIZE, NULL, "<nnnn> Code Segment size" },
175 { 0, OPTION_STACK_LOC, NULL, "<nnnn> Stack pointer initial value" },
176 { 0, OPTION_DATA_LOC, NULL, "<nnnn> Direct data start location" },
177 { 0, OPTION_IDATA_LOC, NULL, NULL },
178 { 0, OPTION_PEEP_FILE, NULL, "<file> use this extra peep-hole file" },
179 { 0, OPTION_LIB_PATH, NULL, "<path> use this path to search for libraries" },
180 { 0, "--int-long-reent", &options.intlong_rent, "Use reenterant calls on the int and long support functions" },
181 { 0, "--float-reent", &options.float_rent, "Use reenterant calls on the floar support functions" },
182 { 0, OPTION_OUT_FMT_IHX, NULL, NULL },
183 { 0, "--out-fmt-s19", &options.out_fmt, NULL },
184 { 0, "--cyclomatic", &options.cyclomatic, NULL },
185 { 0, "--nooverlay", &options.noOverlay, NULL },
186 { 0, "--main-return", &options.mainreturn, "Issue a return after main()" },
187 { 0, "--xram-movc", &options.xram_movc, "Use movc instead of movx to read xram (xdata)" },
188 { 0, "--no-peep", &options.nopeep, "Disable the peephole assembly file optimisation" },
189 { 0, "--no-reg-params", &options.noRegParams, "On some ports, disable passing some parameters in registers" },
190 { 0, "--peep-asm", &options.asmpeep, NULL },
191 { 0, "--debug", &options.debug, "Enable debugging symbol output" },
192 { 'v', OPTION_VERSION, NULL, "Display sdcc's version" },
193 { 'E', "--preprocessonly", &preProcOnly, "Preprocess only, do not compile" },
194 { 0, "--c1mode", &options.c1mode, "Act in c1 mode. The standard input is preprocessed code, the output is assembly code." },
195 { 0, "--help", NULL, "Display this help" },
196 { 0, OPTION_CALLEE_SAVES, NULL, "<func[,func,...]> Cause the called function to save registers insted of the caller" },
197 { 0, "--nostdlib", &options.nostdlib, "Do not include the standard library directory in the search path" },
198 { 0, "--nostdinc", &options.nostdinc, "Do not include the standard include directory in the search path" },
199 { 0, "--verbose", &options.verbose, "Trace calls to the preprocessor, assembler, and linker" },
200 { 0, OPTION_LESS_PEDANTIC, NULL, "Disable some of the more pedantic warnings" },
201 { 0, OPTION_SHORT_IS_8BITS, NULL, "Make short 8bits (for old times sake)" },
202 { 0, "--profile", &options.profile, "On supported ports, generate extra profiling information" },
203 { 0, "--fommit-frame-pointer", &options.ommitFramePtr, "Leave out the frame pointer." },
204 { 0, "--all-callee-saves", &options.all_callee_saves, "callee will always save registers used" },
205 #if !OPT_DISABLE_DS390
206 { 0, "--use-accelerator", &options.useAccelerator,"generate code for DS390 Arithmetic Accelerator"},
208 { 0, "--stack-probe", &options.stack_probe,"insert call to function __stack_probe at each function prologue"},
209 #if !OPT_DISABLE_TININative
210 { 0, "--tini-libid", NULL,"<nnnn> LibraryID used in -mTININative"},
212 #if !OPT_DISABLE_DS390
213 { 0, "--protect-sp-update", &options.protect_sp_update,"DS390 - will disable interrupts during ESP:SP updates"},
215 #if !OPT_DISABLE_DS390 || !OPT_DISABLE_MCS51
216 { 0, "--parms-in-bank1", &options.parms_in_bank1,"MCS51/DS390 - use Bank1 for parameter passing"},
218 { 0, OPTION_NO_XINIT_OPT, &options.noXinitOpt, "don't memcpy initialized xram from code"},
219 { 0, OPTION_NO_CCODE_IN_ASM, &options.noCcodeInAsm, "don't include c-code as comments in the asm file"},
220 { 0, OPTION_ICODE_IN_ASM, &options.iCodeInAsm, "include i-code as comments in the asm file"},
221 { 0, OPTION_PRINT_SEARCH_DIRS, &options.printSearchDirs, "display the directories in the compiler's search path"},
226 /** Table of all unsupported options and help text to display when one
230 /** shortOpt as in OPTIONS. */
232 /** longOpt as in OPTIONS. */
234 /** Message to display inside W_UNSUPPORTED_OPT when this option
239 static const UNSUPPORTEDOPT
240 unsupportedOptTable[] = {
241 { 'X', NULL, "use --xstack-loc instead" },
242 { 'x', NULL, "use --xstack instead" },
243 { 'i', NULL, "use --idata-loc instead" },
244 { 'r', NULL, "use --xdata-loc instead" },
245 { 's', NULL, "use --code-loc instead" },
246 { 'Y', NULL, "use -I instead" }
249 /** List of all default constant macros.
251 static const char *_baseValues[] = {
254 /* Path seperator character */
255 "sep", DIR_SEPARATOR_STRING,
259 static const char *_preCmd = "{cpp} -nostdinc -Wall -std=c99 -DSDCC=1 {cppextraopts} \"{fullsrcfilename}\" \"{cppoutfilename}\"";
263 static PORT *_ports[] =
265 #if !OPT_DISABLE_MCS51
268 #if !OPT_DISABLE_GBZ80
277 #if !OPT_DISABLE_DS390
283 #if !OPT_DISABLE_PIC16
286 #if !OPT_DISABLE_TININative
289 #if !OPT_DISABLE_XA51
292 #if !OPT_DISABLE_DS400
297 #define NUM_PORTS (sizeof(_ports)/sizeof(_ports[0]))
300 extern void picglue ();
302 #if !OPT_DISABLE_PIC16
303 extern void pic16glue();
306 /** Sets the port to the one given by the command line option.
307 @param The name minus the option (eg 'mcs51')
308 @return 0 on success.
311 _setPort (const char *name)
314 for (i = 0; i < NUM_PORTS; i++)
316 if (!strcmp (_ports[i]->target, name))
322 /* Error - didnt find */
323 werror (E_UNKNOWN_TARGET, name);
327 /* Override the default processor with the one specified
328 * on the command line */
330 _setProcessor (char *_processor)
332 port->processor = _processor;
333 fprintf(stderr,"Processor: %s\n",_processor);
337 _validatePorts (void)
340 for (i = 0; i < NUM_PORTS; i++)
342 if (_ports[i]->magic != PORT_MAGIC)
344 /* Uncomment this line to debug which port is causing the problem
345 * (the target name is close to the beginning of the port struct
346 * and probably can be accessed just fine). */
347 fprintf(stderr,"%s :",_ports[i]->target);
348 wassertl (0, "Port definition structure is incomplete");
353 /* search through the command line options for the port */
355 _findPort (int argc, char **argv)
361 if (!strncmp (*argv, "-m", 2))
363 _setPort (*argv + 2);
369 /* Use the first in the list */
370 #if defined(DEFAULT_PORT)
371 /* VR - 13/5/2003 DEFAULT_PORT is defined in port.h */
372 port = &DEFAULT_PORT;
379 /* search through the command line options for the processor */
381 _findProcessor (int argc, char **argv)
385 if (!strncmp (*argv, "-p", 2))
387 _setProcessor (*argv + 2);
393 /* no error if processor was not specified. */
396 /*-----------------------------------------------------------------*/
397 /* printVersionInfo - prints the version info */
398 /*-----------------------------------------------------------------*/
406 for (i = 0; i < NUM_PORTS; i++)
407 fprintf (stderr, "%s%s", i == 0 ? "" : "/", _ports[i]->target);
409 fprintf (stderr, " " SDCC_VERSION_STR
410 #ifdef SDCC_SUB_VERSION_STR
411 "/" SDCC_SUB_VERSION_STR
416 #elif defined __MINGW32__
418 #elif defined __DJGPP__
420 #elif defined(_MSC_VER)
422 #elif defined(__BORLANDC__)
431 printOptions(const OPTION *optionsTable)
434 for (i = 0; optionsTable[i].shortOpt != 0 || optionsTable[i].longOpt != NULL; i++)
436 fprintf(stdout, " %c%c %-20s %s\n",
437 optionsTable[i].shortOpt !=0 ? '-' : ' ',
438 optionsTable[i].shortOpt !=0 ? optionsTable[i].shortOpt : ' ',
439 optionsTable[i].longOpt != NULL ? optionsTable[i].longOpt : "",
440 optionsTable[i].help != NULL ? optionsTable[i].help : ""
445 /*-----------------------------------------------------------------*/
446 /* printUsage - prints command line syntax */
447 /*-----------------------------------------------------------------*/
454 "Usage : sdcc [options] filename\n"
458 printOptions(optionsTable);
460 for (i = 0; i < NUM_PORTS; i++)
462 if (_ports[i]->poptions != NULL)
464 fprintf (stdout, "\nSpecial options for the %s port:\n", _ports[i]->target);
465 printOptions (_ports[i]->poptions);
472 /*-----------------------------------------------------------------*/
473 /* parseWithComma - separates string with comma */
474 /*-----------------------------------------------------------------*/
476 parseWithComma (char **dest, char *src)
480 strtok (src, "\r\n \t");
481 /* skip the initial white spaces */
482 while (isspace (*src))
499 /*-----------------------------------------------------------------*/
500 /* setParseWithComma - separates string with comma to a set */
501 /*-----------------------------------------------------------------*/
503 setParseWithComma (set **dest, char *src)
507 /* skip the initial white spaces */
508 while (isspace (*src))
511 if ((p = strtok(src, ",")) != NULL) {
515 } while ((p = strtok(NULL, ",")) != NULL);
519 /*-----------------------------------------------------------------*/
520 /* setDefaultOptions - sets the default options */
521 /*-----------------------------------------------------------------*/
527 for (i = 0; i < 128; i++)
528 preArgv[i] = /*linkOptions[i] = */relFiles[i] = libFiles[i] = libPaths[i] = NULL;
530 /* first the options part */
531 options.stack_loc = 0; /* stack pointer initialised to 0 */
532 options.xstack_loc = 0; /* xternal stack starts at 0 */
533 options.code_loc = 0; /* code starts at 0 */
534 options.data_loc = 0; /* JCF: By default let the linker locate data */
535 options.xdata_loc = 0;
536 options.idata_loc = 0x80;
538 options.model = port->general.default_model;
539 options.nostdlib = 0;
540 options.nostdinc = 0;
542 options.shortis8bits = 0;
544 options.stack10bit=0;
546 /* now for the optimizations */
547 /* turn on the everything */
548 optimize.global_cse = 1;
553 optimize.loopInvariant = 1;
554 optimize.loopInduction = 1;
556 /* now for the ports */
557 port->setDefaultOptions ();
560 /*-----------------------------------------------------------------*/
561 /* processFile - determines the type of file from the extension */
562 /*-----------------------------------------------------------------*/
564 processFile (char *s)
568 /* get the file extension */
569 fext = s + strlen (s);
570 while ((fext != s) && *fext != '.')
573 /* now if no '.' then we don't know what the file type is
574 so give a warning and return */
577 werror (W_UNKNOWN_FEXT, s);
581 /* otherwise depending on the file type */
582 if (strcmp (fext, ".c") == 0 || strcmp (fext, ".C") == 0)
584 /* source file name : not if we already have a
588 werror (W_TOO_MANY_SRC, s);
592 /* the only source file */
594 if (!(srcFile = fopen (fullSrcFileName, "r")))
596 werror (E_FILE_OPEN_ERR, s);
600 /* copy the file name into the buffer */
601 strncpyz (buffer, s, sizeof(buffer));
603 /* get rid of the "."-extension */
605 /* is there a dot at all? */
606 if (strrchr (buffer, '.') &&
607 /* is the dot in the filename, not in the path? */
608 (strrchr (buffer, DIR_SEPARATOR_CHAR) < strrchr (buffer, '.')))
610 *strrchr (buffer, '.') = '\0';
613 /* get rid of any path information
614 for the module name; */
615 fext = buffer + strlen (buffer);
617 /* do this by going backwards till we
618 get '\' or ':' or start of buffer */
619 while (fext != buffer &&
620 *(fext - 1) != DIR_SEPARATOR_CHAR &&
626 /* do this by going backwards till we
627 get '/' or start of buffer */
628 while (fext != buffer &&
629 *(fext - 1) != DIR_SEPARATOR_CHAR)
634 moduleName = Safe_strdup ( fext );
638 /* if the extention is type .rel or .r or .REL or .R
639 addtional object file will be passed to the linker */
640 if (strcmp (fext, ".r") == 0 || strcmp (fext, ".rel") == 0 ||
641 strcmp (fext, ".R") == 0 || strcmp (fext, ".REL") == 0 ||
642 strcmp (fext, port->linker.rel_ext) == 0)
644 relFiles[nrelFiles++] = s;
648 /* if .lib or .LIB */
649 if (strcmp (fext, ".lib") == 0 || strcmp (fext, ".LIB") == 0)
651 libFiles[nlibFiles++] = s;
655 werror (W_UNKNOWN_FEXT, s);
660 _setModel (int model, const char *sz)
662 if (port->general.supported_models & model)
663 options.model = model;
665 werror (W_UNSUPPORTED_MODEL, sz, port->target);
668 /** Gets the string argument to this option. If the option is '--opt'
669 then for input of '--optxyz' or '--opt xyz' returns xyz.
672 getStringArg(const char *szStart, char **argv, int *pi, int argc)
674 if (argv[*pi][strlen(szStart)])
676 return &argv[*pi][strlen(szStart)];
683 werror (E_ARGUMENT_MISSING, szStart);
684 /* Die here rather than checking for errors later. */
694 /** Gets the integer argument to this option using the same rules as
698 getIntArg(const char *szStart, char **argv, int *pi, int argc)
700 return (int)floatFromVal(constVal(getStringArg(szStart, argv, pi, argc)));
704 verifyShortOption(const char *opt)
706 if (strlen(opt) != 2)
708 werror (W_EXCESS_SHORT_OPTIONS, opt);
713 tryHandleUnsupportedOpt(char **argv, int *pi)
715 if (argv[*pi][0] == '-')
717 const char *longOpt = "";
721 if (argv[*pi][1] == '-')
728 shortOpt = argv[*pi][1];
730 for (i = 0; i < LENGTH(unsupportedOptTable); i++)
732 if (unsupportedOptTable[i].shortOpt == shortOpt ||
733 (longOpt && unsupportedOptTable[i].longOpt && !strcmp(unsupportedOptTable[i].longOpt, longOpt))) {
734 // Found an unsupported opt.
736 SNPRINTF(buffer, sizeof(buffer),
738 longOpt ? longOpt : "",
739 shortOpt ? '-' : ' ', shortOpt ? shortOpt : ' ');
740 werror (W_UNSUPP_OPTION, buffer, unsupportedOptTable[i].message);
744 // Didn't find in the table
749 // Not an option, so can't be unsupported :)
755 scanOptionsTable(const OPTION *optionsTable, char shortOpt, const char *longOpt, char **argv, int *pi)
758 for (i = 0; optionsTable[i].shortOpt != 0 || optionsTable[i].longOpt != NULL; i++)
760 if (optionsTable[i].shortOpt == shortOpt ||
761 (longOpt && optionsTable[i].longOpt &&
762 strcmp(optionsTable[i].longOpt, longOpt) == 0))
765 // If it is a flag then we can handle it here
766 if (optionsTable[i].pparameter != NULL)
768 if (optionsTable[i].shortOpt == shortOpt)
770 verifyShortOption(argv[*pi]);
773 (*optionsTable[i].pparameter)++;
777 // Not a flag. Handled manually later.
782 // Didn't find in the table
787 tryHandleSimpleOpt(char **argv, int *pi)
789 if (argv[*pi][0] == '-')
791 const char *longOpt = "";
794 if (argv[*pi][1] == '-')
801 shortOpt = argv[*pi][1];
804 if (scanOptionsTable(optionsTable, shortOpt, longOpt, argv, pi))
808 else if (port && port->poptions &&
809 scanOptionsTable(port->poptions, shortOpt, longOpt, argv, pi))
820 // Not an option, so can't be handled.
825 /*-----------------------------------------------------------------*/
826 /* parseCmdLine - parses the command line and sets the options */
827 /*-----------------------------------------------------------------*/
829 parseCmdLine (int argc, char **argv)
833 /* go thru all whole command line */
834 for (i = 1; i < argc; i++)
839 if (tryHandleUnsupportedOpt(argv, &i) == TRUE)
844 if (tryHandleSimpleOpt(argv, &i) == TRUE)
850 if (argv[i][0] == '-' && argv[i][1] == '-')
852 if (strcmp (argv[i], OPTION_HELP) == 0)
858 if (strcmp (argv[i], OPTION_STACK_8BIT) == 0)
860 options.stack10bit = 0;
864 if (strcmp (argv[i], OPTION_OUT_FMT_IHX) == 0)
870 if (strcmp (argv[i], OPTION_LARGE_MODEL) == 0)
872 _setModel (MODEL_LARGE, argv[i]);
876 if (strcmp (argv[i], OPTION_MEDIUM_MODEL) == 0)
878 _setModel (MODEL_MEDIUM, argv[i]);
882 if (strcmp (argv[i], OPTION_SMALL_MODEL) == 0)
884 _setModel (MODEL_SMALL, argv[i]);
888 if (strcmp (argv[i], OPTION_FLAT24_MODEL) == 0)
890 _setModel (MODEL_FLAT24, argv[i]);
894 if (strcmp (argv[i], OPTION_DUMP_ALL) == 0)
896 options.dump_rassgn =
902 options.dump_raw = 1;
906 if (strcmp (argv[i], OPTION_PEEP_FILE) == 0)
908 options.peep_file = getStringArg(OPTION_PEEP_FILE, argv, &i, argc);
912 if (strcmp (argv[i], OPTION_LIB_PATH) == 0)
914 libPaths[nlibPaths++] = getStringArg(OPTION_LIB_PATH, argv, &i, argc);
918 if (strcmp (argv[i], OPTION_VERSION) == 0)
925 if (strcmp (argv[i], OPTION_CALLEE_SAVES) == 0)
927 parseWithComma (options.calleeSaves, getStringArg(OPTION_CALLEE_SAVES, argv, &i, argc));
931 if (strcmp (argv[i], OPTION_XSTACK_LOC) == 0)
933 options.xstack_loc = getIntArg(OPTION_XSTACK_LOC, argv, &i, argc);
937 if (strcmp (argv[i], OPTION_STACK_LOC) == 0)
939 options.stack_loc = getIntArg(OPTION_STACK_LOC, argv, &i, argc);
943 if (strcmp (argv[i], OPTION_XRAM_LOC) == 0)
945 options.xdata_loc = getIntArg(OPTION_XRAM_LOC, argv, &i, argc);
949 if (strcmp (argv[i], OPTION_IRAM_SIZE) == 0)
951 options.iram_size = getIntArg(OPTION_IRAM_SIZE, argv, &i, argc);
955 if (strcmp (argv[i], OPTION_XRAM_SIZE) == 0)
957 options.xram_size = getIntArg(OPTION_IRAM_SIZE, argv, &i, argc);
958 options.xram_size_set = TRUE;
962 if (strcmp (argv[i], OPTION_CODE_SIZE) == 0)
964 options.code_size = getIntArg(OPTION_IRAM_SIZE, argv, &i, argc);
968 if (strcmp (argv[i], OPTION_DATA_LOC) == 0)
970 options.data_loc = getIntArg(OPTION_DATA_LOC, argv, &i, argc);
974 if (strcmp (argv[i], OPTION_IDATA_LOC) == 0)
976 options.idata_loc = getIntArg(OPTION_IDATA_LOC, argv, &i, argc);
980 if (strcmp (argv[i], OPTION_CODE_LOC) == 0)
982 options.code_loc = getIntArg(OPTION_CODE_LOC, argv, &i, argc);
986 if (strcmp (argv[i], OPTION_NO_GCSE) == 0)
988 optimize.global_cse = 0;
992 if (strcmp (argv[i], OPTION_NO_LOOP_INV) == 0)
994 optimize.loopInvariant = 0;
998 if (strcmp (argv[i], OPTION_NO_LABEL_OPT) == 0)
1000 optimize.label4 = 0;
1004 if (strcmp (argv[i], OPTION_NO_LOOP_IND) == 0)
1006 optimize.loopInduction = 0;
1010 if (strcmp (argv[i], OPTION_LESS_PEDANTIC) == 0)
1012 options.lessPedantic = 1;
1013 setErrorLogLevel(ERROR_LEVEL_WARNING);
1017 if (strcmp (&argv[i][1], OPTION_SHORT_IS_8BITS) == 0)
1019 options.shortis8bits=1;
1023 if (strcmp (argv[i], OPTION_TINI_LIBID) == 0)
1025 options.tini_libid = getIntArg(OPTION_TINI_LIBID, argv, &i, argc);
1029 if (!port->parseOption (&argc, argv, &i))
1031 werror (W_UNKNOWN_OPTION, argv[i]);
1039 /* if preceded by '-' then option */
1040 if (*argv[i] == '-')
1045 verifyShortOption(argv[i]);
1052 /* Used to select the port. But this has already been done. */
1056 /* Used to select the processor in port. But this has
1057 * already been done. */
1061 verifyShortOption(argv[i]);
1063 options.cc_only = 1;
1067 libPaths[nlibPaths++] = getStringArg("-L", argv, &i, argc);
1071 libFiles[nlibFiles++] = getStringArg("-l", argv, &i, argc);
1078 /* copy the file name into the buffer */
1079 strncpyz(buffer, getStringArg("-o", argv, &i, argc),
1081 /* point to last character */
1082 p = buffer + strlen (buffer) - 1;
1083 if (*p == DIR_SEPARATOR_CHAR)
1085 /* only output path specified */
1086 dstPath = Safe_strdup (buffer);
1087 fullDstFileName = NULL;
1091 fullDstFileName = Safe_strdup (buffer);
1093 /* get rid of the "."-extension */
1095 /* is there a dot at all? */
1096 if (strrchr (buffer, '.') &&
1097 /* is the dot in the filename, not in the path? */
1098 (strrchr (buffer, DIR_SEPARATOR_CHAR) < strrchr (buffer, '.')))
1099 *strrchr (buffer, '.') = '\0';
1101 dstFileName = Safe_strdup (buffer);
1103 /* strip module name to get path */
1104 p = strrchr (buffer, DIR_SEPARATOR_CHAR);
1107 /* path with trailing / */
1109 dstPath = Safe_strdup (buffer);
1116 /* pre-processer options */
1117 if (argv[i][2] == 'p')
1119 parseWithComma ((char **)preArgv, getStringArg("-Wp", argv, &i, argc));
1121 /* linker options */
1122 else if (argv[i][2] == 'l')
1124 setParseWithComma(&linkOptions, getStringArg("-Wl", argv, &i, argc));
1126 /* assembler options */
1127 else if (argv[i][2] == 'a')
1129 setParseWithComma (&asmOptions, getStringArg("-Wa", argv, &i, argc));
1133 werror (W_UNKNOWN_OPTION, argv[i]);
1138 verifyShortOption(argv[i]);
1140 printVersionInfo ();
1144 /* preprocessor options */
1148 addToList (preArgv, "-M");
1153 addToList (preArgv, "-C");
1163 char sOpt = argv[i][1];
1166 if (argv[i][2] == ' ' || argv[i][2] == '\0')
1172 werror(E_ARGUMENT_MISSING, argv[i-1]);
1186 SNPRINTF (buffer, sizeof(buffer),
1187 ((sOpt == 'I') ? "-%c\"%s\"": "-%c%s"), sOpt, rest);
1188 addToList (preArgv, buffer);
1193 if (!port->parseOption (&argc, argv, &i))
1194 werror (W_UNKNOWN_OPTION, argv[i]);
1199 if (!port->parseOption (&argc, argv, &i))
1201 /* no option must be a filename */
1204 werror (W_NO_FILE_ARG_IN_C1, argv[i]);
1208 processFile (argv[i]);
1213 /* some sanity checks in c1 mode */
1218 if (fullSrcFileName)
1221 werror (W_NO_FILE_ARG_IN_C1, fullSrcFileName);
1223 fullSrcFileName = NULL;
1224 for (i = 0; i < nrelFiles; ++i)
1226 werror (W_NO_FILE_ARG_IN_C1, relFiles[i]);
1228 for (i = 0; i < nlibFiles; ++i)
1230 werror (W_NO_FILE_ARG_IN_C1, libFiles[i]);
1232 nrelFiles = nlibFiles = 0;
1233 if (options.cc_only || noAssemble || preProcOnly)
1235 werror (W_ILLEGAL_OPT_COMBINATION);
1237 options.cc_only = noAssemble = preProcOnly = 0;
1240 werror (E_NEED_OPT_O_IN_C1);
1244 /* if no dstFileName given with -o, we've to find one: */
1247 /* use the modulename from the C-source */
1248 if (fullSrcFileName)
1250 size_t bufSize = strlen (dstPath) + strlen (moduleName) + 1;
1252 dstFileName = Safe_alloc (bufSize);
1253 strncpyz (dstFileName, dstPath, bufSize);
1254 strncatz (dstFileName, moduleName, bufSize);
1256 /* use the modulename from the first object file */
1257 else if (nrelFiles >= 1)
1262 strncpyz (buffer, relFiles[0], sizeof(buffer));
1263 /* remove extension (it must be .rel) */
1264 *strrchr (buffer, '.') = '\0';
1266 objectName = strrchr (buffer, DIR_SEPARATOR_CHAR);
1273 objectName = buffer;
1275 bufSize = strlen (dstPath) + strlen (objectName) + 1;
1276 dstFileName = Safe_alloc (bufSize);
1277 strncpyz (dstFileName, dstPath, bufSize);
1278 strncatz (dstFileName, objectName, bufSize);
1280 /* else no module given: help text is displayed */
1283 /* set up external stack location if not explicitly specified */
1284 if (!options.xstack_loc)
1285 options.xstack_loc = options.xdata_loc;
1287 /* if debug option is set then open the cdbFile */
1288 if (options.debug && fullSrcFileName)
1290 SNPRINTF (scratchFileName, sizeof(scratchFileName),
1291 "%s.adb", dstFileName); //JCF: Nov 30, 2002
1292 if(debugFile->openFile(scratchFileName))
1293 debugFile->writeModule(moduleName);
1295 werror (E_FILE_OPEN_ERR, scratchFileName);
1300 /*-----------------------------------------------------------------*/
1301 /* linkEdit : - calls the linkage editor with options */
1302 /*-----------------------------------------------------------------*/
1304 linkEdit (char **envp)
1310 /* first we need to create the <filename>.lnk file */
1311 SNPRINTF (scratchFileName, sizeof(scratchFileName),
1312 "%s.lnk", dstFileName);
1313 if (!(lnkfile = fopen (scratchFileName, "w")))
1315 werror (E_FILE_OPEN_ERR, scratchFileName);
1319 /* now write the options. JCF: added option 'y' */
1320 fprintf (lnkfile, "-myux%c\n", (options.out_fmt ? 's' : 'i'));
1322 /* if iram size specified */
1323 if (options.iram_size)
1324 fprintf (lnkfile, "-a 0x%04x\n", options.iram_size);
1326 /* if xram size specified */
1327 if (options.xram_size_set)
1328 fprintf (lnkfile, "-v 0x%04x\n", options.xram_size);
1330 /* if code size specified */
1331 if (options.code_size)
1332 fprintf (lnkfile, "-w 0x%04x\n", options.code_size);
1335 fprintf (lnkfile, "-z\n");
1337 #define WRITE_SEG_LOC(N, L) \
1338 segName = Safe_strdup(N); \
1339 c = strtok(segName, " \t"); \
1340 fprintf (lnkfile,"-b %s = 0x%04x\n", c, L); \
1341 if (segName) { Safe_free(segName); }
1343 /* code segment start */
1344 WRITE_SEG_LOC (CODE_NAME, options.code_loc);
1346 /* data segment start */
1347 if(options.data_loc){ /*JCF: If zero, the linker chooses the best place for data*/
1348 WRITE_SEG_LOC (DATA_NAME, options.data_loc);
1352 WRITE_SEG_LOC (XDATA_NAME, options.xdata_loc);
1356 WRITE_SEG_LOC (IDATA_NAME, options.idata_loc);
1359 /* bit segment start */
1360 WRITE_SEG_LOC (BIT_NAME, 0);
1362 /* JCF: stack start */
1363 if ( (options.stack_loc) && (options.stack_loc<0x100) ) {
1364 WRITE_SEG_LOC ("SSEG", options.stack_loc);
1367 /* add the extra linker options */
1368 for (i = 0; i<elementsInSet(linkOptions); i++)
1369 fprintf (lnkfile, "%s\n", (char *)indexSet(linkOptions, i));
1371 /* other library paths if specified */
1372 for (i = 0; i < nlibPaths; i++)
1373 fprintf (lnkfile, "-k %s\n", libPaths[i]);
1375 /* standard library path */
1376 if (!options.nostdlib)
1378 switch (options.model)
1388 if (TARGET_IS_DS390)
1392 else if (TARGET_IS_DS400)
1399 "Add support for your FLAT24 target in %s @ line %d\n",
1400 __FILE__, __LINE__);
1408 werror (W_UNKNOWN_MODEL, __FILE__, __LINE__);
1412 mfprintf (lnkfile, getRuntimeVariables(), "-k {libdir}{sep}%s\n", c);
1414 /* standard library files */
1415 #if !OPT_DISABLE_DS390
1416 if (options.model == MODEL_FLAT24)
1418 if (TARGET_IS_DS390)
1420 fprintf (lnkfile, "-l %s\n", STD_DS390_LIB);
1422 else if (TARGET_IS_DS400)
1424 fprintf (lnkfile, "-l %s\n", STD_DS400_LIB);
1429 "Add support for your FLAT24 target in %s @ line %d\n",
1430 __FILE__, __LINE__);
1436 #if !OPT_DISABLE_XA51
1438 if (options.model == MODEL_PAGE0)
1440 fprintf (lnkfile, "-l %s\n", STD_XA51_LIB);
1444 fprintf (lnkfile, "-l %s\n", STD_LIB);
1445 fprintf (lnkfile, "-l %s\n", STD_INT_LIB);
1446 fprintf (lnkfile, "-l %s\n", STD_LONG_LIB);
1447 fprintf (lnkfile, "-l %s\n", STD_FP_LIB);
1450 /* additional libraries if any */
1451 for (i = 0; i < nlibFiles; i++)
1452 fprintf (lnkfile, "-l %s\n", libFiles[i]);
1454 /* put in the object files */
1455 if (fullSrcFileName)
1456 fprintf (lnkfile, "%s ", dstFileName);
1458 for (i = 0; i < nrelFiles; i++)
1459 fprintf (lnkfile, "%s\n", relFiles[i]);
1461 fprintf (lnkfile, "\n-e\n");
1464 if (options.verbose)
1465 printf ("sdcc: Calling linker...\n");
1467 /* build linker output filename */
1469 /* -o option overrides default name? */
1470 if (fullDstFileName)
1472 strncpyz (scratchFileName, fullDstFileName, sizeof(scratchFileName));
1476 /* the linked file gets the name of the first modul */
1477 if (fullSrcFileName)
1479 strncpyz (scratchFileName, dstFileName, sizeof(scratchFileName));
1483 strncpyz (scratchFileName, relFiles[0], sizeof(scratchFileName));
1484 /* strip ".rel" extension */
1485 *strrchr (scratchFileName, '.') = '\0';
1487 strncatz (scratchFileName,
1488 options.out_fmt ? ".S19" : ".ihx",
1489 sizeof(scratchFileName));
1492 if (port->linker.cmd)
1494 char buffer2[PATH_MAX];
1496 /* VR 030517 - gplink needs linker options to set the linker script,*/
1497 buildCmdLine (buffer2, port->linker.cmd, dstFileName, scratchFileName, NULL, linkOptions);
1499 buildCmdLine2 (buffer, buffer2, sizeof(buffer));
1503 buildCmdLine2 (buffer, port->linker.mcmd, sizeof(buffer));
1506 // if (options.verbose)fprintf(stderr, "linker command line: %s\n", buffer);
1508 system_ret = my_system (buffer);
1509 /* TODO: most linker don't have a -o parameter */
1510 /* -o option overrides default name? */
1511 if (fullDstFileName)
1514 /* the linked file gets the name of the first modul */
1515 if (fullSrcFileName)
1517 strncpyz (scratchFileName, dstFileName, sizeof(scratchFileName));
1518 p = strlen (scratchFileName) + scratchFileName;
1522 strncpyz (scratchFileName, relFiles[0], sizeof(scratchFileName));
1523 /* strip ".rel" extension */
1524 p = strrchr (scratchFileName, '.');
1530 strncatz (scratchFileName,
1531 options.out_fmt ? ".S19" : ".ihx",
1532 sizeof(scratchFileName));
1533 rename (scratchFileName, fullDstFileName);
1535 strncpyz (buffer, fullDstFileName, sizeof(buffer));
1536 q = strrchr (buffer, '.');
1539 /* no extension: append new extensions */
1540 q = strlen (buffer) + buffer;
1544 strncatz (scratchFileName, ".map", sizeof(scratchFileName));
1546 strncatz(buffer, ".map", sizeof(buffer));
1547 rename (scratchFileName, buffer);
1549 strncatz (scratchFileName, ".mem", sizeof(scratchFileName));
1551 strncatz(buffer, ".mem", sizeof(buffer));
1552 rename (scratchFileName, buffer);
1560 /*-----------------------------------------------------------------*/
1561 /* assemble - spawns the assembler with arguments */
1562 /*-----------------------------------------------------------------*/
1564 assemble (char **envp)
1566 /* build assembler output filename */
1568 /* -o option overrides default name? */
1569 if (options.cc_only && fullDstFileName) {
1570 strncpyz (scratchFileName, fullDstFileName, sizeof(scratchFileName));
1572 /* the assembled file gets the name of the first modul */
1573 strncpyz (scratchFileName, dstFileName, sizeof(scratchFileName));
1574 strncatz (scratchFileName, port->linker.rel_ext,
1575 sizeof(scratchFileName));
1578 if (port->assembler.do_assemble) {
1579 port->assembler.do_assemble(asmOptions);
1581 } else if (port->assembler.cmd) {
1582 buildCmdLine (buffer, port->assembler.cmd, dstFileName, scratchFileName,
1583 options.debug ? port->assembler.debug_opts : port->assembler.plain_opts,
1586 buildCmdLine2 (buffer, port->assembler.mcmd, sizeof(buffer));
1589 if (my_system (buffer)) {
1590 /* either system() or the assembler itself has reported an error
1591 perror ("Cannot exec assembler");
1595 /* TODO: most assembler don't have a -o parameter */
1596 /* -o option overrides default name? */
1597 if (options.cc_only && fullDstFileName) {
1598 strncpyz (scratchFileName, dstFileName, sizeof(scratchFileName));
1599 strncatz (scratchFileName,
1600 port->linker.rel_ext,
1601 sizeof(scratchFileName));
1602 rename (scratchFileName, fullDstFileName);
1606 /*-----------------------------------------------------------------*/
1607 /* preProcess - spawns the preprocessor with arguments */
1608 /*-----------------------------------------------------------------*/
1610 preProcess (char **envp)
1618 /* if using external stack define the macro */
1619 if (options.useXstack)
1620 addToList (preArgv, "-DSDCC_USE_XSTACK");
1622 /* set the macro for stack autos */
1623 if (options.stackAuto)
1624 addToList (preArgv, "-DSDCC_STACK_AUTO");
1626 /* set the macro for stack autos */
1627 if (options.stack10bit)
1628 addToList (preArgv, "-DSDCC_STACK_TENBIT");
1630 /* set the macro for no overlay */
1631 if (options.noOverlay)
1632 addToList (preArgv, "-DSDCC_NOOVERLAY");
1634 /* set the macro for large model */
1635 switch (options.model)
1638 addToList (preArgv, "-DSDCC_MODEL_LARGE");
1641 addToList (preArgv, "-DSDCC_MODEL_SMALL");
1644 addToList (preArgv, "-DSDCC_MODEL_COMPACT");
1647 addToList (preArgv, "-DSDCC_MODEL_MEDIUM");
1650 addToList (preArgv, "-DSDCC_MODEL_FLAT24");
1653 addToList (preArgv, "-DSDCC_MODEL_PAGE0");
1656 werror (W_UNKNOWN_MODEL, __FILE__, __LINE__);
1660 /* add port (processor information to processor */
1661 addToList (preArgv, "-DSDCC_{port}");
1662 addToList (preArgv, "-D__{port}");
1664 /* standard include path */
1665 if (!options.nostdinc) {
1666 addToList (preArgv, "-I\"{includedir}\"");
1669 setMainValue ("cppextraopts", join(preArgv));
1671 if (preProcOnly && fullDstFileName)
1673 /* -E and -o given */
1674 setMainValue ("cppoutfilename", fullDstFileName);
1678 /* Piping: set cppoutfilename to NULL, to avoid empty quotes */
1679 setMainValue ("cppoutfilename", NULL);
1682 if (options.verbose)
1683 printf ("sdcc: Calling preprocessor...\n");
1685 buildCmdLine2 (buffer, _preCmd, sizeof(buffer));
1688 if (my_system (buffer)) {
1695 yyin = my_popen (buffer);
1697 perror ("Preproc file not found");
1700 addSetHead (&pipeSet, yyin);
1708 setBinPaths(const char *argv0)
1716 * 1. - $SDCCDIR/PREFIX2BIN_DIR
1717 * 2. - path(argv[0])
1721 /* do it in reverse mode, so that addSetHead() can be used
1722 instead of slower addSet() */
1724 if ((p = getBinPath(argv0)) != NULL)
1725 addSetHead(&binPathSet, Safe_strdup(p));
1727 if ((p = getenv(SDCC_DIR_NAME)) != NULL) {
1728 SNPRINTF(buf, sizeof buf, "%s" PREFIX2BIN_DIR, p);
1729 addSetHead(&binPathSet, Safe_strdup(buf));
1732 if (options.printSearchDirs) {
1733 printf("programs: ");
1734 if (NULL != (p = (char *)setFirstItem(binPathSet))) {
1736 while (NULL != (p = (char *)setNextItem(binPathSet)))
1743 /* Set system include path */
1745 setIncludePath(const char *datadir)
1753 * 1. - $SDCC_INCLUDE
1754 * 2. - $SDCC_HOME/PREFIX2DATA_DIR/INCLUDE_DIR_SUFFIX
1755 * 3. - path(argv[0])/BIN2DATA_DIR/INCLUDE_DIR_SUFFIX
1756 * 4. - DATADIR/INCLUDE_DIR_SUFFIX (only on *nix)
1759 if ((p = getenv(SDCC_INCLUDE_NAME)) == NULL) {
1760 SNPRINTF(buf, sizeof buf, "%s" INCLUDE_DIR_SUFFIX, datadir);
1764 if (options.printSearchDirs)
1765 printf("includedir: %s\n", p);
1767 setMainValue ("includedir", p);
1770 /* Set system lib path */
1772 setLibPath(const char *datadir)
1781 * 2. - $SDCC_HOME/PREFIX2DATA_DIR/LIB_DIR_SUFFIX/<model>
1782 * 3. - path(argv[0])/BIN2DATA_DIR/LIB_DIR_SUFFIX/<model>
1783 * 4. - DATADIR/LIB_DIR_SUFFIX/<model> (only on *nix)
1786 if ((p = getenv(SDCC_LIB_NAME)) == NULL) {
1787 SNPRINTF(buf, sizeof buf, "%s" LIB_DIR_SUFFIX, datadir);
1791 if (options.printSearchDirs)
1792 printf("libdir: %s\n", p);
1794 setMainValue ("libdir", p);
1799 setDataPaths(const char *argv0)
1807 * 1. - $SDCC_HOME/PREFIX2DATA_DIR
1808 * 2. - path(argv[0])/BIN2DATA_DIR
1809 * 3. - DATADIR (only on *nix)
1812 if ((p = getenv(SDCC_DIR_NAME)) != NULL) {
1813 SNPRINTF(buf, sizeof buf, "%s" PREFIX2DATA_DIR, p);
1816 else if ((p = getBinPath(argv0)) != NULL) {
1817 SNPRINTF(buf, sizeof buf, "%s" BIN2DATA_DIR, p);
1822 /* this should never happen... */
1823 wassertl(0, "Can't get binary path");
1828 p = DATADIR; /* last resort */
1831 if (options.printSearchDirs)
1832 printf("datadir: %s\n", p);
1837 setMainValue ("datadir", p);
1843 populateMainValues (_baseValues);
1844 setMainValue ("port", port->target);
1845 setMainValue ("objext", port->linker.rel_ext);
1846 setMainValue ("asmext", port->assembler.file_ext);
1848 setMainValue ("dstfilename", dstFileName);
1849 setMainValue ("fullsrcfilename", fullSrcFileName ? fullSrcFileName : "fullsrcfilename");
1851 if (options.cc_only && fullDstFileName)
1852 /* compile + assemble and -o given: -o specifies name of object file */
1854 setMainValue ("objdstfilename", fullDstFileName);
1858 setMainValue ("objdstfilename", "{stdobjdstfilename}");
1860 if (fullDstFileName)
1861 /* if we're linking, -o gives the final file name */
1863 setMainValue ("linkdstfilename", fullDstFileName);
1867 setMainValue ("linkdstfilename", "{stdlinkdstfilename}");
1873 sig_handler (int signal)
1880 sig_string = "SIGABRT";
1883 sig_string = "SIGTERM";
1886 sig_string = "SIGINT";
1889 sig_string = "SIGSEGV";
1892 sig_string = "Unknown?";
1895 fprintf (stderr, "Caught signal %d: %s\n", signal, sig_string);
1901 * initialises and calls the parser
1905 main (int argc, char **argv, char **envp)
1907 /* turn all optimizations off by default */
1908 memset (&optimize, 0, sizeof (struct optimize));
1910 /*printVersionInfo (); */
1913 fprintf (stderr, "Build error: no ports are enabled.\n");
1917 /* install atexit handler */
1918 atexit(rm_tmpfiles);
1920 /* install signal handler;
1921 it's only purpuse is to call exit() to remove temp files */
1922 if (!getenv("SDCC_LEAVE_SIGNALS"))
1924 signal (SIGABRT, sig_handler);
1925 signal (SIGTERM, sig_handler);
1926 signal (SIGINT , sig_handler);
1927 signal (SIGSEGV, sig_handler);
1930 /* Before parsing the command line options, do a
1931 * search for the port and processor and initialize
1932 * them if they're found. (We can't gurantee that these
1933 * will be the first options specified).
1936 _findPort (argc, argv);
1939 if (strcmp(port->target, "mcs51") == 0) {
1940 printf("DS390 jammed in A\n");
1946 _findProcessor (argc, argv);
1948 /* Initalise the port. */
1952 setDefaultOptions ();
1955 options.model = MODEL_SMALL;
1956 options.stack10bit=0;
1959 parseCmdLine (argc, argv);
1962 setBinPaths(argv[0]);
1963 setDataPaths(argv[0]);
1965 /* if no input then printUsage & exit */
1966 if (!options.c1mode && !fullSrcFileName && !nrelFiles) {
1967 if (!options.printSearchDirs)
1973 /* initMem() is expensive, but
1974 initMem() must called before port->finaliseOptions ().
1975 And the z80 port needs port->finaliseOptions(),
1976 even if we're only linking. */
1978 port->finaliseOptions ();
1980 if (fullSrcFileName || options.c1mode)
1990 if (options.verbose)
1991 printf ("sdcc: Generating code...\n");
1996 deleteSetItem(&pipeSet, yyin);
2002 if (TARGET_IS_PIC) {
2003 /* TSD PIC port hack - if the PIC port option is enabled
2004 and SDCC is used to generate PIC code, then we will
2005 generate .asm files in gpasm's format instead of SDCC's
2008 #if !OPT_DISABLE_PIC
2013 if(TARGET_IS_PIC16) {
2014 /* PIC16 port misc improvements Vangelis Rokas - 6-May-2003
2015 Generate .asm files for gpasm (just like PIC target) but use
2019 #if !OPT_DISABLE_PIC16
2026 if (!options.c1mode && !noAssemble)
2028 if (options.verbose)
2029 printf ("sdcc: Calling assembler...\n");
2035 if (options.debug && debugFile)
2036 debugFile->closeFile();
2038 if (!options.cc_only &&
2042 (fullSrcFileName || nrelFiles))
2044 if (port->linker.do_link)
2045 port->linker.do_link ();