diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index a4d3ae9..10a9435 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -2,4 +2,11 @@ - [Workshop Intro: About MLIR and LLVM](./about.md) - [MLIR Basics](./mlir_basics.md) -- [Implementing the language: Part 1](./lang_1.md) +- [Workshop: Setup](./workshop_p1.md) +- [Workshop: Walk through the prepared codebase](./workshop_p2.md) +- [Workshop: Compiling Expressions](./workshop_p3.md) +- [Workshop: Compiling Let](./workshop_p4.md) +- [Workshop: Compiling Return](./workshop_p5.md) +- [Workshop: Compiling If/Else](./workshop_p6.md) +- [Workshop: Compiling Function calls](./workshop_p7.md) +- [Workshop: Extras](./workshop_p8.md) diff --git a/docs/src/about.md b/docs/src/about.md index 361b7d1..d82f3ef 100644 --- a/docs/src/about.md +++ b/docs/src/about.md @@ -1,6 +1,6 @@ # About this Workshop -In this workshop you will learn a bit about what is LLVM and MLIR, by implementing a really simple programming language compiler. This language only has variables of type u64, and only supports simple functions with arguments, basic arithmetic operations and if else statements. +In this workshop you will learn a bit about what is LLVM and MLIR, by implementing a really simple programming language compiler. This language only has variables of type i64, and only supports simple functions with arguments, basic arithmetic operations and if else statements. # What is LLVM? @@ -127,7 +127,7 @@ In our case, we want to have a compiled program, so LLVM IR will be our target, # Other Learning Resources -These are extra resources, they aren't meant to be read now in the workshop but they are here for your convenience. +> These are extra resources, they aren't meant to be read now in the workshop but they are here for your convenience. Resources marked with **→** are best. diff --git a/docs/src/lang_1.md b/docs/src/workshop_p1.md similarity index 87% rename from docs/src/lang_1.md rename to docs/src/workshop_p1.md index 501a8fb..03735b3 100644 --- a/docs/src/lang_1.md +++ b/docs/src/workshop_p1.md @@ -1,4 +1,4 @@ -# Implementing the language: 1 +# Workshop: Setup ## Project Setup @@ -23,4 +23,8 @@ export LLVM_SYS_191_PREFIX="$(brew --prefix llvm@19)" export TABLEGEN_190_PREFIX="$(brew --prefix llvm@19)" ``` -TODO +Verify you can build the project: + +```bash +cargo build +``` diff --git a/docs/src/workshop_p2.md b/docs/src/workshop_p2.md new file mode 100644 index 0000000..1d046d2 --- /dev/null +++ b/docs/src/workshop_p2.md @@ -0,0 +1 @@ +# Workshop: Walkthrough the prepared codebase diff --git a/docs/src/workshop_p3.md b/docs/src/workshop_p3.md new file mode 100644 index 0000000..510bbb9 --- /dev/null +++ b/docs/src/workshop_p3.md @@ -0,0 +1 @@ +# Workshop: Compiling Expressions diff --git a/docs/src/workshop_p4.md b/docs/src/workshop_p4.md new file mode 100644 index 0000000..1bf3b2a --- /dev/null +++ b/docs/src/workshop_p4.md @@ -0,0 +1 @@ +# Workshop: Compiling Let diff --git a/docs/src/workshop_p5.md b/docs/src/workshop_p5.md new file mode 100644 index 0000000..a1ec8ff --- /dev/null +++ b/docs/src/workshop_p5.md @@ -0,0 +1 @@ +# Workshop: Compiling Return diff --git a/docs/src/workshop_p6.md b/docs/src/workshop_p6.md new file mode 100644 index 0000000..4b50c5f --- /dev/null +++ b/docs/src/workshop_p6.md @@ -0,0 +1 @@ +# Workshop: Compiling If/Else diff --git a/docs/src/workshop_p7.md b/docs/src/workshop_p7.md new file mode 100644 index 0000000..6584552 --- /dev/null +++ b/docs/src/workshop_p7.md @@ -0,0 +1 @@ +# Workshop: Compiling Function calls diff --git a/docs/src/workshop_p8.md b/docs/src/workshop_p8.md new file mode 100644 index 0000000..507c519 --- /dev/null +++ b/docs/src/workshop_p8.md @@ -0,0 +1 @@ +# Workshop: Extras diff --git a/src/ast.rs b/src/ast.rs index 0ff7bce..d0fd7b0 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,6 +1,6 @@ #[derive(Debug, Clone)] pub enum Expr { - Number(i32), + Number(i64), Variable(String), Op(Box, Opcode, Box), } diff --git a/src/main.rs b/src/main.rs index f8b2884..a4c0060 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,9 @@ use clap::Parser; use codegen::{compile_program, ModuleCtx}; use lalrpop_util::lalrpop_mod; use melior::{ + dialect::DialectRegistry, ir::{Location, Module}, + utility::register_all_dialects, Context, }; @@ -38,7 +40,13 @@ fn main() { let source = fs::read_to_string(&args.input).unwrap(); let program = grammar::ProgramParser::new().parse(&source).unwrap(); + // We need a registry to hold all the dialects + let registry = DialectRegistry::new(); + // Register all dialects that come with MLIR. + register_all_dialects(®istry); let context = Context::new(); + context.append_dialect_registry(®istry); + context.load_all_available_dialects(); let ctx = ModuleCtx { ctx: &context, module: Module::new(Location::unknown(&context)),