use thiserror::Error;
#[derive(Error, Debug)]
pub(crate) enum CodeGenError {
#[error("32-bit platforms are not supported")]
Unsupported32BitPlatform,
#[error("Unsupported Wasm type")]
UnsupportedWasmType,
#[error("Unimplemented Wasm instruction")]
UnimplementedWasmInstruction,
#[error("Unimplemented Masm instruction")]
UnimplementedMasmInstruction,
#[error("Unimplemented Wasm load kind")]
UnimplementedWasmLoadKind,
#[error("Instruction not implemented for CPUs without AVX support")]
UnimplementedForNoAvx,
#[error("Instruction not implemented for CPUs without AVX2 support")]
UnimplementedForNoAvx2,
#[error("Instruction not implemented for CPUs without AVX512VL support")]
UnimplementedForNoAvx512VL,
#[error("Instruction not implemented for CPUs without AVX512DQ support")]
UnimplementedForNoAvx512DQ,
#[error("Unsupported eager initialization of tables")]
UnsupportedTableEagerInit,
#[error("Winch internal error: {0}")]
Internal(InternalError),
}
#[derive(Error, Debug)]
pub(crate) enum InternalError {
#[error("Expected register to be available")]
ExpectedRegisterToBeAvailable,
#[error("Expected control frame")]
ControlFrameExpected,
#[error("Control frame for if expected")]
IfControlFrameExpected,
#[error("Not enough values in the value stack")]
MissingValuesInStack,
#[error("Unexpected operand size for operation")]
UnexpectedOperandSize,
#[error("Unexpected value stack index")]
UnexpectedValueStackIndex,
#[error("Unexpected value in value stack")]
UnexpectedValueInValueStack,
#[error("Mismatch in control frame state")]
ControlFrameStateMismatch,
#[error("Table element value expected")]
TableElementValueExpected,
#[error("Illegal fuel state")]
IllegalFuelState,
#[error("Argument for `VMContext` expected")]
VMContextArgumentExpected,
#[error("Expected stack pointer addressing")]
SPAddressingExpected,
#[error("Invalid stack pointer offset")]
InvalidSPOffset,
#[error("Unexpected function call in current context")]
UnexpectedFunctionCall,
#[error("Invalid local offset")]
InvalidLocalOffset,
#[error("Unsupported immediate")]
UnsupportedImm,
#[error("Invalid operand combination")]
InvalidOperandCombination,
#[error("Invalid two argument form")]
InvalidTwoArgumentForm,
}
impl CodeGenError {
pub(crate) const fn unsupported_wasm_type() -> Self {
Self::UnsupportedWasmType
}
pub(crate) const fn unsupported_table_eager_init() -> Self {
Self::UnsupportedTableEagerInit
}
pub(crate) const fn unimplemented_wasm_instruction() -> Self {
Self::UnimplementedWasmInstruction
}
pub(crate) const fn unsupported_32_bit_platform() -> Self {
Self::Unsupported32BitPlatform
}
pub(crate) const fn unexpected_function_call() -> Self {
Self::Internal(InternalError::UnexpectedFunctionCall)
}
pub(crate) const fn sp_addressing_expected() -> Self {
Self::Internal(InternalError::SPAddressingExpected)
}
pub(crate) const fn invalid_sp_offset() -> Self {
Self::Internal(InternalError::InvalidSPOffset)
}
pub(crate) const fn expected_register_to_be_available() -> Self {
Self::Internal(InternalError::ExpectedRegisterToBeAvailable)
}
pub(crate) fn vmcontext_arg_expected() -> Self {
Self::Internal(InternalError::VMContextArgumentExpected)
}
pub(crate) const fn control_frame_expected() -> Self {
Self::Internal(InternalError::ControlFrameExpected)
}
pub(crate) const fn if_control_frame_expected() -> Self {
Self::Internal(InternalError::IfControlFrameExpected)
}
pub(crate) const fn missing_values_in_stack() -> Self {
Self::Internal(InternalError::MissingValuesInStack)
}
pub(crate) const fn unexpected_operand_size() -> Self {
Self::Internal(InternalError::UnexpectedOperandSize)
}
pub(crate) const fn unexpected_value_stack_index() -> Self {
Self::Internal(InternalError::UnexpectedValueStackIndex)
}
pub(crate) const fn unexpected_value_in_value_stack() -> Self {
Self::Internal(InternalError::UnexpectedValueInValueStack)
}
pub(crate) const fn control_frame_state_mismatch() -> Self {
Self::Internal(InternalError::ControlFrameStateMismatch)
}
pub(crate) const fn table_element_value_expected() -> Self {
Self::Internal(InternalError::TableElementValueExpected)
}
pub(crate) const fn illegal_fuel_state() -> Self {
Self::Internal(InternalError::IllegalFuelState)
}
pub(crate) const fn invalid_local_offset() -> Self {
Self::Internal(InternalError::InvalidLocalOffset)
}
pub(crate) const fn unsupported_imm() -> Self {
Self::Internal(InternalError::UnsupportedImm)
}
pub(crate) const fn invalid_two_arg_form() -> Self {
Self::Internal(InternalError::InvalidTwoArgumentForm)
}
pub(crate) const fn invalid_operand_combination() -> Self {
Self::Internal(InternalError::InvalidOperandCombination)
}
pub(crate) const fn unimplemented_masm_instruction() -> Self {
Self::UnimplementedMasmInstruction
}
}