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 (void);
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 int RegBankUsed[4] = {1, 0, 0, 0}; /*JCF: Reg Bank 0 used by default*/
59 struct optimize optimize;
60 struct options options;
63 set *preArgvSet = NULL; /* pre-processor arguments */
64 set *asmOptionsSet = NULL; /* set of assembler options */
65 set *linkOptionsSet = NULL; /* set of linker options */
66 set *libFilesSet = NULL;
67 set *libPathsSet = NULL;
68 set *relFilesSet = NULL;
69 set *dataDirsSet = NULL; /* list of data search directories */
70 set *includeDirsSet = NULL; /* list of include search directories */
71 set *libDirsSet = NULL; /* list of lib search directories */
73 /* uncomment JAMIN_DS390 to always override and use ds390 port
74 for mcs51 work. This is temporary, for compatibility testing. */
75 /* #define JAMIN_DS390 */
80 /* Globally accessible scratch buffer for file names. */
81 char scratchFileName[PATH_MAX];
82 char buffer[PATH_MAX * 2];
84 #define OPTION_HELP "-help"
86 #define LENGTH(_a) (sizeof(_a)/sizeof(*(_a)))
88 #define OPTION_STACK_8BIT "--stack-8bit"
89 #define OPTION_OUT_FMT_IHX "--out-fmt-ihx"
90 #define OPTION_LARGE_MODEL "--model-large"
91 #define OPTION_MEDIUM_MODEL "--model-medium"
92 #define OPTION_SMALL_MODEL "--model-small"
93 #define OPTION_FLAT24_MODEL "--model-flat24"
94 #define OPTION_DUMP_ALL "--dumpall"
95 #define OPTION_PEEP_FILE "--peep-file"
96 #define OPTION_LIB_PATH "--lib-path"
97 #define OPTION_XSTACK_LOC "--xstack-loc"
98 #define OPTION_CALLEE_SAVES "--callee-saves"
99 #define OPTION_STACK_LOC "--stack-loc"
100 #define OPTION_XRAM_LOC "--xram-loc"
101 #define OPTION_IRAM_SIZE "--iram-size"
102 #define OPTION_VERSION "--version"
103 #define OPTION_DATA_LOC "--data-loc"
104 #define OPTION_CODE_LOC "--code-loc"
105 #define OPTION_IDATA_LOC "--idata-loc"
106 #define OPTION_NO_LABEL_OPT "--nolabelopt"
107 #define OPTION_NO_LOOP_INV "--noinvariant"
108 #define OPTION_NO_LOOP_IND "--noinduction"
109 #define OPTION_LESS_PEDANTIC "--less-pedantic"
110 #define OPTION_NO_GCSE "--nogcse"
111 #define OPTION_SHORT_IS_8BITS "--short-is-8bits"
112 #define OPTION_TINI_LIBID "--tini-libid"
113 #define OPTION_NO_XINIT_OPT "--no-xinit-opt"
114 #define OPTION_XRAM_SIZE "--xram-size"
115 #define OPTION_CODE_SIZE "--code-size"
116 #define OPTION_NO_CCODE_IN_ASM "--no-c-code-in-asm"
117 #define OPTION_ICODE_IN_ASM "--i-code-in-asm"
118 #define OPTION_PRINT_SEARCH_DIRS "--print-search-dirs"
119 #define OPTION_MSVC_ERROR_STYLE "--vc"
120 #define OPTION_USE_STDOUT "--use-stdout"
124 { 'm', NULL, NULL, "Set the port to use e.g. -mz80." },
125 { 'p', NULL, NULL, "Select port specific processor e.g. -mpic14 -p16f84" },
126 { 'd', NULL, NULL, NULL },
127 { 'D', NULL, NULL, "Define macro as in -Dmacro" },
128 { 'I', NULL, NULL, "Add to the include (*.h) path, as in -Ipath" },
129 { 'A', NULL, NULL, NULL },
130 { 'U', NULL, NULL, NULL },
131 { 'C', NULL, NULL, "Preprocessor option" },
132 { 'M', NULL, NULL, "Preprocessor option" },
133 { 'V', NULL, &options.verboseExec, "Execute verbosely. Show sub commands as they are run" },
134 { 'S', NULL, &noAssemble, "Compile only; do not assemble or link" },
135 { 'W', NULL, NULL, "Pass through options to the pre-processor (p), assembler (a) or linker (l)" },
136 { 'L', NULL, NULL, "Add the next field to the library search path" },
137 { 'l', NULL, NULL, "Include the given library in the link" },
138 { 0, OPTION_LARGE_MODEL, NULL, "external data space is used" },
139 { 0, OPTION_MEDIUM_MODEL, NULL, "not supported" },
140 { 0, OPTION_SMALL_MODEL, NULL, "internal data space is used (default)" },
141 #if !OPT_DISABLE_DS390
142 { 0, OPTION_FLAT24_MODEL, NULL, "use the flat24 model for the ds390 (default)" },
144 { 0, "--stack-auto", &options.stackAuto, "Stack automatic variables" },
145 #if !OPT_DISABLE_DS390
146 { 0, OPTION_STACK_8BIT, NULL, "use the 8bit stack for the ds390 (not supported yet)" },
147 { 0, "--stack-10bit", &options.stack10bit, "use the 10bit stack for ds390 (default)" },
149 { 0, "--xstack", &options.useXstack, "Use external stack" },
150 { 0, OPTION_NO_GCSE, NULL, "Disable the GCSE optimisation" },
151 { 0, OPTION_NO_LABEL_OPT, NULL, "Disable label optimisation" },
152 { 0, OPTION_NO_LOOP_INV, NULL, "Disable optimisation of invariants" },
153 { 0, OPTION_NO_LOOP_IND, NULL, NULL },
154 { 0, "--nojtbound", &optimize.noJTabBoundary, "Don't generate boundary check for jump tables" },
155 { 0, "--noloopreverse", &optimize.noLoopReverse, "Disable the loop reverse optimisation" },
156 { 'c', "--compile-only", &options.cc_only, "Compile and assemble, but do not link" },
157 { 'o', NULL, NULL, "Place the output into the given path resp. file" },
158 { 0, "--dumpraw", &options.dump_raw, "Dump the internal structure after the initial parse" },
159 { 0, "--dumpgcse", &options.dump_gcse, NULL },
160 { 0, "--dumploop", &options.dump_loop, NULL },
161 { 0, "--dumpdeadcode", &options.dump_kill, NULL },
162 { 0, "--dumpliverange", &options.dump_range, NULL },
163 { 0, "--dumpregpack", &options.dump_pack, NULL },
164 { 0, "--dumpregassign", &options.dump_rassgn, NULL },
165 { 0, "--dumptree", &options.dump_tree, "dump front-end AST before generating iCode" },
166 { 0, OPTION_DUMP_ALL, NULL, "Dump the internal structure at all stages" },
167 { 0, OPTION_XRAM_LOC, NULL, "<nnnn> External Ram start location" },
168 { 0, OPTION_XRAM_SIZE, NULL, "<nnnn> External Ram size" },
169 { 0, OPTION_IRAM_SIZE, NULL, "<nnnn> Internal Ram size" },
170 { 0, OPTION_XSTACK_LOC, NULL, "<nnnn> External Ram start location" },
171 { 0, OPTION_CODE_LOC, NULL, "<nnnn> Code Segment Location" },
172 { 0, OPTION_CODE_SIZE, NULL, "<nnnn> Code Segment size" },
173 { 0, OPTION_STACK_LOC, NULL, "<nnnn> Stack pointer initial value" },
174 { 0, OPTION_DATA_LOC, NULL, "<nnnn> Direct data start location" },
175 { 0, OPTION_IDATA_LOC, NULL, NULL },
176 { 0, OPTION_PEEP_FILE, NULL, "<file> use this extra peep-hole file" },
177 { 0, OPTION_LIB_PATH, NULL, "<path> use this path to search for libraries" },
178 { 0, "--int-long-reent", &options.intlong_rent, "Use reenterant calls on the int and long support functions" },
179 { 0, "--float-reent", &options.float_rent, "Use reenterant calls on the floar support functions" },
180 { 0, OPTION_OUT_FMT_IHX, NULL, NULL },
181 { 0, "--out-fmt-s19", &options.out_fmt, NULL },
182 { 0, "--cyclomatic", &options.cyclomatic, NULL },
183 { 0, "--nooverlay", &options.noOverlay, NULL },
184 { 0, "--main-return", &options.mainreturn, "Issue a return after main()" },
185 { 0, "--xram-movc", &options.xram_movc, "Use movc instead of movx to read xram (xdata)" },
186 { 0, "--no-peep", &options.nopeep, "Disable the peephole assembly file optimisation" },
187 { 0, "--no-reg-params", &options.noRegParams, "On some ports, disable passing some parameters in registers" },
188 { 0, "--peep-asm", &options.asmpeep, NULL },
189 { 0, "--debug", &options.debug, "Enable debugging symbol output" },
190 { 'v', OPTION_VERSION, NULL, "Display sdcc's version" },
191 { 'E', "--preprocessonly", &preProcOnly, "Preprocess only, do not compile" },
192 { 0, "--c1mode", &options.c1mode, "Act in c1 mode. The standard input is preprocessed code, the output is assembly code." },
193 { 0, "--help", NULL, "Display this help" },
194 { 0, OPTION_CALLEE_SAVES, NULL, "<func[,func,...]> Cause the called function to save registers insted of the caller" },
195 { 0, "--nostdlib", &options.nostdlib, "Do not include the standard library directory in the search path" },
196 { 0, "--nostdinc", &options.nostdinc, "Do not include the standard include directory in the search path" },
197 { 0, "--verbose", &options.verbose, "Trace calls to the preprocessor, assembler, and linker" },
198 { 0, OPTION_LESS_PEDANTIC, NULL, "Disable some of the more pedantic warnings" },
199 { 0, OPTION_SHORT_IS_8BITS, NULL, "Make short 8bits (for old times sake)" },
200 { 0, "--profile", &options.profile, "On supported ports, generate extra profiling information" },
201 { 0, "--fommit-frame-pointer", &options.ommitFramePtr, "Leave out the frame pointer." },
202 { 0, "--all-callee-saves", &options.all_callee_saves, "callee will always save registers used" },
203 #if !OPT_DISABLE_DS390
204 { 0, "--use-accelerator", &options.useAccelerator,"generate code for DS390 Arithmetic Accelerator"},
206 { 0, "--stack-probe", &options.stack_probe,"insert call to function __stack_probe at each function prologue"},
207 #if !OPT_DISABLE_TININative
208 { 0, "--tini-libid", NULL,"<nnnn> LibraryID used in -mTININative"},
210 #if !OPT_DISABLE_DS390
211 { 0, "--protect-sp-update", &options.protect_sp_update,"DS390 - will disable interrupts during ESP:SP updates"},
213 #if !OPT_DISABLE_DS390 || !OPT_DISABLE_MCS51
214 { 0, "--parms-in-bank1", &options.parms_in_bank1,"MCS51/DS390 - use Bank1 for parameter passing"},
216 { 0, OPTION_NO_XINIT_OPT, &options.noXinitOpt, "don't memcpy initialized xram from code"},
217 { 0, OPTION_NO_CCODE_IN_ASM, &options.noCcodeInAsm, "don't include c-code as comments in the asm file"},
218 { 0, OPTION_ICODE_IN_ASM, &options.iCodeInAsm, "include i-code as comments in the asm file"},
219 { 0, OPTION_PRINT_SEARCH_DIRS, &options.printSearchDirs, "display the directories in the compiler's search path"},
220 { 0, OPTION_MSVC_ERROR_STYLE, &options.vc_err_style, "messages are compatible with Micro$oft visual studio"},
221 { 0, OPTION_USE_STDOUT, &options.use_stdout, "send errors to stdout instead of stderr"},
223 #if 0 /* 10jun03 !OPT_DISABLE_PIC16 */
224 { 0, "--no-movff", &options.no_movff, "disable generating MOVFF opcode in PIC16 port"},
225 { 0, "--gen-banksel", &options.gen_banksel, "enable the generation of banksel assembler directives in PIC16 port"},
230 /** Table of all unsupported options and help text to display when one
234 /** shortOpt as in OPTIONS. */
236 /** longOpt as in OPTIONS. */
238 /** Message to display inside W_UNSUPPORTED_OPT when this option
243 static const UNSUPPORTEDOPT
244 unsupportedOptTable[] = {
245 { 'X', NULL, "use --xstack-loc instead" },
246 { 'x', NULL, "use --xstack instead" },
247 { 'i', NULL, "use --idata-loc instead" },
248 { 'r', NULL, "use --xdata-loc instead" },
249 { 's', NULL, "use --code-loc instead" },
250 { 'Y', NULL, "use -I instead" }
253 /** List of all default constant macros.
255 static const char *_baseValues[] = {
258 /* Path seperator character */
259 "sep", DIR_SEPARATOR_STRING,
263 static const char *_preCmd = "{cpp} -nostdinc -Wall -std=c99 -DSDCC=1 {cppextraopts} \"{fullsrcfilename}\" \"{cppoutfilename}\"";
267 static PORT *_ports[] =
269 #if !OPT_DISABLE_MCS51
272 #if !OPT_DISABLE_GBZ80
281 #if !OPT_DISABLE_DS390
287 #if !OPT_DISABLE_PIC16
290 #if !OPT_DISABLE_TININative
293 #if !OPT_DISABLE_XA51
296 #if !OPT_DISABLE_DS400
301 #define NUM_PORTS (sizeof(_ports)/sizeof(_ports[0]))
304 extern void picglue ();
306 #if !OPT_DISABLE_PIC16
307 extern void pic16glue();
310 /** Sets the port to the one given by the command line option.
311 @param The name minus the option (eg 'mcs51')
312 @return 0 on success.
315 _setPort (const char *name)
318 for (i = 0; i < NUM_PORTS; i++)
320 if (!strcmp (_ports[i]->target, name))
326 /* Error - didnt find */
327 werror (E_UNKNOWN_TARGET, name);
331 /* Override the default processor with the one specified
332 * on the command line */
334 _setProcessor (char *_processor)
336 port->processor = _processor;
337 fprintf(stderr,"Processor: %s\n",_processor);
341 _validatePorts (void)
344 for (i = 0; i < NUM_PORTS; i++)
346 if (_ports[i]->magic != PORT_MAGIC)
348 /* Uncomment this line to debug which port is causing the problem
349 * (the target name is close to the beginning of the port struct
350 * and probably can be accessed just fine). */
351 fprintf(stderr,"%s :",_ports[i]->target);
352 wassertl (0, "Port definition structure is incomplete");
357 /* search through the command line options for the port */
359 _findPort (int argc, char **argv)
365 if (!strncmp (*argv, "-m", 2))
367 _setPort (*argv + 2);
373 /* Use the first in the list */
374 #if defined(DEFAULT_PORT)
375 /* VR - 13/5/2003 DEFAULT_PORT is defined in port.h */
376 port = &DEFAULT_PORT;
383 /* search through the command line options for the processor */
385 _findProcessor (int argc, char **argv)
389 if (!strncmp (*argv, "-p", 2))
391 _setProcessor (*argv + 2);
397 /* no error if processor was not specified. */
400 /*-----------------------------------------------------------------*/
401 /* printVersionInfo - prints the version info */
402 /*-----------------------------------------------------------------*/
410 for (i = 0; i < NUM_PORTS; i++) {
411 fprintf (stderr, "%s%s", i == 0 ? "" : "/", _ports[i]->target);
413 fprintf(stderr, "%s", (&DEFAULT_PORT == _ports[i])?"*":"");
417 fprintf (stderr, " " SDCC_VERSION_STR
418 #ifdef SDCC_SUB_VERSION_STR
419 "/" SDCC_SUB_VERSION_STR
424 #elif defined __MINGW32__
426 #elif defined __DJGPP__
428 #elif defined(_MSC_VER)
430 #elif defined(__BORLANDC__)
439 printOptions(const OPTION *optionsTable)
442 for (i = 0; optionsTable[i].shortOpt != 0 || optionsTable[i].longOpt != NULL; i++)
444 fprintf(stdout, " %c%c %-20s %s\n",
445 optionsTable[i].shortOpt !=0 ? '-' : ' ',
446 optionsTable[i].shortOpt !=0 ? optionsTable[i].shortOpt : ' ',
447 optionsTable[i].longOpt != NULL ? optionsTable[i].longOpt : "",
448 optionsTable[i].help != NULL ? optionsTable[i].help : ""
453 /*-----------------------------------------------------------------*/
454 /* printUsage - prints command line syntax */
455 /*-----------------------------------------------------------------*/
462 "Usage : sdcc [options] filename\n"
466 printOptions(optionsTable);
468 for (i = 0; i < NUM_PORTS; i++)
470 if (_ports[i]->poptions != NULL)
472 fprintf (stdout, "\nSpecial options for the %s port:\n", _ports[i]->target);
473 printOptions (_ports[i]->poptions);
480 /*-----------------------------------------------------------------*/
481 /* setParseWithComma - separates string with comma to a set */
482 /*-----------------------------------------------------------------*/
484 setParseWithComma (set **dest, char *src)
488 /* skip the initial white spaces */
489 while (isspace(*src))
492 for (p = strtok(src, ","); p != NULL; p = strtok(NULL, ","))
493 addSet(dest, Safe_strdup(p));
496 /*-----------------------------------------------------------------*/
497 /* setDefaultOptions - sets the default options */
498 /*-----------------------------------------------------------------*/
500 setDefaultOptions (void)
502 /* first the options part */
503 options.stack_loc = 0; /* stack pointer initialised to 0 */
504 options.xstack_loc = 0; /* xternal stack starts at 0 */
505 options.code_loc = 0; /* code starts at 0 */
506 options.data_loc = 0; /* JCF: By default let the linker locate data */
507 options.xdata_loc = 0;
508 options.idata_loc = 0x80;
510 options.model = port->general.default_model;
511 options.nostdlib = 0;
512 options.nostdinc = 0;
514 options.shortis8bits = 0;
516 options.stack10bit=0;
518 /* now for the optimizations */
519 /* turn on the everything */
520 optimize.global_cse = 1;
525 optimize.loopInvariant = 1;
526 optimize.loopInduction = 1;
528 /* now for the ports */
529 port->setDefaultOptions ();
532 /*-----------------------------------------------------------------*/
533 /* processFile - determines the type of file from the extension */
534 /*-----------------------------------------------------------------*/
536 processFile (char *s)
540 /* get the file extension */
541 fext = s + strlen (s);
542 while ((fext != s) && *fext != '.')
545 /* now if no '.' then we don't know what the file type is
546 so give a warning and return */
549 werror (W_UNKNOWN_FEXT, s);
553 /* otherwise depending on the file type */
554 if (strcmp (fext, ".c") == 0 || strcmp (fext, ".C") == 0)
556 /* source file name : not if we already have a
560 werror (W_TOO_MANY_SRC, s);
564 /* the only source file */
566 if (!(srcFile = fopen (fullSrcFileName, "r")))
568 werror (E_FILE_OPEN_ERR, s);
572 /* copy the file name into the buffer */
573 strncpyz (buffer, s, sizeof(buffer));
575 /* get rid of the "."-extension */
577 /* is there a dot at all? */
578 if (strrchr (buffer, '.') &&
579 /* is the dot in the filename, not in the path? */
580 (strrchr (buffer, DIR_SEPARATOR_CHAR) < strrchr (buffer, '.')))
582 *strrchr (buffer, '.') = '\0';
585 /* get rid of any path information
586 for the module name; */
587 fext = buffer + strlen (buffer);
589 /* do this by going backwards till we
590 get '\' or ':' or start of buffer */
591 while (fext != buffer &&
592 *(fext - 1) != DIR_SEPARATOR_CHAR &&
598 /* do this by going backwards till we
599 get '/' or start of buffer */
600 while (fext != buffer &&
601 *(fext - 1) != DIR_SEPARATOR_CHAR)
606 moduleName = Safe_strdup ( fext );
610 /* if the extention is type .rel or .r or .REL or .R
611 addtional object file will be passed to the linker */
612 if (strcmp (fext, ".r") == 0 || strcmp (fext, ".rel") == 0 ||
613 strcmp (fext, ".R") == 0 || strcmp (fext, ".REL") == 0 ||
614 strcmp (fext, port->linker.rel_ext) == 0)
616 addSet(&relFilesSet, Safe_strdup(s));
620 /* if .lib or .LIB */
621 if (strcmp (fext, ".lib") == 0 || strcmp (fext, ".LIB") == 0)
623 addSet(&libFilesSet, Safe_strdup(s));
627 werror (W_UNKNOWN_FEXT, s);
632 _setModel (int model, const char *sz)
634 if (port->general.supported_models & model)
635 options.model = model;
637 werror (W_UNSUPPORTED_MODEL, sz, port->target);
640 /** Gets the string argument to this option. If the option is '--opt'
641 then for input of '--optxyz' or '--opt xyz' returns xyz.
644 getStringArg(const char *szStart, char **argv, int *pi, int argc)
646 if (argv[*pi][strlen(szStart)])
648 return &argv[*pi][strlen(szStart)];
655 werror (E_ARGUMENT_MISSING, szStart);
656 /* Die here rather than checking for errors later. */
666 /** Gets the integer argument to this option using the same rules as
670 getIntArg(const char *szStart, char **argv, int *pi, int argc)
672 return (int)floatFromVal(constVal(getStringArg(szStart, argv, pi, argc)));
676 verifyShortOption(const char *opt)
678 if (strlen(opt) != 2)
680 werror (W_EXCESS_SHORT_OPTIONS, opt);
685 tryHandleUnsupportedOpt(char **argv, int *pi)
687 if (argv[*pi][0] == '-')
689 const char *longOpt = "";
693 if (argv[*pi][1] == '-')
700 shortOpt = argv[*pi][1];
702 for (i = 0; i < LENGTH(unsupportedOptTable); i++)
704 if (unsupportedOptTable[i].shortOpt == shortOpt ||
705 (longOpt && unsupportedOptTable[i].longOpt && !strcmp(unsupportedOptTable[i].longOpt, longOpt))) {
706 /* Found an unsupported opt. */
708 SNPRINTF(buffer, sizeof(buffer),
710 longOpt ? longOpt : "",
711 shortOpt ? '-' : ' ', shortOpt ? shortOpt : ' ');
712 werror (W_UNSUPP_OPTION, buffer, unsupportedOptTable[i].message);
716 /* Didn't find in the table */
721 /* Not an option, so can't be unsupported :) */
727 scanOptionsTable(const OPTION *optionsTable, char shortOpt, const char *longOpt, char **argv, int *pi)
730 for (i = 0; optionsTable[i].shortOpt != 0 || optionsTable[i].longOpt != NULL; i++)
732 if (optionsTable[i].shortOpt == shortOpt ||
733 (longOpt && optionsTable[i].longOpt &&
734 strcmp(optionsTable[i].longOpt, longOpt) == 0))
737 /* If it is a flag then we can handle it here */
738 if (optionsTable[i].pparameter != NULL)
740 if (optionsTable[i].shortOpt == shortOpt)
742 verifyShortOption(argv[*pi]);
745 (*optionsTable[i].pparameter)++;
749 /* Not a flag. Handled manually later. */
754 /* Didn't find in the table */
759 tryHandleSimpleOpt(char **argv, int *pi)
761 if (argv[*pi][0] == '-')
763 const char *longOpt = "";
766 if (argv[*pi][1] == '-')
773 shortOpt = argv[*pi][1];
776 if (scanOptionsTable(optionsTable, shortOpt, longOpt, argv, pi))
780 else if (port && port->poptions &&
781 scanOptionsTable(port->poptions, shortOpt, longOpt, argv, pi))
792 /* Not an option, so can't be handled. */
797 /*-----------------------------------------------------------------*/
798 /* parseCmdLine - parses the command line and sets the options */
799 /*-----------------------------------------------------------------*/
801 parseCmdLine (int argc, char **argv)
805 /* go thru all whole command line */
806 for (i = 1; i < argc; i++)
811 if (tryHandleUnsupportedOpt(argv, &i) == TRUE)
816 if (tryHandleSimpleOpt(argv, &i) == TRUE)
822 if (argv[i][0] == '-' && argv[i][1] == '-')
824 if (strcmp (argv[i], OPTION_HELP) == 0)
830 if (strcmp (argv[i], OPTION_STACK_8BIT) == 0)
832 options.stack10bit = 0;
836 if (strcmp (argv[i], OPTION_OUT_FMT_IHX) == 0)
842 if (strcmp (argv[i], OPTION_LARGE_MODEL) == 0)
844 _setModel (MODEL_LARGE, argv[i]);
848 if (strcmp (argv[i], OPTION_MEDIUM_MODEL) == 0)
850 _setModel (MODEL_MEDIUM, argv[i]);
854 if (strcmp (argv[i], OPTION_SMALL_MODEL) == 0)
856 _setModel (MODEL_SMALL, argv[i]);
860 if (strcmp (argv[i], OPTION_FLAT24_MODEL) == 0)
862 _setModel (MODEL_FLAT24, argv[i]);
866 if (strcmp (argv[i], OPTION_DUMP_ALL) == 0)
868 options.dump_rassgn =
874 options.dump_raw = 1;
878 if (strcmp (argv[i], OPTION_PEEP_FILE) == 0)
880 options.peep_file = getStringArg(OPTION_PEEP_FILE, argv, &i, argc);
884 if (strcmp (argv[i], OPTION_LIB_PATH) == 0)
886 addSet(&libPathsSet, Safe_strdup(getStringArg(OPTION_LIB_PATH, argv, &i, argc)));
890 if (strcmp (argv[i], OPTION_VERSION) == 0)
897 if (strcmp (argv[i], OPTION_CALLEE_SAVES) == 0)
899 setParseWithComma(&options.calleeSavesSet, getStringArg(OPTION_CALLEE_SAVES, argv, &i, argc));
903 if (strcmp (argv[i], OPTION_XSTACK_LOC) == 0)
905 options.xstack_loc = getIntArg(OPTION_XSTACK_LOC, argv, &i, argc);
909 if (strcmp (argv[i], OPTION_STACK_LOC) == 0)
911 options.stack_loc = getIntArg(OPTION_STACK_LOC, argv, &i, argc);
915 if (strcmp (argv[i], OPTION_XRAM_LOC) == 0)
917 options.xdata_loc = getIntArg(OPTION_XRAM_LOC, argv, &i, argc);
921 if (strcmp (argv[i], OPTION_IRAM_SIZE) == 0)
923 options.iram_size = getIntArg(OPTION_IRAM_SIZE, argv, &i, argc);
927 if (strcmp (argv[i], OPTION_XRAM_SIZE) == 0)
929 options.xram_size = getIntArg(OPTION_IRAM_SIZE, argv, &i, argc);
930 options.xram_size_set = TRUE;
934 if (strcmp (argv[i], OPTION_CODE_SIZE) == 0)
936 options.code_size = getIntArg(OPTION_IRAM_SIZE, argv, &i, argc);
940 if (strcmp (argv[i], OPTION_DATA_LOC) == 0)
942 options.data_loc = getIntArg(OPTION_DATA_LOC, argv, &i, argc);
946 if (strcmp (argv[i], OPTION_IDATA_LOC) == 0)
948 options.idata_loc = getIntArg(OPTION_IDATA_LOC, argv, &i, argc);
952 if (strcmp (argv[i], OPTION_CODE_LOC) == 0)
954 options.code_loc = getIntArg(OPTION_CODE_LOC, argv, &i, argc);
958 if (strcmp (argv[i], OPTION_NO_GCSE) == 0)
960 optimize.global_cse = 0;
964 if (strcmp (argv[i], OPTION_NO_LOOP_INV) == 0)
966 optimize.loopInvariant = 0;
970 if (strcmp (argv[i], OPTION_NO_LABEL_OPT) == 0)
976 if (strcmp (argv[i], OPTION_NO_LOOP_IND) == 0)
978 optimize.loopInduction = 0;
982 if (strcmp (argv[i], OPTION_LESS_PEDANTIC) == 0)
984 options.lessPedantic = 1;
985 setErrorLogLevel(ERROR_LEVEL_WARNING);
989 if (strcmp (&argv[i][1], OPTION_SHORT_IS_8BITS) == 0)
991 options.shortis8bits=1;
995 if (strcmp (argv[i], OPTION_TINI_LIBID) == 0)
997 options.tini_libid = getIntArg(OPTION_TINI_LIBID, argv, &i, argc);
1001 if (!port->parseOption (&argc, argv, &i))
1003 werror (W_UNKNOWN_OPTION, argv[i]);
1011 /* if preceded by '-' then option */
1012 if (*argv[i] == '-')
1017 verifyShortOption(argv[i]);
1024 /* Used to select the port. But this has already been done. */
1028 /* Used to select the processor in port. But this has
1029 * already been done. */
1033 verifyShortOption(argv[i]);
1035 options.cc_only = 1;
1039 addSet(&libPathsSet, Safe_strdup(getStringArg("-L", argv, &i, argc)));
1043 addSet(&libFilesSet, Safe_strdup(getStringArg("-l", argv, &i, argc)));
1050 /* copy the file name into the buffer */
1051 strncpyz(buffer, getStringArg("-o", argv, &i, argc),
1053 /* point to last character */
1054 p = buffer + strlen (buffer) - 1;
1055 if (*p == DIR_SEPARATOR_CHAR)
1057 /* only output path specified */
1058 dstPath = Safe_strdup (buffer);
1059 fullDstFileName = NULL;
1063 fullDstFileName = Safe_strdup (buffer);
1065 /* get rid of the "."-extension */
1067 /* is there a dot at all? */
1068 if (strrchr (buffer, '.') &&
1069 /* is the dot in the filename, not in the path? */
1070 (strrchr (buffer, DIR_SEPARATOR_CHAR) < strrchr (buffer, '.')))
1071 *strrchr (buffer, '.') = '\0';
1073 dstFileName = Safe_strdup (buffer);
1075 /* strip module name to get path */
1076 p = strrchr (buffer, DIR_SEPARATOR_CHAR);
1079 /* path with trailing / */
1081 dstPath = Safe_strdup (buffer);
1088 /* pre-processer options */
1089 if (argv[i][2] == 'p')
1091 setParseWithComma(&preArgvSet, getStringArg("-Wp", argv, &i, argc));
1093 /* linker options */
1094 else if (argv[i][2] == 'l')
1096 setParseWithComma(&linkOptionsSet, getStringArg("-Wl", argv, &i, argc));
1098 /* assembler options */
1099 else if (argv[i][2] == 'a')
1101 setParseWithComma(&asmOptionsSet, getStringArg("-Wa", argv, &i, argc));
1105 werror (W_UNKNOWN_OPTION, argv[i]);
1110 verifyShortOption(argv[i]);
1112 printVersionInfo ();
1116 /* preprocessor options */
1120 addSet(&preArgvSet, Safe_strdup("-M"));
1125 addSet(&preArgvSet, Safe_strdup("-C"));
1135 char sOpt = argv[i][1];
1138 if (argv[i][2] == ' ' || argv[i][2] == '\0')
1144 werror(E_ARGUMENT_MISSING, argv[i-1]);
1158 SNPRINTF (buffer, sizeof(buffer),
1159 ((sOpt == 'I') ? "-%c\"%s\"": "-%c%s"), sOpt, rest);
1160 addSet(&preArgvSet, Safe_strdup(buffer));
1165 if (!port->parseOption (&argc, argv, &i))
1166 werror (W_UNKNOWN_OPTION, argv[i]);
1171 if (!port->parseOption (&argc, argv, &i))
1173 /* no option must be a filename */
1176 werror (W_NO_FILE_ARG_IN_C1, argv[i]);
1180 processFile (argv[i]);
1185 /* some sanity checks in c1 mode */
1190 if (fullSrcFileName)
1193 werror (W_NO_FILE_ARG_IN_C1, fullSrcFileName);
1195 fullSrcFileName = NULL;
1196 for (s = setFirstItem(relFilesSet); s != NULL; s = setNextItem(relFilesSet))
1198 werror (W_NO_FILE_ARG_IN_C1, s);
1200 for (s = setFirstItem(libFilesSet); s != NULL; s = setNextItem(libFilesSet))
1202 werror (W_NO_FILE_ARG_IN_C1, s);
1204 deleteSet(&relFilesSet);
1205 deleteSet(&libFilesSet);
1207 if (options.cc_only || noAssemble || preProcOnly)
1209 werror (W_ILLEGAL_OPT_COMBINATION);
1211 options.cc_only = noAssemble = preProcOnly = 0;
1214 werror (E_NEED_OPT_O_IN_C1);
1218 /* if no dstFileName given with -o, we've to find one: */
1223 /* use the modulename from the C-source */
1224 if (fullSrcFileName)
1226 size_t bufSize = strlen (dstPath) + strlen (moduleName) + 1;
1228 dstFileName = Safe_alloc (bufSize);
1229 strncpyz (dstFileName, dstPath, bufSize);
1230 strncatz (dstFileName, moduleName, bufSize);
1232 /* use the modulename from the first object file */
1233 else if ((s = peekSet(relFilesSet)) != NULL)
1238 strncpyz (buffer, s, sizeof(buffer));
1239 /* remove extension (it must be .rel) */
1240 *strrchr (buffer, '.') = '\0';
1242 objectName = strrchr (buffer, DIR_SEPARATOR_CHAR);
1249 objectName = buffer;
1251 bufSize = strlen (dstPath) + strlen (objectName) + 1;
1252 dstFileName = Safe_alloc (bufSize);
1253 strncpyz (dstFileName, dstPath, bufSize);
1254 strncatz (dstFileName, objectName, bufSize);
1256 /* else no module given: help text is displayed */
1259 /* set up external stack location if not explicitly specified */
1260 if (!options.xstack_loc)
1261 options.xstack_loc = options.xdata_loc;
1263 /* if debug option is set then open the cdbFile */
1264 if (options.debug && fullSrcFileName)
1266 SNPRINTF (scratchFileName, sizeof(scratchFileName),
1267 "%s.adb", dstFileName); /*JCF: Nov 30, 2002*/
1268 if(debugFile->openFile(scratchFileName))
1269 debugFile->writeModule(moduleName);
1271 werror (E_FILE_OPEN_ERR, scratchFileName);
1273 MSVC_style(options.vc_err_style);
1274 if(options.use_stdout) SetErrorOut(stdout);
1278 /*-----------------------------------------------------------------*/
1279 /* linkEdit : - calls the linkage editor with options */
1280 /*-----------------------------------------------------------------*/
1282 linkEdit (char **envp)
1289 /* first we need to create the <filename>.lnk file */
1290 SNPRINTF (scratchFileName, sizeof(scratchFileName),
1291 "%s.lnk", dstFileName);
1292 if (!(lnkfile = fopen (scratchFileName, "w")))
1294 werror (E_FILE_OPEN_ERR, scratchFileName);
1298 /* now write the options. JCF: added option 'y' */
1299 fprintf (lnkfile, "-myux%c\n", (options.out_fmt ? 's' : 'i'));
1301 /* if iram size specified */
1302 if (options.iram_size)
1303 fprintf (lnkfile, "-a 0x%04x\n", options.iram_size);
1305 /* if xram size specified */
1306 if (options.xram_size_set)
1307 fprintf (lnkfile, "-v 0x%04x\n", options.xram_size);
1309 /* if code size specified */
1310 if (options.code_size)
1311 fprintf (lnkfile, "-w 0x%04x\n", options.code_size);
1314 fprintf (lnkfile, "-z\n");
1316 #define WRITE_SEG_LOC(N, L) \
1317 segName = Safe_strdup(N); \
1318 c = strtok(segName, " \t"); \
1319 fprintf (lnkfile,"-b %s = 0x%04x\n", c, L); \
1320 if (segName) { Safe_free(segName); }
1322 /* code segment start */
1323 WRITE_SEG_LOC (CODE_NAME, options.code_loc);
1325 /* data segment start */
1326 if(options.data_loc){ /*JCF: If zero, the linker chooses the best place for data*/
1327 WRITE_SEG_LOC (DATA_NAME, options.data_loc);
1331 WRITE_SEG_LOC (XDATA_NAME, options.xdata_loc);
1335 WRITE_SEG_LOC (IDATA_NAME, options.idata_loc);
1338 /* bit segment start */
1339 WRITE_SEG_LOC (BIT_NAME, 0);
1341 /* JCF: stack start */
1342 if ( (options.stack_loc) && (options.stack_loc<0x100) ) {
1343 WRITE_SEG_LOC ("SSEG", options.stack_loc);
1346 /* add the extra linker options */
1347 fputStrSet(lnkfile, linkOptionsSet);
1349 /* other library paths if specified */
1350 for (s = setFirstItem(libPathsSet); s != NULL; s = setNextItem(libPathsSet))
1351 fprintf (lnkfile, "-k %s\n", s);
1353 /* standard library path */
1354 if (!options.nostdlib)
1356 switch (options.model)
1366 if (TARGET_IS_DS390)
1370 else if (TARGET_IS_DS400)
1377 "Add support for your FLAT24 target in %s @ line %d\n",
1378 __FILE__, __LINE__);
1386 werror (W_UNKNOWN_MODEL, __FILE__, __LINE__);
1390 for (s = setFirstItem(libDirsSet); s != NULL; s = setNextItem(libDirsSet))
1391 mfprintf (lnkfile, getRuntimeVariables(), "-k %s{sep}%s\n", s, c);
1393 /* standard library files */
1394 #if !OPT_DISABLE_DS390
1395 if (options.model == MODEL_FLAT24)
1397 if (TARGET_IS_DS390)
1399 fprintf (lnkfile, "-l %s\n", STD_DS390_LIB);
1401 else if (TARGET_IS_DS400)
1403 fprintf (lnkfile, "-l %s\n", STD_DS400_LIB);
1408 "Add support for your FLAT24 target in %s @ line %d\n",
1409 __FILE__, __LINE__);
1415 #if !OPT_DISABLE_XA51
1417 if (options.model == MODEL_PAGE0)
1419 fprintf (lnkfile, "-l %s\n", STD_XA51_LIB);
1423 fprintf (lnkfile, "-l %s\n", STD_LIB);
1424 fprintf (lnkfile, "-l %s\n", STD_INT_LIB);
1425 fprintf (lnkfile, "-l %s\n", STD_LONG_LIB);
1426 fprintf (lnkfile, "-l %s\n", STD_FP_LIB);
1429 /* additional libraries if any */
1430 for (s = setFirstItem(libFilesSet); s != NULL; s = setNextItem(libFilesSet))
1431 fprintf (lnkfile, "-l %s\n", s);
1433 /* put in the object files */
1434 if (fullSrcFileName)
1435 fprintf (lnkfile, "%s%s\n", dstFileName, port->linker.rel_ext);
1437 fputStrSet(lnkfile, relFilesSet);
1439 fprintf (lnkfile, "\n-e\n");
1442 if (options.verbose)
1443 printf ("sdcc: Calling linker...\n");
1445 /* build linker output filename */
1447 /* -o option overrides default name? */
1448 if (fullDstFileName)
1450 strncpyz (scratchFileName, fullDstFileName, sizeof(scratchFileName));
1454 /* the linked file gets the name of the first modul */
1455 if (fullSrcFileName)
1457 strncpyz (scratchFileName, dstFileName, sizeof(scratchFileName));
1461 s = peekSet(relFilesSet);
1465 strncpyz (scratchFileName, s, sizeof(scratchFileName));
1466 /* strip ".rel" extension */
1467 *strrchr (scratchFileName, '.') = '\0';
1469 strncatz (scratchFileName,
1470 options.out_fmt ? ".S19" : ".ihx",
1471 sizeof(scratchFileName));
1474 if (port->linker.cmd)
1476 char buffer2[PATH_MAX];
1478 /* VR 030517 - gplink needs linker options to set the linker script,*/
1479 buildCmdLine (buffer2, port->linker.cmd, dstFileName, scratchFileName, NULL, linkOptionsSet);
1481 buildCmdLine2 (buffer, buffer2, sizeof(buffer));
1485 buildCmdLine2 (buffer, port->linker.mcmd, sizeof(buffer));
1488 /* if (options.verbose)fprintf(stderr, "linker command line: %s\n", buffer); */
1490 system_ret = my_system (buffer);
1491 /* TODO: most linker don't have a -o parameter */
1492 /* -o option overrides default name? */
1493 if (fullDstFileName)
1496 /* the linked file gets the name of the first modul */
1497 if (fullSrcFileName)
1499 strncpyz (scratchFileName, dstFileName, sizeof(scratchFileName));
1500 p = strlen (scratchFileName) + scratchFileName;
1504 s = peekSet(relFilesSet);
1508 strncpyz (scratchFileName, s, sizeof(scratchFileName));
1509 /* strip ".rel" extension */
1510 p = strrchr (scratchFileName, '.');
1516 strncatz (scratchFileName,
1517 options.out_fmt ? ".S19" : ".ihx",
1518 sizeof(scratchFileName));
1519 rename (scratchFileName, fullDstFileName);
1521 strncpyz (buffer, fullDstFileName, sizeof(buffer));
1522 q = strrchr (buffer, '.');
1525 /* no extension: append new extensions */
1526 q = strlen (buffer) + buffer;
1530 strncatz (scratchFileName, ".map", sizeof(scratchFileName));
1532 strncatz(buffer, ".map", sizeof(buffer));
1533 rename (scratchFileName, buffer);
1535 strncatz (scratchFileName, ".mem", sizeof(scratchFileName));
1537 strncatz(buffer, ".mem", sizeof(buffer));
1538 rename (scratchFileName, buffer);
1546 /*-----------------------------------------------------------------*/
1547 /* assemble - spawns the assembler with arguments */
1548 /*-----------------------------------------------------------------*/
1550 assemble (char **envp)
1552 /* build assembler output filename */
1554 /* -o option overrides default name? */
1555 if (options.cc_only && fullDstFileName) {
1556 strncpyz (scratchFileName, fullDstFileName, sizeof(scratchFileName));
1558 /* the assembled file gets the name of the first modul */
1559 strncpyz (scratchFileName, dstFileName, sizeof(scratchFileName));
1560 strncatz (scratchFileName, port->linker.rel_ext,
1561 sizeof(scratchFileName));
1564 if (port->assembler.do_assemble) {
1565 port->assembler.do_assemble(asmOptionsSet);
1567 } else if (port->assembler.cmd) {
1568 buildCmdLine (buffer, port->assembler.cmd, dstFileName, scratchFileName,
1569 options.debug ? port->assembler.debug_opts : port->assembler.plain_opts,
1572 buildCmdLine2 (buffer, port->assembler.mcmd, sizeof(buffer));
1575 if (my_system (buffer)) {
1576 /* either system() or the assembler itself has reported an error
1577 perror ("Cannot exec assembler");
1581 /* TODO: most assembler don't have a -o parameter */
1582 /* -o option overrides default name? */
1583 if (options.cc_only && fullDstFileName) {
1584 strncpyz (scratchFileName, dstFileName, sizeof(scratchFileName));
1585 strncatz (scratchFileName,
1586 port->linker.rel_ext,
1587 sizeof(scratchFileName));
1588 rename (scratchFileName, fullDstFileName);
1592 /*-----------------------------------------------------------------*/
1593 /* preProcess - spawns the preprocessor with arguments */
1594 /*-----------------------------------------------------------------*/
1596 preProcess (char **envp)
1605 set *inclList = NULL;
1607 /* if using external stack define the macro */
1608 if (options.useXstack)
1609 addSet(&preArgvSet, Safe_strdup("-DSDCC_USE_XSTACK"));
1611 /* set the macro for stack autos */
1612 if (options.stackAuto)
1613 addSet(&preArgvSet, Safe_strdup("-DSDCC_STACK_AUTO"));
1615 /* set the macro for stack autos */
1616 if (options.stack10bit)
1617 addSet(&preArgvSet, Safe_strdup("-DSDCC_STACK_TENBIT"));
1619 /* set the macro for no overlay */
1620 if (options.noOverlay)
1621 addSet(&preArgvSet, Safe_strdup("-DSDCC_NOOVERLAY"));
1623 /* set the macro for large model */
1624 switch (options.model)
1627 addSet(&preArgvSet, Safe_strdup("-DSDCC_MODEL_LARGE"));
1630 addSet(&preArgvSet, Safe_strdup("-DSDCC_MODEL_SMALL"));
1633 addSet(&preArgvSet, Safe_strdup("-DSDCC_MODEL_COMPACT"));
1636 addSet(&preArgvSet, Safe_strdup("-DSDCC_MODEL_MEDIUM"));
1639 addSet(&preArgvSet, Safe_strdup("-DSDCC_MODEL_FLAT24"));
1642 addSet(&preArgvSet, Safe_strdup("-DSDCC_MODEL_PAGE0"));
1645 werror (W_UNKNOWN_MODEL, __FILE__, __LINE__);
1649 /* add port (processor information to processor */
1650 addSet(&preArgvSet, Safe_strdup("-DSDCC_{port}"));
1651 addSet(&preArgvSet, Safe_strdup("-D__{port}"));
1653 /* standard include path */
1654 if (!options.nostdinc) {
1655 inclList = appendStrSet(includeDirsSet, "-I\"", "\"");
1656 mergeSets(&preArgvSet, inclList);
1659 setMainValue("cppextraopts", (s = joinStrSet(preArgvSet)));
1660 Safe_free((void *)s);
1661 if (inclList != NULL)
1662 deleteSet(&inclList);
1664 if (preProcOnly && fullDstFileName)
1666 /* -E and -o given */
1667 setMainValue ("cppoutfilename", fullDstFileName);
1671 /* Piping: set cppoutfilename to NULL, to avoid empty quotes */
1672 setMainValue ("cppoutfilename", NULL);
1675 if (options.verbose)
1676 printf ("sdcc: Calling preprocessor...\n");
1678 buildCmdLine2 (buffer, _preCmd, sizeof(buffer));
1681 if (my_system (buffer)) {
1688 yyin = my_popen (buffer);
1690 perror ("Preproc file not found");
1693 addSetHead (&pipeSet, yyin);
1701 setBinPaths(const char *argv0)
1709 * 1. - $SDCCDIR/PREFIX2BIN_DIR
1710 * 2. - path(argv[0])
1714 /* do it in reverse mode, so that addSetHead() can be used
1715 instead of slower addSet() */
1717 if ((p = getBinPath(argv0)) != NULL)
1718 addSetHead(&binPathSet, Safe_strdup(p));
1720 if ((p = getenv(SDCC_DIR_NAME)) != NULL) {
1721 SNPRINTF(buf, sizeof buf, "%s" PREFIX2BIN_DIR, p);
1722 addSetHead(&binPathSet, Safe_strdup(buf));
1725 if (options.printSearchDirs) {
1726 printf("programs:\n");
1727 fputStrSet(stdout, binPathSet);
1731 /* Set system include path */
1733 setIncludePath(void)
1740 * 1. - $SDCC_INCLUDE
1741 * 2. - $SDCC_HOME/PREFIX2DATA_DIR/INCLUDE_DIR_SUFFIX
1742 * 3. - path(argv[0])/BIN2DATA_DIR/INCLUDE_DIR_SUFFIX
1743 * 4. - DATADIR/INCLUDE_DIR_SUFFIX (only on *nix)
1746 includeDirsSet = appendStrSet(dataDirsSet, NULL, INCLUDE_DIR_SUFFIX);
1748 if ((p = getenv(SDCC_INCLUDE_NAME)) != NULL)
1749 addSetHead(&includeDirsSet, p);
1751 if (options.printSearchDirs) {
1752 printf("includedir:\n");
1753 fputStrSet(stdout, includeDirsSet);
1757 /* Set system lib path */
1767 * 2. - $SDCC_HOME/PREFIX2DATA_DIR/LIB_DIR_SUFFIX/<model>
1768 * 3. - path(argv[0])/BIN2DATA_DIR/LIB_DIR_SUFFIX/<model>
1769 * 4. - DATADIR/LIB_DIR_SUFFIX/<model> (only on *nix)
1772 libDirsSet = appendStrSet(dataDirsSet, NULL, LIB_DIR_SUFFIX);
1774 if ((p = getenv(SDCC_LIB_NAME)) != NULL)
1775 addSetHead(&libDirsSet, p);
1777 if (options.printSearchDirs) {
1778 printf("libdir:\n");
1779 fputStrSet(stdout, libDirsSet);
1785 setDataPaths(const char *argv0)
1793 * 1. - $SDCC_HOME/PREFIX2DATA_DIR
1794 * 2. - path(argv[0])/BIN2DATA_DIR
1795 * 3. - DATADIR (only on *nix)
1798 if ((p = getenv(SDCC_DIR_NAME)) != NULL) {
1799 SNPRINTF(buf, sizeof buf, "%s" PREFIX2DATA_DIR, p);
1800 addSet(&dataDirsSet, Safe_strdup(buf));
1803 if ((p = getBinPath(argv0)) != NULL) {
1804 SNPRINTF(buf, sizeof buf, "%s" BIN2DATA_DIR, p);
1805 addSet(&dataDirsSet, Safe_strdup(buf));
1809 if (peekSet(dataDirsSet) == NULL) {
1810 /* this should never happen... */
1811 wassertl(0, "Can't get binary path");
1814 addSet(&dataDirsSet, Safe_strdup(DATADIR));
1817 if (options.printSearchDirs) {
1818 printf("datadir:\n");
1819 fputStrSet(stdout, dataDirsSet);
1829 populateMainValues (_baseValues);
1830 setMainValue ("port", port->target);
1831 setMainValue ("objext", port->linker.rel_ext);
1832 setMainValue ("asmext", port->assembler.file_ext);
1834 setMainValue ("dstfilename", dstFileName);
1835 setMainValue ("fullsrcfilename", fullSrcFileName ? fullSrcFileName : "fullsrcfilename");
1837 if (options.cc_only && fullDstFileName)
1838 /* compile + assemble and -o given: -o specifies name of object file */
1840 setMainValue ("objdstfilename", fullDstFileName);
1844 setMainValue ("objdstfilename", "{stdobjdstfilename}");
1846 if (fullDstFileName)
1847 /* if we're linking, -o gives the final file name */
1849 setMainValue ("linkdstfilename", fullDstFileName);
1853 setMainValue ("linkdstfilename", "{stdlinkdstfilename}");
1859 sig_handler (int signal)
1866 sig_string = "SIGABRT";
1869 sig_string = "SIGTERM";
1872 sig_string = "SIGINT";
1875 sig_string = "SIGSEGV";
1878 sig_string = "Unknown?";
1881 fprintf (stderr, "Caught signal %d: %s\n", signal, sig_string);
1887 * initialises and calls the parser
1891 main (int argc, char **argv, char **envp)
1893 /* turn all optimizations off by default */
1894 memset (&optimize, 0, sizeof (struct optimize));
1896 /*printVersionInfo (); */
1899 fprintf (stderr, "Build error: no ports are enabled.\n");
1903 /* install atexit handler */
1904 atexit(rm_tmpfiles);
1906 /* install signal handler;
1907 it's only purpuse is to call exit() to remove temp files */
1908 if (!getenv("SDCC_LEAVE_SIGNALS"))
1910 signal (SIGABRT, sig_handler);
1911 signal (SIGTERM, sig_handler);
1912 signal (SIGINT , sig_handler);
1913 signal (SIGSEGV, sig_handler);
1916 /* Before parsing the command line options, do a
1917 * search for the port and processor and initialize
1918 * them if they're found. (We can't gurantee that these
1919 * will be the first options specified).
1922 _findPort (argc, argv);
1925 if (strcmp(port->target, "mcs51") == 0) {
1926 printf("DS390 jammed in A\n");
1932 _findProcessor (argc, argv);
1934 /* Initalise the port. */
1938 setDefaultOptions ();
1941 options.model = MODEL_SMALL;
1942 options.stack10bit=0;
1945 parseCmdLine (argc, argv);
1948 setBinPaths(argv[0]);
1949 setDataPaths(argv[0]);
1951 /* if no input then printUsage & exit */
1952 if (!options.c1mode && !fullSrcFileName && peekSet(relFilesSet) == NULL) {
1953 if (!options.printSearchDirs)
1959 /* initMem() is expensive, but
1960 initMem() must called before port->finaliseOptions ().
1961 And the z80 port needs port->finaliseOptions(),
1962 even if we're only linking. */
1964 port->finaliseOptions ();
1966 if (fullSrcFileName || options.c1mode)
1976 if (options.verbose)
1977 printf ("sdcc: Generating code...\n");
1982 deleteSetItem(&pipeSet, yyin);
1988 if (TARGET_IS_PIC) {
1989 /* TSD PIC port hack - if the PIC port option is enabled
1990 and SDCC is used to generate PIC code, then we will
1991 generate .asm files in gpasm's format instead of SDCC's
1994 #if !OPT_DISABLE_PIC
1999 if(TARGET_IS_PIC16) {
2000 /* PIC16 port misc improvements Vangelis Rokas - 6-May-2003
2001 Generate .asm files for gpasm (just like PIC target) but use
2005 #if !OPT_DISABLE_PIC16
2012 if (!options.c1mode && !noAssemble)
2014 if (options.verbose)
2015 printf ("sdcc: Calling assembler...\n");
2021 if (options.debug && debugFile)
2022 debugFile->closeFile();
2024 if (!options.cc_only &&
2028 (fullSrcFileName || peekSet(relFilesSet) != NULL))
2030 if (port->linker.do_link)
2031 port->linker.do_link ();