summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-06-15 01:29:58 +0200
committermetamuffin <metamuffin@disroot.org>2024-06-15 01:29:58 +0200
commit7d78f85cb2da3354f8d05d2054f90d83d84de66f (patch)
treeb2d26b0369cc767c0061c85f28d4e1684f18492b
parentfdedfa4b7e08263ce00e5c0b42b98ab249d5582b (diff)
downloadattocc-7d78f85cb2da3354f8d05d2054f90d83d84de66f.tar
attocc-7d78f85cb2da3354f8d05d2054f90d83d84de66f.tar.bz2
attocc-7d78f85cb2da3354f8d05d2054f90d83d84de66f.tar.zst
makefile
-rw-r--r--.gitignore6
-rw-r--r--attocc.c9
-rw-r--r--makefile15
3 files changed, 28 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index d2886f5..eafa3bb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
-/attocc
-/test*.c
+/*
+!/attocc.c
+!/makefile
+!/.gitignore
diff --git a/attocc.c b/attocc.c
index 57c934a..7d4abf4 100644
--- a/attocc.c
+++ b/attocc.c
@@ -39,6 +39,8 @@ static char *OPERATORS[] = {
">=", "||", "&&", "+", "-", "*", "/", "%", "<",
">", "~", "&", "|", "^", "!", "&", "*", "=",
};
+
+#ifdef DEBUG
static char *OPERATOR_NAMES[] = {
"OP_SIZEOF",
"OP_SHIFT_LEFT",
@@ -90,6 +92,7 @@ static char *SEPERATOR_NAMES[] = {
"SEP_LPAREN", "SEP_RPAREN", "SEP_LSQUARE", "SEP_RSQUARE", "SEP_LCURLY",
"SEP_RCURLY", "SEP_SEMICOLON", "SEP_COMMA", "SEP_DOT", "SEP_COLOR",
};
+#endif
enum keyword {
KW_AUTO,
@@ -396,6 +399,7 @@ struct token *tokenize(char *source) {
return tokens;
}
+#ifdef DEBUG
void debug_tokens(struct token *tokens) {
for (int i = 0; tokens[i].kind != TOK_END; i++) {
switch (tokens[i].kind) {
@@ -420,6 +424,7 @@ void debug_tokens(struct token *tokens) {
}
printf("TOK_END\n");
}
+#endif
int main(int argc, char **argv) {
if (argc < 3) {
@@ -467,7 +472,11 @@ int main(int argc, char **argv) {
struct token *tokens = tokenize(source);
if (!tokens)
return 1;
+
+#ifdef DEBUG
debug_tokens(tokens);
+#endif
+
free(tokens);
return 0;
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..ffd9c32
--- /dev/null
+++ b/makefile
@@ -0,0 +1,15 @@
+.PHONY: all clean
+ALL = attocc attocc-small attocc-debug
+all: $(ALL)
+clean:
+ rm $(ALL)
+
+attocc: attocc.c
+ gcc -O3 -o $@ $<
+
+attocc-debug: attocc.c
+ gcc -DDEBUG -Wall -Wextra -Wpedantic -o $@ $<
+
+attocc-small: attocc.c
+ gcc -Wl,--gc-sections -flto -ffunction-sections -fdata-sections -fPIC -s -Os -o $@ $<
+ strip -x $@