Skip to content
Snippets Groups Projects
Commit d610f386 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

small fixes to first tutorial

parent 982c96c1
No related merge requests found
(env_setup)= (EnvSetup)=
# Environment and Project Setup # Environment and Project Setup
This chapter attempts to briefly explain the necessary steps to get next-gen code generation This chapter attempts to briefly explain the necessary steps to get next-gen code generation
......
from pystencilssfg import SourceFileGenerator from pystencilssfg import SourceFileGenerator
with SourceFileGenerator() as sfg: with SourceFileGenerator() as sfg:
sfg.include("core/DataTypes.h") sfg.include("<cstdint>")
sfg.namespace("gen") sfg.namespace("gen")
sfg.code("constexpr walberla::uint_t MAGIC_NUMBER = 0xcafe;") sfg.code("constexpr uint64_t MAGIC_NUMBER = 0xcafe;")
...@@ -8,6 +8,9 @@ In the course of this guide, we will ...@@ -8,6 +8,9 @@ In the course of this guide, we will
- register that script with CMake; - register that script with CMake;
- and include the generated files into a simple *Hello World*-like application. - and include the generated files into a simple *Hello World*-like application.
This guide assumes that you already have a CMake project and Python environment correctly
set up, as described in [](EnvSetup).
:::{dropdown} Get The Files :::{dropdown} Get The Files
{download}`GeneratorScriptBasics.zip </zipped-examples/GeneratorScriptBasics.zip>`. {download}`GeneratorScriptBasics.zip </zipped-examples/GeneratorScriptBasics.zip>`.
...@@ -22,10 +25,11 @@ This example comprises the following files: ...@@ -22,10 +25,11 @@ This example comprises the following files:
## Our First Generator Script ## Our First Generator Script
Create and open the file `BasicCodegen.py` and populate it with the following basic code: Create and open the file `BasicCodegen.py` and populate it with the following code:
```{literalinclude} BasicCodegen.py ```{literalinclude} BasicCodegen.py
:caption: BasicCodegen.py :caption: BasicCodegen.py
:lineno-start: 1
``` ```
Let's take this apart. Let's take this apart.
...@@ -45,6 +49,7 @@ Create both the `BasicCodegenApp.cpp` and `CMakeLists.txt` files, open up `CMake ...@@ -45,6 +49,7 @@ Create both the `BasicCodegenApp.cpp` and `CMakeLists.txt` files, open up `CMake
:::{literalinclude} CMakeLists.txt :::{literalinclude} CMakeLists.txt
:language: CMake :language: CMake
:caption: CMakeLists.txt :caption: CMakeLists.txt
:lineno-start: 1
:emphasize-lines: 4-6 :emphasize-lines: 4-6
::: :::
...@@ -61,12 +66,13 @@ To observe this, add the following to your `BasicCodegenApp.cpp`: ...@@ -61,12 +66,13 @@ To observe this, add the following to your `BasicCodegenApp.cpp`:
```{literalinclude} BasicCodegenApp.cpp ```{literalinclude} BasicCodegenApp.cpp
:caption: BasicCodegenApp.cpp :caption: BasicCodegenApp.cpp
:lineno-start: 1
``` ```
Don't worry if your IDE tells you `BasicCodegen.hpp` does not exist yet; Don't worry if your IDE tells you `BasicCodegen.hpp` does not exist yet;
the file will be generated in a moment. the file will be generated in a moment.
Use CMake to build the application `Ex_GeneratorScriptBasics` and run it, and you should see it print `51966` Use CMake to build the application `Ex_GeneratorScriptBasics` and run it,
to stdout. and you should see it print `51966` to stdout.
Let's take a look at what is happening during the build. Let's take a look at what is happening during the build.
Your CMake build output should contain a line somewhat like this: Your CMake build output should contain a line somewhat like this:
...@@ -77,8 +83,8 @@ Generating sfg_sources/gen/Ex_GeneratorScriptBasics/BasicCodegen.hpp, sfg_source ...@@ -77,8 +83,8 @@ Generating sfg_sources/gen/Ex_GeneratorScriptBasics/BasicCodegen.hpp, sfg_source
This indicates that the generator script was executed and produced exactly two files below the `sfg_sources` directory: This indicates that the generator script was executed and produced exactly two files below the `sfg_sources` directory:
- a header file `gen/Ex_GeneratorScriptBasics/BasicCodegen.hpp`, which is the one we included into our application, and - a header file `gen/Ex_GeneratorScriptBasics/BasicCodegen.hpp`, which is the one we included into our application, and
- a source file ``gen/Ex_GeneratorScriptBasics/BasicCodegen.cpp`, which at this time is still empty - a source file `gen/Ex_GeneratorScriptBasics/BasicCodegen.cpp`, which at this time is still empty
because we haven't yet defined any kernels or functions. because we haven't defined any kernels or functions yet.
The `walberla_generate_sources` CMake command made sure that the `sfg_sources` directory was placed in your The `walberla_generate_sources` CMake command made sure that the `sfg_sources` directory was placed in your
target's include path, so you can include the generated files. target's include path, so you can include the generated files.
......
...@@ -12,7 +12,7 @@ This project is still unstable and immature, but growing steadily. ...@@ -12,7 +12,7 @@ This project is still unstable and immature, but growing steadily.
Until the next-gen code generators are stabilized and merged with the waLBerla master, Until the next-gen code generators are stabilized and merged with the waLBerla master,
setting up a build system and development environment for working with them is slightly more setting up a build system and development environment for working with them is slightly more
complicated. Since you will need such an environment to follow along with the examples complicated. Since you will need such an environment to follow along with the examples
in this book, start by reading the chapter [](env_setup). in this book, start by reading the chapter [](EnvSetup).
Afterward, you are free to explore the remainder of the book. Afterward, you are free to explore the remainder of the book.
## Table of Contents ## Table of Contents
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment