├── version.txt ├── example ├── simple │ ├── .gitignore │ ├── CMakeLists.txt │ ├── driver.f90 │ └── simple.cpp └── simple_fetch_content │ ├── .gitignore │ ├── driver.f90 │ ├── simple.cpp │ └── CMakeLists.txt ├── tests ├── unit_tests │ ├── common │ │ ├── CMakeLists.txt │ │ ├── test_any_moveable.cu │ │ ├── test_make_indices.cu │ │ ├── test_make_indices.cpp │ │ └── test_any_moveable.cpp │ ├── test_export.cu │ ├── test_generator.cu │ ├── test_function_traits.cu │ ├── CMakeLists.txt │ ├── test_fortran_array_view.cu │ ├── test_function_wrapper.cu │ ├── test_function_traits.cpp │ ├── test_generator.cpp │ ├── test_function_wrapper.cpp │ ├── test_export.cpp │ └── test_fortran_array_view.cpp ├── regression │ ├── CMakeLists.txt │ ├── simple │ │ ├── driver.c │ │ ├── bindgen_regression_simple.h │ │ ├── bindgen_regression_simple.f90 │ │ ├── driver.f90 │ │ ├── simple.cpp │ │ └── CMakeLists.txt │ ├── array │ │ ├── bindgen_regression_array.h │ │ ├── bindgen_regression_array_cu.h │ │ ├── driver.f90 │ │ ├── driver_cu.f90 │ │ ├── bindgen_regression_array.f90 │ │ ├── CMakeLists.txt │ │ ├── bindgen_regression_array_cu.f90 │ │ ├── implementation.cpp │ │ └── implementation.cu │ └── string │ │ ├── driver.f90 │ │ ├── implementation.cpp │ │ └── CMakeLists.txt └── CMakeLists.txt ├── LICENSE_HEADER ├── AUTHORS ├── include └── cpp_bindgen │ ├── handle_impl.hpp │ ├── string_descriptor.h │ ├── handle.h │ ├── common │ ├── disjunction.hpp │ ├── type_traits.hpp │ ├── for_each.hpp │ ├── function_traits.hpp │ ├── make_indices.hpp │ └── any_moveable.hpp │ ├── array_descriptor.h │ ├── fortran_string_view.hpp │ ├── function_wrapper.hpp │ ├── fortran_array_view.hpp │ ├── export.hpp │ └── generator.hpp ├── src └── cpp_bindgen │ ├── handle.cpp │ ├── handle.f90 │ ├── string_descriptor.f90 │ ├── array_descriptor.f90 │ ├── generator_main.cpp │ └── generator.cpp ├── cmake ├── bindings.cmake ├── cpp_bindgen-config.cmake.in ├── cpp_bindgen_fortran_helpers.cmake ├── cpp_bindgen_generate.cmake ├── detect_features.cmake ├── export.cmake └── cpp_bindgen.cmake.in ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── .clang-format ├── README.md └── jenkins └── build.sh /version.txt: -------------------------------------------------------------------------------- 1 | 1.1.0 2 | -------------------------------------------------------------------------------- /example/simple/.gitignore: -------------------------------------------------------------------------------- 1 | simple.f90 2 | simple.h 3 | 4 | -------------------------------------------------------------------------------- /example/simple_fetch_content/.gitignore: -------------------------------------------------------------------------------- 1 | simple.f90 2 | simple.h 3 | 4 | -------------------------------------------------------------------------------- /tests/unit_tests/common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | foreach(testname 2 | test_any_moveable 3 | test_make_indices 4 | ) 5 | compile_test(${testname}) 6 | endforeach() 7 | -------------------------------------------------------------------------------- /LICENSE_HEADER: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Anton Afanasyev (anstaf), ETH Zurich (CSCS) 2 | Lukas Mosimann (lukasm91), ETH Zurich (CSCS), NVIDIA 3 | Hannes Vogt (havogt), ETH Zurich (CSCS) 4 | Mauro Bianco (mbianco), ETH Zurich (CSCS) 5 | Felix Thaler (fthaler), ETH Zurich (CSCS) 6 | Willem Deconinck (wdeconinck), ECMWF 7 | 8 | -------------------------------------------------------------------------------- /tests/unit_tests/test_export.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #include "test_export.cpp" 11 | -------------------------------------------------------------------------------- /tests/unit_tests/test_generator.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #include "test_generator.cpp" 11 | -------------------------------------------------------------------------------- /tests/regression/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(${PROJECT_SOURCE_DIR}/cmake/detect_features.cmake) 2 | detect_fortran_compiler() 3 | detect_c_compiler() 4 | 5 | add_subdirectory(simple) 6 | 7 | if(CMAKE_Fortran_COMPILER_LOADED) 8 | add_subdirectory(array) 9 | add_subdirectory(string) 10 | endif() 11 | -------------------------------------------------------------------------------- /tests/unit_tests/common/test_any_moveable.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #include "test_any_moveable.cpp" 11 | -------------------------------------------------------------------------------- /tests/unit_tests/common/test_make_indices.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #include "test_make_indices.cpp" 11 | -------------------------------------------------------------------------------- /tests/unit_tests/test_function_traits.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #include "test_function_traits.cpp" 11 | -------------------------------------------------------------------------------- /tests/unit_tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(common) 2 | 3 | foreach(testname 4 | test_export 5 | test_fortran_array_view 6 | test_function_wrapper 7 | test_generator 8 | test_function_traits 9 | ) 10 | 11 | compile_test(${testname}) 12 | endforeach() 13 | -------------------------------------------------------------------------------- /tests/unit_tests/test_fortran_array_view.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #include "test_fortran_array_view.cpp" 11 | -------------------------------------------------------------------------------- /tests/unit_tests/test_function_wrapper.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #include "test_function_wrapper.cpp" 11 | -------------------------------------------------------------------------------- /tests/regression/simple/driver.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #include "bindgen_regression_simple.h" 12 | 13 | int main() { print_number_from_cpp(7); } 14 | -------------------------------------------------------------------------------- /tests/regression/simple/bindgen_regression_simple.h: -------------------------------------------------------------------------------- 1 | // This file is generated! 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | void print_number_from_cpp(int); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /tests/regression/simple/bindgen_regression_simple.f90: -------------------------------------------------------------------------------- 1 | ! This file is generated! 2 | module bindgen_regression_simple 3 | use iso_c_binding 4 | implicit none 5 | interface 6 | 7 | subroutine print_number_from_cpp(arg0) bind(c) 8 | use iso_c_binding 9 | integer(c_int), value :: arg0 10 | end subroutine 11 | 12 | end interface 13 | contains 14 | end module 15 | -------------------------------------------------------------------------------- /tests/regression/array/bindgen_regression_array.h: -------------------------------------------------------------------------------- 1 | // This file is generated! 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | void fill_array(bindgen_fortran_array_descriptor*); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /include/cpp_bindgen/handle_impl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #pragma once 11 | 12 | #include "common/any_moveable.hpp" 13 | 14 | struct bindgen_handle { 15 | cpp_bindgen::any_moveable m_value; 16 | }; 17 | -------------------------------------------------------------------------------- /src/cpp_bindgen/handle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | void bindgen_release(bindgen_handle const *obj) { delete obj; } 15 | -------------------------------------------------------------------------------- /tests/regression/array/bindgen_regression_array_cu.h: -------------------------------------------------------------------------------- 1 | // This file is generated! 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | void fill_array(bindgen_fortran_array_descriptor*); 12 | void fill_gpu_array(bindgen_fortran_array_descriptor*); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /tests/regression/string/driver.f90: -------------------------------------------------------------------------------- 1 | ! GridTools 2 | ! 3 | ! Copyright (c) 2014-2019, ETH Zurich 4 | ! All rights reserved. 5 | ! 6 | ! Please, refer to the LICENSE file in the root directory. 7 | ! SPDX-License-Identifier: BSD-3-Clause 8 | 9 | program main 10 | use iso_c_binding 11 | use bindgen_regression_string 12 | implicit none 13 | if (my_atoi('42') /= 42) stop 1 14 | print *, "Success!" 15 | end 16 | -------------------------------------------------------------------------------- /example/simple/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14.5) 2 | project(simple_example LANGUAGES CXX C Fortran) 3 | 4 | # 1) find installed cpp_bindgen version 5 | find_package(cpp_bindgen) 6 | 7 | # 2) create a library with bindings 8 | bindgen_add_library(simple SOURCES simple.cpp) 9 | 10 | # 3) link the library to a fortran executable 11 | add_executable(driver driver.f90) 12 | target_link_libraries(driver simple_fortran) 13 | -------------------------------------------------------------------------------- /example/simple/driver.f90: -------------------------------------------------------------------------------- 1 | ! GridTools 2 | ! 3 | ! Copyright (c) 2014-2019, ETH Zurich 4 | ! All rights reserved. 5 | ! 6 | ! Please, refer to the LICENSE file in the root directory. 7 | ! SPDX-License-Identifier: BSD-3-Clause 8 | 9 | program main 10 | use iso_c_binding 11 | use bindgen_handle 12 | use simple 13 | implicit none 14 | integer, parameter :: i = 9 15 | 16 | call print_number_from_cpp(i) 17 | 18 | end 19 | -------------------------------------------------------------------------------- /example/simple_fetch_content/driver.f90: -------------------------------------------------------------------------------- 1 | ! GridTools 2 | ! 3 | ! Copyright (c) 2014-2019, ETH Zurich 4 | ! All rights reserved. 5 | ! 6 | ! Please, refer to the LICENSE file in the root directory. 7 | ! SPDX-License-Identifier: BSD-3-Clause 8 | 9 | program main 10 | use iso_c_binding 11 | use bindgen_handle 12 | use simple 13 | implicit none 14 | integer, parameter :: i = 9 15 | 16 | call print_number_from_cpp(i) 17 | 18 | end 19 | -------------------------------------------------------------------------------- /tests/regression/simple/driver.f90: -------------------------------------------------------------------------------- 1 | ! GridTools 2 | ! 3 | ! Copyright (c) 2014-2019, ETH Zurich 4 | ! All rights reserved. 5 | ! 6 | ! Please, refer to the LICENSE file in the root directory. 7 | ! SPDX-License-Identifier: BSD-3-Clause 8 | 9 | program main 10 | use iso_c_binding 11 | use bindgen_handle 12 | use bindgen_regression_simple 13 | implicit none 14 | integer, parameter :: i = 9 15 | 16 | call print_number_from_cpp(i) 17 | 18 | end 19 | -------------------------------------------------------------------------------- /src/cpp_bindgen/handle.f90: -------------------------------------------------------------------------------- 1 | ! GridTools 2 | ! 3 | ! Copyright (c) 2014-2019, ETH Zurich 4 | ! All rights reserved. 5 | ! 6 | ! Please, refer to the LICENSE file in the root directory. 7 | ! SPDX-License-Identifier: BSD-3-Clause 8 | 9 | module bindgen_handle 10 | implicit none 11 | interface 12 | subroutine bindgen_release(h) bind(c) 13 | use iso_c_binding 14 | type(c_ptr), value :: h 15 | end 16 | end interface 17 | end 18 | -------------------------------------------------------------------------------- /tests/regression/string/implementation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | int atoi_impl(std::string const &src) { return atoi(src.c_str()); } 17 | 18 | BINDGEN_EXPORT_BINDING_WRAPPED_1(my_atoi, atoi_impl); 19 | -------------------------------------------------------------------------------- /include/cpp_bindgen/string_descriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | struct bindgen_fortran_string_descriptor { 16 | char *data; 17 | ptrdiff_t size; 18 | }; 19 | typedef struct bindgen_fortran_string_descriptor bindgen_fortran_string_descriptor; 20 | -------------------------------------------------------------------------------- /include/cpp_bindgen/handle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #pragma once 11 | 12 | struct bindgen_handle; 13 | 14 | #ifdef __cplusplus 15 | 16 | extern "C" void bindgen_release(bindgen_handle const *); 17 | 18 | #else 19 | 20 | typedef struct bindgen_handle bindgen_handle; 21 | void bindgen_release(bindgen_handle *); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/cpp_bindgen/string_descriptor.f90: -------------------------------------------------------------------------------- 1 | ! GridTools 2 | ! 3 | ! Copyright (c) 2014-2019, ETH Zurich 4 | ! All rights reserved. 5 | ! 6 | ! Please, refer to the LICENSE file in the root directory. 7 | ! SPDX-License-Identifier: BSD-3-Clause 8 | 9 | module bindgen_string_descriptor 10 | use iso_c_binding 11 | implicit none 12 | 13 | type, bind(c), public :: bindgen_fortran_string_descriptor 14 | type(c_ptr) :: data 15 | integer(c_ptrdiff_t) :: size 16 | end type bindgen_fortran_string_descriptor 17 | end module 18 | -------------------------------------------------------------------------------- /cmake/bindings.cmake: -------------------------------------------------------------------------------- 1 | function(generate_gt_bindings) 2 | set(__CPP_BINDGEN_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src) 3 | set(__CPP_BINDGEN_CMAKE_DIR ${PROJECT_SOURCE_DIR}/cmake) 4 | set(__CPP_BINDGEN_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) 5 | configure_file(${PROJECT_SOURCE_DIR}/cmake/cpp_bindgen.cmake.in 6 | ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/bindings_for_build/cpp_bindgen.cmake 7 | @ONLY) 8 | endfunction() 9 | 10 | generate_gt_bindings() 11 | include(${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/bindings_for_build/cpp_bindgen.cmake) 12 | -------------------------------------------------------------------------------- /tests/regression/string/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | bindgen_add_library(bindgen_regression_string SOURCES implementation.cpp) 2 | 3 | add_executable(bindgen_regression_string_driver_fortran driver.f90) 4 | target_link_libraries(bindgen_regression_string_driver_fortran bindgen_regression_string_fortran) 5 | if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") 6 | set_target_properties(bindgen_regression_string_driver_fortran PROPERTIES LINKER_LANGUAGE Fortran) 7 | endif() 8 | 9 | add_test(NAME bindgen_regression_string_driver_fortran 10 | COMMAND $) 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IDEs 2 | *.project 3 | *.cproject 4 | *.settings 5 | .idea 6 | .pydevproject 7 | .clangd 8 | 9 | # Build folders 10 | build*/ 11 | install*/ 12 | 13 | # Prerequisites 14 | *.d 15 | 16 | # Compiled Object files 17 | *.slo 18 | *.lo 19 | *.o 20 | *.obj 21 | 22 | # Precompiled Headers 23 | *.gch 24 | *.pch 25 | 26 | # Compiled Dynamic libraries 27 | *.so 28 | *.dylib 29 | *.dll 30 | 31 | # Fortran module files 32 | *.mod 33 | *.smod 34 | 35 | # Compiled Static libraries 36 | *.lai 37 | *.la 38 | *.a 39 | *.lib 40 | 41 | # Executables 42 | *.exe 43 | *.out 44 | *.app 45 | 46 | # Logs 47 | *.log 48 | 49 | -------------------------------------------------------------------------------- /cmake/cpp_bindgen-config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | get_filename_component(cpp_bindgen_CONFIG_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 4 | 5 | message(STATUS "GridTools cpp_bindgen version @PROJECT_VERSION@ found at ${cpp_bindgen_CONFIG_CMAKE_DIR}") 6 | 7 | include(CMakeFindDependencyMacro) 8 | find_dependency(Boost @REQUIRED_BOOST_VERSION@) 9 | 10 | set_and_check(cpp_bindgen_CMAKE_DIR @PACKAGE_cpp_bindgen_CMAKE_DIR@) 11 | set_and_check(cpp_bindgen_SOURCE_DIR @PACKAGE_cpp_bindgen_SOURCE_DIR@) 12 | set_and_check(cpp_bindgen_INCLUDE_DIR @PACKAGE_cpp_bindgen_INCLUDE_DIR@) 13 | 14 | include(${cpp_bindgen_CMAKE_DIR}/cpp_bindgen.cmake) 15 | -------------------------------------------------------------------------------- /example/simple/simple.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | // In this example, we demonstrate how the cpp_bindgen library can be used to export functions to C and Fortran. 15 | 16 | namespace { 17 | void print_number(int i) { std::cout << "Printing from C++: " << i << std::endl; } 18 | 19 | BINDGEN_EXPORT_BINDING_1(print_number_from_cpp, print_number); 20 | } // namespace 21 | -------------------------------------------------------------------------------- /tests/regression/simple/simple.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | // In this example, we demonstrate how the cpp_bindgen library can be used to export functions to C and Fortran. 15 | 16 | namespace { 17 | void print_number(int i) { std::cout << "Printing from C++: " << i << std::endl; } 18 | 19 | BINDGEN_EXPORT_BINDING_1(print_number_from_cpp, print_number); 20 | } // namespace 21 | -------------------------------------------------------------------------------- /include/cpp_bindgen/common/disjunction.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace cpp_bindgen { 15 | 16 | template 17 | struct disjunction : std::false_type {}; 18 | template 19 | struct disjunction : B1 {}; 20 | template 21 | struct disjunction : std::conditional>::type {}; 22 | } // namespace cpp_bindgen 23 | -------------------------------------------------------------------------------- /src/cpp_bindgen/array_descriptor.f90: -------------------------------------------------------------------------------- 1 | ! GridTools 2 | ! 3 | ! Copyright (c) 2014-2019, ETH Zurich 4 | ! All rights reserved. 5 | ! 6 | ! Please, refer to the LICENSE file in the root directory. 7 | ! SPDX-License-Identifier: BSD-3-Clause 8 | 9 | module bindgen_array_descriptor 10 | use iso_c_binding 11 | implicit none 12 | 13 | type, bind(c), public :: bindgen_fortran_array_descriptor 14 | integer(c_int) :: type 15 | integer(c_int) :: rank 16 | integer(c_int), dimension(7) :: dims 17 | type(c_ptr) :: data 18 | ! TODO: add support for strides, bounds end type bindgen_fortran_array_descriptor 19 | end type bindgen_fortran_array_descriptor 20 | end module 21 | -------------------------------------------------------------------------------- /src/cpp_bindgen/generator_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | int main(int argc, const char *argv[]) { 17 | if (argc > 3) { 18 | std::ofstream dst(argv[2]); 19 | cpp_bindgen::generate_fortran_interface(dst, argv[3]); 20 | } 21 | if (argc > 1) { 22 | std::ofstream dst(argv[1]); 23 | cpp_bindgen::generate_c_interface(dst); 24 | } else { 25 | cpp_bindgen::generate_c_interface(std::cout); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /example/simple_fetch_content/simple.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | // In this example, we demonstrate how the cpp_bindgen library can be used to export functions to C and Fortran. 15 | 16 | namespace { 17 | void print_number(int i) { std::cout << "Printing from C++: " << i << std::endl; } 18 | 19 | // Exports a unary function with the name `print_number_from_cpp`, which forwards to `print_number`. 20 | BINDGEN_EXPORT_BINDING_1(print_number_from_cpp, print_number); 21 | } // namespace 22 | -------------------------------------------------------------------------------- /tests/regression/array/driver.f90: -------------------------------------------------------------------------------- 1 | ! GridTools 2 | ! 3 | ! Copyright (c) 2014-2019, ETH Zurich 4 | ! All rights reserved. 5 | ! 6 | ! Please, refer to the LICENSE file in the root directory. 7 | ! SPDX-License-Identifier: BSD-3-Clause 8 | 9 | program main 10 | use iso_c_binding 11 | use bindgen_handle 12 | use bindgen_regression_array 13 | implicit none 14 | integer, parameter :: ie = 9, je = 10, ke = 11 15 | integer :: i, j, k 16 | real(8), dimension(ie, je, ke) :: arr, expected 17 | 18 | call fill_array(arr) 19 | 20 | do i=1, ie 21 | do j=1, je 22 | do k=1, ke 23 | expected(i,j,k) = (i-1)*10000 + (j-1)*100 + (k-1) 24 | end do 25 | end do 26 | end do 27 | 28 | if (any(arr /= expected)) stop 1 29 | 30 | print *, "Success!" 31 | end 32 | -------------------------------------------------------------------------------- /tests/unit_tests/common/test_make_indices.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #include 11 | 12 | #include 13 | 14 | using namespace cpp_bindgen; 15 | 16 | static_assert(std::is_same::value_type, int>::value, ""); 17 | static_assert(integer_sequence::size() == 3, ""); 18 | 19 | static_assert(std::is_same, integer_sequence>::value, ""); 20 | 21 | static_assert(std::is_same::type, 22 | list, std::integral_constant>>::value, 23 | ""); 24 | 25 | TEST(make_indices, make_indices) {} 26 | -------------------------------------------------------------------------------- /tests/regression/array/driver_cu.f90: -------------------------------------------------------------------------------- 1 | ! GridTools 2 | ! 3 | ! Copyright (c) 2014-2019, ETH Zurich 4 | ! All rights reserved. 5 | ! 6 | ! Please, refer to the LICENSE file in the root directory. 7 | ! SPDX-License-Identifier: BSD-3-Clause 8 | 9 | program main 10 | use iso_c_binding 11 | use bindgen_handle 12 | use bindgen_regression_array_cu 13 | implicit none 14 | integer, parameter :: ie = 9, je = 10, ke = 11 15 | integer :: i, j, k 16 | real(8), dimension(ie, je, ke) :: arr, expected 17 | 18 | !$acc enter data create(arr) 19 | 20 | call fill_gpu_array(arr) 21 | 22 | !$acc exit data copyout(arr) 23 | 24 | do i=1, ie 25 | do j=1, je 26 | do k=1, ke 27 | expected(i,j,k) = (i-1)*10000 + (j-1)*100 + (k-1) 28 | end do 29 | end do 30 | end do 31 | 32 | if (any(arr /= expected)) stop 1 33 | 34 | print *, "Success!" 35 | end 36 | -------------------------------------------------------------------------------- /tests/regression/array/bindgen_regression_array.f90: -------------------------------------------------------------------------------- 1 | ! This file is generated! 2 | module bindgen_regression_array 3 | use iso_c_binding 4 | implicit none 5 | interface 6 | 7 | subroutine fill_array_impl(arg0) bind(c, name="fill_array") 8 | use iso_c_binding 9 | use bindgen_array_descriptor 10 | type(bindgen_fortran_array_descriptor) :: arg0 11 | end subroutine 12 | 13 | end interface 14 | contains 15 | subroutine fill_array(arg0) 16 | use iso_c_binding 17 | use bindgen_array_descriptor 18 | real(c_double), dimension(:,:,:), target :: arg0 19 | type(bindgen_fortran_array_descriptor) :: descriptor0 20 | 21 | descriptor0%rank = 3 22 | descriptor0%type = 6 23 | descriptor0%dims = reshape(shape(arg0), & 24 | shape(descriptor0%dims), (/0/)) 25 | descriptor0%data = c_loc(arg0(lbound(arg0, 1),lbound(arg0, 2),lbound(arg0, 3))) 26 | 27 | call fill_array_impl(descriptor0) 28 | end subroutine 29 | end module 30 | -------------------------------------------------------------------------------- /tests/regression/simple/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | bindgen_add_library(bindgen_regression_simple SOURCES simple.cpp) 2 | 3 | if(CMAKE_Fortran_COMPILER_LOADED) 4 | add_executable(bindgen_regression_simple_driver_fortran driver.f90) 5 | target_link_libraries(bindgen_regression_simple_driver_fortran bindgen_regression_simple_fortran) 6 | add_test(NAME bindgen_regression_simple_driver_fortran 7 | COMMAND $) 8 | if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") 9 | set_target_properties(bindgen_regression_simple_driver_fortran PROPERTIES LINKER_LANGUAGE Fortran) 10 | endif() 11 | endif() 12 | 13 | if(CMAKE_C_COMPILER_LOADED) 14 | add_executable(bindgen_regression_simple_driver_c driver.c) 15 | target_link_libraries(bindgen_regression_simple_driver_c bindgen_regression_simple_c) 16 | add_test(NAME bindgen_regression_simple_driver_c 17 | COMMAND $) 18 | endif() 19 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14.5) 2 | # when increasing the minium required version, consider updating in examples as well 3 | 4 | file(STRINGS "version.txt" __CPP_BINDGEN_VERSION) 5 | project(cpp_bindgen VERSION ${__CPP_BINDGEN_VERSION} LANGUAGES CXX) 6 | unset(__CPP_BINDGEN_VERSION) 7 | 8 | # Switch default of NO_PACKAGE_REGISTRY. TODO: Can be removed with CMake 3.15+ 9 | set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON CACHE BOOL "") 10 | mark_as_advanced(CMAKE_EXPORT_NO_PACKAGE_REGISTRY) 11 | 12 | set(REQUIRED_BOOST_VERSION 1.58) 13 | find_package(Boost ${REQUIRED_BOOST_VERSION} REQUIRED) 14 | 15 | # if used via FetchContent/add_subdirectory() we need to make the add_bindings_library() available here 16 | include(${CMAKE_CURRENT_LIST_DIR}/cmake/bindings.cmake) 17 | 18 | if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) 19 | include(CTest) 20 | if(BUILD_TESTING) 21 | add_subdirectory(tests) 22 | endif() 23 | endif() 24 | 25 | include(${CMAKE_CURRENT_LIST_DIR}/cmake/export.cmake) 26 | -------------------------------------------------------------------------------- /cmake/cpp_bindgen_fortran_helpers.cmake: -------------------------------------------------------------------------------- 1 | function(bindgen_enable_fortran_openacc_on_target target) 2 | # TODO check if find_package(OpenACC) solves this problem 3 | if(CMAKE_Fortran_COMPILER_ID STREQUAL "Cray") 4 | target_compile_options(${target} PRIVATE $<$:-h acc>) 5 | elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") 6 | target_compile_options(${target} PRIVATE $<$:-fopenacc>) 7 | set_target_properties(${target} PROPERTIES APPEND_STRING PROPERTY LINK_FLAGS -fopenacc) 8 | else() 9 | message(FATAL_ERROR "OpenACC is not configured for this compiler.") 10 | endif() 11 | endfunction() 12 | 13 | function(bindgen_enable_fortran_preprocessing_on_target target) 14 | if (CMAKE_Fortran_COMPILER_ID STREQUAL "Cray") 15 | target_compile_options(${target} PRIVATE $<$:-eF>) 16 | else() 17 | target_compile_options(${target} PRIVATE $<$:-cpp>) 18 | endif() 19 | endfunction() 20 | -------------------------------------------------------------------------------- /include/cpp_bindgen/array_descriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | enum bindgen_fortran_array_kind { 16 | bindgen_fk_Bool, 17 | bindgen_fk_Int, 18 | bindgen_fk_Short, 19 | bindgen_fk_Long, 20 | bindgen_fk_LongLong, 21 | bindgen_fk_Float, 22 | bindgen_fk_Double, 23 | bindgen_fk_LongDouble, 24 | bindgen_fk_SignedChar, 25 | }; 26 | typedef enum bindgen_fortran_array_kind bindgen_fortran_array_kind; 27 | 28 | struct bindgen_fortran_array_descriptor { 29 | bindgen_fortran_array_kind type; 30 | int rank; 31 | int dims[7]; 32 | void *data; 33 | bool is_acc_present; 34 | // TODO: add support for strides, bounds end type bindgen_fortran_array_descriptor 35 | }; 36 | typedef struct bindgen_fortran_array_descriptor bindgen_fortran_array_descriptor; 37 | -------------------------------------------------------------------------------- /tests/unit_tests/test_function_traits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace ft = cpp_bindgen::function_traits; 4 | static_assert(std::is_same::type, void>::value, ""); 5 | static_assert(std::is_same::type, void>::value, ""); 6 | static_assert(std::is_same::type, int>::value, ""); 7 | 8 | static_assert(std::is_same::type, std::tuple<>>::value, ""); 9 | static_assert(std::is_same::type, std::tuple>::value, ""); 10 | static_assert(std::is_same::type, std::tuple>::value, ""); 11 | static_assert(std::is_same::type, std::tuple>::value, ""); 12 | 13 | static_assert(ft::arity::value == 0, ""); 14 | static_assert(ft::arity::value == 1, ""); 15 | static_assert(ft::arity::value == 2, ""); 16 | static_assert(ft::arity::value == 2, ""); 17 | -------------------------------------------------------------------------------- /tests/unit_tests/common/test_any_moveable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace cpp_bindgen { 17 | 18 | TEST(any_moveable, smoke) { 19 | any_moveable x = 42; 20 | EXPECT_TRUE(x.has_value()); 21 | EXPECT_EQ(typeid(int), x.type()); 22 | EXPECT_EQ(42, any_cast(x)); 23 | auto &ref = any_cast(x); 24 | ref = 88; 25 | EXPECT_EQ(88, any_cast(x)); 26 | EXPECT_FALSE(any_cast(&x)); 27 | } 28 | 29 | TEST(any_moveable, empty) { EXPECT_FALSE(any_moveable{}.has_value()); } 30 | 31 | TEST(any_moveable, move_only) { 32 | using testee_t = std::unique_ptr; 33 | any_moveable x = testee_t(new int(42)); 34 | EXPECT_EQ(42, *any_cast(x)); 35 | any_moveable y = std::move(x); 36 | EXPECT_EQ(42, *any_cast(y)); 37 | } 38 | } // namespace cpp_bindgen 39 | -------------------------------------------------------------------------------- /include/cpp_bindgen/common/type_traits.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | namespace cpp_bindgen { 16 | 17 | /** 18 | * @file 19 | * Some c++14/c++17 type_traits drop offs. Please refer to C++14/17 specifications 20 | * to know more about them. 21 | */ 22 | 23 | template 24 | using bool_constant = std::integral_constant; 25 | 26 | template 27 | using remove_reference_t = typename std::remove_reference::type; 28 | template 29 | using remove_pointer_t = typename std::remove_pointer::type; 30 | template 31 | using add_pointer_t = typename std::add_pointer::type; 32 | template 33 | using remove_all_extents_t = typename std::remove_all_extents::type; 34 | template 35 | using decay_t = typename std::decay::type; 36 | template 37 | using enable_if_t = typename std::enable_if::type; 38 | 39 | template 40 | struct make_void { 41 | typedef void type; 42 | }; 43 | template 44 | using void_t = typename make_void::type; 45 | } // namespace cpp_bindgen 46 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(FetchContent) 2 | option(INSTALL_GTEST OFF) 3 | mark_as_advanced(INSTALL_GTEST) 4 | find_package(Threads) 5 | FetchContent_Declare( 6 | googletest 7 | GIT_REPOSITORY https://github.com/google/googletest.git 8 | GIT_TAG release-1.8.1 9 | ) 10 | FetchContent_MakeAvailable(googletest) 11 | 12 | include(${PROJECT_SOURCE_DIR}/cmake/detect_features.cmake) 13 | detect_cuda() 14 | 15 | # If clang+nvcc, we disable the tests, if CUDA < 10.0 because nvcc has problems with C++14 in this combination 16 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL Clang AND DEFINED CMAKE_CUDA_COMPILER AND "${CMAKE_CUDA_COMPILER_VERSION}" VERSION_LESS "10.0") 17 | message("NVCC < 10.0 is not supported with Clang as host compiler. Disabling CUDA tests.") 18 | set(CUDA_AVAILABLE OFF) 19 | endif() 20 | 21 | function(compile_test name) 22 | add_executable(${name} ${name}.cpp) 23 | target_link_libraries(${name} PRIVATE gtest_main) 24 | target_link_libraries(${name} PRIVATE cpp_bindgen_handle) 25 | target_link_libraries(${name} PRIVATE cpp_bindgen_generator) 26 | add_test(NAME ${name} COMMAND $) 27 | 28 | if (CUDA_AVAILABLE) 29 | add_executable(${name}_cu ${name}.cu) 30 | target_link_libraries(${name}_cu PRIVATE gtest_main) 31 | target_link_libraries(${name}_cu PRIVATE cpp_bindgen_handle) 32 | target_link_libraries(${name}_cu PRIVATE cpp_bindgen_generator) 33 | add_test(NAME ${name}_cu COMMAND $) 34 | endif() 35 | endfunction() 36 | 37 | enable_testing() 38 | 39 | add_subdirectory(unit_tests) 40 | add_subdirectory(regression) 41 | -------------------------------------------------------------------------------- /example/simple_fetch_content/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14.5) 2 | project(simple_example_with_fetch_content LANGUAGES CXX Fortran) 3 | 4 | # 1) fetch cpp_bindgen from the repository 5 | include(FetchContent) 6 | FetchContent_Declare( 7 | cpp_bindgen 8 | # In your application remove SOURCE_DIR ... 9 | SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../.. 10 | # By the following 2 lines to fetch content directly from github 11 | # GIT_REPOSITORY https://github.com/GridTools/cpp_bindgen.git 12 | # GIT_TAG master # consider replacing master by a tagged version 13 | ) 14 | FetchContent_MakeAvailable(cpp_bindgen) 15 | 16 | # 2) create a library with bindings. This will generate the files simple.h and simple.f90 which can be included within C and Fortran. In CMake you can use them by linking against `simple_c`or `simple_fortran`. 17 | bindgen_add_library(simple SOURCES simple.cpp) 18 | 19 | # 3) link the generated library to a fortran executable 20 | add_executable(driver driver.f90) 21 | target_link_libraries(driver simple_fortran) 22 | 23 | # 4) optional: demonstrates installing the library with CMake 24 | # installs general cpp_bindgen targets 25 | install_cpp_bindgen_targets( 26 | EXPORT simple_fortran_targets 27 | Fortran_MODULE_DESTINATION include 28 | LIBRARY DESTINATION lib 29 | ARCHIVE DESTINATION lib 30 | ) 31 | # install your library (simple) and the generated bindings library (simple_fortran) as usual 32 | install( 33 | TARGETS simple simple_fortran 34 | EXPORT simple_fortran_targets 35 | LIBRARY DESTINATION lib 36 | ARCHIVE DESTINATION lib 37 | ) 38 | install(EXPORT simple_fortran_targets DESTINATION cmake NAMESPACE SimpleFortran::) 39 | -------------------------------------------------------------------------------- /tests/regression/array/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | bindgen_add_library(bindgen_regression_array SOURCES implementation.cpp) 2 | 3 | add_executable(bindgen_regression_array_driver_fortran driver.f90) 4 | target_link_libraries(bindgen_regression_array_driver_fortran bindgen_regression_array_fortran) 5 | if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") 6 | set_target_properties(bindgen_regression_array_driver_fortran PROPERTIES LINKER_LANGUAGE Fortran) 7 | endif() 8 | 9 | add_test(NAME bindgen_regression_array_driver_fortran 10 | COMMAND $) 11 | 12 | if( CUDA_AVAILABLE 13 | AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" # -fopenacc will be passed to the c++ linker 14 | AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_GREATER_EQUAL "6" 15 | AND "${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU" 16 | AND "${CMAKE_Fortran_COMPILER_VERSION}" VERSION_GREATER_EQUAL "6" 17 | ) 18 | 19 | bindgen_add_library(bindgen_regression_array_cu SOURCES implementation.cu) 20 | bindgen_enable_fortran_openacc_on_target(bindgen_regression_array_cu_fortran) 21 | 22 | add_executable(bindgen_regression_array_driver_cu_fortran driver_cu.f90) 23 | target_link_libraries(bindgen_regression_array_driver_cu_fortran bindgen_regression_array_cu_fortran) 24 | bindgen_enable_fortran_openacc_on_target(bindgen_regression_array_driver_cu_fortran) 25 | 26 | # TODO 27 | # we don't add this test on purpose for now, because it is likely that this test does not work 28 | # out of the box. The Fortran code would need to be compiled separately with a different 29 | # compiler than the C++ code with a compiler that has proper OpenACC support. 30 | endif() 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GridTools 2 | 3 | Copyright (c) 2014-2019, ETH Zurich 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | 1. Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | 3. Neither the name of the copyright holder nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | 33 | For information: https://eth-cscs.github.io/gridtools/ 34 | -------------------------------------------------------------------------------- /tests/regression/array/bindgen_regression_array_cu.f90: -------------------------------------------------------------------------------- 1 | ! This file is generated! 2 | module bindgen_regression_array_cu 3 | use iso_c_binding 4 | implicit none 5 | interface 6 | 7 | subroutine fill_array_impl(arg0) bind(c, name="fill_array") 8 | use iso_c_binding 9 | use bindgen_array_descriptor 10 | type(bindgen_fortran_array_descriptor) :: arg0 11 | end subroutine 12 | subroutine fill_gpu_array_impl(arg0) bind(c, name="fill_gpu_array") 13 | use iso_c_binding 14 | use bindgen_array_descriptor 15 | type(bindgen_fortran_array_descriptor) :: arg0 16 | end subroutine 17 | 18 | end interface 19 | contains 20 | subroutine fill_array(arg0) 21 | use iso_c_binding 22 | use bindgen_array_descriptor 23 | real(c_double), dimension(:,:,:), target :: arg0 24 | type(bindgen_fortran_array_descriptor) :: descriptor0 25 | 26 | descriptor0%rank = 3 27 | descriptor0%type = 6 28 | descriptor0%dims = reshape(shape(arg0), & 29 | shape(descriptor0%dims), (/0/)) 30 | descriptor0%data = c_loc(arg0(lbound(arg0, 1),lbound(arg0, 2),lbound(arg0, 3))) 31 | 32 | call fill_array_impl(descriptor0) 33 | end subroutine 34 | subroutine fill_gpu_array(arg0) 35 | use iso_c_binding 36 | use bindgen_array_descriptor 37 | real(c_double), dimension(:,:,:), target :: arg0 38 | type(bindgen_fortran_array_descriptor) :: descriptor0 39 | 40 | !$acc data present(arg0) 41 | !$acc host_data use_device(arg0) 42 | descriptor0%rank = 3 43 | descriptor0%type = 6 44 | descriptor0%dims = reshape(shape(arg0), & 45 | shape(descriptor0%dims), (/0/)) 46 | descriptor0%data = c_loc(arg0(lbound(arg0, 1),lbound(arg0, 2),lbound(arg0, 3))) 47 | !$acc end host_data 48 | !$acc end data 49 | 50 | call fill_gpu_array_impl(descriptor0) 51 | end subroutine 52 | end module 53 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: LLVM 4 | AccessModifierOffset: -2 5 | ConstructorInitializerIndentWidth: 4 6 | #AlignEscapedNewlinesLeft: false 7 | AlignTrailingComments: true 8 | AllowAllParametersOfDeclarationOnNextLine: true 9 | AllowShortBlocksOnASingleLine: false 10 | AllowShortIfStatementsOnASingleLine: false 11 | AllowShortLoopsOnASingleLine: false 12 | AllowShortFunctionsOnASingleLine: All 13 | AlwaysBreakTemplateDeclarations: true 14 | AlwaysBreakBeforeMultilineStrings: false 15 | BreakBeforeBinaryOperators: false 16 | BreakBeforeTernaryOperators: true 17 | BreakConstructorInitializersBeforeComma: false 18 | BinPackParameters: false 19 | BinPackArguments: false 20 | ColumnLimit: 120 21 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 22 | DerivePointerAlignment: false 23 | ExperimentalAutoDetectBinPacking: false 24 | IndentCaseLabels: false 25 | IndentWrappedFunctionNames: false 26 | IndentFunctionDeclarationAfterType: false 27 | MaxEmptyLinesToKeep: 1 28 | KeepEmptyLinesAtTheStartOfBlocks: true 29 | NamespaceIndentation: All 30 | ObjCSpaceAfterProperty: false 31 | ObjCSpaceBeforeProtocolList: true 32 | PenaltyBreakBeforeFirstCallParameter: 19 33 | PenaltyBreakComment: 300 34 | PenaltyBreakString: 1000 35 | PenaltyBreakFirstLessLess: 120 36 | PenaltyExcessCharacter: 1000000 37 | PenaltyReturnTypeOnItsOwnLine: 60 38 | PointerAlignment: Right 39 | SpacesBeforeTrailingComments: 1 40 | Cpp11BracedListStyle: true 41 | Standard: Cpp11 42 | IndentWidth: 4 43 | TabWidth: 8 44 | UseTab: Never 45 | BreakBeforeBraces: Attach 46 | SpacesInParentheses: false 47 | SpacesInAngles: false 48 | SpaceInEmptyParentheses: false 49 | SpacesInCStyleCastParentheses: false 50 | SpacesInContainerLiterals: true 51 | SpaceBeforeAssignmentOperators: true 52 | ContinuationIndentWidth: 4 53 | CommentPragmas: '*' 54 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] 55 | SpaceBeforeParens: ControlStatements 56 | DisableFormat: false 57 | AlignAfterOpenBracket: false 58 | AlignEscapedNewlinesLeft: true 59 | ... 60 | 61 | -------------------------------------------------------------------------------- /include/cpp_bindgen/fortran_string_view.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | #include "string_descriptor.h" 16 | 17 | bindgen_fortran_string_descriptor inline bindgen_make_fortran_string_view( 18 | bindgen_fortran_string_descriptor desc, bindgen_fortran_string_descriptor *) { 19 | return desc; 20 | } 21 | 22 | #include 23 | 24 | namespace std { 25 | inline string bindgen_make_fortran_string_view(bindgen_fortran_string_descriptor desc, string *) { 26 | return {desc.data, (size_t)desc.size}; 27 | } 28 | } // namespace std 29 | 30 | #if __cplusplus >= 201703L 31 | #include 32 | 33 | namespace std { 34 | inline string_view bindgen_make_fortran_string_view(bindgen_fortran_string_descriptor desc, string_view *) { 35 | return {desc.data, (size_t)desc.size}; 36 | } 37 | } // namespace std 38 | #endif 39 | 40 | namespace cpp_bindgen { 41 | namespace fortran_string_view_impl_ { 42 | 43 | template 44 | auto make_fortran_string_view(bindgen_fortran_string_descriptor desc) 45 | -> decltype(bindgen_make_fortran_string_view(desc, (T *)0)) { 46 | return bindgen_make_fortran_string_view(desc, (T *)0); 47 | } 48 | 49 | template 50 | struct is_fortran_string_bindable : std::false_type {}; 51 | 52 | template 53 | struct is_fortran_string_bindable::type>( 55 | std::declval())), 56 | T>::value>::type> : std::true_type {}; 57 | } // namespace fortran_string_view_impl_ 58 | using fortran_string_view_impl_::is_fortran_string_bindable; 59 | using fortran_string_view_impl_::make_fortran_string_view; 60 | } // namespace cpp_bindgen 61 | -------------------------------------------------------------------------------- /include/cpp_bindgen/common/for_each.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GridTools 3 | * 4 | * Copyright (c) 2014-2019, ETH Zurich 5 | * All rights reserved. 6 | * 7 | * Please, refer to the LICENSE file in the root directory. 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | 11 | #pragma once 12 | 13 | namespace cpp_bindgen { 14 | 15 | namespace for_each_detail { 16 | template 17 | struct for_each_impl; 18 | 19 | template