lmasm authoring skill
lmasm exposes the Java ASM bytecode inspection library to lmcode programs so LMScript workflows can enumerate classes and class-level reference edges across JARs, class directories, and class files.
Purpose
Use lmasm to inspect compiled JVM bytecode from an LMScript program and compute dependency coverage across main-scope code, test-scope code, and third-party library JARs without writing custom Java analyzers.
When to use it
Choose lmasm when you need deterministic class inventory and constant-pool plus syntax-tree reference extraction on JVM archives or class directories. Use a full JVM profiler or build tool when you need runtime call stacks, dynamic reflection traces, or Maven resolution graphs.
Install
Install the LMScript compiler with npm install -g @lmctl-ai/lmctl, or install the standalone GraalVM native release binary for Linux, macOS, or Windows through lmscript install.
npm install -g @lmctl-ai/lmctl
lmscript install github:lmctl-ai/lmasm@v0.1.0
lmasm --version
lmasm --lmcode-schema --json
lmasm --lmcode-signatures
When building from a source checkout, run mvn package with JDK 21 or newer to produce target/lmasm.jar and add bin to PATH.
Commands
Bind lmasm inside an LMScript program with an _lmcode_ block and execute the compiled bytecode through run_lmcode.
program = _lmcode_ cli="lmasm" install="github:lmctl-ai/lmasm@v0.1.0";
let classes = asm_classes("fixtures/jars/liba.jar");
for (cn in classes) {
let refs = asm_refs("fixtures/jars/liba.jar", cn);
print(cn + " references " + str(refs.len()) + " classes");
}
end _lmcode_
r = run_lmcode(program);
assert(r.ok);
You can also pass schema="schema/lmasm.schema.json" during cold syntax checks when the host binary is not yet cached on PATH.
Inputs and outputs
The host function asm_classes accepts a path to a .jar archive, a compiled classes directory, or a single .class file and returns a StrList of dotted class names while skipping module-info and package-info entries.
The host function asm_refs accepts a container path and a dotted class name and returns a deduplicated StrList of every external class referenced in the constant pool or ASM tree walk. Execution concludes with an LMCODE_RETURN_BEGIN and LMCODE_RETURN_END JSON envelope consumed by run_lmcode.
Safety rules
lmasm inspects bytecode statically with ASM 9.11 and never loads or executes target classes on the JVM. Compile newer Java inputs with --release 21 if your compiler emits class file versions newer than the bundled ASM reader supports.
Do not pass untrusted bytecode programs to --lmcode without review, as standard lmcode file functions execute with the permissions of the calling user.
Worked examples
The repository ships examples/dep-analysis.lms, which computes how many classes in each third-party library JAR are referenced by custom code overall versus test-scope code only.
program = _lmcode_ cli="lmasm";
let lib_paths = str_split("fixtures/jars/liba.jar,fixtures/jars/libb.jar", ",");
let main_paths = str_split("fixtures/appmain/classes", ",");
let test_paths = str_split("fixtures/apptest.jar", ",");
fn scan(path: string, lib_set: StrMap, used: StrMap) -> void {
for (class_name in asm_classes(path)) {
for (ref in asm_refs(path, class_name)) {
if (lib_set.has(ref)) { used.set(ref, "1"); }
}
}
}
for (lib in lib_paths) {
let lib_set = str_map();
for (class_name in asm_classes(lib)) { lib_set.set(class_name, "1"); }
let used = str_map();
let used_test = str_map();
for (p in main_paths) { scan(p, lib_set, used); }
for (p in test_paths) { scan(p, lib_set, used); scan(p, lib_set, used_test); }
print(lib + ", " + str(used.len()) + ", " + str(used_test.len()));
}
end _lmcode_
result = run_lmcode(program);
print(json_stringify(result));
Errors and exit codes
lmasm exits with code 0 on success. Code 2 indicates command-line usage or invocation manifest errors. Code 3 indicates bytecode loading, schema hash mismatch, or runtime execution errors such as unreadable archive paths. Code 4 indicates an application assertion failure.
How to verify
Verify the host schema bytes, canonical signatures, and end-to-end dependency analysis gate from the repository root.
lmasm --version
lmasm --lmcode-schema --json > /tmp/lmasm-schema.json
cmp /tmp/lmasm-schema.json schema/lmasm.schema.json
lmasm --lmcode-signatures > /tmp/lmasm-sigs.txt
./test.sh