Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakFarmer committed Nov 3, 2023
1 parent 67cde14 commit ae19086
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion codegen/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'ink, 'b> RecursiveBuilder<'ink, 'b> {
Node::Expression(n) => {
let expression_builder = ExpressionBuilder::new(self.llvm);
expression_builder.build_expression(n)
},
}
_ => panic!("Unknown node"),
}
}
Expand Down
31 changes: 20 additions & 11 deletions codegen/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ impl<'ev> ExpressionValue<'ev> {

pub fn as_r_value(&self, llvm: &Llvm<'ev>, name: Option<&str>) -> BasicValueEnum<'ev> {
match self {
ExpressionValue::LValue(pointer) => llvm.load_pointer(pointer, name.as_deref().unwrap_or("")),
ExpressionValue::LValue(pointer) => {
llvm.load_pointer(pointer, name.as_deref().unwrap_or(""))
}
ExpressionValue::RValue(value) => *value,
}
}
Expand Down Expand Up @@ -101,7 +103,10 @@ impl<'ink, 'b> ExpressionBuilder<'ink, 'b> {
self.llvm.i32_type().const_int(0, false),
"not",
),
TokenType::Minus => self.llvm.builder.build_int_neg(right.into_int_value(), "neg"),
TokenType::Minus => self
.llvm
.builder
.build_int_neg(right.into_int_value(), "neg"),
_ => panic!("Unknown operator"),
};

Expand Down Expand Up @@ -131,20 +136,24 @@ impl<'ink, 'b> ExpressionBuilder<'ink, 'b> {
TokenType::Minus => self.llvm.builder.build_int_sub(left, right, "sub"),
TokenType::Asterisk => self.llvm.builder.build_int_mul(left, right, "mul"),
TokenType::Slash => self.llvm.builder.build_int_unsigned_div(left, right, "div"),
TokenType::Lt => {
self.llvm.builder
.build_int_compare(inkwell::IntPredicate::SLT, left, right, "less_than")
}
TokenType::Lt => self.llvm.builder.build_int_compare(
inkwell::IntPredicate::SLT,
left,
right,
"less_than",
),
TokenType::Gt => self.llvm.builder.build_int_compare(
inkwell::IntPredicate::SGT,
left,
right,
"greater_than",
),
TokenType::Eq => {
self.llvm.builder
.build_int_compare(inkwell::IntPredicate::EQ, left, right, "equal_to")
}
TokenType::Eq => self.llvm.builder.build_int_compare(
inkwell::IntPredicate::EQ,
left,
right,
"equal_to",
),
TokenType::NotEq => self.llvm.builder.build_int_compare(
inkwell::IntPredicate::NE,
left,
Expand All @@ -156,4 +165,4 @@ impl<'ink, 'b> ExpressionBuilder<'ink, 'b> {

BasicValueEnum::IntValue(result)
}
}
}
6 changes: 5 additions & 1 deletion codegen/src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ impl<'ink, 'b> RecursiveBuilder<'ink, 'b> {
Some(value) => self
.llvm
.builder
.build_load(self.llvm.i32_type(), *value, identifier.token.value.as_str())
.build_load(
self.llvm.i32_type(),
*value,
identifier.token.value.as_str(),
)
.into_int_value(),
None => panic!("Unknown identifier"),
};
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![deny(elided_lifetimes_in_paths)]

use anyhow::Error;
use inkwell::{context::Context, OptimizationLevel, types::IntType};
use inkwell::{context::Context, types::IntType, OptimizationLevel};
use llvm::Llvm;

pub mod builder;
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'ink, 'b> RecursiveBuilder<'ink, 'b> {
Statement::Expr(expression) => {
let expression_builder = ExpressionBuilder::new(self.llvm);
expression_builder.build_expression(expression)
},
}
Statement::Return(_return_statement) => todo!(),
_ => panic!("Unknown statement"),
}
Expand Down
2 changes: 1 addition & 1 deletion codegen/tests/symbol_table_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use anyhow::Error;
use codegen::symbol_table::{SymbolTable, SymbolScope, Symbol};
use codegen::symbol_table::{Symbol, SymbolScope, SymbolTable};

#[test]
fn test_define() -> Result<(), Error> {
Expand Down
12 changes: 5 additions & 7 deletions llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ use inkwell::{
builder::Builder,
context::Context,
execution_engine::{ExecutionEngine, JitFunction},
module::Module, values::{PointerValue, BasicValueEnum, GlobalValue}, types::BasicTypeEnum,
module::Module,
types::BasicTypeEnum,
values::{BasicValueEnum, GlobalValue, PointerValue},
};

type MainFn = unsafe extern "C" fn() -> i32;

pub trait GlobalValueExt {
pub trait GlobalValueExt {
fn make_constant(self) -> Self;
fn make_external(self) -> Self;
fn make_private(self) -> Self;
Expand Down Expand Up @@ -46,11 +48,7 @@ pub struct Llvm<'ctx> {

impl<'ctx> Llvm<'ctx> {
/// LLVM constructor
pub fn new(
builder: Builder<'ctx>,
context: &'ctx Context,
module: Module<'ctx>,
) -> Llvm<'ctx> {
pub fn new(builder: Builder<'ctx>, context: &'ctx Context, module: Module<'ctx>) -> Llvm<'ctx> {
Llvm {
builder,
context,
Expand Down
2 changes: 1 addition & 1 deletion source/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ pub fn create_source_code(source: &str) -> Source {
path: None,
contents: source.to_string(),
}
}
}

0 comments on commit ae19086

Please sign in to comment.