mod common;
mod debug;
mod dialect;
mod error;
mod operands;
pub use common::{
AccessBase, AccessKey, BinaryOpInstr, BinaryOpKind, BranchCond, BranchInstr, BranchOperands,
BranchPredicate, CallInstr, CallKind, Capture, CaptureSource, CloseInstr, ClosureInstr,
ConcatInstr, CondOperand, ConstRef, DialectCaptureExtra, ErrNilInstr, GenericForCallInstr,
GenericForLoopInstr, GetTableInstr, GetUpvalueInstr, InstrRef, JumpInstr, LoadBoolInstr,
LoadConstInstr, LoadIntegerInstr, LoadNilInstr, LoadNumberInstr, LowInstr, LoweredChunk,
LoweredProto, LoweringMap, MethodNameHint, MoveInstr, NewTableInstr, NumberLiteral,
NumericForInitInstr, NumericForLoopInstr, ProtoRef, RawInstrRef, Reg, RegRange, ResultPack,
ReturnInstr, SetListInstr, SetTableInstr, SetUpvalueInstr, TailCallInstr, TbcInstr,
UnaryOpInstr, UnaryOpKind, UpvalueRef, ValueOperand, ValuePack, VarArgInstr,
};
pub use debug::{dump_lir, format_low_instr};
pub use error::TransformError;
use crate::decompile::{DecompileContext, DecompileDialect, DecompileError, DecompileState};
use crate::parser::RawChunk;
pub(crate) fn lower_chunk(
state: &mut DecompileState,
_context: &DecompileContext<'_>,
) -> Result<(), DecompileError> {
let raw_chunk = state.raw_chunk.as_ref().unwrap();
state.lowered = Some(match raw_chunk.header.version {
DecompileDialect::Lua51 => dialect::lua51::lower_chunk(raw_chunk),
DecompileDialect::Lua52 => dialect::lua52::lower_chunk(raw_chunk),
DecompileDialect::Lua53 => dialect::lua53::lower_chunk(raw_chunk),
DecompileDialect::Lua54 => dialect::lua54::lower_chunk(raw_chunk),
DecompileDialect::Lua55 => dialect::lua55::lower_chunk(raw_chunk),
DecompileDialect::Luajit => dialect::luajit::lower_chunk(raw_chunk),
DecompileDialect::Luau => dialect::luau::lower_chunk(raw_chunk),
}?);
Ok(())
}
pub fn lower_raw_chunk(chunk: &RawChunk) -> Result<LoweredChunk, TransformError> {
match chunk.header.version {
DecompileDialect::Lua51 => dialect::lua51::lower_chunk(chunk),
DecompileDialect::Lua52 => dialect::lua52::lower_chunk(chunk),
DecompileDialect::Lua53 => dialect::lua53::lower_chunk(chunk),
DecompileDialect::Lua54 => dialect::lua54::lower_chunk(chunk),
DecompileDialect::Lua55 => dialect::lua55::lower_chunk(chunk),
DecompileDialect::Luajit => dialect::luajit::lower_chunk(chunk),
DecompileDialect::Luau => dialect::luau::lower_chunk(chunk),
}
}