+typedef struct OptFunc OptFunc;
+struct OptFunc {
+ unsigned (*Func) (CodeSeg*); /* Optimizer function */
+ const char* Name; /* Name of the function/group */
+ unsigned CodeSizeFactor; /* Code size factor for this opt func */
+ unsigned long TotalRuns; /* Total number of runs */
+ unsigned long LastRuns; /* Last number of runs */
+ unsigned long TotalChanges; /* Total number of changes */
+ unsigned long LastChanges; /* Last number of changes */
+ char Disabled; /* True if function disabled */
+};
+
+
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
+/* Macro that builds a function description */
+#define OptFuncEntry(func) static OptFuncDesc D##func = { func, #func, 0 }
+
+/* A list of all the function descriptions */
+static OptFunc DOpt65C02Ind = { Opt65C02Ind, "Opt65C02Ind", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptAdd1 = { OptAdd1, "OptAdd1", 60, 0, 0, 0, 0, 0 };
+static OptFunc DOptAdd2 = { OptAdd2, "OptAdd2", 200, 0, 0, 0, 0, 0 };
+static OptFunc DOptAdd3 = { OptAdd3, "OptAdd3", 40, 0, 0, 0, 0, 0 };
+static OptFunc DOptBoolTrans = { OptBoolTrans, "OptBoolTrans", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptBranchDist = { OptBranchDist, "OptBranchDist", 0, 0, 0, 0, 0, 0 };
+static OptFunc DOptCmp1 = { OptCmp1, "OptCmp1", 85, 0, 0, 0, 0, 0 };
+static OptFunc DOptCmp2 = { OptCmp2, "OptCmp2", 75, 0, 0, 0, 0, 0 };
+static OptFunc DOptCmp3 = { OptCmp3, "OptCmp3", 75, 0, 0, 0, 0, 0 };
+static OptFunc DOptCmp4 = { OptCmp4, "OptCmp4", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptCmp5 = { OptCmp5, "OptCmp5", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptCmp6 = { OptCmp6, "OptCmp6", 85, 0, 0, 0, 0, 0 };
+static OptFunc DOptCmp7 = { OptCmp7, "OptCmp7", 50, 0, 0, 0, 0, 0 };
+static OptFunc DOptCondBranches = { OptCondBranches, "OptCondBranches", 80, 0, 0, 0, 0, 0 };
+static OptFunc DOptDeadCode = { OptDeadCode, "OptDeadCode", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptDeadJumps = { OptDeadJumps, "OptDeadJumps", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptDecouple = { OptDecouple, "OptDecouple", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptDupLoads = { OptDupLoads, "OptDupLoads", 0, 0, 0, 0, 0, 0 };
+static OptFunc DOptJumpCascades = { OptJumpCascades, "OptJumpCascades", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptJumpTarget = { OptJumpTarget, "OptJumpTarget", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptRTS = { OptRTS, "OptRTS", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptRTSJumps1 = { OptRTSJumps1, "OptRTSJumps1", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptRTSJumps2 = { OptRTSJumps2, "OptRTSJumps2", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptNegA1 = { OptNegA1, "OptNegA1", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptNegA2 = { OptNegA2, "OptNegA2", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptNegAX1 = { OptNegAX1, "OptNegAX1", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptNegAX2 = { OptNegAX2, "OptNegAX2", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptNegAX3 = { OptNegAX3, "OptNegAX3", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptNegAX4 = { OptNegAX4, "OptNegAX4", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptPtrLoad1 = { OptPtrLoad1, "OptPtrLoad1", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptPtrLoad2 = { OptPtrLoad2, "OptPtrLoad2", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptPtrLoad3 = { OptPtrLoad3, "OptPtrLoad3", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptPtrLoad4 = { OptPtrLoad4, "OptPtrLoad4", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptPtrLoad5 = { OptPtrLoad5, "OptPtrLoad5", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptPtrLoad6 = { OptPtrLoad6, "OptPtrLoad6", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptPtrStore1 = { OptPtrStore1, "OptPtrStore1", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptPtrStore2 = { OptPtrStore2, "OptPtrStore2", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptPush1 = { OptPush1, "OptPush1", 65, 0, 0, 0, 0, 0 };
+static OptFunc DOptShift1 = { OptShift1, "OptShift1", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptShift2 = { OptShift2, "OptShift2", 100, 0, 0, 0, 0, 0 };
+/*static OptFunc DOptSize1 = { OptSize1, "OptSize1", 100, 0, 0, 0, 0, 0 };*/
+static OptFunc DOptSize2 = { OptSize2, "OptSize2", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptStackOps = { OptStackOps, "OptStackOps", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptStoreLoad = { OptStoreLoad, "OptStoreLoad", 0, 0, 0, 0, 0, 0 };
+static OptFunc DOptSub1 = { OptSub1, "OptSub1", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptSub2 = { OptSub2, "OptSub2", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptTest1 = { OptTest1, "OptTest1", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptTransfers = { OptTransfers, "OptTransfers", 0, 0, 0, 0, 0, 0 };
+static OptFunc DOptUnusedLoads = { OptUnusedLoads, "OptUnusedLoads", 0, 0, 0, 0, 0, 0 };
+static OptFunc DOptUnusedStores = { OptUnusedStores, "OptUnusedStores", 0, 0, 0, 0, 0, 0 };
+
+
+/* Table containing all the steps in alphabetical order */
+static OptFunc* OptFuncs[] = {
+ &DOpt65C02Ind,
+ &DOptAdd1,
+ &DOptAdd2,
+ &DOptAdd3,
+ &DOptBoolTrans,
+ &DOptBranchDist,
+ &DOptCmp1,
+ &DOptCmp2,
+ &DOptCmp3,
+ &DOptCmp4,
+ &DOptCmp5,
+ &DOptCmp6,
+ &DOptCmp7,
+ &DOptCondBranches,
+ &DOptDeadCode,
+ &DOptDeadJumps,
+ &DOptDecouple,
+ &DOptDupLoads,
+ &DOptJumpCascades,
+ &DOptJumpTarget,
+ &DOptNegA1,
+ &DOptNegA2,
+ &DOptNegAX1,
+ &DOptNegAX2,
+ &DOptNegAX3,
+ &DOptNegAX4,
+ &DOptPtrLoad1,
+ &DOptPtrLoad2,
+ &DOptPtrLoad3,
+ &DOptPtrLoad4,
+ &DOptPtrLoad5,
+ &DOptPtrLoad6,
+ &DOptPtrStore1,
+ &DOptPtrStore2,
+ &DOptPush1,
+ &DOptRTS,
+ &DOptRTSJumps1,
+ &DOptRTSJumps2,
+ &DOptShift1,
+ &DOptShift2,
+ /*&DOptSize1,*/
+ &DOptSize2,
+ &DOptStackOps,
+ &DOptStoreLoad,
+ &DOptSub1,
+ &DOptSub2,
+ &DOptTest1,
+ &DOptTransfers,
+ &DOptUnusedLoads,
+ &DOptUnusedStores,
+};
+#define OPTFUNC_COUNT (sizeof(OptFuncs) / sizeof(OptFuncs[0]))
+
+
+
+static int CmpOptStep (const void* Key, const void* Func)
+/* Compare function for bsearch */
+{
+ return strcmp (Key, (*(const OptFunc**)Func)->Name);
+}
+
+
+
+static OptFunc* FindOptFunc (const char* Name)
+/* Find an optimizer step by name in the table and return a pointer. Return
+ * NULL if no such step is found.