diff --git a/cranelift/codegen/src/binemit/memorysink.rs b/cranelift/codegen/src/binemit/memorysink.rs index 6635bff876..d40d5e7281 100644 --- a/cranelift/codegen/src/binemit/memorysink.rs +++ b/cranelift/codegen/src/binemit/memorysink.rs @@ -99,26 +99,10 @@ impl<'a> MemoryCodeSink<'a> { } impl<'a> CodeSink for MemoryCodeSink<'a> { - fn offset(&self) -> CodeOffset { - self.offset as CodeOffset - } - fn put1(&mut self, x: u8) { self.write(x); } - fn put2(&mut self, x: u16) { - self.write(x); - } - - fn put4(&mut self, x: u32) { - self.write(x); - } - - fn put8(&mut self, x: u64) { - self.write(x); - } - fn reloc_external( &mut self, srcloc: SourceLoc, @@ -126,17 +110,17 @@ impl<'a> CodeSink for MemoryCodeSink<'a> { name: &ExternalName, addend: Addend, ) { - let ofs = self.offset(); + let ofs = self.offset as CodeOffset; self.relocs.reloc_external(ofs, srcloc, rel, name, addend); } fn trap(&mut self, code: TrapCode, srcloc: SourceLoc) { - let ofs = self.offset(); + let ofs = self.offset as CodeOffset; self.traps.trap(ofs, srcloc, code); } fn end_codegen(&mut self) { - self.info.total_size = self.offset(); + self.info.total_size = self.offset as CodeOffset; } fn add_call_site(&mut self, opcode: Opcode, loc: SourceLoc) { @@ -144,7 +128,7 @@ impl<'a> CodeSink for MemoryCodeSink<'a> { opcode.is_call(), "adding call site info for a non-call instruction." ); - let ret_addr = self.offset(); + let ret_addr = self.offset as CodeOffset; self.relocs.add_call_site(opcode, ret_addr, loc); } } diff --git a/cranelift/codegen/src/binemit/mod.rs b/cranelift/codegen/src/binemit/mod.rs index 157a123d7e..ff124ec6fa 100644 --- a/cranelift/codegen/src/binemit/mod.rs +++ b/cranelift/codegen/src/binemit/mod.rs @@ -105,21 +105,9 @@ pub struct CodeInfo { /// A `CodeSink` will receive all of the machine code for a function. It also accepts relocations /// which are locations in the code section that need to be fixed up when linking. pub trait CodeSink { - /// Get the current position. - fn offset(&self) -> CodeOffset; - /// Add 1 byte to the code section. fn put1(&mut self, _: u8); - /// Add 2 bytes to the code section. - fn put2(&mut self, _: u16); - - /// Add 4 bytes to the code section. - fn put4(&mut self, _: u32); - - /// Add 8 bytes to the code section. - fn put8(&mut self, _: u64); - /// Add a relocation referencing an external symbol plus the addend at the current offset. fn reloc_external(&mut self, _: SourceLoc, _: Reloc, _: &ExternalName, _: Addend); diff --git a/cranelift/codegen/src/machinst/buffer.rs b/cranelift/codegen/src/machinst/buffer.rs index 87c2566e9e..2f46f7110e 100644 --- a/cranelift/codegen/src/machinst/buffer.rs +++ b/cranelift/codegen/src/machinst/buffer.rs @@ -2079,21 +2079,9 @@ mod test { relocs: Vec<(CodeOffset, Reloc)>, } impl CodeSink for TestCodeSink { - fn offset(&self) -> CodeOffset { - self.offset - } fn put1(&mut self, _: u8) { self.offset += 1; } - fn put2(&mut self, _: u16) { - self.offset += 2; - } - fn put4(&mut self, _: u32) { - self.offset += 4; - } - fn put8(&mut self, _: u64) { - self.offset += 8; - } fn reloc_external(&mut self, _: SourceLoc, r: Reloc, _: &ExternalName, _: Addend) { self.relocs.push((self.offset, r)); } diff --git a/cranelift/filetests/src/test_compile.rs b/cranelift/filetests/src/test_compile.rs index 4072735ad3..ec8bbbb120 100644 --- a/cranelift/filetests/src/test_compile.rs +++ b/cranelift/filetests/src/test_compile.rs @@ -81,26 +81,10 @@ struct SizeSink { } impl binemit::CodeSink for SizeSink { - fn offset(&self) -> binemit::CodeOffset { - self.offset - } - fn put1(&mut self, _: u8) { self.offset += 1; } - fn put2(&mut self, _: u16) { - self.offset += 2; - } - - fn put4(&mut self, _: u32) { - self.offset += 4; - } - - fn put8(&mut self, _: u64) { - self.offset += 8; - } - fn reloc_external( &mut self, _srcloc: ir::SourceLoc,