Make CtonError parameterized on the result type.
This makes it more consistent with other custom `Result` types.
This commit is contained in:
@@ -32,12 +32,12 @@ use cursor::{Cursor, FuncCursor};
|
||||
use ir::{Function, InstructionData, Opcode};
|
||||
use isa::{EncInfo, TargetIsa};
|
||||
use iterators::IteratorExtras;
|
||||
use result::CtonError;
|
||||
use result::CtonResult;
|
||||
|
||||
/// Relax branches and compute the final layout of EBB headers in `func`.
|
||||
///
|
||||
/// Fill in the `func.offsets` table so the function is ready for binary emission.
|
||||
pub fn relax_branches(func: &mut Function, isa: &TargetIsa) -> Result<CodeOffset, CtonError> {
|
||||
pub fn relax_branches(func: &mut Function, isa: &TargetIsa) -> CtonResult<CodeOffset> {
|
||||
let encinfo = isa.encoding_info();
|
||||
|
||||
// Clear all offsets so we can recognize EBBs that haven't been visited yet.
|
||||
|
||||
@@ -22,7 +22,7 @@ use nan_canonicalization::do_nan_canonicalization;
|
||||
use postopt::do_postopt;
|
||||
use preopt::do_preopt;
|
||||
use regalloc;
|
||||
use result::{CtonError, CtonResult};
|
||||
use result::CtonResult;
|
||||
use settings::{FlagsOrIsa, OptLevel};
|
||||
use simple_gvn::do_simple_gvn;
|
||||
use std::vec::Vec;
|
||||
@@ -95,7 +95,7 @@ impl Context {
|
||||
mem: &mut Vec<u8>,
|
||||
relocs: &mut RelocSink,
|
||||
traps: &mut TrapSink,
|
||||
) -> CtonResult {
|
||||
) -> CtonResult<()> {
|
||||
let code_size = self.compile(isa)?;
|
||||
let old_len = mem.len();
|
||||
mem.resize(old_len + code_size as usize, 0);
|
||||
@@ -117,7 +117,7 @@ impl Context {
|
||||
/// code sink.
|
||||
///
|
||||
/// Returns the size of the function's code.
|
||||
pub fn compile(&mut self, isa: &TargetIsa) -> Result<CodeOffset, CtonError> {
|
||||
pub fn compile(&mut self, isa: &TargetIsa) -> CtonResult<CodeOffset> {
|
||||
let _tt = timing::compile();
|
||||
self.verify_if(isa)?;
|
||||
|
||||
@@ -179,7 +179,7 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Run the verifier only if the `enable_verifier` setting is true.
|
||||
pub fn verify_if<'a, FOI: Into<FlagsOrIsa<'a>>>(&self, fisa: FOI) -> CtonResult {
|
||||
pub fn verify_if<'a, FOI: Into<FlagsOrIsa<'a>>>(&self, fisa: FOI) -> CtonResult<()> {
|
||||
let fisa = fisa.into();
|
||||
if fisa.flags.enable_verifier() {
|
||||
self.verify(fisa).map_err(Into::into)
|
||||
@@ -194,7 +194,7 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Run the locations verifier only if the `enable_verifier` setting is true.
|
||||
pub fn verify_locations_if(&self, isa: &TargetIsa) -> CtonResult {
|
||||
pub fn verify_locations_if(&self, isa: &TargetIsa) -> CtonResult<()> {
|
||||
if isa.flags().enable_verifier() {
|
||||
self.verify_locations(isa).map_err(Into::into)
|
||||
} else {
|
||||
@@ -203,27 +203,27 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Perform dead-code elimination on the function.
|
||||
pub fn dce<'a, FOI: Into<FlagsOrIsa<'a>>>(&mut self, fisa: FOI) -> CtonResult {
|
||||
pub fn dce<'a, FOI: Into<FlagsOrIsa<'a>>>(&mut self, fisa: FOI) -> CtonResult<()> {
|
||||
do_dce(&mut self.func, &mut self.domtree);
|
||||
self.verify_if(fisa)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Perform pre-legalization rewrites on the function.
|
||||
pub fn preopt(&mut self, isa: &TargetIsa) -> CtonResult {
|
||||
pub fn preopt(&mut self, isa: &TargetIsa) -> CtonResult<()> {
|
||||
do_preopt(&mut self.func);
|
||||
self.verify_if(isa)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Perform NaN canonicalizing rewrites on the function.
|
||||
pub fn canonicalize_nans(&mut self, isa: &TargetIsa) -> CtonResult {
|
||||
pub fn canonicalize_nans(&mut self, isa: &TargetIsa) -> CtonResult<()> {
|
||||
do_nan_canonicalization(&mut self.func);
|
||||
self.verify_if(isa)
|
||||
}
|
||||
|
||||
/// Run the legalizer for `isa` on the function.
|
||||
pub fn legalize(&mut self, isa: &TargetIsa) -> CtonResult {
|
||||
pub fn legalize(&mut self, isa: &TargetIsa) -> CtonResult<()> {
|
||||
// Legalization invalidates the domtree and loop_analysis by mutating the CFG.
|
||||
// TODO: Avoid doing this when legalization doesn't actually mutate the CFG.
|
||||
self.domtree.clear();
|
||||
@@ -233,7 +233,7 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Perform post-legalization rewrites on the function.
|
||||
pub fn postopt(&mut self, isa: &TargetIsa) -> CtonResult {
|
||||
pub fn postopt(&mut self, isa: &TargetIsa) -> CtonResult<()> {
|
||||
do_postopt(&mut self.func, isa);
|
||||
self.verify_if(isa)?;
|
||||
Ok(())
|
||||
@@ -262,13 +262,13 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Perform simple GVN on the function.
|
||||
pub fn simple_gvn<'a, FOI: Into<FlagsOrIsa<'a>>>(&mut self, fisa: FOI) -> CtonResult {
|
||||
pub fn simple_gvn<'a, FOI: Into<FlagsOrIsa<'a>>>(&mut self, fisa: FOI) -> CtonResult<()> {
|
||||
do_simple_gvn(&mut self.func, &mut self.domtree);
|
||||
self.verify_if(fisa)
|
||||
}
|
||||
|
||||
/// Perform LICM on the function.
|
||||
pub fn licm<'a, FOI: Into<FlagsOrIsa<'a>>>(&mut self, fisa: FOI) -> CtonResult {
|
||||
pub fn licm<'a, FOI: Into<FlagsOrIsa<'a>>>(&mut self, fisa: FOI) -> CtonResult<()> {
|
||||
do_licm(
|
||||
&mut self.func,
|
||||
&mut self.cfg,
|
||||
@@ -279,7 +279,7 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Perform unreachable code elimination.
|
||||
pub fn eliminate_unreachable_code<'a, FOI>(&mut self, fisa: FOI) -> CtonResult
|
||||
pub fn eliminate_unreachable_code<'a, FOI>(&mut self, fisa: FOI) -> CtonResult<()>
|
||||
where
|
||||
FOI: Into<FlagsOrIsa<'a>>,
|
||||
{
|
||||
@@ -288,13 +288,13 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Run the register allocator.
|
||||
pub fn regalloc(&mut self, isa: &TargetIsa) -> CtonResult {
|
||||
pub fn regalloc(&mut self, isa: &TargetIsa) -> CtonResult<()> {
|
||||
self.regalloc
|
||||
.run(isa, &mut self.func, &self.cfg, &mut self.domtree)
|
||||
}
|
||||
|
||||
/// Insert prologue and epilogues after computing the stack frame layout.
|
||||
pub fn prologue_epilogue(&mut self, isa: &TargetIsa) -> CtonResult {
|
||||
pub fn prologue_epilogue(&mut self, isa: &TargetIsa) -> CtonResult<()> {
|
||||
assert!(
|
||||
self.func.stack_limit.is_none(),
|
||||
"stack_limit isn't implemented yet"
|
||||
@@ -306,7 +306,7 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Run the instruction shrinking pass.
|
||||
pub fn shrink_instructions(&mut self, isa: &TargetIsa) -> CtonResult {
|
||||
pub fn shrink_instructions(&mut self, isa: &TargetIsa) -> CtonResult<()> {
|
||||
shrink_instructions(&mut self.func, isa);
|
||||
self.verify_if(isa)?;
|
||||
self.verify_locations_if(isa)?;
|
||||
@@ -314,7 +314,7 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Run the branch relaxation pass and return the final code size.
|
||||
pub fn relax_branches(&mut self, isa: &TargetIsa) -> Result<CodeOffset, CtonError> {
|
||||
pub fn relax_branches(&mut self, isa: &TargetIsa) -> CtonResult<CodeOffset> {
|
||||
let code_size = relax_branches(&mut self.func, isa)?;
|
||||
self.verify_if(isa)?;
|
||||
self.verify_locations_if(isa)?;
|
||||
|
||||
@@ -56,7 +56,7 @@ use flowgraph;
|
||||
use ir;
|
||||
use isa::enc_tables::Encodings;
|
||||
use regalloc;
|
||||
use result;
|
||||
use result::CtonResult;
|
||||
use settings;
|
||||
use settings::CallConv;
|
||||
use std::boxed::Box;
|
||||
@@ -281,7 +281,7 @@ pub trait TargetIsa: fmt::Display {
|
||||
/// Compute the stack layout and insert prologue and epilogue code into `func`.
|
||||
///
|
||||
/// Return an error if the stack frame is too large.
|
||||
fn prologue_epilogue(&self, func: &mut ir::Function) -> result::CtonResult {
|
||||
fn prologue_epilogue(&self, func: &mut ir::Function) -> CtonResult<()> {
|
||||
let _tt = timing::prologue_epilogue();
|
||||
// This default implementation is unlikely to be good enough.
|
||||
use ir::stackslot::{StackOffset, StackSize};
|
||||
|
||||
@@ -10,7 +10,7 @@ use ir::{get_probestack_funcref, AbiParam, ArgumentExtension, ArgumentLoc, Argum
|
||||
InstBuilder, ValueLoc};
|
||||
use isa::{RegClass, RegUnit, TargetIsa};
|
||||
use regalloc::RegisterSet;
|
||||
use result;
|
||||
use result::CtonResult;
|
||||
use settings::CallConv;
|
||||
use stack_layout::layout_stack;
|
||||
use std::i32;
|
||||
@@ -257,7 +257,7 @@ fn callee_saved_gprs_used(isa: &TargetIsa, func: &ir::Function) -> RegisterSet {
|
||||
used
|
||||
}
|
||||
|
||||
pub fn prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult {
|
||||
pub fn prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult<()> {
|
||||
match func.signature.call_conv {
|
||||
// For now, just translate fast and cold as system_v.
|
||||
CallConv::Fast | CallConv::Cold | CallConv::SystemV => {
|
||||
@@ -269,7 +269,7 @@ pub fn prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::Ct
|
||||
}
|
||||
}
|
||||
|
||||
pub fn baldrdash_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult {
|
||||
pub fn baldrdash_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult<()> {
|
||||
debug_assert!(
|
||||
!isa.flags().probestack_enabled(),
|
||||
"baldrdash does not expect cretonne to emit stack probes"
|
||||
@@ -290,7 +290,7 @@ pub fn baldrdash_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) ->
|
||||
|
||||
/// Implementation of the fastcall-based Win64 calling convention described at [1]
|
||||
/// [1] https://msdn.microsoft.com/en-us/library/ms235286.aspx
|
||||
pub fn fastcall_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult {
|
||||
pub fn fastcall_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult<()> {
|
||||
if isa.triple().pointer_width().unwrap() != PointerWidth::U64 {
|
||||
panic!("TODO: windows-fastcall: x86-32 not implemented yet");
|
||||
}
|
||||
@@ -362,7 +362,7 @@ pub fn fastcall_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> r
|
||||
}
|
||||
|
||||
/// Insert a System V-compatible prologue and epilogue.
|
||||
pub fn system_v_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult {
|
||||
pub fn system_v_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult<()> {
|
||||
// The original 32-bit x86 ELF ABI had a 4-byte aligned stack pointer, but
|
||||
// newer versions use a 16-byte aligned stack pointer.
|
||||
let stack_align = 16;
|
||||
|
||||
@@ -13,7 +13,7 @@ use isa::enc_tables::{self as shared_enc_tables, lookup_enclist, Encodings};
|
||||
use isa::Builder as IsaBuilder;
|
||||
use isa::{EncInfo, RegClass, RegInfo, TargetIsa};
|
||||
use regalloc;
|
||||
use result;
|
||||
use result::CtonResult;
|
||||
use std::boxed::Box;
|
||||
use std::fmt;
|
||||
use target_lexicon::{PointerWidth, Triple};
|
||||
@@ -129,7 +129,7 @@ impl TargetIsa for Isa {
|
||||
emit_function(func, binemit::emit_inst, sink)
|
||||
}
|
||||
|
||||
fn prologue_epilogue(&self, func: &mut ir::Function) -> result::CtonResult {
|
||||
fn prologue_epilogue(&self, func: &mut ir::Function) -> CtonResult<()> {
|
||||
let _tt = timing::prologue_epilogue();
|
||||
abi::prologue_epilogue(func, self)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ impl Context {
|
||||
func: &mut Function,
|
||||
cfg: &ControlFlowGraph,
|
||||
domtree: &mut DominatorTree,
|
||||
) -> CtonResult {
|
||||
) -> CtonResult<()> {
|
||||
let _tt = timing::regalloc();
|
||||
debug_assert!(domtree.is_valid());
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ pub enum CtonError {
|
||||
}
|
||||
|
||||
/// A Cretonne compilation result.
|
||||
pub type CtonResult = Result<(), CtonError>;
|
||||
pub type CtonResult<T> = Result<T, CtonError>;
|
||||
|
||||
impl From<VerifierError> for CtonError {
|
||||
fn from(e: VerifierError) -> Self {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use ir::stackslot::{StackOffset, StackSize, StackSlotKind};
|
||||
use ir::StackSlots;
|
||||
use result::CtonError;
|
||||
use result::{CtonError, CtonResult};
|
||||
use std::cmp::{max, min};
|
||||
|
||||
/// Compute the stack frame layout.
|
||||
@@ -15,7 +15,7 @@ use std::cmp::{max, min};
|
||||
/// Returns the total stack frame size which is also saved in `frame.frame_size`.
|
||||
///
|
||||
/// If the stack frame is too big, returns an `ImplLimitExceeded` error.
|
||||
pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> Result<StackSize, CtonError> {
|
||||
pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> CtonResult<StackSize> {
|
||||
// Each object and the whole stack frame must fit in 2 GB such that any relative offset within
|
||||
// the frame fits in a `StackOffset`.
|
||||
let max_size = StackOffset::max_value() as StackSize;
|
||||
|
||||
Reference in New Issue
Block a user