use of com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor in project sulong by graalvm.
the class LLVMParserRuntime method registerFunctionAlias.
private void registerFunctionAlias(GlobalAlias alias, FunctionDefinition existingFunction) {
LLVMFunctionDescriptor existingDescriptor = scope.getFunctionDescriptor(existingFunction.getName());
LLVMFunctionDescriptor aliasDescriptor = scope.lookupOrCreateFunction(context, alias.getName(), !Linkage.isFileLocal(alias.getLinkage()), index -> LLVMFunctionDescriptor.createDescriptor(context, library, alias.getName(), existingFunction.getType(), index));
boolean replaceExistingFunction = checkReplaceExistingFunction(aliasDescriptor);
aliasDescriptor.declareInSulong(existingDescriptor.getFunction(), Linkage.isWeak(alias.getLinkage()), replaceExistingFunction);
}
use of com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor in project sulong by graalvm.
the class LLVMParserRuntime method checkReplaceExistingFunction.
private boolean checkReplaceExistingFunction(LLVMFunctionDescriptor functionDescriptor) {
if (library.getLibrariesToReplace() != null) {
for (ExternalLibrary lib : library.getLibrariesToReplace()) {
if (functionDescriptor.getLibrary().equals(lib)) {
// We already have a symbol defined in another library but now we are
// overwriting it. We rename the already existing symbol by prefixing it with
// "__libName_", e.g., "@__clock_gettime" would be renamed to
// "@__libc___clock_gettime".
String functionName = functionDescriptor.getName();
assert functionName.charAt(0) == '@';
String renamedFunctionName = "@__" + functionDescriptor.getLibrary().getName() + "_" + functionName.substring(1);
LLVMFunctionDescriptor renamedFunctionDescriptor = scope.lookupOrCreateFunction(functionDescriptor.getContext(), renamedFunctionName, true, index -> LLVMFunctionDescriptor.createDescriptor(functionDescriptor.getContext(), functionDescriptor.getLibrary(), renamedFunctionName, functionDescriptor.getType(), index));
renamedFunctionDescriptor.declareInSulong(functionDescriptor.getFunction(), functionDescriptor.isWeak(), false);
functionDescriptor.setLibrary(library);
return true;
}
}
}
return false;
}
use of com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor in project sulong by graalvm.
the class LLVMFunctionArrayLiteralNode method handleTruffleObject.
@Specialization(guards = "array.isManaged()")
@ExplodeLoop
protected LLVMTruffleObject handleTruffleObject(VirtualFrame frame, LLVMTruffleObject array, @Cached("createForeignWrites()") LLVMForeignWriteNode[] foreignWrites) {
LLVMTruffleObject currentPtr = array;
for (int i = 0; i < values.length; i++) {
try {
LLVMFunctionDescriptor currentValue = (LLVMFunctionDescriptor) values[i].executeTruffleObject(frame);
foreignWrites[i].execute(currentPtr, currentValue);
currentPtr = currentPtr.increment(stride);
} catch (UnexpectedResultException e) {
CompilerDirectives.transferToInterpreter();
throw new IllegalStateException(e);
}
}
return array;
}
use of com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor in project sulong by graalvm.
the class LLVMFunctionArrayLiteralNode method handleAddress.
@Specialization
@ExplodeLoop
protected LLVMAddress handleAddress(VirtualFrame frame, LLVMAddress array, @Cached("createToNativeWithTarget()") LLVMToNativeNode toNative, @Cached("getLLVMMemory()") LLVMMemory memory) {
long currentPtr = array.getVal();
for (int i = 0; i < values.length; i++) {
try {
LLVMFunctionDescriptor currentValue = (LLVMFunctionDescriptor) values[i].executeTruffleObject(frame);
memory.putFunctionPointer(currentPtr, toNative.executeWithTarget(currentValue).getVal());
currentPtr += stride;
} catch (UnexpectedResultException e) {
CompilerDirectives.transferToInterpreter();
throw new IllegalStateException(e);
}
}
return array;
}
use of com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor in project sulong by graalvm.
the class BasicNodeFactory method createInlineAssemblerExpression.
@Override
public LLVMExpressionNode createInlineAssemblerExpression(LLVMParserRuntime runtime, String asmExpression, String asmFlags, LLVMExpressionNode[] args, Type[] argTypes, Type retType, LLVMSourceLocation sourceSection) {
Type[] retTypes = null;
int[] retOffsets = null;
if (retType instanceof StructureType) {
// multiple out values
assert args[1] instanceof LLVMAllocaConstInstruction;
LLVMAllocaConstInstruction alloca = (LLVMAllocaConstInstruction) args[1];
retTypes = alloca.getTypes();
retOffsets = alloca.getOffsets();
}
Parser asmParser = new Parser(runtime.getLanguage(), sourceSection, asmExpression, asmFlags, argTypes, retType, retTypes, retOffsets);
LLVMInlineAssemblyRootNode assemblyRoot = asmParser.Parse();
LLVMFunctionDescriptor asm = LLVMFunctionDescriptor.createDescriptor(runtime.getContext(), runtime.getLibrary(), "<asm>", new FunctionType(MetaType.UNKNOWN, new Type[0], false), -1);
asm.declareInSulong(Truffle.getRuntime().createCallTarget(assemblyRoot), false);
LLVMFunctionLiteralNode asmFunction = LLVMFunctionLiteralNodeGen.create(asm);
return new LLVMCallNode(new FunctionType(MetaType.UNKNOWN, argTypes, false), asmFunction, args, sourceSection);
}
Aggregations