Improve backwards compatibility with GNU Make

This commit is contained in:
Justine Tunney 2021-05-02 07:48:59 -07:00
parent fabf7f9f02
commit 1f2288be6e
18 changed files with 412 additions and 96 deletions

View file

@ -136,7 +136,12 @@
#define ISRIP 0x00080000
#define ISREG 0x00100000
#define APPEND(L) L.p = realloc(L.p, ++L.n * sizeof(*L.p))
#define APPEND(L) \
if (++L.n > L.c) { \
L.c = L.n + 2 + (L.c >> 1); \
L.p = realloc(L.p, L.c * sizeof(*L.p)); \
}
#define IS(P, N, S) (N == sizeof(S) - 1 && !strncasecmp(P, S, sizeof(S) - 1))
#define MAX(X, Y) ((Y) < (X) ? (X) : (Y))
#define READ128BE(S) ((unsigned __int128)READ64BE(S) << 64 | READ64BE((S) + 8))
@ -152,29 +157,29 @@ struct As {
bool inhibiterr;
bool inhibitwarn;
struct Ints {
unsigned long n;
unsigned long n, c;
long *p;
} ints;
struct Floats {
unsigned long n;
unsigned long n, c;
long double *p;
} floats;
struct Slices {
unsigned long n;
unsigned long n, c;
struct Slice {
unsigned long n;
unsigned long n, c;
char *p;
} * p;
} slices;
struct Sauces {
unsigned long n;
unsigned long n, c;
struct Sauce {
unsigned path; // strings
unsigned line; // 1-indexed
} * p;
} sauces;
struct Things {
unsigned long n;
unsigned long n, c;
struct Thing {
enum ThingType {
TT_INT,
@ -189,7 +194,7 @@ struct As {
} * p;
} things;
struct Sections {
unsigned long n;
unsigned long n, c;
struct Section {
unsigned name; // strings
int flags;
@ -199,7 +204,7 @@ struct As {
} * p;
} sections;
struct Symbols {
unsigned long n;
unsigned long n, c;
struct Symbol {
bool isused;
unsigned char stb; // STB_*
@ -220,7 +225,7 @@ struct As {
} * p;
} symbolindex;
struct Labels {
unsigned long n;
unsigned long n, c;
struct Label {
unsigned id;
unsigned tok; // things
@ -228,7 +233,7 @@ struct As {
} * p;
} labels;
struct Relas {
unsigned long n;
unsigned long n, c;
struct Rela {
bool isdead;
int kind; // R_X86_64_{16,32,64,PC8,PC32,PLT32,GOTPCRELX,...}
@ -239,7 +244,7 @@ struct As {
} * p;
} relas;
struct Exprs {
unsigned long n;
unsigned long n, c;
struct Expr {
enum ExprKind {
EX_INT, // integer
@ -277,11 +282,11 @@ struct As {
} * p;
} exprs;
struct Strings {
unsigned long n;
unsigned long n, c;
char **p;
} strings, incpaths;
struct SectionStack {
unsigned long n;
unsigned long n, c;
int *p;
} sectionstack;
};
@ -805,8 +810,7 @@ static void Tokenize(struct As *a, int path) {
continue;
}
if (c == '"') {
buf.n = 0;
buf.p = NULL;
memset(&buf, 0, sizeof(buf));
for (i = 1; (c = p[i++]);) {
if (c == '"') break;
c = ReadCharLiteral(&buf, c, p, &i);