X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCmain.c;h=7f58094f4866837ee85e5cb22319028262443e49;hb=dded9a9b5ed895064bab8b5951f44c18c639430b;hp=b0c27c3aed97c66687d2a7b865a59265c8786214;hpb=e33697a63656f0521f622699c6051483f7c740ed;p=fw%2Fsdcc diff --git a/src/SDCCmain.c b/src/SDCCmain.c index b0c27c3a..7f58094f 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -35,18 +35,8 @@ #include "spawn.h" #endif -// This is a bit messy because we define link ourself #if !defined(__BORLANDC__) && !defined(_MSC_VER) - #include - -#else -// No unistd.h in Borland C++ -/* -extern int access (const char *, int); -#define X_OK 1 -*/ - #endif //REMOVE ME!!! @@ -141,16 +131,17 @@ optionsTable[] = { { 'C', NULL, NULL, "Preprocessor option" }, { 'M', NULL, NULL, "Preprocessor option" }, { 'V', NULL, &verboseExec, "Execute verbosely. Show sub commands as they are run" }, - { 'S', NULL, &noAssemble, "Assemble only" }, + { 'S', NULL, &noAssemble, "Compile only; do not assemble or link" }, { 'W', NULL, NULL, "Pass through options to the assembler (a) or linker (l)" }, { 'L', NULL, NULL, "Add the next field to the library search path" }, - { 0, OPTION_LARGE_MODEL, NULL, "Far functions, far data" }, - { 0, OPTION_MEDIUM_MODEL, NULL, "Far functions, near data" }, - { 0, OPTION_SMALL_MODEL, NULL, "Small model (default)" }, - { 0, OPTION_FLAT24_MODEL, NULL, NULL }, + { 'l', NULL, NULL, "Include the given library in the link" }, + { 0, OPTION_LARGE_MODEL, NULL, "external data space is used" }, + { 0, OPTION_MEDIUM_MODEL, NULL, "not supported" }, + { 0, OPTION_SMALL_MODEL, NULL, "internal data space is used (default)" }, + { 0, OPTION_FLAT24_MODEL, NULL, "use the flat24 model for the ds390 (default)" }, { 0, "--stack-auto", &options.stackAuto, "Stack automatic variables" }, - { 0, OPTION_STACK_8BIT, NULL, NULL }, - { 0, "--stack-10bit", &options.stack10bit, NULL }, + { 0, OPTION_STACK_8BIT, NULL, "use the 8bit stack for the ds390 (not supported yet)" }, + { 0, "--stack-10bit", &options.stack10bit, "use the 10bit stack for ds390 (default)" }, { 0, "--xstack", &options.useXstack, "Use external stack" }, { 0, "--generic", &options.genericPtr, "All unqualified ptrs converted to '_generic'" }, { 0, OPTION_NO_GCSE, NULL, "Disable the GCSE optimisation" }, @@ -158,7 +149,7 @@ optionsTable[] = { { 0, OPTION_NO_LOOP_IND, NULL, NULL }, { 0, "--nojtbound", &optimize.noJTabBoundary, "Don't generate boundary check for jump tables" }, { 0, "--noloopreverse", &optimize.noLoopReverse, "Disable the loop reverse optimisation" }, - { 'c', "--compile-only", &options.cc_only, "Compile only, do not assemble or link" }, + { 'c', "--compile-only", &options.cc_only, "Compile and assemble, but do not link" }, { 0, "--dumpraw", &options.dump_raw, "Dump the internal structure after the initial parse" }, { 0, "--dumpgcse", &options.dump_gcse, NULL }, { 0, "--dumploop", &options.dump_loop, NULL }, @@ -167,15 +158,15 @@ optionsTable[] = { { 0, "--dumpregpack", &options.dump_pack, NULL }, { 0, "--dumpregassign", &options.dump_rassgn, NULL }, { 0, OPTION_DUMP_ALL, NULL, "Dump the internal structure at all stages" }, - { 0, OPTION_XRAM_LOC, NULL, NULL }, + { 0, OPTION_XRAM_LOC, NULL, " External Ram start location" }, { 0, OPTION_IRAM_SIZE, NULL, " Internal Ram size" }, { 0, OPTION_XSTACK_LOC, NULL, " External Ram start location" }, { 0, OPTION_CODE_LOC, NULL, " Code Segment Location" }, { 0, OPTION_STACK_LOC, NULL, " Stack pointer initial value" }, { 0, OPTION_DATA_LOC, NULL, " Direct data start location" }, { 0, OPTION_IDATA_LOC, NULL, NULL }, - { 0, OPTION_PEEP_FILE, NULL, NULL }, - { 0, OPTION_LIB_PATH, NULL, NULL }, + { 0, OPTION_PEEP_FILE, NULL, " use this extra peep-hole file" }, + { 0, OPTION_LIB_PATH, NULL, " use this path to search for libraries" }, { 0, "--int-long-reent", &options.intlong_rent, "Use reenterant calls on the int and long support functions" }, { 0, "--float-reent", &options.float_rent, "Use reenterant calls on the floar support functions" }, { 0, OPTION_OUT_FMT_IHX, NULL, NULL }, @@ -184,19 +175,21 @@ optionsTable[] = { { 0, "--nooverlay", &options.noOverlay, NULL }, { 0, "--main-return", &options.mainreturn, "Issue a return after main()" }, { 0, "--no-peep", &options.nopeep, "Disable the peephole assembly file optimisation" }, + { 0, "--no-reg-params", &options.noRegParams, "On some ports, disable passing some parameters in registers" }, { 0, "--peep-asm", &options.asmpeep, NULL }, { 0, "--debug", &options.debug, "Enable debugging symbol output" }, { 'v', OPTION_VERSION, NULL, "Display sdcc's version" }, - { 0, "--stack-after-data", &options.stackOnData, NULL }, + { 0, "--stack-after-data", &options.stackOnData, "initialize the stackpointer with the last byte use in DSEG" }, { 'E', "--preprocessonly", &preProcOnly, "Preprocess only, do not compile" }, { 0, "--c1mode", &options.c1mode, "Act in c1 mode. The input is preprocessed code, the output is assembly code." }, { 0, "--help", NULL, "Display this help" }, - { 0, OPTION_CALLEE_SAVES, NULL, "Cause the called function to save registers insted of the caller" }, + { 0, OPTION_CALLEE_SAVES, NULL, " Cause the called function to save registers insted of the caller" }, { 0, "--nostdlib", &options.nostdlib, "Do not include the standard library directory in the search path" }, - { 0, "--nostdinc", &options.nostdinc, NULL }, + { 0, "--nostdinc", &options.nostdinc, "Do not include the standard include directory in the search path" }, { 0, "--verbose", &options.verbose, "Trace calls to the preprocessor, assembler, and linker" }, { 0, OPTION_LESS_PEDANTIC, NULL, "Disable some of the more pedantic warnings" }, - { 0, OPTION_SHORT_IS_8BITS, NULL, "Make short 8bits (for old times sake)" } + { 0, OPTION_SHORT_IS_8BITS, NULL, "Make short 8bits (for old times sake)" }, + { 0, "--profile", &options.profile, "On supported ports, generate extra profiling information" } }; /** Table of all unsupported options and help text to display when one @@ -298,8 +291,7 @@ _validatePorts (void) { if (_ports[i]->magic != PORT_MAGIC) { - printf ("Error: port %s is incomplete.\n", _ports[i]->target); - wassert (0); + wassertl (0, "Port definition structure is incomplete"); } } } @@ -320,8 +312,8 @@ printVersionInfo () #ifdef SDCC_SUB_VERSION_STR "/" SDCC_SUB_VERSION_STR #endif -#ifdef __CYGWIN32__ - " (CYGWIN32)\n" +#ifdef __CYGWIN__ + " (CYGWIN)\n" #else #ifdef __DJGPP__ " (DJGPP) \n" @@ -338,27 +330,6 @@ printVersionInfo () ); } -/* - "\t-m - Target processor . Default %s\n" - "\t Try --version for supported values of \n" - "\t--model-large - Large Model\n" - "\t--model-small - Small Model (default)\n" - "\t--stack-auto - Stack automatic variables\n" - "\t--xstack - Use external stack\n" - "\t--xram-loc - External Ram start location\n" - "\t--xstack-loc - Xternal Stack Location\n" - "\t--code-loc - Code Segment Location\n" - "\t--stack-loc - Stack pointer initial value\n" - "\t--data-loc - Direct data start location\n" - "\t--idata-loc - Indirect data start location\n" - "\t--iram-size - Internal Ram size\n" - "\t--nojtbound - Don't generate boundary check for jump tables\n" - "\t--generic - All unqualified ptrs converted to '_generic'\n" - "PreProcessor Options :-\n" - "\t-Dmacro - Define Macro\n" - "\t-Ipath - Include \"*.h\" path\n" - "Note: this is NOT a complete list of options see docs for details\n", -*/ /*-----------------------------------------------------------------*/ /* printUsage - prints command line syntax */ /*-----------------------------------------------------------------*/ @@ -391,7 +362,7 @@ parseWithComma (char **dest, char *src) { int i = 0; - strtok (src, "\n \t"); + strtok (src, "\r\n \t"); /* skip the initial white spaces */ while (isspace (*src)) src++; @@ -436,7 +407,7 @@ setDefaultOptions () options.nostdlib = 0; options.nostdinc = 0; options.verbose = 0; - options.shortis8bits = 1; + options.shortis8bits = 0; options.stack10bit=0; @@ -584,13 +555,25 @@ _setModel (int model, const char *sz) then for input of '--optxyz' or '--opt xyz' returns xyz. */ static char * -getStringArg(const char *szStart, char **argv, int *pi) +getStringArg(const char *szStart, char **argv, int *pi, int argc) { - if (argv[*pi][strlen(szStart)]) { - return &argv[*pi][strlen(szStart)]; + if (argv[*pi][strlen(szStart)]) + { + return &argv[*pi][strlen(szStart)]; } - else { - return argv[++(*pi)]; + else + { + ++(*pi); + if (*pi >= argc) + { + werror (E_ARGUMENT_MISSING, szStart); + /* Die here rather than checking for errors later. */ + exit(-1); + } + else + { + return argv[*pi]; + } } } @@ -598,9 +581,18 @@ getStringArg(const char *szStart, char **argv, int *pi) getStringArg. */ static int -getIntArg(const char *szStart, char **argv, int *pi) +getIntArg(const char *szStart, char **argv, int *pi, int argc) +{ + return (int)floatFromVal(constVal(getStringArg(szStart, argv, pi, argc))); +} + +static void +verifyShortOption(const char *opt) { - return (int)floatFromVal(constVal(getStringArg(szStart, argv, pi))); + if (strlen(opt) != 2) + { + werror (W_EXCESS_SHORT_OPTIONS, opt); + } } static bool @@ -662,22 +654,29 @@ tryHandleSimpleOpt(char **argv, int *pi) } for (i = 0; i < LENGTH(optionsTable); i++) - { - if (optionsTable[i].shortOpt == shortOpt || - (longOpt && optionsTable[i].longOpt && strcmp(optionsTable[i].longOpt, longOpt) == 0)) - { - // If it is a flag then we can handle it here - if (optionsTable[i].pparameter != NULL) - { - (*optionsTable[i].pparameter)++; - return 1; - } - else { - // Not a flag. Handled manually later. - return 0; - } - } - } + { + if (optionsTable[i].shortOpt == shortOpt || + (longOpt && optionsTable[i].longOpt && + strcmp(optionsTable[i].longOpt, longOpt) == 0)) + { + + // If it is a flag then we can handle it here + if (optionsTable[i].pparameter != NULL) + { + if (optionsTable[i].shortOpt == shortOpt) + { + verifyShortOption(argv[*pi]); + } + + (*optionsTable[i].pparameter)++; + return 1; + } + else { + // Not a flag. Handled manually later. + return 0; + } + } + } // Didn't find in the table return 0; } @@ -771,13 +770,13 @@ parseCmdLine (int argc, char **argv) if (strcmp (argv[i], OPTION_PEEP_FILE) == 0) { - options.peep_file = getStringArg(OPTION_PEEP_FILE, argv, &i); + options.peep_file = getStringArg(OPTION_PEEP_FILE, argv, &i, argc); continue; } if (strcmp (argv[i], OPTION_LIB_PATH) == 0) { - libPaths[nlibPaths++] = getStringArg(OPTION_LIB_PATH, argv, &i); + libPaths[nlibPaths++] = getStringArg(OPTION_LIB_PATH, argv, &i, argc); continue; } @@ -790,49 +789,49 @@ parseCmdLine (int argc, char **argv) if (strcmp (argv[i], OPTION_CALLEE_SAVES) == 0) { - parseWithComma (options.calleeSaves, getStringArg(OPTION_CALLEE_SAVES, argv, &i)); + parseWithComma (options.calleeSaves, getStringArg(OPTION_CALLEE_SAVES, argv, &i, argc)); continue; } if (strcmp (argv[i], OPTION_XSTACK_LOC) == 0) { - options.xstack_loc = getIntArg(OPTION_XSTACK_LOC, argv, &i); + options.xstack_loc = getIntArg(OPTION_XSTACK_LOC, argv, &i, argc); continue; } if (strcmp (argv[i], OPTION_STACK_LOC) == 0) { - options.stack_loc = getIntArg(OPTION_STACK_LOC, argv, &i); + options.stack_loc = getIntArg(OPTION_STACK_LOC, argv, &i, argc); continue; } if (strcmp (argv[i], OPTION_XRAM_LOC) == 0) { - options.xdata_loc = getIntArg(OPTION_XRAM_LOC, argv, &i); + options.xdata_loc = getIntArg(OPTION_XRAM_LOC, argv, &i, argc); continue; } if (strcmp (argv[i], OPTION_IRAM_SIZE) == 0) { - options.iram_size = getIntArg(OPTION_IRAM_SIZE, argv, &i); + options.iram_size = getIntArg(OPTION_IRAM_SIZE, argv, &i, argc); continue; } if (strcmp (argv[i], OPTION_DATA_LOC) == 0) { - options.data_loc = getIntArg(OPTION_DATA_LOC, argv, &i); + options.data_loc = getIntArg(OPTION_DATA_LOC, argv, &i, argc); continue; } if (strcmp (argv[i], OPTION_IDATA_LOC) == 0) { - options.idata_loc = getIntArg(OPTION_IDATA_LOC, argv, &i); + options.idata_loc = getIntArg(OPTION_IDATA_LOC, argv, &i, argc); continue; } if (strcmp (argv[i], OPTION_CODE_LOC) == 0) { - options.code_loc = getIntArg(OPTION_CODE_LOC, argv, &i); + options.code_loc = getIntArg(OPTION_CODE_LOC, argv, &i, argc); continue; } @@ -855,15 +854,16 @@ parseCmdLine (int argc, char **argv) } if (strcmp (argv[i], OPTION_LESS_PEDANTIC) == 0) - { - setErrorLogLevel(ERROR_LEVEL_WARNING); - continue; - } + { + setErrorLogLevel(ERROR_LEVEL_WARNING); + continue; + } - if (strcmp (&argv[i][1], OPTION_SHORT_IS_8BITS) == 0) { - options.shortis8bits=1; - continue; - } + if (strcmp (&argv[i][1], OPTION_SHORT_IS_8BITS) == 0) + { + options.shortis8bits=1; + continue; + } if (!port->parseOption (&argc, argv, &i)) { @@ -881,6 +881,8 @@ parseCmdLine (int argc, char **argv) switch (argv[i][1]) { case 'h': + verifyShortOption(argv[i]); + printUsage (); exit (0); break; @@ -891,25 +893,31 @@ parseCmdLine (int argc, char **argv) break; case 'c': + verifyShortOption(argv[i]); + options.cc_only = 1; break; case 'L': - libPaths[nlibPaths++] = getStringArg("-L", argv, &i); + libPaths[nlibPaths++] = getStringArg("-L", argv, &i, argc); + break; + + case 'l': + libFiles[nlibFiles++] = getStringArg("-l", argv, &i, argc); break; case 'W': /* linker options */ if (argv[i][2] == 'l') { - parseWithComma(linkOptions, getStringArg("-Wl", argv, &i)); + parseWithComma(linkOptions, getStringArg("-Wl", argv, &i, argc)); } else { /* assembler options */ if (argv[i][2] == 'a') { - parseWithComma ((char **) asmOptions, getStringArg("-Wa", argv, &i)); + parseWithComma ((char **) asmOptions, getStringArg("-Wa", argv, &i, argc)); } else { @@ -919,6 +927,8 @@ parseCmdLine (int argc, char **argv) break; case 'v': + verifyShortOption(argv[i]); + printVersionInfo (); exit (0); break; @@ -1309,10 +1319,6 @@ main (int argc, char **argv, char **envp) setDefaultOptions (); parseCmdLine (argc, argv); - initMem (); - - port->finaliseOptions (); - /* if no input then printUsage & exit */ if ((!options.c1mode && !srcFileName && !nrelFiles) || (options.c1mode && !srcFileName && !options.out_name)) @@ -1325,6 +1331,10 @@ main (int argc, char **argv, char **envp) { preProcess (envp); + initMem (); + + port->finaliseOptions (); + initSymt (); initiCode (); initCSupport (); @@ -1381,6 +1391,9 @@ main (int argc, char **argv, char **envp) free (preOutName); } // EndFix + #if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER) + rm_tmpfiles(); + #endif return 1; } @@ -1391,6 +1404,12 @@ main (int argc, char **argv, char **envp) if (cdbFile) fclose (cdbFile); + if (preOutName && !options.c1mode) + { + unlink (preOutName); + free (preOutName); + } + if (!options.cc_only && !fatalError && !noAssemble && @@ -1406,12 +1425,6 @@ main (int argc, char **argv, char **envp) if (yyin && yyin != stdin) fclose (yyin); - if (preOutName && !options.c1mode) - { - unlink (preOutName); - free (preOutName); - } - return 0; }