Implemented -c support for --gas
STM8 code generator was generating some instructions in a "ld register, (#%d, register)" way, causing assembling errors on stm8-as. This is because stm8-as does not require the '#' character. A quick and dirty workaround has been implemented for this. Added new warning W_IGNORED_OPT_IN_ASM, which warns the user when both "--no-optsdcc-in-asm" and "--gas" are used (the first is ignored when the latter is active since GNU as does not accept the .optsdcc directive, as opposed to asxxx).
This commit is contained in:
parent
4df948b3c1
commit
9c47d08e98
|
@ -37,14 +37,14 @@
|
|||
#define DEFAULT_ERROR_OUT stderr
|
||||
#endif
|
||||
|
||||
struct SDCCERRG _SDCCERRG;
|
||||
struct SDCCERRG _SDCCERRG;
|
||||
|
||||
extern char *filename;
|
||||
extern int lineno;
|
||||
extern int fatalError;
|
||||
|
||||
/* Currently the errIndex field must match the position of the
|
||||
* entry in the array. It is only included in order to make
|
||||
/* Currently the errIndex field must match the position of the
|
||||
* entry in the array. It is only included in order to make
|
||||
* human error lookup easier.
|
||||
*/
|
||||
struct
|
||||
|
@ -561,6 +561,8 @@ struct
|
|||
"invalid value for __z88dk_shortcall %s parameter: %x", 0},
|
||||
{ E_DUPLICATE_PARAMTER_NAME, ERROR_LEVEL_ERROR,
|
||||
"duplicate parameter name %s for function %s", 0},
|
||||
{W_IGNORED_OPT_IN_ASM, ERROR_LEVEL_WARNING,
|
||||
"no optsdcc in assembly file configuration is ignored when using GNU as format output"}
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------------
|
||||
|
|
|
@ -276,6 +276,7 @@ enum {
|
|||
E_DECL_AFTER_STATEMENT_C99 = 247, /* declaration after statement requires ISO C99 or later */
|
||||
E_SHORTCALL_INVALID_VALUE = 248, /* Invalid value for a __z88dk_shortcall specifier */
|
||||
E_DUPLICATE_PARAMTER_NAME = 249, /* duplicate parameter name */
|
||||
W_IGNORED_OPT_IN_ASM = 250, /* Ignored OPTION_NO_OPTSDCC_IN_ASM when GNU assembler output is used */
|
||||
|
||||
/* don't touch this! */
|
||||
NUMBER_OF_ERROR_MESSAGES /* Number of error messages */
|
||||
|
|
|
@ -2357,8 +2357,10 @@ glue (void)
|
|||
tfprintf (asmFile, "\t!module\n", moduleName);
|
||||
if (mcs51_like)
|
||||
{
|
||||
if(!options.noOptsdccInAsm)
|
||||
if(!options.noOptsdccInAsm && !options.gasOutput)
|
||||
fprintf (asmFile, "\t.optsdcc -m%s", port->target);
|
||||
else if (options.gasOutput && options.noOptsdccInAsm)
|
||||
werror(W_IGNORED_OPT_IN_ASM);
|
||||
|
||||
switch (options.model)
|
||||
{
|
||||
|
@ -2398,8 +2400,11 @@ glue (void)
|
|||
}
|
||||
else if (!TARGET_PIC_LIKE && !options.noOptsdccInAsm)
|
||||
{
|
||||
fprintf (asmFile, "\t.optsdcc -m%s\n", port->target);
|
||||
if(!options.gasOutput)
|
||||
fprintf (asmFile, "\t.optsdcc -m%s", port->target);
|
||||
}
|
||||
else if (options.noOptsdccInAsm && options.gasOutput)
|
||||
werror(W_IGNORED_OPT_IN_ASM);
|
||||
|
||||
tfprintf (asmFile, "\t!fileprelude\n");
|
||||
|
||||
|
|
|
@ -1512,7 +1512,7 @@ parseCmdLine (int argc, char **argv)
|
|||
deleteSet (&relFilesSet);
|
||||
deleteSet (&libFilesSet);
|
||||
|
||||
if (options.cc_only || noAssemble || preProcOnly || options.gasOutput)
|
||||
if (options.cc_only || noAssemble || preProcOnly)
|
||||
{
|
||||
werror (W_ILLEGAL_OPT_COMBINATION);
|
||||
}
|
||||
|
@ -1956,8 +1956,11 @@ assemble (char **envp)
|
|||
}
|
||||
else
|
||||
{
|
||||
const char *const ext = options.gasOutput ?
|
||||
port->linker.o_ext
|
||||
: port->linker.rel_ext;
|
||||
/* the assembled file gets the name of the first module */
|
||||
dbuf_printf (&asmName, "%s%s", dstFileName, port->linker.rel_ext);
|
||||
dbuf_printf (&asmName, "%s%s", dstFileName, ext);
|
||||
}
|
||||
|
||||
if (port->assembler.cmd)
|
||||
|
@ -1966,8 +1969,8 @@ assemble (char **envp)
|
|||
char *dfn = shell_escape (dstFileName);
|
||||
char *asmn = shell_escape (dbuf_c_str (&asmName));
|
||||
|
||||
buf = buildCmdLine (port->assembler.cmd, dfn, asmn,
|
||||
options.debug ? port->assembler.debug_opts : port->assembler.plain_opts, asmOptionsSet);
|
||||
buf = buildCmdLine (options.gasOutput ? port->assembler.binutils_cmd : port->assembler.cmd,
|
||||
dfn, asmn, options.debug ? port->assembler.debug_opts : port->assembler.plain_opts, asmOptionsSet);
|
||||
Safe_free (dfn);
|
||||
Safe_free (asmn);
|
||||
}
|
||||
|
@ -2684,7 +2687,7 @@ main (int argc, char **argv, char **envp)
|
|||
if (fatalError)
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
if (!options.c1mode && !noAssemble && !options.gasOutput)
|
||||
if (!options.c1mode && !noAssemble)
|
||||
{
|
||||
if (options.verbose)
|
||||
printf ("sdcc: Calling assembler...\n");
|
||||
|
@ -2696,7 +2699,7 @@ main (int argc, char **argv, char **envp)
|
|||
if (options.debug && debugFile)
|
||||
debugFile->closeFile ();
|
||||
|
||||
if (!options.cc_only && !fatalError && !noAssemble && !options.gasOutput && !options.c1mode && (fullSrcFileName || peekSet (relFilesSet) != NULL))
|
||||
if (!options.cc_only && !fatalError && !noAssemble && !options.c1mode && (fullSrcFileName || peekSet (relFilesSet) != NULL))
|
||||
{
|
||||
if (options.verbose)
|
||||
printf ("sdcc: Calling linker...\n");
|
||||
|
|
|
@ -3561,7 +3561,7 @@ genReturn (const iCode *ic)
|
|||
for(i = 0; i < size; i++)
|
||||
if (aopInReg (left->aop, i, A_IDX))
|
||||
{
|
||||
emit2 ("ld", "(#%d, x), a", size - 1 - i);
|
||||
emit2 ("ld", options.gasOutput ? "(%d, x), a" : "(#%d, x), a", size - 1 - i);
|
||||
cost (2, 1);
|
||||
break;
|
||||
}
|
||||
|
@ -3573,7 +3573,7 @@ genReturn (const iCode *ic)
|
|||
genMove_o (ASMOP_Y, 0, left->aop, i, 2, TRUE, FALSE, TRUE);
|
||||
if (size - 2 - i)
|
||||
{
|
||||
emit2 ("ldw", "(#%d, x), y", size - 2 - i);
|
||||
emit2 ("ldw", options.gasOutput ? "(%d, x), y" : "(#%d, x), y", size - 2 - i);
|
||||
cost (2, 2);
|
||||
}
|
||||
else
|
||||
|
@ -3585,8 +3585,9 @@ genReturn (const iCode *ic)
|
|||
}
|
||||
else if (aopInReg (left->aop, i, XL_IDX) || aopInReg (left->aop, i, XH_IDX))
|
||||
{
|
||||
emit2 ("ld", "a, (#%d, sp)", (int)(aopInReg (left->aop, i, XL_IDX)) + 1);
|
||||
emit2 ("ld", "(#%d, x), a", size - 1 - i);
|
||||
emit2 ("ld", options.gasOutput ? "a, (%d, sp)" : "a, (#%d, sp)",
|
||||
(int)(aopInReg (left->aop, i, XL_IDX)) + 1);
|
||||
emit2 ("ld", options.gasOutput ? "(%d, x), a" : "(#%d, x), a", size - 1 - i);
|
||||
cost (4, 2);
|
||||
i++;
|
||||
}
|
||||
|
@ -3595,7 +3596,7 @@ genReturn (const iCode *ic)
|
|||
cheapMove (ASMOP_A, 0, left->aop, i, FALSE);
|
||||
if (size - 1 - i)
|
||||
{
|
||||
emit2 ("ld", "(#%d, x), a", size - 1 - i);
|
||||
emit2 ("ld", options.gasOutput ? "(%d, x), a" : "(#%d, x), a", size - 1 - i);
|
||||
cost (2, 1);
|
||||
}
|
||||
else
|
||||
|
@ -7651,7 +7652,13 @@ genJumpTab (const iCode *ic)
|
|||
for (jtab = setFirstItem (IC_JTLABELS (ic)); jtab; jtab = setNextItem (IC_JTLABELS (ic)))
|
||||
{
|
||||
if (!regalloc_dry_run)
|
||||
emit2 (".dw", "#!tlabel", labelKey2num (jtab->key));
|
||||
{
|
||||
struct dbuf_s b;
|
||||
|
||||
dbuf_init(&b, 1024);
|
||||
/* emit2 (".dw", "#!tlabel", labelKey2num (jtab->key)); */
|
||||
emit2 ("", "!dw %d", labelKey2num (jtab->key));
|
||||
}
|
||||
cost (2, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -285,8 +285,7 @@ stm8_genInitStartup (FILE *of)
|
|||
"\tincw x\n"
|
||||
"\tcpw x, __bss_end\n"
|
||||
"\tjrne 0$\n"
|
||||
"\t; Copying .data from ROM to RAM\n"
|
||||
"\t; Calculate .data section size\n"
|
||||
"\t; Transfer .data from ROM to RAM\n"
|
||||
"\tldw x, __data_load_start\n"
|
||||
"\tldw y, __data_start\n"
|
||||
"1$:\n"
|
||||
|
@ -427,6 +426,11 @@ static const char *stm8AsmCmd[] =
|
|||
"sdasstm8", "$l", "$3", "\"$1.asm\"", NULL
|
||||
};
|
||||
|
||||
static const char *stm8AsmGNUCmd[] =
|
||||
{
|
||||
"stm8-as", "\"$1.asm\"", "-o", "\"$1.o\"", NULL
|
||||
};
|
||||
|
||||
static const char *const _libs_stm8[] = { "stm8", NULL, };
|
||||
|
||||
PORT stm8_port =
|
||||
|
@ -448,7 +452,9 @@ PORT stm8_port =
|
|||
"-plosgffwy", /* Options with debug */
|
||||
"-plosgffw", /* Options without debug */
|
||||
0,
|
||||
".asm"
|
||||
".asm",
|
||||
NULL,
|
||||
stm8AsmGNUCmd /* GNU assembler command */
|
||||
},
|
||||
{ /* Linker */
|
||||
_linkCmd,
|
||||
|
@ -458,6 +464,7 @@ PORT stm8_port =
|
|||
1,
|
||||
NULL, /* crt */
|
||||
_libs_stm8, /* libs */
|
||||
".o" /* ELF output extension */
|
||||
},
|
||||
{ /* Peephole optimizer */
|
||||
stm8_defaultRules,
|
||||
|
|
Loading…
Reference in New Issue