29 lines
No EOL
848 B
Rust
29 lines
No EOL
848 B
Rust
use std::collections::HashMap;
|
|
|
|
use inkwell::{builder::Builder, context::Context, module::Module, values::{FunctionValue, PointerValue}};
|
|
|
|
use crate::code_generation::Function;
|
|
|
|
pub struct Compiler<'a, 'ctx> {
|
|
pub context: &'ctx Context,
|
|
pub builder: &'a Builder<'ctx>,
|
|
pub module: &'a Module<'ctx>,
|
|
pub function: &'a Function,
|
|
|
|
variables: HashMap<String, PointerValue<'ctx>>,
|
|
fn_value_opt: Option<FunctionValue<'ctx>>
|
|
}
|
|
|
|
impl<'a, 'ctx> Compiler<'a, 'ctx> {
|
|
/// Gets a defined function given its name.
|
|
#[inline]
|
|
fn get_function(&self, name: &str) -> Option<FunctionValue<'ctx>> {
|
|
self.module.get_function(name)
|
|
}
|
|
|
|
/// Returns the `FunctionValue` representing the function being compiled.
|
|
#[inline]
|
|
fn fn_value(&self) -> FunctionValue<'ctx> {
|
|
self.fn_value_opt.unwrap()
|
|
}
|
|
} |