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 */
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 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 *linkCmd[] = {
119 "$1", "-nf", "$2", NULL
122 static const char *preCmd[] = {
123 "sdcpp", "-version", "-Wall", "-lang-c++", "-DSDCC=1",
124 "-I" SDCC_INCLUDE_DIR, "$l", "$1", "$2", NULL
127 static const char *asmCmd[] = {
128 "$1", "-plosgffc", "$2.asm", NULL
132 extern PORT mcs51_port;
133 extern PORT z80_port;
137 static PORT *_ports[] = {
142 #define NUM_PORTS (sizeof(_ports)/sizeof(_ports[0]))
144 /** Sets the port to the one given by the command line option.
145 @param The name minus the option (eg 'mcs51')
146 @return 0 on success.
148 static int _setPort(const char *name)
151 for (i=0; i<NUM_PORTS; i++) {
152 if (!strcmp(_ports[i]->target, name)) {
157 /* Error - didnt find */
161 static void _buildCmdLine(char *into, char **args, const char **cmds,
162 const char *p1, const char *p2,
163 const char *p3, const char **list)
165 const char *p, *from;
175 /* See if it has a '$' anywhere - if not, just copy */
176 if ((p = strchr(from, '$'))) {
177 strncpy(into, from, p - from);
194 const char **tmp = list;
198 into += strlen(into)+1;
211 if (strlen(into) == 0)
213 into += strlen(into)+1;
218 /*-----------------------------------------------------------------*/
219 /* printVersionInfo - prints the version info */
220 /*-----------------------------------------------------------------*/
221 void printVersionInfo ()
227 for (i=0; i<NUM_PORTS; i++)
228 fprintf(stderr, "%s%s", i==0 ? "" : "/", _ports[i]->target);
230 fprintf(stderr, " %s `"
244 /*-----------------------------------------------------------------*/
245 /* printUsage - prints command line syntax */
246 /*-----------------------------------------------------------------*/
251 "Usage : [options] filename\n"
253 "\t-m<proc> - Target processor <proc>. Default %s\n"
254 "\t Try --version for supported values of <proc>\n"
255 "\t--model-large - Large Model\n"
256 "\t--model-small - Small Model (default)\n"
257 "\t--stack-auto - Stack automatic variables\n"
258 "\t--xstack - Use external stack\n"
259 "\t--xram-loc <nnnn> - External Ram start location\n"
260 "\t--xstack-loc <nnnn> - Xternal Stack Location\n"
261 "\t--code-loc <nnnn> - Code Segment Location\n"
262 "\t--stack-loc <nnnn> - Stack pointer initial value\n"
263 "\t--data-loc <nnnn> - Direct data start location\n"
264 "\t--idata-loc <nnnn> - Indirect data start location\n"
265 "\t--iram-size <nnnn> - Internal Ram size\n"
266 "\t--nojtbound - Don't generate boundary check for jump tables\n"
267 "\t--generic - All unqualified ptrs converted to '_generic'\n"
268 "PreProcessor Options :-\n"
269 "\t-Dmacro - Define Macro\n"
270 "\t-Ipath - Include \"*.h\" path\n"
271 "Note: this is a complete list of options see docs for details\n",
277 /*-----------------------------------------------------------------*/
278 /* parseWithComma - separates string with comma */
279 /*-----------------------------------------------------------------*/
280 void parseWithComma (char **dest,char *src)
285 /* skip the initial white spaces */
286 while (isspace(*src)) src++;
300 /*-----------------------------------------------------------------*/
301 /* setDefaultOptions - sets the default options */
302 /*-----------------------------------------------------------------*/
303 static void setDefaultOptions()
307 for ( i = 0 ; i < 128 ; i++)
308 preArgv[i] = linkOptions [i] =
309 asmOptions[i] = relFiles[i] = libFiles[i] =
312 /* first the options part */
313 options.stack_loc = 0; /* stack pointer initialised to 0 */
314 options.xstack_loc= 0; /* xternal stack starts at 0 */
315 options.code_loc = 0; /* code starts at 0 */
316 options.data_loc = 0x0030; /* data starts at 0x0030 */
317 options.xdata_loc = 0;
318 options.idata_loc = 0x80;
319 options.genericPtr = 1; /* default on */
322 /* now for the optimizations */
323 /* turn on the everything */
324 optimize.global_cse = 1;
329 optimize.loopInvariant = 1;
330 optimize.loopInduction = 1;
332 port->setDefaultOptions();
335 /*-----------------------------------------------------------------*/
336 /* processFile - determines the type of file from the extension */
337 /*-----------------------------------------------------------------*/
338 static void processFile (char *s)
342 /* get the file extension */
343 fext = s + strlen(s);
344 while ((fext != s) && *fext != '.') fext--;
346 /* now if no '.' then we don't know what the file type is
347 so give a warning and return */
349 werror(W_UNKNOWN_FEXT,s);
353 /* otherwise depending on the file type */
354 if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0) {
355 /* source file name : not if we already have a
358 werror(W_TOO_MANY_SRC,s);
362 /* the only source file */
363 if (!(srcFile = fopen((fullSrcFileName = s),"r"))) {
364 werror(E_FILE_OPEN_ERR,s);
368 /* copy the file name into the buffer */
371 /* get rid of the "." */
373 ALLOC_ATOMIC(srcFileName,strlen(buffer)+1);
374 strcpy(srcFileName,buffer);
376 /* get rid of any path information
377 for the module name; do this by going
378 backwards till we get to either '/' or '\' or ':'
379 or start of buffer */
380 fext = buffer + strlen(buffer);
381 while (fext != buffer &&
382 *(fext -1) != '\\' &&
386 ALLOC_ATOMIC(moduleName,strlen(fext)+1);
387 strcpy(moduleName,fext);
392 /* if the extention is type .rel or .r or .REL or .R
393 addtional object file will be passed to the linker */
394 if (strcmp(fext,".r") == 0 || strcmp(fext,".rel") == 0 ||
395 strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0) {
397 relFiles[nrelFiles++] = s;
401 /* if .lib or .LIB */
402 if (strcmp(fext,".lib") == 0 || strcmp(fext,".LIB") == 0) {
403 libFiles[nlibFiles++] = s;
407 werror(W_UNKNOWN_FEXT,s);
411 static void _addToList(char **list, const char *str)
413 /* This is the bad way to do things :) */
418 werror(E_OUT_OF_MEM,__FILE__, 0);
424 /*-----------------------------------------------------------------*/
425 /* parseCmdLine - parses the command line and sets the options */
426 /*-----------------------------------------------------------------*/
427 int parseCmdLine ( int argc, char **argv )
432 /* go thru all whole command line */
433 for ( i = 1; i < argc; i++ ) {
438 if (argv[i][0] == '-' && argv[i][1] == '-') {
440 if (strcmp(&argv[i][1],OPTION_HELP) == 0) {
445 if (strcmp(&argv[i][1],OPTION_XREGS) == 0) {
446 options.regExtend = 1;
450 if (strcmp(&argv[i][1],OPTION_LARGE_MODEL) == 0) {
455 if (strcmp(&argv[i][1],OPTION_SMALL_MODEL) == 0) {
460 if (strcmp(&argv[i][1],OPTION_STACK_AUTO) == 0) {
461 options.stackAuto = 1;
465 if (strcmp(&argv[i][1],OPTION_DUMP_RAW) == 0) {
466 options.dump_raw = 1;
470 if (strcmp(&argv[i][1],OPTION_CYCLOMATIC) == 0) {
471 options.cyclomatic = 1;
475 if (strcmp(&argv[i][1],OPTION_DUMP_GCSE) == 0) {
476 options.dump_gcse = 1;
480 if (strcmp(&argv[i][1],OPTION_DUMP_LOOP) == 0) {
481 options.dump_loop = 1;
485 if (strcmp(&argv[i][1],OPTION_DUMP_KILL) == 0) {
486 options.dump_kill = 1;
490 if (strcmp(&argv[i][1],OPTION_INTLONG_RENT) == 0) {
491 options.intlong_rent = 1;
495 if (strcmp(&argv[i][1],OPTION_FLOAT_RENT) == 0) {
496 options.float_rent = 1;
500 if (strcmp(&argv[i][1],OPTION_DUMP_RANGE) == 0) {
501 options.dump_range = 1;
505 if (strcmp(&argv[i][1],OPTION_DUMP_PACK) == 0) {
506 options.dump_pack = 1;
510 if (strcmp(&argv[i][1],OPTION_DUMP_RASSGN) == 0) {
511 options.dump_rassgn = 1;
515 if (strcmp(&argv[i][1],OPTION_OUT_FMT_IHX) == 0) {
520 if (strcmp(&argv[i][1],OPTION_OUT_FMT_S19) == 0) {
525 if (strcmp(&argv[i][1],OPTION_NOOVERLAY) == 0) {
526 options.noOverlay = 1;
530 if (strcmp(&argv[i][1],OPTION_STKAFTRDATA) == 0) {
531 options.stackOnData = 1;
535 if (strcmp(&argv[i][1],OPTION_PREPROC_ONLY) == 0) {
541 if (strcmp(&argv[i][1],OPTION_DUMP_ALL) == 0) {
542 options.dump_rassgn =
548 options.dump_raw = 1;
552 if (strcmp(&argv[i][1],OPTION_COMP_ONLY) == 0) {
557 if (strcmp(&argv[i][1],OPTION_GENERIC) == 0) {
558 options.genericPtr = 1;
562 if (strcmp(&argv[i][1],OPTION_NOPEEP) == 0) {
567 if (strcmp(&argv[i][1],OPTION_ASMPEEP) == 0) {
572 if (strcmp(&argv[i][1],OPTION_DEBUG) == 0) {
577 if (strcmp(&argv[i][1],OPTION_NOREGPARMS) == 0) {
578 options.noregparms = 1;
582 if (strcmp(&argv[i][1],OPTION_PEEP_FILE) == 0) {
583 if (argv[i][1+strlen(OPTION_PEEP_FILE)])
585 &argv[i][1+strlen(OPTION_PEEP_FILE)];
587 options.peep_file = argv[++i];
591 if (strcmp(&argv[i][1],OPTION_LIB_PATH) == 0) {
592 if (argv[i][1+strlen(OPTION_LIB_PATH)])
593 libPaths[nlibPaths++] =
594 &argv[i][1+strlen(OPTION_PEEP_FILE)];
596 libPaths[nlibPaths++] = argv[++i];
600 if (strcmp(&argv[i][1],OPTION_XSTACK_LOC) == 0) {
602 if (argv[i][1+strlen(OPTION_XSTACK_LOC)])
604 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XSTACK_LOC)]));
607 (int) floatFromVal(constVal(argv[++i]));
611 if (strcmp(&argv[i][1],OPTION_XSTACK) == 0) {
612 options.useXstack = 1;
616 if (strcmp(&argv[i][1],OPTION_MAINRETURN) == 0) {
617 options.mainreturn = 1;
621 if (strcmp(&argv[i][1],OPTION_CALLEE_SAVES) == 0) {
622 if (argv[i][1+strlen(OPTION_CALLEE_SAVES)])
623 parseWithComma(options.calleeSaves
624 ,&argv[i][1+strlen(OPTION_CALLEE_SAVES)]);
626 parseWithComma(options.calleeSaves,argv[++i]);
630 if (strcmp(&argv[i][1],OPTION_STACK_LOC) == 0) {
632 if (argv[i][1+strlen(OPTION_STACK_LOC)])
634 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_STACK_LOC)]));
637 (int) floatFromVal(constVal(argv[++i]));
641 if (strcmp(&argv[i][1],OPTION_XRAM_LOC) == 0) {
643 if (argv[i][1+strlen(OPTION_XRAM_LOC)])
645 (unsigned int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XRAM_LOC)]));
648 (unsigned int) floatFromVal(constVal(argv[++i]));
652 if (strcmp(&argv[i][1],OPTION_IRAM_SIZE) == 0) {
654 if (argv[i][1+strlen(OPTION_IRAM_SIZE)])
656 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IRAM_SIZE)]));
659 (int) floatFromVal(constVal(argv[++i]));
663 if (strcmp(&argv[i][1],OPTION_VERSION) == 0) {
669 if (strcmp(&argv[i][1],OPTION_DATA_LOC) == 0) {
671 if (argv[i][1+strlen(OPTION_DATA_LOC)])
673 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_DATA_LOC)]));
676 (int) floatFromVal(constVal(argv[++i]));
680 if (strcmp(&argv[i][1],OPTION_IDATA_LOC) == 0) {
682 if (argv[i][1+strlen(OPTION_IDATA_LOC)])
684 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IDATA_LOC)]));
687 (int) floatFromVal(constVal(argv[++i]));
691 if (strcmp(&argv[i][1],OPTION_CODE_LOC) == 0) {
693 if (argv[i][1+strlen(OPTION_CODE_LOC)])
695 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_CODE_LOC)]));
698 (int) floatFromVal(constVal(argv[++i]));
703 if (strcmp(&argv[i][1],OPTION_NO_JTBOUND) == 0) {
704 optimize.noJTabBoundary = 1;
708 if (strcmp(&argv[i][1],OPTION_NO_GCSE) == 0) {
709 optimize.global_cse = 0;
713 if (strcmp(&argv[i][1],OPTION_NO_LOOP_INV) == 0) {
714 optimize.loopInvariant = 0;
718 if (strcmp(&argv[i][1],OPTION_NO_LOOP_IND) == 0) {
719 optimize.loopInduction = 0;
723 if (strcmp(&argv[i][1],OPTION_NO_LOOPREV) == 0) {
724 optimize.noLoopReverse = 1;
728 if (!port->parseOption(&argc, argv))
729 werror(W_UNKNOWN_OPTION,argv[i]);
732 /* these are undocumented options */
733 /* if preceded by '/' then turn off certain optmizations, used
734 for debugging only these are also the legacy options from
735 version 1.xx will be removed gradually */
736 if ( *argv[i] == '/') {
737 switch (argv[i][1]) {
740 optimize.ptrArithmetic=0;
744 switch (argv[i][2]) {
749 optimize.label4 = 0 ;
767 switch (argv[i][2]) {
769 optimize.loopInvariant = 0;
772 optimize.loopInduction = 0;
779 optimize.global_cse = 0;
786 /* if preceded by '-' then option */
787 if ( *argv[i] == '-' ) {
788 switch (argv[i][1]) {
799 /* Used to select the port */
800 if (_setPort(argv[i] + 2)) {
801 werror(W_UNSUPP_OPTION,"-m","Unrecognised processor");
806 werror(W_UNSUPP_OPTION,"-a","use --stack-auto instead");
810 werror(W_UNSUPP_OPTION,"-g","use --generic instead");
813 case 'X' : /* use external stack */
814 werror(W_UNSUPP_OPTION,"-X","use --xstack-loc instead");
818 werror(W_UNSUPP_OPTION,"-x","use --xstack instead");
821 case 'p' : /* stack pointer intial value */
823 werror(W_UNSUPP_OPTION,"-p","use --stack-loc instead");
827 werror(W_UNSUPP_OPTION,"-i","use --idata-loc instead");
831 werror(W_UNSUPP_OPTION,"-r","use --xdata-loc instead");
835 werror(W_UNSUPP_OPTION,"-s","use --code-loc instead");
843 werror(W_UNSUPP_OPTION,"-Y","use -I instead");
848 libPaths[nlibPaths++] = &argv[i][2];
850 libPaths[nlibPaths++] = argv[++i];
855 if (argv[i][2] == 'l') {
857 parseWithComma(linkOptions,&argv[i][3]);
859 parseWithComma(linkOptions,argv[++i]);
861 /* assembler options */
862 if (argv[i][2] == 'a') {
864 parseWithComma(asmOptions,&argv[i][3]);
866 parseWithComma(asmOptions,argv[++i]);
869 werror(W_UNKNOWN_OPTION,argv[i]);
878 #if FEATURE_VERBOSE_EXEC
886 /* preprocessor options */
895 char sOpt = argv[i][1] ;
898 if ( argv[i][2] == ' ' || argv[i][2] == '\0') {
905 if ( argv[i][1] == 'Y' )
907 if (argv[i][1] == 'M')
910 sprintf(buffer, "-%c%s", sOpt, rest);
911 _addToList(preArgv, buffer);
916 if (!port->parseOption(&argc, argv))
917 werror(W_UNKNOWN_OPTION,argv[i]);
922 if (!port->parseOption(&argc, argv)) {
923 /* no option must be a filename */
924 processFile(argv[i]);
928 /* set up external stack location if not explicitly specified */
929 if ( !options.xstack_loc )
930 options.xstack_loc = options.xdata_loc ;
932 /* if debug option is set the open the cdbFile */
933 if (/* options.debug && */ srcFileName) {
934 sprintf(cdbfnbuf,"%s.cdb",srcFileName);
935 if ((cdbFile = fopen(cdbfnbuf,"w")) == NULL)
936 werror(E_FILE_OPEN_ERR,cdbfnbuf);
938 /* add a module record */
939 fprintf(cdbFile,"M:%s\n",moduleName);
942 port->finaliseOptions();
946 /*-----------------------------------------------------------------*/
947 /* my_system - will call a program with arguments */
948 /*-----------------------------------------------------------------*/
949 char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
950 int my_system (const char *cmd, char **cmd_argv)
953 char *dir, *got= NULL; int i= 0;
954 while (!got && try_dir[i]) {
955 dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10);
956 strcpy(dir, try_dir[i]); strcat(dir, "/"); strcat(dir, cmd);
957 if (access(dir, X_OK) == 0)
962 #if FEATURE_VERBOSE_EXEC
964 char **pCmd = cmd_argv;
966 printf("%s ", *pCmd);
973 i= spawnv(P_WAIT,got,cmd_argv) == -1;
975 i= spawnvp(P_WAIT,cmd,cmd_argv) == -1;
977 perror("Cannot exec process ");
984 /*-----------------------------------------------------------------*/
985 /* linkEdit : - calls the linkage editor with options */
986 /*-----------------------------------------------------------------*/
987 static void linkEdit (char **envp)
994 srcFileName = "temp";
996 /* first we need to create the <filename>.lnk file */
997 sprintf(buffer,"%s.lnk",srcFileName);
998 if (!(lnkfile = fopen(buffer,"w"))) {
999 werror(E_FILE_OPEN_ERR,buffer);
1003 /* now write the options */
1004 fprintf(lnkfile,"-mux%c\n", (options.out_fmt ? 's' : 'i'));
1006 /* if iram size specified */
1007 if (options.iram_size)
1008 fprintf(lnkfile,"-a 0x%04x\n",options.iram_size);
1010 /*if (options.debug) */
1011 fprintf(lnkfile,"-z\n");
1012 /* code segment start */
1013 fprintf (lnkfile,"-b CODE = 0x%04x\n",options.code_loc);
1014 /* data segment start */
1015 fprintf (lnkfile,"-b DSEG = 0x%04x\n",options.data_loc);
1017 fprintf (lnkfile,"-b XSEG = 0x%04x\n",options.xdata_loc);
1019 fprintf (lnkfile,"-b ISEG = 0x%04x\n",options.idata_loc);
1020 /* bit segment start */
1021 fprintf (lnkfile,"-b BSEG = 0x%04x\n",0);
1023 /* add the extra linker options */
1024 for (i=0; linkOptions[i] ; i++)
1025 fprintf(lnkfile,"%s\n",linkOptions[i]);
1027 /* standard library path */
1028 fprintf (lnkfile,"-k %s/%s\n",SDCC_LIB_DIR/*STD_LIB_PATH*/,
1029 ( (options.model==0) ? "small": "large"));
1031 /* other library paths if specified */
1032 for (i = 0 ; i < nlibPaths ; i++ )
1033 fprintf (lnkfile,"-k %s\n",libPaths[i]);
1035 /* standard library files */
1036 fprintf (lnkfile,"-l %s\n",STD_LIB);
1037 fprintf (lnkfile,"-l %s\n",STD_INT_LIB);
1038 fprintf (lnkfile,"-l %s\n",STD_LONG_LIB);
1039 fprintf (lnkfile,"-l %s\n",STD_FP_LIB);
1041 /* additional libraries if any */
1042 for (i = 0 ; i < nlibFiles; i++)
1043 fprintf (lnkfile,"-l %s\n",libFiles[i]);
1045 /* put in the object files */
1046 if (strcmp(srcFileName,"temp"))
1047 fprintf (lnkfile,"%s ",srcFileName);
1049 for (i = 0 ; i < nrelFiles ; i++ )
1050 fprintf (lnkfile,"%s\n",relFiles[i]);
1052 fprintf (lnkfile,"\n-e\n");
1055 _buildCmdLine(buffer, argv, linkCmd, port->linker.exec_name, srcFileName, NULL, NULL);
1057 /* call the linker */
1058 if (my_system(argv[0], argv)) {
1059 perror("Cannot exec linker");
1063 if (strcmp(srcFileName,"temp") == 0) {
1064 /* rename "temp.cdb" to "firstRelFile.cdb" */
1065 char *f = strtok(strdup(relFiles[0]),".");
1066 f = strcat(f,".cdb");
1067 rename("temp.cdb",f);
1072 /*-----------------------------------------------------------------*/
1073 /* assemble - spawns the assembler with arguments */
1074 /*-----------------------------------------------------------------*/
1075 static void assemble (char **envp)
1077 char *argv[128]; /* assembler arguments */
1079 _buildCmdLine(buffer, argv, asmCmd, port->assembler.exec_name, srcFileName, NULL, asmOptions);
1081 if (my_system(argv[0], argv)) {
1082 perror("Cannot exec assember");
1089 /*-----------------------------------------------------------------*/
1090 /* preProcess - spawns the preprocessor with arguments */
1091 /*-----------------------------------------------------------------*/
1092 static int preProcess (char **envp)
1098 /* if using external stack define the macro */
1099 if ( options.useXstack )
1100 _addToList(preArgv, "-DSDCC_USE_XSTACK");
1102 /* set the macro for stack autos */
1103 if ( options.stackAuto )
1104 _addToList(preArgv, "-DSDCC_STACK_AUTO");
1106 /* set the macro for large model */
1107 if ( options.model )
1108 _addToList(preArgv, "-DSDCC_MODEL_LARGE");
1110 _addToList(preArgv, "-DSDCC_MODEL_SMALL");
1113 preOutName = strdup(tmpnam(NULL));
1115 _buildCmdLine(buffer, argv, preCmd, fullSrcFileName,
1116 preOutName, srcFileName, preArgv);
1118 if (my_system(argv[0], argv)) {
1119 unlink (preOutName);
1120 perror("Cannot exec Preprocessor");
1127 yyin = fopen(preOutName,"r");
1129 perror("Preproc file not found\n");
1136 static void _findPort(int argc, char **argv)
1140 if (!strncmp(*argv, "-m", 2)) {
1141 _setPort(*argv + 2);
1147 /* Use the first in the list */
1153 * initialises and calls the parser
1156 int main ( int argc, char **argv , char **envp)
1158 /* turn all optimizations off by default */
1159 memset(&optimize,0,sizeof(struct optimize));
1161 /*printVersionInfo ();*/
1163 _findPort(argc, argv);
1164 setDefaultOptions();
1165 parseCmdLine(argc,argv);
1167 /* if no input then printUsage & exit */
1168 if (!srcFileName && !nrelFiles) {
1195 if (!options.cc_only &&
1198 (srcFileName || nrelFiles))
1201 if (yyin && yyin != stdin)