package com.oracle.truffle.llvm.parser.metadata.debuginfo;
import com.oracle.truffle.llvm.parser.metadata.MDBaseNode;
import com.oracle.truffle.llvm.parser.metadata.MDKind;
import com.oracle.truffle.llvm.parser.metadata.MetadataAttachmentHolder;
import com.oracle.truffle.llvm.parser.metadata.MetadataValueList;
import com.oracle.truffle.llvm.parser.model.SymbolImpl;
import com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation;
import com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceSymbol;
import com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceStaticMemberType;
import com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType;
import java.util.HashMap;
import java.util.Map;
final class DebugInfoCache {
static MDBaseNode getDebugInfo(MetadataAttachmentHolder holder) {
if (holder.hasAttachedMetadata()) {
return holder.getMetadataAttachment(MDKind.DBG_NAME);
} else {
return null;
}
}
private final Map<MDBaseNode, LLVMSourceSymbol> parsedVariables;
private final DIScopeBuilder scopeBuilder;
private final DITypeExtractor ;
DebugInfoCache(MetadataValueList metadata, Map<LLVMSourceStaticMemberType, SymbolImpl> staticMembers) {
this.parsedVariables = new HashMap<>();
this.scopeBuilder = new DIScopeBuilder(metadata);
this.typeExtractor = new DITypeExtractor(scopeBuilder, metadata, staticMembers);
}
LLVMSourceSymbol getSourceSymbol(MDBaseNode mdVariable, boolean isStatic) {
LLVMSourceSymbol lookup = parsedVariables.get(mdVariable);
if (lookup != null) {
return lookup;
}
LLVMSourceLocation location = scopeBuilder.buildLocation(mdVariable);
final LLVMSourceType type = typeExtractor.parseType(mdVariable);
final String varName = MDNameExtractor.getName(mdVariable);
final LLVMSourceSymbol symbol = LLVMSourceSymbol.create(varName, location, type, isStatic);
parsedVariables.put(mdVariable, symbol);
if (location != null) {
location = location.getParent();
}
if (location != null) {
location.addSymbol(symbol);
}
return symbol;
}
LLVMSourceLocation buildLocation(MDBaseNode node) {
return scopeBuilder.buildLocation(node);
}
LLVMSourceType parseType(MDBaseNode mdType) {
return typeExtractor.parseType(mdType);
}
void endLocalScope() {
scopeBuilder.clearLocalScopes();
}
void importScope(MDBaseNode node, LLVMSourceLocation importedScope) {
scopeBuilder.importScope(node, importedScope);
}
}