Deuglify use of _PARSE_COMMANDS macro expansions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
diff --git a/api.c b/api.c
index 75c1c4f..c70446d 100644
--- a/api.c
+++ b/api.c
@@ -1211,6 +1211,9 @@ static struct api_data *print_data(struct api_data *root, char *buf, bool isjson
return root;
}
+#define DRIVER_COUNT_DRV(X) if (devices[i]->drv->drv_id == DRIVER_##X) \
+ count++;
+
#ifdef HAVE_AN_ASIC
static int numascs(void)
{
@@ -1219,11 +1222,7 @@ static int numascs(void)
rd_lock(&devices_lock);
for (i = 0; i < total_devices; i++) {
-#define DRIVER_ADD_COMMAND(X) \
- if (devices[i]->drv->drv_id == DRIVER_##X) \
- count++;
- ASIC_PARSE_COMMANDS
-#undef DRIVER_ADD_COMMAND
+ ASIC_PARSE_COMMANDS(DRIVER_COUNT_DRV)
}
rd_unlock(&devices_lock);
return count;
@@ -1236,11 +1235,7 @@ static int ascdevice(int ascid)
rd_lock(&devices_lock);
for (i = 0; i < total_devices; i++) {
-#define DRIVER_ADD_COMMAND(X) \
- if (devices[i]->drv->drv_id == DRIVER_##X) \
- count++;
- ASIC_PARSE_COMMANDS
-#undef DRIVER_ADD_COMMAND
+ ASIC_PARSE_COMMANDS(DRIVER_COUNT_DRV)
if (count == (ascid + 1))
goto foundit;
}
@@ -1263,11 +1258,7 @@ static int numpgas(void)
rd_lock(&devices_lock);
for (i = 0; i < total_devices; i++) {
-#define DRIVER_ADD_COMMAND(X) \
- if (devices[i]->drv->drv_id == DRIVER_##X) \
- count++;
- FPGA_PARSE_COMMANDS
-#undef DRIVER_ADD_COMMAND
+ FPGA_PARSE_COMMANDS(DRIVER_COUNT_DRV)
}
rd_unlock(&devices_lock);
return count;
@@ -1280,11 +1271,7 @@ static int pgadevice(int pgaid)
rd_lock(&devices_lock);
for (i = 0; i < total_devices; i++) {
-#define DRIVER_ADD_COMMAND(X) \
- if (devices[i]->drv->drv_id == DRIVER_##X) \
- count++;
- FPGA_PARSE_COMMANDS
-#undef DRIVER_ADD_COMMAND
+ FPGA_PARSE_COMMANDS(DRIVER_COUNT_DRV)
if (count == (pgaid + 1))
goto foundit;
}
diff --git a/cgminer.c b/cgminer.c
index 19f2a0d..337722a 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -7604,6 +7604,8 @@ static void hotplug_process()
switch_logsize(true);
}
+#define DRIVER_DRV_DETECT_HOTPLUG(X) X##_drv.drv_detect(true);
+
static void *hotplug_thread(void __maybe_unused *userdata)
{
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
@@ -7625,9 +7627,7 @@ static void *hotplug_thread(void __maybe_unused *userdata)
/* Use the DRIVER_PARSE_COMMANDS macro to detect all
* devices */
-#define DRIVER_ADD_COMMAND(X) X##_drv.drv_detect(true);
- DRIVER_PARSE_COMMANDS
-#undef DRIVER_ADD_COMMAND
+ DRIVER_PARSE_COMMANDS(DRIVER_DRV_DETECT_HOTPLUG)
if (new_devices)
hotplug_process();
@@ -7653,6 +7653,9 @@ static void probe_pools(void)
}
}
+#define DRIVER_FILL_DEVICE_DRV(X) fill_device_drv(&X##_drv);
+#define DRIVER_DRV_DETECT_ALL(X) X##_drv.drv_detect(false);
+
int main(int argc, char *argv[])
{
struct sigaction handler;
@@ -7834,17 +7837,13 @@ int main(int argc, char *argv[])
#endif
/* Use the DRIVER_PARSE_COMMANDS macro to fill all the device_drvs */
-#define DRIVER_ADD_COMMAND(X) fill_device_drv(&X##_drv);
- DRIVER_PARSE_COMMANDS
-#undef DRIVER_ADD_COMMAND
+ DRIVER_PARSE_COMMANDS(DRIVER_FILL_DEVICE_DRV)
if (opt_scrypt)
opencl_drv.drv_detect(false);
else {
/* Use the DRIVER_PARSE_COMMANDS macro to detect all devices */
-#define DRIVER_ADD_COMMAND(X) X##_drv.drv_detect(false);
- DRIVER_PARSE_COMMANDS
-#undef DRIVER_ADD_COMMAND
+ DRIVER_PARSE_COMMANDS(DRIVER_DRV_DETECT_ALL)
}
if (opt_display_devs) {
diff --git a/miner.h b/miner.h
index 42f9743..d945740 100644
--- a/miner.h
+++ b/miner.h
@@ -234,34 +234,33 @@ static inline int fsync (int fd)
* trying to claim same chip but different devices. Adding a device here will
* update all macros in the code that use the *_PARSE_COMMANDS macros for each
* listed driver. */
-#define FPGA_PARSE_COMMANDS \
+#define FPGA_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
DRIVER_ADD_COMMAND(bitforce) \
DRIVER_ADD_COMMAND(icarus) \
DRIVER_ADD_COMMAND(modminer) \
DRIVER_ADD_COMMAND(ztex)
-#define ASIC_PARSE_COMMANDS \
+#define ASIC_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
DRIVER_ADD_COMMAND(bflsc) \
DRIVER_ADD_COMMAND(bitfury) \
DRIVER_ADD_COMMAND(avalon)
-#define DRIVER_PARSE_COMMANDS \
+#define DRIVER_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
DRIVER_ADD_COMMAND(opencl) \
- FPGA_PARSE_COMMANDS \
- ASIC_PARSE_COMMANDS
+ FPGA_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
+ ASIC_PARSE_COMMANDS(DRIVER_ADD_COMMAND)
+
+#define DRIVER_ENUM(X) DRIVER_##X,
+#define DRIVER_PROTOTYPE(X) struct device_drv X##_drv;
/* Create drv_driver enum from DRIVER_PARSE_COMMANDS macro */
-#define DRIVER_ADD_COMMAND(X) DRIVER_##X,
enum drv_driver {
- DRIVER_PARSE_COMMANDS
+ DRIVER_PARSE_COMMANDS(DRIVER_ENUM)
DRIVER_MAX
};
-#undef DRIVER_ADD_COMMAND
/* Use DRIVER_PARSE_COMMANDS to generate extern device_drv prototypes */
-#define DRIVER_ADD_COMMAND(X) struct device_drv X##_drv;
-DRIVER_PARSE_COMMANDS;
-#undef DRIVER_ADD_COMMAND
+DRIVER_PARSE_COMMANDS(DRIVER_PROTOTYPE)
enum alive {
LIFE_WELL,
diff --git a/usbutils.c b/usbutils.c
index eae597f..e333b59 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -1840,6 +1840,9 @@ static struct usb_find_devices *usb_check_each(int drvnum, struct device_drv *dr
return NULL;
}
+#define DRIVER_USB_CHECK_EACH(X) if (drv->drv_id == DRIVER_##X) \
+ return usb_check_each(DRIVER_##X, drv, dev);
+
static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv, __maybe_unused struct libusb_device *dev)
{
if (drv_count[drv->drv_id].count >= drv_count[drv->drv_id].limit) {
@@ -1849,11 +1852,7 @@ static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv,
return NULL;
}
-#define DRIVER_ADD_COMMAND(X) \
- if (drv->drv_id == DRIVER_##X) \
- return usb_check_each(DRIVER_##X, drv, dev);
- DRIVER_PARSE_COMMANDS
-#undef DRIVER_ADD_COMMAND
+ DRIVER_PARSE_COMMANDS(DRIVER_USB_CHECK_EACH)
return NULL;
}
@@ -3125,6 +3124,10 @@ void usb_cleanup()
cgsem_destroy(&usb_resource_sem);
}
+#define DRIVER_COUNT_FOUND(X) if (strcasecmp(ptr, X##_drv.name) == 0) { \
+ drv_count[X##_drv.drv_id].limit = lim; \
+ found = true; \
+ }
void usb_initialise()
{
char *fre, *ptr, *comma, *colon;
@@ -3210,12 +3213,7 @@ void usb_initialise()
found = false;
/* Use the DRIVER_PARSE_COMMANDS macro to iterate
* over all the drivers. */
-#define DRIVER_ADD_COMMAND(X) if (strcasecmp(ptr, X##_drv.name) == 0) { \
- drv_count[X##_drv.drv_id].limit = lim; \
- found = true; \
- }
- DRIVER_PARSE_COMMANDS
-#undef DRIVER_ADD_COMMAND
+ DRIVER_PARSE_COMMANDS(DRIVER_COUNT_FOUND)
if (!found)
quit(1, "Invalid --usb DRV:limit - unknown DRV='%s'", ptr);