Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/api/src/trampoline/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use alloc::{boxed::Box, rc::Rc, string::ToString, vec::Vec};
use anyhow::Result;
use core::cmp;
use cranelift_codegen::ir::{types, InstBuilder, StackSlotData, StackSlotKind, TrapCode};
use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::{binemit, ir, isa, Context};
use cranelift_entity::{EntityRef, PrimaryMap};
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
Expand Down Expand Up @@ -174,6 +175,7 @@ fn make_trampoline(
&mut trap_sink,
&mut stackmap_sink,
)
.map_err(|error| pretty_error(&context.func, Some(isa), error))
.expect("compile_and_emit");

let mut unwind_info = Vec::new();
Expand Down
6 changes: 3 additions & 3 deletions crates/environ/src/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::address_map::{ModuleAddressMap, ValueLabelsRanges};
use crate::module;
use crate::module_environ::FunctionBodyData;
use alloc::vec::Vec;
use cranelift_codegen::{binemit, ir, isa, CodegenError};
use cranelift_codegen::{binemit, ir, isa};
use cranelift_entity::PrimaryMap;
use cranelift_wasm::{DefinedFuncIndex, FuncIndex, ModuleTranslationState, WasmError};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -156,8 +156,8 @@ pub enum CompileError {
Wasm(#[from] WasmError),

/// A compilation error occured.
#[error("Compilation error")]
Codegen(#[from] CodegenError),
#[error("Compilation error: {0}")]
Codegen(String),

/// A compilation error occured.
#[error("Debug info is not supported with this configuration")]
Expand Down
33 changes: 25 additions & 8 deletions crates/environ/src/cranelift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use cranelift_codegen::binemit;
use cranelift_codegen::ir;
use cranelift_codegen::ir::ExternalName;
use cranelift_codegen::isa;
use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::Context;
use cranelift_entity::PrimaryMap;
use cranelift_wasm::{DefinedFuncIndex, FuncIndex, FuncTranslator, ModuleTranslationState};
Expand Down Expand Up @@ -239,13 +240,21 @@ impl crate::compilation::Compiler for Cranelift {
let mut reloc_sink = RelocSink::new(func_index);
let mut trap_sink = TrapSink::new();
let mut stackmap_sink = binemit::NullStackmapSink {};
context.compile_and_emit(
isa,
&mut code_buf,
&mut reloc_sink,
&mut trap_sink,
&mut stackmap_sink,
)?;
context
.compile_and_emit(
isa,
&mut code_buf,
&mut reloc_sink,
&mut trap_sink,
&mut stackmap_sink,
)
.map_err(|error| {
CompileError::Codegen(pretty_error(
&context.func,
Some(isa),
error,
))
})?;

context.emit_unwind_info(isa, &mut unwind_info);

Expand All @@ -257,7 +266,15 @@ impl crate::compilation::Compiler for Cranelift {
};

let ranges = if generate_debug_info {
Some(context.build_value_labels_ranges(isa)?)
let ranges =
context.build_value_labels_ranges(isa).map_err(|error| {
CompileError::Codegen(pretty_error(
&context.func,
Some(isa),
error,
))
})?;
Some(ranges)
} else {
None
};
Expand Down
9 changes: 8 additions & 1 deletion crates/jit/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use alloc::vec::Vec;
use core::convert::TryFrom;
use cranelift_codegen::ir::InstBuilder;
use cranelift_codegen::isa::{TargetFrontendConfig, TargetIsa};
use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::Context;
use cranelift_codegen::{binemit, ir};
use cranelift_entity::{EntityRef, PrimaryMap};
Expand Down Expand Up @@ -336,7 +337,13 @@ fn make_trampoline(
&mut trap_sink,
&mut stackmap_sink,
)
.map_err(|error| SetupError::Compile(CompileError::Codegen(error)))?;
.map_err(|error| {
SetupError::Compile(CompileError::Codegen(pretty_error(
&context.func,
Some(isa),
error,
)))
})?;

context.emit_unwind_info(isa, &mut unwind_info);

Expand Down