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[] = {
128 #define NUM_PORTS (sizeof(_ports)/sizeof(_ports[0]))
130 /** Sets the port to the one given by the command line option.
131 @param The name minus the option (eg 'mcs51')
132 @return 0 on success.
134 static int _setPort(const char *name)
137 for (i=0; i<NUM_PORTS; i++) {
138 if (!strcmp(_ports[i]->target, name)) {
143 /* Error - didnt find */
147 /*-----------------------------------------------------------------*/
148 /* printVersionInfo - prints the version info */
149 /*-----------------------------------------------------------------*/
150 void printVersionInfo ()
155 "SDCC : MCU 8051 %s "
169 /*-----------------------------------------------------------------*/
170 /* printUsage - prints command line syntax */
171 /*-----------------------------------------------------------------*/
176 "Usage : [options] filename\n"
178 "\t--model-large - Large Model\n"
179 "\t--model-small - Small Model (default)\n"
180 "\t--stack-auto - Stack automatic variables\n"
181 "\t--xstack - Use external stack\n"
182 "\t--xram-loc <nnnn> - External Ram start location\n"
183 "\t--xstack-loc <nnnn> - Xternal Stack Location\n"
184 "\t--code-loc <nnnn> - Code Segment Location\n"
185 "\t--stack-loc <nnnn> - Stack pointer initial value\n"
186 "\t--data-loc <nnnn> - Direct data start location\n"
187 "\t--idata-loc <nnnn> - Indirect data start location\n"
188 "\t--iram-size <nnnn> - Internal Ram size\n"
189 "\t--nojtbound - Don't generate boundary check for jump tables\n"
190 "\t--generic - All unqualified ptrs converted to '_generic'\n"
191 "PreProcessor Options :-\n"
192 "\t-Dmacro - Define Macro\n"
193 "\t-Ipath - Include \"*.h\" path\n"
194 "Note: this is a complete list of options see docs for details\n");
198 /*-----------------------------------------------------------------*/
199 /* parseWithComma - separates string with comma */
200 /*-----------------------------------------------------------------*/
201 void parseWithComma (char **dest,char *src)
206 /* skip the initial white spaces */
207 while (isspace(*src)) src++;
221 /*-----------------------------------------------------------------*/
222 /* setDefaultOptions - sets the default options */
223 /*-----------------------------------------------------------------*/
224 static void setDefaultOptions()
228 for ( i = 0 ; i < 128 ; i++)
229 preArgv[i] = linkOptions [i] =
230 asmOptions[i] = relFiles[i] = libFiles[i] =
232 preArgv[preArgc++] = "-version";
233 preArgv[preArgc++] = "-Wall";
234 preArgv[preArgc++] = "-lang-c++";
235 preArgv[preArgc++] = "-DSDCC=1";
236 preArgv[preArgc++] = "-I" SDCC_INCLUDE_DIR ;
238 /* first the options part */
239 options.stack_loc = 0; /* stack pointer initialised to 0 */
240 options.xstack_loc= 0; /* xternal stack starts at 0 */
241 options.code_loc = 0; /* code starts at 0 */
242 options.data_loc = 0x0030; /* data starts at 0x0030 */
243 options.xdata_loc = 0;
244 options.idata_loc = 0x80;
245 options.genericPtr = 1; /* default on */
248 /* now for the optimizations */
249 /* turn on the everything */
250 optimize.global_cse = 1;
255 optimize.loopInvariant = 1;
256 optimize.loopInduction = 1;
258 port->setDefaultOptions();
261 /*-----------------------------------------------------------------*/
262 /* processFile - determines the type of file from the extension */
263 /*-----------------------------------------------------------------*/
264 static void processFile (char *s)
268 /* get the file extension */
269 fext = s + strlen(s);
270 while ((fext != s) && *fext != '.') fext--;
272 /* now if no '.' then we don't know what the file type is
273 so give a warning and return */
275 werror(W_UNKNOWN_FEXT,s);
279 /* otherwise depending on the file type */
280 if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0) {
281 /* source file name : not if we already have a
284 werror(W_TOO_MANY_SRC,s);
288 /* the only source file */
289 if (!(srcFile = fopen((fullSrcFileName = s),"r"))) {
290 werror(E_FILE_OPEN_ERR,s);
294 /* copy the file name into the buffer */
297 /* get rid of the "." */
299 ALLOC_ATOMIC(srcFileName,strlen(buffer)+1);
300 strcpy(srcFileName,buffer);
302 /* get rid of any path information
303 for the module name; do this by going
304 backwards till we get to either '/' or '\' or ':'
305 or start of buffer */
306 fext = buffer + strlen(buffer);
307 while (fext != buffer &&
308 *(fext -1) != '\\' &&
312 ALLOC_ATOMIC(moduleName,strlen(fext)+1);
313 strcpy(moduleName,fext);
318 /* if the extention is type .rel or .r or .REL or .R
319 addtional object file will be passed to the linker */
320 if (strcmp(fext,".r") == 0 || strcmp(fext,".rel") == 0 ||
321 strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0) {
323 relFiles[nrelFiles++] = s;
327 /* if .lib or .LIB */
328 if (strcmp(fext,".lib") == 0 || strcmp(fext,".LIB") == 0) {
329 libFiles[nlibFiles++] = s;
333 werror(W_UNKNOWN_FEXT,s);
338 /*-----------------------------------------------------------------*/
339 /* parseCmdLine - parses the command line and sets the options */
340 /*-----------------------------------------------------------------*/
341 int parseCmdLine ( int argc, char **argv )
346 /* go thru all whole command line */
347 for ( i = 1; i < argc; i++ ) {
352 if (argv[i][0] == '-' && argv[i][1] == '-') {
354 if (strcmp(&argv[i][1],OPTION_HELP) == 0) {
359 if (strcmp(&argv[i][1],OPTION_XREGS) == 0) {
360 options.regExtend = 1;
364 if (strcmp(&argv[i][1],OPTION_LARGE_MODEL) == 0) {
369 if (strcmp(&argv[i][1],OPTION_SMALL_MODEL) == 0) {
374 if (strcmp(&argv[i][1],OPTION_STACK_AUTO) == 0) {
375 options.stackAuto = 1;
379 if (strcmp(&argv[i][1],OPTION_DUMP_RAW) == 0) {
380 options.dump_raw = 1;
384 if (strcmp(&argv[i][1],OPTION_CYCLOMATIC) == 0) {
385 options.cyclomatic = 1;
389 if (strcmp(&argv[i][1],OPTION_DUMP_GCSE) == 0) {
390 options.dump_gcse = 1;
394 if (strcmp(&argv[i][1],OPTION_DUMP_LOOP) == 0) {
395 options.dump_loop = 1;
399 if (strcmp(&argv[i][1],OPTION_DUMP_KILL) == 0) {
400 options.dump_kill = 1;
404 if (strcmp(&argv[i][1],OPTION_INTLONG_RENT) == 0) {
405 options.intlong_rent = 1;
409 if (strcmp(&argv[i][1],OPTION_FLOAT_RENT) == 0) {
410 options.float_rent = 1;
414 if (strcmp(&argv[i][1],OPTION_DUMP_RANGE) == 0) {
415 options.dump_range = 1;
419 if (strcmp(&argv[i][1],OPTION_DUMP_PACK) == 0) {
420 options.dump_pack = 1;
424 if (strcmp(&argv[i][1],OPTION_DUMP_RASSGN) == 0) {
425 options.dump_rassgn = 1;
429 if (strcmp(&argv[i][1],OPTION_OUT_FMT_IHX) == 0) {
434 if (strcmp(&argv[i][1],OPTION_OUT_FMT_S19) == 0) {
439 if (strcmp(&argv[i][1],OPTION_NOOVERLAY) == 0) {
440 options.noOverlay = 1;
444 if (strcmp(&argv[i][1],OPTION_STKAFTRDATA) == 0) {
445 options.stackOnData = 1;
449 if (strcmp(&argv[i][1],OPTION_PREPROC_ONLY) == 0) {
455 if (strcmp(&argv[i][1],OPTION_DUMP_ALL) == 0) {
456 options.dump_rassgn =
462 options.dump_raw = 1;
466 if (strcmp(&argv[i][1],OPTION_COMP_ONLY) == 0) {
471 if (strcmp(&argv[i][1],OPTION_GENERIC) == 0) {
472 options.genericPtr = 1;
476 if (strcmp(&argv[i][1],OPTION_NOPEEP) == 0) {
481 if (strcmp(&argv[i][1],OPTION_ASMPEEP) == 0) {
486 if (strcmp(&argv[i][1],OPTION_DEBUG) == 0) {
491 if (strcmp(&argv[i][1],OPTION_NOREGPARMS) == 0) {
492 options.noregparms = 1;
496 if (strcmp(&argv[i][1],OPTION_PEEP_FILE) == 0) {
497 if (argv[i][1+strlen(OPTION_PEEP_FILE)])
499 &argv[i][1+strlen(OPTION_PEEP_FILE)];
501 options.peep_file = argv[++i];
505 if (strcmp(&argv[i][1],OPTION_LIB_PATH) == 0) {
506 if (argv[i][1+strlen(OPTION_LIB_PATH)])
507 libPaths[nlibPaths++] =
508 &argv[i][1+strlen(OPTION_PEEP_FILE)];
510 libPaths[nlibPaths++] = argv[++i];
514 if (strcmp(&argv[i][1],OPTION_XSTACK_LOC) == 0) {
516 if (argv[i][1+strlen(OPTION_XSTACK_LOC)])
518 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XSTACK_LOC)]));
521 (int) floatFromVal(constVal(argv[++i]));
525 if (strcmp(&argv[i][1],OPTION_XSTACK) == 0) {
526 options.useXstack = 1;
530 if (strcmp(&argv[i][1],OPTION_MAINRETURN) == 0) {
531 options.mainreturn = 1;
535 if (strcmp(&argv[i][1],OPTION_CALLEE_SAVES) == 0) {
536 if (argv[i][1+strlen(OPTION_CALLEE_SAVES)])
537 parseWithComma(options.calleeSaves
538 ,&argv[i][1+strlen(OPTION_CALLEE_SAVES)]);
540 parseWithComma(options.calleeSaves,argv[++i]);
544 if (strcmp(&argv[i][1],OPTION_STACK_LOC) == 0) {
546 if (argv[i][1+strlen(OPTION_STACK_LOC)])
548 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_STACK_LOC)]));
551 (int) floatFromVal(constVal(argv[++i]));
555 if (strcmp(&argv[i][1],OPTION_XRAM_LOC) == 0) {
557 if (argv[i][1+strlen(OPTION_XRAM_LOC)])
559 (unsigned int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XRAM_LOC)]));
562 (unsigned int) floatFromVal(constVal(argv[++i]));
566 if (strcmp(&argv[i][1],OPTION_IRAM_SIZE) == 0) {
568 if (argv[i][1+strlen(OPTION_IRAM_SIZE)])
570 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IRAM_SIZE)]));
573 (int) floatFromVal(constVal(argv[++i]));
577 if (strcmp(&argv[i][1],OPTION_VERSION) == 0) {
583 if (strcmp(&argv[i][1],OPTION_DATA_LOC) == 0) {
585 if (argv[i][1+strlen(OPTION_DATA_LOC)])
587 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_DATA_LOC)]));
590 (int) floatFromVal(constVal(argv[++i]));
594 if (strcmp(&argv[i][1],OPTION_IDATA_LOC) == 0) {
596 if (argv[i][1+strlen(OPTION_IDATA_LOC)])
598 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IDATA_LOC)]));
601 (int) floatFromVal(constVal(argv[++i]));
605 if (strcmp(&argv[i][1],OPTION_CODE_LOC) == 0) {
607 if (argv[i][1+strlen(OPTION_CODE_LOC)])
609 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_CODE_LOC)]));
612 (int) floatFromVal(constVal(argv[++i]));
617 if (strcmp(&argv[i][1],OPTION_NO_JTBOUND) == 0) {
618 optimize.noJTabBoundary = 1;
622 if (strcmp(&argv[i][1],OPTION_NO_GCSE) == 0) {
623 optimize.global_cse = 0;
627 if (strcmp(&argv[i][1],OPTION_NO_LOOP_INV) == 0) {
628 optimize.loopInvariant = 0;
632 if (strcmp(&argv[i][1],OPTION_NO_LOOP_IND) == 0) {
633 optimize.loopInduction = 0;
637 if (strcmp(&argv[i][1],OPTION_NO_LOOPREV) == 0) {
638 optimize.noLoopReverse = 1;
642 if (!port->parseOption(&argc, argv))
643 werror(W_UNKNOWN_OPTION,argv[i]);
646 /* these are undocumented options */
647 /* if preceded by '/' then turn off certain optmizations, used
648 for debugging only these are also the legacy options from
649 version 1.xx will be removed gradually */
650 if ( *argv[i] == '/') {
651 switch (argv[i][1]) {
654 optimize.ptrArithmetic=0;
658 switch (argv[i][2]) {
663 optimize.label4 = 0 ;
681 switch (argv[i][2]) {
683 optimize.loopInvariant = 0;
686 optimize.loopInduction = 0;
693 optimize.global_cse = 0;
700 /* if preceded by '-' then option */
701 if ( *argv[i] == '-' ) {
702 switch (argv[i][1]) {
713 /* Used to select the port */
714 if (_setPort(argv[i] + 2)) {
715 werror(W_UNSUPP_OPTION,"-m","Unrecognised processor");
720 werror(W_UNSUPP_OPTION,"-a","use --stack-auto instead");
724 werror(W_UNSUPP_OPTION,"-g","use --generic instead");
727 case 'X' : /* use external stack */
728 werror(W_UNSUPP_OPTION,"-X","use --xstack-loc instead");
732 werror(W_UNSUPP_OPTION,"-x","use --xstack instead");
735 case 'p' : /* stack pointer intial value */
737 werror(W_UNSUPP_OPTION,"-p","use --stack-loc instead");
741 werror(W_UNSUPP_OPTION,"-i","use --idata-loc instead");
745 werror(W_UNSUPP_OPTION,"-r","use --xdata-loc instead");
749 werror(W_UNSUPP_OPTION,"-s","use --code-loc instead");
757 werror(W_UNSUPP_OPTION,"-Y","use -I instead");
762 libPaths[nlibPaths++] = &argv[i][2];
764 libPaths[nlibPaths++] = argv[++i];
769 if (argv[i][2] == 'l') {
771 parseWithComma(linkOptions,&argv[i][3]);
773 parseWithComma(linkOptions,argv[++i]);
775 /* assembler options */
776 if (argv[i][2] == 'a') {
778 parseWithComma(asmOptions,&argv[i][3]);
780 parseWithComma(asmOptions,argv[++i]);
783 werror(W_UNKNOWN_OPTION,argv[i]);
792 #if FEATURE_VERBOSE_EXEC
800 /* preprocessor options */
809 char sOpt = argv[i][1] ;
812 if ( argv[i][2] == ' ' || argv[i][2] == '\0') {
819 /* increase allocation for preprocessor argv
820 if (!(preArgv = realloc(preArgv,(preArgc+1)*sizeof(char **)))) {
821 werror (E_OUT_OF_MEM);
824 if ( argv[i][1] == 'Y' )
826 if (argv[i][1] == 'M')
829 if (!(preArgv[preArgc] = GC_malloc(strlen(rest)+3))) {
830 werror(E_OUT_OF_MEM,__FILE__,strlen(rest)+3);
834 sprintf(preArgv[preArgc],"-%c%s",sOpt,rest);
840 if (!port->parseOption(&argc, argv))
841 werror(W_UNKNOWN_OPTION,argv[i]);
846 if (!port->parseOption(&argc, argv)) {
847 /* no option must be a filename */
848 processFile(argv[i]);
852 /* set up external stack location if not explicitly specified */
853 if ( !options.xstack_loc )
854 options.xstack_loc = options.xdata_loc ;
856 /* if debug option is set the open the cdbFile */
857 if (/* options.debug && */ srcFileName) {
858 sprintf(cdbfnbuf,"%s.cdb",srcFileName);
859 if ((cdbFile = fopen(cdbfnbuf,"w")) == NULL)
860 werror(E_FILE_OPEN_ERR,cdbfnbuf);
862 /* add a module record */
863 fprintf(cdbFile,"M:%s\n",moduleName);
866 port->finaliseOptions();
870 /*-----------------------------------------------------------------*/
871 /* my_system - will call a program with arguments */
872 /*-----------------------------------------------------------------*/
873 char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
874 int my_system (const char *cmd, char **cmd_argv)
877 char *dir, *got= NULL; int i= 0;
878 while (!got && try_dir[i]) {
879 dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10);
880 strcpy(dir, try_dir[i]); strcat(dir, "/"); strcat(dir, cmd);
881 if (access(dir, X_OK) == 0)
886 #if FEATURE_VERBOSE_EXEC
888 char **pCmd = cmd_argv;
890 printf("%s ", *pCmd);
897 i= spawnv(P_WAIT,got,cmd_argv) == -1;
899 i= spawnvp(P_WAIT,cmd,cmd_argv) == -1;
901 perror("Cannot exec process ");
908 /*-----------------------------------------------------------------*/
909 /* linkEdit : - calls the linkage editor with options */
910 /*-----------------------------------------------------------------*/
911 static void linkEdit (char **envp)
917 srcFileName = "temp";
919 /* first we need to create the <filename>.lnk file */
920 sprintf(buffer,"%s.lnk",srcFileName);
921 if (!(lnkfile = fopen(buffer,"w"))) {
922 werror(E_FILE_OPEN_ERR,buffer);
926 /* now write the options */
927 fprintf(lnkfile,"-mux%c\n", (options.out_fmt ? 's' : 'i'));
929 /* if iram size specified */
930 if (options.iram_size)
931 fprintf(lnkfile,"-a 0x%04x\n",options.iram_size);
933 /*if (options.debug) */
934 fprintf(lnkfile,"-z\n");
935 /* code segment start */
936 fprintf (lnkfile,"-b CODE = 0x%04x\n",options.code_loc);
937 /* data segment start */
938 fprintf (lnkfile,"-b DSEG = 0x%04x\n",options.data_loc);
940 fprintf (lnkfile,"-b XSEG = 0x%04x\n",options.xdata_loc);
942 fprintf (lnkfile,"-b ISEG = 0x%04x\n",options.idata_loc);
943 /* bit segment start */
944 fprintf (lnkfile,"-b BSEG = 0x%04x\n",0);
946 /* add the extra linker options */
947 for (i=0; linkOptions[i] ; i++)
948 fprintf(lnkfile,"%s\n",linkOptions[i]);
950 /* standard library path */
951 fprintf (lnkfile,"-k %s/%s\n",SDCC_LIB_DIR/*STD_LIB_PATH*/,
952 ( (options.model==0) ? "small": "large"));
954 /* other library paths if specified */
955 for (i = 0 ; i < nlibPaths ; i++ )
956 fprintf (lnkfile,"-k %s\n",libPaths[i]);
958 /* standard library files */
959 fprintf (lnkfile,"-l %s\n",STD_LIB);
960 fprintf (lnkfile,"-l %s\n",STD_INT_LIB);
961 fprintf (lnkfile,"-l %s\n",STD_LONG_LIB);
962 fprintf (lnkfile,"-l %s\n",STD_FP_LIB);
964 /* additional libraries if any */
965 for (i = 0 ; i < nlibFiles; i++)
966 fprintf (lnkfile,"-l %s\n",libFiles[i]);
968 /* put in the object files */
969 if (strcmp(srcFileName,"temp"))
970 fprintf (lnkfile,"%s ",srcFileName);
972 for (i = 0 ; i < nrelFiles ; i++ )
973 fprintf (lnkfile,"%s\n",relFiles[i]);
975 fprintf (lnkfile,"\n-e\n");
978 /* call the linker */
979 lnkArgs[0] = "aslink";
981 lnkArgs[2] = srcFileName;
984 if (my_system("aslink",lnkArgs)) {
985 perror("Cannot exec linker");
989 if (strcmp(srcFileName,"temp") == 0) {
990 /* rename "temp.cdb" to "firstRelFile.cdb" */
991 char *f = strtok(strdup(relFiles[0]),".");
992 f = strcat(f,".cdb");
993 rename("temp.cdb",f);
998 /*-----------------------------------------------------------------*/
999 /* assemble - spawns the assembler with arguments */
1000 /*-----------------------------------------------------------------*/
1001 static void assemble (char **envp)
1003 char *asmArgs[128]; /* assembler arguments */
1006 asmArgs[0] = "asx8051";
1008 /* if (options.debug) */
1009 asmArgs[1] = "-plosgffc" ;
1011 /* asmArgs[1] = "-plosgff"; */
1013 /* add the extra options if any */
1014 for (; asmOptions[i-2] ; i++)
1015 asmArgs[i] = asmOptions[i-2];
1017 /* create the assembler file name */
1018 sprintf (buffer, srcFileName);
1019 strcat (buffer, ".asm");
1020 asmArgs[i++] = buffer;
1022 asmArgs[i] = 0; /* end of args */
1024 if (my_system("asx8051",asmArgs)) {
1025 perror("Cannot exec linker");
1030 /*-----------------------------------------------------------------*/
1031 /* preProcess - spawns the preprocessor with arguments */
1032 /*-----------------------------------------------------------------*/
1033 static int preProcess (char **envp)
1036 /* if using external stack define the macro */
1037 if ( options.useXstack )
1038 preArgv[preArgc++] = "-DSDCC_USE_XSTACK" ;
1040 /* set the macro for stack autos */
1041 if ( options.stackAuto )
1042 preArgv[preArgc++] = "-DSDCC_STACK_AUTO";
1044 /* set the macro for large model */
1045 if ( options.model )
1046 preArgv[preArgc++] = "-DSDCC_MODEL_LARGE" ;
1048 preArgv[preArgc++] = "-DSDCC_MODEL_SMALL" ;
1050 preArgv[preArgc++] = fullSrcFileName ;
1052 preArgv[preArgc++] = preOutName = strdup(tmpnam(NULL));
1053 preArgv[preArgc] = NULL;
1055 preArgv[0] = "sdcpp";
1057 if (my_system("sdcpp",preArgv)) {
1058 unlink (preOutName);
1059 perror("Cannot exec Preprocessor");
1066 yyin = fopen(preOutName,"r");
1068 perror("Preproc file not found\n");
1075 static void _findPort(int argc, char **argv)
1079 if (!strncmp(*argv, "-m", 2)) {
1080 _setPort(*argv + 2);
1092 * initialises and calls the parser
1095 int main ( int argc, char **argv , char **envp)
1097 /* turn all optimizations off by default */
1098 memset(&optimize,0,sizeof(struct optimize));
1100 /*printVersionInfo ();*/
1102 _findPort(argc, argv);
1103 setDefaultOptions();
1104 parseCmdLine(argc,argv);
1106 /* if no input then printUsage & exit */
1107 if (!srcFileName && !nrelFiles) {
1134 if (!options.cc_only &&
1137 (srcFileName || nrelFiles))
1140 if (yyin && yyin != stdin)