OK, so welcome to our talk.
I'm Ivan, and this is my colleague Michaela,
and we are from the Leibniz Super Computing Center.
So in this talk, we hope to give you knowledge
about a very special software refactoring tool,
which we kind of innovatively applied
to wrap a sea library.
So as you all probably know, in scientific software,
we always have this need to interoperate
with components written in different programming languages.
So I've experienced this most personally writing PD solvers
in Fortune, where I wanted to use a KD3 in C,
and some system library called,
and I've been wrapping these wrappers manually all the time
in sleepless nights.
So as a HPC application support person,
I see the same problem in the projects I support,
where people may have a finite element framework
in C++, but they want to call a special software in Fortune,
and then one of the students, of course,
wants to do scripting and analysis from Python,
and it always creates this need to interoperate.
So for the sake of this talk, let's pretend
that we want to wrap the function lead DJM
from the Blitz library, which is a linear algebra library
I believe written at the University of Texas,
and this is the C prototype for this function.
And for me to be able to call this function as a Fortune programmer,
I have to write this interface block.
And this is really a kind of, let's say,
one-to-one mapping to a different grammar,
but it's still tedious to write these procedures with many parameters,
and libraries like Blitz, which is an implementation of a full blast library,
it has many symbols.
And in fact, it introduces even more symbols.
And of course, all these symbols are provided in four different numerical types,
plus basic and expert versions, plus utility functions.
So this really grows overwhelming,
and one has libraries with over 600 procedures.
So the source of truth is obviously the header,
which is pretty bulky with 30,000 lines,
and makes heavy use of macros,
and the code is really impenetrable.
And one could try to use some ad hoc scripts with regax,
or a oc, but it quickly kind of goes overboard.
So I was telling Michaela about the problems I have.
And luckily, he had the perfect tool for me to use.
So Michaela.
So coxinella is the name of the software we are using for this,
which is a semantic matching and patching engine.
Coxinella means in French ladybug,
and ladybugs are not all used for attacking other specific other bugs,
which they don't like.
And yeah, it's used for the Linux kernel for besaging
but programming practices, let's say,
and migrating kernel, sorry,
driver modules to new kernel versions.
So in other words, for big transformations of C code.
In our case, the big amounts of C code happen in headers,
or in the talk to of today, in this big headers,
which we are interested in to processing,
our characteristic of coxinella is that it does,
it's pretty agnostic to white space, new lines, and so on.
So all of that doesn't matter really,
and what happens is that abstract syntax tree is being created.
So fully fledged parses parser goes through the code
and creates an representation of the C code
and composing all of the elements,
which occur in our program.
In the case of a sequence of declarations,
identifiers are being recognized.
Parameter lists in a context of, for instance,
here in this rule here of void functions.
So here we have a rule which matches void functions,
with whatever number of parameters, as long as the identifiers
begin with bleed underscore.
So this will apply this sort of filtering rule,
and with this complete short filtering rule,
we write maybe something a bit longer,
which is a bit more ad hoc you could say,
but it can be pretty elegant as long as you have a clear idea
of what you want to achieve.
So in this case here we have a coxinella rule,
which contains a Python script,
which gets all of what has been parsed in the rule before,
which is being reused here.
The name of the earlier rule, which was match,
we used entities from there, we inherited them,
and we used them here in Python.
So what we got from the abstract syntax tree,
we reused them in Python.
Here we omit maybe a dozen,
maybe a hundred lines, why a hundred,
because there is a lot of types,
we want, which we want to translate into four turn types,
and that is outside of the scope of coxinella,
but we solve with dictionary of in Python.
So yeah, that way.
In the end we end up printing a bunch of variables,
interface, subroutine, interface declarations,
which is what force needs to get this right.
This is another example where the difference is that,
yeah, we are parsing another,
we are seeking a different signature type.
We could be much more specific here on the signature,
but if others along us here we are general,
and our script is general, yeah,
we can have any kind of translation,
as long as we well know how to do with the limitations.
So if we are quite selective,
we would translate,
and we don't care about unions,
because there is no union in Fortran,
and we kind of also ignore callback functions from C,
which is not so clear how to deal them in Fortran,
in other words.
If we are content with the correspondence,
with the missing full correspondence of C to Fortran,
it's fine.
The point is that we use coxinella,
and we want to use coxinella for large scale code transformations.
So transformations where we would be overwhelmed
of doing this by hand,
and of which it would be too much error prone
of doing this by a set of unimate script.
So we reuse here the abstract syntax three manipulation
opportunities of coxinella,
and even has put here the code,
the full code behind this presentation.
This is on this QR behind this QR code,
should be that URL.
We have been sponsored by this project,
and I have given a last week our new training
for introducing coxinella in one day.
We will be repeating,
offering such a training at the Lebanese,
Reconcentrum and Munich this year.
We don't know yet, but we will.
This cheat sheet here on the right is completely new,
so yeah,
it didn't exist.
I did not aware of cheat sheets for coxinella earlier.
We can enjoy this once you learn coxinella
to not to,
to recall important facts.
This is the coxinella website,
and this is the cheat sheet,
and this is the training of the site.
And I think this is it.