use of com.oracle.truffle.llvm.parser.LLVMParserResult in project sulong by graalvm.
the class Runner method parse.
private LLVMParserResult parse(LLVMLanguage language, LLVMContext context, Source source, ExternalLibrary library, ByteBuffer bytes) throws IOException {
assert library != null;
BitcodeParserResult bitcodeParserResult = BitcodeParserResult.getFromSource(source, bytes);
context.addLibraryPaths(bitcodeParserResult.getLibraryPaths());
List<String> libraries = bitcodeParserResult.getLibraries();
if (!libraries.isEmpty()) {
ExternalLibrary[] libs = context.addExternalLibraries(libraries);
LLVMParserResult[] parserResults = parse(language, context, libs);
handleParserResult(context, parserResults);
}
return LLVMParserRuntime.parse(source, library, bitcodeParserResult, language, context, nodeFactory);
}
use of com.oracle.truffle.llvm.parser.LLVMParserResult in project sulong by graalvm.
the class Runner method parse.
private LLVMParserResult[] parse(LLVMLanguage language, LLVMContext context, ExternalLibrary[] libs) {
LLVMParserResult[] parserResults = new LLVMParserResult[libs.length];
for (int i = 0; i < libs.length; i++) {
ExternalLibrary lib = libs[i];
if (!lib.isParsed()) {
try {
Path path = lib.getPath();
byte[] bytes = Files.readAllBytes(path);
// at the moment, we don't need the bitcode as the content of the source
Source source = Source.newBuilder(path.toString()).mimeType(LLVMLanguage.LLVM_BITCODE_MIME_TYPE).name(path.getFileName().toString()).build();
parserResults[i] = parse(language, context, source, lib, ByteBuffer.wrap(bytes));
lib.setParsed();
} catch (Throwable t) {
throw new RuntimeException("Error while trying to parse " + lib.getName(), t);
}
}
}
return parserResults;
}
use of com.oracle.truffle.llvm.parser.LLVMParserResult in project sulong by graalvm.
the class Runner method parse.
/**
* Parse bitcode data and do first initializations to prepare bitcode execution.
*/
public CallTarget parse(LLVMLanguage language, LLVMContext context, Source source) throws IOException {
initializeContext(language, context);
try {
ByteBuffer bytes;
ExternalLibrary library;
if (source.getMimeType().equals(LLVMLanguage.LLVM_BITCODE_BASE64_MIME_TYPE)) {
bytes = ByteBuffer.wrap(decodeBase64(source.getCharacters()));
library = new ExternalLibrary("<STREAM>");
} else if (source.getMimeType().equals(LLVMLanguage.LLVM_SULONG_TYPE)) {
NativeLibraryDescriptor descriptor = Parser.parseLibraryDescriptor(source.getCharacters());
String filename = descriptor.getFilename();
bytes = read(filename);
library = new ExternalLibrary(Paths.get(filename), null);
} else if (source.getPath() != null) {
bytes = read(source.getPath());
library = new ExternalLibrary(Paths.get(source.getPath()), null);
} else {
throw new IllegalStateException();
}
LLVMParserResult parserResult = parse(language, context, source, library, bytes);
handleParserResult(context, parserResult);
return createLibraryCallTarget(context, library, parserResult);
} catch (Throwable t) {
throw new IOException("Error while trying to parse " + source.getPath(), t);
}
}
Aggregations