From bbbae4dc47484f93bfb934c281bd517915f7e51e Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 23 Mar 2017 12:31:29 -0700 Subject: [PATCH] Start the binemit module. This module will provide supporting code for emitting binary machine code with relocations. --- lib/cretonne/src/binemit/mod.rs | 33 +++++++++++++++++++++++++++++++++ lib/cretonne/src/lib.rs | 1 + 2 files changed, 34 insertions(+) create mode 100644 lib/cretonne/src/binemit/mod.rs diff --git a/lib/cretonne/src/binemit/mod.rs b/lib/cretonne/src/binemit/mod.rs new file mode 100644 index 0000000000..d3c97ec539 --- /dev/null +++ b/lib/cretonne/src/binemit/mod.rs @@ -0,0 +1,33 @@ +//! Binary machine code emission. +//! +//! The `binemit` module contains code for translating Cretonne's intermediate representation into +//! binary machine code. + +use ir::{FuncRef, JumpTable}; + +/// Relocation kinds depend on the current ISA. +pub struct Reloc(u16); + +/// Abstract interface for adding bytes to the code segment. +/// +/// 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 { + /// 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 function at the current offset. + fn reloc_func(&mut self, Reloc, FuncRef); + + /// Add a relocation referencing a jump table. + fn reloc_jt(&mut self, Reloc, JumpTable); +} diff --git a/lib/cretonne/src/lib.rs b/lib/cretonne/src/lib.rs index 079b9a4559..b4c163b14d 100644 --- a/lib/cretonne/src/lib.rs +++ b/lib/cretonne/src/lib.rs @@ -10,6 +10,7 @@ pub use write::write_function; /// Version number of the cretonne crate. pub const VERSION: &'static str = env!("CARGO_PKG_VERSION"); +pub mod binemit; pub mod flowgraph; pub mod dominator_tree; pub mod entity_list;