Rename FunctionBuilder back to CodeBuilder

This commit is contained in:
Brian Carroll 2021-10-23 13:48:20 +02:00
parent dbe6d195f7
commit 973626fe2d
6 changed files with 20 additions and 20 deletions

View file

@ -8,7 +8,7 @@ use roc_module::symbol::Symbol;
use roc_mono::ir::{CallType, Expr, JoinPointId, Literal, Proc, Stmt}; use roc_mono::ir::{CallType, Expr, JoinPointId, Literal, Proc, Stmt};
use roc_mono::layout::{Builtin, Layout}; use roc_mono::layout::{Builtin, Layout};
use crate::function_builder::{BlockType, FunctionBuilder, ValueType}; use crate::code_builder::{BlockType, CodeBuilder, ValueType};
use crate::layout::WasmLayout; use crate::layout::WasmLayout;
use crate::storage::{Storage, StoredValue, StoredValueKind}; use crate::storage::{Storage, StoredValue, StoredValueKind};
use crate::{copy_memory, CopyMemoryConfig, Env, LocalId, PTR_TYPE}; use crate::{copy_memory, CopyMemoryConfig, Env, LocalId, PTR_TYPE};
@ -32,7 +32,7 @@ pub struct WasmBackend<'a> {
proc_symbol_map: MutMap<Symbol, CodeLocation>, proc_symbol_map: MutMap<Symbol, CodeLocation>,
// Function level // Function level
code_builder: FunctionBuilder<'a>, code_builder: CodeBuilder<'a>,
storage: Storage<'a>, storage: Storage<'a>,
/// how many blocks deep are we (used for jumps) /// how many blocks deep are we (used for jumps)
@ -56,7 +56,7 @@ impl<'a> WasmBackend<'a> {
joinpoint_label_map: MutMap::default(), joinpoint_label_map: MutMap::default(),
// Functions // Functions
code_builder: FunctionBuilder::new(env.arena), code_builder: CodeBuilder::new(env.arena),
storage: Storage::new(env.arena), storage: Storage::new(env.arena),
} }
} }

View file

