Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 54 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ version = "0.1.0"
edition = "2024"

[dependencies]
anyhow = "1.0.100"
ntest = "0.9.3"
cranelift = "0.131.0"
cranelift-codegen = "0.131.0"
cranelift-frontend = "0.131.0"
cranelift-module = "0.131.0"
cranelift-object = "0.131.0"
target-lexicon = "0.13"
32 changes: 21 additions & 11 deletions src/emitter.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
//! The emitter for turning the abstract syntax tree into LLVM IR
//! The emitter for turning the abstract syntax tree into Cranelift IR.

// Temp used for the emitter placeholder
use std::marker::PhantomData;
use cranelift_codegen::{isa, settings};
use cranelift_frontend::FunctionBuilderContext;
use cranelift_module::default_libcall_names;
use cranelift_object::{ObjectBuilder, ObjectModule};
use target_lexicon::HOST;

/// The emiter structure, including a lifetime.
///
/// See lexer.rs about doing away with lifetimes like this
/// The emitter state.
#[allow(dead_code)]
pub struct Emitter<'ctx> {
temporary: PhantomData<&'ctx ()>,
pub struct Emitter {
module: ObjectModule,
function_context: FunctionBuilderContext,
}

#[allow(unused_variables, dead_code)]
impl Emitter<'_> {
pub fn new(module_name: &str) -> Self {
unimplemented!()
impl Emitter {
pub fn new() -> anyhow::Result<Self> {
let shared_flags = settings::Flags::new(settings::builder());
let isa_builder = isa::lookup(HOST)?;
let isa = isa_builder.finish(shared_flags)?;
let builder = ObjectBuilder::new(isa, "bcomp", default_libcall_names())?;

Ok(Self {
module: ObjectModule::new(builder),
function_context: FunctionBuilderContext::new(),
})
}
}
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

//! A compiler for the basic language

use crate::parser::Parser;

mod emitter;
mod lexer;
mod parser;

fn main() {
println!("Hello, world!");
let mut parser = Parser::from_input("1");

let _program = parser.parse_program();
}
Loading