From 60a2d2c9862c348c5fdc54d9d29621bbf9c163f7 Mon Sep 17 00:00:00 2001 From: Francois Coppens Date: Thu, 23 Feb 2023 13:49:21 +0100 Subject: [PATCH 1/3] Fixes tab-key not working to open/close Org-mode sections in Emacs Evil mode. Fix works on Linux and macOS. --- tools/init.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/init.el b/tools/init.el index bf2b48f..f0470d7 100644 --- a/tools/init.el +++ b/tools/init.el @@ -58,8 +58,8 @@ (add-hook 'org-babel-after-execute-hook 'org-display-inline-images) '(indent-tabs-mode nil) -(require 'evil) (setq evil-want-C-i-jump nil) +(require 'evil) (evil-mode 1) (global-font-lock-mode t) (global-superword-mode 1) From 216fcebf707a386274188bf88c65b74d456ac89a Mon Sep 17 00:00:00 2001 From: Francois Coppens Date: Thu, 23 Feb 2023 16:17:39 +0100 Subject: [PATCH 2/3] Added fucntion that generates private c headers. --- tools/lib.org | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/tools/lib.org b/tools/lib.org index 2d55f34..46fe807 100644 --- a/tools/lib.org +++ b/tools/lib.org @@ -32,7 +32,6 @@ | ~C~ | ~double[n][ldc]~ | out | Array containing the $m \times n$ matrix $C$ | | ~ldc~ | ~int64_t~ | in | Leading dimension of array ~C~ | - *** Fortran-C type conversions #+NAME:f_of_c @@ -132,22 +131,36 @@ return template #+END_SRC - #+RESULTS: generate_c_header - #+begin_src c :tangle (eval h_func) :comments org - qmckl_exit_code [] ( - const qmckl_context context, - const char transa, - const char transb, - const int64_t m, - const int64_t n, - const double* A, - const int64_t lda, - const double* B, - const int64_t ldb, - double* const C, - const int64_t ldc ); - #+end_src + #+NAME: generate_private_c_header + #+BEGIN_SRC python :var table=test :var rettyp="qmckl_exit_code" :var fname=[] :results drawer :noweb yes :wrap "src c :tangle (eval h_private_func) :comments org" +<> +results = [] +for d in parse_table(table): + name = d["name"] + c_type = d["c_type"] + + # Add star for arrays + if d["rank"] > 0 or d["inout"] in ["out", "inout"]: + c_type += "*" + + if d["inout"] == "out": + c_type += " const" + + # Only inputs are const + if d["inout"] == "in": + const = "const " + else: + const = "" + + results += [ f" {const}{c_type} {name}" ] + +results=',\n'.join(results) +template = f"""{rettyp} {fname} (\n{results} ); """ +return template + + #+END_SRC + *** Generates a C interface to the Fortran function #+NAME: generate_c_interface @@ -255,8 +268,6 @@ results='\n'.join(results) return results #+END_SRC - - ** Creating provide functions #+NAME: write_provider_header @@ -421,3 +432,4 @@ return msg return QMCKL_SUCCESS; } #+end_src + From 7c57fe2b6fad8d2de8f510176aaed34c0e3b3044 Mon Sep 17 00:00:00 2001 From: Francois Coppens Date: Thu, 23 Feb 2023 17:30:00 +0100 Subject: [PATCH 3/3] Added fucntion that generates private fortran interfaces to C functions. --- tools/lib.org | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tools/lib.org b/tools/lib.org index 46fe807..8e3c719 100644 --- a/tools/lib.org +++ b/tools/lib.org @@ -240,6 +240,55 @@ results = [ f"interface" , "" ] +for d in parse_table(table): + f_type = f_of_c_d[d["c_type"]] + inout = "intent("+d["inout"]+")" + name = d["name"] + + # Input scalars are passed by value + if d["rank"] == 0 and d["inout"] == "in": + value = ", value" + else: + value = " " + + # Append dimensions to the name + if d["rank"] == 0: + dims = "" + else: + d["dims"].reverse() + dims = "(" + ",".join(d["dims"]) + ")" + + results += [ f" {f_type:20}, {inout:12}{value} :: {name}{dims}" ] + +results += [ "" +, f" end function {fname}" +, f"end interface" +] +results='\n'.join(results) +return results + #+END_SRC + + #+NAME: generate_private_f_interface + #+BEGIN_SRC python :var table=test :var rettyp="integer" :var fname=[] :results value :noweb yes :wrap "src f90 :tangle (eval fh_private_func) :comments org :exports none" +<> +<> +<> +d = parse_table(table) + +args = ", ".join([ x["name"] for x in d ]) + +rettyp_c = ctypeid_d[rettyp.lower()] + +results = [ f"interface" +, f" {rettyp_c} function {fname} &" +, f" ({args}) &" +, " bind(C)" +, " use, intrinsic :: iso_c_binding" +, " import" +, " implicit none" +, "" +] + for d in parse_table(table): f_type = f_of_c_d[d["c_type"]] inout = "intent("+d["inout"]+")"