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_FLAT24_MODEL "-model-flat24"
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 static const char *_preCmd[] = {
120 "sdcpp", "-Wall", "-lang-c++", "-DSDCC=1",
121 "-I" SDCC_INCLUDE_DIR, "$l", "$1", "$2", NULL
124 extern PORT mcs51_port;
125 extern PORT z80_port;
129 static PORT *_ports[] = {
134 #define NUM_PORTS (sizeof(_ports)/sizeof(_ports[0]))
136 /** Sets the port to the one given by the command line option.
137 @param The name minus the option (eg 'mcs51')
138 @return 0 on success.
140 static int _setPort(const char *name)
143 for (i=0; i<NUM_PORTS; i++) {
144 if (!strcmp(_ports[i]->target, name)) {
149 /* Error - didnt find */
153 static void _buildCmdLine(char *into, char **args, const char **cmds,
154 const char *p1, const char *p2,
155 const char *p3, const char **list)
157 const char *p, *from;
167 /* See if it has a '$' anywhere - if not, just copy */
168 if ((p = strchr(from, '$'))) {
169 strncpy(into, from, p - from);
186 const char **tmp = list;
190 into += strlen(into)+1;
203 if (strlen(into) == 0)
205 into += strlen(into)+1;
210 /*-----------------------------------------------------------------*/
211 /* printVersionInfo - prints the version info */
212 /*-----------------------------------------------------------------*/
213 void printVersionInfo ()
219 for (i=0; i<NUM_PORTS; i++)
220 fprintf(stderr, "%s%s", i==0 ? "" : "/", _ports[i]->target);
222 fprintf(stderr, " %s `"
236 /*-----------------------------------------------------------------*/
237 /* printUsage - prints command line syntax */
238 /*-----------------------------------------------------------------*/
243 "Usage : [options] filename\n"
245 "\t-m<proc> - Target processor <proc>. Default %s\n"
246 "\t Try --version for supported values of <proc>\n"
247 "\t--model-large - Large Model\n"
248 "\t--model-small - Small Model (default)\n"
249 "\t--stack-auto - Stack automatic variables\n"
250 "\t--xstack - Use external stack\n"
251 "\t--xram-loc <nnnn> - External Ram start location\n"
252 "\t--xstack-loc <nnnn> - Xternal Stack Location\n"
253 "\t--code-loc <nnnn> - Code Segment Location\n"
254 "\t--stack-loc <nnnn> - Stack pointer initial value\n"
255 "\t--data-loc <nnnn> - Direct data start location\n"
256 "\t--idata-loc <nnnn> - Indirect data start location\n"
257 "\t--iram-size <nnnn> - Internal Ram size\n"
258 "\t--nojtbound - Don't generate boundary check for jump tables\n"
259 "\t--generic - All unqualified ptrs converted to '_generic'\n"
260 "PreProcessor Options :-\n"
261 "\t-Dmacro - Define Macro\n"
262 "\t-Ipath - Include \"*.h\" path\n"
263 "Note: this is a complete list of options see docs for details\n",
269 /*-----------------------------------------------------------------*/
270 /* parseWithComma - separates string with comma */
271 /*-----------------------------------------------------------------*/
272 void parseWithComma (char **dest,char *src)
277 /* skip the initial white spaces */
278 while (isspace(*src)) src++;
292 /*-----------------------------------------------------------------*/
293 /* setDefaultOptions - sets the default options */
294 /*-----------------------------------------------------------------*/
295 static void setDefaultOptions()
299 for ( i = 0 ; i < 128 ; i++)
300 preArgv[i] = asmOptions [i] =
301 linkOptions[i] = relFiles[i] = libFiles[i] =
304 /* first the options part */
305 options.stack_loc = 0; /* stack pointer initialised to 0 */
306 options.xstack_loc= 0; /* xternal stack starts at 0 */
307 options.code_loc = 0; /* code starts at 0 */
308 options.data_loc = 0x0030; /* data starts at 0x0030 */
309 options.xdata_loc = 0;
310 options.idata_loc = 0x80;
311 options.genericPtr = 1; /* default on */
314 /* now for the optimizations */
315 /* turn on the everything */
316 optimize.global_cse = 1;
321 optimize.loopInvariant = 1;
322 optimize.loopInduction = 1;
324 port->setDefaultOptions();
327 /*-----------------------------------------------------------------*/
328 /* processFile - determines the type of file from the extension */
329 /*-----------------------------------------------------------------*/
330 static void processFile (char *s)
334 /* get the file extension */
335 fext = s + strlen(s);
336 while ((fext != s) && *fext != '.') fext--;
338 /* now if no '.' then we don't know what the file type is
339 so give a warning and return */
341 werror(W_UNKNOWN_FEXT,s);
345 /* otherwise depending on the file type */
346 if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0) {
347 /* source file name : not if we already have a
350 werror(W_TOO_MANY_SRC,s);
354 /* the only source file */
355 if (!(srcFile = fopen((fullSrcFileName = s),"r"))) {
356 werror(E_FILE_OPEN_ERR,s);
360 /* copy the file name into the buffer */
363 /* get rid of the "." */
365 ALLOC_ATOMIC(srcFileName,strlen(buffer)+1);
366 strcpy(srcFileName,buffer);
368 /* get rid of any path information
369 for the module name; do this by going
370 backwards till we get to either '/' or '\' or ':'
371 or start of buffer */
372 fext = buffer + strlen(buffer);
373 while (fext != buffer &&
374 *(fext -1) != '\\' &&
378 ALLOC_ATOMIC(moduleName,strlen(fext)+1);
379 strcpy(moduleName,fext);
384 /* if the extention is type .rel or .r or .REL or .R
385 addtional object file will be passed to the linker */
386 if (strcmp(fext,".r") == 0 || strcmp(fext,".rel") == 0 ||
387 strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0) {
389 relFiles[nrelFiles++] = s;
393 /* if .lib or .LIB */
394 if (strcmp(fext,".lib") == 0 || strcmp(fext,".LIB") == 0) {
395 libFiles[nlibFiles++] = s;
399 werror(W_UNKNOWN_FEXT,s);
403 static void _addToList(const char **list, const char *str)
405 /* This is the bad way to do things :) */
410 werror(E_OUT_OF_MEM,__FILE__, 0);
416 /*-----------------------------------------------------------------*/
417 /* parseCmdLine - parses the command line and sets the options */
418 /*-----------------------------------------------------------------*/
419 int parseCmdLine ( int argc, char **argv )
424 /* go thru all whole command line */
425 for ( i = 1; i < argc; i++ ) {
430 if (argv[i][0] == '-' && argv[i][1] == '-') {
432 if (strcmp(&argv[i][1],OPTION_HELP) == 0) {
437 if (strcmp(&argv[i][1],OPTION_XREGS) == 0) {
438 options.regExtend = 1;
442 if (strcmp(&argv[i][1],OPTION_LARGE_MODEL) == 0) {
443 options.model = MODEL_LARGE;
447 if (strcmp(&argv[i][1],OPTION_SMALL_MODEL) == 0) {
448 options.model = MODEL_SMALL;
452 if (strcmp(&argv[i][1],OPTION_FLAT24_MODEL) == 0) {
453 options.model = MODEL_FLAT24;
457 if (strcmp(&argv[i][1],OPTION_STACK_AUTO) == 0) {
458 options.stackAuto = 1;
462 if (strcmp(&argv[i][1],OPTION_DUMP_RAW) == 0) {
463 options.dump_raw = 1;
467 if (strcmp(&argv[i][1],OPTION_CYCLOMATIC) == 0) {
468 options.cyclomatic = 1;
472 if (strcmp(&argv[i][1],OPTION_DUMP_GCSE) == 0) {
473 options.dump_gcse = 1;
477 if (strcmp(&argv[i][1],OPTION_DUMP_LOOP) == 0) {
478 options.dump_loop = 1;
482 if (strcmp(&argv[i][1],OPTION_DUMP_KILL) == 0) {
483 options.dump_kill = 1;
487 if (strcmp(&argv[i][1],OPTION_INTLONG_RENT) == 0) {
488 options.intlong_rent = 1;
492 if (strcmp(&argv[i][1],OPTION_FLOAT_RENT) == 0) {
493 options.float_rent = 1;
497 if (strcmp(&argv[i][1],OPTION_DUMP_RANGE) == 0) {
498 options.dump_range = 1;
502 if (strcmp(&argv[i][1],OPTION_DUMP_PACK) == 0) {
503 options.dump_pack = 1;
507 if (strcmp(&argv[i][1],OPTION_DUMP_RASSGN) == 0) {
508 options.dump_rassgn = 1;
512 if (strcmp(&argv[i][1],OPTION_OUT_FMT_IHX) == 0) {
517 if (strcmp(&argv[i][1],OPTION_OUT_FMT_S19) == 0) {
522 if (strcmp(&argv[i][1],OPTION_NOOVERLAY) == 0) {
523 options.noOverlay = 1;
527 if (strcmp(&argv[i][1],OPTION_STKAFTRDATA) == 0) {
528 options.stackOnData = 1;
532 if (strcmp(&argv[i][1],OPTION_PREPROC_ONLY) == 0) {
538 if (strcmp(&argv[i][1],OPTION_DUMP_ALL) == 0) {
539 options.dump_rassgn =
545 options.dump_raw = 1;
549 if (strcmp(&argv[i][1],OPTION_COMP_ONLY) == 0) {
554 if (strcmp(&argv[i][1],OPTION_GENERIC) == 0) {
555 options.genericPtr = 1;
559 if (strcmp(&argv[i][1],OPTION_NOPEEP) == 0) {
564 if (strcmp(&argv[i][1],OPTION_ASMPEEP) == 0) {
569 if (strcmp(&argv[i][1],OPTION_DEBUG) == 0) {
574 if (strcmp(&argv[i][1],OPTION_NOREGPARMS) == 0) {
575 options.noregparms = 1;
579 if (strcmp(&argv[i][1],OPTION_PEEP_FILE) == 0) {
580 if (argv[i][1+strlen(OPTION_PEEP_FILE)])
582 &argv[i][1+strlen(OPTION_PEEP_FILE)];
584 options.peep_file = argv[++i];
588 if (strcmp(&argv[i][1],OPTION_LIB_PATH) == 0) {
589 if (argv[i][1+strlen(OPTION_LIB_PATH)])
590 libPaths[nlibPaths++] =
591 &argv[i][1+strlen(OPTION_PEEP_FILE)];
593 libPaths[nlibPaths++] = argv[++i];
597 if (strcmp(&argv[i][1],OPTION_XSTACK_LOC) == 0) {
599 if (argv[i][1+strlen(OPTION_XSTACK_LOC)])
601 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XSTACK_LOC)]));
604 (int) floatFromVal(constVal(argv[++i]));
608 if (strcmp(&argv[i][1],OPTION_XSTACK) == 0) {
609 options.useXstack = 1;
613 if (strcmp(&argv[i][1],OPTION_MAINRETURN) == 0) {
614 options.mainreturn = 1;
618 if (strcmp(&argv[i][1],OPTION_CALLEE_SAVES) == 0) {
619 if (argv[i][1+strlen(OPTION_CALLEE_SAVES)])
620 parseWithComma(options.calleeSaves
621 ,&argv[i][1+strlen(OPTION_CALLEE_SAVES)]);
623 parseWithComma(options.calleeSaves,argv[++i]);
627 if (strcmp(&argv[i][1],OPTION_STACK_LOC) == 0) {
629 if (argv[i][1+strlen(OPTION_STACK_LOC)])
631 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_STACK_LOC)]));
634 (int) floatFromVal(constVal(argv[++i]));
638 if (strcmp(&argv[i][1],OPTION_XRAM_LOC) == 0) {
640 if (argv[i][1+strlen(OPTION_XRAM_LOC)])
642 (unsigned int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_XRAM_LOC)]));
645 (unsigned int) floatFromVal(constVal(argv[++i]));
649 if (strcmp(&argv[i][1],OPTION_IRAM_SIZE) == 0) {
651 if (argv[i][1+strlen(OPTION_IRAM_SIZE)])
653 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IRAM_SIZE)]));
656 (int) floatFromVal(constVal(argv[++i]));
660 if (strcmp(&argv[i][1],OPTION_VERSION) == 0) {
666 if (strcmp(&argv[i][1],OPTION_DATA_LOC) == 0) {
668 if (argv[i][1+strlen(OPTION_DATA_LOC)])
670 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_DATA_LOC)]));
673 (int) floatFromVal(constVal(argv[++i]));
677 if (strcmp(&argv[i][1],OPTION_IDATA_LOC) == 0) {
679 if (argv[i][1+strlen(OPTION_IDATA_LOC)])
681 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_IDATA_LOC)]));
684 (int) floatFromVal(constVal(argv[++i]));
688 if (strcmp(&argv[i][1],OPTION_CODE_LOC) == 0) {
690 if (argv[i][1+strlen(OPTION_CODE_LOC)])
692 (int) floatFromVal(constVal(&argv[i][1+strlen(OPTION_CODE_LOC)]));
695 (int) floatFromVal(constVal(argv[++i]));
700 if (strcmp(&argv[i][1],OPTION_NO_JTBOUND) == 0) {
701 optimize.noJTabBoundary = 1;
705 if (strcmp(&argv[i][1],OPTION_NO_GCSE) == 0) {
706 optimize.global_cse = 0;
710 if (strcmp(&argv[i][1],OPTION_NO_LOOP_INV) == 0) {
711 optimize.loopInvariant = 0;
715 if (strcmp(&argv[i][1],OPTION_NO_LOOP_IND) == 0) {
716 optimize.loopInduction = 0;
720 if (strcmp(&argv[i][1],OPTION_NO_LOOPREV) == 0) {
721 optimize.noLoopReverse = 1;
725 if (!port->parseOption(&argc, argv, &i))
727 werror(W_UNKNOWN_OPTION,argv[i]);
735 /* these are undocumented options */
736 /* if preceded by '/' then turn off certain optmizations, used
737 for debugging only these are also the legacy options from
738 version 1.xx will be removed gradually */
739 if ( *argv[i] == '/') {
740 switch (argv[i][1]) {
743 optimize.ptrArithmetic=0;
747 switch (argv[i][2]) {
752 optimize.label4 = 0 ;
770 switch (argv[i][2]) {
772 optimize.loopInvariant = 0;
775 optimize.loopInduction = 0;
782 optimize.global_cse = 0;
789 /* if preceded by '-' then option */
790 if ( *argv[i] == '-' ) {
791 switch (argv[i][1]) {
802 /* Used to select the port */
803 if (_setPort(argv[i] + 2)) {
804 werror(W_UNSUPP_OPTION,"-m","Unrecognised processor");
809 werror(W_UNSUPP_OPTION,"-a","use --stack-auto instead");
813 werror(W_UNSUPP_OPTION,"-g","use --generic instead");
816 case 'X' : /* use external stack */
817 werror(W_UNSUPP_OPTION,"-X","use --xstack-loc instead");
821 werror(W_UNSUPP_OPTION,"-x","use --xstack instead");
824 case 'p' : /* stack pointer intial value */
826 werror(W_UNSUPP_OPTION,"-p","use --stack-loc instead");
830 werror(W_UNSUPP_OPTION,"-i","use --idata-loc instead");
834 werror(W_UNSUPP_OPTION,"-r","use --xdata-loc instead");
838 werror(W_UNSUPP_OPTION,"-s","use --code-loc instead");
846 werror(W_UNSUPP_OPTION,"-Y","use -I instead");
851 libPaths[nlibPaths++] = &argv[i][2];
853 libPaths[nlibPaths++] = argv[++i];
858 if (argv[i][2] == 'l') {
860 parseWithComma(linkOptions,&argv[i][3]);
862 parseWithComma(linkOptions,argv[++i]);
864 /* assembler options */
865 if (argv[i][2] == 'a') {
867 parseWithComma((char **)asmOptions,&argv[i][3]);
869 parseWithComma((char **)asmOptions,argv[++i]);
872 werror(W_UNKNOWN_OPTION,argv[i]);
881 #if FEATURE_VERBOSE_EXEC
889 /* preprocessor options */
898 char sOpt = argv[i][1] ;
901 if ( argv[i][2] == ' ' || argv[i][2] == '\0') {
908 if ( argv[i][1] == 'Y' )
910 if (argv[i][1] == 'M')
913 sprintf(buffer, "-%c%s", sOpt, rest);
914 _addToList(preArgv, buffer);
919 if (!port->parseOption(&argc, argv, &i))
920 werror(W_UNKNOWN_OPTION,argv[i]);
925 if (!port->parseOption(&argc, argv, &i)) {
926 /* no option must be a filename */
927 processFile(argv[i]);
931 /* set up external stack location if not explicitly specified */
932 if ( !options.xstack_loc )
933 options.xstack_loc = options.xdata_loc ;
935 /* if debug option is set the open the cdbFile */
936 if (/* options.debug && */ srcFileName) {
937 sprintf(cdbfnbuf,"%s.cdb",srcFileName);
938 if ((cdbFile = fopen(cdbfnbuf,"w")) == NULL)
939 werror(E_FILE_OPEN_ERR,cdbfnbuf);
941 /* add a module record */
942 fprintf(cdbFile,"M:%s\n",moduleName);
945 port->finaliseOptions();
949 /*-----------------------------------------------------------------*/
950 /* my_system - will call a program with arguments */
951 /*-----------------------------------------------------------------*/
952 char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
953 int my_system (const char *cmd, char **cmd_argv)
956 char *dir, *got= NULL; int i= 0;
957 while (!got && try_dir[i]) {
958 dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10);
959 strcpy(dir, try_dir[i]); strcat(dir, "/"); strcat(dir, cmd);
960 if (access(dir, X_OK) == 0)
965 #if FEATURE_VERBOSE_EXEC
967 char **pCmd = cmd_argv;
969 printf("%s ", *pCmd);
976 i= spawnv(P_WAIT,got,cmd_argv) == -1;
978 i= spawnvp(P_WAIT,cmd,cmd_argv) == -1;
980 perror("Cannot exec process ");
987 /*-----------------------------------------------------------------*/
988 /* linkEdit : - calls the linkage editor with options */
989 /*-----------------------------------------------------------------*/
990 static void linkEdit (char **envp)
998 srcFileName = "temp";
1000 /* first we need to create the <filename>.lnk file */
1001 sprintf(buffer,"%s.lnk",srcFileName);
1002 if (!(lnkfile = fopen(buffer,"w"))) {
1003 werror(E_FILE_OPEN_ERR,buffer);
1007 /* now write the options */
1008 fprintf(lnkfile,"-mux%c\n", (options.out_fmt ? 's' : 'i'));
1010 /* if iram size specified */
1011 if (options.iram_size)
1012 fprintf(lnkfile,"-a 0x%04x\n",options.iram_size);
1014 /*if (options.debug) */
1015 fprintf(lnkfile,"-z\n");
1017 #define WRITE_SEG_LOC(N, L) \
1018 segName = strdup(N); \
1019 c = strtok(segName, " \t"); \
1020 fprintf (lnkfile,"-b %s = 0x%04x\n", c, L); \
1021 if (segName) { free(segName); }
1023 /* code segment start */
1024 WRITE_SEG_LOC(CODE_NAME, options.code_loc);
1026 /* data segment start */
1027 WRITE_SEG_LOC(DATA_NAME, options.data_loc);
1030 WRITE_SEG_LOC(XDATA_NAME, options. xdata_loc);
1033 WRITE_SEG_LOC(IDATA_NAME, options.idata_loc);
1035 /* bit segment start */
1036 WRITE_SEG_LOC(BIT_NAME, 0);
1038 /* add the extra linker options */
1039 for (i=0; linkOptions[i] ; i++)
1040 fprintf(lnkfile,"%s\n",linkOptions[i]);
1042 /* standard library path */
1043 switch(options.model)
1055 werror(W_UNKNOWN_MODEL, __FILE__, __LINE__);
1059 fprintf (lnkfile,"-k %s/%s\n",SDCC_LIB_DIR/*STD_LIB_PATH*/,c);
1061 /* other library paths if specified */
1062 for (i = 0 ; i < nlibPaths ; i++ )
1063 fprintf (lnkfile,"-k %s\n",libPaths[i]);
1065 /* standard library files */
1066 fprintf (lnkfile,"-l %s\n",STD_LIB);
1067 fprintf (lnkfile,"-l %s\n",STD_INT_LIB);
1068 fprintf (lnkfile,"-l %s\n",STD_LONG_LIB);
1069 fprintf (lnkfile,"-l %s\n",STD_FP_LIB);
1071 /* additional libraries if any */
1072 for (i = 0 ; i < nlibFiles; i++)
1073 fprintf (lnkfile,"-l %s\n",libFiles[i]);
1075 /* put in the object files */
1076 if (strcmp(srcFileName,"temp"))
1077 fprintf (lnkfile,"%s ",srcFileName);
1079 for (i = 0 ; i < nrelFiles ; i++ )
1080 fprintf (lnkfile,"%s\n",relFiles[i]);
1082 fprintf (lnkfile,"\n-e\n");
1085 _buildCmdLine(buffer, argv, port->linker.cmd, srcFileName, NULL, NULL, NULL);
1087 /* call the linker */
1088 if (my_system(argv[0], argv)) {
1089 perror("Cannot exec linker");
1093 if (strcmp(srcFileName,"temp") == 0) {
1094 /* rename "temp.cdb" to "firstRelFile.cdb" */
1095 char *f = strtok(strdup(relFiles[0]),".");
1096 f = strcat(f,".cdb");
1097 rename("temp.cdb",f);
1102 /*-----------------------------------------------------------------*/
1103 /* assemble - spawns the assembler with arguments */
1104 /*-----------------------------------------------------------------*/
1105 static void assemble (char **envp)
1107 char *argv[128]; /* assembler arguments */
1109 _buildCmdLine(buffer, argv, port->assembler.cmd, srcFileName, NULL, NULL, asmOptions);
1111 if (my_system(argv[0], argv)) {
1112 perror("Cannot exec assember");
1119 /*-----------------------------------------------------------------*/
1120 /* preProcess - spawns the preprocessor with arguments */
1121 /*-----------------------------------------------------------------*/
1122 static int preProcess (char **envp)
1129 /* if using external stack define the macro */
1130 if ( options.useXstack )
1131 _addToList(preArgv, "-DSDCC_USE_XSTACK");
1133 /* set the macro for stack autos */
1134 if ( options.stackAuto )
1135 _addToList(preArgv, "-DSDCC_STACK_AUTO");
1137 /* set the macro for large model */
1138 switch(options.model)
1141 _addToList(preArgv, "-DSDCC_MODEL_LARGE");
1144 _addToList(preArgv, "-DSDCC_MODEL_SMALL");
1147 _addToList(preArgv, "-DSDCC_MODEL_FLAT24");
1150 werror(W_UNKNOWN_MODEL, __FILE__, __LINE__);
1155 /* add port (processor information to processor */
1156 sprintf(procDef,"-DSDCC_%s",port->target);
1157 _addToList(preArgv,procDef);
1160 preOutName = strdup(tmpnam(NULL));
1162 _buildCmdLine(buffer, argv, _preCmd, fullSrcFileName,
1163 preOutName, srcFileName, preArgv);
1165 if (my_system(argv[0], argv)) {
1166 unlink (preOutName);
1167 perror("Cannot exec Preprocessor");
1174 yyin = fopen(preOutName,"r");
1176 perror("Preproc file not found\n");
1183 static void _findPort(int argc, char **argv)
1187 if (!strncmp(*argv, "-m", 2)) {
1188 _setPort(*argv + 2);
1194 /* Use the first in the list */
1200 * initialises and calls the parser
1203 int main ( int argc, char **argv , char **envp)
1205 /* turn all optimizations off by default */
1206 memset(&optimize,0,sizeof(struct optimize));
1208 /*printVersionInfo ();*/
1210 _findPort(argc, argv);
1211 setDefaultOptions();
1212 parseCmdLine(argc,argv);
1214 /* if no input then printUsage & exit */
1215 if (!srcFileName && !nrelFiles) {
1242 if (!options.cc_only &&
1245 (srcFileName || nrelFiles))
1248 if (yyin && yyin != stdin)