org.qbicc.plugin.serialization.ObjectLiteralSerializingVisitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qbicc-plugin-serialization Show documentation
Show all versions of qbicc-plugin-serialization Show documentation
Support for serializing the build time heap
package org.qbicc.plugin.serialization;
import org.qbicc.context.CompilationContext;
import org.qbicc.graph.BasicBlock;
import org.qbicc.graph.Node;
import org.qbicc.graph.NodeVisitor;
import org.qbicc.graph.Value;
import org.qbicc.graph.ValueHandle;
import org.qbicc.graph.literal.ObjectLiteral;
import org.qbicc.graph.literal.ProgramObjectLiteral;
import org.qbicc.graph.literal.StringLiteral;
import org.qbicc.interpreter.VmString;
/**
* A visitor that finds object literals, serializes them to the initial heap
* and replaces the object literal with a reference to the data declaration
* in the initial heap.
*/
public class ObjectLiteralSerializingVisitor implements NodeVisitor.Delegating {
private final CompilationContext ctxt;
private final NodeVisitor delegate;
public ObjectLiteralSerializingVisitor(final CompilationContext ctxt, final NodeVisitor delegate) {
this.ctxt = ctxt;
this.delegate = delegate;
}
public NodeVisitor getDelegateNodeVisitor() {
return delegate;
}
public Value visit(final Node.Copier param, final StringLiteral node) {
VmString vString = ctxt.getVm().intern(node.getValue());
ProgramObjectLiteral literal = BuildtimeHeap.get(ctxt).serializeVmObject(vString);
ctxt.getImplicitSection(param.getBlockBuilder().getRootElement()).declareData(literal.getProgramObject());
return param.getBlockBuilder().notNull(ctxt.getLiteralFactory().bitcastLiteral(literal, node.getType()));
}
public Value visit(final Node.Copier param, final ObjectLiteral node) {
ProgramObjectLiteral literal = BuildtimeHeap.get(ctxt).serializeVmObject(node.getValue());
ctxt.getImplicitSection(param.getBlockBuilder().getRootElement()).declareData(literal.getProgramObject());
return param.getBlockBuilder().notNull(ctxt.getLiteralFactory().bitcastLiteral(literal, node.getType()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy