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 const char *preArgv[128] ;/* pre-processor arguments */
55 struct optimize optimize ;
56 struct options options ;
57 char *VersionString = SDCC_VERSION_STR /*"Version 2.1.8a"*/;
58 short preProcOnly = 0;
60 char *linkOptions[128];
61 const char *asmOptions[128];
68 bool verboseExec = FALSE;
69 //extern int wait (int *);
72 #define OPTION_LARGE_MODEL "-model-large"
73 #define OPTION_SMALL_MODEL "-model-small"
74 #define OPTION_STACK_AUTO "-stack-auto"
75 #define OPTION_XSTACK "-xstack"
76 #define OPTION_GENERIC "-generic"
77 #define OPTION_NO_GCSE "-nogcse"
78 #define OPTION_NO_LOOP_INV "-noinvariant"
79 #define OPTION_NO_LOOP_IND "-noinduction"
80 #define OPTION_NO_JTBOUND "-nojtbound"
81 #define OPTION_NO_LOOPREV "-noloopreverse"
82 #define OPTION_XREGS "-regextend"
83 #define OPTION_COMP_ONLY "-compile-only"
84 #define OPTION_DUMP_RAW "-dumpraw"
85 #define OPTION_DUMP_GCSE "-dumpgcse"
86 #define OPTION_DUMP_LOOP "-dumploop"
87 #define OPTION_DUMP_KILL "-dumpdeadcode"
88 #define OPTION_DUMP_RANGE "-dumpliverange"
89 #define OPTION_DUMP_PACK "-dumpregpack"
90 #define OPTION_DUMP_RASSGN "-dumpregassign"
91 #define OPTION_DUMP_ALL "-dumpall"
92 #define OPTION_XRAM_LOC "-xram-loc"
93 #define OPTION_IRAM_SIZE "-iram-size"
94 #define OPTION_XSTACK_LOC "-xstack-loc"
95 #define OPTION_CODE_LOC "-code-loc"
96 #define OPTION_STACK_LOC "-stack-loc"
97 #define OPTION_DATA_LOC "-data-loc"
98 #define OPTION_IDATA_LOC "-idata-loc"
99 #define OPTION_PEEP_FILE "-peep-file"
100 #define OPTION_LIB_PATH "-lib-path"
101 #define OPTION_INTLONG_RENT "-int-long-reent"
102 #define OPTION_FLOAT_RENT "-float-reent"
103 #define OPTION_OUT_FMT_IHX "-out-fmt-ihx"
104 #define OPTION_OUT_FMT_S19 "-out-fmt-s19"
105 #define OPTION_CYCLOMATIC "-cyclomatic"
106 #define OPTION_NOOVERLAY "-nooverlay"
107 #define OPTION_MAINRETURN "-main-return"
108 #define OPTION_NOPEEP "-no-peep"
109 #define OPTION_ASMPEEP "-peep-asm"
110 #define OPTION_DEBUG "-debug"
111 #define OPTION_VERSION "-version"
112 #define OPTION_STKAFTRDATA "-stack-after-data"
113 #define OPTION_PREPROC_ONLY "-preprocessonly"
114 #define OPTION_HELP "-help"
115 #define OPTION_CALLEE_SAVES "-callee-saves"
116 #define OPTION_NOREGPARMS "-noregparms"
118 static const char *_preCmd[] = {
119 "sdcpp", "-version", "-Wall", "-lang-c++", "-DSDCC=1",
120 "-I" SDCC_INCLUDE_DIR, "$l", "$1", "$2", NULL
123 extern PORT mcs51_port;
124 extern PORT z80_port;
128 static PORT *_ports[] = {
133 #define NUM_PORTS (sizeof(_ports)/sizeof(_ports[0]))
135 /** Sets the port to the one given by the command line option.
136 @param The name minus the option (eg 'mcs51')
137 @return 0 on success.
139 static int _setPort(const char *name)
142 for (i=0; i<NUM_PORTS; i++) {
143 if (!strcmp(_ports[i]->target, name)) {
148 /* Error - didnt find */
152 static void _buildCmdLine(char *into, char **args, const char **cmds,
153 const char *p1, const char *p2,
154 const char *p3, const char **list)
156 const char *p, *from;
166 /* See if it has a '$' anywhere - if not, just copy */
167 if ((p = strchr(from, '$'))) {
168 strncpy(into, from, p - from);
185 const char **tmp = list;
189 into += strlen(into)+1;
202 if (strlen(into) == 0)
204 into += strlen(into)+1;
209 /*-----------------------------------------------------------------*/
210 /* printVersionInfo - prints the version info */
211 /*-----------------------------------------------------------------*/
212 void printVersionInfo ()
218 for (i=0; i<NUM_PORTS; i++)
219 fprintf(stderr, "%s%s", i==0 ? "" : "/", _ports[i]->target);
221 fprintf(stderr, " %s `"
235 /*-----------------------------------------------------------------*/
236 /* printUsage - prints command line syntax */
237 /*-----------------------------------------------------------------*/
242 "Usage : [options] filename\n"
244 "\t-m<proc> - Target processor <proc>. Default %s\n"
245 "\t Try --version for supported values of <proc>\n"
246 "\t--model-large - Large Model\n"
247 "\t--model-small - Small Model (default)\n"
248 "\t--stack-auto - Stack automatic variables\n"
249 "\t--xstack - Use external stack\n"
250 "\t--xram-loc <nnnn> - External Ram start location\n"
251 "\t--xstack-loc <nnnn> - Xternal Stack Location\n"
252 "\t--code-loc <nnnn> - Code Segment Location\n"
253 "\t--stack-loc <nnnn> - Stack pointer initial value\n"
254 "\t--data-loc <nnnn> - Direct data start location\n"
255 "\t--idata-loc <nnnn> - Indirect data start location\n"
256 "\t--iram-size <nnnn> - Internal Ram size\n"
257 "\t--nojtbound - Don't generate boundary check for jump tables\n"
258 "\t--generic - All unqualified ptrs converted to '_generic'\n"
259 "PreProcessor Options :-\n"
260 "\t-Dmacro - Define Macro\n"
261 "\t-Ipath - Include \"*.h\" path\n"
262 "Note: this is a complete list of options see docs for details\n",
268 /*-----------------------------------------------------------------*/
269 /* parseWithComma - separates string with comma */
270 /*-----------------------------------------------------------------*/
271 void parseWithComma (char **dest,char *src)
276 /* skip the initial white spaces */
277 while (isspace(*src)) src++;
291 /*-----------------------------------------------------------------*/
292 /* setDefaultOptions - sets the default options */
293 /*-----------------------------------------------------------------*/
294 static void setDefaultOptions()
298 for ( i = 0 ; i < 128 ; i++)
299 preArgv[i] = linkOptions [i] =
300 asmOptions[i] = relFiles[i] = libFiles[i] =
303 /* first the options part */
304 options.stack_loc = 0; /* stack pointer initialised to 0 */
305 options.xstack_loc= 0; /* xternal stack starts at 0 */
306 options.code_loc = 0; /* code starts at 0 */
307 options.data_loc = 0x0030; /* data starts at 0x0030 */
308 options.xdata_loc = 0;
309 options.idata_loc = 0x80;
310 options.genericPtr = 1; /* default on */
313 /* now for the optimizations */
314 /* turn on the everything */
315 optimize.global_cse = 1;
320 optimize.loopInvariant = 1;
321 optimize.loopInduction = 1;
323 port->setDefaultOptions();
326 /*-----------------------------------------------------------------*/
327 /* processFile - determines the type of file from the extension */
328 /*-----------------------------------------------------------------*/
329 static void processFile (char *s)
333 /* get the file extension */
334 fext = s + strlen(s);
335 while ((fext != s) && *fext != '.') fext--;
337 /* now if no '.' then we don't know what the file type is
338 so give a warning and return */
340 werror(W_UNKNOWN_FEXT,s);
344 /* otherwise depending on the file type */
345 if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0) {
346 /* source file name : not if we already have a
349 werror(W_TOO_MANY_SRC,s);
353 /* the only source file */
354 if (!(srcFile = fopen((fullSrcFileName = s),"r"))) {
355 werror(E_FILE_OPEN_ERR,s);
359 /* copy the file name into the buffer */
362 /* get rid of the "." */
364 ALLOC_ATOMIC(srcFileName,strlen(buffer)+1);
365 strcpy(srcFileName,buffer);
367 /* get rid of any path information
368 for the module name; do this by going
369 backwards till we get to either '/' or '\' or ':'
370 or start of buffer */
371 fext = buffer + strlen(buffer);
372 while (fext != buffer &&
373 *(fext -1) != '\\' &&
377 ALLOC_ATOMIC(moduleName,strlen(fext)+1);
378 strcpy(moduleName,fext);
383 /* if the extention is type .rel or .r or .REL or .R
384 addtional object file will be passed to the linker */
385 if (strcmp(fext,".r") == 0 || strcmp(fext,".rel") == 0 ||
386 strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0) {
388 relFiles[nrelFiles++] = s;
392 /* if .lib or .LIB */
393 if (strcmp(fext,".lib") == 0 || strcmp(fext,".LIB") == 0) {
394 libFiles[nlibFiles++] = s;
398 werror(W_UNKNOWN_FEXT,s);
402 static void _addToList(const char **list, const char *str)
404 /* This is the bad way to do things :) */
409 werror(E_OUT_OF_MEM,__FILE__, 0);
415 /*-----------------------------------------------------------------*/
416 /* parseCmdLine - parses the command line and sets the options */
417 /*-----------------------------------------------------------------*/
418 int parseCmdLine ( int argc, char **argv )
423 /* go thru all whole command line */
424 for ( i = 1; i < argc; i++ ) {
429 if (argv[i][0] == '-' && argv[i][1] == '-') {
431 if (strcmp(&argv[i][1],OPTION_HELP) == 0) {
436 if (strcmp(&argv[i][1],OPTION_XREGS) == 0) {
437 options.regExtend = 1;
441 if (strcmp(&argv[i][1],OPTION_LARGE_MODEL) == 0) {
446 if (strcmp(&argv[i][1],OPTION_SMALL_MODEL) == 0) {
451 if (strcmp(&argv[i][1],OPTION_STACK_AUTO) == 0) {
452 options.stackAuto = 1;
456 if (strcmp(&argv[i][1],OPTION_DUMP_RAW) == 0) {
457 options.dump_raw = 1;
461 if (strcmp(&argv[i][1],OPTION_CYCLOMATIC) == 0) {
462 options.cyclomatic = 1;
466 if (strcmp(&argv[i][1],OPTION_DUMP_GCSE) == 0) {
467 options.dump_gcse = 1;
471 if (strcmp(&argv[i][1],OPTION_DUMP_LOOP) == 0) {
472 options.dump_loop = 1;
476 if (strcmp(&argv[i][1],OPTION_DUMP_KILL) == 0) {
477 options.dump_kill = 1;
481 if (strcmp(&argv[i][1],OPTION_INTLONG_RENT) == 0) {
482 options.intlong_rent = 1;
486 if (strcmp(&argv[i][1],OPTION_FLOAT_RENT) == 0) {
487 options.float_rent = 1;
491 if (strcmp(&argv[i][1],OPTION_DUMP_RANGE) == 0) {
492 options.dump_range = 1;
496 if (strcmp(&argv[i][1],OPTION_DUMP_PACK) == 0) {
497 options.dump_pack = 1;
501 if (strcmp(&argv[i][1],OPTION_DUMP_RASSGN) == 0) {
502 options.dump_rassgn = 1;
506 if (strcmp(&argv[i][1],OPTION_OUT_FMT_IHX) == 0) {
511 if (strcmp(&argv[i][1],OPTION_OUT_FMT_S19) == 0) {
516 if (strcmp(&argv[i][1],OPTION_NOOVERLAY) == 0) {
517 options.noOverlay = 1;
521 if (strcmp(&argv[i][1],OPTION_STKAFTRDATA) == 0) {
522 options.stackOnData = 1;
526 if (strcmp(&argv[i][1],OPTION_PREPROC_ONLY) == 0) {
532 if (strcmp(&argv[i][1],OPTION_DUMP_ALL) == 0) {
533 options.dump_rassgn =
539 options.dump_raw = 1;
543 if (strcmp(&argv[i][1],OPTION_COMP_ONLY) == 0) {
548 if (strcmp(&argv[i][1],OPTION_GENERIC) == 0) {
549 options.genericPtr = 1;
553 if (strcmp(&argv[i][1],OPTION_NOPEEP) == 0) {
558 if (strcmp(&argv[i][1],OPTION_ASMPEEP) == 0) {
563 if (strcmp(&argv[i][1],OPTION_DEBUG) == 0) {
568 if (strcmp(&argv[i][1],OPTION_NOREGPARMS) == 0) {
569 options.noregparms = 1;
573 if (strcmp(&argv[i][1],OPTION_PEEP_FILE) == 0) {
574 if (argv[i][1+strlen(OPTION_PEEP_FILE)])
576 &argv[i][1+strlen(OPTION_PEEP_FILE)];
578 options.peep_file = argv[++i];
582 if (strcmp(&argv[i][1],OPTION_LIB_PATH) == 0) {
583 if (argv[i][1+strlen(OPTION_LIB_PATH)])
584 libPaths[nlibPaths++] =
585 &argv[i][1+strlen(OPTION_PEEP_FILE)];
587 libPaths[nlibPaths++] = argv[++i];
591 if (strcmp(&argv[i][1],OPTION_XSTACK_LOC) == 0) {
593 if (argv[i][1+strlen(OPTION_XSTACK_LOC)])
595 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XSTACK_LOC)]));
598 (int) floatFromVal(constVal(argv[++i]));
602 if (strcmp(&argv[i][1],OPTION_XSTACK) == 0) {
603 options.useXstack = 1;
607 if (strcmp(&argv[i][1],OPTION_MAINRETURN) == 0) {
608 options.mainreturn = 1;
612 if (strcmp(&argv[i][1],OPTION_CALLEE_SAVES) == 0) {
613 if (argv[i][1+strlen(OPTION_CALLEE_SAVES)])
614 parseWithComma(options.calleeSaves
615 ,&argv[i][1+strlen(OPTION_CALLEE_SAVES)]);
617 parseWithComma(options.calleeSaves,argv[++i]);
621 if (strcmp(&argv[i][1],OPTION_STACK_LOC) == 0) {
623 if (argv[i][1+strlen(OPTION_STACK_LOC)])
625 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_STACK_LOC)]));
628 (int) floatFromVal(constVal(argv[++i]));
632 if (strcmp(&argv[i][1],OPTION_XRAM_LOC) == 0) {
634 if (argv[i][1+strlen(OPTION_XRAM_LOC)])
636 (unsigned int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XRAM_LOC)]));
639 (unsigned int) floatFromVal(constVal(argv[++i]));
643 if (strcmp(&argv[i][1],OPTION_IRAM_SIZE) == 0) {
645 if (argv[i][1+strlen(OPTION_IRAM_SIZE)])
647 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IRAM_SIZE)]));
650 (int) floatFromVal(constVal(argv[++i]));
654 if (strcmp(&argv[i][1],OPTION_VERSION) == 0) {
660 if (strcmp(&argv[i][1],OPTION_DATA_LOC) == 0) {
662 if (argv[i][1+strlen(OPTION_DATA_LOC)])
664 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_DATA_LOC)]));
667 (int) floatFromVal(constVal(argv[++i]));
671 if (strcmp(&argv[i][1],OPTION_IDATA_LOC) == 0) {
673 if (argv[i][1+strlen(OPTION_IDATA_LOC)])
675 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IDATA_LOC)]));
678 (int) floatFromVal(constVal(argv[++i]));
682 if (strcmp(&argv[i][1],OPTION_CODE_LOC) == 0) {
684 if (argv[i][1+strlen(OPTION_CODE_LOC)])
686 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_CODE_LOC)]));
689 (int) floatFromVal(constVal(argv[++i]));
694 if (strcmp(&argv[i][1],OPTION_NO_JTBOUND) == 0) {
695 optimize.noJTabBoundary = 1;
699 if (strcmp(&argv[i][1],OPTION_NO_GCSE) == 0) {
700 optimize.global_cse = 0;
704 if (strcmp(&argv[i][1],OPTION_NO_LOOP_INV) == 0) {
705 optimize.loopInvariant = 0;
709 if (strcmp(&argv[i][1],OPTION_NO_LOOP_IND) == 0) {
710 optimize.loopInduction = 0;
714 if (strcmp(&argv[i][1],OPTION_NO_LOOPREV) == 0) {
715 optimize.noLoopReverse = 1;
719 if (!port->parseOption(&argc, argv))
720 werror(W_UNKNOWN_OPTION,argv[i]);
723 /* these are undocumented options */
724 /* if preceded by '/' then turn off certain optmizations, used
725 for debugging only these are also the legacy options from
726 version 1.xx will be removed gradually */
727 if ( *argv[i] == '/') {
728 switch (argv[i][1]) {
731 optimize.ptrArithmetic=0;
735 switch (argv[i][2]) {
740 optimize.label4 = 0 ;
758 switch (argv[i][2]) {
760 optimize.loopInvariant = 0;
763 optimize.loopInduction = 0;
770 optimize.global_cse = 0;
777 /* if preceded by '-' then option */
778 if ( *argv[i] == '-' ) {
779 switch (argv[i][1]) {
790 /* Used to select the port */
791 if (_setPort(argv[i] + 2)) {
792 werror(W_UNSUPP_OPTION,"-m","Unrecognised processor");
797 werror(W_UNSUPP_OPTION,"-a","use --stack-auto instead");
801 werror(W_UNSUPP_OPTION,"-g","use --generic instead");
804 case 'X' : /* use external stack */
805 werror(W_UNSUPP_OPTION,"-X","use --xstack-loc instead");
809 werror(W_UNSUPP_OPTION,"-x","use --xstack instead");
812 case 'p' : /* stack pointer intial value */
814 werror(W_UNSUPP_OPTION,"-p","use --stack-loc instead");
818 werror(W_UNSUPP_OPTION,"-i","use --idata-loc instead");
822 werror(W_UNSUPP_OPTION,"-r","use --xdata-loc instead");
826 werror(W_UNSUPP_OPTION,"-s","use --code-loc instead");
834 werror(W_UNSUPP_OPTION,"-Y","use -I instead");
839 libPaths[nlibPaths++] = &argv[i][2];
841 libPaths[nlibPaths++] = argv[++i];
846 if (argv[i][2] == 'l') {
848 parseWithComma(linkOptions,&argv[i][3]);
850 parseWithComma(linkOptions,argv[++i]);
852 /* assembler options */
853 if (argv[i][2] == 'a') {
855 parseWithComma(asmOptions,&argv[i][3]);
857 parseWithComma(asmOptions,argv[++i]);
860 werror(W_UNKNOWN_OPTION,argv[i]);
869 #if FEATURE_VERBOSE_EXEC
877 /* preprocessor options */
886 char sOpt = argv[i][1] ;
889 if ( argv[i][2] == ' ' || argv[i][2] == '\0') {
896 if ( argv[i][1] == 'Y' )
898 if (argv[i][1] == 'M')
901 sprintf(buffer, "-%c%s", sOpt, rest);
902 _addToList(preArgv, buffer);
907 if (!port->parseOption(&argc, argv))
908 werror(W_UNKNOWN_OPTION,argv[i]);
913 if (!port->parseOption(&argc, argv)) {
914 /* no option must be a filename */
915 processFile(argv[i]);
919 /* set up external stack location if not explicitly specified */
920 if ( !options.xstack_loc )
921 options.xstack_loc = options.xdata_loc ;
923 /* if debug option is set the open the cdbFile */
924 if (/* options.debug && */ srcFileName) {
925 sprintf(cdbfnbuf,"%s.cdb",srcFileName);
926 if ((cdbFile = fopen(cdbfnbuf,"w")) == NULL)
927 werror(E_FILE_OPEN_ERR,cdbfnbuf);
929 /* add a module record */
930 fprintf(cdbFile,"M:%s\n",moduleName);
933 port->finaliseOptions();
937 /*-----------------------------------------------------------------*/
938 /* my_system - will call a program with arguments */
939 /*-----------------------------------------------------------------*/
940 char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
941 int my_system (const char *cmd, char **cmd_argv)
944 char *dir, *got= NULL; int i= 0;
945 while (!got && try_dir[i]) {
946 dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10);
947 strcpy(dir, try_dir[i]); strcat(dir, "/"); strcat(dir, cmd);
948 if (access(dir, X_OK) == 0)
953 #if FEATURE_VERBOSE_EXEC
955 char **pCmd = cmd_argv;
957 printf("%s ", *pCmd);
964 i= spawnv(P_WAIT,got,cmd_argv) == -1;
966 i= spawnvp(P_WAIT,cmd,cmd_argv) == -1;
968 perror("Cannot exec process ");
975 /*-----------------------------------------------------------------*/
976 /* linkEdit : - calls the linkage editor with options */
977 /*-----------------------------------------------------------------*/
978 static void linkEdit (char **envp)
985 srcFileName = "temp";
987 /* first we need to create the <filename>.lnk file */
988 sprintf(buffer,"%s.lnk",srcFileName);
989 if (!(lnkfile = fopen(buffer,"w"))) {
990 werror(E_FILE_OPEN_ERR,buffer);
994 /* now write the options */
995 fprintf(lnkfile,"-mux%c\n", (options.out_fmt ? 's' : 'i'));
997 /* if iram size specified */
998 if (options.iram_size)
999 fprintf(lnkfile,"-a 0x%04x\n",options.iram_size);
1001 /*if (options.debug) */
1002 fprintf(lnkfile,"-z\n");
1003 /* code segment start */
1004 fprintf (lnkfile,"-b CODE = 0x%04x\n",options.code_loc);
1005 /* data segment start */
1006 fprintf (lnkfile,"-b DSEG = 0x%04x\n",options.data_loc);
1008 fprintf (lnkfile,"-b XSEG = 0x%04x\n",options.xdata_loc);
1010 fprintf (lnkfile,"-b ISEG = 0x%04x\n",options.idata_loc);
1011 /* bit segment start */
1012 fprintf (lnkfile,"-b BSEG = 0x%04x\n",0);
1014 /* add the extra linker options */
1015 for (i=0; linkOptions[i] ; i++)
1016 fprintf(lnkfile,"%s\n",linkOptions[i]);
1018 /* standard library path */
1019 fprintf (lnkfile,"-k %s/%s\n",SDCC_LIB_DIR/*STD_LIB_PATH*/,
1020 ( (options.model==0) ? "small": "large"));
1022 /* other library paths if specified */
1023 for (i = 0 ; i < nlibPaths ; i++ )
1024 fprintf (lnkfile,"-k %s\n",libPaths[i]);
1026 /* standard library files */
1027 fprintf (lnkfile,"-l %s\n",STD_LIB);
1028 fprintf (lnkfile,"-l %s\n",STD_INT_LIB);
1029 fprintf (lnkfile,"-l %s\n",STD_LONG_LIB);
1030 fprintf (lnkfile,"-l %s\n",STD_FP_LIB);
1032 /* additional libraries if any */
1033 for (i = 0 ; i < nlibFiles; i++)
1034 fprintf (lnkfile,"-l %s\n",libFiles[i]);
1036 /* put in the object files */
1037 if (strcmp(srcFileName,"temp"))
1038 fprintf (lnkfile,"%s ",srcFileName);
1040 for (i = 0 ; i < nrelFiles ; i++ )
1041 fprintf (lnkfile,"%s\n",relFiles[i]);
1043 fprintf (lnkfile,"\n-e\n");
1046 _buildCmdLine(buffer, argv, port->linker.cmd, srcFileName, NULL, NULL, NULL);
1048 /* call the linker */
1049 if (my_system(argv[0], argv)) {
1050 perror("Cannot exec linker");
1054 if (strcmp(srcFileName,"temp") == 0) {
1055 /* rename "temp.cdb" to "firstRelFile.cdb" */
1056 char *f = strtok(strdup(relFiles[0]),".");
1057 f = strcat(f,".cdb");
1058 rename("temp.cdb",f);
1063 /*-----------------------------------------------------------------*/
1064 /* assemble - spawns the assembler with arguments */
1065 /*-----------------------------------------------------------------*/
1066 static void assemble (char **envp)
1068 char *argv[128]; /* assembler arguments */
1070 _buildCmdLine(buffer, argv, port->assembler.cmd, srcFileName, NULL, NULL, asmOptions);
1072 if (my_system(argv[0], argv)) {
1073 perror("Cannot exec assember");
1080 /*-----------------------------------------------------------------*/
1081 /* preProcess - spawns the preprocessor with arguments */
1082 /*-----------------------------------------------------------------*/
1083 static int preProcess (char **envp)
1089 /* if using external stack define the macro */
1090 if ( options.useXstack )
1091 _addToList(preArgv, "-DSDCC_USE_XSTACK");
1093 /* set the macro for stack autos */
1094 if ( options.stackAuto )
1095 _addToList(preArgv, "-DSDCC_STACK_AUTO");
1097 /* set the macro for large model */
1098 if ( options.model )
1099 _addToList(preArgv, "-DSDCC_MODEL_LARGE");
1101 _addToList(preArgv, "-DSDCC_MODEL_SMALL");
1104 preOutName = strdup(tmpnam(NULL));
1106 _buildCmdLine(buffer, argv, _preCmd, fullSrcFileName,
1107 preOutName, srcFileName, preArgv);
1109 if (my_system(argv[0], argv)) {
1110 unlink (preOutName);
1111 perror("Cannot exec Preprocessor");
1118 yyin = fopen(preOutName,"r");
1120 perror("Preproc file not found\n");
1127 static void _findPort(int argc, char **argv)
1131 if (!strncmp(*argv, "-m", 2)) {
1132 _setPort(*argv + 2);
1138 /* Use the first in the list */
1144 * initialises and calls the parser
1147 int main ( int argc, char **argv , char **envp)
1149 /* turn all optimizations off by default */
1150 memset(&optimize,0,sizeof(struct optimize));
1152 /*printVersionInfo ();*/
1154 _findPort(argc, argv);
1155 setDefaultOptions();
1156 parseCmdLine(argc,argv);
1158 /* if no input then printUsage & exit */
1159 if (!srcFileName && !nrelFiles) {
1186 if (!options.cc_only &&
1189 (srcFileName || nrelFiles))
1192 if (yyin && yyin != stdin)