aboutsummaryrefslogtreecommitdiff
path: root/include/cu/debug.h
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2023-04-01 10:53:44 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2023-04-01 10:53:44 +0300
commitad18c24e7223b1c0d48a20ba9b618c4eaf1e3a84 (patch)
tree86f3cba0b5b4bf4b7e49b96ceb61bec8b0be2780 /include/cu/debug.h
parentb8211cda90f8a9cb14657d3328cfa9ec78722c5c (diff)
downloadek-ad18c24e7223b1c0d48a20ba9b618c4eaf1e3a84.tar.gz
ek-ad18c24e7223b1c0d48a20ba9b618c4eaf1e3a84.zip
fix gitignore
Diffstat (limited to 'include/cu/debug.h')
-rw-r--r--include/cu/debug.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/include/cu/debug.h b/include/cu/debug.h
new file mode 100644
index 0000000..3099b3c
--- /dev/null
+++ b/include/cu/debug.h
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+
+#ifndef CT_DEBUG_H
+#define CT_DEBUG_H
+
+#include <stdio.h>
+
+#include <cu/ast.h>
+
+#if DEBUG
+#define debug(x, ...) \
+ do {fprintf(stderr, "debug: " x "\n",##__VA_ARGS__);} while(0)
+#else
+#define debug(x, ...)
+#endif
+
+#define error(x, ...) \
+ do {fprintf(stderr, "error: " x "\n",##__VA_ARGS__);} while(0)
+
+#define warn(x, ...) \
+ do {fprintf(stderr, "warn: " x "\n",##__VA_ARGS__);} while(0)
+
+#define info(x, ...) \
+ do {fprintf(stderr, "info: " x "\n",##__VA_ARGS__);} while(0)
+
+
+struct file_ctx {
+ const char *fname;
+ const char *fbuf;
+};
+
+char *type_str(struct ast_node *type);
+char *call_str(struct ast_node *call);
+void semantic_info(struct file_ctx ctx, struct ast_node *node, const char *fmt,
+ ...);
+void semantic_warn(struct file_ctx ctx, struct ast_node *node, const char *fmt,
+ ...);
+void semantic_error(struct file_ctx ctx, struct ast_node *node, const char *fmt,
+ ...);
+void internal_error(const char *fmt, ...);
+
+enum issue_level {
+ SRC_INFO,
+ SRC_WARN,
+ SRC_ERROR
+};
+
+struct src_issue {
+ enum issue_level level;
+ struct src_loc loc;
+ struct file_ctx fctx;
+ size_t offset;
+};
+
+void src_issue(struct src_issue issue, const char *err_msg, ...);
+#endif /* CT_DEBUG_H */