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"
32 extern void initSymt ();
33 extern void initMem ();
34 extern void initExpr ();
35 extern void initiCode ();
36 extern void initCSupport ();
37 extern void initPeepHole ();
38 extern void createObject ();
39 extern int yyparse ();
41 extern struct value *constVal(char *s);
42 extern double floatFromVal(struct value *);
43 extern int fatalError ;
44 FILE *srcFile ;/* source file */
45 FILE *cdbFile = NULL ;/* debugger information output file */
46 char *fullSrcFileName ;/* full name for the source file */
47 char *srcFileName ;/* source file name with the .c stripped */
48 char *moduleName ;/* module name is srcFilename stripped of any path */
49 char *preArgv[128] ;/* pre-processor arguments */
50 int preArgc = 0 ;/* pre-processor argument count */
52 struct optimize optimize ;
53 struct options options ;
54 char *VersionString = SDCC_VERSION_STR /*"Version 2.1.8a"*/;
55 short preProcOnly = 0;
57 char *linkOptions[128];
58 char *asmOptions[128];
65 //extern int wait (int *);
68 #define OPTION_LARGE_MODEL "-model-large"
69 #define OPTION_SMALL_MODEL "-model-small"
70 #define OPTION_STACK_AUTO "-stack-auto"
71 #define OPTION_XSTACK "-xstack"
72 #define OPTION_GENERIC "-generic"
73 #define OPTION_NO_GCSE "-nogcse"
74 #define OPTION_NO_LOOP_INV "-noinvariant"
75 #define OPTION_NO_LOOP_IND "-noinduction"
76 #define OPTION_NO_JTBOUND "-nojtbound"
77 #define OPTION_NO_LOOPREV "-noloopreverse"
78 #define OPTION_XREGS "-regextend"
79 #define OPTION_COMP_ONLY "-compile-only"
80 #define OPTION_DUMP_RAW "-dumpraw"
81 #define OPTION_DUMP_GCSE "-dumpgcse"
82 #define OPTION_DUMP_LOOP "-dumploop"
83 #define OPTION_DUMP_KILL "-dumpdeadcode"
84 #define OPTION_DUMP_RANGE "-dumpliverange"
85 #define OPTION_DUMP_PACK "-dumpregpack"
86 #define OPTION_DUMP_RASSGN "-dumpregassign"
87 #define OPTION_DUMP_ALL "-dumpall"
88 #define OPTION_XRAM_LOC "-xram-loc"
89 #define OPTION_IRAM_SIZE "-iram-size"
90 #define OPTION_XSTACK_LOC "-xstack-loc"
91 #define OPTION_CODE_LOC "-code-loc"
92 #define OPTION_STACK_LOC "-stack-loc"
93 #define OPTION_DATA_LOC "-data-loc"
94 #define OPTION_IDATA_LOC "-idata-loc"
95 #define OPTION_PEEP_FILE "-peep-file"
96 #define OPTION_LIB_PATH "-lib-path"
97 #define OPTION_INTLONG_RENT "-int-long-reent"
98 #define OPTION_FLOAT_RENT "-float-reent"
99 #define OPTION_OUT_FMT_IHX "-out-fmt-ihx"
100 #define OPTION_OUT_FMT_S19 "-out-fmt-s19"
101 #define OPTION_CYCLOMATIC "-cyclomatic"
102 #define OPTION_NOOVERLAY "-nooverlay"
103 #define OPTION_MAINRETURN "-main-return"
104 #define OPTION_NOPEEP "-no-peep"
105 #define OPTION_ASMPEEP "-peep-asm"
106 #define OPTION_DEBUG "-debug"
107 #define OPTION_VERSION "-version"
108 #define OPTION_STKAFTRDATA "-stack-after-data"
109 #define OPTION_PREPROC_ONLY "-preprocessonly"
110 #define OPTION_HELP "-help"
111 #define OPTION_CALLEE_SAVES "-callee-saves"
112 #define OPTION_NOREGPARMS "-noregparms"
113 /*-----------------------------------------------------------------*/
114 /* printVersionInfo - prints the version info */
115 /*-----------------------------------------------------------------*/
116 void printVersionInfo ()
121 "SDCC : MCU 8051 %s "
135 /*-----------------------------------------------------------------*/
136 /* printUsage - prints command line syntax */
137 /*-----------------------------------------------------------------*/
142 "Usage : [options] filename\n"
144 "\t--model-large - Large Model\n"
145 "\t--model-small - Small Model (default)\n"
146 "\t--stack-auto - Stack automatic variables\n"
147 "\t--xstack - Use external stack\n"
148 "\t--xram-loc <nnnn> - External Ram start location\n"
149 "\t--xstack-loc <nnnn> - Xternal Stack Location\n"
150 "\t--code-loc <nnnn> - Code Segment Location\n"
151 "\t--stack-loc <nnnn> - Stack pointer initial value\n"
152 "\t--data-loc <nnnn> - Direct data start location\n"
153 "\t--idata-loc <nnnn> - Indirect data start location\n"
154 "\t--iram-size <nnnn> - Internal Ram size\n"
155 "\t--nojtbound - Don't generate boundary check for jump tables\n"
156 "\t--generic - All unqualified ptrs converted to '_generic'\n"
157 "PreProcessor Options :-\n"
158 "\t-Dmacro - Define Macro\n"
159 "\t-Ipath - Include \"*.h\" path\n"
160 "Note: this is a complete list of options see docs for details\n");
164 /*-----------------------------------------------------------------*/
165 /* parseWithComma - separates string with comma */
166 /*-----------------------------------------------------------------*/
167 void parseWithComma (char **dest,char *src)
172 /* skip the initial white spaces */
173 while (isspace(*src)) src++;
187 /*-----------------------------------------------------------------*/
188 /* setDefaultOptions - sets the default options */
189 /*-----------------------------------------------------------------*/
190 static void setDefaultOptions()
194 for ( i = 0 ; i < 128 ; i++)
195 preArgv[i] = linkOptions [i] =
196 asmOptions[i] = relFiles[i] = libFiles[i] =
198 preArgv[preArgc++] = "-version";
199 preArgv[preArgc++] = "-Wall";
200 preArgv[preArgc++] = "-lang-c++";
201 preArgv[preArgc++] = "-DSDCC=1";
202 preArgv[preArgc++] = "-I" SDCC_INCLUDE_DIR ;
204 /* first the options part */
205 options.stack_loc = 0; /* stack pointer initialised to 0 */
206 options.xstack_loc= 0; /* xternal stack starts at 0 */
207 options.code_loc = 0; /* code starts at 0 */
208 options.data_loc = 0x0030; /* data starts at 0x0030 */
209 options.xdata_loc = 0;
210 options.idata_loc = 0x80;
211 options.genericPtr = 1; /* default on */
214 /* now for the optimizations */
215 /* turn on the everything */
216 optimize.global_cse = 1;
221 optimize.loopInvariant = 1;
222 optimize.loopInduction = 1;
225 /*-----------------------------------------------------------------*/
226 /* processFile - determines the type of file from the extension */
227 /*-----------------------------------------------------------------*/
228 static void processFile (char *s)
232 /* get the file extension */
233 fext = s + strlen(s);
234 while ((fext != s) && *fext != '.') fext--;
236 /* now if no '.' then we don't know what the file type is
237 so give a warning and return */
239 werror(W_UNKNOWN_FEXT,s);
243 /* otherwise depending on the file type */
244 if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0) {
245 /* source file name : not if we already have a
248 werror(W_TOO_MANY_SRC,s);
252 /* the only source file */
253 if (!(srcFile = fopen((fullSrcFileName = s),"r"))) {
254 werror(E_FILE_OPEN_ERR,s);
258 /* copy the file name into the buffer */
261 /* get rid of the "." */
263 ALLOC_ATOMIC(srcFileName,strlen(buffer)+1);
264 strcpy(srcFileName,buffer);
266 /* get rid of any path information
267 for the module name; do this by going
268 backwards till we get to either '/' or '\' or ':'
269 or start of buffer */
270 fext = buffer + strlen(buffer);
271 while (fext != buffer &&
272 *(fext -1) != '\\' &&
276 ALLOC_ATOMIC(moduleName,strlen(fext)+1);
277 strcpy(moduleName,fext);
282 /* if the extention is type .rel or .r or .REL or .R
283 addtional object file will be passed to the linker */
284 if (strcmp(fext,".r") == 0 || strcmp(fext,".rel") == 0 ||
285 strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0) {
287 relFiles[nrelFiles++] = s;
291 /* if .lib or .LIB */
292 if (strcmp(fext,".lib") == 0 || strcmp(fext,".LIB") == 0) {
293 libFiles[nlibFiles++] = s;
297 werror(W_UNKNOWN_FEXT,s);
302 /*-----------------------------------------------------------------*/
303 /* parseCmdLine - parses the command line and sets the options */
304 /*-----------------------------------------------------------------*/
305 int parseCmdLine ( int argc, char **argv )
310 /* go thru all whole command line */
311 for ( i = 1; i < argc; i++ ) {
316 if (argv[i][0] == '-' && argv[i][1] == '-') {
318 if (strcmp(&argv[i][1],OPTION_HELP) == 0) {
323 if (strcmp(&argv[i][1],OPTION_XREGS) == 0) {
324 options.regExtend = 1;
328 if (strcmp(&argv[i][1],OPTION_LARGE_MODEL) == 0) {
333 if (strcmp(&argv[i][1],OPTION_SMALL_MODEL) == 0) {
338 if (strcmp(&argv[i][1],OPTION_STACK_AUTO) == 0) {
339 options.stackAuto = 1;
343 if (strcmp(&argv[i][1],OPTION_DUMP_RAW) == 0) {
344 options.dump_raw = 1;
348 if (strcmp(&argv[i][1],OPTION_CYCLOMATIC) == 0) {
349 options.cyclomatic = 1;
353 if (strcmp(&argv[i][1],OPTION_DUMP_GCSE) == 0) {
354 options.dump_gcse = 1;
358 if (strcmp(&argv[i][1],OPTION_DUMP_LOOP) == 0) {
359 options.dump_loop = 1;
363 if (strcmp(&argv[i][1],OPTION_DUMP_KILL) == 0) {
364 options.dump_kill = 1;
368 if (strcmp(&argv[i][1],OPTION_INTLONG_RENT) == 0) {
369 options.intlong_rent = 1;
373 if (strcmp(&argv[i][1],OPTION_FLOAT_RENT) == 0) {
374 options.float_rent = 1;
378 if (strcmp(&argv[i][1],OPTION_DUMP_RANGE) == 0) {
379 options.dump_range = 1;
383 if (strcmp(&argv[i][1],OPTION_DUMP_PACK) == 0) {
384 options.dump_pack = 1;
388 if (strcmp(&argv[i][1],OPTION_DUMP_RASSGN) == 0) {
389 options.dump_rassgn = 1;
393 if (strcmp(&argv[i][1],OPTION_OUT_FMT_IHX) == 0) {
398 if (strcmp(&argv[i][1],OPTION_OUT_FMT_S19) == 0) {
403 if (strcmp(&argv[i][1],OPTION_NOOVERLAY) == 0) {
404 options.noOverlay = 1;
408 if (strcmp(&argv[i][1],OPTION_STKAFTRDATA) == 0) {
409 options.stackOnData = 1;
413 if (strcmp(&argv[i][1],OPTION_PREPROC_ONLY) == 0) {
419 if (strcmp(&argv[i][1],OPTION_DUMP_ALL) == 0) {
420 options.dump_rassgn =
426 options.dump_raw = 1;
430 if (strcmp(&argv[i][1],OPTION_COMP_ONLY) == 0) {
435 if (strcmp(&argv[i][1],OPTION_GENERIC) == 0) {
436 options.genericPtr = 1;
440 if (strcmp(&argv[i][1],OPTION_NOPEEP) == 0) {
445 if (strcmp(&argv[i][1],OPTION_ASMPEEP) == 0) {
450 if (strcmp(&argv[i][1],OPTION_DEBUG) == 0) {
455 if (strcmp(&argv[i][1],OPTION_NOREGPARMS) == 0) {
456 options.noregparms = 1;
460 if (strcmp(&argv[i][1],OPTION_PEEP_FILE) == 0) {
461 if (argv[i][1+strlen(OPTION_PEEP_FILE)])
463 &argv[i][1+strlen(OPTION_PEEP_FILE)];
465 options.peep_file = argv[++i];
469 if (strcmp(&argv[i][1],OPTION_LIB_PATH) == 0) {
470 if (argv[i][1+strlen(OPTION_LIB_PATH)])
471 libPaths[nlibPaths++] =
472 &argv[i][1+strlen(OPTION_PEEP_FILE)];
474 libPaths[nlibPaths++] = argv[++i];
478 if (strcmp(&argv[i][1],OPTION_XSTACK_LOC) == 0) {
480 if (argv[i][1+strlen(OPTION_XSTACK_LOC)])
482 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XSTACK_LOC)]));
485 (int) floatFromVal(constVal(argv[++i]));
489 if (strcmp(&argv[i][1],OPTION_XSTACK) == 0) {
490 options.useXstack = 1;
494 if (strcmp(&argv[i][1],OPTION_MAINRETURN) == 0) {
495 options.mainreturn = 1;
499 if (strcmp(&argv[i][1],OPTION_CALLEE_SAVES) == 0) {
500 if (argv[i][1+strlen(OPTION_CALLEE_SAVES)])
501 parseWithComma(options.calleeSaves
502 ,&argv[i][1+strlen(OPTION_CALLEE_SAVES)]);
504 parseWithComma(options.calleeSaves,argv[++i]);
508 if (strcmp(&argv[i][1],OPTION_STACK_LOC) == 0) {
510 if (argv[i][1+strlen(OPTION_STACK_LOC)])
512 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_STACK_LOC)]));
515 (int) floatFromVal(constVal(argv[++i]));
519 if (strcmp(&argv[i][1],OPTION_XRAM_LOC) == 0) {
521 if (argv[i][1+strlen(OPTION_XRAM_LOC)])
523 (unsigned int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XRAM_LOC)]));
526 (unsigned int) floatFromVal(constVal(argv[++i]));
530 if (strcmp(&argv[i][1],OPTION_IRAM_SIZE) == 0) {
532 if (argv[i][1+strlen(OPTION_IRAM_SIZE)])
534 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IRAM_SIZE)]));
537 (int) floatFromVal(constVal(argv[++i]));
541 if (strcmp(&argv[i][1],OPTION_VERSION) == 0) {
547 if (strcmp(&argv[i][1],OPTION_DATA_LOC) == 0) {
549 if (argv[i][1+strlen(OPTION_DATA_LOC)])
551 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_DATA_LOC)]));
554 (int) floatFromVal(constVal(argv[++i]));
558 if (strcmp(&argv[i][1],OPTION_IDATA_LOC) == 0) {
560 if (argv[i][1+strlen(OPTION_IDATA_LOC)])
562 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IDATA_LOC)]));
565 (int) floatFromVal(constVal(argv[++i]));
569 if (strcmp(&argv[i][1],OPTION_CODE_LOC) == 0) {
571 if (argv[i][1+strlen(OPTION_CODE_LOC)])
573 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_CODE_LOC)]));
576 (int) floatFromVal(constVal(argv[++i]));
581 if (strcmp(&argv[i][1],OPTION_NO_JTBOUND) == 0) {
582 optimize.noJTabBoundary = 1;
586 if (strcmp(&argv[i][1],OPTION_NO_GCSE) == 0) {
587 optimize.global_cse = 0;
591 if (strcmp(&argv[i][1],OPTION_NO_LOOP_INV) == 0) {
592 optimize.loopInvariant = 0;
596 if (strcmp(&argv[i][1],OPTION_NO_LOOP_IND) == 0) {
597 optimize.loopInduction = 0;
601 if (strcmp(&argv[i][1],OPTION_NO_LOOPREV) == 0) {
602 optimize.noLoopReverse = 1;
606 werror(W_UNKNOWN_OPTION,argv[i]);
609 /* these are undocumented options */
610 /* if preceded by '/' then turn off certain optmizations, used
611 for debugging only these are also the legacy options from
612 version 1.xx will be removed gradually */
613 if ( *argv[i] == '/') {
614 switch (argv[i][1]) {
617 optimize.ptrArithmetic=0;
621 switch (argv[i][2]) {
626 optimize.label4 = 0 ;
644 switch (argv[i][2]) {
646 optimize.loopInvariant = 0;
649 optimize.loopInduction = 0;
656 optimize.global_cse = 0;
663 /* if preceded by '-' then option */
664 if ( *argv[i] == '-' ) {
665 switch (argv[i][1]) {
676 werror(W_UNSUPP_OPTION,"-mL/-mS","use --model-large/--model-small instead");
680 werror(W_UNSUPP_OPTION,"-a","use --stack-auto instead");
684 werror(W_UNSUPP_OPTION,"-g","use --generic instead");
687 case 'X' : /* use external stack */
688 werror(W_UNSUPP_OPTION,"-X","use --xstack-loc instead");
692 werror(W_UNSUPP_OPTION,"-x","use --xstack instead");
695 case 'p' : /* stack pointer intial value */
697 werror(W_UNSUPP_OPTION,"-p","use --stack-loc instead");
701 werror(W_UNSUPP_OPTION,"-i","use --idata-loc instead");
705 werror(W_UNSUPP_OPTION,"-r","use --xdata-loc instead");
709 werror(W_UNSUPP_OPTION,"-s","use --code-loc instead");
717 werror(W_UNSUPP_OPTION,"-Y","use -I instead");
722 libPaths[nlibPaths++] = &argv[i][2];
724 libPaths[nlibPaths++] = argv[++i];
729 if (argv[i][2] == 'l') {
731 parseWithComma(linkOptions,&argv[i][3]);
733 parseWithComma(linkOptions,argv[++i]);
735 /* assembler options */
736 if (argv[i][2] == 'a') {
738 parseWithComma(asmOptions,&argv[i][3]);
740 parseWithComma(asmOptions,argv[++i]);
743 werror(W_UNKNOWN_OPTION,argv[i]);
756 /* preprocessor options */
765 char sOpt = argv[i][1] ;
768 if ( argv[i][2] == ' ' || argv[i][2] == '\0') {
775 /* increase allocation for preprocessor argv
776 if (!(preArgv = realloc(preArgv,(preArgc+1)*sizeof(char **)))) {
777 werror (E_OUT_OF_MEM);
780 if ( argv[i][1] == 'Y' )
782 if (argv[i][1] == 'M')
785 if (!(preArgv[preArgc] = GC_malloc(strlen(rest)+3))) {
786 werror(E_OUT_OF_MEM,__FILE__,strlen(rest)+3);
790 sprintf(preArgv[preArgc],"-%c%s",sOpt,rest);
796 werror(W_UNKNOWN_OPTION,argv[i]);
801 /* no option must be a filename */
802 processFile(argv[i]);
807 /* set up external stack location if not explicitly specified */
808 if ( !options.xstack_loc )
809 options.xstack_loc = options.xdata_loc ;
811 /* if debug option is set the open the cdbFile */
812 if (/* options.debug && */ srcFileName) {
813 sprintf(cdbfnbuf,"%s.cdb",srcFileName);
814 if ((cdbFile = fopen(cdbfnbuf,"w")) == NULL)
815 werror(E_FILE_OPEN_ERR,cdbfnbuf);
817 /* add a module record */
818 fprintf(cdbFile,"M:%s\n",moduleName);
824 /*-----------------------------------------------------------------*/
825 /* my_system - will call a program with arguments */
826 /*-----------------------------------------------------------------*/
827 char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
828 int my_system (const char *cmd, char **cmd_argv)
831 char *dir, *got= NULL; int i= 0;
832 while (!got && try_dir[i]) {
833 dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10);
834 strcpy(dir, try_dir[i]); strcat(dir, "/"); strcat(dir, cmd);
835 if (access(dir, X_OK) == 0)
841 i= spawnv(P_WAIT,got,cmd_argv) == -1;
843 i= spawnvp(P_WAIT,cmd,cmd_argv) == -1;
845 perror("Cannot exec process ");
852 /*-----------------------------------------------------------------*/
853 /* linkEdit : - calls the linkage editor with options */
854 /*-----------------------------------------------------------------*/
855 static void linkEdit (char **envp)
861 srcFileName = "temp";
863 /* first we need to create the <filename>.lnk file */
864 sprintf(buffer,"%s.lnk",srcFileName);
865 if (!(lnkfile = fopen(buffer,"w"))) {
866 werror(E_FILE_OPEN_ERR,buffer);
870 /* now write the options */
871 fprintf(lnkfile,"-mux%c\n", (options.out_fmt ? 's' : 'i'));
873 /* if iram size specified */
874 if (options.iram_size)
875 fprintf(lnkfile,"-a 0x%04x\n",options.iram_size);
877 /*if (options.debug) */
878 fprintf(lnkfile,"-z\n");
879 /* code segment start */
880 fprintf (lnkfile,"-b CODE = 0x%04x\n",options.code_loc);
881 /* data segment start */
882 fprintf (lnkfile,"-b DSEG = 0x%04x\n",options.data_loc);
884 fprintf (lnkfile,"-b XSEG = 0x%04x\n",options.xdata_loc);
886 fprintf (lnkfile,"-b ISEG = 0x%04x\n",options.idata_loc);
887 /* bit segment start */
888 fprintf (lnkfile,"-b BSEG = 0x%04x\n",0);
890 /* add the extra linker options */
891 for (i=0; linkOptions[i] ; i++)
892 fprintf(lnkfile,"%s\n",linkOptions[i]);
894 /* standard library path */
895 fprintf (lnkfile,"-k %s/%s\n",SDCC_LIB_DIR/*STD_LIB_PATH*/,
896 ( (options.model==0) ? "small": "large"));
898 /* other library paths if specified */
899 for (i = 0 ; i < nlibPaths ; i++ )
900 fprintf (lnkfile,"-k %s\n",libPaths[i]);
902 /* standard library files */
903 fprintf (lnkfile,"-l %s\n",STD_LIB);
904 fprintf (lnkfile,"-l %s\n",STD_INT_LIB);
905 fprintf (lnkfile,"-l %s\n",STD_LONG_LIB);
906 fprintf (lnkfile,"-l %s\n",STD_FP_LIB);
908 /* additional libraries if any */
909 for (i = 0 ; i < nlibFiles; i++)
910 fprintf (lnkfile,"-l %s\n",libFiles[i]);
912 /* put in the object files */
913 if (strcmp(srcFileName,"temp"))
914 fprintf (lnkfile,"%s ",srcFileName);
916 for (i = 0 ; i < nrelFiles ; i++ )
917 fprintf (lnkfile,"%s\n",relFiles[i]);
919 fprintf (lnkfile,"\n-e\n");
922 /* call the linker */
923 lnkArgs[0] = "aslink";
925 lnkArgs[2] = srcFileName;
928 if (my_system("aslink",lnkArgs)) {
929 perror("Cannot exec linker");
933 if (strcmp(srcFileName,"temp") == 0) {
934 /* rename "temp.cdb" to "firstRelFile.cdb" */
935 char *f = strtok(strdup(relFiles[0]),".");
936 f = strcat(f,".cdb");
937 rename("temp.cdb",f);
942 /*-----------------------------------------------------------------*/
943 /* assemble - spawns the assembler with arguments */
944 /*-----------------------------------------------------------------*/
945 static void assemble (char **envp)
947 char *asmArgs[128]; /* assembler arguments */
950 asmArgs[0] = "asx8051";
952 /* if (options.debug) */
953 asmArgs[1] = "-plosgffc" ;
955 /* asmArgs[1] = "-plosgff"; */
957 /* add the extra options if any */
958 for (; asmOptions[i-2] ; i++)
959 asmArgs[i] = asmOptions[i-2];
961 /* create the assembler file name */
962 sprintf (buffer, srcFileName);
963 strcat (buffer, ".asm");
964 asmArgs[i++] = buffer;
966 asmArgs[i] = 0; /* end of args */
968 if (my_system("asx8051",asmArgs)) {
969 perror("Cannot exec linker");
975 /*-----------------------------------------------------------------*/
976 /* preProcess - spawns the preprocessor with arguments */
977 /*-----------------------------------------------------------------*/
978 static int preProcess (char **envp)
981 /* if using external stack define the macro */
982 if ( options.useXstack )
983 preArgv[preArgc++] = "-DSDCC_USE_XSTACK" ;
985 /* set the macro for stack autos */
986 if ( options.stackAuto )
987 preArgv[preArgc++] = "-DSDCC_STACK_AUTO";
989 /* set the macro for large model */
991 preArgv[preArgc++] = "-DSDCC_MODEL_LARGE" ;
993 preArgv[preArgc++] = "-DSDCC_MODEL_SMALL" ;
995 preArgv[preArgc++] = fullSrcFileName ;
997 preArgv[preArgc++] = preOutName = strdup(tmpnam(NULL));
998 preArgv[preArgc] = NULL;
1000 preArgv[0] = "sdcpp";
1002 if (my_system("sdcpp",preArgv)) {
1003 unlink (preOutName);
1004 perror("Cannot exec Preprocessor");
1011 yyin = fopen(preOutName,"r");
1013 perror("Preproc file not found\n");
1022 * initialises and calls the parser
1025 int main ( int argc, char **argv , char **envp)
1027 /* turn all optimizations off by default */
1028 memset(&optimize,0,sizeof(struct optimize));
1030 /*printVersionInfo ();*/
1032 setDefaultOptions();
1033 parseCmdLine (argc,argv);
1035 /* if no input then printUsage & exit */
1036 if (!srcFileName && !nrelFiles) {
1063 if (!options.cc_only &&
1066 (srcFileName || nrelFiles))
1069 if (yyin && yyin != stdin)