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 -------------------------------------------------------------------------*/
34 // This is a bit messy because we define link ourself
40 // No unistd.h in Borland C++
41 extern int access(const char *, int);
48 FILE *srcFile ;/* source file */
49 FILE *cdbFile = NULL ;/* debugger information output file */
50 char *fullSrcFileName ;/* full name for the source file */
51 char *srcFileName ;/* source file name with the .c stripped */
52 char *moduleName ;/* module name is srcFilename stripped of any path */
53 const char *preArgv[128] ;/* pre-processor arguments */
55 struct optimize optimize ;
56 struct options options ;
57 char *VersionString = SDCC_VERSION_STR /*"Version 2.1.8a"*/;
58 short preProcOnly = 0;
60 char *linkOptions[128];
61 const char *asmOptions[128];
68 bool verboseExec = FALSE;
71 /* Far functions, far data */
72 #define OPTION_LARGE_MODEL "-model-large"
73 /* Far functions, near data */
74 #define OPTION_MEDIUM_MODEL "-model-medium"
75 #define OPTION_SMALL_MODEL "-model-small"
76 #define OPTION_FLAT24_MODEL "-model-flat24"
77 #define OPTION_STACK_AUTO "-stack-auto"
78 #define OPTION_STACK_10BIT "-stack-10bit"
79 #define OPTION_XSTACK "-xstack"
80 #define OPTION_GENERIC "-generic"
81 #define OPTION_NO_GCSE "-nogcse"
82 #define OPTION_NO_LOOP_INV "-noinvariant"
83 #define OPTION_NO_LOOP_IND "-noinduction"
84 #define OPTION_NO_JTBOUND "-nojtbound"
85 #define OPTION_NO_LOOPREV "-noloopreverse"
86 #define OPTION_XREGS "-regextend"
87 #define OPTION_COMP_ONLY "-compile-only"
88 #define OPTION_DUMP_RAW "-dumpraw"
89 #define OPTION_DUMP_GCSE "-dumpgcse"
90 #define OPTION_DUMP_LOOP "-dumploop"
91 #define OPTION_DUMP_KILL "-dumpdeadcode"
92 #define OPTION_DUMP_RANGE "-dumpliverange"
93 #define OPTION_DUMP_PACK "-dumpregpack"
94 #define OPTION_DUMP_RASSGN "-dumpregassign"
95 #define OPTION_DUMP_ALL "-dumpall"
96 #define OPTION_XRAM_LOC "-xram-loc"
97 #define OPTION_IRAM_SIZE "-iram-size"
98 #define OPTION_XSTACK_LOC "-xstack-loc"
99 #define OPTION_CODE_LOC "-code-loc"
100 #define OPTION_STACK_LOC "-stack-loc"
101 #define OPTION_DATA_LOC "-data-loc"
102 #define OPTION_IDATA_LOC "-idata-loc"
103 #define OPTION_PEEP_FILE "-peep-file"
104 #define OPTION_LIB_PATH "-lib-path"
105 #define OPTION_INTLONG_RENT "-int-long-reent"
106 #define OPTION_FLOAT_RENT "-float-reent"
107 #define OPTION_OUT_FMT_IHX "-out-fmt-ihx"
108 #define OPTION_OUT_FMT_S19 "-out-fmt-s19"
109 #define OPTION_CYCLOMATIC "-cyclomatic"
110 #define OPTION_NOOVERLAY "-nooverlay"
111 #define OPTION_MAINRETURN "-main-return"
112 #define OPTION_NOPEEP "-no-peep"
113 #define OPTION_ASMPEEP "-peep-asm"
114 #define OPTION_DEBUG "-debug"
115 #define OPTION_NODEBUG "-nodebug"
116 #define OPTION_VERSION "-version"
117 #define OPTION_STKAFTRDATA "-stack-after-data"
118 #define OPTION_PREPROC_ONLY "-preprocessonly"
119 #define OPTION_C1_MODE "-c1mode"
120 #define OPTION_HELP "-help"
121 #define OPTION_CALLEE_SAVES "-callee-saves"
122 #define OPTION_NOREGPARMS "-noregparms"
123 #define OPTION_NOSTDLIB "-nostdlib"
124 #define OPTION_NOSTDINC "-nostdinc"
125 #define OPTION_VERBOSE "-verbose"
126 static const char *_preCmd[] = {
127 "sdcpp", "-Wall", "-lang-c++", "-DSDCC=1",
128 "$l", "-I" SDCC_INCLUDE_DIR, "$1", "$2", NULL
133 static PORT *_ports[] = {
134 #if !OPT_DISABLE_MCS51
137 #if !OPT_DISABLE_GBZ80
146 #if !OPT_DISABLE_DS390
154 #define NUM_PORTS (sizeof(_ports)/sizeof(_ports[0]))
157 remove me - TSD a hack to force sdcc to generate gpasm format .asm files.
159 extern void pic14glue();
161 /** Sets the port to the one given by the command line option.
162 @param The name minus the option (eg 'mcs51')
163 @return 0 on success.
165 static int _setPort(const char *name)
168 for (i=0; i<NUM_PORTS; i++) {
169 if (!strcmp(_ports[i]->target, name)) {
174 /* Error - didnt find */
175 werror(E_UNKNOWN_TARGET,name);
179 void buildCmdLine(char *into, char **args, const char **cmds,
180 const char *p1, const char *p2,
181 const char *p3, const char **list)
183 const char *p, *from;
193 /* See if it has a '$' anywhere - if not, just copy */
194 if ((p = strchr(from, '$'))) {
195 strncpy(into, from, p - from);
196 /* NULL terminate it */
214 const char **tmp = list;
218 into += strlen(into)+1;
231 if (strlen(into) == 0)
233 into += strlen(into)+1;
238 /*-----------------------------------------------------------------*/
239 /* printVersionInfo - prints the version info */
240 /*-----------------------------------------------------------------*/
241 void printVersionInfo ()
247 for (i=0; i<NUM_PORTS; i++)
248 fprintf(stderr, "%s%s", i==0 ? "" : "/", _ports[i]->target);
249 fprintf(stderr, " %s"
250 #ifdef SDCC_SUB_VERSION_STR
251 "/" SDCC_SUB_VERSION_STR
268 /*-----------------------------------------------------------------*/
269 /* printUsage - prints command line syntax */
270 /*-----------------------------------------------------------------*/
275 "Usage : [options] filename\n"
277 "\t-m<proc> - Target processor <proc>. Default %s\n"
278 "\t Try --version for supported values of <proc>\n"
279 "\t--model-large - Large Model\n"
280 "\t--model-small - Small Model (default)\n"
281 "\t--stack-auto - Stack automatic variables\n"
282 "\t--xstack - Use external stack\n"
283 "\t--xram-loc <nnnn> - External Ram start location\n"
284 "\t--xstack-loc <nnnn> - Xternal Stack Location\n"
285 "\t--code-loc <nnnn> - Code Segment Location\n"
286 "\t--stack-loc <nnnn> - Stack pointer initial value\n"
287 "\t--data-loc <nnnn> - Direct data start location\n"
288 "\t--idata-loc <nnnn> - Indirect data start location\n"
289 "\t--iram-size <nnnn> - Internal Ram size\n"
290 "\t--nojtbound - Don't generate boundary check for jump tables\n"
291 "\t--generic - All unqualified ptrs converted to '_generic'\n"
292 "PreProcessor Options :-\n"
293 "\t-Dmacro - Define Macro\n"
294 "\t-Ipath - Include \"*.h\" path\n"
295 "Note: this is NOT a complete list of options see docs for details\n",
301 /*-----------------------------------------------------------------*/
302 /* parseWithComma - separates string with comma */
303 /*-----------------------------------------------------------------*/
304 void parseWithComma (char **dest,char *src)
309 /* skip the initial white spaces */
310 while (isspace(*src)) src++;
324 /*-----------------------------------------------------------------*/
325 /* setDefaultOptions - sets the default options */
326 /*-----------------------------------------------------------------*/
327 static void setDefaultOptions()
331 for ( i = 0 ; i < 128 ; i++)
332 preArgv[i] = asmOptions [i] =
333 linkOptions[i] = relFiles[i] = libFiles[i] =
336 /* first the options part */
337 options.stack_loc = 0; /* stack pointer initialised to 0 */
338 options.xstack_loc= 0; /* xternal stack starts at 0 */
339 options.code_loc = 0; /* code starts at 0 */
340 options.data_loc = 0x0030; /* data starts at 0x0030 */
341 options.xdata_loc = 0;
342 options.idata_loc = 0x80;
343 options.genericPtr = 1; /* default on */
345 options.model = port->general.default_model;
350 /* now for the optimizations */
351 /* turn on the everything */
352 optimize.global_cse = 1;
357 optimize.loopInvariant = 1;
358 optimize.loopInduction = 1;
360 port->setDefaultOptions();
363 /*-----------------------------------------------------------------*/
364 /* processFile - determines the type of file from the extension */
365 /*-----------------------------------------------------------------*/
366 static void processFile (char *s)
370 /* get the file extension */
371 fext = s + strlen(s);
372 while ((fext != s) && *fext != '.') fext--;
374 /* now if no '.' then we don't know what the file type is
375 so give a warning and return */
377 werror(W_UNKNOWN_FEXT,s);
381 /* otherwise depending on the file type */
382 if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0 || options.c1mode) {
383 /* source file name : not if we already have a
386 werror(W_TOO_MANY_SRC,s);
390 /* the only source file */
391 if (!(srcFile = fopen((fullSrcFileName = s),"r"))) {
392 werror(E_FILE_OPEN_ERR,s);
396 /* copy the file name into the buffer */
399 /* get rid of the "." */
401 ALLOC_ATOMIC(srcFileName,strlen(buffer)+1);
402 strcpy(srcFileName,buffer);
404 /* get rid of any path information
405 for the module name; do this by going
406 backwards till we get to either '/' or '\' or ':'
407 or start of buffer */
408 fext = buffer + strlen(buffer);
409 while (fext != buffer &&
410 *(fext -1) != '\\' &&
414 ALLOC_ATOMIC(moduleName,strlen(fext)+1);
415 strcpy(moduleName,fext);
420 /* if the extention is type .rel or .r or .REL or .R
421 addtional object file will be passed to the linker */
422 if (strcmp(fext,".r") == 0 || strcmp(fext,".rel") == 0 ||
423 strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0 ||
424 strcmp(fext, port->linker.rel_ext) == 0)
426 relFiles[nrelFiles++] = s;
430 /* if .lib or .LIB */
431 if (strcmp(fext,".lib") == 0 || strcmp(fext,".LIB") == 0) {
432 libFiles[nlibFiles++] = s;
436 werror(W_UNKNOWN_FEXT,s);
440 static void _processC1Arg(char *s)
443 if (options.out_name) {
444 werror(W_TOO_MANY_SRC,s);
447 options.out_name = strdup(s);
454 static void _addToList(const char **list, const char *str)
456 /* This is the bad way to do things :) */
461 werror(E_OUT_OF_MEM,__FILE__, 0);
467 static void _setModel(int model, const char *sz)
469 if (port->general.supported_models & model)
470 options.model = model;
472 werror(W_UNSUPPORTED_MODEL, sz, port->target);
475 /*-----------------------------------------------------------------*/
476 /* parseCmdLine - parses the command line and sets the options */
477 /*-----------------------------------------------------------------*/
478 int parseCmdLine ( int argc, char **argv )
483 /* go thru all whole command line */
484 for ( i = 1; i < argc; i++ ) {
489 if (argv[i][0] == '-' && argv[i][1] == '-') {
491 if (strcmp(&argv[i][1],OPTION_HELP) == 0) {
496 if (strcmp(&argv[i][1],OPTION_XREGS) == 0) {
497 options.regExtend = 1;
501 if (strcmp(&argv[i][1],OPTION_LARGE_MODEL) == 0) {
502 _setModel(MODEL_LARGE, argv[i]);
506 if (strcmp(&argv[i][1],OPTION_MEDIUM_MODEL) == 0) {
507 _setModel(MODEL_MEDIUM, argv[i]);
511 if (strcmp(&argv[i][1],OPTION_SMALL_MODEL) == 0) {
512 _setModel(MODEL_SMALL, argv[i]);
516 if (strcmp(&argv[i][1],OPTION_FLAT24_MODEL) == 0) {
517 _setModel(MODEL_FLAT24, argv[i]);
521 if (strcmp(&argv[i][1],OPTION_STACK_10BIT) == 0) {
522 options.stack10bit = 1;
526 if (strcmp(&argv[i][1],OPTION_STACK_AUTO) == 0) {
527 options.stackAuto = 1;
531 if (strcmp(&argv[i][1],OPTION_DUMP_RAW) == 0) {
532 options.dump_raw = 1;
536 if (strcmp(&argv[i][1],OPTION_CYCLOMATIC) == 0) {
537 options.cyclomatic = 1;
541 if (strcmp(&argv[i][1],OPTION_DUMP_GCSE) == 0) {
542 options.dump_gcse = 1;
546 if (strcmp(&argv[i][1],OPTION_DUMP_LOOP) == 0) {
547 options.dump_loop = 1;
551 if (strcmp(&argv[i][1],OPTION_DUMP_KILL) == 0) {
552 options.dump_kill = 1;
556 if (strcmp(&argv[i][1],OPTION_INTLONG_RENT) == 0) {
557 options.intlong_rent = 1;
561 if (strcmp(&argv[i][1],OPTION_FLOAT_RENT) == 0) {
562 options.float_rent = 1;
566 if (strcmp(&argv[i][1],OPTION_DUMP_RANGE) == 0) {
567 options.dump_range = 1;
571 if (strcmp(&argv[i][1],OPTION_DUMP_PACK) == 0) {
572 options.dump_pack = 1;
576 if (strcmp(&argv[i][1],OPTION_DUMP_RASSGN) == 0) {
577 options.dump_rassgn = 1;
581 if (strcmp(&argv[i][1],OPTION_OUT_FMT_IHX) == 0) {
586 if (strcmp(&argv[i][1],OPTION_OUT_FMT_S19) == 0) {
591 if (strcmp(&argv[i][1],OPTION_NOOVERLAY) == 0) {
592 options.noOverlay = 1;
596 if (strcmp(&argv[i][1],OPTION_STKAFTRDATA) == 0) {
597 options.stackOnData = 1;
601 if (strcmp(&argv[i][1],OPTION_PREPROC_ONLY) == 0) {
606 if (strcmp(&argv[i][1],OPTION_C1_MODE) == 0) {
612 if (strcmp(&argv[i][1],OPTION_DUMP_ALL) == 0) {
613 options.dump_rassgn =
619 options.dump_raw = 1;
623 if (strcmp(&argv[i][1],OPTION_COMP_ONLY) == 0) {
628 if (strcmp(&argv[i][1],OPTION_GENERIC) == 0) {
629 options.genericPtr = 1;
633 if (strcmp(&argv[i][1],OPTION_NOPEEP) == 0) {
638 if (strcmp(&argv[i][1],OPTION_ASMPEEP) == 0) {
643 if (strcmp(&argv[i][1],OPTION_DEBUG) == 0) {
648 if (strcmp(&argv[i][1],OPTION_NODEBUG) == 0) {
653 if (strcmp(&argv[i][1],OPTION_NOREGPARMS) == 0) {
654 options.noregparms = 1;
658 if (strcmp(&argv[i][1],OPTION_PEEP_FILE) == 0) {
659 if (argv[i][1+strlen(OPTION_PEEP_FILE)])
661 &argv[i][1+strlen(OPTION_PEEP_FILE)];
663 options.peep_file = argv[++i];
667 if (strcmp(&argv[i][1],OPTION_LIB_PATH) == 0) {
668 if (argv[i][1+strlen(OPTION_LIB_PATH)])
669 libPaths[nlibPaths++] =
670 &argv[i][1+strlen(OPTION_PEEP_FILE)];
672 libPaths[nlibPaths++] = argv[++i];
676 if (strcmp(&argv[i][1],OPTION_XSTACK_LOC) == 0) {
678 if (argv[i][1+strlen(OPTION_XSTACK_LOC)])
680 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XSTACK_LOC)]));
683 (int) floatFromVal(constVal(argv[++i]));
687 if (strcmp(&argv[i][1],OPTION_XSTACK) == 0) {
688 options.useXstack = 1;
692 if (strcmp(&argv[i][1],OPTION_MAINRETURN) == 0) {
693 options.mainreturn = 1;
697 if (strcmp(&argv[i][1],OPTION_CALLEE_SAVES) == 0) {
698 if (argv[i][1+strlen(OPTION_CALLEE_SAVES)])
699 parseWithComma(options.calleeSaves
700 ,&argv[i][1+strlen(OPTION_CALLEE_SAVES)]);
702 parseWithComma(options.calleeSaves,argv[++i]);
706 if (strcmp(&argv[i][1],OPTION_STACK_LOC) == 0) {
708 if (argv[i][1+strlen(OPTION_STACK_LOC)])
710 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_STACK_LOC)]));
713 (int) floatFromVal(constVal(argv[++i]));
717 if (strcmp(&argv[i][1],OPTION_XRAM_LOC) == 0) {
719 if (argv[i][1+strlen(OPTION_XRAM_LOC)])
721 (unsigned int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XRAM_LOC)]));
724 (unsigned int) floatFromVal(constVal(argv[++i]));
728 if (strcmp(&argv[i][1],OPTION_IRAM_SIZE) == 0) {
730 if (argv[i][1+strlen(OPTION_IRAM_SIZE)])
732 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IRAM_SIZE)]));
735 (int) floatFromVal(constVal(argv[++i]));
739 if (strcmp(&argv[i][1],OPTION_VERSION) == 0) {
745 if (strcmp(&argv[i][1],OPTION_DATA_LOC) == 0) {
747 if (argv[i][1+strlen(OPTION_DATA_LOC)])
749 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_DATA_LOC)]));
752 (int) floatFromVal(constVal(argv[++i]));
756 if (strcmp(&argv[i][1],OPTION_IDATA_LOC) == 0) {
758 if (argv[i][1+strlen(OPTION_IDATA_LOC)])
760 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IDATA_LOC)]));
763 (int) floatFromVal(constVal(argv[++i]));
767 if (strcmp(&argv[i][1],OPTION_CODE_LOC) == 0) {
769 if (argv[i][1+strlen(OPTION_CODE_LOC)])
771 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_CODE_LOC)]));
774 (int) floatFromVal(constVal(argv[++i]));
779 if (strcmp(&argv[i][1],OPTION_NO_JTBOUND) == 0) {
780 optimize.noJTabBoundary = 1;
784 if (strcmp(&argv[i][1],OPTION_NO_GCSE) == 0) {
785 optimize.global_cse = 0;
789 if (strcmp(&argv[i][1],OPTION_NO_LOOP_INV) == 0) {
790 optimize.loopInvariant = 0;
794 if (strcmp(&argv[i][1],OPTION_NO_LOOP_IND) == 0) {
795 optimize.loopInduction = 0;
799 if (strcmp(&argv[i][1],OPTION_NO_LOOPREV) == 0) {
800 optimize.noLoopReverse = 1;
804 if (strcmp(&argv[i][1],OPTION_NOSTDLIB) == 0) {
809 if (strcmp(&argv[i][1],OPTION_NOSTDINC) == 0) {
814 if (strcmp(&argv[i][1],OPTION_VERBOSE) == 0) {
819 if (!port->parseOption(&argc, argv, &i))
821 werror(W_UNKNOWN_OPTION,argv[i]);
829 /* these are undocumented options */
830 /* if preceded by '/' then turn off certain optmizations, used
831 for debugging only these are also the legacy options from
832 version 1.xx will be removed gradually.
833 It may be an absolute filename.
835 if ( *argv[i] == '/' && strlen(argv[i]) < 3) {
836 switch (argv[i][1]) {
839 optimize.ptrArithmetic=0;
843 switch (argv[i][2]) {
848 optimize.label4 = 0 ;
866 switch (argv[i][2]) {
868 optimize.loopInvariant = 0;
871 optimize.loopInduction = 0;
878 optimize.global_cse = 0;
885 /* if preceded by '-' then option */
886 if ( *argv[i] == '-' ) {
887 switch (argv[i][1]) {
898 /* Used to select the port */
899 if (_setPort(argv[i] + 2)) {
900 werror(W_UNSUPP_OPTION,"-m","Unrecognised processor");
905 werror(W_UNSUPP_OPTION,"-a","use --stack-auto instead");
909 werror(W_UNSUPP_OPTION,"-g","use --generic instead");
912 case 'X' : /* use external stack */
913 werror(W_UNSUPP_OPTION,"-X","use --xstack-loc instead");
917 werror(W_UNSUPP_OPTION,"-x","use --xstack instead");
920 case 'p' : /* stack pointer intial value */
922 werror(W_UNSUPP_OPTION,"-p","use --stack-loc instead");
926 werror(W_UNSUPP_OPTION,"-i","use --idata-loc instead");
930 werror(W_UNSUPP_OPTION,"-r","use --xdata-loc instead");
934 werror(W_UNSUPP_OPTION,"-s","use --code-loc instead");
942 werror(W_UNSUPP_OPTION,"-Y","use -I instead");
947 libPaths[nlibPaths++] = &argv[i][2];
949 libPaths[nlibPaths++] = argv[++i];
954 if (argv[i][2] == 'l') {
956 parseWithComma(linkOptions,&argv[i][3]);
958 parseWithComma(linkOptions,argv[++i]);
960 /* assembler options */
961 if (argv[i][2] == 'a') {
963 parseWithComma((char **)asmOptions,&argv[i][3]);
965 parseWithComma((char **)asmOptions,argv[++i]);
968 werror(W_UNKNOWN_OPTION,argv[i]);
985 /* preprocessor options */
989 _addToList(preArgv, "-M");
994 _addToList(preArgv, "-C");
1003 char sOpt = argv[i][1] ;
1006 if ( argv[i][2] == ' ' || argv[i][2] == '\0') {
1011 rest = &argv[i][2] ;
1013 if ( argv[i][1] == 'Y' )
1016 sprintf(buffer, "-%c%s", sOpt, rest);
1017 _addToList(preArgv, buffer);
1022 if (!port->parseOption(&argc, argv, &i))
1023 werror(W_UNKNOWN_OPTION,argv[i]);
1028 if (!port->parseOption(&argc, argv, &i)) {
1029 /* no option must be a filename */
1031 _processC1Arg(argv[i]);
1033 processFile(argv[i]);
1037 /* set up external stack location if not explicitly specified */
1038 if ( !options.xstack_loc )
1039 options.xstack_loc = options.xdata_loc ;
1041 /* if debug option is set the open the cdbFile */
1042 if (!options.nodebug && srcFileName) {
1043 sprintf(cdbfnbuf,"%s.cdb",srcFileName);
1044 if ((cdbFile = fopen(cdbfnbuf,"w")) == NULL)
1045 werror(E_FILE_OPEN_ERR,cdbfnbuf);
1047 /* add a module record */
1048 fprintf(cdbFile,"M:%s\n",moduleName);
1054 /*-----------------------------------------------------------------*/
1055 /* my_system - will call a program with arguments */
1056 /*-----------------------------------------------------------------*/
1057 char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
1058 int my_system (const char *cmd, char **cmd_argv)
1060 char *dir, *got= NULL; int i= 0;
1062 while (!got && try_dir[i])
1064 dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10);
1065 strcpy(dir, try_dir[i]);
1070 strcat(dir, ".exe");
1072 /* Mung slashes into backslashes to keep WIndoze happy. */
1088 if (access(dir, X_OK) == 0)
1097 char **pCmd = cmd_argv;
1100 printf("%s ", *pCmd);
1107 i= spawnv(P_WAIT,got,cmd_argv) == -1;
1109 i= spawnvp(P_WAIT,cmd,cmd_argv) == -1;
1111 perror("Cannot exec process ");
1118 /*-----------------------------------------------------------------*/
1119 /* linkEdit : - calls the linkage editor with options */
1120 /*-----------------------------------------------------------------*/
1121 static void linkEdit (char **envp)
1129 srcFileName = "temp";
1131 /* first we need to create the <filename>.lnk file */
1132 sprintf(buffer,"%s.lnk",srcFileName);
1133 if (!(lnkfile = fopen(buffer,"w"))) {
1134 werror(E_FILE_OPEN_ERR,buffer);
1138 /* now write the options */
1139 fprintf(lnkfile,"-mux%c\n", (options.out_fmt ? 's' : 'i'));
1141 /* if iram size specified */
1142 if (options.iram_size)
1143 fprintf(lnkfile,"-a 0x%04x\n",options.iram_size);
1145 /*if (options.debug) */
1146 fprintf(lnkfile,"-z\n");
1148 #define WRITE_SEG_LOC(N, L) \
1149 segName = strdup(N); \
1150 c = strtok(segName, " \t"); \
1151 fprintf (lnkfile,"-b %s = 0x%04x\n", c, L); \
1152 if (segName) { free(segName); }
1154 /* code segment start */
1155 WRITE_SEG_LOC(CODE_NAME, options.code_loc);
1157 /* data segment start */
1158 WRITE_SEG_LOC(DATA_NAME, options.data_loc);
1161 WRITE_SEG_LOC(XDATA_NAME, options. xdata_loc);
1164 WRITE_SEG_LOC(IDATA_NAME, options.idata_loc);
1166 /* bit segment start */
1167 WRITE_SEG_LOC(BIT_NAME, 0);
1169 /* add the extra linker options */
1170 for (i=0; linkOptions[i] ; i++)
1171 fprintf(lnkfile,"%s\n",linkOptions[i]);
1173 /* other library paths if specified */
1174 for (i = 0 ; i < nlibPaths ; i++ )
1175 fprintf (lnkfile,"-k %s\n",libPaths[i]);
1177 /* standard library path */
1178 if (!options.nostdlib) {
1179 if (IS_DS390_PORT) {
1182 switch(options.model)
1194 werror(W_UNKNOWN_MODEL, __FILE__, __LINE__);
1199 fprintf (lnkfile,"-k %s/%s\n",SDCC_LIB_DIR/*STD_LIB_PATH*/,c);
1201 /* standard library files */
1202 if (strcmp(port->target, "ds390")==0) {
1203 fprintf (lnkfile,"-l %s\n",STD_DS390_LIB);
1205 fprintf (lnkfile,"-l %s\n",STD_LIB);
1206 fprintf (lnkfile,"-l %s\n",STD_INT_LIB);
1207 fprintf (lnkfile,"-l %s\n",STD_LONG_LIB);
1208 fprintf (lnkfile,"-l %s\n",STD_FP_LIB);
1211 /* additional libraries if any */
1212 for (i = 0 ; i < nlibFiles; i++)
1213 fprintf (lnkfile,"-l %s\n",libFiles[i]);
1215 /* put in the object files */
1216 if (strcmp(srcFileName,"temp"))
1217 fprintf (lnkfile,"%s ",srcFileName);
1219 for (i = 0 ; i < nrelFiles ; i++ )
1220 fprintf (lnkfile,"%s\n",relFiles[i]);
1222 fprintf (lnkfile,"\n-e\n");
1225 buildCmdLine(buffer, argv, port->linker.cmd, srcFileName, NULL, NULL, NULL);
1227 if (options.verbose)
1228 printf ("sdcc: Calling linker...\n");
1229 if (my_system(argv[0], argv)) {
1230 perror("Cannot exec linker");
1234 if (strcmp(srcFileName,"temp") == 0) {
1235 /* rename "temp.cdb" to "firstRelFile.cdb" */
1236 char *f = strtok(strdup(relFiles[0]),".");
1237 f = strcat(f,".cdb");
1238 rename("temp.cdb",f);
1243 /*-----------------------------------------------------------------*/
1244 /* assemble - spawns the assembler with arguments */
1245 /*-----------------------------------------------------------------*/
1246 static void assemble (char **envp)
1248 char *argv[128]; /* assembler arguments */
1250 buildCmdLine(buffer, argv, port->assembler.cmd, srcFileName, NULL, NULL, asmOptions);
1252 if (my_system(argv[0], argv)) {
1253 perror("Cannot exec assember");
1260 /*-----------------------------------------------------------------*/
1261 /* preProcess - spawns the preprocessor with arguments */
1262 /*-----------------------------------------------------------------*/
1263 static int preProcess (char **envp)
1270 if (!options.c1mode) {
1271 /* if using external stack define the macro */
1272 if ( options.useXstack )
1273 _addToList(preArgv, "-DSDCC_USE_XSTACK");
1275 /* set the macro for stack autos */
1276 if ( options.stackAuto )
1277 _addToList(preArgv, "-DSDCC_STACK_AUTO");
1279 /* set the macro for stack autos */
1280 if ( options.stack10bit )
1281 _addToList(preArgv, "-DSDCC_STACK_TENBIT");
1283 /* set the macro for large model */
1284 switch(options.model)
1287 _addToList(preArgv, "-DSDCC_MODEL_LARGE");
1290 _addToList(preArgv, "-DSDCC_MODEL_SMALL");
1293 _addToList(preArgv, "-DSDCC_MODEL_COMPACT");
1296 _addToList(preArgv, "-DSDCC_MODEL_MEDIUM");
1299 _addToList(preArgv, "-DSDCC_MODEL_FLAT24");
1302 werror(W_UNKNOWN_MODEL, __FILE__, __LINE__);
1307 /* add port (processor information to processor */
1308 sprintf(procDef,"-DSDCC_%s",port->target);
1309 _addToList(preArgv,procDef);
1312 preOutName = strdup(tmpnam(NULL));
1314 buildCmdLine(buffer, argv, _preCmd, fullSrcFileName,
1315 preOutName, srcFileName, preArgv);
1317 if (options.verbose)
1318 printf ("sdcc: Calling preprocessor...\n");
1320 if (my_system(argv[0], argv)) {
1321 unlink (preOutName);
1322 perror("Cannot exec Preprocessor");
1330 preOutName = fullSrcFileName;
1333 yyin = fopen(preOutName, "r");
1335 perror("Preproc file not found\n");
1342 static void _findPort(int argc, char **argv)
1346 if (!strncmp(*argv, "-m", 2)) {
1347 _setPort(*argv + 2);
1353 /* Use the first in the list */
1359 * initialises and calls the parser
1362 int main ( int argc, char **argv , char **envp)
1364 /* turn all optimizations off by default */
1365 memset(&optimize,0,sizeof(struct optimize));
1367 /*printVersionInfo ();*/
1369 _findPort(argc, argv);
1370 /* Initalise the port. */
1374 setDefaultOptions();
1375 parseCmdLine(argc,argv);
1379 port->finaliseOptions();
1381 /* if no input then printUsage & exit */
1382 if ((!options.c1mode && !srcFileName && !nrelFiles) || (options.c1mode && !srcFileName && !options.out_name)) {
1395 if (options.verbose)
1396 printf ("sdcc: Generating code...\n");
1410 if (!options.c1mode)
1412 if (options.verbose)
1413 printf ("sdcc: Calling assembler...\n");
1428 if (!options.cc_only &&
1432 (srcFileName || nrelFiles)) {
1433 if (port->linker.do_link)
1434 port->linker.do_link();
1439 if (yyin && yyin != stdin)
1442 if (preOutName && !options.c1mode) {