57 lines
1.6 KiB
Rust
57 lines
1.6 KiB
Rust
use crate::constants_table::ConstantsTable;
|
|
use crate::ir::assemble::assemble_ir_function;
|
|
use crate::ir::ir_function::IrFunction;
|
|
use crate::ir::register_allocation::{AssignRegistersResult, assign_registers};
|
|
use crate::ir::variable_locations::VariableLocations;
|
|
use dvm_lib::vm::function::Function;
|
|
|
|
mod assemble;
|
|
mod debug_print;
|
|
pub mod ir_allocate;
|
|
pub mod ir_assign;
|
|
pub mod ir_binary_operation;
|
|
pub mod ir_block;
|
|
pub mod ir_call;
|
|
pub mod ir_class;
|
|
pub mod ir_expression;
|
|
pub mod ir_function;
|
|
pub mod ir_get_field_ref;
|
|
pub mod ir_get_field_ref_mut;
|
|
pub mod ir_operation;
|
|
pub mod ir_parameter;
|
|
pub mod ir_parameter_or_variable;
|
|
pub mod ir_read_field;
|
|
pub mod ir_return;
|
|
pub mod ir_set_field;
|
|
pub mod ir_statement;
|
|
pub mod ir_type_info;
|
|
pub mod ir_variable;
|
|
mod register_allocation;
|
|
mod util;
|
|
pub mod variable_locations;
|
|
|
|
pub fn compile_dvm_function(
|
|
ir_function: &IrFunction,
|
|
register_count: usize,
|
|
variable_locations: &mut VariableLocations,
|
|
constants_table: &mut ConstantsTable,
|
|
) -> Function {
|
|
let AssignRegistersResult {
|
|
register_variables,
|
|
spilled_variables,
|
|
} = assign_registers(ir_function, register_count);
|
|
|
|
variable_locations.push_all_register_variables(®ister_variables);
|
|
for spilled_variable in spilled_variables {
|
|
variable_locations.push_stack_variable(spilled_variable);
|
|
}
|
|
|
|
let instructions = assemble_ir_function(ir_function, &variable_locations, constants_table);
|
|
Function::new(
|
|
ir_function.fqn().into(),
|
|
ir_function.parameters().len(),
|
|
variable_locations.stack_variables_count(),
|
|
instructions,
|
|
)
|
|
}
|