LIBINT 2.9.0
iface.h
1/*
2 * Copyright (C) 2004-2024 Edward F. Valeev
3 *
4 * This file is part of Libint compiler.
5 *
6 * Libint compiler is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Libint compiler is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Libint compiler. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_bin_libint_iface_h_
22#define _libint2_src_bin_libint_iface_h_
23
24#include <context.h>
25#include <default_params.h>
26#include <smart_ptr.h>
27#include <task.h>
28
29#include <fstream>
30#include <sstream>
31
32namespace libint2 {
43 public:
44 typedef std::vector<std::string> Tasks;
45 Libint2Iface(const std::shared_ptr<CompilationParameters>& cparams,
46 const std::shared_ptr<CodeContext>& ctext);
48
50 void to_types(const std::string& s) { th_ << s << std::endl; }
52 void to_params(const std::string& s) { ph_ << s << std::endl; }
54 void to_iface(const std::string& s) { ih_ << s << std::endl; }
56 void to_int_iface(const std::string& s) { ii_ << s << std::endl; }
58 void to_static_init(const std::string& s) { si_ << s << std::endl; }
60 void to_static_cleanup(const std::string& s) { sc_ << s << std::endl; }
62 // void to_libint_init(const std::string& s) {
63 // li_ << s << endl;
64 // }
65
66 std::string macro(const std::string& label) {
67 std::string result("LIBINT2_");
68 result += label;
69 return result;
70 }
71
72 std::string macro(const std::string& task_label, const std::string& label) {
73 std::string result("LIBINT2_");
74 result += label;
75 if (task_label != "") {
76 result += "_";
77 result += task_label;
78 }
79 return result;
80 }
81
82 template <typename T>
83 std::string macro_define(const std::string& label, const T& value) {
84 oss_.str(null_str_);
85 oss_ << "#ifndef " << macro(label) << std::endl;
86 oss_ << "# define " << macro(label) << " " << value << std::endl;
87 oss_ << "#endif" << std::endl;
88 return oss_.str();
89 }
90
91 template <typename T>
92 std::string macro_define(const std::string& task_label,
93 const std::string& label, const T& value) {
94 oss_.str(null_str_);
95 oss_ << "#define " << macro(task_label, label) << " " << value << std::endl;
96 return oss_.str();
97 }
98
99 template <typename T>
100 std::string var_declare_v(const std::string& label) {
101 return ctext_->declare_v(ctext_->type_name<T>(),
102 ctext_->label_to_name(label), macro("MAX_VECLEN"));
103 }
104
105 private:
106 std::string null_str_;
107 std::ostringstream oss_;
108 std::shared_ptr<CompilationParameters> cparams_;
109 std::shared_ptr<CodeContext> ctext_;
110
111 // computation-specific functions are libint2_init_xxx, libint2_cleanup_xxx,
112 // etc. -- these are their declarations, e.g. "libint2_init_xxx(Libint_t*
113 // libint, int max_am, LIBINT2_REALTYPE* buf)"
114 std::vector<std::string> li_decls_; // _init_
115 std::vector<std::string> lm_decls_; // _need_memory_
116 std::vector<std::string> lc_decls_; // _cleanup_
117
118 std::string lf_decl_; // _init_flopcounter
119
120 typedef std::basic_ofstream<char> fstream;
121
122 fstream th_;
123 fstream ph_;
124 fstream ih_;
125 fstream ii_;
126 fstream si_;
127 fstream sc_;
128 fstream li_;
129
130 void generate_inteval_type(std::ostream& os);
131};
132}; // namespace libint2
133
134#endif
Libint2Iface is used to generate Libint2 interfaces.
Definition iface.h:42
std::string macro(const std::string &label)
Writes string s to the Libint_t init code.
Definition iface.h:66
void to_int_iface(const std::string &s)
Writes string s to the internal iface header.
Definition iface.h:56
void to_types(const std::string &s)
Writes string s to the types header.
Definition iface.h:50
void to_iface(const std::string &s)
Writes string s to the iface header.
Definition iface.h:54
void to_static_cleanup(const std::string &s)
Writes string s to the static cleanup code.
Definition iface.h:60
void to_params(const std::string &s)
Writes string s to the params header.
Definition iface.h:52
void to_static_init(const std::string &s)
Writes string s to the static init code.
Definition iface.h:58
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24