summaryrefslogtreecommitdiff
path: root/willow/tools/willowc/include/ast.hpp
diff options
context:
space:
mode:
authorStefan Weigl-Bosker <stefan@s00.xyz>2026-02-03 14:59:53 -0500
committerGitHub <noreply@github.com>2026-02-03 14:59:53 -0500
commitadd95b14f74e6dbe04a6efe98ff0f20424930b73 (patch)
tree13ce413ee4190a4c8f8743c7740aaa8d04353f14 /willow/tools/willowc/include/ast.hpp
parentc5b2905c5a64433f8519531a77d3acc42d881f17 (diff)
downloadcompiler-add95b14f74e6dbe04a6efe98ff0f20424930b73.tar.gz
[willow]: initial frontend work, unit tests (#8)dev/stefan
Diffstat (limited to 'willow/tools/willowc/include/ast.hpp')
-rw-r--r--willow/tools/willowc/include/ast.hpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/willow/tools/willowc/include/ast.hpp b/willow/tools/willowc/include/ast.hpp
new file mode 100644
index 0000000..8c59067
--- /dev/null
+++ b/willow/tools/willowc/include/ast.hpp
@@ -0,0 +1,62 @@
+#ifndef WILLOWC_INCLUDE_AST_HPP
+#define WILLOWC_INCLUDE_AST_HPP
+
+#include <cstdint>
+#include <memory>
+#include <vector>
+
+#include <willow/IR/Instructions.h>
+#include <willow/IR/Types.h>
+
+#include <tokenizer.hpp>
+
+namespace willowc {
+
+using Opcode = willow::Instruction::Opcode;
+using TokenIndex = std::size_t;
+
+// this is like willow::ValueKind, but treats groups all ssa values into 'Value'
+// (because they can't be differentiated by syntax alone)
+enum class ExprKind { Constant, BasicBlock, Function, Value };
+
+struct ExprAST {
+ ExprKind kind;
+
+ std::string name;
+ // token??
+};
+
+struct InstAST {
+ Opcode op;
+ std::string name;
+
+ std::vector<std::unique_ptr<ExprAST>> args;
+};
+
+struct BlockAST {
+ std::string label;
+ std::vector<std::unique_ptr<InstAST>> body;
+};
+
+struct ParameterAST {
+ std::string name;
+ willow::Type type;
+};
+
+struct FunctionDeclAST {
+ std::string name;
+ std::vector<std::unique_ptr<ParameterAST>> parameters;
+ std::string returntype;
+
+ std::vector<std::unique_ptr<BlockAST>> body;
+ // TODO: movable symbol table
+};
+
+struct ModuleAST {
+ std::vector<std::unique_ptr<FunctionDeclAST>> Functions;
+ // TODO: imports, symbol table
+};
+
+}; // namespace willowc
+
+#endif // WILLOWC_INCLUDE_AST_HPP