mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Modify ownership to fix layout copying
This commit is contained in:
parent
54861ef5fa
commit
931b373d80
3 changed files with 19 additions and 19 deletions
|
@ -243,14 +243,14 @@ pub struct Backend64Bit<
|
||||||
buf: Vec<'a, u8>,
|
buf: Vec<'a, u8>,
|
||||||
relocs: Vec<'a, Relocation>,
|
relocs: Vec<'a, Relocation>,
|
||||||
proc_name: Option<String>,
|
proc_name: Option<String>,
|
||||||
is_self_recursive: Option<SelfRecursive>,
|
is_self_recursive: Option<&'a SelfRecursive>,
|
||||||
|
|
||||||
last_seen_map: MutMap<Symbol, *const Stmt<'a>>,
|
last_seen_map: MutMap<Symbol, *const Stmt<'a>>,
|
||||||
layout_map: MutMap<Symbol, Layout<'a>>,
|
layout_map: MutMap<Symbol, Layout<'a>>,
|
||||||
free_map: MutMap<*const Stmt<'a>, Vec<'a, Symbol>>,
|
free_map: MutMap<*const Stmt<'a>, Vec<'a, Symbol>>,
|
||||||
|
|
||||||
symbol_storage_map: MutMap<Symbol, SymbolStorage<GeneralReg, FloatReg>>,
|
symbol_storage_map: MutMap<Symbol, SymbolStorage<GeneralReg, FloatReg>>,
|
||||||
literal_map: MutMap<Symbol, (Literal<'a>, Layout<'a>)>,
|
literal_map: MutMap<Symbol, (&'a Literal<'a>, &'a Layout<'a>)>,
|
||||||
join_map: MutMap<JoinPointId, u64>,
|
join_map: MutMap<JoinPointId, u64>,
|
||||||
|
|
||||||
// This should probably be smarter than a vec.
|
// This should probably be smarter than a vec.
|
||||||
|
@ -313,7 +313,7 @@ impl<
|
||||||
self.env
|
self.env
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset(&mut self, name: String, is_self_recursive: SelfRecursive) {
|
fn reset(&mut self, name: String, is_self_recursive: &'a SelfRecursive) {
|
||||||
self.proc_name = Some(name);
|
self.proc_name = Some(name);
|
||||||
self.is_self_recursive = Some(is_self_recursive);
|
self.is_self_recursive = Some(is_self_recursive);
|
||||||
self.stack_size = 0;
|
self.stack_size = 0;
|
||||||
|
@ -337,7 +337,7 @@ impl<
|
||||||
.extend_from_slice(CC::FLOAT_DEFAULT_FREE_REGS);
|
.extend_from_slice(CC::FLOAT_DEFAULT_FREE_REGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn literal_map(&mut self) -> &mut MutMap<Symbol, (Literal<'a>, Layout<'a>)> {
|
fn literal_map(&mut self) -> &mut MutMap<Symbol, (&'a Literal<'a>, &'a Layout<'a>)> {
|
||||||
&mut self.literal_map
|
&mut self.literal_map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ where
|
||||||
|
|
||||||
/// reset resets any registers or other values that may be occupied at the end of a procedure.
|
/// reset resets any registers or other values that may be occupied at the end of a procedure.
|
||||||
/// It also passes basic procedure information to the builder for setup of the next function.
|
/// It also passes basic procedure information to the builder for setup of the next function.
|
||||||
fn reset(&mut self, name: String, is_self_recursive: SelfRecursive);
|
fn reset(&mut self, name: String, is_self_recursive: &'a SelfRecursive);
|
||||||
|
|
||||||
/// finalize does any setup and cleanup that should happen around the procedure.
|
/// finalize does any setup and cleanup that should happen around the procedure.
|
||||||
/// finalize does setup because things like stack size and jump locations are not know until the function is written.
|
/// finalize does setup because things like stack size and jump locations are not know until the function is written.
|
||||||
|
@ -81,11 +81,11 @@ where
|
||||||
fn build_wrapped_jmp(&mut self) -> (&'a [u8], u64);
|
fn build_wrapped_jmp(&mut self) -> (&'a [u8], u64);
|
||||||
|
|
||||||
/// build_proc creates a procedure and outputs it to the wrapped object writer.
|
/// build_proc creates a procedure and outputs it to the wrapped object writer.
|
||||||
fn build_proc(&mut self, proc: Proc<'a>) -> (&'a [u8], &[Relocation]) {
|
fn build_proc(&mut self, proc: &'a Proc<'a>) -> (&'a [u8], &[Relocation]) {
|
||||||
let proc_name = LayoutIds::default()
|
let proc_name = LayoutIds::default()
|
||||||
.get(proc.name, &proc.ret_layout)
|
.get(proc.name, &proc.ret_layout)
|
||||||
.to_symbol_string(proc.name, &self.env().interns);
|
.to_symbol_string(proc.name, &self.env().interns);
|
||||||
self.reset(proc_name, proc.is_self_recursive);
|
self.reset(proc_name, &proc.is_self_recursive);
|
||||||
self.load_args(proc.args, &proc.ret_layout);
|
self.load_args(proc.args, &proc.ret_layout);
|
||||||
for (layout, sym) in proc.args {
|
for (layout, sym) in proc.args {
|
||||||
self.set_layout_map(*sym, layout);
|
self.set_layout_map(*sym, layout);
|
||||||
|
@ -97,7 +97,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// build_stmt builds a statement and outputs at the end of the buffer.
|
/// build_stmt builds a statement and outputs at the end of the buffer.
|
||||||
fn build_stmt(&mut self, stmt: &Stmt<'a>, ret_layout: &Layout<'a>) {
|
fn build_stmt(&mut self, stmt: &'a Stmt<'a>, ret_layout: &Layout<'a>) {
|
||||||
match stmt {
|
match stmt {
|
||||||
Stmt::Let(sym, expr, layout, following) => {
|
Stmt::Let(sym, expr, layout, following) => {
|
||||||
self.build_expr(sym, expr, layout);
|
self.build_expr(sym, expr, layout);
|
||||||
|
@ -192,11 +192,11 @@ where
|
||||||
|
|
||||||
/// build_expr builds the expressions for the specified symbol.
|
/// build_expr builds the expressions for the specified symbol.
|
||||||
/// The builder must keep track of the symbol because it may be referred to later.
|
/// The builder must keep track of the symbol because it may be referred to later.
|
||||||
fn build_expr(&mut self, sym: &Symbol, expr: &Expr<'a>, layout: &Layout<'a>) {
|
fn build_expr(&mut self, sym: &Symbol, expr: &'a Expr<'a>, layout: &'a Layout<'a>) {
|
||||||
match expr {
|
match expr {
|
||||||
Expr::Literal(lit) => {
|
Expr::Literal(lit) => {
|
||||||
if self.env().lazy_literals {
|
if self.env().lazy_literals {
|
||||||
self.literal_map().insert(*sym, (*lit, *layout));
|
self.literal_map().insert(*sym, (lit, layout));
|
||||||
} else {
|
} else {
|
||||||
self.load_literal(sym, layout, lit);
|
self.load_literal(sym, layout, lit);
|
||||||
}
|
}
|
||||||
|
@ -547,7 +547,7 @@ where
|
||||||
);
|
);
|
||||||
|
|
||||||
/// literal_map gets the map from symbol to literal and layout, used for lazy loading and literal folding.
|
/// literal_map gets the map from symbol to literal and layout, used for lazy loading and literal folding.
|
||||||
fn literal_map(&mut self) -> &mut MutMap<Symbol, (Literal<'a>, Layout<'a>)>;
|
fn literal_map(&mut self) -> &mut MutMap<Symbol, (&'a Literal<'a>, &'a Layout<'a>)>;
|
||||||
|
|
||||||
fn load_literal_symbols(&mut self, syms: &[Symbol]) {
|
fn load_literal_symbols(&mut self, syms: &[Symbol]) {
|
||||||
if self.env().lazy_literals {
|
if self.env().lazy_literals {
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub fn build_module<'a>(
|
||||||
> = Backend::new(env);
|
> = Backend::new(env);
|
||||||
build_object(
|
build_object(
|
||||||
env,
|
env,
|
||||||
procedures,
|
&procedures,
|
||||||
backend,
|
backend,
|
||||||
Object::new(BinaryFormat::Elf, Architecture::X86_64, Endianness::Little),
|
Object::new(BinaryFormat::Elf, Architecture::X86_64, Endianness::Little),
|
||||||
)
|
)
|
||||||
|
@ -56,7 +56,7 @@ pub fn build_module<'a>(
|
||||||
> = Backend::new(env);
|
> = Backend::new(env);
|
||||||
build_object(
|
build_object(
|
||||||
env,
|
env,
|
||||||
procedures,
|
&procedures,
|
||||||
backend,
|
backend,
|
||||||
Object::new(
|
Object::new(
|
||||||
BinaryFormat::MachO,
|
BinaryFormat::MachO,
|
||||||
|
@ -78,7 +78,7 @@ pub fn build_module<'a>(
|
||||||
> = Backend::new(env);
|
> = Backend::new(env);
|
||||||
build_object(
|
build_object(
|
||||||
env,
|
env,
|
||||||
procedures,
|
&procedures,
|
||||||
backend,
|
backend,
|
||||||
Object::new(BinaryFormat::Elf, Architecture::Aarch64, Endianness::Little),
|
Object::new(BinaryFormat::Elf, Architecture::Aarch64, Endianness::Little),
|
||||||
)
|
)
|
||||||
|
@ -96,7 +96,7 @@ pub fn build_module<'a>(
|
||||||
> = Backend::new(env);
|
> = Backend::new(env);
|
||||||
build_object(
|
build_object(
|
||||||
env,
|
env,
|
||||||
procedures,
|
&procedures,
|
||||||
backend,
|
backend,
|
||||||
Object::new(
|
Object::new(
|
||||||
BinaryFormat::MachO,
|
BinaryFormat::MachO,
|
||||||
|
@ -164,7 +164,7 @@ fn generate_wrapper<'a, B: Backend<'a>>(
|
||||||
|
|
||||||
fn build_object<'a, B: Backend<'a>>(
|
fn build_object<'a, B: Backend<'a>>(
|
||||||
env: &'a Env,
|
env: &'a Env,
|
||||||
procedures: MutMap<(symbol::Symbol, ProcLayout<'a>), Proc<'a>>,
|
procedures: &'a MutMap<(symbol::Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||||
mut backend: B,
|
mut backend: B,
|
||||||
mut output: Object,
|
mut output: Object,
|
||||||
) -> Object {
|
) -> Object {
|
||||||
|
@ -212,8 +212,8 @@ fn build_object<'a, B: Backend<'a>>(
|
||||||
let mut procs = Vec::with_capacity_in(procedures.len(), env.arena);
|
let mut procs = Vec::with_capacity_in(procedures.len(), env.arena);
|
||||||
for ((sym, layout), proc) in procedures {
|
for ((sym, layout), proc) in procedures {
|
||||||
let base_name = layout_ids
|
let base_name = layout_ids
|
||||||
.get_toplevel(sym, &layout)
|
.get_toplevel(*sym, &layout)
|
||||||
.to_symbol_string(sym, &env.interns);
|
.to_symbol_string(*sym, &env.interns);
|
||||||
|
|
||||||
let fn_name = if env.exposed_to_host.contains(&sym) {
|
let fn_name = if env.exposed_to_host.contains(&sym) {
|
||||||
format!("roc_{}_exposed", base_name)
|
format!("roc_{}_exposed", base_name)
|
||||||
|
@ -251,7 +251,7 @@ fn build_object<'a, B: Backend<'a>>(
|
||||||
let mut relocations = bumpalo::vec![in env.arena];
|
let mut relocations = bumpalo::vec![in env.arena];
|
||||||
for (fn_name, section_id, proc_id, proc) in procs {
|
for (fn_name, section_id, proc_id, proc) in procs {
|
||||||
let mut local_data_index = 0;
|
let mut local_data_index = 0;
|
||||||
let (proc_data, relocs) = backend.build_proc(proc);
|
let (proc_data, relocs) = backend.build_proc(&proc);
|
||||||
let proc_offset = output.add_symbol_data(proc_id, section_id, proc_data, 16);
|
let proc_offset = output.add_symbol_data(proc_id, section_id, proc_data, 16);
|
||||||
for reloc in relocs {
|
for reloc in relocs {
|
||||||
let elfreloc = match reloc {
|
let elfreloc = match reloc {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue