2 * Copyright (C) 2010-2011 Marcin KoĆcielnicki <koriakin@0x04.net>
3 * Copyright (C) 2010 Francisco Jerez <currojerez@riseup.net>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
33 #define ADDARRAY(a, e) \
35 if ((a ## num) >= (a ## max)) { \
40 (a) = realloc((a), (a ## max)*sizeof(*(a))); \
42 (a)[(a ## num)++] = (e); \
45 #define FINDARRAY(a, tmp, pred) \
49 for (__i = 0; __i < (a ## num); __i++) { \
55 tmp = ((pred) ? tmp : NULL); \
59 static inline int clog2(uint64_t x
) {
63 while (x
- 1 > (1ull << r
) - 1)
68 #define ARRAY_SIZE(a) (sizeof (a) / sizeof *(a))
72 typeof (a) _a = (a); \
73 typeof (b) _b = (b); \
79 typeof (a) _a = (a); \
80 typeof (b) _b = (b); \
84 #define CEILDIV(a, b) (((a) + (b) - 1)/(b))
86 #define extr(a, b, c) ((uint64_t)(a) << (64 - (b) - (c)) >> (64 - (c)))
87 #define extrs(a, b, c) ((int64_t)(a) << (64 - (b) - (c)) >> (64 - (c)))
88 #define sext(a, b) extrs(a, 0, b+1)
89 #define bflmask(a) ((2ull << ((a)-1)) - 1)
90 #define insrt(a, b, c, d) ((a) = ((a) & ~(bflmask(c) << (b))) | ((d) & bflmask(c)) << (b))
100 #define LOC_FORMAT(loc, str) "%s:%d.%d-%d.%d: " str, (loc).file, (loc).lstart, (loc).cstart, (loc).lend, (loc).cend
102 uint32_t elf_hash(const char *str
);
104 FILE *find_in_path(const char *name
, const char *path
, char **pfullname
);
111 void print_escaped_astr(FILE *out
, struct astr
*astr
);
113 char *aprintf(const char *format
, ...);