use of com.oracle.svm.hosted.c.codegen.CSourceCodeWriter in project graal by oracle.
the class NativeBootImage method writeHeaderFile.
void writeHeaderFile(Path outFile, String imageName, boolean dynamic) {
List<HostedMethod> methodsWithHeader = uniqueEntryPoints.stream().filter(this::shouldWriteHeader).collect(Collectors.toList());
methodsWithHeader.sort(NativeBootImage::sortMethodsByFileNameAndPosition);
if (methodsWithHeader.size() > 0) {
CSourceCodeWriter writer = new CSourceCodeWriter(outFile.getParent());
String imageHeaderGuard = "__" + imageName.toUpperCase().replaceAll("[^A-Z0-9]", "_") + "_H";
writer.appendln("#ifndef " + imageHeaderGuard);
writer.appendln("#define " + imageHeaderGuard);
String preamblePath = NativeImageOptions.PreamblePath.getValue();
if (preamblePath != null) {
NativeImageHeaderPreamble.read(preamblePath).forEach(writer::appendln);
} else {
writer.appendln("#include <" + DEFAULT_HEADER_FILE_NAME + ">");
}
if (NativeImageOptions.getCStandard() != CStandards.C89) {
writer.appendln("#include <stdbool.h>");
}
writer.appendln("#if defined(__cplusplus)");
writer.appendln("extern \"C\" {");
writer.appendln("#endif");
methodsWithHeader.forEach(m -> writeMethodHeader(m, writer, dynamic));
writer.appendln("#if defined(__cplusplus)");
writer.appendln("}");
writer.appendln("#endif");
writer.appendln("#endif");
writer.writeFile(outFile.getFileName().toString(), false);
}
}
use of com.oracle.svm.hosted.c.codegen.CSourceCodeWriter in project graal by oracle.
the class SharedLibraryViaCCBootImage method writeGraalIsolateHeader.
private static void writeGraalIsolateHeader(Path outputDirectory) {
CSourceCodeWriter writer = new CSourceCodeWriter(outputDirectory);
NativeImageHeaderPreamble.read("/" + DEFAULT_HEADER_FILE_NAME).forEach(writer::appendln);
writer.writeFile(DEFAULT_HEADER_FILE_NAME, false);
}
Aggregations