diff options
Diffstat (limited to 'willow/tools/willowc/include/ast.hpp')
| -rw-r--r-- | willow/tools/willowc/include/ast.hpp | 62 |
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 |