-char *preOutName;
-
-/* Far functions, far data */
-#define OPTION_LARGE_MODEL "-model-large"
-/* Far functions, near data */
-#define OPTION_MEDIUM_MODEL "-model-medium"
-#define OPTION_SMALL_MODEL "-model-small"
-#define OPTION_FLAT24_MODEL "-model-flat24"
-#define OPTION_STACK_AUTO "-stack-auto"
-#define OPTION_STACK_10BIT "-stack-10bit"
-#define OPTION_XSTACK "-xstack"
-#define OPTION_GENERIC "-generic"
-#define OPTION_NO_GCSE "-nogcse"
-#define OPTION_NO_LOOP_INV "-noinvariant"
-#define OPTION_NO_LOOP_IND "-noinduction"
-#define OPTION_NO_JTBOUND "-nojtbound"
-#define OPTION_NO_LOOPREV "-noloopreverse"
-#define OPTION_XREGS "-regextend"
-#define OPTION_COMP_ONLY "-compile-only"
-#define OPTION_DUMP_RAW "-dumpraw"
-#define OPTION_DUMP_GCSE "-dumpgcse"
-#define OPTION_DUMP_LOOP "-dumploop"
-#define OPTION_DUMP_KILL "-dumpdeadcode"
-#define OPTION_DUMP_RANGE "-dumpliverange"
-#define OPTION_DUMP_PACK "-dumpregpack"
-#define OPTION_DUMP_RASSGN "-dumpregassign"
-#define OPTION_DUMP_ALL "-dumpall"
-#define OPTION_XRAM_LOC "-xram-loc"
-#define OPTION_IRAM_SIZE "-iram-size"
-#define OPTION_XSTACK_LOC "-xstack-loc"
-#define OPTION_CODE_LOC "-code-loc"
-#define OPTION_STACK_LOC "-stack-loc"
-#define OPTION_DATA_LOC "-data-loc"
-#define OPTION_IDATA_LOC "-idata-loc"
-#define OPTION_PEEP_FILE "-peep-file"
-#define OPTION_LIB_PATH "-lib-path"
-#define OPTION_INTLONG_RENT "-int-long-reent"
-#define OPTION_FLOAT_RENT "-float-reent"
-#define OPTION_OUT_FMT_IHX "-out-fmt-ihx"
-#define OPTION_OUT_FMT_S19 "-out-fmt-s19"
-#define OPTION_CYCLOMATIC "-cyclomatic"
-#define OPTION_NOOVERLAY "-nooverlay"
-#define OPTION_MAINRETURN "-main-return"
-#define OPTION_NOPEEP "-no-peep"
-#define OPTION_ASMPEEP "-peep-asm"
-#define OPTION_DEBUG "-debug"
-#define OPTION_NODEBUG "-nodebug"
-#define OPTION_VERSION "-version"
-#define OPTION_STKAFTRDATA "-stack-after-data"
-#define OPTION_PREPROC_ONLY "-preprocessonly"
-#define OPTION_C1_MODE "-c1mode"
-#define OPTION_HELP "-help"
-#define OPTION_CALLEE_SAVES "-callee-saves"
-#define OPTION_NOREGPARMS "-noregparms"
-#define OPTION_NOSTDLIB "-nostdlib"
-#define OPTION_NOSTDINC "-nostdinc"
-#define OPTION_VERBOSE "-verbose"
-static const char *_preCmd[] = {
- "sdcpp", "-Wall", "-lang-c++", "-DSDCC=1",
- "$l", "-I" SDCC_INCLUDE_DIR, "$1", "$2", NULL
+char *preOutName;
+bool noXinitOpt = FALSE;
+
+/* uncomment JAMIN_DS390 to always override and use ds390 port
+ for mcs51 work. This is temporary, for compatibility testing. */
+/* #define JAMIN_DS390 */
+#ifdef JAMIN_DS390
+int ds390_jammed = 0;
+#endif
+
+// Globally accessible scratch buffer for file names.
+char scratchFileName[PATH_MAX];
+char buffer[PATH_MAX];
+
+// In MSC VC6 default search path for exe's to path for this
+
+char DefaultExePath[128];
+
+#define OPTION_HELP "-help"
+
+#define LENGTH(_a) (sizeof(_a)/sizeof(*(_a)))
+
+#define OPTION_STACK_8BIT "--stack-8bit"
+#define OPTION_OUT_FMT_IHX "--out-fmt-ihx"
+#define OPTION_LARGE_MODEL "--model-large"
+#define OPTION_MEDIUM_MODEL "--model-medium"
+#define OPTION_SMALL_MODEL "--model-small"
+#define OPTION_FLAT24_MODEL "--model-flat24"
+#define OPTION_DUMP_ALL "--dumpall"
+#define OPTION_PEEP_FILE "--peep-file"
+#define OPTION_LIB_PATH "--lib-path"
+#define OPTION_XSTACK_LOC "--xstack-loc"
+#define OPTION_CALLEE_SAVES "--callee-saves"
+#define OPTION_STACK_LOC "--stack-loc"
+#define OPTION_XRAM_LOC "--xram-loc"
+#define OPTION_IRAM_SIZE "--iram-size"
+#define OPTION_VERSION "--version"
+#define OPTION_DATA_LOC "--data-loc"
+#define OPTION_CODE_LOC "--code-loc"
+#define OPTION_IDATA_LOC "--idata-loc"
+#define OPTION_NO_LOOP_INV "--noinvariant"
+#define OPTION_NO_LOOP_IND "--noinduction"
+#define OPTION_LESS_PEDANTIC "--lesspedantic"
+#define OPTION_NO_GCSE "--nogcse"
+#define OPTION_SHORT_IS_8BITS "--short-is-8bits"
+#define OPTION_TINI_LIBID "--tini-libid"
+#define OPTION_NO_XINIT_OPT "--no-xinit-opt"
+#define OPTION_XRAM_SIZE "--xram-size"
+#define OPTION_CODE_SIZE "--code-size"
+
+static const OPTION
+optionsTable[] = {
+ { 'm', NULL, NULL, "Set the port to use e.g. -mz80." },
+ { 'p', NULL, NULL, "Select port specific processor e.g. -mpic14 -p16f84" },
+ { 'd', NULL, NULL, NULL },
+ { 'D', NULL, NULL, "Define macro as in -Dmacro" },
+ { '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" },
+ { 'V', NULL, &verboseExec, "Execute verbosely. Show sub commands as they are run" },
+ { 'S', NULL, &noAssemble, "Compile only; do not assemble or link" },
+ { 'W', NULL, NULL, "Pass through options to the pre-processor (p), assembler (a) or linker (l)" },
+ { 'L', NULL, NULL, "Add the next field to the library search path" },
+ { '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, "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, OPTION_NO_GCSE, NULL, "Disable the GCSE optimisation" },
+ { 0, OPTION_NO_LOOP_INV, NULL, "Disable optimisation of invariants" },
+ { 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 and assemble, but do not link" },
+ { 'o', NULL, NULL, "Place the output into the given path resp. file" },
+ { 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 },
+ { 0, "--dumpdeadcode", &options.dump_kill, NULL },
+ { 0, "--dumpliverange", &options.dump_range, NULL },
+ { 0, "--dumpregpack", &options.dump_pack, NULL },
+ { 0, "--dumpregassign", &options.dump_rassgn, NULL },
+ { 0, "--dumptree", &options.dump_tree, "dump front-end AST before generating iCode" },
+ { 0, OPTION_DUMP_ALL, NULL, "Dump the internal structure at all stages" },
+ { 0, OPTION_XRAM_LOC, NULL, "<nnnn> External Ram start location" },
+ { 0, OPTION_XRAM_SIZE, NULL, "<nnnn> External Ram size" },
+ { 0, OPTION_IRAM_SIZE, NULL, "<nnnn> Internal Ram size" },
+ { 0, OPTION_XSTACK_LOC, NULL, "<nnnn> External Ram start location" },
+ { 0, OPTION_CODE_LOC, NULL, "<nnnn> Code Segment Location" },
+ { 0, OPTION_CODE_SIZE, NULL, "<nnnn> Code Segment size" },
+ { 0, OPTION_STACK_LOC, NULL, "<nnnn> Stack pointer initial value" },
+ { 0, OPTION_DATA_LOC, NULL, "<nnnn> Direct data start location" },
+ { 0, OPTION_IDATA_LOC, NULL, NULL },
+ { 0, OPTION_PEEP_FILE, NULL, "<file> use this extra peep-hole file" },
+ { 0, OPTION_LIB_PATH, NULL, "<path> 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 },
+ { 0, "--out-fmt-s19", &options.out_fmt, NULL },
+ { 0, "--cyclomatic", &options.cyclomatic, NULL },
+ { 0, "--nooverlay", &options.noOverlay, NULL },
+ { 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, "--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" },
+ { '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, "<func[,func,...]> 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, "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, "--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" },
+ { 0, "--use-accelerator", &options.useAccelerator,"generate code for DS390 Arithmetic Accelerator"},
+ { 0, "--stack-probe", &options.stack_probe,"insert call to function __stack_probe at each function prologue"},
+ { 0, "--tini-libid", NULL,"<nnnn> LibraryID used in -mTININative"},
+ { 0, "--protect-sp-update", &options.protect_sp_update,"DS390 - will disable interrupts during ESP:SP updates"},
+ { 0, "--parms-in-bank1", &options.parms_in_bank1,"MCS51/DS390 - use Bank1 for parameter passing"},
+ { 0, OPTION_NO_XINIT_OPT, &noXinitOpt, "don't memcpy initialized xram from code"},
+ /* End of options */
+ { 0, NULL }
+};
+
+/** Table of all unsupported options and help text to display when one
+ is used.
+*/
+typedef struct {
+ /** shortOpt as in OPTIONS. */
+ char shortOpt;
+ /** longOpt as in OPTIONS. */
+ const char *longOpt;
+ /** Message to display inside W_UNSUPPORTED_OPT when this option
+ is used. */
+ const char *message;
+} UNSUPPORTEDOPT;
+
+static const UNSUPPORTEDOPT
+unsupportedOptTable[] = {
+ { 'X', NULL, "use --xstack-loc instead" },
+ { 'x', NULL, "use --xstack instead" },
+ { 'i', NULL, "use --idata-loc instead" },
+ { 'r', NULL, "use --xdata-loc instead" },
+ { 's', NULL, "use --code-loc instead" },
+ { 'Y', NULL, "use -I instead" }
+};
+
+/** List of all default constant macros.
+ */
+static const char *_baseValues[] = {
+ "cpp", "{bindir}{sep}sdcpp",
+ "cppextraopts", "",
+ /* Path seperator character */
+ "sep", DIR_SEPARATOR_STRING,
+ NULL