< prev index next >

src/jdk.incubator.jextract/share/classes/jdk/incubator/jextract/tool/HandleSourceFactory.java

Print this page

        

*** 76,85 **** --- 76,103 ---- this.libraryPaths = libraryPaths; this.clsName = clsName; this.pkgName = pkgName; } + private static String getCLangConstantsHolder() { + String prefix = "jdk.incubator.foreign.MemoryLayouts."; + String arch = System.getProperty("os.arch"); + String os = System.getProperty("os.name"); + if (arch.equals("amd64") || arch.equals("x86_64")) { + if (os.startsWith("Windows")) { + return prefix + "WinABI"; + } else { + return prefix + "SysV"; + } + } else if (arch.equals("aarch64")) { + return prefix + "AArch64ABI"; + } + throw new UnsupportedOperationException("Unsupported os or arch: " + os + ", " + arch); + } + + private static final String C_LANG_CONSTANTS_HOLDER = getCLangConstantsHolder(); + public JavaFileObject[] generate(Declaration.Scoped decl) { builder.addPackagePrefix(pkgName); builder.classBegin(clsName); builder.addLibraries(libraryNames.toArray(new String[0]), libraryPaths != null ? libraryPaths.toArray(new String[0]) : null);
*** 97,107 **** try { return new JavaFileObject[] { fileFromString(pkgName, clsName, src), fileFromString(pkgName,"RuntimeHelper", (pkgName.isEmpty()? "" : "package " + pkgName + ";\n") + Files.readAllLines(Paths.get(runtimeHelper.toURI())) ! .stream().collect(Collectors.joining("\n"))) }; } catch (IOException ex) { throw new UncheckedIOException(ex); } catch (URISyntaxException ex2) { throw new RuntimeException(ex2); --- 115,125 ---- try { return new JavaFileObject[] { fileFromString(pkgName, clsName, src), fileFromString(pkgName,"RuntimeHelper", (pkgName.isEmpty()? "" : "package " + pkgName + ";\n") + Files.readAllLines(Paths.get(runtimeHelper.toURI())) ! .stream().collect(Collectors.joining("\n")).replace("${C_LANG}", C_LANG_CONSTANTS_HOLDER)) }; } catch (IOException ex) { throw new UncheckedIOException(ex); } catch (URISyntaxException ex2) { throw new RuntimeException(ex2);
< prev index next >