So far the built-in inlining of several known standard function was always (!) enabled and the option -Os enabled additional, potentially unsafe inlining of some of those functions.
There were two aspects of this behavior that were considered undesirable: - Although the safe inlining is in general desirable it should only be enabled if asked for it - like any other optimization. - The option name -Os implies that it is a safe option, the potentially unsafe inlining should have a more explicit name. So now: - The option -Os enables the safe inlining. - The new option --eagerly-inline-funcs enables the potentially unsafe inlining (including the safe inlining). Additionally was added: - The option --inline-stdfuncs that does like -Os enable the safe inlining but doesn't enable optimizations. - The pragma inline-stdfuncs that works identical to --inline-stdfuncs. - The pragma allow-eager-inline that enables the potentially unsafe inlining but doesn't include the safe inlining. That means that by itself it only marks code as safe for potentially unsafe inlining but doesn't actually enable any inlining.
This commit is contained in:
parent
cbb2833c01
commit
02daf9f8b5
9 changed files with 1033 additions and 868 deletions
294
doc/cc65.sgml
294
doc/cc65.sgml
|
@ -58,7 +58,7 @@ Short options:
|
|||
-O Optimize code
|
||||
-Oi Optimize code, inline more code
|
||||
-Or Enable register variables
|
||||
-Os Inline some known functions
|
||||
-Os Inline some standard functions
|
||||
-T Include source as comment
|
||||
-V Print the compiler version number
|
||||
-W warning[,...] Suppress warnings
|
||||
|
@ -88,9 +88,11 @@ Long options:
|
|||
--debug-opt name Debug optimization steps
|
||||
--dep-target target Use this dependency target
|
||||
--disable-opt name Disable an optimization step
|
||||
--eagerly-inline-funcs Eagerly inline some known functions
|
||||
--enable-opt name Enable an optimization step
|
||||
--help Help (this text)
|
||||
--include-dir dir Set an include directory search path
|
||||
--inline-stdfuncs Inline some standard functions
|
||||
--list-opt-steps List all optimizer steps and exit
|
||||
--list-warnings List available warning types for -W
|
||||
--local-strings Emit string literals immediately
|
||||
|
@ -219,11 +221,53 @@ Here is a description of all the command line options:
|
|||
symbols in a special section in the object file.
|
||||
|
||||
|
||||
<label id="option-eagerly-inline-funcs">
|
||||
<tag><tt>--eagerly-inline-funcs</tt></tag>
|
||||
|
||||
Have the compiler eagerly inline these functions from the C library:
|
||||
<itemize>
|
||||
<item><tt/memcpy()/
|
||||
<item><tt/memset()/
|
||||
<item><tt/strcmp()/
|
||||
<item><tt/strcpy()/
|
||||
<item><tt/strlen()/
|
||||
<item>most of the functions declared in <tt/<ctype.h>/
|
||||
</itemize>
|
||||
|
||||
Note: This has two consequences:
|
||||
<itemize>
|
||||
<item>You may not use names of standard C functions for your own functions.
|
||||
If you do that, your program is not standard-compliant anyway; but,
|
||||
using <tt/--eagerly-inline-funcs/ actually will break things.
|
||||
<p>
|
||||
<item>The inlined string and memory functions will not handle strings or
|
||||
memory areas larger than 255 bytes. Similarly, the inlined <tt/is..()/
|
||||
functions will not work with values outside the char. range (such as
|
||||
<tt/EOF/).
|
||||
<p>
|
||||
</itemize>
|
||||
|
||||
<tt/--eagerly-inline-funcs/ implies the <tt/<ref id="option-inline-stdfuncs"
|
||||
name="--inline-stdfuncs"/ command line option.
|
||||
|
||||
See also <tt/<ref id="pragma-allow-eager-inline" name="#pragma allow-eager-inline">/.
|
||||
|
||||
|
||||
<tag><tt>-h, --help</tt></tag>
|
||||
|
||||
Print the short option summary shown above.
|
||||
|
||||
|
||||
<label id="option-inline-stdfuncs">
|
||||
<tag><tt>--inline-stdfuncs</tt></tag>
|
||||
|
||||
Allow the compiler to inline some standard functions from the C library like
|
||||
strlen. This will not only remove the overhead for a function call, but will
|
||||
make the code visible for the optimizer. See also the <tt/<ref id="option-O"
|
||||
name="-Os"/ command line option and <tt/<ref id="pragma-inline-stdfuncs"
|
||||
name="#pragma inline-stdfuncs">/.
|
||||
|
||||
|
||||
<label id="option-list-warnings">
|
||||
<tag><tt>--list-warnings</tt></tag>
|
||||
|
||||
|
@ -392,22 +436,22 @@ Here is a description of all the command line options:
|
|||
using
|
||||
|
||||
<tscreen><verb>
|
||||
void f (void)
|
||||
{
|
||||
unsigned a = 1;
|
||||
...
|
||||
}
|
||||
void f (void)
|
||||
{
|
||||
unsigned a = 1;
|
||||
...
|
||||
}
|
||||
</verb></tscreen>
|
||||
|
||||
the variable <tt/a/ will always have the value <tt/1/ when entering the
|
||||
function and using <tt/-Cl/, while in
|
||||
|
||||
<tscreen><verb>
|
||||
void f (void)
|
||||
{
|
||||
static unsigned a = 1;
|
||||
....
|
||||
}
|
||||
void f (void)
|
||||
{
|
||||
static unsigned a = 1;
|
||||
....
|
||||
}
|
||||
</verb></tscreen>
|
||||
|
||||
the variable <tt/a/ will have the value <tt/1/ only the first time that the
|
||||
|
@ -444,23 +488,13 @@ Here is a description of all the command line options:
|
|||
name="--register-vars">/ command line option, and the <ref
|
||||
id="register-vars" name="discussion of register variables"> below.
|
||||
|
||||
Using <tt/-Os/ will force the compiler to inline some known functions from
|
||||
the C library like strlen. Note: This has two consequences:
|
||||
<p>
|
||||
<itemize>
|
||||
<item>You may not use names of standard C functions in your own code. If you
|
||||
do that, your program is not standard compliant anyway, but using
|
||||
<tt/-Os/ will actually break things.
|
||||
<p>
|
||||
<item>The inlined string and memory functions will not handle strings or
|
||||
memory areas larger than 255 bytes. Similarly, the inlined <tt/is..()/
|
||||
functions will not work with values outside the char. range (such as
|
||||
<tt/EOF/).
|
||||
<p>
|
||||
</itemize>
|
||||
<p>
|
||||
Using <tt/-Os/ will allow the compiler to inline some standard functions
|
||||
from the C library like strlen. This will not only remove the overhead
|
||||
for a function call, but will make the code visible for the optimizer.
|
||||
See also <tt/<ref id="option-inline-stdfuncs" name="--inline-stdfuncs"/.
|
||||
|
||||
It is possible to concatenate the modifiers for <tt/-O/. For example, to
|
||||
enable register variables and inlining of known functions, you may use
|
||||
enable register variables and inlining of standard functions, you may use
|
||||
<tt/-Ors/.
|
||||
|
||||
|
||||
|
@ -518,6 +552,7 @@ Here is a description of all the command line options:
|
|||
</descrip><p>
|
||||
|
||||
|
||||
|
||||
<sect>Input and output<p>
|
||||
|
||||
The compiler will accept one C file per invocation and create a file with
|
||||
|
@ -556,21 +591,21 @@ and the one defined by the ISO standard:
|
|||
|
||||
<itemize>
|
||||
|
||||
<item> The datatypes "float" and "double" are not available.
|
||||
<p>
|
||||
<item> C Functions may not return structs (or unions), and structs may not
|
||||
<item> The datatypes "float" and "double" are not available.
|
||||
<p>
|
||||
<item> C Functions may not return structs (or unions), and structs may not
|
||||
be passed as parameters by value. However, struct assignment *is*
|
||||
possible.
|
||||
<p>
|
||||
<item> Most of the C library is available with only the fastcall calling
|
||||
convention (<ref id="extension-fastcall" name="see below">). It means
|
||||
that you must not mix pointers to those functions with pointers to
|
||||
user-written, cdecl functions (the calling conventions are incompatible).
|
||||
<p>
|
||||
<item> The <tt/volatile/ keyword has almost no effect. That is not as bad
|
||||
possible.
|
||||
<p>
|
||||
<item> Most of the C library is available with only the fastcall calling
|
||||
convention (<ref id="extension-fastcall" name="see below">). It means
|
||||
that you must not mix pointers to those functions with pointers to
|
||||
user-written, cdecl functions (the calling conventions are incompatible).
|
||||
<p>
|
||||
<item> The <tt/volatile/ keyword has almost no effect. That is not as bad
|
||||
as it sounds, since the 6502 has so few registers that it isn't
|
||||
possible to keep values in registers anyway.
|
||||
<p>
|
||||
<p>
|
||||
</itemize>
|
||||
|
||||
There may be some more minor differences I'm currently not aware of. The
|
||||
|
@ -585,49 +620,48 @@ This cc65 version has some extensions to the ISO C standard.
|
|||
|
||||
<itemize>
|
||||
|
||||
<item> The compiler allows to insert assembler statements into the output
|
||||
file. The syntax is
|
||||
<item> The compiler allows to insert assembler statements into the output
|
||||
file. The syntax is
|
||||
|
||||
<tscreen><verb>
|
||||
asm [optional volatile] (<string literal>[, optional parameters]) ;
|
||||
</verb></tscreen>
|
||||
or
|
||||
<tscreen><verb>
|
||||
<tscreen><verb>
|
||||
asm [optional volatile] (<string literal>[, optional parameters]) ;
|
||||
</verb></tscreen>
|
||||
or
|
||||
<tscreen><verb>
|
||||
__asm__ [optional volatile] (<string literal>[, optional parameters]) ;
|
||||
</verb></tscreen>
|
||||
</verb></tscreen>
|
||||
|
||||
The first form is in the user namespace; and, is disabled if the <tt/-A/
|
||||
switch is given.
|
||||
The first form is in the user namespace; and, is disabled if the <tt/-A/
|
||||
switch is given.
|
||||
|
||||
There is a whole section covering inline assembler statements,
|
||||
<ref id="inline-asm" name="see there">.
|
||||
<p>
|
||||
There is a whole section covering inline assembler statements,
|
||||
<ref id="inline-asm" name="see there">.
|
||||
<p>
|
||||
|
||||
<label id="extension-fastcall">
|
||||
<item> The normal calling convention -- for non-variadic functions -- is
|
||||
named "fastcall". The syntax for a function declaration that
|
||||
<em/explicitly/ uses fastcall is
|
||||
<item> The normal calling convention -- for non-variadic functions -- is
|
||||
named "fastcall". The syntax for a function declaration that
|
||||
<em/explicitly/ uses fastcall is
|
||||
|
||||
<tscreen><verb>
|
||||
<return type> fastcall <function name> (<parameter list>)
|
||||
</verb></tscreen>
|
||||
or
|
||||
<tscreen><verb>
|
||||
<return type> __fastcall__ <function name> (<parameter list>)
|
||||
</verb></tscreen>
|
||||
An example is
|
||||
<tscreen><verb>
|
||||
void __fastcall__ f (unsigned char c)
|
||||
</verb></tscreen>
|
||||
The first form of the fastcall keyword is in the user namespace and can
|
||||
therefore be disabled with the <tt><ref id="option--standard"
|
||||
<tscreen><verb>
|
||||
<return type> fastcall <function name> (<parameter list>)
|
||||
</verb></tscreen>
|
||||
or
|
||||
<tscreen><verb>
|
||||
<return type> __fastcall__ <function name> (<parameter list>)
|
||||
</verb></tscreen>
|
||||
An example is
|
||||
<tscreen><verb>
|
||||
void __fastcall__ f (unsigned char c)
|
||||
</verb></tscreen>
|
||||
The first form of the fastcall keyword is in the user namespace and can
|
||||
therefore be disabled with the <tt><ref id="option--standard"
|
||||
name="--standard"></tt> command line option.
|
||||
|
||||
For functions that are <tt/fastcall/, the rightmost parameter is not
|
||||
pushed on the stack but left in the primary register when the function
|
||||
is called. That significantly reduces the cost of calling those functions.
|
||||
<newline><newline>
|
||||
<p>
|
||||
For functions that are <tt/fastcall/, the rightmost parameter is not
|
||||
pushed on the stack but left in the primary register when the function
|
||||
is called. That significantly reduces the cost of calling those functions.
|
||||
<p>
|
||||
|
||||
<item> There is another calling convention named "cdecl". Variadic functions
|
||||
(their prototypes have an ellipsis [<tt/.../]) always use that
|
||||
|
@ -652,40 +686,40 @@ This cc65 version has some extensions to the ISO C standard.
|
|||
For functions that are <tt/cdecl/, the rightmost parameter is pushed
|
||||
onto the stack before the function is called. That increases the cost
|
||||
of calling those functions, especially when they are called from many
|
||||
places.<newline><newline>
|
||||
places.
|
||||
<p>
|
||||
|
||||
<item> There are two pseudo variables named <tt/__AX__/ and <tt/__EAX__/.
|
||||
Both refer to the primary register that is used by the compiler to
|
||||
evaluate expressions or return function results. <tt/__AX__/ is of
|
||||
type <tt/unsigned int/ and <tt/__EAX__/ of type <tt/long unsigned int/
|
||||
respectively. The pseudo variables may be used as lvalue and rvalue as
|
||||
every other variable. They are most useful together with short
|
||||
sequences of assembler code. For example, the macro
|
||||
<item> There are two pseudo variables named <tt/__AX__/ and <tt/__EAX__/.
|
||||
Both refer to the primary register that is used by the compiler to
|
||||
evaluate expressions or return function results. <tt/__AX__/ is of
|
||||
type <tt/unsigned int/ and <tt/__EAX__/ of type <tt/long unsigned int/
|
||||
respectively. The pseudo variables may be used as lvalue and rvalue as
|
||||
every other variable. They are most useful together with short
|
||||
sequences of assembler code. For example, the macro
|
||||
|
||||
<tscreen><verb>
|
||||
#define hi(x) \
|
||||
<tscreen><verb>
|
||||
#define hi(x) \
|
||||
(__AX__ = (x), \
|
||||
asm ("txa"), \
|
||||
asm ("ldx #$00"), \
|
||||
__AX__)
|
||||
</verb></tscreen>
|
||||
</verb></tscreen>
|
||||
|
||||
will give the high byte of any unsigned value.
|
||||
<p>
|
||||
will give the high byte of any unsigned value.
|
||||
<p>
|
||||
|
||||
<item> Inside a function, the identifier <tt/__func__/ gives the name of the
|
||||
current function as a string. Outside of functions, <tt/__func__/ is
|
||||
undefined.
|
||||
Example:
|
||||
<item> Inside a function, the identifier <tt/__func__/ gives the name of the
|
||||
current function as a string. Outside of functions, <tt/__func__/ is
|
||||
undefined.
|
||||
Example:
|
||||
|
||||
<tscreen><verb>
|
||||
#define PRINT_DEBUG(s) printf ("%s: %s\n", __func__, s);
|
||||
</verb></tscreen>
|
||||
<tscreen><verb>
|
||||
#define PRINT_DEBUG(s) printf ("%s: %s\n", __func__, s);
|
||||
</verb></tscreen>
|
||||
|
||||
The macro will print the name of the current function plus a given
|
||||
string.
|
||||
<p>
|
||||
The macro will print the name of the current function plus a given
|
||||
string.
|
||||
<p>
|
||||
|
||||
<item> cc65 allows the initialization of <tt/void/ variables. This may be
|
||||
used to create arbitrary structures that are more compatible with
|
||||
|
@ -825,6 +859,11 @@ The compiler defines several macros at startup:
|
|||
This macro expands to the date of translation of the preprocessing
|
||||
translation unit in the form "Mmm dd yyyy".
|
||||
|
||||
<tag><tt>__EAGERLY_INLINE_FUNCS__</tt></tag>
|
||||
|
||||
Is defined if the compiler was called with the <tt/<ref id="option-eagerly-inline-funcs"
|
||||
name="--eagerly-inline-funcs"/ command line option.
|
||||
|
||||
<tag><tt>__FILE__</tt></tag>
|
||||
|
||||
This macro expands to a string containing the name of the C source file.
|
||||
|
@ -912,6 +951,7 @@ The compiler defines several macros at startup:
|
|||
</descrip>
|
||||
|
||||
|
||||
|
||||
<sect>#pragmas<label id="pragmas"><p>
|
||||
|
||||
The compiler understands some pragmas that may be used to change code
|
||||
|
@ -920,6 +960,19 @@ If the first parameter is <tt/push/, the old value is saved onto a stack
|
|||
before changing it. The value may later be restored by using the <tt/pop/
|
||||
parameter with the <tt/#pragma/.
|
||||
|
||||
|
||||
<sect1><tt>#pragma allow-eager-inline ([push,] on|off)</tt><label id="pragma-allow-eager-inline"><p>
|
||||
|
||||
Allow eager inlining of known functions. If the argument is "off", eager
|
||||
inlining is disabled, otherwise it is enabled. Please note that (in contrast
|
||||
to the <tt/<ref id="option-eagerly-inline-funcs" name="--eagerly-inline-funcs"/
|
||||
command line option) this pragma does not imply the <tt/<ref id="option-inline-stdfuncs"
|
||||
name="--inline-stdfuncs"/ command line option. Rather it marks code to be safe for
|
||||
eager inlining of known functions if inlining of standard functions is enabled.
|
||||
|
||||
The <tt/#pragma/ understands the push and pop parameters as explained above.
|
||||
|
||||
|
||||
<sect1><tt>#pragma bss-name ([push,] <name>)</tt><label id="pragma-bss-name"><p>
|
||||
|
||||
This pragma changes the name used for the BSS segment (the BSS segment
|
||||
|
@ -938,7 +991,7 @@ parameter with the <tt/#pragma/.
|
|||
|
||||
Example:
|
||||
<tscreen><verb>
|
||||
#pragma bss-name ("MyBSS")
|
||||
#pragma bss-name ("MyBSS")
|
||||
</verb></tscreen>
|
||||
|
||||
|
||||
|
@ -993,6 +1046,7 @@ parameter with the <tt/#pragma/.
|
|||
|
||||
The <tt/#pragma/ understands the push and pop parameters as explained above.
|
||||
|
||||
|
||||
<sect1><tt>#pragma code-name ([push,] <name>)</tt><label id="pragma-code-name"><p>
|
||||
|
||||
This pragma changes the name used for the CODE segment (the CODE segment
|
||||
|
@ -1007,7 +1061,7 @@ parameter with the <tt/#pragma/.
|
|||
|
||||
Example:
|
||||
<tscreen><verb>
|
||||
#pragma code-name ("MyCODE")
|
||||
#pragma code-name ("MyCODE")
|
||||
</verb></tscreen>
|
||||
|
||||
|
||||
|
@ -1035,10 +1089,21 @@ parameter with the <tt/#pragma/.
|
|||
|
||||
Example:
|
||||
<tscreen><verb>
|
||||
#pragma data-name ("MyDATA")
|
||||
#pragma data-name ("MyDATA")
|
||||
</verb></tscreen>
|
||||
|
||||
|
||||
<sect1><tt>#pragma inline-stdfuncs ([push,] on|off)</tt><label id="pragma-inline-stdfuncs"><p>
|
||||
|
||||
Allow the compiler to inline some standard functions from the C library like
|
||||
strlen. If the argument is "off", inlining is disabled, otherwise it is enabled.
|
||||
|
||||
See also the the <tt/<ref id="option-inline-stdfuncs" name="--inline-stdfuncs"/
|
||||
command line option.
|
||||
|
||||
The <tt/#pragma/ understands the push and pop parameters as explained above.
|
||||
|
||||
|
||||
<sect1><tt>#pragma local-strings ([push,] on|off)</tt><label id="pragma-local-strings"><p>
|
||||
|
||||
When "on", emit string literals to the data segment when they're encountered
|
||||
|
@ -1083,7 +1148,7 @@ parameter with the <tt/#pragma/.
|
|||
|
||||
Example:
|
||||
<tscreen><verb>
|
||||
#pragma rodata-name ("MyRODATA")
|
||||
#pragma rodata-name ("MyRODATA")
|
||||
</verb></tscreen>
|
||||
|
||||
|
||||
|
@ -1105,9 +1170,9 @@ parameter with the <tt/#pragma/.
|
|||
|
||||
Example:
|
||||
<tscreen><verb>
|
||||
#pragma regvaraddr(on) /* Allow taking the address
|
||||
* of register variables
|
||||
*/
|
||||
#pragma regvaraddr(on) /* Allow taking the address
|
||||
* of register variables
|
||||
*/
|
||||
</verb></tscreen>
|
||||
|
||||
|
||||
|
@ -1154,7 +1219,7 @@ parameter with the <tt/#pragma/.
|
|||
Example:
|
||||
<tscreen><verb>
|
||||
/* Don't warn about the unused parameter in function func */
|
||||
#pragma warn (unused-param, push, off)
|
||||
#pragma warn (unused-param, push, off)
|
||||
static int func (int unused)
|
||||
{
|
||||
return 0;
|
||||
|
@ -1187,13 +1252,12 @@ parameter with the <tt/#pragma/.
|
|||
|
||||
Example:
|
||||
<tscreen><verb>
|
||||
extern int foo;
|
||||
#pragma zpsym ("foo"); /* foo is in the zeropage */
|
||||
extern int foo;
|
||||
#pragma zpsym ("foo"); /* foo is in the zeropage */
|
||||
</verb></tscreen>
|
||||
|
||||
|
||||
|
||||
|
||||
<sect>Register variables<label id="register-vars"><p>
|
||||
|
||||
The runtime for all supported platforms has 6 bytes of zero page space
|
||||
|
@ -1450,14 +1514,14 @@ including commercial applications, and to alter it and redistribute it
|
|||
freely, subject to the following restrictions:
|
||||
|
||||
<enum>
|
||||
<item> The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
<item> Altered source versions must be plainly marked as such, and must not
|
||||
be misrepresented as being the original software.
|
||||
<item> This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
<item> The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
<item> Altered source versions must be plainly marked as such, and must not
|
||||
be misrepresented as being the original software.
|
||||
<item> This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
</enum>
|
||||
|
||||
</article>
|
||||
|
|
|
@ -54,9 +54,9 @@ Short options:
|
|||
-L path Specify a library search path
|
||||
-Ln name Create a VICE label file
|
||||
-O Optimize code
|
||||
-Oi Optimize code, inline functions
|
||||
-Oi Optimize code, inline more code
|
||||
-Or Optimize code, honour the register keyword
|
||||
-Os Optimize code, inline known C funtions
|
||||
-Os Optimize code, inline standard funtions
|
||||
-S Compile but don't assemble and link
|
||||
-T Include source as comment
|
||||
-V Print the version number
|
||||
|
|
|
@ -89,9 +89,9 @@ unsigned char __fastcall__ toascii (unsigned char c);
|
|||
** #undef'ing the macroes.
|
||||
** Please note that the following macroes do NOT handle EOF correctly, as
|
||||
** stated in the manual. If you need correct behaviour for EOF, don't
|
||||
** use -Os, or #undefine the following macroes.
|
||||
** use --eagerly-inline-funcs, or #undefine the following macroes.
|
||||
*/
|
||||
#ifdef __OPT_s__
|
||||
#ifdef __EAGERLY_INLINE_FUNCS__
|
||||
|
||||
#define isalnum(c) (__AX__ = (c), \
|
||||
__asm__ ("tay"), \
|
||||
|
|
|
@ -335,17 +335,22 @@ void Compile (const char* FileName)
|
|||
** changes using #pragma later.
|
||||
*/
|
||||
if (IS_Get (&Optimize)) {
|
||||
long CodeSize = IS_Get (&CodeSizeFactor);
|
||||
DefineNumericMacro ("__OPT__", 1);
|
||||
}
|
||||
{
|
||||
long CodeSize = IS_Get (&CodeSizeFactor);
|
||||
if (CodeSize > 100) {
|
||||
DefineNumericMacro ("__OPT_i__", CodeSize);
|
||||
}
|
||||
if (IS_Get (&EnableRegVars)) {
|
||||
DefineNumericMacro ("__OPT_r__", 1);
|
||||
}
|
||||
if (IS_Get (&InlineStdFuncs)) {
|
||||
DefineNumericMacro ("__OPT_s__", 1);
|
||||
}
|
||||
}
|
||||
if (IS_Get (&EnableRegVars)) {
|
||||
DefineNumericMacro ("__OPT_r__", 1);
|
||||
}
|
||||
if (IS_Get (&InlineStdFuncs)) {
|
||||
DefineNumericMacro ("__OPT_s__", 1);
|
||||
}
|
||||
if (IS_Get (&EagerlyInlineFuncs)) {
|
||||
DefineNumericMacro ("__EAGERLY_INLINE_FUNCS__", 1);
|
||||
}
|
||||
|
||||
/* __TIME__ and __DATE__ macros */
|
||||
|
|
|
@ -53,7 +53,8 @@ unsigned RegisterSpace = 6; /* Space available for register vars */
|
|||
/* Stackable options */
|
||||
IntStack WritableStrings = INTSTACK(0); /* Literal strings are r/w */
|
||||
IntStack LocalStrings = INTSTACK(0); /* Emit string literals immediately */
|
||||
IntStack InlineStdFuncs = INTSTACK(0); /* Inline some known functions */
|
||||
IntStack InlineStdFuncs = INTSTACK(0); /* Inline some standard functions */
|
||||
IntStack EagerlyInlineFuncs = INTSTACK(0); /* Eagerly inline some known functions */
|
||||
IntStack EnableRegVars = INTSTACK(0); /* Enable register variables */
|
||||
IntStack AllowRegVarAddr = INTSTACK(0); /* Allow taking addresses of register vars */
|
||||
IntStack RegVarsToCallStack = INTSTACK(0); /* Save reg variables on call stack */
|
||||
|
|
|
@ -61,7 +61,8 @@ extern unsigned RegisterSpace; /* Space available for register
|
|||
/* Stackable options */
|
||||
extern IntStack WritableStrings; /* Literal strings are r/w */
|
||||
extern IntStack LocalStrings; /* Emit string literals immediately */
|
||||
extern IntStack InlineStdFuncs; /* Inline some known functions */
|
||||
extern IntStack InlineStdFuncs; /* Inline some standard functions */
|
||||
extern IntStack EagerlyInlineFuncs; /* Eagerly inline some known functions */
|
||||
extern IntStack EnableRegVars; /* Enable register variables */
|
||||
extern IntStack AllowRegVarAddr; /* Allow taking addresses of register vars */
|
||||
extern IntStack RegVarsToCallStack; /* Save reg variables on call stack */
|
||||
|
|
|
@ -88,7 +88,7 @@ static void Usage (void)
|
|||
" -O\t\t\t\tOptimize code\n"
|
||||
" -Oi\t\t\t\tOptimize code, inline more code\n"
|
||||
" -Or\t\t\t\tEnable register variables\n"
|
||||
" -Os\t\t\t\tInline some known functions\n"
|
||||
" -Os\t\t\t\tInline some standard functions\n"
|
||||
" -T\t\t\t\tInclude source as comment\n"
|
||||
" -V\t\t\t\tPrint the compiler version number\n"
|
||||
" -W warning[,...]\t\tSuppress warnings\n"
|
||||
|
@ -118,9 +118,11 @@ static void Usage (void)
|
|||
" --debug-opt name\t\tDebug optimization steps\n"
|
||||
" --dep-target target\t\tUse this dependency target\n"
|
||||
" --disable-opt name\t\tDisable an optimization step\n"
|
||||
" --eagerly-inline-funcs\t\tEagerly inline some known functions\n"
|
||||
" --enable-opt name\t\tEnable an optimization step\n"
|
||||
" --help\t\t\tHelp (this text)\n"
|
||||
" --include-dir dir\t\tSet an include directory search path\n"
|
||||
" --inline-stdfuncs\t\tInline some standard functions\n"
|
||||
" --list-opt-steps\t\tList all optimizer steps and exit\n"
|
||||
" --list-warnings\t\tList available warning types for -W\n"
|
||||
" --local-strings\t\tEmit string literals immediately\n"
|
||||
|
@ -581,6 +583,16 @@ static void OptDisableOpt (const char* Opt attribute ((unused)), const char* Arg
|
|||
|
||||
|
||||
|
||||
static void OptEagerlyInlineFuncs (const char* Opt attribute((unused)),
|
||||
const char* Arg attribute((unused)))
|
||||
/* Eagerly inline some known functions */
|
||||
{
|
||||
IS_Set (&InlineStdFuncs, 1);
|
||||
IS_Set (&EagerlyInlineFuncs, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void OptEnableOpt (const char* Opt attribute ((unused)), const char* Arg)
|
||||
/* Enable an optimization step */
|
||||
{
|
||||
|
@ -608,6 +620,15 @@ static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg
|
|||
|
||||
|
||||
|
||||
static void OptInlineStdFuncs (const char* Opt attribute((unused)),
|
||||
const char* Arg attribute((unused)))
|
||||
/* Inline some standard functions */
|
||||
{
|
||||
IS_Set (&InlineStdFuncs, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void OptListOptSteps (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
/* List all optimizer steps */
|
||||
|
@ -819,39 +840,41 @@ int main (int argc, char* argv[])
|
|||
{
|
||||
/* Program long options */
|
||||
static const LongOpt OptTab[] = {
|
||||
{ "--add-source", 0, OptAddSource },
|
||||
{ "--all-cdecl", 0, OptAllCDecl },
|
||||
{ "--bss-name", 1, OptBssName },
|
||||
{ "--check-stack", 0, OptCheckStack },
|
||||
{ "--code-name", 1, OptCodeName },
|
||||
{ "--codesize", 1, OptCodeSize },
|
||||
{ "--cpu", 1, OptCPU },
|
||||
{ "--create-dep", 1, OptCreateDep },
|
||||
{ "--create-full-dep", 1, OptCreateFullDep },
|
||||
{ "--data-name", 1, OptDataName },
|
||||
{ "--debug", 0, OptDebug },
|
||||
{ "--debug-info", 0, OptDebugInfo },
|
||||
{ "--debug-opt", 1, OptDebugOpt },
|
||||
{ "--debug-opt-output", 0, OptDebugOptOutput },
|
||||
{ "--dep-target", 1, OptDepTarget },
|
||||
{ "--disable-opt", 1, OptDisableOpt },
|
||||
{ "--enable-opt", 1, OptEnableOpt },
|
||||
{ "--help", 0, OptHelp },
|
||||
{ "--include-dir", 1, OptIncludeDir },
|
||||
{ "--list-opt-steps", 0, OptListOptSteps },
|
||||
{ "--list-warnings", 0, OptListWarnings },
|
||||
{ "--local-strings", 0, OptLocalStrings },
|
||||
{ "--memory-model", 1, OptMemoryModel },
|
||||
{ "--register-space", 1, OptRegisterSpace },
|
||||
{ "--register-vars", 0, OptRegisterVars },
|
||||
{ "--rodata-name", 1, OptRodataName },
|
||||
{ "--signed-chars", 0, OptSignedChars },
|
||||
{ "--standard", 1, OptStandard },
|
||||
{ "--static-locals", 0, OptStaticLocals },
|
||||
{ "--target", 1, OptTarget },
|
||||
{ "--verbose", 0, OptVerbose },
|
||||
{ "--version", 0, OptVersion },
|
||||
{ "--writable-strings", 0, OptWritableStrings },
|
||||
{ "--add-source", 0, OptAddSource },
|
||||
{ "--all-cdecl", 0, OptAllCDecl },
|
||||
{ "--bss-name", 1, OptBssName },
|
||||
{ "--check-stack", 0, OptCheckStack },
|
||||
{ "--code-name", 1, OptCodeName },
|
||||
{ "--codesize", 1, OptCodeSize },
|
||||
{ "--cpu", 1, OptCPU },
|
||||
{ "--create-dep", 1, OptCreateDep },
|
||||
{ "--create-full-dep", 1, OptCreateFullDep },
|
||||
{ "--data-name", 1, OptDataName },
|
||||
{ "--debug", 0, OptDebug },
|
||||
{ "--debug-info", 0, OptDebugInfo },
|
||||
{ "--debug-opt", 1, OptDebugOpt },
|
||||
{ "--debug-opt-output", 0, OptDebugOptOutput },
|
||||
{ "--dep-target", 1, OptDepTarget },
|
||||
{ "--disable-opt", 1, OptDisableOpt },
|
||||
{ "--eagerly-inline-funcs", 0, OptEagerlyInlineFuncs },
|
||||
{ "--enable-opt", 1, OptEnableOpt },
|
||||
{ "--help", 0, OptHelp },
|
||||
{ "--include-dir", 1, OptIncludeDir },
|
||||
{ "--inline-stdfuncs", 0, OptInlineStdFuncs },
|
||||
{ "--list-opt-steps", 0, OptListOptSteps },
|
||||
{ "--list-warnings", 0, OptListWarnings },
|
||||
{ "--local-strings", 0, OptLocalStrings },
|
||||
{ "--memory-model", 1, OptMemoryModel },
|
||||
{ "--register-space", 1, OptRegisterSpace },
|
||||
{ "--register-vars", 0, OptRegisterVars },
|
||||
{ "--rodata-name", 1, OptRodataName },
|
||||
{ "--signed-chars", 0, OptSignedChars },
|
||||
{ "--standard", 1, OptStandard },
|
||||
{ "--static-locals", 0, OptStaticLocals },
|
||||
{ "--target", 1, OptTarget },
|
||||
{ "--verbose", 0, OptVerbose },
|
||||
{ "--version", 0, OptVersion },
|
||||
{ "--writable-strings", 0, OptWritableStrings },
|
||||
};
|
||||
|
||||
unsigned I;
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
typedef enum {
|
||||
PRAGMA_ILLEGAL = -1,
|
||||
PRAGMA_ALIGN,
|
||||
PRAGMA_ALLOW_EAGER_INLINE,
|
||||
PRAGMA_BSS_NAME,
|
||||
PRAGMA_BSSSEG, /* obsolete */
|
||||
PRAGMA_CHARMAP,
|
||||
|
@ -74,6 +75,7 @@ typedef enum {
|
|||
PRAGMA_CODESIZE,
|
||||
PRAGMA_DATA_NAME,
|
||||
PRAGMA_DATASEG, /* obsolete */
|
||||
PRAGMA_INLINE_STDFUNCS,
|
||||
PRAGMA_LOCAL_STRINGS,
|
||||
PRAGMA_OPTIMIZE,
|
||||
PRAGMA_REGVARADDR,
|
||||
|
@ -96,31 +98,33 @@ static const struct Pragma {
|
|||
const char* Key; /* Keyword */
|
||||
pragma_t Tok; /* Token */
|
||||
} Pragmas[PRAGMA_COUNT] = {
|
||||
{ "align", PRAGMA_ALIGN },
|
||||
{ "bss-name", PRAGMA_BSS_NAME },
|
||||
{ "bssseg", PRAGMA_BSSSEG }, /* obsolete */
|
||||
{ "charmap", PRAGMA_CHARMAP },
|
||||
{ "check-stack", PRAGMA_CHECK_STACK },
|
||||
{ "checkstack", PRAGMA_CHECKSTACK }, /* obsolete */
|
||||
{ "code-name", PRAGMA_CODE_NAME },
|
||||
{ "codeseg", PRAGMA_CODESEG }, /* obsolete */
|
||||
{ "codesize", PRAGMA_CODESIZE },
|
||||
{ "data-name", PRAGMA_DATA_NAME },
|
||||
{ "dataseg", PRAGMA_DATASEG }, /* obsolete */
|
||||
{ "local-strings", PRAGMA_LOCAL_STRINGS },
|
||||
{ "optimize", PRAGMA_OPTIMIZE },
|
||||
{ "register-vars", PRAGMA_REGISTER_VARS },
|
||||
{ "regvaraddr", PRAGMA_REGVARADDR },
|
||||
{ "regvars", PRAGMA_REGVARS }, /* obsolete */
|
||||
{ "rodata-name", PRAGMA_RODATA_NAME },
|
||||
{ "rodataseg", PRAGMA_RODATASEG }, /* obsolete */
|
||||
{ "signed-chars", PRAGMA_SIGNED_CHARS },
|
||||
{ "signedchars", PRAGMA_SIGNEDCHARS }, /* obsolete */
|
||||
{ "static-locals", PRAGMA_STATIC_LOCALS },
|
||||
{ "staticlocals", PRAGMA_STATICLOCALS }, /* obsolete */
|
||||
{ "warn", PRAGMA_WARN },
|
||||
{ "writable-strings", PRAGMA_WRITABLE_STRINGS },
|
||||
{ "zpsym", PRAGMA_ZPSYM },
|
||||
{ "align", PRAGMA_ALIGN },
|
||||
{ "allow-eager-inline", PRAGMA_ALLOW_EAGER_INLINE },
|
||||
{ "bss-name", PRAGMA_BSS_NAME },
|
||||
{ "bssseg", PRAGMA_BSSSEG }, /* obsolete */
|
||||
{ "charmap", PRAGMA_CHARMAP },
|
||||
{ "check-stack", PRAGMA_CHECK_STACK },
|
||||
{ "checkstack", PRAGMA_CHECKSTACK }, /* obsolete */
|
||||
{ "code-name", PRAGMA_CODE_NAME },
|
||||
{ "codeseg", PRAGMA_CODESEG }, /* obsolete */
|
||||
{ "codesize", PRAGMA_CODESIZE },
|
||||
{ "data-name", PRAGMA_DATA_NAME },
|
||||
{ "dataseg", PRAGMA_DATASEG }, /* obsolete */
|
||||
{ "inline-stdfuncs", PRAGMA_INLINE_STDFUNCS },
|
||||
{ "local-strings", PRAGMA_LOCAL_STRINGS },
|
||||
{ "optimize", PRAGMA_OPTIMIZE },
|
||||
{ "register-vars", PRAGMA_REGISTER_VARS },
|
||||
{ "regvaraddr", PRAGMA_REGVARADDR },
|
||||
{ "regvars", PRAGMA_REGVARS }, /* obsolete */
|
||||
{ "rodata-name", PRAGMA_RODATA_NAME },
|
||||
{ "rodataseg", PRAGMA_RODATASEG }, /* obsolete */
|
||||
{ "signed-chars", PRAGMA_SIGNED_CHARS },
|
||||
{ "signedchars", PRAGMA_SIGNEDCHARS }, /* obsolete */
|
||||
{ "static-locals", PRAGMA_STATIC_LOCALS },
|
||||
{ "staticlocals", PRAGMA_STATICLOCALS }, /* obsolete */
|
||||
{ "warn", PRAGMA_WARN },
|
||||
{ "writable-strings", PRAGMA_WRITABLE_STRINGS },
|
||||
{ "zpsym", PRAGMA_ZPSYM },
|
||||
};
|
||||
|
||||
/* Result of ParsePushPop */
|
||||
|
@ -703,6 +707,10 @@ static void ParsePragma (void)
|
|||
IntPragma (&B, &DataAlignment, 1, 4096);
|
||||
break;
|
||||
|
||||
case PRAGMA_ALLOW_EAGER_INLINE:
|
||||
FlagPragma (&B, &EagerlyInlineFuncs);
|
||||
break;
|
||||
|
||||
case PRAGMA_BSSSEG:
|
||||
Warning ("#pragma bssseg is obsolete, please use #pragma bss-name instead");
|
||||
/* FALLTHROUGH */
|
||||
|
@ -739,6 +747,10 @@ static void ParsePragma (void)
|
|||
SegNamePragma (&B, SEG_DATA);
|
||||
break;
|
||||
|
||||
case PRAGMA_INLINE_STDFUNCS:
|
||||
FlagPragma (&B, &InlineStdFuncs);
|
||||
break;
|
||||
|
||||
case PRAGMA_LOCAL_STRINGS:
|
||||
FlagPragma (&B, &LocalStrings);
|
||||
break;
|
||||
|
|
1421
src/cc65/stdfunc.c
1421
src/cc65/stdfunc.c
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue