use of com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry in project sulong by graalvm.
the class Function method createInvoke.
private void createInvoke(long[] args) {
int i = 0;
final AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(args[i++]);
final long ccInfo = args[i++];
final InstructionBlock normalSuccessor = function.getBlock(args[i++]);
final InstructionBlock unwindSuccessor = function.getBlock(args[i++]);
FunctionType functionType = null;
if (((ccInfo >> INVOKE_HASEXPLICITFUNCTIONTYPE_SHIFT) & 1) != 0) {
functionType = (FunctionType) types.get(args[i++]);
}
final int target = getIndex(args[i++]);
final Type calleeType;
if (scope.isValueForwardRef(target)) {
calleeType = types.get(args[i++]);
} else {
calleeType = scope.getValueType(target);
}
if (functionType == null) {
if (calleeType instanceof PointerType) {
functionType = (FunctionType) ((PointerType) calleeType).getPointeeType();
} else if (calleeType instanceof FunctionType) {
functionType = (FunctionType) calleeType;
} else {
throw new AssertionError("Cannot find Type of invoked function: " + calleeType.toString());
}
}
int[] arguments = new int[args.length - i];
int skipped = 0;
int j = 0;
while (j < functionType.getArgumentTypes().length && i < args.length) {
arguments[j++] = getIndex(args[i++]);
}
while (i < args.length) {
int index = getIndex(args[i++]);
arguments[j++] = index;
if (scope.isValueForwardRef(index)) {
i++;
skipped++;
}
}
if (skipped > 0) {
arguments = Arrays.copyOf(arguments, arguments.length - skipped);
}
final Type returnType = functionType.getReturnType();
if (returnType == VoidType.INSTANCE) {
emit(VoidInvokeInstruction.fromSymbols(scope, target, arguments, normalSuccessor, unwindSuccessor, paramAttr));
} else {
emit(InvokeInstruction.fromSymbols(scope, returnType, target, arguments, normalSuccessor, unwindSuccessor, paramAttr));
}
isLastBlockTerminated = true;
}
use of com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry in project sulong by graalvm.
the class Module method createFunction.
private void createFunction(long[] args) {
final int recordOffset = useStrTab() ? STRTAB_RECORD_OFFSET : 0;
Type type = types.get(args[FUNCTION_TYPE + recordOffset]);
if (type instanceof PointerType) {
type = ((PointerType) type).getPointeeType();
}
final FunctionType functionType = (FunctionType) type;
final boolean isPrototype = args[FUNCTION_ISPROTOTYPE + recordOffset] != 0;
final Linkage linkage = Linkage.decode(args[FUNCTION_LINKAGE + recordOffset]);
final AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(args[FUNCTION_PARAMATTR + recordOffset]);
if (isPrototype) {
final FunctionDeclaration function = new FunctionDeclaration(functionType, linkage, paramAttr);
module.addFunctionDeclaration(function);
scope.addSymbol(function, function.getType());
if (useStrTab()) {
readNameFromStrTab(args, function);
}
} else {
final FunctionDefinition function = new FunctionDefinition(functionType, linkage, paramAttr);
module.addFunctionDefinition(function);
scope.addSymbol(function, function.getType());
if (useStrTab()) {
readNameFromStrTab(args, function);
}
functionQueue.addLast(function);
}
}
use of com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry in project sulong by graalvm.
the class ParameterAttributes method decodeOldCodeEntry.
private void decodeOldCodeEntry(long[] args) {
final List<AttributesGroup> attrGroup = new ArrayList<>();
for (int i = 0; i < args.length; i += 2) {
attrGroup.add(decodeOldGroupCodeEntry(args[i], args[i + 1]));
}
parameterCodeEntry.add(new AttributesCodeEntry(attrGroup));
}
use of com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry in project sulong by graalvm.
the class Function method createFunctionCall.
private void createFunctionCall(long[] args) {
int i = 0;
final AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(args[i++]);
final long ccinfo = args[i++];
if (((ccinfo >> CALL_HAS_FMF_SHIFT) & 1) != 0) {
// fast math flags
i++;
}
FunctionType functionType = null;
if (((ccinfo >> CALL_HAS_EXPLICITTYPE_SHIFT) & 1) != 0) {
functionType = (FunctionType) types.get(args[i++]);
}
int callee = getIndex(args[i++]);
Type calleeType;
if (scope.isValueForwardRef(callee)) {
calleeType = types.get(args[i++]);
} else {
calleeType = scope.getValueType(callee);
}
if (functionType == null) {
if (calleeType instanceof FunctionType) {
functionType = (FunctionType) calleeType;
} else {
functionType = (FunctionType) ((PointerType) calleeType).getPointeeType();
}
}
int[] arguments = new int[args.length - i];
int skipped = 0;
int j = 0;
while (j < functionType.getArgumentTypes().length && i < args.length) {
arguments[j++] = getIndex(args[i++]);
}
while (i < args.length) {
int index = getIndex(args[i++]);
arguments[j++] = index;
if (scope.isValueForwardRef(index)) {
i++;
skipped++;
}
}
if (skipped > 0) {
arguments = Arrays.copyOf(arguments, arguments.length - skipped);
}
final Type returnType = functionType.getReturnType();
if (returnType == VoidType.INSTANCE) {
emit(VoidCallInstruction.fromSymbols(scope, callee, arguments, paramAttr));
} else {
emit(CallInstruction.fromSymbols(scope, returnType, callee, arguments, paramAttr));
}
}
use of com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry in project sulong by graalvm.
the class ParameterAttributes method decodeCodeEntry.
private void decodeCodeEntry(long[] args) {
final List<AttributesGroup> attrGroup = new ArrayList<>();
for (long groupId : args) {
for (AttributesGroup attr : attributes) {
if (attr.getGroupId() == groupId) {
attrGroup.add(attr);
break;
}
}
}
if (attrGroup.size() != args.length) {
throw new AssertionError("there is a mismatch between defined and found group id's");
}
parameterCodeEntry.add(new AttributesCodeEntry(attrGroup));
}
Aggregations