From 6210487131834e13c9a50d4eb9739f9036bb66e0 Mon Sep 17 00:00:00 2001 From: borutr Date: Mon, 18 Jun 2007 18:24:42 +0000 Subject: [PATCH] * src/SDCCmain.c: removed option -C since SDCC compiler doesn't know how to handle comments, so they have to be removed by the preprocessor; fixed bug #1738926:SDCC #4852: broken option -V * src/SDCCmain.c, src/SDCCargs.h, src/ds390/main.c, src/mcs15/main.c, src/pic16/main.c, src/pic/main.c, src/z80/main.c, support/Util/SDCCerr.c, support/Util/SDCCerr.h: table driven option hadling git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4855 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 10 + src/SDCCargs.h | 8 +- src/SDCCmain.c | 190 +++++-------- src/ds390/main.c | 53 ++-- src/mcs51/main.c | 7 +- src/pic/main.c | 23 +- src/pic16/main.c | 588 ++++++++++++++++++++--------------------- src/z80/main.c | 20 +- support/Util/SDCCerr.c | 2 + support/Util/SDCCerr.h | 1 + 10 files changed, 389 insertions(+), 513 deletions(-) diff --git a/ChangeLog b/ChangeLog index 09a5f257..772a6ab3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-06-18 Borut Razem + + * src/SDCCmain.c: removed option -C since SDCC compiler doesn't know + how to handle comments, so they have to be removed by the + preprocessor; fixed bug #1738926:SDCC #4852: broken option -V + * src/SDCCmain.c, src/SDCCargs.h, src/ds390/main.c, src/mcs15/main.c, + src/pic16/main.c, src/pic/main.c, src/z80/main.c, + support/Util/SDCCerr.c, support/Util/SDCCerr.h: + table driven option hadling + 2007-06-16 Maarten Brock * src/SDCCast.c (decorateType), diff --git a/src/SDCCargs.h b/src/SDCCargs.h index dc8c3ff5..5a143d6f 100644 --- a/src/SDCCargs.h +++ b/src/SDCCargs.h @@ -24,18 +24,18 @@ /** Definition of the structures used by the options parser. The port may implement one of these for any options it wants parsed - automatically. + automatically. */ #ifndef SDCCARGS_H #define SDCCARGS_H /** Specifies option argument types. */ enum cl_opt_arg_type { - /* */ - CLAT_BOOLEAN, + CLAT_BOOLEAN = 0, /* has to be zero! */ CLAT_INTEGER, CLAT_STRING, - CLAT_SET + CLAT_SET, + CLAT_ADD_SET }; /** Table of all options supported by all ports. diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 71fb8863..ee6cd530 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -153,7 +153,6 @@ optionsTable[] = { { 'I', NULL, NULL, "Add to the include (*.h) path, as in -Ipath" }, { 'A', NULL, NULL, NULL }, { 'U', NULL, NULL, NULL }, - { 'C', NULL, NULL, "Preprocessor option" }, { 'M', NULL, NULL, "Preprocessor option" }, { 'W', NULL, NULL, "Pass through options to the pre-processor (p), assembler (a) or linker (l)" }, { 'S', NULL, &noAssemble, "Compile only; do not assemble or link" }, @@ -189,7 +188,7 @@ optionsTable[] = { { 0, "--float-reent", &options.float_rent, "Use reenterant calls on the float support functions" }, { 0, "--main-return", &options.mainreturn, "Issue a return after main()" }, { 0, "--xram-movc", &options.xram_movc, "Use movc instead of movx to read xram (xdata)" }, - { 0, OPTION_CALLEE_SAVES, NULL, " Cause the called function to save registers insted of the caller" }, + { 0, OPTION_CALLEE_SAVES, &options.calleeSavesSet, " Cause the called function to save registers insted of the caller", CLAT_SET }, { 0, "--profile", &options.profile, "On supported ports, generate extra profiling information" }, { 0, "--fommit-frame-pointer", &options.ommitFramePtr, "Leave out the frame pointer." }, { 0, "--all-callee-saves", &options.all_callee_saves, "callee will always save registers used" }, @@ -213,7 +212,7 @@ optionsTable[] = { { 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, "Enable peephole optimization on inline assembly" }, - { 0, OPTION_PEEP_FILE, NULL, " use this extra peephole file" }, + { 0, OPTION_PEEP_FILE, &options.peep_file, " use this extra peephole file", CLAT_STRING }, { 0, OPTION_OPT_CODE_SPEED, NULL, "Optimize for code speed rather than size" }, { 0, OPTION_OPT_CODE_SIZE, NULL, "Optimize for code size rather than speed" }, @@ -232,18 +231,18 @@ optionsTable[] = { { 0, NULL, NULL, "Linker options" }, { 'l', NULL, NULL, "Include the given library in the link" }, { 'L', NULL, NULL, "Add the next field to the library search path" }, - { 0, OPTION_LIB_PATH, NULL, " use this path to search for libraries" }, + { 0, OPTION_LIB_PATH, &libPathsSet, " use this path to search for libraries", CLAT_ADD_SET }, { 0, OPTION_OUT_FMT_IHX, NULL, "Output in Intel hex format" }, { 0, OPTION_OUT_FMT_S19, NULL, "Output in S19 hex format" }, - { 0, OPTION_XRAM_LOC, NULL, " External Ram start location" }, - { 0, OPTION_XRAM_SIZE, NULL, " External Ram size" }, - { 0, OPTION_IRAM_SIZE, NULL, " Internal Ram size" }, - { 0, OPTION_XSTACK_LOC, NULL, " External Stack start location" }, - { 0, OPTION_CODE_LOC, NULL, " Code Segment Location" }, - { 0, OPTION_CODE_SIZE, NULL, " Code Segment size" }, - { 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_XRAM_LOC, &options.xdata_loc, " External Ram start location", CLAT_INTEGER }, + { 0, OPTION_XRAM_SIZE, &options.xram_size, " External Ram size", CLAT_INTEGER }, + { 0, OPTION_IRAM_SIZE, &options.iram_size, " Internal Ram size", CLAT_INTEGER }, + { 0, OPTION_XSTACK_LOC, &options.xstack_loc, " External Stack start location", CLAT_INTEGER }, + { 0, OPTION_CODE_LOC, &options.code_loc, " Code Segment Location", CLAT_INTEGER }, + { 0, OPTION_CODE_SIZE, &options.code_size, " Code Segment size", CLAT_INTEGER }, + { 0, OPTION_STACK_LOC, &options.stack_loc, " Stack pointer initial value", CLAT_INTEGER }, + { 0, OPTION_DATA_LOC, &options.data_loc, " Direct data start location", CLAT_INTEGER }, + { 0, OPTION_IDATA_LOC, &options.idata_loc, NULL, CLAT_INTEGER }, /* End of options */ { 0, NULL } @@ -343,7 +342,7 @@ _setPort (const char *name) } /* Error - didnt find */ werror (E_UNKNOWN_TARGET, name); - exit (1); + exit (EXIT_FAILURE); } /* Override the default processor with the one specified @@ -437,7 +436,7 @@ printVersionInfo (FILE *stream) #elif defined(__BORLANDC__) " (BORLANDC)\n" #else - " (UNIX) \n" + " (UNIX)\n" #endif , getBuildNumber() ); } @@ -624,7 +623,7 @@ processFile (char *s) dbuf_destroy (&path); - exit (1); + exit (EXIT_FAILURE); } /* get rid of any path information @@ -712,7 +711,18 @@ getStringArg(const char *szStart, char **argv, int *pi, int argc) int getIntArg(const char *szStart, char **argv, int *pi, int argc) { - return (int)floatFromVal(constVal(getStringArg(szStart, argv, pi, argc))); + char *p; + int val; + char *str = getStringArg(szStart, argv, pi, argc); + + val = strtol(str, &p, 0); + if (p == str || *p != '\0') + { + werror (E_BAD_INT_ARGUMENT, szStart); + /* Die here rather than checking for errors later. */ + exit (EXIT_FAILURE); + } + return val; } static void @@ -784,21 +794,18 @@ scanOptionsTable(const OPTION *optionsTable, char shortOpt, const char *longOpt, verifyShortOption(argv[*pi]); (*(int *)optionsTable[i].pparameter)++; - } - else - { - /* Not a flag. Handled manually later. */ - return FALSE; + + return TRUE; } } else { - size_t len = optionsTable[i].longOpt ? strlen(optionsTable[i].longOpt) : 0; + size_t len = optionsTable[i].longOpt ? strlen (optionsTable[i].longOpt) : 0; if (longOpt && (optionsTable[i].arg_type != CLAT_BOOLEAN || - (optionsTable[i].arg_type == CLAT_BOOLEAN && len == strlen(longOpt) && optionsTable[i].longOpt)) && - strncmp(optionsTable[i].longOpt, longOpt, len) == 0) + (optionsTable[i].arg_type == CLAT_BOOLEAN && len == strlen (longOpt) && optionsTable[i].longOpt)) && + strncmp (optionsTable[i].longOpt, longOpt, len) == 0) { /* If it is a flag then we can handle it here */ if (optionsTable[i].pparameter != NULL) @@ -816,13 +823,19 @@ scanOptionsTable(const OPTION *optionsTable, char shortOpt, const char *longOpt, case CLAT_STRING: if (*(char **)optionsTable[i].pparameter) Safe_free(*(char **)optionsTable[i].pparameter); - *(char **)optionsTable[i].pparameter = Safe_strdup(getStringArg (optionsTable[i].longOpt, argv, pi, argc)); + *(char **)optionsTable[i].pparameter = Safe_strdup (getStringArg (optionsTable[i].longOpt, argv, pi, argc)); break; case CLAT_SET: if (*(set **)optionsTable[i].pparameter) - deleteSet((set **)optionsTable[i].pparameter); - setParseWithComma((set **)optionsTable[i].pparameter, getStringArg(optionsTable[i].longOpt, argv, &i, argc)); + { + deleteSet ((set **)optionsTable[i].pparameter); + } + setParseWithComma ((set **)optionsTable[i].pparameter, getStringArg (optionsTable[i].longOpt, argv, pi, argc)); + break; + + case CLAT_ADD_SET: + addSet((set **)optionsTable[i].pparameter, Safe_strdup (getStringArg (optionsTable[i].longOpt, argv, pi, argc))); break; } return TRUE; @@ -968,18 +981,6 @@ parseCmdLine (int argc, char **argv) continue; } - if (strcmp (argv[i], OPTION_PEEP_FILE) == 0) - { - options.peep_file = getStringArg(OPTION_PEEP_FILE, argv, &i, argc); - continue; - } - - if (strcmp (argv[i], OPTION_LIB_PATH) == 0) - { - addSet(&libPathsSet, Safe_strdup(getStringArg(OPTION_LIB_PATH, argv, &i, argc))); - continue; - } - if (strcmp (argv[i], OPTION_VERSION) == 0) { printVersionInfo (stdout); @@ -987,67 +988,6 @@ parseCmdLine (int argc, char **argv) continue; } - if (strcmp (argv[i], OPTION_CALLEE_SAVES) == 0) - { - setParseWithComma(&options.calleeSavesSet, 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, argc); - continue; - } - - if (strcmp (argv[i], OPTION_STACK_LOC) == 0) - { - 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, argc); - continue; - } - - if (strcmp (argv[i], OPTION_IRAM_SIZE) == 0) - { - options.iram_size = getIntArg(OPTION_IRAM_SIZE, argv, &i, argc); - continue; - } - - if (strcmp (argv[i], OPTION_XRAM_SIZE) == 0) - { - options.xram_size = getIntArg(OPTION_XRAM_SIZE, argv, &i, argc); - options.xram_size_set = TRUE; - continue; - } - - if (strcmp (argv[i], OPTION_CODE_SIZE) == 0) - { - options.code_size = getIntArg(OPTION_CODE_SIZE, argv, &i, argc); - continue; - } - - if (strcmp (argv[i], OPTION_DATA_LOC) == 0) - { - 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, argc); - continue; - } - - if (strcmp (argv[i], OPTION_CODE_LOC) == 0) - { - options.code_loc = getIntArg(OPTION_CODE_LOC, argv, &i, argc); - continue; - } - if (strcmp (argv[i], OPTION_NO_GCSE) == 0) { optimize.global_cse = 0; @@ -1264,7 +1204,7 @@ parseCmdLine (int argc, char **argv) verifyShortOption(argv[i]); printVersionInfo (stdout); - exit (0); + exit (EXIT_SUCCESS); break; /* preprocessor options */ @@ -1277,11 +1217,6 @@ parseCmdLine (int argc, char **argv) addSet(&preArgvSet, Safe_strdup("-M")); break; } - case 'C': - { - addSet(&preArgvSet, Safe_strdup("-C")); - break; - } case 'd': case 'D': @@ -1369,7 +1304,7 @@ parseCmdLine (int argc, char **argv) if (!dstFileName) { werror (E_NEED_OPT_O_IN_C1); - exit (1); + exit (EXIT_FAILURE); } } /* if no dstFileName given with -o, we've to find one: */ @@ -1511,7 +1446,7 @@ linkEdit (char **envp) if (!(lnkfile = fopen (linkerScriptFileName, "w"))) { werror (E_FILE_OPEN_ERR, linkerScriptFileName); - exit (1); + exit (EXIT_FAILURE); } if (TARGET_Z80_LIKE) @@ -1944,7 +1879,7 @@ linkEdit (char **envp) } if (system_ret) { - exit (1); + exit (EXIT_FAILURE); } } @@ -1981,7 +1916,7 @@ assemble (char **envp) /* either system() or the assembler itself has reported an error perror ("Cannot exec assembler"); */ - exit (1); + exit (EXIT_FAILURE); } /* TODO: most assembler don't have a -o parameter */ /* -o option overrides default name? */ @@ -2113,16 +2048,16 @@ preProcess (char **envp) if (preProcOnly) { if (my_system (buffer)) { - exit (1); + exit (EXIT_FAILURE); } - exit (0); + exit (EXIT_SUCCESS); } yyin = my_popen (buffer); if (yyin == NULL) { perror ("Preproc file not found"); - exit (1); + exit (EXIT_FAILURE); } } @@ -2335,7 +2270,7 @@ sig_handler (int signal) break; } fprintf (stderr, "Caught signal %d: %s\n", signal, sig_string); - exit (1); + exit (EXIT_FAILURE); } /* @@ -2349,10 +2284,11 @@ main (int argc, char **argv, char **envp) /* turn all optimizations off by default */ memset (&optimize, 0, sizeof (struct optimize)); - if (NUM_PORTS==0) { - fprintf (stderr, "Build error: no ports are enabled.\n"); - exit (1); - } + if (NUM_PORTS==0) + { + fprintf (stderr, "Build error: no ports are enabled.\n"); + exit (EXIT_FAILURE); + } /* install signal handler; it's only purpose is to call exit() to remove temp files */ @@ -2404,11 +2340,11 @@ main (int argc, char **argv, char **envp) setBinPaths(argv[0]); setDataPaths(argv[0]); - if(port->initPaths) - port->initPaths(); + if (port->initPaths) + port->initPaths(); - if(options.printSearchDirs) - doPrintSearchDirs(); + if (options.printSearchDirs) + doPrintSearchDirs(); /* if no input then printUsage & exit */ if (!options.c1mode && !fullSrcFileName && peekSet(relFilesSet) == NULL) @@ -2454,17 +2390,17 @@ main (int argc, char **argv, char **envp) } if (port->general.do_glue != NULL) - (*port->general.do_glue)(); + (*port->general.do_glue) (); else { /* this shouldn't happen */ - assert(FALSE); + assert (FALSE); /* in case of NDEBUG */ - glue(); + glue (); } if (fatalError) { - exit (1); + exit (EXIT_FAILURE); } if (!options.c1mode && !noAssemble) diff --git a/src/ds390/main.c b/src/ds390/main.c index ae17bdc2..ba67a622 100644 --- a/src/ds390/main.c +++ b/src/ds390/main.c @@ -26,13 +26,13 @@ static OPTION _ds390_options[] = { { 0, OPTION_FLAT24_MODEL, NULL, "use the flat24 model for the ds390 (default)" }, { 0, OPTION_STACK_8BIT, NULL, "use the 8bit stack for the ds390 (not supported yet)" }, - { 0, OPTION_STACK_SIZE, NULL, "Tells the linker to allocate this space for stack"}, + { 0, OPTION_STACK_SIZE, &options.stack_size, "Tells the linker to allocate this space for stack", CLAT_INTEGER }, { 0, "--pack-iram", NULL, "Tells the linker to pack variables in internal ram (default)"}, - { 0, "--no-pack-iram", &options.no_pack_iram,"Tells the linker not to pack variables in internal ram"}, + { 0, "--no-pack-iram", &options.no_pack_iram, "Tells the linker not to pack variables in internal ram"}, { 0, "--stack-10bit", &options.stack10bit, "use the 10bit stack for ds390 (default)" }, - { 0, "--use-accelerator", &options.useAccelerator,"generate code for ds390 arithmetic accelerator"}, - { 0, "--protect-sp-update", &options.protect_sp_update,"will disable interrupts during ESP:SP updates"}, - { 0, "--parms-in-bank1", &options.parms_in_bank1,"use Bank1 for parameter passing"}, + { 0, "--use-accelerator", &options.useAccelerator, "generate code for ds390 arithmetic accelerator"}, + { 0, "--protect-sp-update", &options.protect_sp_update, "will disable interrupts during ESP:SP updates"}, + { 0, "--parms-in-bank1", &options.parms_in_bank1, "use Bank1 for parameter passing"}, { 0, NULL } }; @@ -145,11 +145,6 @@ _ds390_parseOptions (int *pargc, char **argv, int *i) options.model = MODEL_FLAT24; return TRUE; } - else if (!strcmp (argv[*i], OPTION_STACK_SIZE)) - { - options.stack_size = getIntArg (OPTION_STACK_SIZE, argv, i, *pargc); - return TRUE; - } return FALSE; } @@ -992,31 +987,17 @@ static OPTION _tininative_options[] = { { 0, OPTION_FLAT24_MODEL, NULL, "use the flat24 model for the ds390 (default)" }, { 0, OPTION_STACK_8BIT, NULL, "use the 8bit stack for the ds390 (not supported yet)" }, - { 0, OPTION_STACK_SIZE, NULL, "Tells the linker to allocate this space for stack"}, + { 0, OPTION_STACK_SIZE, &options.stack_size, "Tells the linker to allocate this space for stack", CLAT_INTEGER }, { 0, "--pack-iram", NULL, "Tells the linker to pack variables in internal ram (default)"}, - { 0, "--no-pack-iram", &options.no_pack_iram,"Tells the linker not to pack variables in internal ram"}, + { 0, "--no-pack-iram", &options.no_pack_iram, "Tells the linker not to pack variables in internal ram"}, { 0, "--stack-10bit", &options.stack10bit, "use the 10bit stack for ds390 (default)" }, - { 0, "--use-accelerator", &options.useAccelerator,"generate code for ds390 arithmetic accelerator"}, - { 0, "--protect-sp-update", &options.protect_sp_update,"will disable interrupts during ESP:SP updates"}, - { 0, "--parms-in-bank1", &options.parms_in_bank1,"use Bank1 for parameter passing"}, - { 0, OPTION_TINI_LIBID, NULL, " LibraryID used in -mTININative"}, + { 0, "--use-accelerator", &options.useAccelerator, "generate code for ds390 arithmetic accelerator"}, + { 0, "--protect-sp-update", &options.protect_sp_update, "will disable interrupts during ESP:SP updates"}, + { 0, "--parms-in-bank1", &options.parms_in_bank1, "use Bank1 for parameter passing"}, + { 0, OPTION_TINI_LIBID, &options.tini_libid, " LibraryID used in -mTININative", CLAT_INTEGER }, { 0, NULL } }; -static bool -_tininative_parseOptions (int *pargc, char **argv, int *i) -{ - if (_ds390_parseOptions (pargc, argv, i)) - return TRUE; - - if (!strcmp (argv[*i], OPTION_TINI_LIBID)) - { - options.tini_libid = getIntArg (OPTION_TINI_LIBID, argv, i, *pargc); - return TRUE; - } - return FALSE; -} - static void _tininative_init (void) { asm_addTree (&asm_a390_mapping); @@ -1293,7 +1274,7 @@ PORT tininative_port = }, "", _tininative_init, - _tininative_parseOptions, + _ds390_parseOptions, _tininative_options, NULL, _tininative_finaliseOptions, @@ -1356,13 +1337,13 @@ static OPTION _ds400_options[] = { { 0, OPTION_FLAT24_MODEL, NULL, "use the flat24 model for the ds400 (default)" }, { 0, OPTION_STACK_8BIT, NULL, "use the 8bit stack for the ds400 (not supported yet)" }, - { 0, OPTION_STACK_SIZE, NULL, "Tells the linker to allocate this space for stack"}, + { 0, OPTION_STACK_SIZE, &options.stack_size, "Tells the linker to allocate this space for stack", CLAT_INTEGER }, { 0, "--pack-iram", NULL, "Tells the linker to pack variables in internal ram (default)"}, - { 0, "--no-pack-iram", &options.no_pack_iram,"Tells the linker not to pack variables in internal ram"}, + { 0, "--no-pack-iram", &options.no_pack_iram, "Tells the linker not to pack variables in internal ram"}, { 0, "--stack-10bit", &options.stack10bit, "use the 10bit stack for ds400 (default)" }, - { 0, "--use-accelerator", &options.useAccelerator,"generate code for ds400 arithmetic accelerator"}, - { 0, "--protect-sp-update", &options.protect_sp_update,"will disable interrupts during ESP:SP updates"}, - { 0, "--parms-in-bank1", &options.parms_in_bank1,"use Bank1 for parameter passing"}, + { 0, "--use-accelerator", &options.useAccelerator, "generate code for ds400 arithmetic accelerator"}, + { 0, "--protect-sp-update", &options.protect_sp_update, "will disable interrupts during ESP:SP updates"}, + { 0, "--parms-in-bank1", &options.parms_in_bank1, "use Bank1 for parameter passing"}, { 0, NULL } }; diff --git a/src/mcs51/main.c b/src/mcs51/main.c index b1676b91..ef5407e8 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -20,7 +20,7 @@ static char _defaultRules[] = static OPTION _mcs51_options[] = { - { 0, OPTION_STACK_SIZE, NULL, "Tells the linker to allocate this space for stack"}, + { 0, OPTION_STACK_SIZE, &options.stack_size, "Tells the linker to allocate this space for stack", CLAT_INTEGER }, { 0, "--parms-in-bank1", &options.parms_in_bank1, "use Bank1 for parameter passing"}, { 0, "--pack-iram", NULL, "Tells the linker to pack variables in internal ram (default)"}, { 0, "--no-pack-iram", &options.no_pack_iram, "Tells the linker not to pack variables in internal ram"}, @@ -124,11 +124,6 @@ _mcs51_parseOptions (int *pargc, char **argv, int *i) /* TODO: allow port-specific command line options to specify * segment names here. */ - if (!strcmp (argv[*i], OPTION_STACK_SIZE)) - { - options.stack_size = getIntArg(OPTION_STACK_SIZE, argv, i, *pargc); - return TRUE; - } return FALSE; } diff --git a/src/pic/main.c b/src/pic/main.c index d438a15f..74b79ca3 100644 --- a/src/pic/main.c +++ b/src/pic/main.c @@ -27,13 +27,14 @@ static char _defaultRules[] = pic14_options_t pic14_options; extern int debug_verbose; /* from pcode.c */ +extern char *udata_section_name; static OPTION _pic14_poptions[] = { { 0, "--debug-xtra", &debug_verbose, "show more debug info in assembly output" }, { 0, "--no-pcode-opt", &pic14_options.disable_df, "disable (slightly faulty) optimization on pCode" }, - { 0, OPTION_STACK_SIZE, NULL, "sets the size if the argument passing stack (default: 16, minimum: 4)" }, - { 0, OPTION_UDATA_SECTION_NAME, NULL, "set udata section name" }, + { 0, OPTION_STACK_SIZE, &options.stack_size, "sets the size if the argument passing stack (default: 16, minimum: 4)", CLAT_INTEGER }, + { 0, OPTION_UDATA_SECTION_NAME, &udata_section_name, "set udata section name", CLAT_STRING }, { 0, NULL, NULL, NULL } }; @@ -100,30 +101,12 @@ _pic14_regparm (sym_link * l, bool reentrant) return 1; } -extern char *udata_section_name; - static bool _pic14_parseOptions (int *pargc, char **argv, int *i) { /* TODO: allow port-specific command line options to specify * segment names here. */ - - /* This is a temporary hack, to solve problems with some processors - * that do not have udata section. It will be changed when a more - * robust solution is figured out -- VR 27-11-2003 FIXME - */ - if (!strcmp (argv[*i], OPTION_UDATA_SECTION_NAME)) - { - if (udata_section_name) Safe_free(udata_section_name); - udata_section_name = Safe_strdup(getStringArg (OPTION_UDATA_SECTION_NAME, argv, i, *pargc)); - return TRUE; - } - else if (!strcmp (argv[*i], OPTION_STACK_SIZE)) - { - options.stack_size = getIntArg (OPTION_STACK_SIZE, argv, i, *pargc); - return TRUE; - } return FALSE; } diff --git a/src/pic16/main.c b/src/pic16/main.c index 81ee7110..9409a269 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -4,7 +4,7 @@ Written by - Scott Dattalo scott@dattalo.com Ported to PIC16 by - Martin Dubuc m.debuc@rogers.com - + Note that mlh prepended _pic16_ on the static functions. Makes it easier to set a breakpoint using the debugger. @@ -13,12 +13,12 @@ under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -68,7 +68,7 @@ static char *_pic16_keywords[] = "prodhp", "fsr0lp", "fixed16x16", - + // "bit", // "idata", // "sbit", @@ -90,7 +90,7 @@ void pic16_pCodeInitRegisters(void); void pic16_assignRegisters (ebbIndex *); -static int regParmFlg = 0; /* determine if we can register a parameter */ +static int regParmFlg = 0; /* determine if we can register a parameter */ pic16_options_t pic16_options; @@ -101,7 +101,7 @@ extern set *libFilesSet; /* Also defined in gen.h, but the #include is commented out */ /* for an unknowned reason. - EEP */ void pic16_emitDebuggerSymbol (char *); - + extern void pic16_emitConfigRegs(FILE *of); extern void pic16_emitIDRegs(FILE *of); @@ -130,7 +130,7 @@ _pic16_regparm (sym_link * l, bool reentrant) * can pass only the first parameter in a register */ if(regParmFlg)return 0; regParmFlg++; - return 1; //regParmFlg; + return 1; //regParmFlg; } else { /* otherwise pass all arguments in registers via SEND/RECEIVE */ regParmFlg++;// = 1; @@ -139,12 +139,12 @@ _pic16_regparm (sym_link * l, bool reentrant) } -int initsfpnt=0; /* set to 1 if source provides a pragma for stack - * so glue() later emits code to initialize stack/frame pointers */ +int initsfpnt=0; /* set to 1 if source provides a pragma for stack + * so glue() later emits code to initialize stack/frame pointers */ set *absSymSet; -set *sectNames=NULL; /* list of section listed in pragma directives */ -set *sectSyms=NULL; /* list of symbols set in a specific section */ +set *sectNames=NULL; /* list of section listed in pragma directives */ +set *sectSyms=NULL; /* list of symbols set in a specific section */ set *wparamList=NULL; #if 0 @@ -160,7 +160,7 @@ struct { unsigned want_libio: 1; unsigned want_libdebug: 1; } libflags = { 0, 0, 0, 0, 0 }; - + enum { P_MAXRAM = 1, @@ -280,7 +280,7 @@ do_pragma(int id, const char *name, const char *cp) sym = newSymbol("stack_end", 0); sprintf(sym->rname, "_%s", sym->name); addSet(&publics, sym); - + initsfpnt = 1; // force glue() to initialize stack/frame pointers */ } break; @@ -424,12 +424,12 @@ do_pragma(int id, const char *name, const char *cp) lmodule = get_pragma_string(&token); /* lmodule can be: - * c link the C library - * math link the math library - * io link the IO library - * debug link the debug libary + * c link the C library + * math link the math library + * io link the IO library + * debug link the debug libary * anything else, will link as-is */ - + if(!strcmp(lmodule, "c")) libflags.want_libc = 1; else if(!strcmp(lmodule, "math")) @@ -478,7 +478,7 @@ do_pragma(int id, const char *name, const char *cp) { char *s; - + for(s = setFirstItem(asmInlineMap); s ; s = setNextItem(asmInlineMap)) { debugf("inline asm: `%s'\n", s); } @@ -517,25 +517,25 @@ _process_pragma(const char *s) return process_pragma_tbl(pragma_tbl, s); } -#define REP_UDATA "--preplace-udata-with=" +#define REP_UDATA "--preplace-udata-with=" -#define STACK_MODEL "--pstack-model=" -#define OPT_BANKSEL "--obanksel=" +#define STACK_MODEL "--pstack-model=" +#define OPT_BANKSEL "--obanksel=" -#define ALT_ASM "--asm=" -#define ALT_LINK "--link=" +#define ALT_ASM "--asm=" +#define ALT_LINK "--link=" -#define IVT_LOC "--ivt-loc=" -#define NO_DEFLIBS "--nodefaultlibs" -#define MPLAB_COMPAT "--mplab-comp" +#define IVT_LOC "--ivt-loc=" +#define NO_DEFLIBS "--nodefaultlibs" +#define MPLAB_COMPAT "--mplab-comp" -#define USE_CRT "--use-crt=" +#define USE_CRT "--use-crt=" -#define OFMSG_LRSUPPORT "--flr-support" +#define OFMSG_LRSUPPORT "--flr-support" #define OPTIMIZE_GOTO "--optimize-goto" -#define OPTIMIZE_CMP "--optimize-cmp" -#define OPTIMIZE_DF "--optimize-df" +#define OPTIMIZE_CMP "--optimize-cmp" +#define OPTIMIZE_DF "--optimize-df" char *alt_asm=NULL; char *alt_link=NULL; @@ -548,54 +548,54 @@ extern int pic16_pcode_verbose; int pic16_enable_peeps=0; OPTION pic16_optionsTable[]= { - /* code generation options */ - { 0, STACK_MODEL, NULL, "use stack model 'small' (default) or 'large'"}, + /* code generation options */ + { 0, STACK_MODEL, NULL, "use stack model 'small' (default) or 'large'"}, #if XINST - { 'y', "--extended", &xinst, "enable Extended Instruction Set/Literal Offset Addressing mode"}, + { 'y', "--extended", &xinst, "enable Extended Instruction Set/Literal Offset Addressing mode"}, #endif - { 0, "--pno-banksel", &pic16_options.no_banksel, "do not generate BANKSEL assembler directives"}, - - /* optimization options */ - { 0, OPT_BANKSEL, NULL, "set banksel optimization level (default=0 no)"}, - { 0, "--denable-peeps", &pic16_enable_peeps, "explicit enable of peepholes"}, - { 0, OPTIMIZE_GOTO, NULL, "try to use (conditional) BRA instead of GOTO"}, - { 0, OPTIMIZE_CMP, NULL, "try to optimize some compares"}, - { 0, OPTIMIZE_DF, NULL, "thoroughly analyze data flow (memory and time intensive!)"}, - - /* assembling options */ - { 0, ALT_ASM, NULL, "Use alternative assembler"}, - { 0, MPLAB_COMPAT, &pic16_mplab_comp, "enable compatibility mode for MPLAB utilities (MPASM/MPLINK)"}, - - /* linking options */ - { 0, ALT_LINK, NULL, "Use alternative linker"}, - { 0, REP_UDATA, NULL, "Place udata variables at another section: udata_acs, udata_ovr, udata_shr"}, - { 0, IVT_LOC, NULL, "Set address of interrupt vector table."}, - { 0, NO_DEFLIBS, &pic16_options.nodefaultlibs, "do not link default libraries when linking"}, - { 0, USE_CRT, NULL, "use run-time initialization module"}, - { 0, "--no-crt", &pic16_options.no_crt, "do not link any default run-time initialization module"}, - - /* debugging options */ - { 0, "--debug-xtra", &pic16_debug_verbose, "show more debug info in assembly output"}, - { 0, "--debug-ralloc", &pic16_ralloc_debug, "dump register allocator debug file *.d"}, - { 0, "--pcode-verbose", &pic16_pcode_verbose, "dump pcode related info"}, - { 0, "--calltree", &pic16_options.dumpcalltree, "dump call tree in .calltree file"}, - { 0, "--gstack", &pic16_options.gstack, "trace stack pointer push/pop to overflow"}, - { 0, NULL, NULL, NULL} + { 0, "--pno-banksel", &pic16_options.no_banksel, "do not generate BANKSEL assembler directives"}, + + /* optimization options */ + { 0, OPT_BANKSEL, &pic16_options.opt_banksel, "set banksel optimization level (default=0 no)", CLAT_INTEGER }, + { 0, "--denable-peeps", &pic16_enable_peeps, "explicit enable of peepholes"}, + { 0, OPTIMIZE_GOTO, NULL, "try to use (conditional) BRA instead of GOTO"}, + { 0, OPTIMIZE_CMP, NULL, "try to optimize some compares"}, + { 0, OPTIMIZE_DF, NULL, "thoroughly analyze data flow (memory and time intensive!)"}, + + /* assembling options */ + { 0, ALT_ASM, &alt_asm, "Use alternative assembler", CLAT_STRING}, + { 0, MPLAB_COMPAT, &pic16_mplab_comp, "enable compatibility mode for MPLAB utilities (MPASM/MPLINK)"}, + + /* linking options */ + { 0, ALT_LINK, &alt_link, "Use alternative linker", CLAT_STRING }, + { 0, REP_UDATA, &pic16_sectioninfo.at_udata, "Place udata variables at another section: udata_acs, udata_ovr, udata_shr", CLAT_STRING }, + { 0, IVT_LOC, NULL, "Set address of interrupt vector table."}, + { 0, NO_DEFLIBS, &pic16_options.nodefaultlibs, "do not link default libraries when linking"}, + { 0, USE_CRT, NULL, "use run-time initialization module"}, + { 0, "--no-crt", &pic16_options.no_crt, "do not link any default run-time initialization module"}, + + /* debugging options */ + { 0, "--debug-xtra", &pic16_debug_verbose, "show more debug info in assembly output"}, + { 0, "--debug-ralloc", &pic16_ralloc_debug, "dump register allocator debug file *.d"}, + { 0, "--pcode-verbose", &pic16_pcode_verbose, "dump pcode related info"}, + { 0, "--calltree", &pic16_options.dumpcalltree, "dump call tree in .calltree file"}, + { 0, "--gstack", &pic16_options.gstack, "trace stack pointer push/pop to overflow"}, + { 0, NULL, NULL, NULL} }; -#define ISOPT(str) !strncmp(argv[ *i ], str, strlen(str) ) +#define ISOPT(str) !strncmp(argv[ *i ], str, strlen(str) ) static bool _pic16_parseOptions (int *pargc, char **argv, int *i) { int j=0; char *stkmodel; - + /* TODO: allow port-specific command line options to specify * segment names here. */ - + /* check for arguments that have associated an integer variable */ while(pic16_optionsTable[j].pparameter) { if(ISOPT( pic16_optionsTable[j].longOpt )) { @@ -616,32 +616,12 @@ _pic16_parseOptions (int *pargc, char **argv, int *i) return TRUE; } - if(ISOPT(OPT_BANKSEL)) { - pic16_options.opt_banksel = getIntArg(OPT_BANKSEL, argv, i, *pargc); - return TRUE; - } - - if(ISOPT(REP_UDATA)) { - pic16_sectioninfo.at_udata = Safe_strdup(getStringArg(REP_UDATA, argv, i, *pargc)); - return TRUE; - } - - if(ISOPT(ALT_ASM)) { - alt_asm = Safe_strdup(getStringArg(ALT_ASM, argv, i, *pargc)); - return TRUE; - } - - if(ISOPT(ALT_LINK)) { - alt_link = Safe_strdup(getStringArg(ALT_LINK, argv, i, *pargc)); - return TRUE; - } - if(ISOPT(IVT_LOC)) { pic16_options.ivt_loc = getIntArg(IVT_LOC, argv, i, *pargc); fprintf(stderr, "%s:%d setting interrupt vector addresses 0x%x\n", __FILE__, __LINE__, pic16_options.ivt_loc); return TRUE; } - + if(ISOPT(USE_CRT)) { pic16_options.no_crt = 0; pic16_options.crt_name = Safe_strdup( getStringArg(USE_CRT, argv, i, *pargc) ); @@ -670,7 +650,7 @@ _pic16_parseOptions (int *pargc, char **argv, int *i) pic16_options.opt_flags |= OF_OPTIMIZE_DF; return TRUE; } - + return FALSE; } @@ -731,11 +711,11 @@ extern set *linkOptionsSet; char *msprintf(hTab *pvals, const char *pformat, ...); int my_system(const char *cmd); -/* forward declarations */ +/* forward declarations */ extern const char *pic16_linkCmd[]; extern const char *pic16_asmCmd[]; extern set *asmOptionsSet; - + /* custom function to link objects */ static void _pic16_linkEdit(void) { @@ -745,61 +725,61 @@ static void _pic16_linkEdit(void) char temp[1024]; set *tSet=NULL; int ret; - - /* - * link command format: - * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs} - * - */ - sprintf(lfrm, "{linker} {incdirs} {lflags} -w -r -o {outfile} {user_ofile} {ofiles} {spec_ofiles} {libs}"); - - shash_add(&linkValues, "linker", pic16_linkCmd[0]); - - mergeSets(&tSet, libDirsSet); - mergeSets(&tSet, libPathsSet); - - shash_add(&linkValues, "incdirs", joinStrSet( appendStrSet(tSet, "-I\"", "\""))); - shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet)); - - shash_add(&linkValues, "outfile", fullDstFileName ? fullDstFileName : dstFileName); - - if(fullSrcFileName) { - sprintf(temp, "%s.o", fullDstFileName ? fullDstFileName : dstFileName); -// addSetHead(&relFilesSet, Safe_strdup(temp)); + + /* + * link command format: + * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs} + * + */ + sprintf(lfrm, "{linker} {incdirs} {lflags} -w -r -o {outfile} {user_ofile} {ofiles} {spec_ofiles} {libs}"); + + shash_add(&linkValues, "linker", pic16_linkCmd[0]); + + mergeSets(&tSet, libDirsSet); + mergeSets(&tSet, libPathsSet); + + shash_add(&linkValues, "incdirs", joinStrSet( appendStrSet(tSet, "-I\"", "\""))); + shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet)); + + shash_add(&linkValues, "outfile", fullDstFileName ? fullDstFileName : dstFileName); + + if(fullSrcFileName) { + sprintf(temp, "%s.o", fullDstFileName ? fullDstFileName : dstFileName); +// addSetHead(&relFilesSet, Safe_strdup(temp)); shash_add(&linkValues, "user_ofile", temp); - } + } - if(!pic16_options.no_crt) + if(!pic16_options.no_crt) shash_add(&linkValues, "spec_ofiles", pic16_options.crt_name); - shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet)); + shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet)); + + if(!libflags.ignore) { + if(libflags.want_libc) + addSet(&libFilesSet, Safe_strdup("libc18f.lib")); - if(!libflags.ignore) { - if(libflags.want_libc) - addSet(&libFilesSet, Safe_strdup("libc18f.lib")); - if(libflags.want_libm) addSet(&libFilesSet, Safe_strdup("libm18f.lib")); - + if(libflags.want_libio) { - sprintf(temp, "libio%s.lib", pic16->name[1]); /* build libio18f452.lib name */ + sprintf(temp, "libio%s.lib", pic16->name[1]); /* build libio18f452.lib name */ addSet(&libFilesSet, Safe_strdup(temp)); } - + if(libflags.want_libdebug) addSet(&libFilesSet, Safe_strdup("libdebug.lib")); } - shash_add(&linkValues, "libs", joinStrSet(libFilesSet)); - - lcmd = msprintf(linkValues, lfrm); - - ret = my_system( lcmd ); - - Safe_free( lcmd ); - - if(ret) - exit(1); + shash_add(&linkValues, "libs", joinStrSet(libFilesSet)); + + lcmd = msprintf(linkValues, lfrm); + + ret = my_system( lcmd ); + + Safe_free( lcmd ); + + if(ret) + exit(1); } @@ -816,31 +796,31 @@ _pic16_finaliseOptions (void) if(pic16_enable_peeps) options.nopeep = 0; - options.all_callee_saves = 1; // always callee saves + options.all_callee_saves = 1; // always callee saves #if 0 options.float_rent = 1; options.intlong_rent = 1; #endif - + if(alt_asm && strlen(alt_asm)) pic16_asmCmd[0] = alt_asm; - + if(alt_link && strlen(alt_link)) pic16_linkCmd[0] = alt_link; - + if(!pic16_options.no_crt) { pic16_options.omit_ivt = 1; pic16_options.leave_reset = 0; } - + if(options.model == MODEL_SMALL) addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_SMALL")); else if(options.model == MODEL_LARGE) addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_LARGE")); - + { char buf[128]; @@ -848,7 +828,7 @@ _pic16_finaliseOptions (void) *(strrchr(buf, 'f')) = 'F'; addSet(&asmOptionsSet, Safe_strdup( buf )); } - + if(STACK_MODEL_LARGE) { addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_LARGE")); addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_LARGE")); @@ -874,20 +854,20 @@ _pic16_finaliseOptions (void) if (options.stack10bit) { if (options.model != MODEL_FLAT24) - { - fprintf (stderr, - "*** warning: 10 bit stack mode is only supported in flat24 model.\n"); - fprintf (stderr, "\t10 bit stack mode disabled.\n"); - options.stack10bit = 0; - } + { + fprintf (stderr, + "*** warning: 10 bit stack mode is only supported in flat24 model.\n"); + fprintf (stderr, "\t10 bit stack mode disabled.\n"); + options.stack10bit = 0; + } else - { - /* Fixup the memory map for the stack; it is now in - * far space and requires a FPOINTER to access it. - */ - istack->fmap = 1; - istack->ptrType = FPOINTER; - } + { + /* Fixup the memory map for the stack; it is now in + * far space and requires a FPOINTER to access it. + */ + istack->fmap = 1; + istack->ptrType = FPOINTER; + } } #endif @@ -895,12 +875,12 @@ _pic16_finaliseOptions (void) static void _pic16_setDefaultOptions (void) { - options.stackAuto = 0; /* implicit declaration */ - /* port is not capable yet to allocate separate registers + options.stackAuto = 0; /* implicit declaration */ + /* port is not capable yet to allocate separate registers * dedicated for passing certain parameters */ - + /* initialize to defaults section locations, names and addresses */ - pic16_sectioninfo.at_udata = "udata"; + pic16_sectioninfo.at_udata = "udata"; /* set pic16 port options to defaults */ pic16_options.no_banksel = 0; @@ -908,13 +888,13 @@ _pic16_setDefaultOptions (void) pic16_options.omit_configw = 0; pic16_options.omit_ivt = 0; pic16_options.leave_reset = 0; - pic16_options.stack_model = 0; /* 0 for 'small', 1 for 'large' */ + pic16_options.stack_model = 0; /* 0 for 'small', 1 for 'large' */ pic16_options.ivt_loc = 0x000000; pic16_options.nodefaultlibs = 0; pic16_options.dumpcalltree = 0; - pic16_options.crt_name = "crt0i.o"; /* the default crt to link */ - pic16_options.no_crt = 0; /* use crt by default */ - pic16_options.ip_stack = 1; /* set to 1 to enable ipop/ipush for stack */ + pic16_options.crt_name = "crt0i.o"; /* the default crt to link */ + pic16_options.no_crt = 0; /* use crt by default */ + pic16_options.ip_stack = 1; /* set to 1 to enable ipop/ipush for stack */ pic16_options.gstack = 0; pic16_options.debgen = 0; } @@ -931,7 +911,7 @@ _pic16_getRegName (struct regs *reg) #if 1 static char *_pic16_mangleFunctionName(char *sz) { -// fprintf(stderr, "mangled function name: %s\n", sz); +// fprintf(stderr, "mangled function name: %s\n", sz); return sz; } @@ -943,23 +923,23 @@ _pic16_genAssemblerPreamble (FILE * of) { char *name = pic16_processor_base_name(); - if(!name) { - name = "p18f452"; - fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name); - } - - fprintf (of, "\tlist\tp=%s\n",&name[1]); - if (pic16_mplab_comp) { - // provide ACCESS macro used during SFR accesses - fprintf (of, "\tinclude \n", &name[1]); - } - - if(!pic16_options.omit_configw) { - pic16_emitConfigRegs(of); - fprintf(of, "\n"); - pic16_emitIDRegs(of); - } - + if(!name) { + name = "p18f452"; + fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name); + } + + fprintf (of, "\tlist\tp=%s\n",&name[1]); + if (pic16_mplab_comp) { + // provide ACCESS macro used during SFR accesses + fprintf (of, "\tinclude \n", &name[1]); + } + + if(!pic16_options.omit_configw) { + pic16_emitConfigRegs(of); + fprintf(of, "\n"); + pic16_emitIDRegs(of); + } + fprintf (of, "\tradix dec\n"); } @@ -968,34 +948,34 @@ static int _pic16_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts) { #if 1 - /* PIC18F family has only two interrupts, the high and the low - * priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */ - - if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) { - dbuf_printf(oBuf, "; RESET vector\n"); - dbuf_printf(oBuf, "\tgoto\t__sdcc_gsinit_startup\n"); - } - - if(!pic16_options.omit_ivt) { - dbuf_printf(oBuf, "\tres 4\n"); - - - dbuf_printf(oBuf, "; High priority interrupt vector 0x0008\n"); - if(interrupts[1]) { - dbuf_printf(oBuf, "\tgoto\t%s\n", interrupts[1]->rname); - dbuf_printf(oBuf, "\tres\t12\n"); - } else { - dbuf_printf(oBuf, "\tretfie\n"); - dbuf_printf(oBuf, "\tres\t14\n"); - } - - dbuf_printf(oBuf, "; Low priority interrupt vector 0x0018\n"); - if(interrupts[2]) { - dbuf_printf(oBuf, "\tgoto\t%s\n", interrupts[2]->rname); - } else { - dbuf_printf(oBuf, "\tretfie\n"); - } - } + /* PIC18F family has only two interrupts, the high and the low + * priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */ + + if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) { + dbuf_printf(oBuf, "; RESET vector\n"); + dbuf_printf(oBuf, "\tgoto\t__sdcc_gsinit_startup\n"); + } + + if(!pic16_options.omit_ivt) { + dbuf_printf(oBuf, "\tres 4\n"); + + + dbuf_printf(oBuf, "; High priority interrupt vector 0x0008\n"); + if(interrupts[1]) { + dbuf_printf(oBuf, "\tgoto\t%s\n", interrupts[1]->rname); + dbuf_printf(oBuf, "\tres\t12\n"); + } else { + dbuf_printf(oBuf, "\tretfie\n"); + dbuf_printf(oBuf, "\tres\t14\n"); + } + + dbuf_printf(oBuf, "; Low priority interrupt vector 0x0018\n"); + if(interrupts[2]) { + dbuf_printf(oBuf, "\tgoto\t%s\n", interrupts[2]->rname); + } else { + dbuf_printf(oBuf, "\tretfie\n"); + } + } #endif return TRUE; } @@ -1055,9 +1035,9 @@ static bool _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right) //printf( "%s: val(left) = %ld\n", __FUNCTION__, l ); if (l >= -128 && l < 256) { - sizeL = 1; + sizeL = 1; } else { - //printf( "%s: left value %ld outside [-128..256)\n", __FUNCTION__, l ); + //printf( "%s: left value %ld outside [-128..256)\n", __FUNCTION__, l ); } } if (IS_VALOP( IC_RIGHT(ic) )) @@ -1067,9 +1047,9 @@ static bool _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right) //printf( "%s: val(right) = %ld\n", __FUNCTION__, l ); if (l >= -128 && l < 256) { - sizeR = 1; + sizeR = 1; } else { - //printf( "%s: right value %ld outside [-128..256)\n", __FUNCTION__, l ); + //printf( "%s: right value %ld outside [-128..256)\n", __FUNCTION__, l ); } } @@ -1092,9 +1072,9 @@ static bool _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right) //printf( "%s: val(left) = %ld\n", __FUNCTION__, l ); if (l >= -128 && l < 256) { - sizeL = 1; + sizeL = 1; } else { - //printf( "%s: left value %ld outside [-128..256)\n", __FUNCTION__, l ); + //printf( "%s: left value %ld outside [-128..256)\n", __FUNCTION__, l ); } } if (IS_VALOP( IC_RIGHT(ic) )) @@ -1104,9 +1084,9 @@ static bool _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right) //printf( "%s: val(right) = %ld\n", __FUNCTION__, l ); if (l >= -128 && l < 256) { - sizeR = 1; + sizeR = 1; } else { - //printf( "%s: right value %ld outside [-128..256)\n", __FUNCTION__, l ); + //printf( "%s: right value %ld outside [-128..256)\n", __FUNCTION__, l ); } } if (sizeL == 1 && sizeR == 1) { return TRUE; } @@ -1124,16 +1104,16 @@ static bool cseCostEstimation (iCode *ic, iCode *pdic) // sym_link *result_type = operandType(result); - /* VR -- this is an adhoc. Put here after conversation - * with Erik Epetrich */ + /* VR -- this is an adhoc. Put here after conversation + * with Erik Epetrich */ - if(ic->op == '<' - || ic->op == '>' - || ic->op == EQ_OP) { + if(ic->op == '<' + || ic->op == '>' + || ic->op == EQ_OP) { - fprintf(stderr, "%d %s\n", __LINE__, __FUNCTION__); - return 0; - } + fprintf(stderr, "%d %s\n", __LINE__, __FUNCTION__); + return 0; + } #if 0 /* if it is a pointer then return ok for now */ @@ -1177,11 +1157,11 @@ oclsExpense (struct memmap *oclass) /* free to remove this test -- EEP */ if (IN_FARSPACE(oclass)) return 1; - + return 0; } -/** $1 is the input object file (PIC16 specific) // >>always the basename<<. +/** $1 is the input object file (PIC16 specific) // >>always the basename<<. $2 is always the output file. $3 -L path and -l libraries $l is the list of extra options that should be there somewhere... @@ -1211,91 +1191,91 @@ PORT pic16_port = { TARGET_ID_PIC16, "pic16", - "MCU PIC16", /* Target name */ - "p18f452", /* Processor */ + "MCU PIC16", /* Target name */ + "p18f452", /* Processor */ { pic16glue, - TRUE, /* Emit glue around main */ + TRUE, /* Emit glue around main */ MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24, MODEL_SMALL }, { - pic16_asmCmd, /* assembler command and arguments */ - NULL, /* alternate macro based form */ - "-g", /* arguments for debug mode */ - NULL, /* arguments for normal mode */ - 0, /* print externs as global */ - ".asm", /* assembler file extension */ - NULL /* no do_assemble function */ + pic16_asmCmd, /* assembler command and arguments */ + NULL, /* alternate macro based form */ + "-g", /* arguments for debug mode */ + NULL, /* arguments for normal mode */ + 0, /* print externs as global */ + ".asm", /* assembler file extension */ + NULL /* no do_assemble function */ }, { - NULL, // pic16_linkCmd, /* linker command and arguments */ - NULL, /* alternate macro based form */ - _pic16_linkEdit, //NULL, /* no do_link function */ - ".o", /* extension for object files */ - 0 /* no need for linker file */ + NULL, // pic16_linkCmd, /* linker command and arguments */ + NULL, /* alternate macro based form */ + _pic16_linkEdit, //NULL, /* no do_link function */ + ".o", /* extension for object files */ + 0 /* no need for linker file */ }, { _defaultRules }, { - /* Sizes */ - 1, /* char */ - 2, /* short */ - 2, /* int */ - 4, /* long */ - 2, /* ptr */ - 3, /* fptr, far pointers (see Microchip) */ - 3, /* gptr */ - 1, /* bit */ - 4, /* float */ - 4 /* max */ + /* Sizes */ + 1, /* char */ + 2, /* short */ + 2, /* int */ + 4, /* long */ + 2, /* ptr */ + 3, /* fptr, far pointers (see Microchip) */ + 3, /* gptr */ + 1, /* bit */ + 4, /* float */ + 4 /* max */ }, /* generic pointer tags */ { - 0x00, /* far */ - 0x80, /* near */ - 0x00, /* xstack */ - 0x00 /* code */ + 0x00, /* far */ + 0x80, /* near */ + 0x00, /* xstack */ + 0x00 /* code */ }, - + { - "XSEG (XDATA)", // xstack - "STACK (DATA)", // istack - "CSEG (CODE)", // code - "DSEG (DATA)", // data - "ISEG (DATA)", // idata - "PSEG (DATA)", // pdata - "XSEG (XDATA)", // xdata - "BSEG (BIT)", // bit - "RSEG (DATA)", // reg - "GSINIT (CODE)", // static - "OSEG (OVR,DATA)", // overlay - "GSFINAL (CODE)", // post static - "HOME (CODE)", // home - NULL, // xidata - NULL, // xinit - "CONST (CODE)", // const_name - const data (code or not) - "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not) - "XABS (ABS,XDATA)", // xabs_name - absolute xdata - "IABS (ABS,DATA)", // iabs_name - absolute data - NULL, // default location for auto vars - NULL, // default location for global vars - 1 // code is read only 1=yes + "XSEG (XDATA)", // xstack + "STACK (DATA)", // istack + "CSEG (CODE)", // code + "DSEG (DATA)", // data + "ISEG (DATA)", // idata + "PSEG (DATA)", // pdata + "XSEG (XDATA)", // xdata + "BSEG (BIT)", // bit + "RSEG (DATA)", // reg + "GSINIT (CODE)", // static + "OSEG (OVR,DATA)", // overlay + "GSFINAL (CODE)", // post static + "HOME (CODE)", // home + NULL, // xidata + NULL, // xinit + "CONST (CODE)", // const_name - const data (code or not) + "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not) + "XABS (ABS,XDATA)", // xabs_name - absolute xdata + "IABS (ABS,DATA)", // iabs_name - absolute data + NULL, // default location for auto vars + NULL, // default location for global vars + 1 // code is read only 1=yes }, { - NULL, /* genExtraAreaDeclaration */ - NULL /* genExatrAreaLinkOptions */ + NULL, /* genExtraAreaDeclaration */ + NULL /* genExatrAreaLinkOptions */ }, { - /* stack related information */ - -1, /* -1 stack grows downwards, +1 upwards */ - 1, /* extra overhead when calling between banks */ - 4, /* extra overhead when the function is an ISR */ - 1, /* extra overhead for a function call */ - 1, /* re-entrant space */ - 0 /* 'banked' call overhead, mild overlap with bank_overhead */ + /* stack related information */ + -1, /* -1 stack grows downwards, +1 upwards */ + 1, /* extra overhead when calling between banks */ + 4, /* extra overhead when the function is an ISR */ + 1, /* extra overhead for a function call */ + 1, /* re-entrant space */ + 0 /* 'banked' call overhead, mild overlap with bank_overhead */ }, /* pic16 has an 8 bit mul */ { @@ -1325,30 +1305,30 @@ PORT pic16_port = _pic16_getRegName, _pic16_keywords, _pic16_genAssemblerPreamble, - NULL, /* no genAssemblerEnd */ + NULL, /* no genAssemblerEnd */ _pic16_genIVT, NULL, // _pic16_genXINIT - NULL, /* genInitStartup */ + NULL, /* genInitStartup */ _pic16_reset_regparm, _pic16_regparm, - _process_pragma, /* process a pragma */ - _pic16_mangleFunctionName, /* mangles function name */ + _process_pragma, /* process a pragma */ + _pic16_mangleFunctionName, /* mangles function name */ _hasNativeMulFor, - hasExtBitOp, /* hasExtBitOp */ - oclsExpense, /* oclsExpense */ - FALSE, - TRUE, /* little endian */ - 0, /* leave lt */ - 0, /* leave gt */ - 1, /* transform <= to ! > */ - 1, /* transform >= to ! < */ - 1, /* transform != to !(a == b) */ - 0, /* leave == */ - FALSE, /* No array initializer support. */ - 0, //cseCostEstimation, /* !!!no CSE cost estimation yet */ - NULL, /* no builtin functions */ - GPOINTER, /* treat unqualified pointers as "generic" pointers */ - 1, /* reset labelKey to 1 */ - 1, /* globals & local static allowed */ + hasExtBitOp, /* hasExtBitOp */ + oclsExpense, /* oclsExpense */ + FALSE, + TRUE, /* little endian */ + 0, /* leave lt */ + 0, /* leave gt */ + 1, /* transform <= to ! > */ + 1, /* transform >= to ! < */ + 1, /* transform != to !(a == b) */ + 0, /* leave == */ + FALSE, /* No array initializer support. */ + 0, //cseCostEstimation, /* !!!no CSE cost estimation yet */ + NULL, /* no builtin functions */ + GPOINTER, /* treat unqualified pointers as "generic" pointers */ + 1, /* reset labelKey to 1 */ + 1, /* globals & local static allowed */ PORT_MAGIC }; diff --git a/src/z80/main.c b/src/z80/main.c index 23089afe..dbd02319 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -59,8 +59,8 @@ static OPTION _z80_options[] = { 0, OPTION_CALLEE_SAVES_BC, &z80_opts.calleeSavesBC, "Force a called function to always save BC" }, { 0, OPTION_PORTMODE, NULL, "Determine PORT I/O mode (z80/z180)" }, { 0, OPTION_ASM, NULL, "Define assembler name (rgbds/asxxxx/isas/z80asm)" }, - { 0, OPTION_CODE_SEG, NULL, " use this name for the code segment" }, - { 0, OPTION_CONST_SEG, NULL, " use this name for the const segment" }, + { 0, OPTION_CODE_SEG, &options.code_seg, " use this name for the code segment", CLAT_STRING }, + { 0, OPTION_CONST_SEG, &options.const_seg, " use this name for the const segment", CLAT_STRING }, { 0, OPTION_NO_STD_CRT0, &options.no_std_crt0, "For the z80/gbz80 do not link default crt0.o"}, { 0, NULL } }; @@ -70,8 +70,8 @@ static OPTION _gbz80_options[] = { 0, OPTION_BO, NULL, " use code bank " }, { 0, OPTION_BA, NULL, " use data bank " }, { 0, OPTION_CALLEE_SAVES_BC, &z80_opts.calleeSavesBC, "Force a called function to always save BC" }, - { 0, OPTION_CODE_SEG, NULL, " use this name for the code segment" }, - { 0, OPTION_CONST_SEG, NULL, " use this name for the const segment" }, + { 0, OPTION_CODE_SEG, &options.code_seg, " use this name for the code segment", CLAT_STRING }, + { 0, OPTION_CONST_SEG, &options.const_seg, " use this name for the const segment", CLAT_STRING }, { 0, OPTION_NO_STD_CRT0, &options.no_std_crt0, "For the z80/gbz80 do not link default crt0.o"}, { 0, NULL } }; @@ -463,18 +463,6 @@ _parseOptions (int *pargc, char **argv, int *i) return TRUE; } } - else if (!strcmp (argv[*i], OPTION_CODE_SEG)) - { - if (options.code_seg) Safe_free(options.code_seg); - options.code_seg = Safe_strdup(getStringArg (OPTION_CODE_SEG, argv, i, *pargc)); - return TRUE; - } - else if (!strcmp (argv[*i], OPTION_CONST_SEG)) - { - if (options.const_seg) Safe_free(options.const_seg); - options.const_seg = Safe_strdup(getStringArg (OPTION_CONST_SEG, argv, i, *pargc)); - return TRUE; - } } return FALSE; } diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index a6b4cf6f..eb69d38d 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -440,6 +440,8 @@ struct "Only pointers may be qualified with 'restrict'" }, { E_BAD_INLINE, ERROR_LEVEL_ERROR, "Only functions may be qualified with 'inline'" }, +{ E_BAD_INT_ARGUMENT, ERROR_LEVEL_ERROR, + "Bad integer argument for option %s." }, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index 40e71b95..3fcbdc8d 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -209,6 +209,7 @@ SDCCERR - SDCC Standard error handler #define W_BAD_PRAGMA_ARGUMENTS 191 /* #pragma %s: bad argument(s); pragma ignored */ #define E_BAD_RESTRICT 192 /* Only pointers may be qualified with 'restrict' */ #define E_BAD_INLINE 193 /* Only functions may be qualified with 'inline' */ +#define E_BAD_INT_ARGUMENT 194 /* Bad integer option argument. */ #define MAX_ERROR_WARNING 256 /* size of disable warnings array */ /** Describes the maximum error level that will be logged. Any level -- 2.30.2