Search in sources :

Example 51 with Source

use of com.oracle.truffle.api.source.Source in project sieve by jtulach.

the class Main method main.

public static void main(String[] args) throws Exception {
    System.err.println("Setting up PolyglotEngine");
    PolyglotEngine vm = PolyglotEngine.newBuilder().build();
    URL url = Main.class.getProtectionDomain().getCodeSource().getLocation();
    File local = new File(url.toURI());
    for (; ; ) {
        File sieveInRuby = new File(local, "sieve.R");
        if (sieveInRuby.exists()) {
            break;
        }
        local = local.getParentFile();
    }
    Source r = Source.fromFileName(new File(local, "sieve.R").getPath());
    Source js = Source.fromFileName(new File(local, "sieve.js").getPath());
    vm.eval(r);
    vm.eval(js);
}
Also used : File(java.io.File) PolyglotEngine(com.oracle.truffle.api.vm.PolyglotEngine) URL(java.net.URL) Source(com.oracle.truffle.api.source.Source)

Example 52 with Source

use of com.oracle.truffle.api.source.Source in project sulong by graalvm.

the class InteropTestBase method loadTestBitcodeInternal.

protected static TruffleObject loadTestBitcodeInternal(String name) {
    File dir = new File(testBase, name);
    File file = new File(dir, "O0_MEM2REG.bc");
    Source source;
    try {
        source = Source.newBuilder(file).language("llvm").build();
    } catch (IOException ex) {
        throw new AssertionError(ex);
    }
    CallTarget target = runWithPolyglot.getTruffleTestEnv().parse(source);
    return (TruffleObject) target.call();
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) IOException(java.io.IOException) File(java.io.File) Source(com.oracle.truffle.api.source.Source) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 53 with Source

use of com.oracle.truffle.api.source.Source in project sulong by graalvm.

the class NFIAPITest method loadLibrary.

private static TruffleObject loadLibrary(String lib, String filename, String mimetype) {
    File file = new File(TEST_DIR.toFile(), lib + "/" + filename);
    String loadLib = "load '" + file.getAbsolutePath() + "'";
    Source source = Source.newBuilder(loadLib).name("loadLibrary").mimeType(mimetype).build();
    CallTarget target = runWithPolyglot.getTruffleTestEnv().parse(source);
    return (TruffleObject) target.call();
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) File(java.io.File) Source(com.oracle.truffle.api.source.Source) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 54 with Source

use of com.oracle.truffle.api.source.Source 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;
}
Also used : Path(java.nio.file.Path) ExternalLibrary(com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary) LLVMParserResult(com.oracle.truffle.llvm.parser.LLVMParserResult) Source(com.oracle.truffle.api.source.Source)

Example 55 with Source

use of com.oracle.truffle.api.source.Source in project sulong by graalvm.

the class NFIContextExtension method loadDefaultLibrary.

private TruffleObject loadDefaultLibrary() {
    CompilerAsserts.neverPartOfCompilation();
    final Source source = Source.newBuilder("default").name("default").mimeType("application/x-native").build();
    try {
        return (TruffleObject) env.parse(source).call();
    } catch (Exception ex) {
        throw new IllegalArgumentException(ex);
    }
}
Also used : Source(com.oracle.truffle.api.source.Source) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) InteropException(com.oracle.truffle.api.interop.InteropException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Aggregations

Source (com.oracle.truffle.api.source.Source)113 Test (org.junit.Test)65 RootNode (com.oracle.truffle.api.nodes.RootNode)23 File (java.io.File)20 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)16 Node (com.oracle.truffle.api.nodes.Node)16 SourceSection (com.oracle.truffle.api.source.SourceSection)16 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)15 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)11 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 CallTarget (com.oracle.truffle.api.CallTarget)5 FileWriter (java.io.FileWriter)5 RootCallTarget (com.oracle.truffle.api.RootCallTarget)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)3 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)3 Script (com.oracle.truffle.tools.chromeinspector.types.Script)3