small code improvements
This commit is contained in:
+23
-3
@@ -2,6 +2,7 @@ package p.studio.compiler.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import p.studio.utilities.structures.MutableList;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
@Builder
|
||||
@@ -10,9 +11,28 @@ public class IRBackend {
|
||||
@Builder.Default
|
||||
private final ReadOnlyList<IRFunction> functions = ReadOnlyList.empty();
|
||||
|
||||
/**
|
||||
* Returns a stable human-readable representation useful for debug logs and tests.
|
||||
*/
|
||||
public static IRBackendAggregator aggregator() {
|
||||
return new IRBackendAggregator();
|
||||
}
|
||||
|
||||
public static final class IRBackendAggregator {
|
||||
private final MutableList<IRFunction> functions = MutableList.create();
|
||||
|
||||
public void merge(final IRBackendFile backendFile) {
|
||||
if (backendFile == null) {
|
||||
return;
|
||||
}
|
||||
functions.addAll(backendFile.functions());
|
||||
}
|
||||
|
||||
public IRBackend emit() {
|
||||
return IRBackend
|
||||
.builder()
|
||||
.functions(functions.toReadOnlyList())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final var sb = new StringBuilder();
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record IRBackendFile(
|
||||
FileId fileId,
|
||||
ReadOnlyList<IRFunction> functions) {
|
||||
public IRBackendFile {
|
||||
fileId = Objects.requireNonNull(fileId, "fileId");
|
||||
functions = functions == null ? ReadOnlyList.empty() : functions;
|
||||
}
|
||||
|
||||
public static IRBackendFile empty(final FileId fileId) {
|
||||
return new IRBackendFile(fileId, ReadOnlyList.empty());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user