use of com.oracle.truffle.llvm.parser.model.SymbolImpl in project sulong by graalvm.
the class DebugInfoModuleProcessor method processModule.
public static void processModule(ModelModule irModel, Source bitcodeSource, MetadataValueList metadata) {
MDUpgrade.perform(metadata);
final DebugInfoCache cache = new DebugInfoCache(metadata, irModel.getSourceStaticMembers());
final Map<LLVMSourceSymbol, SymbolImpl> globals = irModel.getSourceGlobals();
final Map<LLVMSourceStaticMemberType, SymbolImpl> staticMembers = irModel.getSourceStaticMembers();
irModel.accept(new SymbolProcessor(cache, bitcodeSource, globals, staticMembers));
final MDBaseNode cuNode = metadata.getNamedNode(MDNamedNode.COMPILEUNIT_NAME);
final MetadataProcessor mdParser = new MetadataProcessor(cache, globals, staticMembers);
if (cuNode != null) {
cuNode.accept(mdParser);
}
irModel.setFunctionProcessor(new DebugInfoFunctionProcessor(cache));
}
use of com.oracle.truffle.llvm.parser.model.SymbolImpl in project sulong by graalvm.
the class MDUpgrade method visit.
@Override
public void visit(MDGlobalVariable mdGlobal) {
final SymbolImpl symbol = MDSymbolExtractor.getSymbol(mdGlobal.getVariable());
if (symbol instanceof GlobalValueSymbol) {
final GlobalValueSymbol global = (GlobalValueSymbol) symbol;
attachSymbol(global, mdGlobal);
}
if (currentCU != null) {
mdGlobal.setCompileUnit(currentCU);
}
}
use of com.oracle.truffle.llvm.parser.model.SymbolImpl in project sulong by graalvm.
the class MDUpgrade method visit.
@Override
public void visit(MDSubprogram md) {
final SymbolImpl valueSymbol = MDSymbolExtractor.getSymbol(md.getFunction());
if (valueSymbol instanceof FunctionDefinition) {
final FunctionDefinition function = (FunctionDefinition) valueSymbol;
attachSymbol(function, md);
}
if (currentCU != null && md.getCompileUnit() == MDVoidNode.INSTANCE) {
md.setCompileUnit(currentCU);
}
}
use of com.oracle.truffle.llvm.parser.model.SymbolImpl in project sulong by graalvm.
the class LLVMSymbolReadResolver method resolveElementPointer.
public LLVMExpressionNode resolveElementPointer(SymbolImpl base, List<SymbolImpl> indices) {
LLVMExpressionNode currentAddress = resolve(base);
Type currentType = base.getType();
for (int i = 0, indicesSize = indices.size(); i < indicesSize; i++) {
final SymbolImpl indexSymbol = indices.get(i);
final Type indexType = indexSymbol.getType();
final Long indexInteger = evaluateLongIntegerConstant(indexSymbol);
if (indexInteger == null) {
// the index is determined at runtime
if (currentType instanceof StructureType) {
// according to http://llvm.org/docs/LangRef.html#getelementptr-instruction
throw new IllegalStateException("Indices on structs must be constant integers!");
}
AggregateType aggregate = (AggregateType) currentType;
final long indexedTypeLength = runtime.getContext().getIndexOffset(1, aggregate);
currentType = aggregate.getElementType(1);
final LLVMExpressionNode indexNode = resolve(indexSymbol);
currentAddress = runtime.getNodeFactory().createTypedElementPointer(runtime, currentAddress, indexNode, indexedTypeLength, currentType);
} else {
// the index is a constant integer
AggregateType aggregate = (AggregateType) currentType;
final long addressOffset = runtime.getContext().getIndexOffset(indexInteger, aggregate);
currentType = aggregate.getElementType(indexInteger);
// computed by getelementptr even if it is the same as the basepointer
if (addressOffset != 0 || i == indicesSize - 1) {
final LLVMExpressionNode indexNode;
if (indexType == PrimitiveType.I32) {
indexNode = runtime.getNodeFactory().createLiteral(runtime, 1, PrimitiveType.I32);
} else if (indexType == PrimitiveType.I64) {
indexNode = runtime.getNodeFactory().createLiteral(runtime, 1L, PrimitiveType.I64);
} else {
throw new AssertionError(indexType);
}
currentAddress = runtime.getNodeFactory().createTypedElementPointer(runtime, currentAddress, indexNode, addressOffset, currentType);
}
}
}
return currentAddress;
}
use of com.oracle.truffle.llvm.parser.model.SymbolImpl in project sulong by graalvm.
the class ParseUtil method asLong.
public static long asLong(long[] args, int index, Metadata md) {
final int typeIndex = index << 1;
if (typeIndex >= args.length) {
return DEFAULT_NUMBER;
}
final Type type = md.getTypeById(args[typeIndex]);
if (type == MetaType.METADATA || VoidType.INSTANCE.equals(type)) {
return DEFAULT_NUMBER;
}
final int valueIndex = typeIndex + 1;
final SymbolImpl value = md.getScope().getSymbols().getOrNull((int) args[valueIndex]);
if (value instanceof IntegerConstant) {
return ((IntegerConstant) value).getValue();
} else if (value instanceof BigIntegerConstant) {
return ((BigIntegerConstant) value).getValue().longValue();
} else if (value instanceof NullConstant || value instanceof UndefinedConstant) {
return 0L;
} else {
return DEFAULT_NUMBER;
}
}
Aggregations