package com.oracle.objectfile;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.oracle.objectfile.ObjectFile.Element;
import com.oracle.objectfile.ObjectFile.ProgbitsSectionImpl;
import com.oracle.objectfile.ObjectFile.RelocatableSectionImpl;
import com.oracle.objectfile.ObjectFile.RelocationKind;
import com.oracle.objectfile.ObjectFile.RelocationRecord;
import com.oracle.objectfile.ObjectFile.Section;
public class BasicProgbitsSectionImpl extends BasicElementImpl implements ProgbitsSectionImpl {
private byte[] content;
public BasicProgbitsSectionImpl(byte[] content) {
this(content, null);
}
public BasicProgbitsSectionImpl(Section s) {
this(new byte[0], s);
}
public BasicProgbitsSectionImpl(byte[] content, Section s) {
super(s);
this.content = content;
}
public BasicProgbitsSectionImpl() {
}
@Override
public Set<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) {
return ObjectFile.minimalDependencies(decisions, getElement());
}
@Override
public int getOrDecideSize(Map<Element, LayoutDecisionMap> alreadyDecided, int sizeHint) {
return content.length;
}
@Override
public byte[] getOrDecideContent(Map<Element, LayoutDecisionMap> alreadyDecided, byte[] contentHint) {
return content;
}
@Override
public int getMemSize(Map<Element, LayoutDecisionMap> alreadyDecided) {
return content.length;
}
@Override
public int getAlignment() {
return getElement().getAlignment();
}
@Override
public void setContent(byte[] c) {
this.content = c;
}
@Override
public byte[] getContent() {
return content;
}
@Override
public Section getElement() {
return (Section) super.getElement();
}
public List<Section> getElements() {
return Collections.singletonList(getElement());
}
@Override
public RelocationRecord markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
return ((RelocatableSectionImpl) getElement()).markRelocationSite(offset, ByteBuffer.wrap(getContent()).order(getOwner().getByteOrder()), k, symbolName, useImplicitAddend,
explicitAddend);
}
@Override
public final RelocationRecord markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
assert getContent() == null || bb.array() == getContent();
return ((RelocatableSectionImpl) getElement()).markRelocationSite(offset, bb, k, symbolName, useImplicitAddend, explicitAddend);
}
@Override
public Element getOrCreateRelocationElement(boolean useImplicitAddend) {
return ((RelocatableSectionImpl) getElement()).getOrCreateRelocationElement(useImplicitAddend);
}
@Override
public boolean isLoadable() {
return true;
}
}