Skip to content

Commit

Permalink
feat: add function names to bytecode
Browse files Browse the repository at this point in the history
  • Loading branch information
jac3km4 committed May 1, 2024
1 parent c4fae7b commit 336d448
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion decompiler/src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::str::FromStr;
use itertools::Itertools;
use redscript::ast::{BinOp, Constant, Expr, Ident, Literal, Seq, SourceAst, SwitchCase, TypeName, UnOp};
use redscript::bundle::ConstantPool;
use redscript::bytecode::Instr;
use redscript::definition::{AnyDefinition, Definition, Function, Type};

use crate::error::Error;
Expand Down Expand Up @@ -219,7 +220,15 @@ fn write_function_body<W: Write>(
for (offset, instr) in fun.code.iter() {
let op = format!("{:?}", instr).to_lowercase();
write_indent(out, depth + 1)?;
writeln!(out, "{}: {}", offset.value, op)?;
match instr {
Instr::InvokeStatic(_, _, fun, _) => {
writeln!(out, "{}: {} // {}", offset.value, op, pool.def_name(fun)?)?;
}
Instr::InvokeVirtual(_, _, name, _) => {
writeln!(out, "{}: {} // {}", offset.value, op, pool.names.get(name)?)?;
}
_ => writeln!(out, "{}: {}", offset.value, op)?,
}
}
}
}
Expand Down

0 comments on commit 336d448

Please sign in to comment.