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 ()
156 "SDCC : MCU 8051 %s "
170 /*-----------------------------------------------------------------*/
171 /* printUsage - prints command line syntax */
172 /*-----------------------------------------------------------------*/
177 "Usage : [options] filename\n"
179 "\t--model-large - Large Model\n"
180 "\t--model-small - Small Model (default)\n"
181 "\t--stack-auto - Stack automatic variables\n"
182 "\t--xstack - Use external stack\n"
183 "\t--xram-loc <nnnn> - External Ram start location\n"
184 "\t--xstack-loc <nnnn> - Xternal Stack Location\n"
185 "\t--code-loc <nnnn> - Code Segment Location\n"
186 "\t--stack-loc <nnnn> - Stack pointer initial value\n"
187 "\t--data-loc <nnnn> - Direct data start location\n"
188 "\t--idata-loc <nnnn> - Indirect data start location\n"
189 "\t--iram-size <nnnn> - Internal Ram size\n"
190 "\t--nojtbound - Don't generate boundary check for jump tables\n"
191 "\t--generic - All unqualified ptrs converted to '_generic'\n"
192 "PreProcessor Options :-\n"
193 "\t-Dmacro - Define Macro\n"
194 "\t-Ipath - Include \"*.h\" path\n"
195 "Note: this is a complete list of options see docs for details\n");
199 /*-----------------------------------------------------------------*/
200 /* parseWithComma - separates string with comma */
201 /*-----------------------------------------------------------------*/
202 void parseWithComma (char **dest,char *src)
207 /* skip the initial white spaces */
208 while (isspace(*src)) src++;
222 /*-----------------------------------------------------------------*/
223 /* setDefaultOptions - sets the default options */
224 /*-----------------------------------------------------------------*/
225 static void setDefaultOptions()
229 for ( i = 0 ; i < 128 ; i++)
230 preArgv[i] = linkOptions [i] =
231 asmOptions[i] = relFiles[i] = libFiles[i] =
233 preArgv[preArgc++] = "-version";
234 preArgv[preArgc++] = "-Wall";
235 preArgv[preArgc++] = "-lang-c++";
236 preArgv[preArgc++] = "-DSDCC=1";
237 preArgv[preArgc++] = "-I" SDCC_INCLUDE_DIR ;
239 /* first the options part */
240 options.stack_loc = 0; /* stack pointer initialised to 0 */
241 options.xstack_loc= 0; /* xternal stack starts at 0 */
242 options.code_loc = 0; /* code starts at 0 */
243 options.data_loc = 0x0030; /* data starts at 0x0030 */
244 options.xdata_loc = 0;
245 options.idata_loc = 0x80;
246 options.genericPtr = 1; /* default on */
249 /* now for the optimizations */
250 /* turn on the everything */
251 optimize.global_cse = 1;
256 optimize.loopInvariant = 1;
257 optimize.loopInduction = 1;
259 port->setDefaultOptions();
262 /*-----------------------------------------------------------------*/
263 /* processFile - determines the type of file from the extension */
264 /*-----------------------------------------------------------------*/
265 static void processFile (char *s)
269 /* get the file extension */
270 fext = s + strlen(s);
271 while ((fext != s) && *fext != '.') fext--;
273 /* now if no '.' then we don't know what the file type is
274 so give a warning and return */
276 werror(W_UNKNOWN_FEXT,s);
280 /* otherwise depending on the file type */
281 if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0) {
282 /* source file name : not if we already have a
285 werror(W_TOO_MANY_SRC,s);
289 /* the only source file */
290 if (!(srcFile = fopen((fullSrcFileName = s),"r"))) {
291 werror(E_FILE_OPEN_ERR,s);
295 /* copy the file name into the buffer */
298 /* get rid of the "." */
300 ALLOC_ATOMIC(srcFileName,strlen(buffer)+1);
301 strcpy(srcFileName,buffer);
303 /* get rid of any path information
304 for the module name; do this by going
305 backwards till we get to either '/' or '\' or ':'
306 or start of buffer */
307 fext = buffer + strlen(buffer);
308 while (fext != buffer &&
309 *(fext -1) != '\\' &&
313 ALLOC_ATOMIC(moduleName,strlen(fext)+1);
314 strcpy(moduleName,fext);
319 /* if the extention is type .rel or .r or .REL or .R
320 addtional object file will be passed to the linker */
321 if (strcmp(fext,".r") == 0 || strcmp(fext,".rel") == 0 ||
322 strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0) {
324 relFiles[nrelFiles++] = s;
328 /* if .lib or .LIB */
329 if (strcmp(fext,".lib") == 0 || strcmp(fext,".LIB") == 0) {
330 libFiles[nlibFiles++] = s;
334 werror(W_UNKNOWN_FEXT,s);
339 /*-----------------------------------------------------------------*/
340 /* parseCmdLine - parses the command line and sets the options */
341 /*-----------------------------------------------------------------*/
342 int parseCmdLine ( int argc, char **argv )
347 /* go thru all whole command line */
348 for ( i = 1; i < argc; i++ ) {
353 if (argv[i][0] == '-' && argv[i][1] == '-') {
355 if (strcmp(&argv[i][1],OPTION_HELP) == 0) {
360 if (strcmp(&argv[i][1],OPTION_XREGS) == 0) {
361 options.regExtend = 1;
365 if (strcmp(&argv[i][1],OPTION_LARGE_MODEL) == 0) {
370 if (strcmp(&argv[i][1],OPTION_SMALL_MODEL) == 0) {
375 if (strcmp(&argv[i][1],OPTION_STACK_AUTO) == 0) {
376 options.stackAuto = 1;
380 if (strcmp(&argv[i][1],OPTION_DUMP_RAW) == 0) {
381 options.dump_raw = 1;
385 if (strcmp(&argv[i][1],OPTION_CYCLOMATIC) == 0) {
386 options.cyclomatic = 1;
390 if (strcmp(&argv[i][1],OPTION_DUMP_GCSE) == 0) {
391 options.dump_gcse = 1;
395 if (strcmp(&argv[i][1],OPTION_DUMP_LOOP) == 0) {
396 options.dump_loop = 1;
400 if (strcmp(&argv[i][1],OPTION_DUMP_KILL) == 0) {
401 options.dump_kill = 1;
405 if (strcmp(&argv[i][1],OPTION_INTLONG_RENT) == 0) {
406 options.intlong_rent = 1;
410 if (strcmp(&argv[i][1],OPTION_FLOAT_RENT) == 0) {
411 options.float_rent = 1;
415 if (strcmp(&argv[i][1],OPTION_DUMP_RANGE) == 0) {
416 options.dump_range = 1;
420 if (strcmp(&argv[i][1],OPTION_DUMP_PACK) == 0) {
421 options.dump_pack = 1;
425 if (strcmp(&argv[i][1],OPTION_DUMP_RASSGN) == 0) {
426 options.dump_rassgn = 1;
430 if (strcmp(&argv[i][1],OPTION_OUT_FMT_IHX) == 0) {
435 if (strcmp(&argv[i][1],OPTION_OUT_FMT_S19) == 0) {
440 if (strcmp(&argv[i][1],OPTION_NOOVERLAY) == 0) {
441 options.noOverlay = 1;
445 if (strcmp(&argv[i][1],OPTION_STKAFTRDATA) == 0) {
446 options.stackOnData = 1;
450 if (strcmp(&argv[i][1],OPTION_PREPROC_ONLY) == 0) {
456 if (strcmp(&argv[i][1],OPTION_DUMP_ALL) == 0) {
457 options.dump_rassgn =
463 options.dump_raw = 1;
467 if (strcmp(&argv[i][1],OPTION_COMP_ONLY) == 0) {
472 if (strcmp(&argv[i][1],OPTION_GENERIC) == 0) {
473 options.genericPtr = 1;
477 if (strcmp(&argv[i][1],OPTION_NOPEEP) == 0) {
482 if (strcmp(&argv[i][1],OPTION_ASMPEEP) == 0) {
487 if (strcmp(&argv[i][1],OPTION_DEBUG) == 0) {
492 if (strcmp(&argv[i][1],OPTION_NOREGPARMS) == 0) {
493 options.noregparms = 1;
497 if (strcmp(&argv[i][1],OPTION_PEEP_FILE) == 0) {
498 if (argv[i][1+strlen(OPTION_PEEP_FILE)])
500 &argv[i][1+strlen(OPTION_PEEP_FILE)];
502 options.peep_file = argv[++i];
506 if (strcmp(&argv[i][1],OPTION_LIB_PATH) == 0) {
507 if (argv[i][1+strlen(OPTION_LIB_PATH)])
508 libPaths[nlibPaths++] =
509 &argv[i][1+strlen(OPTION_PEEP_FILE)];
511 libPaths[nlibPaths++] = argv[++i];
515 if (strcmp(&argv[i][1],OPTION_XSTACK_LOC) == 0) {
517 if (argv[i][1+strlen(OPTION_XSTACK_LOC)])
519 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XSTACK_LOC)]));
522 (int) floatFromVal(constVal(argv[++i]));
526 if (strcmp(&argv[i][1],OPTION_XSTACK) == 0) {
527 options.useXstack = 1;
531 if (strcmp(&argv[i][1],OPTION_MAINRETURN) == 0) {
532 options.mainreturn = 1;
536 if (strcmp(&argv[i][1],OPTION_CALLEE_SAVES) == 0) {
537 if (argv[i][1+strlen(OPTION_CALLEE_SAVES)])
538 parseWithComma(options.calleeSaves
539 ,&argv[i][1+strlen(OPTION_CALLEE_SAVES)]);
541 parseWithComma(options.calleeSaves,argv[++i]);
545 if (strcmp(&argv[i][1],OPTION_STACK_LOC) == 0) {
547 if (argv[i][1+strlen(OPTION_STACK_LOC)])
549 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_STACK_LOC)]));
552 (int) floatFromVal(constVal(argv[++i]));
556 if (strcmp(&argv[i][1],OPTION_XRAM_LOC) == 0) {
558 if (argv[i][1+strlen(OPTION_XRAM_LOC)])
560 (unsigned int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XRAM_LOC)]));
563 (unsigned int) floatFromVal(constVal(argv[++i]));
567 if (strcmp(&argv[i][1],OPTION_IRAM_SIZE) == 0) {
569 if (argv[i][1+strlen(OPTION_IRAM_SIZE)])
571 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IRAM_SIZE)]));
574 (int) floatFromVal(constVal(argv[++i]));
578 if (strcmp(&argv[i][1],OPTION_VERSION) == 0) {
584 if (strcmp(&argv[i][1],OPTION_DATA_LOC) == 0) {
586 if (argv[i][1+strlen(OPTION_DATA_LOC)])
588 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_DATA_LOC)]));
591 (int) floatFromVal(constVal(argv[++i]));
595 if (strcmp(&argv[i][1],OPTION_IDATA_LOC) == 0) {
597 if (argv[i][1+strlen(OPTION_IDATA_LOC)])
599 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IDATA_LOC)]));
602 (int) floatFromVal(constVal(argv[++i]));
606 if (strcmp(&argv[i][1],OPTION_CODE_LOC) == 0) {
608 if (argv[i][1+strlen(OPTION_CODE_LOC)])
610 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_CODE_LOC)]));
613 (int) floatFromVal(constVal(argv[++i]));
618 if (strcmp(&argv[i][1],OPTION_NO_JTBOUND) == 0) {
619 optimize.noJTabBoundary = 1;
623 if (strcmp(&argv[i][1],OPTION_NO_GCSE) == 0) {
624 optimize.global_cse = 0;
628 if (strcmp(&argv[i][1],OPTION_NO_LOOP_INV) == 0) {
629 optimize.loopInvariant = 0;
633 if (strcmp(&argv[i][1],OPTION_NO_LOOP_IND) == 0) {
634 optimize.loopInduction = 0;
638 if (strcmp(&argv[i][1],OPTION_NO_LOOPREV) == 0) {
639 optimize.noLoopReverse = 1;
643 if (!port->parseOption(&argc, argv))
644 werror(W_UNKNOWN_OPTION,argv[i]);
647 /* these are undocumented options */
648 /* if preceded by '/' then turn off certain optmizations, used
649 for debugging only these are also the legacy options from
650 version 1.xx will be removed gradually */
651 if ( *argv[i] == '/') {
652 switch (argv[i][1]) {
655 optimize.ptrArithmetic=0;
659 switch (argv[i][2]) {
664 optimize.label4 = 0 ;
682 switch (argv[i][2]) {
684 optimize.loopInvariant = 0;
687 optimize.loopInduction = 0;
694 optimize.global_cse = 0;
701 /* if preceded by '-' then option */
702 if ( *argv[i] == '-' ) {
703 switch (argv[i][1]) {
714 /* Used to select the port */
715 if (_setPort(argv[i] + 2)) {
716 werror(W_UNSUPP_OPTION,"-m","Unrecognised processor");
721 werror(W_UNSUPP_OPTION,"-a","use --stack-auto instead");
725 werror(W_UNSUPP_OPTION,"-g","use --generic instead");
728 case 'X' : /* use external stack */
729 werror(W_UNSUPP_OPTION,"-X","use --xstack-loc instead");
733 werror(W_UNSUPP_OPTION,"-x","use --xstack instead");
736 case 'p' : /* stack pointer intial value */
738 werror(W_UNSUPP_OPTION,"-p","use --stack-loc instead");
742 werror(W_UNSUPP_OPTION,"-i","use --idata-loc instead");
746 werror(W_UNSUPP_OPTION,"-r","use --xdata-loc instead");
750 werror(W_UNSUPP_OPTION,"-s","use --code-loc instead");
758 werror(W_UNSUPP_OPTION,"-Y","use -I instead");
763 libPaths[nlibPaths++] = &argv[i][2];
765 libPaths[nlibPaths++] = argv[++i];
770 if (argv[i][2] == 'l') {
772 parseWithComma(linkOptions,&argv[i][3]);
774 parseWithComma(linkOptions,argv[++i]);
776 /* assembler options */
777 if (argv[i][2] == 'a') {
779 parseWithComma(asmOptions,&argv[i][3]);
781 parseWithComma(asmOptions,argv[++i]);
784 werror(W_UNKNOWN_OPTION,argv[i]);
793 #if FEATURE_VERBOSE_EXEC
801 /* preprocessor options */
810 char sOpt = argv[i][1] ;
813 if ( argv[i][2] == ' ' || argv[i][2] == '\0') {
820 /* increase allocation for preprocessor argv
821 if (!(preArgv = realloc(preArgv,(preArgc+1)*sizeof(char **)))) {
822 werror (E_OUT_OF_MEM);
825 if ( argv[i][1] == 'Y' )
827 if (argv[i][1] == 'M')
830 if (!(preArgv[preArgc] = GC_malloc(strlen(rest)+3))) {
831 werror(E_OUT_OF_MEM,__FILE__,strlen(rest)+3);
835 sprintf(preArgv[preArgc],"-%c%s",sOpt,rest);
841 if (!port->parseOption(&argc, argv))
842 werror(W_UNKNOWN_OPTION,argv[i]);
847 if (!port->parseOption(&argc, argv)) {
848 /* no option must be a filename */
849 processFile(argv[i]);
853 /* set up external stack location if not explicitly specified */
854 if ( !options.xstack_loc )
855 options.xstack_loc = options.xdata_loc ;
857 /* if debug option is set the open the cdbFile */
858 if (/* options.debug && */ srcFileName) {
859 sprintf(cdbfnbuf,"%s.cdb",srcFileName);
860 if ((cdbFile = fopen(cdbfnbuf,"w")) == NULL)
861 werror(E_FILE_OPEN_ERR,cdbfnbuf);
863 /* add a module record */
864 fprintf(cdbFile,"M:%s\n",moduleName);
867 port->finaliseOptions();
871 /*-----------------------------------------------------------------*/
872 /* my_system - will call a program with arguments */
873 /*-----------------------------------------------------------------*/
874 char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
875 int my_system (const char *cmd, char **cmd_argv)
878 char *dir, *got= NULL; int i= 0;
879 while (!got && try_dir[i]) {
880 dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10);
881 strcpy(dir, try_dir[i]); strcat(dir, "/"); strcat(dir, cmd);
882 if (access(dir, X_OK) == 0)
887 #if FEATURE_VERBOSE_EXEC
889 char **pCmd = cmd_argv;
891 printf("%s ", *pCmd);
898 i= spawnv(P_WAIT,got,cmd_argv) == -1;
900 i= spawnvp(P_WAIT,cmd,cmd_argv) == -1;
902 perror("Cannot exec process ");
909 /*-----------------------------------------------------------------*/
910 /* linkEdit : - calls the linkage editor with options */
911 /*-----------------------------------------------------------------*/
912 static void linkEdit (char **envp)
918 srcFileName = "temp";
920 /* first we need to create the <filename>.lnk file */
921 sprintf(buffer,"%s.lnk",srcFileName);
922 if (!(lnkfile = fopen(buffer,"w"))) {
923 werror(E_FILE_OPEN_ERR,buffer);
927 /* now write the options */
928 fprintf(lnkfile,"-mux%c\n", (options.out_fmt ? 's' : 'i'));
930 /* if iram size specified */
931 if (options.iram_size)
932 fprintf(lnkfile,"-a 0x%04x\n",options.iram_size);
934 /*if (options.debug) */
935 fprintf(lnkfile,"-z\n");
936 /* code segment start */
937 fprintf (lnkfile,"-b CODE = 0x%04x\n",options.code_loc);
938 /* data segment start */
939 fprintf (lnkfile,"-b DSEG = 0x%04x\n",options.data_loc);
941 fprintf (lnkfile,"-b XSEG = 0x%04x\n",options.xdata_loc);
943 fprintf (lnkfile,"-b ISEG = 0x%04x\n",options.idata_loc);
944 /* bit segment start */
945 fprintf (lnkfile,"-b BSEG = 0x%04x\n",0);
947 /* add the extra linker options */
948 for (i=0; linkOptions[i] ; i++)
949 fprintf(lnkfile,"%s\n",linkOptions[i]);
951 /* standard library path */
952 fprintf (lnkfile,"-k %s/%s\n",SDCC_LIB_DIR/*STD_LIB_PATH*/,
953 ( (options.model==0) ? "small": "large"));
955 /* other library paths if specified */
956 for (i = 0 ; i < nlibPaths ; i++ )
957 fprintf (lnkfile,"-k %s\n",libPaths[i]);
959 /* standard library files */
960 fprintf (lnkfile,"-l %s\n",STD_LIB);
961 fprintf (lnkfile,"-l %s\n",STD_INT_LIB);
962 fprintf (lnkfile,"-l %s\n",STD_LONG_LIB);
963 fprintf (lnkfile,"-l %s\n",STD_FP_LIB);
965 /* additional libraries if any */
966 for (i = 0 ; i < nlibFiles; i++)
967 fprintf (lnkfile,"-l %s\n",libFiles[i]);
969 /* put in the object files */
970 if (strcmp(srcFileName,"temp"))
971 fprintf (lnkfile,"%s ",srcFileName);
973 for (i = 0 ; i < nrelFiles ; i++ )
974 fprintf (lnkfile,"%s\n",relFiles[i]);
976 fprintf (lnkfile,"\n-e\n");
979 /* call the linker */
980 lnkArgs[0] = "aslink";
982 lnkArgs[2] = srcFileName;
985 if (my_system("aslink",lnkArgs)) {
986 perror("Cannot exec linker");
990 if (strcmp(srcFileName,"temp") == 0) {
991 /* rename "temp.cdb" to "firstRelFile.cdb" */
992 char *f = strtok(strdup(relFiles[0]),".");
993 f = strcat(f,".cdb");
994 rename("temp.cdb",f);
999 /*-----------------------------------------------------------------*/
1000 /* assemble - spawns the assembler with arguments */
1001 /*-----------------------------------------------------------------*/
1002 static void assemble (char **envp)
1004 char *asmArgs[128]; /* assembler arguments */
1005 /* PENDING: A bit messy */
1010 asmArgs[0] = port->assembler.exec_name;
1012 /* if (options.debug) */
1013 asmArgs[1] = port->assembler.debug_opts;
1015 /* asmArgs[1] = port->assembler.plain_opts; */
1017 /* add the extra options if any */
1018 for (; asmOptions[i-2] ; i++)
1019 asmArgs[i] = asmOptions[i-2];
1021 if (port->assembler.requires_output_name) {
1022 sprintf(buffer2, srcFileName);
1023 strcat(buffer2, ".o");
1024 asmArgs[i++] = buffer2;
1027 /* create the assembler file name */
1028 sprintf (buffer, srcFileName);
1029 strcat (buffer, ".asm");
1030 asmArgs[i++] = buffer;
1032 asmArgs[i] = 0; /* end of args */
1034 if (my_system(port->assembler.exec_name, asmArgs)) {
1035 perror("Cannot exec linker");
1040 /*-----------------------------------------------------------------*/
1041 /* preProcess - spawns the preprocessor with arguments */
1042 /*-----------------------------------------------------------------*/
1043 static int preProcess (char **envp)
1046 /* if using external stack define the macro */
1047 if ( options.useXstack )
1048 preArgv[preArgc++] = "-DSDCC_USE_XSTACK" ;
1050 /* set the macro for stack autos */
1051 if ( options.stackAuto )
1052 preArgv[preArgc++] = "-DSDCC_STACK_AUTO";
1054 /* set the macro for large model */
1055 if ( options.model )
1056 preArgv[preArgc++] = "-DSDCC_MODEL_LARGE" ;
1058 preArgv[preArgc++] = "-DSDCC_MODEL_SMALL" ;
1060 preArgv[preArgc++] = fullSrcFileName ;
1062 preArgv[preArgc++] = preOutName = strdup(tmpnam(NULL));
1063 preArgv[preArgc] = NULL;
1065 preArgv[0] = "sdcpp";
1067 if (my_system("sdcpp",preArgv)) {
1068 unlink (preOutName);
1069 perror("Cannot exec Preprocessor");
1076 yyin = fopen(preOutName,"r");
1078 perror("Preproc file not found\n");
1085 static void _findPort(int argc, char **argv)
1089 if (!strncmp(*argv, "-m", 2)) {
1090 _setPort(*argv + 2);
1096 /* Use the first in the list */
1102 * initialises and calls the parser
1105 int main ( int argc, char **argv , char **envp)
1107 /* turn all optimizations off by default */
1108 memset(&optimize,0,sizeof(struct optimize));
1110 /*printVersionInfo ();*/
1112 _findPort(argc, argv);
1113 setDefaultOptions();
1114 parseCmdLine(argc,argv);
1116 /* if no input then printUsage & exit */
1117 if (!srcFileName && !nrelFiles) {
1144 if (!options.cc_only &&
1147 (srcFileName || nrelFiles))
1150 if (yyin && yyin != stdin)