mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
working happy path
This commit is contained in:
parent
d3ac7d616d
commit
644def72f1
7 changed files with 103 additions and 59 deletions
|
@ -463,6 +463,10 @@ impl CallConv<AArch64GeneralReg, AArch64FloatReg, AArch64Assembler> for AArch64C
|
|||
fn longjmp(buf: &mut Vec<'_, u8>, relocs: &mut Vec<'_, Relocation>) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn roc_panic(buf: &mut Vec<'_, u8>, relocs: &mut Vec<'_, Relocation>) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Assembler<AArch64GeneralReg, AArch64FloatReg> for AArch64Assembler {
|
||||
|
|
|
@ -137,6 +137,7 @@ pub trait CallConv<GeneralReg: RegTrait, FloatReg: RegTrait, ASM: Assembler<Gene
|
|||
|
||||
fn setjmp(buf: &mut Vec<'_, u8>, relocs: &mut Vec<'_, Relocation>);
|
||||
fn longjmp(buf: &mut Vec<'_, u8>, relocs: &mut Vec<'_, Relocation>);
|
||||
fn roc_panic(buf: &mut Vec<'_, u8>, relocs: &mut Vec<'_, Relocation>);
|
||||
}
|
||||
|
||||
pub enum CompareOperation {
|
||||
|
@ -913,6 +914,16 @@ impl<
|
|||
out.into_bump_slice()
|
||||
}
|
||||
|
||||
fn build_roc_panic(&mut self) -> &'a [u8] {
|
||||
let mut out = bumpalo::vec![in self.env.arena];
|
||||
|
||||
CC::roc_panic(&mut out, &mut self.relocs);
|
||||
|
||||
dbg!(&self.relocs);
|
||||
|
||||
out.into_bump_slice()
|
||||
}
|
||||
|
||||
fn build_fn_pointer(&mut self, dst: &Symbol, fn_name: String) {
|
||||
let reg = self.storage_manager.claim_general_reg(&mut self.buf, dst);
|
||||
|
||||
|
@ -922,7 +933,11 @@ impl<
|
|||
fn build_data_pointer(&mut self, dst: &Symbol, data_name: String) {
|
||||
let reg = self.storage_manager.claim_general_reg(&mut self.buf, dst);
|
||||
|
||||
ASM::data_pointer(&mut self.buf, &mut self.relocs, data_name, reg)
|
||||
// now, this gives a pointer to the value
|
||||
ASM::data_pointer(&mut self.buf, &mut self.relocs, data_name, reg);
|
||||
|
||||
// dereference
|
||||
ASM::mov_reg64_mem64_offset32(&mut self.buf, reg, reg, 0);
|
||||
}
|
||||
|
||||
fn build_fn_call(
|
||||
|
|
|
@ -266,7 +266,6 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg, X86_64Assembler> for X86_64Syste
|
|||
args: &'a [(InLayout<'a>, Symbol)],
|
||||
ret_layout: &InLayout<'a>,
|
||||
) {
|
||||
dbg!(layout_interner.dbg(*ret_layout));
|
||||
let returns_via_pointer =
|
||||
X86_64SystemV::returns_via_arg_pointer(layout_interner, ret_layout);
|
||||
|
||||
|
@ -277,7 +276,7 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg, X86_64Assembler> for X86_64Syste
|
|||
argument_offset: X86_64SystemV::SHADOW_SPACE_SIZE as i32 + 16,
|
||||
};
|
||||
|
||||
if dbg!(returns_via_pointer) {
|
||||
if returns_via_pointer {
|
||||
storage_manager.ret_pointer_arg(X86_64SystemV::GENERAL_PARAM_REGS[0]);
|
||||
}
|
||||
|
||||
|
@ -380,7 +379,6 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg, X86_64Assembler> for X86_64Syste
|
|||
}
|
||||
_ => {
|
||||
// This is a large type returned via the arg pointer.
|
||||
dbg!(sym);
|
||||
storage_manager.copy_symbol_to_arg_pointer(buf, sym, layout);
|
||||
// Also set the return reg to the arg pointer.
|
||||
storage_manager.load_to_specified_general_reg(
|
||||
|
@ -522,6 +520,17 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg, X86_64Assembler> for X86_64Syste
|
|||
|
||||
jmp_reg64_offset8(buf, RDI, offset as i8)
|
||||
}
|
||||
|
||||
fn roc_panic(buf: &mut Vec<'_, u8>, relocs: &mut Vec<'_, Relocation>) {
|
||||
use X86_64GeneralReg::*;
|
||||
type ASM = X86_64Assembler;
|
||||
|
||||
ASM::data_pointer(buf, relocs, String::from("setlongjmp_buffer"), RDI);
|
||||
ASM::mov_reg64_imm64(buf, RSI, 42);
|
||||
|
||||
// Call function and generate reloc.
|
||||
ASM::call(buf, relocs, String::from("roc_longjmp"));
|
||||
}
|
||||
}
|
||||
|
||||
struct X64_64SystemVStoreArgs {
|
||||
|
@ -1117,6 +1126,10 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg, X86_64Assembler> for X86_64Windo
|
|||
fn longjmp(buf: &mut Vec<'_, u8>, relocs: &mut Vec<'_, Relocation>) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn roc_panic(buf: &mut Vec<'_, u8>, relocs: &mut Vec<'_, Relocation>) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl X86_64WindowsFastcall {
|
||||
|
|
|
@ -466,6 +466,7 @@ trait Backend<'a> {
|
|||
// use for roc_panic
|
||||
fn build_roc_setjmp(&mut self) -> &'a [u8];
|
||||
fn build_roc_longjmp(&mut self) -> &'a [u8];
|
||||
fn build_roc_panic(&mut self) -> &'a [u8];
|
||||
|
||||
/// build_proc creates a procedure and outputs it to the wrapped object writer.
|
||||
/// Returns the procedure bytes, its relocations, and the names of the refcounting functions it references.
|
||||
|
@ -1680,7 +1681,8 @@ trait Backend<'a> {
|
|||
ret_layout,
|
||||
),
|
||||
LowLevel::SetLongJmpBuffer => {
|
||||
self.build_data_pointer(sym, String::from("setlongjmp_buffer"))
|
||||
let ptr_to_the_thing =
|
||||
self.build_data_pointer(sym, String::from("setlongjmp_buffer"));
|
||||
}
|
||||
LowLevel::DictPseudoSeed => self.build_fn_call(
|
||||
sym,
|
||||
|
|
|
@ -118,14 +118,9 @@ pub fn build_module<'a, 'r>(
|
|||
}
|
||||
}
|
||||
|
||||
fn generate_setlongjmp_buffer<'a, B: Backend<'a>>(
|
||||
backend: &mut B,
|
||||
output: &mut Object,
|
||||
) -> SymbolId {
|
||||
fn define_setlongjmp_buffer(output: &mut Object) -> SymbolId {
|
||||
let bss_section = output.section_id(StandardSection::Data);
|
||||
|
||||
dbg!(bss_section);
|
||||
|
||||
let symbol = Symbol {
|
||||
name: b"setlongjmp_buffer".to_vec(),
|
||||
value: 0,
|
||||
|
@ -138,29 +133,11 @@ fn generate_setlongjmp_buffer<'a, B: Backend<'a>>(
|
|||
};
|
||||
|
||||
let symbol_id = output.add_symbol(symbol);
|
||||
let section_offset = output.add_symbol_data(symbol_id, bss_section, &[0; 64], 8);
|
||||
output.add_symbol_data(symbol_id, bss_section, &[0xAA; 64], 8);
|
||||
|
||||
symbol_id
|
||||
}
|
||||
|
||||
fn generate_roc_setlongjmp_buffer<'a, B: Backend<'a>>(backend: &mut B, output: &mut Object) {
|
||||
let text_section = output.section_id(StandardSection::Text);
|
||||
let proc_symbol = Symbol {
|
||||
name: b"roc_setjmp".to_vec(),
|
||||
value: 0,
|
||||
size: 0,
|
||||
kind: SymbolKind::Text,
|
||||
scope: SymbolScope::Dynamic,
|
||||
weak: false,
|
||||
section: SymbolSection::Section(text_section),
|
||||
flags: SymbolFlags::None,
|
||||
};
|
||||
|
||||
let proc_id = output.add_symbol(proc_symbol);
|
||||
let (proc_data, offset) = backend.build_wrapped_jmp();
|
||||
let proc_offset = output.add_symbol_data(proc_id, text_section, proc_data, 16);
|
||||
}
|
||||
|
||||
fn generate_setjmp<'a, B: Backend<'a>>(backend: &mut B, output: &mut Object) {
|
||||
let text_section = output.section_id(StandardSection::Text);
|
||||
let proc_symbol = Symbol {
|
||||
|
@ -197,6 +174,25 @@ fn generate_longjmp<'a, B: Backend<'a>>(backend: &mut B, output: &mut Object) {
|
|||
output.add_symbol_data(proc_id, text_section, proc_data, 16);
|
||||
}
|
||||
|
||||
// a roc_panic to be used in tests; relies on setjmp/longjmp
|
||||
fn generate_roc_panic<'a, B: Backend<'a>>(backend: &mut B, output: &mut Object) {
|
||||
let text_section = output.section_id(StandardSection::Text);
|
||||
let proc_symbol = Symbol {
|
||||
name: b"roc_panic".to_vec(),
|
||||
value: 0,
|
||||
size: 0,
|
||||
kind: SymbolKind::Text,
|
||||
scope: SymbolScope::Dynamic,
|
||||
weak: false,
|
||||
section: SymbolSection::Section(text_section),
|
||||
flags: SymbolFlags::None,
|
||||
};
|
||||
let proc_id = output.add_symbol(proc_symbol);
|
||||
let proc_data = backend.build_roc_panic();
|
||||
|
||||
output.add_symbol_data(proc_id, text_section, proc_data, 16);
|
||||
}
|
||||
|
||||
fn generate_wrapper<'a, B: Backend<'a>>(
|
||||
backend: &mut B,
|
||||
output: &mut Object,
|
||||
|
@ -257,8 +253,6 @@ fn build_object<'a, B: Backend<'a>>(
|
|||
) -> Object<'a> {
|
||||
let data_section = output.section_id(StandardSection::Data);
|
||||
|
||||
dbg!("build object");
|
||||
|
||||
let arena = backend.env().arena;
|
||||
|
||||
/*
|
||||
|
@ -271,8 +265,9 @@ fn build_object<'a, B: Backend<'a>>(
|
|||
);
|
||||
*/
|
||||
|
||||
generate_setlongjmp_buffer(&mut backend, &mut output);
|
||||
define_setlongjmp_buffer(&mut output);
|
||||
|
||||
generate_roc_panic(&mut backend, &mut output);
|
||||
generate_setjmp(&mut backend, &mut output);
|
||||
generate_longjmp(&mut backend, &mut output);
|
||||
|
||||
|
@ -295,12 +290,14 @@ fn build_object<'a, B: Backend<'a>>(
|
|||
"roc_dealloc".into(),
|
||||
"free".into(),
|
||||
);
|
||||
generate_wrapper(
|
||||
&mut backend,
|
||||
&mut output,
|
||||
"roc_panic".into(),
|
||||
"roc_builtins.utils.test_panic".into(),
|
||||
);
|
||||
|
||||
// generate_wrapper(
|
||||
// &mut backend,
|
||||
// &mut output,
|
||||
// "roc_panic".into(),
|
||||
// "roc_builtins.utils.test_panic".into(),
|
||||
// );
|
||||
|
||||
// Extra symbols only required on unix systems.
|
||||
if matches!(output.format(), BinaryFormat::Elf | BinaryFormat::MachO) {
|
||||
generate_wrapper(
|
||||
|
@ -360,7 +357,7 @@ fn build_object<'a, B: Backend<'a>>(
|
|||
module_id.register_debug_idents(ident_ids);
|
||||
}
|
||||
|
||||
println!("{}", test_helper.to_pretty(backend.interner(), 200, true));
|
||||
// println!("{}", test_helper.to_pretty(backend.interner(), 200, true));
|
||||
|
||||
build_proc_symbol(
|
||||
&mut output,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue