implements PR-O3.2
This commit is contained in:
+33
-2
@@ -6,6 +6,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -23,6 +24,8 @@ public class BytecodeEmitter {
|
||||
public BytecodeModule emit(
|
||||
final EmissionPlan plan) {
|
||||
final var inputPlan = plan == null ? EmissionPlan.empty() : plan;
|
||||
final var canonicalConstPool = dedupeConstPool(inputPlan.constPool());
|
||||
final var canonicalExports = dedupeExports(inputPlan.exports());
|
||||
final var functionFragments = new ArrayList<BytecodeFunctionLayoutBuilder.FunctionFragment>(inputPlan.functions().size());
|
||||
final var orderedSyscalls = new LinkedHashMap<SyscallIdentity, BytecodeModule.SyscallDecl>();
|
||||
final var syscallIndexByIdentity = new LinkedHashMap<SyscallIdentity, Integer>();
|
||||
@@ -101,11 +104,11 @@ public class BytecodeEmitter {
|
||||
final var layout = BytecodeFunctionLayoutBuilder.build(ReadOnlyList.wrap(functionFragments));
|
||||
return new BytecodeModule(
|
||||
inputPlan.version(),
|
||||
inputPlan.constPool(),
|
||||
canonicalConstPool,
|
||||
layout.functions(),
|
||||
layout.code(),
|
||||
layout.debugInfo(),
|
||||
inputPlan.exports(),
|
||||
canonicalExports,
|
||||
ReadOnlyList.wrap(orderedSyscalls.values()));
|
||||
}
|
||||
|
||||
@@ -125,6 +128,34 @@ public class BytecodeEmitter {
|
||||
return span;
|
||||
}
|
||||
|
||||
private ReadOnlyList<BytecodeModule.ConstantPoolEntry> dedupeConstPool(
|
||||
final ReadOnlyList<BytecodeModule.ConstantPoolEntry> input) {
|
||||
if (input == null || input.isEmpty()) {
|
||||
return ReadOnlyList.empty();
|
||||
}
|
||||
final var ordered = new LinkedHashSet<BytecodeModule.ConstantPoolEntry>(input.size());
|
||||
for (final var constant : input) {
|
||||
if (constant != null) {
|
||||
ordered.add(constant);
|
||||
}
|
||||
}
|
||||
return ReadOnlyList.wrap(ordered.stream().toList());
|
||||
}
|
||||
|
||||
private ReadOnlyList<BytecodeModule.Export> dedupeExports(
|
||||
final ReadOnlyList<BytecodeModule.Export> input) {
|
||||
if (input == null || input.isEmpty()) {
|
||||
return ReadOnlyList.empty();
|
||||
}
|
||||
final var ordered = new LinkedHashSet<BytecodeModule.Export>(input.size());
|
||||
for (final var export : input) {
|
||||
if (export != null) {
|
||||
ordered.add(export);
|
||||
}
|
||||
}
|
||||
return ReadOnlyList.wrap(ordered.stream().toList());
|
||||
}
|
||||
|
||||
private record SyscallIdentity(
|
||||
String module,
|
||||
String name,
|
||||
|
||||
Reference in New Issue
Block a user