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 char *preArgv[128] ;/* pre-processor arguments */
54 int preArgc = 0 ;/* pre-processor argument count */
56 struct optimize optimize ;
57 struct options options ;
58 char *VersionString = SDCC_VERSION_STR /*"Version 2.1.8a"*/;
59 short preProcOnly = 0;
61 char *linkOptions[128];
62 char *asmOptions[128];
69 bool verboseExec = FALSE;
70 //extern int wait (int *);
73 #define OPTION_LARGE_MODEL "-model-large"
74 #define OPTION_SMALL_MODEL "-model-small"
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 extern PORT mcs51_port;
120 extern PORT z80_port;
124 static PORT *_ports[] = {
129 #define NUM_PORTS (sizeof(_ports)/sizeof(_ports[0]))
131 /** Sets the port to the one given by the command line option.
132 @param The name minus the option (eg 'mcs51')
133 @return 0 on success.
135 static int _setPort(const char *name)
138 for (i=0; i<NUM_PORTS; i++) {
139 if (!strcmp(_ports[i]->target, name)) {
144 /* Error - didnt find */
148 /*-----------------------------------------------------------------*/
149 /* printVersionInfo - prints the version info */
150 /*-----------------------------------------------------------------*/
151 void printVersionInfo ()
157 for (i=0; i<NUM_PORTS; i++)
158 fprintf(stderr, "%s%s", i==0 ? "" : "/", _ports[i]->target);
160 fprintf(stderr, " %s `"
174 /*-----------------------------------------------------------------*/
175 /* printUsage - prints command line syntax */
176 /*-----------------------------------------------------------------*/
181 "Usage : [options] filename\n"
183 "\t-m<proc> - Target processor <proc>. Default %s\n"
184 "\t Try --version for supported values of <proc>\n"
185 "\t--model-large - Large Model\n"
186 "\t--model-small - Small Model (default)\n"
187 "\t--stack-auto - Stack automatic variables\n"
188 "\t--xstack - Use external stack\n"
189 "\t--xram-loc <nnnn> - External Ram start location\n"
190 "\t--xstack-loc <nnnn> - Xternal Stack Location\n"
191 "\t--code-loc <nnnn> - Code Segment Location\n"
192 "\t--stack-loc <nnnn> - Stack pointer initial value\n"
193 "\t--data-loc <nnnn> - Direct data start location\n"
194 "\t--idata-loc <nnnn> - Indirect data start location\n"
195 "\t--iram-size <nnnn> - Internal Ram size\n"
196 "\t--nojtbound - Don't generate boundary check for jump tables\n"
197 "\t--generic - All unqualified ptrs converted to '_generic'\n"
198 "PreProcessor Options :-\n"
199 "\t-Dmacro - Define Macro\n"
200 "\t-Ipath - Include \"*.h\" path\n"
201 "Note: this is a complete list of options see docs for details\n",
207 /*-----------------------------------------------------------------*/
208 /* parseWithComma - separates string with comma */
209 /*-----------------------------------------------------------------*/
210 void parseWithComma (char **dest,char *src)
215 /* skip the initial white spaces */
216 while (isspace(*src)) src++;
230 /*-----------------------------------------------------------------*/
231 /* setDefaultOptions - sets the default options */
232 /*-----------------------------------------------------------------*/
233 static void setDefaultOptions()
237 for ( i = 0 ; i < 128 ; i++)
238 preArgv[i] = linkOptions [i] =
239 asmOptions[i] = relFiles[i] = libFiles[i] =
241 preArgv[preArgc++] = "-version";
242 preArgv[preArgc++] = "-Wall";
243 preArgv[preArgc++] = "-lang-c++";
244 preArgv[preArgc++] = "-DSDCC=1";
245 preArgv[preArgc++] = "-I" SDCC_INCLUDE_DIR ;
247 /* first the options part */
248 options.stack_loc = 0; /* stack pointer initialised to 0 */
249 options.xstack_loc= 0; /* xternal stack starts at 0 */
250 options.code_loc = 0; /* code starts at 0 */
251 options.data_loc = 0x0030; /* data starts at 0x0030 */
252 options.xdata_loc = 0;
253 options.idata_loc = 0x80;
254 options.genericPtr = 1; /* default on */
257 /* now for the optimizations */
258 /* turn on the everything */
259 optimize.global_cse = 1;
264 optimize.loopInvariant = 1;
265 optimize.loopInduction = 1;
267 port->setDefaultOptions();
270 /*-----------------------------------------------------------------*/
271 /* processFile - determines the type of file from the extension */
272 /*-----------------------------------------------------------------*/
273 static void processFile (char *s)
277 /* get the file extension */
278 fext = s + strlen(s);
279 while ((fext != s) && *fext != '.') fext--;
281 /* now if no '.' then we don't know what the file type is
282 so give a warning and return */
284 werror(W_UNKNOWN_FEXT,s);
288 /* otherwise depending on the file type */
289 if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0) {
290 /* source file name : not if we already have a
293 werror(W_TOO_MANY_SRC,s);
297 /* the only source file */
298 if (!(srcFile = fopen((fullSrcFileName = s),"r"))) {
299 werror(E_FILE_OPEN_ERR,s);
303 /* copy the file name into the buffer */
306 /* get rid of the "." */
308 ALLOC_ATOMIC(srcFileName,strlen(buffer)+1);
309 strcpy(srcFileName,buffer);
311 /* get rid of any path information
312 for the module name; do this by going
313 backwards till we get to either '/' or '\' or ':'
314 or start of buffer */
315 fext = buffer + strlen(buffer);
316 while (fext != buffer &&
317 *(fext -1) != '\\' &&
321 ALLOC_ATOMIC(moduleName,strlen(fext)+1);
322 strcpy(moduleName,fext);
327 /* if the extention is type .rel or .r or .REL or .R
328 addtional object file will be passed to the linker */
329 if (strcmp(fext,".r") == 0 || strcmp(fext,".rel") == 0 ||
330 strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0) {
332 relFiles[nrelFiles++] = s;
336 /* if .lib or .LIB */
337 if (strcmp(fext,".lib") == 0 || strcmp(fext,".LIB") == 0) {
338 libFiles[nlibFiles++] = s;
342 werror(W_UNKNOWN_FEXT,s);
347 /*-----------------------------------------------------------------*/
348 /* parseCmdLine - parses the command line and sets the options */
349 /*-----------------------------------------------------------------*/
350 int parseCmdLine ( int argc, char **argv )
355 /* go thru all whole command line */
356 for ( i = 1; i < argc; i++ ) {
361 if (argv[i][0] == '-' && argv[i][1] == '-') {
363 if (strcmp(&argv[i][1],OPTION_HELP) == 0) {
368 if (strcmp(&argv[i][1],OPTION_XREGS) == 0) {
369 options.regExtend = 1;
373 if (strcmp(&argv[i][1],OPTION_LARGE_MODEL) == 0) {
378 if (strcmp(&argv[i][1],OPTION_SMALL_MODEL) == 0) {
383 if (strcmp(&argv[i][1],OPTION_STACK_AUTO) == 0) {
384 options.stackAuto = 1;
388 if (strcmp(&argv[i][1],OPTION_DUMP_RAW) == 0) {
389 options.dump_raw = 1;
393 if (strcmp(&argv[i][1],OPTION_CYCLOMATIC) == 0) {
394 options.cyclomatic = 1;
398 if (strcmp(&argv[i][1],OPTION_DUMP_GCSE) == 0) {
399 options.dump_gcse = 1;
403 if (strcmp(&argv[i][1],OPTION_DUMP_LOOP) == 0) {
404 options.dump_loop = 1;
408 if (strcmp(&argv[i][1],OPTION_DUMP_KILL) == 0) {
409 options.dump_kill = 1;
413 if (strcmp(&argv[i][1],OPTION_INTLONG_RENT) == 0) {
414 options.intlong_rent = 1;
418 if (strcmp(&argv[i][1],OPTION_FLOAT_RENT) == 0) {
419 options.float_rent = 1;
423 if (strcmp(&argv[i][1],OPTION_DUMP_RANGE) == 0) {
424 options.dump_range = 1;
428 if (strcmp(&argv[i][1],OPTION_DUMP_PACK) == 0) {
429 options.dump_pack = 1;
433 if (strcmp(&argv[i][1],OPTION_DUMP_RASSGN) == 0) {
434 options.dump_rassgn = 1;
438 if (strcmp(&argv[i][1],OPTION_OUT_FMT_IHX) == 0) {
443 if (strcmp(&argv[i][1],OPTION_OUT_FMT_S19) == 0) {
448 if (strcmp(&argv[i][1],OPTION_NOOVERLAY) == 0) {
449 options.noOverlay = 1;
453 if (strcmp(&argv[i][1],OPTION_STKAFTRDATA) == 0) {
454 options.stackOnData = 1;
458 if (strcmp(&argv[i][1],OPTION_PREPROC_ONLY) == 0) {
464 if (strcmp(&argv[i][1],OPTION_DUMP_ALL) == 0) {
465 options.dump_rassgn =
471 options.dump_raw = 1;
475 if (strcmp(&argv[i][1],OPTION_COMP_ONLY) == 0) {
480 if (strcmp(&argv[i][1],OPTION_GENERIC) == 0) {
481 options.genericPtr = 1;
485 if (strcmp(&argv[i][1],OPTION_NOPEEP) == 0) {
490 if (strcmp(&argv[i][1],OPTION_ASMPEEP) == 0) {
495 if (strcmp(&argv[i][1],OPTION_DEBUG) == 0) {
500 if (strcmp(&argv[i][1],OPTION_NOREGPARMS) == 0) {
501 options.noregparms = 1;
505 if (strcmp(&argv[i][1],OPTION_PEEP_FILE) == 0) {
506 if (argv[i][1+strlen(OPTION_PEEP_FILE)])
508 &argv[i][1+strlen(OPTION_PEEP_FILE)];
510 options.peep_file = argv[++i];
514 if (strcmp(&argv[i][1],OPTION_LIB_PATH) == 0) {
515 if (argv[i][1+strlen(OPTION_LIB_PATH)])
516 libPaths[nlibPaths++] =
517 &argv[i][1+strlen(OPTION_PEEP_FILE)];
519 libPaths[nlibPaths++] = argv[++i];
523 if (strcmp(&argv[i][1],OPTION_XSTACK_LOC) == 0) {
525 if (argv[i][1+strlen(OPTION_XSTACK_LOC)])
527 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XSTACK_LOC)]));
530 (int) floatFromVal(constVal(argv[++i]));
534 if (strcmp(&argv[i][1],OPTION_XSTACK) == 0) {
535 options.useXstack = 1;
539 if (strcmp(&argv[i][1],OPTION_MAINRETURN) == 0) {
540 options.mainreturn = 1;
544 if (strcmp(&argv[i][1],OPTION_CALLEE_SAVES) == 0) {
545 if (argv[i][1+strlen(OPTION_CALLEE_SAVES)])
546 parseWithComma(options.calleeSaves
547 ,&argv[i][1+strlen(OPTION_CALLEE_SAVES)]);
549 parseWithComma(options.calleeSaves,argv[++i]);
553 if (strcmp(&argv[i][1],OPTION_STACK_LOC) == 0) {
555 if (argv[i][1+strlen(OPTION_STACK_LOC)])
557 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_STACK_LOC)]));
560 (int) floatFromVal(constVal(argv[++i]));
564 if (strcmp(&argv[i][1],OPTION_XRAM_LOC) == 0) {
566 if (argv[i][1+strlen(OPTION_XRAM_LOC)])
568 (unsigned int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XRAM_LOC)]));
571 (unsigned int) floatFromVal(constVal(argv[++i]));
575 if (strcmp(&argv[i][1],OPTION_IRAM_SIZE) == 0) {
577 if (argv[i][1+strlen(OPTION_IRAM_SIZE)])
579 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IRAM_SIZE)]));
582 (int) floatFromVal(constVal(argv[++i]));
586 if (strcmp(&argv[i][1],OPTION_VERSION) == 0) {
592 if (strcmp(&argv[i][1],OPTION_DATA_LOC) == 0) {
594 if (argv[i][1+strlen(OPTION_DATA_LOC)])
596 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_DATA_LOC)]));
599 (int) floatFromVal(constVal(argv[++i]));
603 if (strcmp(&argv[i][1],OPTION_IDATA_LOC) == 0) {
605 if (argv[i][1+strlen(OPTION_IDATA_LOC)])
607 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IDATA_LOC)]));
610 (int) floatFromVal(constVal(argv[++i]));
614 if (strcmp(&argv[i][1],OPTION_CODE_LOC) == 0) {
616 if (argv[i][1+strlen(OPTION_CODE_LOC)])
618 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_CODE_LOC)]));
621 (int) floatFromVal(constVal(argv[++i]));
626 if (strcmp(&argv[i][1],OPTION_NO_JTBOUND) == 0) {
627 optimize.noJTabBoundary = 1;
631 if (strcmp(&argv[i][1],OPTION_NO_GCSE) == 0) {
632 optimize.global_cse = 0;
636 if (strcmp(&argv[i][1],OPTION_NO_LOOP_INV) == 0) {
637 optimize.loopInvariant = 0;
641 if (strcmp(&argv[i][1],OPTION_NO_LOOP_IND) == 0) {
642 optimize.loopInduction = 0;
646 if (strcmp(&argv[i][1],OPTION_NO_LOOPREV) == 0) {
647 optimize.noLoopReverse = 1;
651 if (!port->parseOption(&argc, argv))
652 werror(W_UNKNOWN_OPTION,argv[i]);
655 /* these are undocumented options */
656 /* if preceded by '/' then turn off certain optmizations, used
657 for debugging only these are also the legacy options from
658 version 1.xx will be removed gradually */
659 if ( *argv[i] == '/') {
660 switch (argv[i][1]) {
663 optimize.ptrArithmetic=0;
667 switch (argv[i][2]) {
672 optimize.label4 = 0 ;
690 switch (argv[i][2]) {
692 optimize.loopInvariant = 0;
695 optimize.loopInduction = 0;
702 optimize.global_cse = 0;
709 /* if preceded by '-' then option */
710 if ( *argv[i] == '-' ) {
711 switch (argv[i][1]) {
722 /* Used to select the port */
723 if (_setPort(argv[i] + 2)) {
724 werror(W_UNSUPP_OPTION,"-m","Unrecognised processor");
729 werror(W_UNSUPP_OPTION,"-a","use --stack-auto instead");
733 werror(W_UNSUPP_OPTION,"-g","use --generic instead");
736 case 'X' : /* use external stack */
737 werror(W_UNSUPP_OPTION,"-X","use --xstack-loc instead");
741 werror(W_UNSUPP_OPTION,"-x","use --xstack instead");
744 case 'p' : /* stack pointer intial value */
746 werror(W_UNSUPP_OPTION,"-p","use --stack-loc instead");
750 werror(W_UNSUPP_OPTION,"-i","use --idata-loc instead");
754 werror(W_UNSUPP_OPTION,"-r","use --xdata-loc instead");
758 werror(W_UNSUPP_OPTION,"-s","use --code-loc instead");
766 werror(W_UNSUPP_OPTION,"-Y","use -I instead");
771 libPaths[nlibPaths++] = &argv[i][2];
773 libPaths[nlibPaths++] = argv[++i];
778 if (argv[i][2] == 'l') {
780 parseWithComma(linkOptions,&argv[i][3]);
782 parseWithComma(linkOptions,argv[++i]);
784 /* assembler options */
785 if (argv[i][2] == 'a') {
787 parseWithComma(asmOptions,&argv[i][3]);
789 parseWithComma(asmOptions,argv[++i]);
792 werror(W_UNKNOWN_OPTION,argv[i]);
801 #if FEATURE_VERBOSE_EXEC
809 /* preprocessor options */
818 char sOpt = argv[i][1] ;
821 if ( argv[i][2] == ' ' || argv[i][2] == '\0') {
828 /* increase allocation for preprocessor argv
829 if (!(preArgv = realloc(preArgv,(preArgc+1)*sizeof(char **)))) {
830 werror (E_OUT_OF_MEM);
833 if ( argv[i][1] == 'Y' )
835 if (argv[i][1] == 'M')
838 if (!(preArgv[preArgc] = GC_malloc(strlen(rest)+3))) {
839 werror(E_OUT_OF_MEM,__FILE__,strlen(rest)+3);
843 sprintf(preArgv[preArgc],"-%c%s",sOpt,rest);
849 if (!port->parseOption(&argc, argv))
850 werror(W_UNKNOWN_OPTION,argv[i]);
855 if (!port->parseOption(&argc, argv)) {
856 /* no option must be a filename */
857 processFile(argv[i]);
861 /* set up external stack location if not explicitly specified */
862 if ( !options.xstack_loc )
863 options.xstack_loc = options.xdata_loc ;
865 /* if debug option is set the open the cdbFile */
866 if (/* options.debug && */ srcFileName) {
867 sprintf(cdbfnbuf,"%s.cdb",srcFileName);
868 if ((cdbFile = fopen(cdbfnbuf,"w")) == NULL)
869 werror(E_FILE_OPEN_ERR,cdbfnbuf);
871 /* add a module record */
872 fprintf(cdbFile,"M:%s\n",moduleName);
875 port->finaliseOptions();
879 /*-----------------------------------------------------------------*/
880 /* my_system - will call a program with arguments */
881 /*-----------------------------------------------------------------*/
882 char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
883 int my_system (const char *cmd, char **cmd_argv)
886 char *dir, *got= NULL; int i= 0;
887 while (!got && try_dir[i]) {
888 dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10);
889 strcpy(dir, try_dir[i]); strcat(dir, "/"); strcat(dir, cmd);
890 if (access(dir, X_OK) == 0)
895 #if FEATURE_VERBOSE_EXEC
897 char **pCmd = cmd_argv;
899 printf("%s ", *pCmd);
906 i= spawnv(P_WAIT,got,cmd_argv) == -1;
908 i= spawnvp(P_WAIT,cmd,cmd_argv) == -1;
910 perror("Cannot exec process ");
917 /*-----------------------------------------------------------------*/
918 /* linkEdit : - calls the linkage editor with options */
919 /*-----------------------------------------------------------------*/
920 static void linkEdit (char **envp)
926 srcFileName = "temp";
928 /* first we need to create the <filename>.lnk file */
929 sprintf(buffer,"%s.lnk",srcFileName);
930 if (!(lnkfile = fopen(buffer,"w"))) {
931 werror(E_FILE_OPEN_ERR,buffer);
935 /* now write the options */
936 fprintf(lnkfile,"-mux%c\n", (options.out_fmt ? 's' : 'i'));
938 /* if iram size specified */
939 if (options.iram_size)
940 fprintf(lnkfile,"-a 0x%04x\n",options.iram_size);
942 /*if (options.debug) */
943 fprintf(lnkfile,"-z\n");
944 /* code segment start */
945 fprintf (lnkfile,"-b CODE = 0x%04x\n",options.code_loc);
946 /* data segment start */
947 fprintf (lnkfile,"-b DSEG = 0x%04x\n",options.data_loc);
949 fprintf (lnkfile,"-b XSEG = 0x%04x\n",options.xdata_loc);
951 fprintf (lnkfile,"-b ISEG = 0x%04x\n",options.idata_loc);
952 /* bit segment start */
953 fprintf (lnkfile,"-b BSEG = 0x%04x\n",0);
955 /* add the extra linker options */
956 for (i=0; linkOptions[i] ; i++)
957 fprintf(lnkfile,"%s\n",linkOptions[i]);
959 /* standard library path */
960 fprintf (lnkfile,"-k %s/%s\n",SDCC_LIB_DIR/*STD_LIB_PATH*/,
961 ( (options.model==0) ? "small": "large"));
963 /* other library paths if specified */
964 for (i = 0 ; i < nlibPaths ; i++ )
965 fprintf (lnkfile,"-k %s\n",libPaths[i]);
967 /* standard library files */
968 fprintf (lnkfile,"-l %s\n",STD_LIB);
969 fprintf (lnkfile,"-l %s\n",STD_INT_LIB);
970 fprintf (lnkfile,"-l %s\n",STD_LONG_LIB);
971 fprintf (lnkfile,"-l %s\n",STD_FP_LIB);
973 /* additional libraries if any */
974 for (i = 0 ; i < nlibFiles; i++)
975 fprintf (lnkfile,"-l %s\n",libFiles[i]);
977 /* put in the object files */
978 if (strcmp(srcFileName,"temp"))
979 fprintf (lnkfile,"%s ",srcFileName);
981 for (i = 0 ; i < nrelFiles ; i++ )
982 fprintf (lnkfile,"%s\n",relFiles[i]);
984 fprintf (lnkfile,"\n-e\n");
987 /* call the linker */
988 lnkArgs[0] = "aslink";
990 lnkArgs[2] = srcFileName;
993 if (my_system("aslink",lnkArgs)) {
994 perror("Cannot exec linker");
998 if (strcmp(srcFileName,"temp") == 0) {
999 /* rename "temp.cdb" to "firstRelFile.cdb" */
1000 char *f = strtok(strdup(relFiles[0]),".");
1001 f = strcat(f,".cdb");
1002 rename("temp.cdb",f);
1007 /*-----------------------------------------------------------------*/
1008 /* assemble - spawns the assembler with arguments */
1009 /*-----------------------------------------------------------------*/
1010 static void assemble (char **envp)
1012 char *asmArgs[128]; /* assembler arguments */
1013 /* PENDING: A bit messy */
1018 asmArgs[0] = port->assembler.exec_name;
1020 asmArgs[1] = port->assembler.debug_opts;
1022 /* add the extra options if any */
1023 for (; asmOptions[i-2] ; i++)
1024 asmArgs[i] = asmOptions[i-2];
1026 if (port->assembler.requires_output_name) {
1027 sprintf(buffer2, srcFileName);
1028 strcat(buffer2, ".o");
1029 asmArgs[i++] = buffer2;
1032 /* create the assembler file name */
1033 sprintf (buffer, srcFileName);
1034 strcat (buffer, ".asm");
1035 asmArgs[i++] = buffer;
1037 asmArgs[i] = 0; /* end of args */
1039 if (my_system(port->assembler.exec_name, asmArgs)) {
1040 perror("Cannot exec linker");
1045 /*-----------------------------------------------------------------*/
1046 /* preProcess - spawns the preprocessor with arguments */
1047 /*-----------------------------------------------------------------*/
1048 static int preProcess (char **envp)
1051 /* if using external stack define the macro */
1052 if ( options.useXstack )
1053 preArgv[preArgc++] = "-DSDCC_USE_XSTACK" ;
1055 /* set the macro for stack autos */
1056 if ( options.stackAuto )
1057 preArgv[preArgc++] = "-DSDCC_STACK_AUTO";
1059 /* set the macro for large model */
1060 if ( options.model )
1061 preArgv[preArgc++] = "-DSDCC_MODEL_LARGE" ;
1063 preArgv[preArgc++] = "-DSDCC_MODEL_SMALL" ;
1065 preArgv[preArgc++] = fullSrcFileName ;
1067 preArgv[preArgc++] = preOutName = strdup(tmpnam(NULL));
1068 preArgv[preArgc] = NULL;
1070 preArgv[0] = "sdcpp";
1072 if (my_system("sdcpp",preArgv)) {
1073 unlink (preOutName);
1074 perror("Cannot exec Preprocessor");
1081 yyin = fopen(preOutName,"r");
1083 perror("Preproc file not found\n");
1090 static void _findPort(int argc, char **argv)
1094 if (!strncmp(*argv, "-m", 2)) {
1095 _setPort(*argv + 2);
1101 /* Use the first in the list */
1107 * initialises and calls the parser
1110 int main ( int argc, char **argv , char **envp)
1112 /* turn all optimizations off by default */
1113 memset(&optimize,0,sizeof(struct optimize));
1115 /*printVersionInfo ();*/
1117 _findPort(argc, argv);
1118 setDefaultOptions();
1119 parseCmdLine(argc,argv);
1121 /* if no input then printUsage & exit */
1122 if (!srcFileName && !nrelFiles) {
1149 if (!options.cc_only &&
1152 (srcFileName || nrelFiles))
1155 if (yyin && yyin != stdin)