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 -------------------------------------------------------------------------*/
30 #include "SDCCglobl.h"
33 extern void initSymt ();
34 extern void initMem ();
35 extern void initExpr ();
36 extern void initiCode ();
37 extern void initCSupport ();
38 extern void initPeepHole ();
39 extern void createObject ();
40 extern int yyparse ();
42 extern struct value *constVal(char *s);
43 extern double floatFromVal(struct value *);
44 extern int fatalError ;
45 FILE *srcFile ;/* source file */
46 FILE *cdbFile = NULL ;/* debugger information output file */
47 char *fullSrcFileName ;/* full name for the source file */
48 char *srcFileName ;/* source file name with the .c stripped */
49 char *moduleName ;/* module name is srcFilename stripped of any path */
50 char *preArgv[128] ;/* pre-processor arguments */
51 int preArgc = 0 ;/* pre-processor argument count */
53 struct optimize optimize ;
54 struct options options ;
55 char *VersionString = SDCC_VERSION_STR /*"Version 2.1.8a"*/;
56 short preProcOnly = 0;
58 char *linkOptions[128];
59 char *asmOptions[128];
66 bool verboseExec = FALSE;
67 //extern int wait (int *);
70 #define OPTION_LARGE_MODEL "-model-large"
71 #define OPTION_SMALL_MODEL "-model-small"
72 #define OPTION_STACK_AUTO "-stack-auto"
73 #define OPTION_XSTACK "-xstack"
74 #define OPTION_GENERIC "-generic"
75 #define OPTION_NO_GCSE "-nogcse"
76 #define OPTION_NO_LOOP_INV "-noinvariant"
77 #define OPTION_NO_LOOP_IND "-noinduction"
78 #define OPTION_NO_JTBOUND "-nojtbound"
79 #define OPTION_NO_LOOPREV "-noloopreverse"
80 #define OPTION_XREGS "-regextend"
81 #define OPTION_COMP_ONLY "-compile-only"
82 #define OPTION_DUMP_RAW "-dumpraw"
83 #define OPTION_DUMP_GCSE "-dumpgcse"
84 #define OPTION_DUMP_LOOP "-dumploop"
85 #define OPTION_DUMP_KILL "-dumpdeadcode"
86 #define OPTION_DUMP_RANGE "-dumpliverange"
87 #define OPTION_DUMP_PACK "-dumpregpack"
88 #define OPTION_DUMP_RASSGN "-dumpregassign"
89 #define OPTION_DUMP_ALL "-dumpall"
90 #define OPTION_XRAM_LOC "-xram-loc"
91 #define OPTION_IRAM_SIZE "-iram-size"
92 #define OPTION_XSTACK_LOC "-xstack-loc"
93 #define OPTION_CODE_LOC "-code-loc"
94 #define OPTION_STACK_LOC "-stack-loc"
95 #define OPTION_DATA_LOC "-data-loc"
96 #define OPTION_IDATA_LOC "-idata-loc"
97 #define OPTION_PEEP_FILE "-peep-file"
98 #define OPTION_LIB_PATH "-lib-path"
99 #define OPTION_INTLONG_RENT "-int-long-reent"
100 #define OPTION_FLOAT_RENT "-float-reent"
101 #define OPTION_OUT_FMT_IHX "-out-fmt-ihx"
102 #define OPTION_OUT_FMT_S19 "-out-fmt-s19"
103 #define OPTION_CYCLOMATIC "-cyclomatic"
104 #define OPTION_NOOVERLAY "-nooverlay"
105 #define OPTION_MAINRETURN "-main-return"
106 #define OPTION_NOPEEP "-no-peep"
107 #define OPTION_ASMPEEP "-peep-asm"
108 #define OPTION_DEBUG "-debug"
109 #define OPTION_VERSION "-version"
110 #define OPTION_STKAFTRDATA "-stack-after-data"
111 #define OPTION_PREPROC_ONLY "-preprocessonly"
112 #define OPTION_HELP "-help"
113 #define OPTION_CALLEE_SAVES "-callee-saves"
114 #define OPTION_NOREGPARMS "-noregparms"
115 /*-----------------------------------------------------------------*/
116 /* printVersionInfo - prints the version info */
117 /*-----------------------------------------------------------------*/
118 void printVersionInfo ()
123 "SDCC : MCU 8051 %s "
137 /*-----------------------------------------------------------------*/
138 /* printUsage - prints command line syntax */
139 /*-----------------------------------------------------------------*/
144 "Usage : [options] filename\n"
146 "\t--model-large - Large Model\n"
147 "\t--model-small - Small Model (default)\n"
148 "\t--stack-auto - Stack automatic variables\n"
149 "\t--xstack - Use external stack\n"
150 "\t--xram-loc <nnnn> - External Ram start location\n"
151 "\t--xstack-loc <nnnn> - Xternal Stack Location\n"
152 "\t--code-loc <nnnn> - Code Segment Location\n"
153 "\t--stack-loc <nnnn> - Stack pointer initial value\n"
154 "\t--data-loc <nnnn> - Direct data start location\n"
155 "\t--idata-loc <nnnn> - Indirect data start location\n"
156 "\t--iram-size <nnnn> - Internal Ram size\n"
157 "\t--nojtbound - Don't generate boundary check for jump tables\n"
158 "\t--generic - All unqualified ptrs converted to '_generic'\n"
159 "PreProcessor Options :-\n"
160 "\t-Dmacro - Define Macro\n"
161 "\t-Ipath - Include \"*.h\" path\n"
162 "Note: this is a complete list of options see docs for details\n");
166 /*-----------------------------------------------------------------*/
167 /* parseWithComma - separates string with comma */
168 /*-----------------------------------------------------------------*/
169 void parseWithComma (char **dest,char *src)
174 /* skip the initial white spaces */
175 while (isspace(*src)) src++;
189 /*-----------------------------------------------------------------*/
190 /* setDefaultOptions - sets the default options */
191 /*-----------------------------------------------------------------*/
192 static void setDefaultOptions()
196 for ( i = 0 ; i < 128 ; i++)
197 preArgv[i] = linkOptions [i] =
198 asmOptions[i] = relFiles[i] = libFiles[i] =
200 preArgv[preArgc++] = "-version";
201 preArgv[preArgc++] = "-Wall";
202 preArgv[preArgc++] = "-lang-c++";
203 preArgv[preArgc++] = "-DSDCC=1";
204 preArgv[preArgc++] = "-I" SDCC_INCLUDE_DIR ;
206 /* first the options part */
207 options.stack_loc = 0; /* stack pointer initialised to 0 */
208 options.xstack_loc= 0; /* xternal stack starts at 0 */
209 options.code_loc = 0; /* code starts at 0 */
210 options.data_loc = 0x0030; /* data starts at 0x0030 */
211 options.xdata_loc = 0;
212 options.idata_loc = 0x80;
213 options.genericPtr = 1; /* default on */
216 /* now for the optimizations */
217 /* turn on the everything */
218 optimize.global_cse = 1;
223 optimize.loopInvariant = 1;
224 optimize.loopInduction = 1;
227 /*-----------------------------------------------------------------*/
228 /* processFile - determines the type of file from the extension */
229 /*-----------------------------------------------------------------*/
230 static void processFile (char *s)
234 /* get the file extension */
235 fext = s + strlen(s);
236 while ((fext != s) && *fext != '.') fext--;
238 /* now if no '.' then we don't know what the file type is
239 so give a warning and return */
241 werror(W_UNKNOWN_FEXT,s);
245 /* otherwise depending on the file type */
246 if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0) {
247 /* source file name : not if we already have a
250 werror(W_TOO_MANY_SRC,s);
254 /* the only source file */
255 if (!(srcFile = fopen((fullSrcFileName = s),"r"))) {
256 werror(E_FILE_OPEN_ERR,s);
260 /* copy the file name into the buffer */
263 /* get rid of the "." */
265 ALLOC_ATOMIC(srcFileName,strlen(buffer)+1);
266 strcpy(srcFileName,buffer);
268 /* get rid of any path information
269 for the module name; do this by going
270 backwards till we get to either '/' or '\' or ':'
271 or start of buffer */
272 fext = buffer + strlen(buffer);
273 while (fext != buffer &&
274 *(fext -1) != '\\' &&
278 ALLOC_ATOMIC(moduleName,strlen(fext)+1);
279 strcpy(moduleName,fext);
284 /* if the extention is type .rel or .r or .REL or .R
285 addtional object file will be passed to the linker */
286 if (strcmp(fext,".r") == 0 || strcmp(fext,".rel") == 0 ||
287 strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0) {
289 relFiles[nrelFiles++] = s;
293 /* if .lib or .LIB */
294 if (strcmp(fext,".lib") == 0 || strcmp(fext,".LIB") == 0) {
295 libFiles[nlibFiles++] = s;
299 werror(W_UNKNOWN_FEXT,s);
304 /*-----------------------------------------------------------------*/
305 /* parseCmdLine - parses the command line and sets the options */
306 /*-----------------------------------------------------------------*/
307 int parseCmdLine ( int argc, char **argv )
312 /* go thru all whole command line */
313 for ( i = 1; i < argc; i++ ) {
318 if (argv[i][0] == '-' && argv[i][1] == '-') {
320 if (strcmp(&argv[i][1],OPTION_HELP) == 0) {
325 if (strcmp(&argv[i][1],OPTION_XREGS) == 0) {
326 options.regExtend = 1;
330 if (strcmp(&argv[i][1],OPTION_LARGE_MODEL) == 0) {
335 if (strcmp(&argv[i][1],OPTION_SMALL_MODEL) == 0) {
340 if (strcmp(&argv[i][1],OPTION_STACK_AUTO) == 0) {
341 options.stackAuto = 1;
345 if (strcmp(&argv[i][1],OPTION_DUMP_RAW) == 0) {
346 options.dump_raw = 1;
350 if (strcmp(&argv[i][1],OPTION_CYCLOMATIC) == 0) {
351 options.cyclomatic = 1;
355 if (strcmp(&argv[i][1],OPTION_DUMP_GCSE) == 0) {
356 options.dump_gcse = 1;
360 if (strcmp(&argv[i][1],OPTION_DUMP_LOOP) == 0) {
361 options.dump_loop = 1;
365 if (strcmp(&argv[i][1],OPTION_DUMP_KILL) == 0) {
366 options.dump_kill = 1;
370 if (strcmp(&argv[i][1],OPTION_INTLONG_RENT) == 0) {
371 options.intlong_rent = 1;
375 if (strcmp(&argv[i][1],OPTION_FLOAT_RENT) == 0) {
376 options.float_rent = 1;
380 if (strcmp(&argv[i][1],OPTION_DUMP_RANGE) == 0) {
381 options.dump_range = 1;
385 if (strcmp(&argv[i][1],OPTION_DUMP_PACK) == 0) {
386 options.dump_pack = 1;
390 if (strcmp(&argv[i][1],OPTION_DUMP_RASSGN) == 0) {
391 options.dump_rassgn = 1;
395 if (strcmp(&argv[i][1],OPTION_OUT_FMT_IHX) == 0) {
400 if (strcmp(&argv[i][1],OPTION_OUT_FMT_S19) == 0) {
405 if (strcmp(&argv[i][1],OPTION_NOOVERLAY) == 0) {
406 options.noOverlay = 1;
410 if (strcmp(&argv[i][1],OPTION_STKAFTRDATA) == 0) {
411 options.stackOnData = 1;
415 if (strcmp(&argv[i][1],OPTION_PREPROC_ONLY) == 0) {
421 if (strcmp(&argv[i][1],OPTION_DUMP_ALL) == 0) {
422 options.dump_rassgn =
428 options.dump_raw = 1;
432 if (strcmp(&argv[i][1],OPTION_COMP_ONLY) == 0) {
437 if (strcmp(&argv[i][1],OPTION_GENERIC) == 0) {
438 options.genericPtr = 1;
442 if (strcmp(&argv[i][1],OPTION_NOPEEP) == 0) {
447 if (strcmp(&argv[i][1],OPTION_ASMPEEP) == 0) {
452 if (strcmp(&argv[i][1],OPTION_DEBUG) == 0) {
457 if (strcmp(&argv[i][1],OPTION_NOREGPARMS) == 0) {
458 options.noregparms = 1;
462 if (strcmp(&argv[i][1],OPTION_PEEP_FILE) == 0) {
463 if (argv[i][1+strlen(OPTION_PEEP_FILE)])
465 &argv[i][1+strlen(OPTION_PEEP_FILE)];
467 options.peep_file = argv[++i];
471 if (strcmp(&argv[i][1],OPTION_LIB_PATH) == 0) {
472 if (argv[i][1+strlen(OPTION_LIB_PATH)])
473 libPaths[nlibPaths++] =
474 &argv[i][1+strlen(OPTION_PEEP_FILE)];
476 libPaths[nlibPaths++] = argv[++i];
480 if (strcmp(&argv[i][1],OPTION_XSTACK_LOC) == 0) {
482 if (argv[i][1+strlen(OPTION_XSTACK_LOC)])
484 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XSTACK_LOC)]));
487 (int) floatFromVal(constVal(argv[++i]));
491 if (strcmp(&argv[i][1],OPTION_XSTACK) == 0) {
492 options.useXstack = 1;
496 if (strcmp(&argv[i][1],OPTION_MAINRETURN) == 0) {
497 options.mainreturn = 1;
501 if (strcmp(&argv[i][1],OPTION_CALLEE_SAVES) == 0) {
502 if (argv[i][1+strlen(OPTION_CALLEE_SAVES)])
503 parseWithComma(options.calleeSaves
504 ,&argv[i][1+strlen(OPTION_CALLEE_SAVES)]);
506 parseWithComma(options.calleeSaves,argv[++i]);
510 if (strcmp(&argv[i][1],OPTION_STACK_LOC) == 0) {
512 if (argv[i][1+strlen(OPTION_STACK_LOC)])
514 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_STACK_LOC)]));
517 (int) floatFromVal(constVal(argv[++i]));
521 if (strcmp(&argv[i][1],OPTION_XRAM_LOC) == 0) {
523 if (argv[i][1+strlen(OPTION_XRAM_LOC)])
525 (unsigned int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XRAM_LOC)]));
528 (unsigned int) floatFromVal(constVal(argv[++i]));
532 if (strcmp(&argv[i][1],OPTION_IRAM_SIZE) == 0) {
534 if (argv[i][1+strlen(OPTION_IRAM_SIZE)])
536 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IRAM_SIZE)]));
539 (int) floatFromVal(constVal(argv[++i]));
543 if (strcmp(&argv[i][1],OPTION_VERSION) == 0) {
549 if (strcmp(&argv[i][1],OPTION_DATA_LOC) == 0) {
551 if (argv[i][1+strlen(OPTION_DATA_LOC)])
553 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_DATA_LOC)]));
556 (int) floatFromVal(constVal(argv[++i]));
560 if (strcmp(&argv[i][1],OPTION_IDATA_LOC) == 0) {
562 if (argv[i][1+strlen(OPTION_IDATA_LOC)])
564 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IDATA_LOC)]));
567 (int) floatFromVal(constVal(argv[++i]));
571 if (strcmp(&argv[i][1],OPTION_CODE_LOC) == 0) {
573 if (argv[i][1+strlen(OPTION_CODE_LOC)])
575 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_CODE_LOC)]));
578 (int) floatFromVal(constVal(argv[++i]));
583 if (strcmp(&argv[i][1],OPTION_NO_JTBOUND) == 0) {
584 optimize.noJTabBoundary = 1;
588 if (strcmp(&argv[i][1],OPTION_NO_GCSE) == 0) {
589 optimize.global_cse = 0;
593 if (strcmp(&argv[i][1],OPTION_NO_LOOP_INV) == 0) {
594 optimize.loopInvariant = 0;
598 if (strcmp(&argv[i][1],OPTION_NO_LOOP_IND) == 0) {
599 optimize.loopInduction = 0;
603 if (strcmp(&argv[i][1],OPTION_NO_LOOPREV) == 0) {
604 optimize.noLoopReverse = 1;
608 werror(W_UNKNOWN_OPTION,argv[i]);
611 /* these are undocumented options */
612 /* if preceded by '/' then turn off certain optmizations, used
613 for debugging only these are also the legacy options from
614 version 1.xx will be removed gradually */
615 if ( *argv[i] == '/') {
616 switch (argv[i][1]) {
619 optimize.ptrArithmetic=0;
623 switch (argv[i][2]) {
628 optimize.label4 = 0 ;
646 switch (argv[i][2]) {
648 optimize.loopInvariant = 0;
651 optimize.loopInduction = 0;
658 optimize.global_cse = 0;
665 /* if preceded by '-' then option */
666 if ( *argv[i] == '-' ) {
667 switch (argv[i][1]) {
678 werror(W_UNSUPP_OPTION,"-mL/-mS","use --model-large/--model-small instead");
682 werror(W_UNSUPP_OPTION,"-a","use --stack-auto instead");
686 werror(W_UNSUPP_OPTION,"-g","use --generic instead");
689 case 'X' : /* use external stack */
690 werror(W_UNSUPP_OPTION,"-X","use --xstack-loc instead");
694 werror(W_UNSUPP_OPTION,"-x","use --xstack instead");
697 case 'p' : /* stack pointer intial value */
699 werror(W_UNSUPP_OPTION,"-p","use --stack-loc instead");
703 werror(W_UNSUPP_OPTION,"-i","use --idata-loc instead");
707 werror(W_UNSUPP_OPTION,"-r","use --xdata-loc instead");
711 werror(W_UNSUPP_OPTION,"-s","use --code-loc instead");
719 werror(W_UNSUPP_OPTION,"-Y","use -I instead");
724 libPaths[nlibPaths++] = &argv[i][2];
726 libPaths[nlibPaths++] = argv[++i];
731 if (argv[i][2] == 'l') {
733 parseWithComma(linkOptions,&argv[i][3]);
735 parseWithComma(linkOptions,argv[++i]);
737 /* assembler options */
738 if (argv[i][2] == 'a') {
740 parseWithComma(asmOptions,&argv[i][3]);
742 parseWithComma(asmOptions,argv[++i]);
745 werror(W_UNKNOWN_OPTION,argv[i]);
754 #if FEATURE_VERBOSE_EXEC
762 /* preprocessor options */
771 char sOpt = argv[i][1] ;
774 if ( argv[i][2] == ' ' || argv[i][2] == '\0') {
781 /* increase allocation for preprocessor argv
782 if (!(preArgv = realloc(preArgv,(preArgc+1)*sizeof(char **)))) {
783 werror (E_OUT_OF_MEM);
786 if ( argv[i][1] == 'Y' )
788 if (argv[i][1] == 'M')
791 if (!(preArgv[preArgc] = GC_malloc(strlen(rest)+3))) {
792 werror(E_OUT_OF_MEM,__FILE__,strlen(rest)+3);
796 sprintf(preArgv[preArgc],"-%c%s",sOpt,rest);
802 werror(W_UNKNOWN_OPTION,argv[i]);
807 /* no option must be a filename */
808 processFile(argv[i]);
813 /* set up external stack location if not explicitly specified */
814 if ( !options.xstack_loc )
815 options.xstack_loc = options.xdata_loc ;
817 /* if debug option is set the open the cdbFile */
818 if (/* options.debug && */ srcFileName) {
819 sprintf(cdbfnbuf,"%s.cdb",srcFileName);
820 if ((cdbFile = fopen(cdbfnbuf,"w")) == NULL)
821 werror(E_FILE_OPEN_ERR,cdbfnbuf);
823 /* add a module record */
824 fprintf(cdbFile,"M:%s\n",moduleName);
830 /*-----------------------------------------------------------------*/
831 /* my_system - will call a program with arguments */
832 /*-----------------------------------------------------------------*/
833 char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
834 int my_system (const char *cmd, char **cmd_argv)
837 char *dir, *got= NULL; int i= 0;
838 while (!got && try_dir[i]) {
839 dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10);
840 strcpy(dir, try_dir[i]); strcat(dir, "/"); strcat(dir, cmd);
841 if (access(dir, X_OK) == 0)
846 #if FEATURE_VERBOSE_EXEC
848 char **pCmd = cmd_argv;
850 printf("%s ", *pCmd);
857 i= spawnv(P_WAIT,got,cmd_argv) == -1;
859 i= spawnvp(P_WAIT,cmd,cmd_argv) == -1;
861 perror("Cannot exec process ");
868 /*-----------------------------------------------------------------*/
869 /* linkEdit : - calls the linkage editor with options */
870 /*-----------------------------------------------------------------*/
871 static void linkEdit (char **envp)
877 srcFileName = "temp";
879 /* first we need to create the <filename>.lnk file */
880 sprintf(buffer,"%s.lnk",srcFileName);
881 if (!(lnkfile = fopen(buffer,"w"))) {
882 werror(E_FILE_OPEN_ERR,buffer);
886 /* now write the options */
887 fprintf(lnkfile,"-mux%c\n", (options.out_fmt ? 's' : 'i'));
889 /* if iram size specified */
890 if (options.iram_size)
891 fprintf(lnkfile,"-a 0x%04x\n",options.iram_size);
893 /*if (options.debug) */
894 fprintf(lnkfile,"-z\n");
895 /* code segment start */
896 fprintf (lnkfile,"-b CODE = 0x%04x\n",options.code_loc);
897 /* data segment start */
898 fprintf (lnkfile,"-b DSEG = 0x%04x\n",options.data_loc);
900 fprintf (lnkfile,"-b XSEG = 0x%04x\n",options.xdata_loc);
902 fprintf (lnkfile,"-b ISEG = 0x%04x\n",options.idata_loc);
903 /* bit segment start */
904 fprintf (lnkfile,"-b BSEG = 0x%04x\n",0);
906 /* add the extra linker options */
907 for (i=0; linkOptions[i] ; i++)
908 fprintf(lnkfile,"%s\n",linkOptions[i]);
910 /* standard library path */
911 fprintf (lnkfile,"-k %s/%s\n",SDCC_LIB_DIR/*STD_LIB_PATH*/,
912 ( (options.model==0) ? "small": "large"));
914 /* other library paths if specified */
915 for (i = 0 ; i < nlibPaths ; i++ )
916 fprintf (lnkfile,"-k %s\n",libPaths[i]);
918 /* standard library files */
919 fprintf (lnkfile,"-l %s\n",STD_LIB);
920 fprintf (lnkfile,"-l %s\n",STD_INT_LIB);
921 fprintf (lnkfile,"-l %s\n",STD_LONG_LIB);
922 fprintf (lnkfile,"-l %s\n",STD_FP_LIB);
924 /* additional libraries if any */
925 for (i = 0 ; i < nlibFiles; i++)
926 fprintf (lnkfile,"-l %s\n",libFiles[i]);
928 /* put in the object files */
929 if (strcmp(srcFileName,"temp"))
930 fprintf (lnkfile,"%s ",srcFileName);
932 for (i = 0 ; i < nrelFiles ; i++ )
933 fprintf (lnkfile,"%s\n",relFiles[i]);
935 fprintf (lnkfile,"\n-e\n");
938 /* call the linker */
939 lnkArgs[0] = "aslink";
941 lnkArgs[2] = srcFileName;
944 if (my_system("aslink",lnkArgs)) {
945 perror("Cannot exec linker");
949 if (strcmp(srcFileName,"temp") == 0) {
950 /* rename "temp.cdb" to "firstRelFile.cdb" */
951 char *f = strtok(strdup(relFiles[0]),".");
952 f = strcat(f,".cdb");
953 rename("temp.cdb",f);
958 /*-----------------------------------------------------------------*/
959 /* assemble - spawns the assembler with arguments */
960 /*-----------------------------------------------------------------*/
961 static void assemble (char **envp)
963 char *asmArgs[128]; /* assembler arguments */
966 asmArgs[0] = "asx8051";
968 /* if (options.debug) */
969 asmArgs[1] = "-plosgffc" ;
971 /* asmArgs[1] = "-plosgff"; */
973 /* add the extra options if any */
974 for (; asmOptions[i-2] ; i++)
975 asmArgs[i] = asmOptions[i-2];
977 /* create the assembler file name */
978 sprintf (buffer, srcFileName);
979 strcat (buffer, ".asm");
980 asmArgs[i++] = buffer;
982 asmArgs[i] = 0; /* end of args */
984 if (my_system("asx8051",asmArgs)) {
985 perror("Cannot exec linker");
991 /*-----------------------------------------------------------------*/
992 /* preProcess - spawns the preprocessor with arguments */
993 /*-----------------------------------------------------------------*/
994 static int preProcess (char **envp)
997 /* if using external stack define the macro */
998 if ( options.useXstack )
999 preArgv[preArgc++] = "-DSDCC_USE_XSTACK" ;
1001 /* set the macro for stack autos */
1002 if ( options.stackAuto )
1003 preArgv[preArgc++] = "-DSDCC_STACK_AUTO";
1005 /* set the macro for large model */
1006 if ( options.model )
1007 preArgv[preArgc++] = "-DSDCC_MODEL_LARGE" ;
1009 preArgv[preArgc++] = "-DSDCC_MODEL_SMALL" ;
1011 preArgv[preArgc++] = fullSrcFileName ;
1013 preArgv[preArgc++] = preOutName = strdup(tmpnam(NULL));
1014 preArgv[preArgc] = NULL;
1016 preArgv[0] = "sdcpp";
1018 if (my_system("sdcpp",preArgv)) {
1019 unlink (preOutName);
1020 perror("Cannot exec Preprocessor");
1027 yyin = fopen(preOutName,"r");
1029 perror("Preproc file not found\n");
1038 * initialises and calls the parser
1041 int main ( int argc, char **argv , char **envp)
1043 /* turn all optimizations off by default */
1044 memset(&optimize,0,sizeof(struct optimize));
1046 /*printVersionInfo ();*/
1048 setDefaultOptions();
1049 parseCmdLine (argc,argv);
1051 /* if no input then printUsage & exit */
1052 if (!srcFileName && !nrelFiles) {
1079 if (!options.cc_only &&
1082 (srcFileName || nrelFiles))
1085 if (yyin && yyin != stdin)