]> git.sur5r.net Git - cc65/blob - src/cc65/codeinfo.c
0dc89acb1baf92fe185b55fce8850d69fc0128bd
[cc65] / src / cc65 / codeinfo.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                codeinfo.c                                 */
4 /*                                                                           */
5 /*                  Additional information about 6502 code                   */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include <stdlib.h>
37 #include <string.h>
38
39 /* cc65 */
40 #include "codeinfo.h"
41
42
43
44 /*****************************************************************************/
45 /*                                   Data                                    */
46 /*****************************************************************************/
47
48
49
50 /* Table listing the function names and code info values for known internally
51  * used functions. This table should get auto-generated in the future.
52  */
53 typedef struct FuncInfo FuncInfo;
54 struct FuncInfo {
55     const char*     Name;       /* Function name */
56     unsigned char   Use;        /* Register usage */
57     unsigned char   Chg;        /* Changed/destroyed registers */
58 };
59
60 static const FuncInfo FuncInfoTable[] = {
61     { "booleq",         REG_NONE,       REG_AX  },
62     { "boolge",         REG_NONE,       REG_AX  },
63     { "boolgt",         REG_NONE,       REG_AX  },
64     { "boolle",         REG_NONE,       REG_AX  },
65     { "boollt",         REG_NONE,       REG_AX  },
66     { "boolne",         REG_NONE,       REG_AX  },
67     { "booluge",        REG_NONE,       REG_AX  },
68     { "boolugt",        REG_NONE,       REG_AX  },
69     { "boolule",        REG_NONE,       REG_AX  },
70     { "boolult",        REG_NONE,       REG_AX  },
71     { "decax1",         REG_AX,         REG_AX  },
72     { "decax2",         REG_AX,         REG_AX  },
73     { "decax3",         REG_AX,         REG_AX  },
74     { "decax4",         REG_AX,         REG_AX  },
75     { "decax5",         REG_AX,         REG_AX  },
76     { "decax6",         REG_AX,         REG_AX  },
77     { "decax7",         REG_AX,         REG_AX  },
78     { "decax8",         REG_AX,         REG_AX  },
79     { "decaxy",         REG_AXY,        REG_AX  },
80     { "decsp2",         REG_NONE,       REG_A   },
81     { "decsp3",         REG_NONE,       REG_A   },
82     { "decsp4",         REG_NONE,       REG_A   },
83     { "decsp5",         REG_NONE,       REG_A   },
84     { "decsp6",         REG_NONE,       REG_A   },
85     { "decsp7",         REG_NONE,       REG_A   },
86     { "decsp8",         REG_NONE,       REG_A   },
87     { "ldax0sp",        REG_Y,          REG_AX  },
88     { "ldaxysp",        REG_Y,          REG_AX  },
89     { "pusha",          REG_A,          REG_Y   },
90     { "pusha0",         REG_A,          REG_XY  },
91     { "pushax",         REG_AX,         REG_Y   },
92     { "pushw0sp",       REG_NONE,       REG_AXY },
93     { "pushwysp",       REG_Y,          REG_AXY },
94     { "tosicmp",        REG_AX,         REG_AXY },
95 };
96 #define FuncInfoCount   (sizeof(FuncInfoTable) / sizeof(FuncInfoTable[0]))
97
98
99
100 /*****************************************************************************/
101 /*                                   Code                                    */
102 /*****************************************************************************/
103
104
105
106 static int CompareFuncInfo (const void* Key, const void* Info)
107 /* Compare function for bsearch */
108 {
109     return strcmp (Key, ((const FuncInfo*) Info)->Name);
110 }
111
112
113
114 void GetFuncInfo (const char* Name, unsigned char* Use, unsigned char* Chg)
115 /* For the given function, lookup register information and combine it with
116  * the information already in place. If the function is unknown, assume it
117  * will use all registers and load all registers.
118  * See codeinfo.h for possible flags.
119  */
120 {
121     /* Search for the function */
122     const FuncInfo* Info = bsearch (Name, FuncInfoTable, FuncInfoCount,
123                                     sizeof(FuncInfo), CompareFuncInfo);
124
125     /* Do we know the function? */
126     if (Info) {
127         /* Use the information we have */
128         *Use |= Info->Use;
129         *Chg |= Info->Chg;
130     } else {
131         *Use |= REG_AXY;
132         *Chg |= REG_AXY;
133     }
134 }
135
136
137
138