21 #include <default_params.h> 23 #ifndef _libint2_src_bin_libint_codecontext_h_ 24 #define _libint2_src_bin_libint_codecontext_h_ 38 const SafePtr<CompilationParameters>&
cparams()
const;
57 virtual std::string
label_to_name(
const std::string& label)
const =0;
61 virtual std::string
declare(
const std::string& type,
62 const std::string& name)
const =0;
66 virtual std::string
declare_v(
const std::string& type,
67 const std::string& name,
68 const std::string& nelem)
const =0;
72 virtual std::string
decldef(
const std::string& type,
73 const std::string& name,
74 const std::string& value) =0;
78 virtual std::string
assign(
const std::string& name,
79 const std::string& value) =0;
83 virtual std::string
accumulate(
const std::string& name,
84 const std::string& value) =0;
89 const std::string& left,
90 const std::string& oper,
91 const std::string& right) =0;
96 const std::string& arg1,
97 const std::string& oper1,
98 const std::string& arg2,
99 const std::string& oper2,
100 const std::string& arg3) =0;
105 const std::string& left,
106 const std::string& oper,
107 const std::string& right) =0;
112 const std::string& arg1,
113 const std::string& oper1,
114 const std::string& arg2,
115 const std::string& oper2,
116 const std::string& arg3) =0;
121 virtual std::string
macro_define(
const std::string& name)
const =0;
123 virtual std::string
macro_define(
const std::string& name,
const std::string& value)
const =0;
125 virtual std::string
macro_if(
const std::string& name)
const =0;
127 virtual std::string
macro_ifdef(
const std::string& name)
const =0;
132 virtual std::string
comment(
const std::string& statement)
const =0;
144 virtual SafePtr<ForLoop>
for_loop(std::string& varname,
const SafePtr<Entity>& less_than,
145 const SafePtr<Entity>& start_at = SafePtr<Entity>(
new CTimeEntity<int>(0)))
const =0;
148 template <
typename T>
151 template <
typename T>
166 CodeContext(
const SafePtr<CompilationParameters>& cparams);
178 const std::string& From,
179 const std::string& To);
182 virtual std::string
void_type()
const =0;
184 virtual std::string
int_type()
const =0;
186 virtual std::string
size_type()
const =0;
188 virtual std::string
fp_type()
const =0;
193 SafePtr<CompilationParameters> cparams_;
194 mutable unsigned int next_index_[EntityTypes::ntypes];
195 void zero_out_counters()
const;
220 std::string
declare(
const std::string& type,
221 const std::string& name)
const;
223 std::string
declare_v(
const std::string& type,
224 const std::string& name,
225 const std::string& nelem)
const;
227 std::string
decldef(
const std::string& type,
228 const std::string& name,
229 const std::string& value);
231 std::string
assign(
const std::string& name,
232 const std::string& value);
234 std::string
accumulate(
const std::string& name,
235 const std::string& value);
238 const std::string& left,
239 const std::string& oper,
240 const std::string& right);
243 const std::string& arg1,
244 const std::string& oper1,
245 const std::string& arg2,
246 const std::string& oper2,
247 const std::string& arg3);
250 const std::string& left,
251 const std::string& oper,
252 const std::string& right);
255 const std::string& arg1,
256 const std::string& oper1,
257 const std::string& arg2,
258 const std::string& oper2,
259 const std::string& arg3);
264 std::string
macro_define(
const std::string& name)
const;
266 std::string
macro_define(
const std::string& name,
const std::string& value)
const;
268 virtual std::string
macro_if(
const std::string& name)
const;
270 virtual std::string
macro_ifdef(
const std::string& name)
const;
275 std::string
comment(
const std::string& statement)
const;
285 SafePtr<ForLoop>
for_loop(std::string& varname,
const SafePtr<Entity>& less_than,
286 const SafePtr<Entity>& start_at)
const;
303 std::string symbol_to_pointer(
const std::string& symbol);
313 std::string start_expr()
const;
314 std::string end_expr()
const;
317 std::string assign_(
const std::string& name,
318 const std::string& value,
321 std::string assign_binary_expr_(
const std::string& name,
322 const std::string& left,
323 const std::string& oper,
324 const std::string& right,
327 std::string assign_ternary_expr_(
const std::string& name,
328 const std::string& arg1,
329 const std::string& oper1,
330 const std::string& arg2,
331 const std::string& oper2,
332 const std::string& arg3,
virtual void reset()
this function resets the context to be used for the next source file
Definition: context.cc:118
virtual std::string unique_fp_name() const =0
generates a unique name for a floating-point variable
virtual std::string comment(const std::string &statement) const =0
comment(statement) returns commented statement
virtual std::string assign_binary_expr(const std::string &name, const std::string &left, const std::string &oper, const std::string &right)=0
assign_binary_expr returns a statement which assigns binary expression 'left oper right' to variable ...
CTimeEntity is an Entity of type T that exists at compile-time of the generated code (hence has a val...
Definition: entity.h:183
MemoryManager::Address Address
The address on the stack during computation is described using this type.
Definition: dgvertex.h:45
virtual std::string open_block() const =0
open a code block
virtual std::string std_function_header() const =0
std_function_header() returns declarations and definitions necessary for every function ...
CodeContext provides context for generating code.
Definition: context.h:33
virtual std::string code_postfix() const =0
produces postfix to function declarations or definitions
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
virtual std::string int_type() const =0
returns name of integer type
virtual std::string declare_v(const std::string &type, const std::string &name, const std::string &nelem) const =0
declare_v returns a statement which declares a vector 'name' of 'nelem' elements of type 'type' ...
const SafePtr< CompilationParameters > & cparams() const
Returns the CompilationParameters used to create this context.
Definition: context.cc:90
virtual std::string size_type() const =0
returns name of array size type (e.g. size_t)
virtual std::string macro_if(const std::string &name) const =0
#if macro
virtual std::string const_modifier() const =0
returns the modifier for constant variables
virtual SafePtr< ForLoop > for_loop(std::string &varname, const SafePtr< Entity > &less_than, const SafePtr< Entity > &start_at=SafePtr< Entity >(new CTimeEntity< int >(0))) const =0
returns a ForLoop object.
std::string unique_name() const
unique_name<T> returns a unique name for a variable of type T
static std::string replace_chars(const std::string &S, const std::string &From, const std::string &To)
replaces every appearance of From with To in S
Definition: context.cc:124
virtual std::string inteval_gen_type_name() const =0
returns the name of the generic evaluator type (works for any task)
virtual std::string inteval_type_name(const std::string &task) const =0
returns the name of the evaluator type for task 'task'
virtual std::string stack_address(const DGVertex::Address &a) const =0
converts an address on the stack to its string representation
virtual std::string fp_type() const =0
returns name of floating-point type
CodeContext(const SafePtr< CompilationParameters > &cparams)
Lone constructor takes CompilationParams.
Definition: context.cc:82
virtual std::string label_to_name(const std::string &label) const =0
label_to_name(label) converts label to a name valid within the context of the language ...
unsigned int next_fp_index() const
next fp index
Definition: context.cc:99
virtual std::string decldef(const std::string &type, const std::string &name, const std::string &value)=0
decldef returns a statement which declares variable named 'name' of type 'type' and defines its value...
void turn_comments(bool on)
turn comments on and off (the default is on)
virtual std::string std_header() const =0
std_header() returns declarations necessary for every source file
virtual std::string ptr_fp_type() const =0
returns name of pointer to floating-point type
virtual std::string mutable_modifier() const =0
returns the modifier for mutable variables
virtual std::string accumulate_ternary_expr(const std::string &name, const std::string &arg1, const std::string &oper1, const std::string &arg2, const std::string &oper2, const std::string &arg3)=0
accumulate_ternary_expr returns a statement which accumulates ternary expression 'arg1 oper1 arg2 ope...
virtual std::string accumulate(const std::string &name, const std::string &value)=0
accumulate returns a statement which assigns variable 'value' to variable 'name'
virtual std::string value_to_pointer(const std::string &val) const =0
converts a value to a pointer
virtual std::string macro_endif() const =0
#endif
virtual std::string code_prefix() const =0
produces prefix to function declarations or definitions
virtual std::string declare(const std::string &type, const std::string &name) const =0
declare returns a statement which declares variable named 'name' of type 'type'
std::string type_name() const
type_name<T> returns name for type T
CppCodeContext is an implementation of CodeContext for C++.
Definition: context.h:204
virtual std::string end_of_stat() const =0
end a statement
virtual std::string assign_ternary_expr(const std::string &name, const std::string &arg1, const std::string &oper1, const std::string &arg2, const std::string &oper2, const std::string &arg3)=0
assign_ternary_expr returns a statement which assigns ternary expression 'arg1 oper1 arg2 oper2 arg3'...
virtual std::string macro_ifdef(const std::string &name) const =0
#ifdef macro
virtual std::string assign(const std::string &name, const std::string &value)=0
assign returns a statement which assigns variable 'value' to variable 'name'
virtual std::string inteval_spec_type_name(const std::string &task) const =0
returns the name of the specialized evaluator type for task 'task'
unsigned int next_int_index() const
next int index
Definition: context.cc:105
virtual std::string unique_int_name() const =0
generates a unique name for an integer
bool comments_on() const
returns true if to print comments
Definition: context.cc:96
virtual std::string accumulate_binary_expr(const std::string &name, const std::string &left, const std::string &oper, const std::string &right)=0
accumulate_binary_expr returns a statement which accumulates binary expression 'left oper right' to v...
virtual std::string macro_define(const std::string &name) const =0
#define a macro
virtual std::string void_type() const =0
returns name of void type
virtual std::string close_block() const =0
close a code block