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 -------------------------------------------------------------------------*/
29 /* This is a bit messy. We cant include unistd.h as it defines
30 'link' which we also use.
32 int access(const char *path, int mode);
34 int unlink(const char *path);
36 extern void initSymt ();
37 extern void initMem ();
38 extern void initExpr ();
39 extern void initiCode ();
40 extern void initCSupport ();
41 extern void initPeepHole ();
42 extern void createObject ();
43 extern int yyparse ();
45 extern struct value *constVal(char *s);
46 extern double floatFromVal(struct value *);
47 extern int fatalError ;
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;
69 //extern int wait (int *);
72 #define OPTION_LARGE_MODEL "-model-large"
73 #define OPTION_SMALL_MODEL "-model-small"
74 #define OPTION_FLAT24_MODEL "-model-flat24"
75 #define OPTION_STACK_AUTO "-stack-auto"
76 #define OPTION_XSTACK "-xstack"
77 #define OPTION_GENERIC "-generic"
78 #define OPTION_NO_GCSE "-nogcse"
79 #define OPTION_NO_LOOP_INV "-noinvariant"
80 #define OPTION_NO_LOOP_IND "-noinduction"
81 #define OPTION_NO_JTBOUND "-nojtbound"
82 #define OPTION_NO_LOOPREV "-noloopreverse"
83 #define OPTION_XREGS "-regextend"
84 #define OPTION_COMP_ONLY "-compile-only"
85 #define OPTION_DUMP_RAW "-dumpraw"
86 #define OPTION_DUMP_GCSE "-dumpgcse"
87 #define OPTION_DUMP_LOOP "-dumploop"
88 #define OPTION_DUMP_KILL "-dumpdeadcode"
89 #define OPTION_DUMP_RANGE "-dumpliverange"
90 #define OPTION_DUMP_PACK "-dumpregpack"
91 #define OPTION_DUMP_RASSGN "-dumpregassign"
92 #define OPTION_DUMP_ALL "-dumpall"
93 #define OPTION_XRAM_LOC "-xram-loc"
94 #define OPTION_IRAM_SIZE "-iram-size"
95 #define OPTION_XSTACK_LOC "-xstack-loc"
96 #define OPTION_CODE_LOC "-code-loc"
97 #define OPTION_STACK_LOC "-stack-loc"
98 #define OPTION_DATA_LOC "-data-loc"
99 #define OPTION_IDATA_LOC "-idata-loc"
100 #define OPTION_PEEP_FILE "-peep-file"
101 #define OPTION_LIB_PATH "-lib-path"
102 #define OPTION_INTLONG_RENT "-int-long-reent"
103 #define OPTION_FLOAT_RENT "-float-reent"
104 #define OPTION_OUT_FMT_IHX "-out-fmt-ihx"
105 #define OPTION_OUT_FMT_S19 "-out-fmt-s19"
106 #define OPTION_CYCLOMATIC "-cyclomatic"
107 #define OPTION_NOOVERLAY "-nooverlay"
108 #define OPTION_MAINRETURN "-main-return"
109 #define OPTION_NOPEEP "-no-peep"
110 #define OPTION_ASMPEEP "-peep-asm"
111 #define OPTION_DEBUG "-debug"
112 #define OPTION_VERSION "-version"
113 #define OPTION_STKAFTRDATA "-stack-after-data"
114 #define OPTION_PREPROC_ONLY "-preprocessonly"
115 #define OPTION_HELP "-help"
116 #define OPTION_CALLEE_SAVES "-callee-saves"
117 #define OPTION_NOREGPARMS "-noregparms"
119 static const char *_preCmd[] = {
120 "sdcpp", "-Wall", "-lang-c++", "-DSDCC=1",
121 "-I" SDCC_INCLUDE_DIR, "$l", "$1", "$2", NULL
124 extern PORT mcs51_port;
125 extern PORT z80_port;
126 extern PORT gbz80_port;
130 static PORT *_ports[] = {
136 #define NUM_PORTS (sizeof(_ports)/sizeof(_ports[0]))
138 /** Sets the port to the one given by the command line option.
139 @param The name minus the option (eg 'mcs51')
140 @return 0 on success.
142 static int _setPort(const char *name)
145 for (i=0; i<NUM_PORTS; i++) {
146 if (!strcmp(_ports[i]->target, name)) {
151 /* Error - didnt find */
155 static void _buildCmdLine(char *into, char **args, const char **cmds,
156 const char *p1, const char *p2,
157 const char *p3, const char **list)
159 const char *p, *from;
169 /* See if it has a '$' anywhere - if not, just copy */
170 if ((p = strchr(from, '$'))) {
171 strncpy(into, from, p - from);
188 const char **tmp = list;
192 into += strlen(into)+1;
205 if (strlen(into) == 0)
207 into += strlen(into)+1;
212 /*-----------------------------------------------------------------*/
213 /* printVersionInfo - prints the version info */
214 /*-----------------------------------------------------------------*/
215 void printVersionInfo ()
221 for (i=0; i<NUM_PORTS; i++)
222 fprintf(stderr, "%s%s", i==0 ? "" : "/", _ports[i]->target);
224 fprintf(stderr, " %s `"
238 /*-----------------------------------------------------------------*/
239 /* printUsage - prints command line syntax */
240 /*-----------------------------------------------------------------*/
245 "Usage : [options] filename\n"
247 "\t-m<proc> - Target processor <proc>. Default %s\n"
248 "\t Try --version for supported values of <proc>\n"
249 "\t--model-large - Large Model\n"
250 "\t--model-small - Small Model (default)\n"
251 "\t--stack-auto - Stack automatic variables\n"
252 "\t--xstack - Use external stack\n"
253 "\t--xram-loc <nnnn> - External Ram start location\n"
254 "\t--xstack-loc <nnnn> - Xternal Stack Location\n"
255 "\t--code-loc <nnnn> - Code Segment Location\n"
256 "\t--stack-loc <nnnn> - Stack pointer initial value\n"
257 "\t--data-loc <nnnn> - Direct data start location\n"
258 "\t--idata-loc <nnnn> - Indirect data start location\n"
259 "\t--iram-size <nnnn> - Internal Ram size\n"
260 "\t--nojtbound - Don't generate boundary check for jump tables\n"
261 "\t--generic - All unqualified ptrs converted to '_generic'\n"
262 "PreProcessor Options :-\n"
263 "\t-Dmacro - Define Macro\n"
264 "\t-Ipath - Include \"*.h\" path\n"
265 "Note: this is a complete list of options see docs for details\n",
271 /*-----------------------------------------------------------------*/
272 /* parseWithComma - separates string with comma */
273 /*-----------------------------------------------------------------*/
274 void parseWithComma (char **dest,char *src)
279 /* skip the initial white spaces */
280 while (isspace(*src)) src++;
294 /*-----------------------------------------------------------------*/
295 /* setDefaultOptions - sets the default options */
296 /*-----------------------------------------------------------------*/
297 static void setDefaultOptions()
301 for ( i = 0 ; i < 128 ; i++)
302 preArgv[i] = asmOptions [i] =
303 linkOptions[i] = relFiles[i] = libFiles[i] =
306 /* first the options part */
307 options.stack_loc = 0; /* stack pointer initialised to 0 */
308 options.xstack_loc= 0; /* xternal stack starts at 0 */
309 options.code_loc = 0; /* code starts at 0 */
310 options.data_loc = 0x0030; /* data starts at 0x0030 */
311 options.xdata_loc = 0;
312 options.idata_loc = 0x80;
313 options.genericPtr = 1; /* default on */
316 /* now for the optimizations */
317 /* turn on the everything */
318 optimize.global_cse = 1;
323 optimize.loopInvariant = 1;
324 optimize.loopInduction = 1;
326 port->setDefaultOptions();
329 /*-----------------------------------------------------------------*/
330 /* processFile - determines the type of file from the extension */
331 /*-----------------------------------------------------------------*/
332 static void processFile (char *s)
336 /* get the file extension */
337 fext = s + strlen(s);
338 while ((fext != s) && *fext != '.') fext--;
340 /* now if no '.' then we don't know what the file type is
341 so give a warning and return */
343 werror(W_UNKNOWN_FEXT,s);
347 /* otherwise depending on the file type */
348 if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0) {
349 /* source file name : not if we already have a
352 werror(W_TOO_MANY_SRC,s);
356 /* the only source file */
357 if (!(srcFile = fopen((fullSrcFileName = s),"r"))) {
358 werror(E_FILE_OPEN_ERR,s);
362 /* copy the file name into the buffer */
365 /* get rid of the "." */
367 ALLOC_ATOMIC(srcFileName,strlen(buffer)+1);
368 strcpy(srcFileName,buffer);
370 /* get rid of any path information
371 for the module name; do this by going
372 backwards till we get to either '/' or '\' or ':'
373 or start of buffer */
374 fext = buffer + strlen(buffer);
375 while (fext != buffer &&
376 *(fext -1) != '\\' &&
380 ALLOC_ATOMIC(moduleName,strlen(fext)+1);
381 strcpy(moduleName,fext);
386 /* if the extention is type .rel or .r or .REL or .R
387 addtional object file will be passed to the linker */
388 if (strcmp(fext,".r") == 0 || strcmp(fext,".rel") == 0 ||
389 strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0) {
391 relFiles[nrelFiles++] = s;
395 /* if .lib or .LIB */
396 if (strcmp(fext,".lib") == 0 || strcmp(fext,".LIB") == 0) {
397 libFiles[nlibFiles++] = s;
401 werror(W_UNKNOWN_FEXT,s);
405 static void _addToList(const char **list, const char *str)
407 /* This is the bad way to do things :) */
412 werror(E_OUT_OF_MEM,__FILE__, 0);
418 /*-----------------------------------------------------------------*/
419 /* parseCmdLine - parses the command line and sets the options */
420 /*-----------------------------------------------------------------*/
421 int parseCmdLine ( int argc, char **argv )
426 /* go thru all whole command line */
427 for ( i = 1; i < argc; i++ ) {
432 if (argv[i][0] == '-' && argv[i][1] == '-') {
434 if (strcmp(&argv[i][1],OPTION_HELP) == 0) {
439 if (strcmp(&argv[i][1],OPTION_XREGS) == 0) {
440 options.regExtend = 1;
444 if (strcmp(&argv[i][1],OPTION_LARGE_MODEL) == 0) {
445 options.model = MODEL_LARGE;
449 if (strcmp(&argv[i][1],OPTION_SMALL_MODEL) == 0) {
450 options.model = MODEL_SMALL;
454 if (strcmp(&argv[i][1],OPTION_FLAT24_MODEL) == 0) {
455 options.model = MODEL_FLAT24;
459 if (strcmp(&argv[i][1],OPTION_STACK_AUTO) == 0) {
460 options.stackAuto = 1;
464 if (strcmp(&argv[i][1],OPTION_DUMP_RAW) == 0) {
465 options.dump_raw = 1;
469 if (strcmp(&argv[i][1],OPTION_CYCLOMATIC) == 0) {
470 options.cyclomatic = 1;
474 if (strcmp(&argv[i][1],OPTION_DUMP_GCSE) == 0) {
475 options.dump_gcse = 1;
479 if (strcmp(&argv[i][1],OPTION_DUMP_LOOP) == 0) {
480 options.dump_loop = 1;
484 if (strcmp(&argv[i][1],OPTION_DUMP_KILL) == 0) {
485 options.dump_kill = 1;
489 if (strcmp(&argv[i][1],OPTION_INTLONG_RENT) == 0) {
490 options.intlong_rent = 1;
494 if (strcmp(&argv[i][1],OPTION_FLOAT_RENT) == 0) {
495 options.float_rent = 1;
499 if (strcmp(&argv[i][1],OPTION_DUMP_RANGE) == 0) {
500 options.dump_range = 1;
504 if (strcmp(&argv[i][1],OPTION_DUMP_PACK) == 0) {
505 options.dump_pack = 1;
509 if (strcmp(&argv[i][1],OPTION_DUMP_RASSGN) == 0) {
510 options.dump_rassgn = 1;
514 if (strcmp(&argv[i][1],OPTION_OUT_FMT_IHX) == 0) {
519 if (strcmp(&argv[i][1],OPTION_OUT_FMT_S19) == 0) {
524 if (strcmp(&argv[i][1],OPTION_NOOVERLAY) == 0) {
525 options.noOverlay = 1;
529 if (strcmp(&argv[i][1],OPTION_STKAFTRDATA) == 0) {
530 options.stackOnData = 1;
534 if (strcmp(&argv[i][1],OPTION_PREPROC_ONLY) == 0) {
540 if (strcmp(&argv[i][1],OPTION_DUMP_ALL) == 0) {
541 options.dump_rassgn =
547 options.dump_raw = 1;
551 if (strcmp(&argv[i][1],OPTION_COMP_ONLY) == 0) {
556 if (strcmp(&argv[i][1],OPTION_GENERIC) == 0) {
557 options.genericPtr = 1;
561 if (strcmp(&argv[i][1],OPTION_NOPEEP) == 0) {
566 if (strcmp(&argv[i][1],OPTION_ASMPEEP) == 0) {
571 if (strcmp(&argv[i][1],OPTION_DEBUG) == 0) {
576 if (strcmp(&argv[i][1],OPTION_NOREGPARMS) == 0) {
577 options.noregparms = 1;
581 if (strcmp(&argv[i][1],OPTION_PEEP_FILE) == 0) {
582 if (argv[i][1+strlen(OPTION_PEEP_FILE)])
584 &argv[i][1+strlen(OPTION_PEEP_FILE)];
586 options.peep_file = argv[++i];
590 if (strcmp(&argv[i][1],OPTION_LIB_PATH) == 0) {
591 if (argv[i][1+strlen(OPTION_LIB_PATH)])
592 libPaths[nlibPaths++] =
593 &argv[i][1+strlen(OPTION_PEEP_FILE)];
595 libPaths[nlibPaths++] = argv[++i];
599 if (strcmp(&argv[i][1],OPTION_XSTACK_LOC) == 0) {
601 if (argv[i][1+strlen(OPTION_XSTACK_LOC)])
603 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XSTACK_LOC)]));
606 (int) floatFromVal(constVal(argv[++i]));
610 if (strcmp(&argv[i][1],OPTION_XSTACK) == 0) {
611 options.useXstack = 1;
615 if (strcmp(&argv[i][1],OPTION_MAINRETURN) == 0) {
616 options.mainreturn = 1;
620 if (strcmp(&argv[i][1],OPTION_CALLEE_SAVES) == 0) {
621 if (argv[i][1+strlen(OPTION_CALLEE_SAVES)])
622 parseWithComma(options.calleeSaves
623 ,&argv[i][1+strlen(OPTION_CALLEE_SAVES)]);
625 parseWithComma(options.calleeSaves,argv[++i]);
629 if (strcmp(&argv[i][1],OPTION_STACK_LOC) == 0) {
631 if (argv[i][1+strlen(OPTION_STACK_LOC)])
633 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_STACK_LOC)]));
636 (int) floatFromVal(constVal(argv[++i]));
640 if (strcmp(&argv[i][1],OPTION_XRAM_LOC) == 0) {
642 if (argv[i][1+strlen(OPTION_XRAM_LOC)])
644 (unsigned int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XRAM_LOC)]));
647 (unsigned int) floatFromVal(constVal(argv[++i]));
651 if (strcmp(&argv[i][1],OPTION_IRAM_SIZE) == 0) {
653 if (argv[i][1+strlen(OPTION_IRAM_SIZE)])
655 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IRAM_SIZE)]));
658 (int) floatFromVal(constVal(argv[++i]));
662 if (strcmp(&argv[i][1],OPTION_VERSION) == 0) {
668 if (strcmp(&argv[i][1],OPTION_DATA_LOC) == 0) {
670 if (argv[i][1+strlen(OPTION_DATA_LOC)])
672 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_DATA_LOC)]));
675 (int) floatFromVal(constVal(argv[++i]));
679 if (strcmp(&argv[i][1],OPTION_IDATA_LOC) == 0) {
681 if (argv[i][1+strlen(OPTION_IDATA_LOC)])
683 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IDATA_LOC)]));
686 (int) floatFromVal(constVal(argv[++i]));
690 if (strcmp(&argv[i][1],OPTION_CODE_LOC) == 0) {
692 if (argv[i][1+strlen(OPTION_CODE_LOC)])
694 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_CODE_LOC)]));
697 (int) floatFromVal(constVal(argv[++i]));
702 if (strcmp(&argv[i][1],OPTION_NO_JTBOUND) == 0) {
703 optimize.noJTabBoundary = 1;
707 if (strcmp(&argv[i][1],OPTION_NO_GCSE) == 0) {
708 optimize.global_cse = 0;
712 if (strcmp(&argv[i][1],OPTION_NO_LOOP_INV) == 0) {
713 optimize.loopInvariant = 0;
717 if (strcmp(&argv[i][1],OPTION_NO_LOOP_IND) == 0) {
718 optimize.loopInduction = 0;
722 if (strcmp(&argv[i][1],OPTION_NO_LOOPREV) == 0) {
723 optimize.noLoopReverse = 1;
727 if (!port->parseOption(&argc, argv, &i))
729 werror(W_UNKNOWN_OPTION,argv[i]);
737 /* these are undocumented options */
738 /* if preceded by '/' then turn off certain optmizations, used
739 for debugging only these are also the legacy options from
740 version 1.xx will be removed gradually */
741 if ( *argv[i] == '/') {
742 switch (argv[i][1]) {
745 optimize.ptrArithmetic=0;
749 switch (argv[i][2]) {
754 optimize.label4 = 0 ;
772 switch (argv[i][2]) {
774 optimize.loopInvariant = 0;
777 optimize.loopInduction = 0;
784 optimize.global_cse = 0;
791 /* if preceded by '-' then option */
792 if ( *argv[i] == '-' ) {
793 switch (argv[i][1]) {
804 /* Used to select the port */
805 if (_setPort(argv[i] + 2)) {
806 werror(W_UNSUPP_OPTION,"-m","Unrecognised processor");
811 werror(W_UNSUPP_OPTION,"-a","use --stack-auto instead");
815 werror(W_UNSUPP_OPTION,"-g","use --generic instead");
818 case 'X' : /* use external stack */
819 werror(W_UNSUPP_OPTION,"-X","use --xstack-loc instead");
823 werror(W_UNSUPP_OPTION,"-x","use --xstack instead");
826 case 'p' : /* stack pointer intial value */
828 werror(W_UNSUPP_OPTION,"-p","use --stack-loc instead");
832 werror(W_UNSUPP_OPTION,"-i","use --idata-loc instead");
836 werror(W_UNSUPP_OPTION,"-r","use --xdata-loc instead");
840 werror(W_UNSUPP_OPTION,"-s","use --code-loc instead");
848 werror(W_UNSUPP_OPTION,"-Y","use -I instead");
853 libPaths[nlibPaths++] = &argv[i][2];
855 libPaths[nlibPaths++] = argv[++i];
860 if (argv[i][2] == 'l') {
862 parseWithComma(linkOptions,&argv[i][3]);
864 parseWithComma(linkOptions,argv[++i]);
866 /* assembler options */
867 if (argv[i][2] == 'a') {
869 parseWithComma((char **)asmOptions,&argv[i][3]);
871 parseWithComma((char **)asmOptions,argv[++i]);
874 werror(W_UNKNOWN_OPTION,argv[i]);
883 #if FEATURE_VERBOSE_EXEC
891 /* preprocessor options */
900 char sOpt = argv[i][1] ;
903 if ( argv[i][2] == ' ' || argv[i][2] == '\0') {
910 if ( argv[i][1] == 'Y' )
912 if (argv[i][1] == 'M')
915 sprintf(buffer, "-%c%s", sOpt, rest);
916 _addToList(preArgv, buffer);
921 if (!port->parseOption(&argc, argv, &i))
922 werror(W_UNKNOWN_OPTION,argv[i]);
927 if (!port->parseOption(&argc, argv, &i)) {
928 /* no option must be a filename */
929 processFile(argv[i]);
933 /* set up external stack location if not explicitly specified */
934 if ( !options.xstack_loc )
935 options.xstack_loc = options.xdata_loc ;
937 /* if debug option is set the open the cdbFile */
938 if (/* options.debug && */ srcFileName) {
939 sprintf(cdbfnbuf,"%s.cdb",srcFileName);
940 if ((cdbFile = fopen(cdbfnbuf,"w")) == NULL)
941 werror(E_FILE_OPEN_ERR,cdbfnbuf);
943 /* add a module record */
944 fprintf(cdbFile,"M:%s\n",moduleName);
947 port->finaliseOptions();
951 /*-----------------------------------------------------------------*/
952 /* my_system - will call a program with arguments */
953 /*-----------------------------------------------------------------*/
954 char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
955 int my_system (const char *cmd, char **cmd_argv)
958 char *dir, *got= NULL; int i= 0;
959 while (!got && try_dir[i]) {
960 dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10);
961 strcpy(dir, try_dir[i]); strcat(dir, "/"); strcat(dir, cmd);
962 if (access(dir, X_OK) == 0)
967 #if FEATURE_VERBOSE_EXEC
969 char **pCmd = cmd_argv;
971 printf("%s ", *pCmd);
978 i= spawnv(P_WAIT,got,cmd_argv) == -1;
980 i= spawnvp(P_WAIT,cmd,cmd_argv) == -1;
982 perror("Cannot exec process ");
989 /*-----------------------------------------------------------------*/
990 /* linkEdit : - calls the linkage editor with options */
991 /*-----------------------------------------------------------------*/
992 static void linkEdit (char **envp)
1000 srcFileName = "temp";
1002 /* first we need to create the <filename>.lnk file */
1003 sprintf(buffer,"%s.lnk",srcFileName);
1004 if (!(lnkfile = fopen(buffer,"w"))) {
1005 werror(E_FILE_OPEN_ERR,buffer);
1009 /* now write the options */
1010 fprintf(lnkfile,"-mux%c\n", (options.out_fmt ? 's' : 'i'));
1012 /* if iram size specified */
1013 if (options.iram_size)
1014 fprintf(lnkfile,"-a 0x%04x\n",options.iram_size);
1016 /*if (options.debug) */
1017 fprintf(lnkfile,"-z\n");
1019 #define WRITE_SEG_LOC(N, L) \
1020 segName = strdup(N); \
1021 c = strtok(segName, " \t"); \
1022 fprintf (lnkfile,"-b %s = 0x%04x\n", c, L); \
1023 if (segName) { free(segName); }
1025 /* code segment start */
1026 WRITE_SEG_LOC(CODE_NAME, options.code_loc);
1028 /* data segment start */
1029 WRITE_SEG_LOC(DATA_NAME, options.data_loc);
1032 WRITE_SEG_LOC(XDATA_NAME, options. xdata_loc);
1035 WRITE_SEG_LOC(IDATA_NAME, options.idata_loc);
1037 /* bit segment start */
1038 WRITE_SEG_LOC(BIT_NAME, 0);
1040 /* add the extra linker options */
1041 for (i=0; linkOptions[i] ; i++)
1042 fprintf(lnkfile,"%s\n",linkOptions[i]);
1044 /* standard library path */
1045 switch(options.model)
1057 werror(W_UNKNOWN_MODEL, __FILE__, __LINE__);
1061 fprintf (lnkfile,"-k %s/%s\n",SDCC_LIB_DIR/*STD_LIB_PATH*/,c);
1063 /* other library paths if specified */
1064 for (i = 0 ; i < nlibPaths ; i++ )
1065 fprintf (lnkfile,"-k %s\n",libPaths[i]);
1067 /* standard library files */
1068 fprintf (lnkfile,"-l %s\n",STD_LIB);
1069 fprintf (lnkfile,"-l %s\n",STD_INT_LIB);
1070 fprintf (lnkfile,"-l %s\n",STD_LONG_LIB);
1071 fprintf (lnkfile,"-l %s\n",STD_FP_LIB);
1073 /* additional libraries if any */
1074 for (i = 0 ; i < nlibFiles; i++)
1075 fprintf (lnkfile,"-l %s\n",libFiles[i]);
1077 /* put in the object files */
1078 if (strcmp(srcFileName,"temp"))
1079 fprintf (lnkfile,"%s ",srcFileName);
1081 for (i = 0 ; i < nrelFiles ; i++ )
1082 fprintf (lnkfile,"%s\n",relFiles[i]);
1084 fprintf (lnkfile,"\n-e\n");
1087 _buildCmdLine(buffer, argv, port->linker.cmd, srcFileName, NULL, NULL, NULL);
1089 /* call the linker */
1090 if (my_system(argv[0], argv)) {
1091 perror("Cannot exec linker");
1095 if (strcmp(srcFileName,"temp") == 0) {
1096 /* rename "temp.cdb" to "firstRelFile.cdb" */
1097 char *f = strtok(strdup(relFiles[0]),".");
1098 f = strcat(f,".cdb");
1099 rename("temp.cdb",f);
1104 /*-----------------------------------------------------------------*/
1105 /* assemble - spawns the assembler with arguments */
1106 /*-----------------------------------------------------------------*/
1107 static void assemble (char **envp)
1109 char *argv[128]; /* assembler arguments */
1111 _buildCmdLine(buffer, argv, port->assembler.cmd, srcFileName, NULL, NULL, asmOptions);
1113 if (my_system(argv[0], argv)) {
1114 perror("Cannot exec assember");
1121 /*-----------------------------------------------------------------*/
1122 /* preProcess - spawns the preprocessor with arguments */
1123 /*-----------------------------------------------------------------*/
1124 static int preProcess (char **envp)
1131 /* if using external stack define the macro */
1132 if ( options.useXstack )
1133 _addToList(preArgv, "-DSDCC_USE_XSTACK");
1135 /* set the macro for stack autos */
1136 if ( options.stackAuto )
1137 _addToList(preArgv, "-DSDCC_STACK_AUTO");
1139 /* set the macro for large model */
1140 switch(options.model)
1143 _addToList(preArgv, "-DSDCC_MODEL_LARGE");
1146 _addToList(preArgv, "-DSDCC_MODEL_SMALL");
1149 _addToList(preArgv, "-DSDCC_MODEL_FLAT24");
1152 werror(W_UNKNOWN_MODEL, __FILE__, __LINE__);
1157 /* add port (processor information to processor */
1158 sprintf(procDef,"-DSDCC_%s",port->target);
1159 _addToList(preArgv,procDef);
1162 preOutName = strdup(tmpnam(NULL));
1164 _buildCmdLine(buffer, argv, _preCmd, fullSrcFileName,
1165 preOutName, srcFileName, preArgv);
1167 if (my_system(argv[0], argv)) {
1168 unlink (preOutName);
1169 perror("Cannot exec Preprocessor");
1176 yyin = fopen(preOutName,"r");
1178 perror("Preproc file not found\n");
1185 static void _findPort(int argc, char **argv)
1189 if (!strncmp(*argv, "-m", 2)) {
1190 _setPort(*argv + 2);
1196 /* Use the first in the list */
1202 * initialises and calls the parser
1205 int main ( int argc, char **argv , char **envp)
1207 /* turn all optimizations off by default */
1208 memset(&optimize,0,sizeof(struct optimize));
1210 /*printVersionInfo ();*/
1212 _findPort(argc, argv);
1213 /* Initalise the port. */
1217 setDefaultOptions();
1218 parseCmdLine(argc,argv);
1220 /* if no input then printUsage & exit */
1221 if (!srcFileName && !nrelFiles) {
1249 if (!options.cc_only &&
1252 (srcFileName || nrelFiles))
1255 if (yyin && yyin != stdin)