/* Generate code */
if (Bytes == 1) {
- if (CodeSizeFactor < 165) {
+ if (IS_Get (&CodeSizeFactor) < 165) {
ldyconst (StackOffs);
ldxconst (RegOffs);
AddCodeLine ("jsr regswap1");
AddCodeLine ("lda (sp),y");
AddCodeLine ("sta regbank%+d", RegOffs+1);
- } else if (Bytes == 3 && CodeSizeFactor >= 133) {
+ } else if (Bytes == 3 && IS_Get (&CodeSizeFactor) >= 133) {
ldyconst (StackOffs);
AddCodeLine ("lda (sp),y");
AddCodeLine ("lda sp");
AddCodeLine ("ldx sp+1");
} else {
- if (CodeSizeFactor < 300) {
+ if (IS_Get (&CodeSizeFactor) < 300) {
ldaconst (offs); /* Load A with offset value */
AddCodeLine ("jsr leaasp"); /* Load effective address */
} else {
AddCodeLine ("lda (sp),y");
/* Add the value of the stackpointer */
- if (CodeSizeFactor > 250) {
+ if (IS_Get (&CodeSizeFactor) > 250) {
unsigned L = GetLocalLabel();
AddCodeLine ("ldx sp+1");
AddCodeLine ("clc");
}
AddCodeLine ("sta (sp),y");
} else {
- if ((Flags & CF_NOKEEP) == 0 || CodeSizeFactor < 160) {
+ if ((Flags & CF_NOKEEP) == 0 || IS_Get (&CodeSizeFactor) < 160) {
ldyconst (Offs);
AddCodeLine ("jsr staxysp");
} else {
if (Flags & CF_FORCECHAR) {
/* Conversion is from char */
if (Flags & CF_UNSIGNED) {
- if (CodeSizeFactor >= 200) {
+ if (IS_Get (&CodeSizeFactor) >= 200) {
AddCodeLine ("ldx #$00");
AddCodeLine ("stx sreg");
AddCodeLine ("stx sreg+1");
AddCodeLine ("jsr aulong");
}
} else {
- if (CodeSizeFactor >= 366) {
+ if (IS_Get (&CodeSizeFactor) >= 366) {
L = GetLocalLabel();
AddCodeLine ("ldx #$00");
AddCodeLine ("cmp #$80");
case CF_INT:
if (Flags & CF_UNSIGNED) {
- if (CodeSizeFactor >= 200) {
+ if (IS_Get (&CodeSizeFactor) >= 200) {
ldyconst (0);
AddCodeLine ("sty sreg");
AddCodeLine ("sty sreg+1");
/* FALLTHROUGH */
case CF_INT:
- if (CodeSizeFactor >= (p2+1)*130U) {
+ if (IS_Get (&CodeSizeFactor) >= (p2+1)*130) {
AddCodeLine ("stx tmp1");
while (p2--) {
AddCodeLine ("asl a");
case CF_INT:
if (flags & CF_UNSIGNED) {
- if (CodeSizeFactor >= (p2+1)*130U) {
+ if (IS_Get (&CodeSizeFactor) >= (p2+1)*130) {
AddCodeLine ("stx tmp1");
while (p2--) {
AddCodeLine ("lsr tmp1");
AddCodeLine ("jsr lsrax%d", p2);
}
} else {
- if (CodeSizeFactor >= (p2+1)*150U) {
+ if (IS_Get (&CodeSizeFactor) >= (p2+1)*150) {
AddCodeLine ("stx tmp1");
while (p2--) {
AddCodeLine ("cpx #$80");
case CF_INT:
ldyconst (offs);
if (flags & CF_CONST) {
- if (CodeSizeFactor >= 400) {
+ if (IS_Get (&CodeSizeFactor) >= 400) {
AddCodeLine ("clc");
AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
AddCodeLine ("adc (sp),y");
break;
case CF_INT:
- if (CodeSizeFactor >= 200) {
+ if (IS_Get (&CodeSizeFactor) >= 200) {
/* Lots of code, use only if size is not important */
AddCodeLine ("sta ptr1");
AddCodeLine ("stx ptr1+1");
break;
case CF_INT:
- if (CodeSizeFactor >= 200) {
+ if (IS_Get (&CodeSizeFactor) >= 200) {
/* Lots of code, use only if size is not important */
AddCodeLine ("sta ptr1");
AddCodeLine ("stx ptr1+1");
AddCodeLine ("bne %s", LocalLabelName (L));
AddCodeLine ("inx");
g_defcodelabel (L);
- } else if (CodeSizeFactor < 200) {
+ } else if (IS_Get (&CodeSizeFactor) < 200) {
/* Use jsr calls */
if (val <= 8) {
AddCodeLine ("jsr incax%lu", val);
/* FALLTHROUGH */
case CF_INT:
- if (CodeSizeFactor < 200) {
+ if (IS_Get (&CodeSizeFactor) < 200) {
/* Use subroutines */
if (val <= 8) {
AddCodeLine ("jsr decax%d", (int) val);
/* Don't run the function if it is disabled or if it is prohibited by the
* code size factor
*/
- if (F->Disabled || F->CodeSizeFactor > CodeSizeFactor) {
+ if (F->Disabled || F->CodeSizeFactor > S->CodeSizeFactor) {
return 0;
}
unsigned Changes = 0;
unsigned C;
- if (CodeSizeFactor <= 100) {
+ if (S->CodeSizeFactor <= 100) {
/* Optimize for size, that is replace operations by shorter ones, even
* if this does hinder further optimizations (no problem since we're
* done soon).
const char* StatFileName;
/* If we shouldn't run the optimizer, bail out */
- if (!Optimize) {
+ if (!S->Optimize) {
return;
}
#include "asmlabel.h"
#include "codeent.h"
#include "codeinfo.h"
+#include "codeseg.h"
#include "datatype.h"
#include "error.h"
+#include "global.h"
#include "ident.h"
#include "symentry.h"
-#include "codeseg.h"
S->ExitRegs = REG_NONE;
}
+ /* Copy the global optimization settings */
+ S->Optimize = (unsigned char) IS_Get (&Optimize);
+ S->CodeSizeFactor = (unsigned) IS_Get (&CodeSizeFactor);
+
/* Return the new struct */
return S;
}
SymEntry* Func; /* Owner function */
Collection Entries; /* List of code entries */
Collection Labels; /* Labels for next insn */
- CodeLabel* LabelHash [CS_LABEL_HASH_SIZE]; /* Label hash table */
+ CodeLabel* LabelHash[CS_LABEL_HASH_SIZE]; /* Label hash table */
unsigned short ExitRegs; /* Register use on exit */
+
+ /* Optimization settings for this segment */
+ unsigned char Optimize; /* On/off switch */
+ unsigned CodeSizeFactor;
};
/* End of codeseg.h */
-#endif
+#endif
* IS_Get functions access the values in effect now, regardless of any
* changes using #pragma later.
*/
- if (Optimize) {
+ if (IS_Get (&Optimize)) {
+ long CodeSize = IS_Get (&CodeSizeFactor);
DefineNumericMacro ("__OPT__", 1);
- if (FavourSize == 0) {
- DefineNumericMacro ("__OPT_i__", 1);
+ if (CodeSize > 100) {
+ DefineNumericMacro ("__OPT_i__", CodeSize);
}
if (IS_Get (&EnableRegVars)) {
DefineNumericMacro ("__OPT_r__", 1);
* (instead of pushing) is enabled.
*
*/
- if (CodeSizeFactor >= 200) {
+ if (IS_Get (&CodeSizeFactor) >= 200) {
/* Calculate the number and size of the parameters */
FrameParams = Func->ParamCount;
unsigned char CreateDep = 0; /* Create a dependency file */
unsigned char ANSI = 0; /* Strict ANSI flag */
unsigned char NoWarn = 0; /* Suppress warnings */
-unsigned char Optimize = 0; /* Optimize flag */
unsigned long OptDisable = 0; /* Optimizer passes to disable */
-unsigned char FavourSize = 1; /* Favour size over speed */
-unsigned CodeSizeFactor = 100; /* Size factor for generated code */
unsigned RegisterSpace = 6; /* Space available for register vars */
/* Stackable options */
IntStack StaticLocals = INTSTACK(0); /* Make local variables static */
IntStack SignedChars = INTSTACK(0); /* Make characters signed by default */
IntStack CheckStack = INTSTACK(0); /* Generate stack overflow checks */
+IntStack Optimize = INTSTACK(0); /* Optimize flag */
+IntStack CodeSizeFactor = INTSTACK(100);/* Size factor for generated code */
/*****************************************************************************/
-
+
extern unsigned char AddSource; /* Add source lines as comments */
extern unsigned char DebugInfo; /* Add debug info to the obj */
extern unsigned char CreateDep; /* Create a dependency file */
extern unsigned char ANSI; /* Strict ANSI flag */
extern unsigned char NoWarn; /* Suppress warnings */
-extern unsigned char Optimize; /* Optimize flag */
extern unsigned long OptDisable; /* Optimizer passes to disable */
-extern unsigned char FavourSize; /* Favour size over speed */
-extern unsigned CodeSizeFactor; /* Size factor for generated code */
extern unsigned RegisterSpace; /* Space available for register vars */
/* Stackable options */
extern IntStack StaticLocals; /* Make local variables static */
extern IntStack SignedChars; /* Make characters signed by default */
extern IntStack CheckStack; /* Generate stack overflow checks */
+extern IntStack Optimize; /* Optimize flag */
+extern IntStack CodeSizeFactor; /* Size factor for generated code */
static void OptCodeSize (const char* Opt, const char* Arg)
/* Handle the --codesize option */
{
+ unsigned Factor;
+ char BoundsCheck;
+
/* Numeric argument expected */
- if (sscanf (Arg, "%u", &CodeSizeFactor) != 1 ||
- CodeSizeFactor < 100 ||
- CodeSizeFactor > 1000) {
+ if (sscanf (Arg, "%u%c", &Factor, &BoundsCheck) != 1 ||
+ Factor < 10 || Factor > 1000) {
AbEnd ("Argument for %s is invalid", Opt);
}
+ IS_Set (&CodeSizeFactor, Factor);
}
break;
case 'O':
- Optimize = 1;
+ IS_Set (&Optimize, 1);
P = Arg + 2;
while (*P) {
switch (*P++) {
sscanf (P, "%lx", (long*) &OptDisable);
break;
case 'i':
- FavourSize = 0;
- CodeSizeFactor = 200;
+ IS_Set (&CodeSizeFactor, 200);
break;
case 'r':
IS_Set (&EnableRegVars, 1);
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
ED_IsConstAbsInt (&Arg2.Expr) &&
- (Arg2.Expr.IVal != 0 || CodeSizeFactor > 200)) {
+ (Arg2.Expr.IVal != 0 || IS_Get (&CodeSizeFactor) > 200)) {
/* Remove all of the generated code but the load of the first
* argument.
* requested on the command line, and the code size factor is more than
* 400 (code is 13 bytes vs. 3 for a jsr call).
*/
- } else if (CodeSizeFactor > 400 && IS_Get (&InlineStdFuncs)) {
+ } else if (IS_Get (&CodeSizeFactor) > 400 && IS_Get (&InlineStdFuncs)) {
/* Load the expression into the primary */
LoadExpr (CF_NONE, &Arg);