Skip to content

Commit

Permalink
Make getHeaderSnippet into an internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
olpaw committed Aug 28, 2020
1 parent 63e7e86 commit d1bc3c9
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 23 deletions.
1 change: 0 additions & 1 deletion sdk/src/org.graalvm.nativeimage/snapshot.sigtest
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ meth public boolean isInConfiguration()
meth public java.util.List<java.lang.String> getHeaderFiles()
meth public java.util.List<java.lang.String> getLibraries()
meth public java.util.List<java.lang.String> getLibraryPaths()
meth public java.util.List<java.lang.String> getHeaderSnippet()
meth public java.util.List<java.lang.String> getMacroDefinitions()
meth public java.util.List<java.lang.String> getOptions()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,5 @@ default List<String> getLibraries() {
default List<String> getLibraryPaths() {
return Collections.emptyList();
}

/**
* Returns a C header file snippet that should be injected into the query code that gets
* generated for this CContext.
*
* @since 20.3
*/
default List<String> getHeaderSnippet() {
return Collections.emptyList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@

import java.util.List;

import org.graalvm.nativeimage.c.CContext;

import com.oracle.svm.core.c.function.GraalIsolateHeader;

public class BuiltinDirectives implements CContext.Directives {
public class BuiltinDirectives implements DirectivesExtension {
@Override
public List<String> getHeaderSnippet() {
return GraalIsolateHeader.getGraalIsolatePreamble();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package com.oracle.svm.hosted.c;

import java.util.Collections;
import java.util.List;

import org.graalvm.nativeimage.c.CContext;

public interface DirectivesExtension extends CContext.Directives {

/**
* Returns a C header file snippet that should be injected into the query code that gets
* generated for this CContext.
*
*/
default List<String> getHeaderSnippet() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import java.util.List;

import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.c.CContext;

import com.oracle.svm.hosted.c.DirectivesExtension;
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 @@ -106,8 +108,10 @@ public String getLine(int lineNumber) {

@Override
protected void visitNativeCodeInfo(NativeCodeInfo nativeCodeInfo) {
CContext.Directives directives = nativeCodeInfo.getDirectives();

/* Write general macro definitions. */
List<String> macroDefinitions = nativeCodeInfo.getDirectives().getMacroDefinitions();
List<String> macroDefinitions = directives.getMacroDefinitions();
if (!macroDefinitions.isEmpty()) {
macroDefinitions.forEach(writer::appendMacroDefinition);
writer.appendln();
Expand All @@ -129,14 +133,16 @@ protected void visitNativeCodeInfo(NativeCodeInfo nativeCodeInfo) {
}

/* Inject CContext specific C header file snippet. */
List<String> headerSnippet = nativeCodeInfo.getDirectives().getHeaderSnippet();
if (!headerSnippet.isEmpty()) {
headerSnippet.forEach(writer::appendln);
writer.appendln();
if (directives instanceof DirectivesExtension) {
List<String> headerSnippet = ((DirectivesExtension) directives).getHeaderSnippet();
if (!headerSnippet.isEmpty()) {
headerSnippet.forEach(writer::appendln);
writer.appendln();
}
}

/* CContext specific header file inclusions. */
List<String> headerFiles = nativeCodeInfo.getDirectives().getHeaderFiles();
List<String> headerFiles = directives.getHeaderFiles();
if (!headerFiles.isEmpty()) {
writer.includeFiles(headerFiles);
writer.appendln();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
import java.util.Collections;
import java.util.List;

import org.graalvm.nativeimage.c.CContext.Directives;

import com.oracle.svm.core.c.function.GraalIsolateHeader;
import com.oracle.svm.hosted.c.DirectivesExtension;

public class PolyglotNativeAPICContext implements Directives {
public class PolyglotNativeAPICContext implements DirectivesExtension {

@Override
public List<String> getHeaderFiles() {
Expand Down

0 comments on commit d1bc3c9

Please sign in to comment.