All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.qbicc.graph.Load Maven / Gradle / Ivy

There is a newer version: 0.77.0
Show newest version
package org.qbicc.graph;

import java.util.Objects;

import org.qbicc.graph.atomic.ReadAccessMode;
import org.qbicc.type.ValueType;
import org.qbicc.type.definition.element.ExecutableElement;

/**
 * A load from memory.
 */
public class Load extends AbstractValue implements OrderedNode {
    private final Node dependency;
    private final Value pointer;
    private final ReadAccessMode mode;

    Load(Node callSite, ExecutableElement element, int line, int bci, Node dependency, Value pointer, ReadAccessMode mode) {
        super(callSite, element, line, bci);
        this.dependency = dependency;
        this.pointer = pointer;
        this.mode = mode;
        if (! pointer.isReadable()) {
            throw new IllegalArgumentException("Pointer is not readable");
        }
    }

    @Override
    public Node getDependency() {
        return dependency;
    }

    int calcHashCode() {
        return Objects.hash(dependency, pointer, mode);
    }

    @Override
    String getNodeName() {
        return "Load";
    }

    public boolean equals(final Object other) {
        return other instanceof Load && equals((Load) other);
    }

    @Override
    public StringBuilder toString(StringBuilder b) {
        return super.toString(b).append('(').append(mode).append(')');
    }

    @Override
    StringBuilder toRValueString(StringBuilder b) {
        return pointer.toReferenceString(b.append("load ").append(mode).append(" from "));
    }

    public boolean equals(final Load other) {
        return this == other || other != null && dependency.equals(other.dependency) && pointer.equals(other.pointer) && mode == other.mode;
    }

    public ValueType getType() {
        return pointer.getPointeeType();
    }

    public Value getPointer() {
        return pointer;
    }

    public ReadAccessMode getAccessMode() {
        return mode;
    }

    @Override
    public int getValueDependencyCount() {
        return 1;
    }

    @Override
    public Value getValueDependency(int index) throws IndexOutOfBoundsException {
        return switch (index) {
            case 0 -> pointer;
            default -> throw new IndexOutOfBoundsException(index);
        };
    }

    public  R accept(final ValueVisitor visitor, final T param) {
        return visitor.visit(param, this);
    }

    public boolean isConstant() {
        return pointer.isPointeeConstant();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy