Skip to content

Commit

Permalink
Move writeCStandardHeaders() to CSourceCodeWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
olpaw committed Aug 26, 2020
1 parent 4425973 commit cc5dc55
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import static com.oracle.svm.core.util.VMError.shouldNotReachHere;
import static com.oracle.svm.hosted.NativeImageOptions.CStandards.C11;
import static com.oracle.svm.hosted.NativeImageOptions.CStandards.C99;

import java.io.BufferedWriter;
import java.io.IOException;
Expand All @@ -36,6 +37,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -80,6 +82,21 @@ public CSourceCodeWriter(Path tempDirectory) {
this.currentLine = new StringBuilder(100);
}

public void writeCStandardHeaders() {
if (NativeImageOptions.getCStandard().compatibleWith(C99)) {
if (!Platform.includedIn(Platform.WINDOWS.class)) {
/*
* No stdbool.h in Windows SDK 7.1. If we add native-compiler version detection this
* should only be omitted if cl.exe version is < 19.*.
*/
includeFiles(Collections.singletonList("<stdbool.h>"));
}
}
if (NativeImageOptions.getCStandard().compatibleWith(C11)) {
includeFiles(Collections.singletonList("<stdint.h>"));
}
}

public int currentLineNumber() {
return lines.size() + 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,16 @@
package com.oracle.svm.hosted.c.codegen;

import static com.oracle.svm.core.util.VMError.shouldNotReachHere;
import static com.oracle.svm.hosted.NativeImageOptions.CStandards.C11;
import static com.oracle.svm.hosted.NativeImageOptions.CStandards.C99;
import static com.oracle.svm.hosted.c.query.QueryResultFormat.DELIMINATOR;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.graalvm.nativeimage.Platform;

import com.oracle.svm.core.c.NativeImageHeaderPreamble;
import com.oracle.svm.hosted.NativeImageOptions;
import com.oracle.svm.hosted.c.info.ConstantInfo;
import com.oracle.svm.hosted.c.info.ElementInfo;
import com.oracle.svm.hosted.c.info.EnumConstantInfo;
Expand Down Expand Up @@ -107,7 +103,7 @@ protected void visitNativeCodeInfo(NativeCodeInfo nativeCodeInfo) {

writer.includeFiles(Arrays.asList("<stdio.h>", "<stddef.h>", "<memory.h>"));

writeCStandardHeaders(writer);
writer.writeCStandardHeaders();

/* Write general macro definitions. */
writer.appendln();
Expand All @@ -130,21 +126,6 @@ protected void visitNativeCodeInfo(NativeCodeInfo nativeCodeInfo) {
writer.appendln("}");
}

public static void writeCStandardHeaders(CSourceCodeWriter writer) {
if (NativeImageOptions.getCStandard().compatibleWith(C99)) {
if (!Platform.includedIn(Platform.WINDOWS.class)) {
/*
* No stdbool.h in Windows SDK 7.1. If we add native-compiler version detection this
* should only be omitted if cl.exe version is < 19.*.
*/
writer.includeFiles(Collections.singletonList("<stdbool.h>"));
}
}
if (NativeImageOptions.getCStandard().compatibleWith(C11)) {
writer.includeFiles(Collections.singletonList("<stdint.h>"));
}
}

@Override
protected void visitConstantInfo(ConstantInfo constantInfo) {
switch (constantInfo.getKind()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
import com.oracle.svm.hosted.c.GraalAccess;
import com.oracle.svm.hosted.c.NativeLibraries;
import com.oracle.svm.hosted.c.codegen.CSourceCodeWriter;
import com.oracle.svm.hosted.c.codegen.QueryCodeWriter;
import com.oracle.svm.hosted.code.CEntryPointCallStubMethod;
import com.oracle.svm.hosted.code.CEntryPointCallStubSupport;
import com.oracle.svm.hosted.code.CEntryPointData;
Expand Down Expand Up @@ -207,7 +206,7 @@ private void writeHeaderFile(Path outDir, Header header, List<HostedMethod> meth

writer.appendln();

QueryCodeWriter.writeCStandardHeaders(writer);
writer.writeCStandardHeaders();

List<String> dependencies = header.dependsOn().stream()
.map(NativeBootImage::instantiateCHeader)
Expand Down

0 comments on commit cc5dc55

Please sign in to comment.