@ -100,7 +100,7 @@ macro_rules! instruction_memargs {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct FunctionBuilder<'a> { pub struct CodeBuilder<'a> {
/// The main container for the instructions /// The main container for the instructions
code: Vec<'a, u8>, code: Vec<'a, u8>,
@ -128,9 +128,9 @@ pub struct FunctionBuilder<'a> {
} }
#[allow(clippy::new_without_default)] #[allow(clippy::new_without_default)]
impl<'a> FunctionBuilder<'a> { impl<'a> CodeBuilder<'a> {
pub fn new(arena: &'a Bump) -> Self { pub fn new(arena: &'a Bump) -> Self {
FunctionBuilder { CodeBuilder {
code: Vec::with_capacity_in(1024, arena), code: Vec::with_capacity_in(1024, arena),
insertions: Vec::with_capacity_in(32, arena), insertions: Vec::with_capacity_in(32, arena),
insertions_byte_len: 0, insertions_byte_len: 0,

View file

@ -1,6 +1,6 @@
use roc_mono::layout::{Layout, UnionLayout}; use roc_mono::layout::{Layout, UnionLayout};
use crate::{function_builder::ValueType, PTR_SIZE, PTR_TYPE}; use crate::{code_builder::ValueType, PTR_SIZE, PTR_TYPE};
// See README for background information on Wasm locals, memory and function calls // See README for background information on Wasm locals, memory and function calls
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View file

@ -4,7 +4,7 @@ mod layout;
mod storage; mod storage;
#[allow(dead_code)] #[allow(dead_code)]
pub mod function_builder; pub mod code_builder;
#[allow(dead_code)] #[allow(dead_code)]
mod opcodes; mod opcodes;
@ -20,7 +20,7 @@ use roc_mono::ir::{Proc, ProcLayout};
use roc_mono::layout::LayoutIds; use roc_mono::layout::LayoutIds;
use crate::backend::WasmBackend; use crate::backend::WasmBackend;
use crate::function_builder::{Align, FunctionBuilder, ValueType}; use crate::code_builder::{Align, CodeBuilder, ValueType};
const PTR_SIZE: u32 = 4; const PTR_SIZE: u32 = 4;
const PTR_TYPE: ValueType = ValueType::I32; const PTR_TYPE: ValueType = ValueType::I32;
@ -134,7 +134,7 @@ pub struct CopyMemoryConfig {
alignment_bytes: u32, alignment_bytes: u32,
} }
pub fn copy_memory(code_builder: &mut FunctionBuilder, config: CopyMemoryConfig) { pub fn copy_memory(code_builder: &mut CodeBuilder, config: CopyMemoryConfig) {
if config.from_ptr == config.to_ptr && config.from_offset == config.to_offset { if config.from_ptr == config.to_ptr && config.from_offset == config.to_offset {
return; return;
} }

View file

@ -4,7 +4,7 @@ use bumpalo::Bump;
use roc_collections::all::MutMap; use roc_collections::all::MutMap;
use roc_module::symbol::Symbol; use roc_module::symbol::Symbol;
use crate::function_builder::{FunctionBuilder, ValueType, VirtualMachineSymbolState}; use crate::code_builder::{CodeBuilder, ValueType, VirtualMachineSymbolState};
use crate::layout::WasmLayout; use crate::layout::WasmLayout;
use crate::{copy_memory, round_up_to_alignment, CopyMemoryConfig, LocalId, PTR_SIZE, PTR_TYPE}; use crate::{copy_memory, round_up_to_alignment, CopyMemoryConfig, LocalId, PTR_SIZE, PTR_TYPE};
@ -188,7 +188,7 @@ impl<'a> Storage<'a> {
/// Load symbols to the top of the VM stack /// Load symbols to the top of the VM stack
/// Avoid calling this method in a loop with one symbol at a time! It will work, /// Avoid calling this method in a loop with one symbol at a time! It will work,
/// but it generates very inefficient Wasm code. /// but it generates very inefficient Wasm code.
pub fn load_symbols(&mut self, code_builder: &mut FunctionBuilder, symbols: &[Symbol]) { pub fn load_symbols(&mut self, code_builder: &mut CodeBuilder, symbols: &[Symbol]) {
if code_builder.verify_stack_match(symbols) { if code_builder.verify_stack_match(symbols) {
// The symbols were already at the top of the stack, do nothing! // The symbols were already at the top of the stack, do nothing!
// This should be quite common due to the structure of the Mono IR // This should be quite common due to the structure of the Mono IR
@ -258,7 +258,7 @@ impl<'a> Storage<'a> {
/// (defined by a pointer and offset). /// (defined by a pointer and offset).
pub fn copy_value_to_memory( pub fn copy_value_to_memory(
&mut self, &mut self,
code_builder: &mut FunctionBuilder, code_builder: &mut CodeBuilder,
to_ptr: LocalId, to_ptr: LocalId,
to_offset: u32, to_offset: u32,
from_symbol: Symbol, from_symbol: Symbol,
@ -291,7 +291,7 @@ impl<'a> Storage<'a> {
| StoredValue::Local { | StoredValue::Local {
value_type, size, .. value_type, size, ..
} => { } => {
use crate::function_builder::Align::*; use crate::code_builder::Align::*;
code_builder.get_local(to_ptr); code_builder.get_local(to_ptr);
self.load_symbols(code_builder, &[from_symbol]); self.load_symbols(code_builder, &[from_symbol]);
match (value_type, size) { match (value_type, size) {
@ -314,7 +314,7 @@ impl<'a> Storage<'a> {
/// Copies the _entire_ value. For struct fields etc., see `copy_value_to_memory` /// Copies the _entire_ value. For struct fields etc., see `copy_value_to_memory`
pub fn clone_value( pub fn clone_value(
&mut self, &mut self,
code_builder: &mut FunctionBuilder, code_builder: &mut CodeBuilder,
to: &StoredValue, to: &StoredValue,
from: &StoredValue, from: &StoredValue,
from_symbol: Symbol, from_symbol: Symbol,
@ -402,7 +402,7 @@ impl<'a> Storage<'a> {
/// (In the case of structs in stack memory, we just use the stack frame pointer local) /// (In the case of structs in stack memory, we just use the stack frame pointer local)
pub fn ensure_value_has_local( pub fn ensure_value_has_local(
&mut self, &mut self,
code_builder: &mut FunctionBuilder, code_builder: &mut CodeBuilder,
symbol: Symbol, symbol: Symbol,
storage: StoredValue, storage: StoredValue,
) -> StoredValue { ) -> StoredValue {

View file

@ -2,13 +2,13 @@ use parity_wasm::builder;
use parity_wasm::builder::ModuleBuilder; use parity_wasm::builder::ModuleBuilder;
use roc_gen_wasm::from_wasm32_memory::FromWasm32Memory; use roc_gen_wasm::from_wasm32_memory::FromWasm32Memory;
use roc_gen_wasm::function_builder::{Align, FunctionBuilder, ValueType}; use roc_gen_wasm::code_builder::{Align, CodeBuilder, ValueType};
use roc_std::{RocDec, RocList, RocOrder, RocStr}; use roc_std::{RocDec, RocList, RocOrder, RocStr};
pub trait Wasm32TestResult { pub trait Wasm32TestResult {
fn insert_test_wrapper( fn insert_test_wrapper(
module_builder: &mut ModuleBuilder, module_builder: &mut ModuleBuilder,
code_builder: &mut FunctionBuilder, code_builder: &mut CodeBuilder,
wrapper_name: &str, wrapper_name: &str,
main_function_index: u32, main_function_index: u32,
) { ) {
@ -26,7 +26,7 @@ pub trait Wasm32TestResult {
self.build_wrapper_body(code_builder, main_function_index); self.build_wrapper_body(code_builder, main_function_index);
} }
fn build_wrapper_body(code_builder: &mut FunctionBuilder, main_function_index: u32); fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32);
} }
macro_rules! build_wrapper_body_primitive { macro_rules! build_wrapper_body_primitive {
@ -59,7 +59,7 @@ macro_rules! wasm_test_result_primitive {
} }
fn build_wrapper_body_stack_memory( fn build_wrapper_body_stack_memory(
code_builder: &mut FunctionBuilder, code_builder: &mut CodeBuilder,
main_function_index: u32, main_function_index: u32,
size: usize, size: usize,
) -> Vec<Instruction> { ) -> Vec<Instruction> {