21#include <default_params.h>
24#ifndef _libint2_src_bin_libint_codecontext_h_
25#define _libint2_src_bin_libint_codecontext_h_
39 const std::shared_ptr<CompilationParameters>&
cparams()
const;
66 virtual std::string
declare(
const std::string& type,
67 const std::string& name)
const = 0;
71 virtual std::string
declare_v(
const std::string& type,
72 const std::string& name,
73 const std::string& nelem)
const = 0;
77 virtual std::string
decldef(
const std::string& type,
const std::string& name,
78 const std::string& value) = 0;
82 virtual std::string
assign(
const std::string& name,
83 const std::string& value) = 0;
88 const std::string& value) = 0;
93 const std::string& left,
94 const std::string& oper,
95 const std::string& right) = 0;
100 const std::string& arg1,
101 const std::string& oper1,
102 const std::string& arg2,
103 const std::string& oper2,
104 const std::string& arg3) = 0;
109 const std::string& left,
110 const std::string& oper,
111 const std::string& right) = 0;
116 const std::string& arg1,
117 const std::string& oper1,
118 const std::string& arg2,
119 const std::string& oper2,
120 const std::string& arg3) = 0;
128 const std::string& value)
const = 0;
130 virtual std::string
macro_if(
const std::string& name)
const = 0;
132 virtual std::string
macro_ifdef(
const std::string& name)
const = 0;
137 virtual std::string
comment(
const std::string& statement)
const = 0;
150 std::string& varname,
const std::shared_ptr<Entity>& less_than,
151 const std::shared_ptr<Entity>& start_at =
155 template <
typename T>
158 template <
typename T>
185 const std::string& From,
186 const std::string& To);
200 std::shared_ptr<CompilationParameters> cparams_;
201 mutable unsigned int next_index_[EntityTypes::ntypes];
202 void zero_out_counters()
const;
210 public std::enable_shared_from_this<CppCodeContext> {
213 bool vectorize =
false);
227 std::string
label_to_name(
const std::string& label)
const override;
229 std::string
declare(
const std::string& type,
230 const std::string& name)
const override;
232 std::string
declare_v(
const std::string& type,
const std::string& name,
233 const std::string& nelem)
const override;
235 std::string
decldef(
const std::string& type,
const std::string& name,
236 const std::string& value)
override;
238 std::string
assign(
const std::string& name,
239 const std::string& value)
override;
241 std::string
accumulate(
const std::string& name,
242 const std::string& value)
override;
245 const std::string& left,
246 const std::string& oper,
247 const std::string& right)
override;
250 const std::string& arg1,
251 const std::string& oper1,
252 const std::string& arg2,
253 const std::string& oper2,
254 const std::string& arg3)
override;
257 const std::string& left,
258 const std::string& oper,
259 const std::string& right)
override;
262 const std::string& arg1,
263 const std::string& oper1,
264 const std::string& arg2,
265 const std::string& oper2,
266 const std::string& arg3)
override;
271 std::string
macro_define(
const std::string& name)
const override;
274 const std::string& value)
const override;
276 std::string
macro_if(
const std::string& name)
const override;
278 std::string
macro_ifdef(
const std::string& name)
const override;
283 std::string
comment(
const std::string& statement)
const override;
294 std::string& varname,
const std::shared_ptr<Entity>& less_than,
295 const std::shared_ptr<Entity>& start_at)
const override;
308 std::string unique_fp_name()
const override;
310 std::string unique_int_name()
const override;
312 std::string symbol_to_pointer(
const std::string& symbol);
314 std::string void_type()
const override;
315 std::string int_type()
const override;
316 std::string size_type()
const override;
317 std::string fp_type()
const override;
318 std::string ptr_fp_type()
const override;
319 std::string const_modifier()
const override;
320 std::string mutable_modifier()
const override;
322 std::string start_expr()
const;
323 std::string end_expr()
const;
326 std::string assign_(
const std::string& name,
const std::string& value,
329 std::string assign_binary_expr_(
const std::string& name,
330 const std::string& left,
331 const std::string& oper,
332 const std::string& right,
bool accum);
334 std::string assign_ternary_expr_(
const std::string& name,
335 const std::string& arg1,
336 const std::string& oper1,
337 const std::string& arg2,
338 const std::string& oper2,
339 const std::string& arg3,
bool accum);
CTimeEntity is an Entity of type T that exists at compile-time of the generated code (hence has a val...
Definition entity.h:220
CodeContext provides context for generating code.
Definition context.h:34
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_ifdef(const std::string &name) const =0
#ifdef macro
virtual std::string accumulate(const std::string &name, const std::string &value)=0
accumulate returns a statement which assigns variable 'value' to variable 'name'
void turn_comments(bool on)
turn comments on and off (the default is on)
virtual std::string comment(const std::string &statement) const =0
comment(statement) returns commented statement
virtual std::string inteval_gen_type_name() const =0
returns the name of the generic evaluator type (works for any task)
virtual std::string fp_type() const =0
returns name of floating-point type
virtual std::string inteval_spec_type_name(const std::string &task) const =0
returns the name of the specialized evaluator type for task 'task'
virtual std::string mutable_modifier() const =0
returns the modifier for mutable variables
virtual std::string macro_define(const std::string &name, const std::string &value) const =0
#define a macro
virtual std::string void_type() const =0
returns name of void type
virtual std::string unique_fp_name() const =0
generates a unique name for a floating-point variable
virtual std::string open_block() const =0
open a code block
virtual std::string code_prefix() const =0
produces prefix to function declarations or definitions
virtual std::string close_block() const =0
close a code block
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'
virtual std::string code_postfix() const =0
produces postfix to function declarations or definitions
virtual std::string macro_endif() const =0
#endif
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:101
virtual std::string macro_define(const std::string &name) const =0
#define a macro
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'...
const std::shared_ptr< CompilationParameters > & cparams() const
Returns the CompilationParameters used to create this context.
Definition context.cc:81
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 ...
virtual std::string stack_address(const DGVertex::Address &a) const =0
converts an address on the stack to its string representation
virtual std::string value_to_pointer(const std::string &val) const =0
converts a value to a pointer
virtual std::string assign(const std::string &name, const std::string &value)=0
assign returns a statement which assigns variable 'value' to variable 'name'
std::string type_name() const
type_name<T> returns name for type T
virtual std::string std_function_header() const =0
std_function_header() returns declarations and definitions necessary for every function
unsigned int next_int_index() const
next int index
Definition context.cc:91
bool comments_on() const
returns true if to print comments
Definition context.cc:85
virtual std::string const_modifier() const =0
returns the modifier for constant variables
virtual std::string copyright() const =0
copyright() returns the copyright statement
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 macro_if(const std::string &name) const =0
#if macro
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'
virtual std::string int_type() const =0
returns name of integer type
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
virtual std::string std_header() const =0
std_header() returns declarations necessary for every source file
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 ptr_fp_type() const =0
returns name of pointer to floating-point type
unsigned int next_fp_index() const
next fp index
Definition context.cc:87
virtual std::shared_ptr< ForLoop > for_loop(std::string &varname, const std::shared_ptr< Entity > &less_than, const std::shared_ptr< Entity > &start_at=std::shared_ptr< Entity >(new CTimeEntity< int >(0))) const =0
returns a ForLoop object.
CodeContext(const std::shared_ptr< CompilationParameters > &cparams)
Lone constructor takes CompilationParams.
Definition context.cc:76
virtual std::string size_type() const =0
returns name of array size type (e.g. size_t)
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...
virtual void reset()
this function resets the context to be used for the next source file
Definition context.cc:99
virtual std::string end_of_stat() const =0
end a statement
virtual std::string unique_int_name() const =0
generates a unique name for an integer
std::string unique_name() const
unique_name<T> returns a unique name for a variable of type T
CppCodeContext is an implementation of CodeContext for C++.
Definition context.h:210
std::string end_of_stat() const override
Implementation of CodeContext::end_of_stat()
Definition context.cc:527
std::string inteval_type_name(const std::string &task) const override
Implementation of CodeContext::inteval_type_name()
Definition context.cc:577
std::shared_ptr< ForLoop > for_loop(std::string &varname, const std::shared_ptr< Entity > &less_than, const std::shared_ptr< Entity > &start_at) const override
Implementation of CodeContext::for_loop()
Definition context.cc:543
std::string code_prefix() const override
Implementation of CodeContext::code_prefix()
Definition context.cc:139
std::string assign_binary_expr(const std::string &name, const std::string &left, const std::string &oper, const std::string &right) override
Implementation of CodeContext::assign_binary_expr()
Definition context.cc:290
std::string copyright() const override
Implementation of CodeContext::copyright()
Definition context.cc:158
std::string accumulate(const std::string &name, const std::string &value) override
Implementation of CodeContext::accumulate()
Definition context.cc:252
std::string value_to_pointer(const std::string &val) const override
Implementation of CodeContext::value_to_pointer()
Definition context.cc:532
std::string inteval_spec_type_name(const std::string &task) const override
Implementation of CodeContext::inteval_spec_type_name()
Definition context.cc:584
std::string accumulate_binary_expr(const std::string &name, const std::string &left, const std::string &oper, const std::string &right) override
Implementation of CodeContext::accumulate_binary_expr()
Definition context.cc:297
std::string declare_v(const std::string &type, const std::string &name, const std::string &nelem) const override
Implementation of CodeContext::declare_v()
Definition context.cc:227
std::string inteval_gen_type_name() const override
Implementation of CodeContext::inteval_spec_type_name()
Definition context.cc:591
std::string decldef(const std::string &type, const std::string &name, const std::string &value) override
decldef returns a statement which declares variable named 'name' of type 'type' and defines its value...
Definition context.cc:237
std::string macro_endif() const override
Implementation of CodeContext::macro_endif()
Definition context.cc:510
std::string macro_ifdef(const std::string &name) const override
Implementation of CodeContext::macro_ifdef()
Definition context.cc:504
std::string close_block() const override
Implementation of CodeContext::close_block()
Definition context.cc:525
std::string comment(const std::string &statement) const override
Implementation of CodeContext::comment(statement)
Definition context.cc:516
std::string code_postfix() const override
Implementation of CodeContext::code_postfix()
Definition context.cc:150
std::string stack_address(const DGVertex::Address &a) const override
Implementation of CodeContext::stack_address()
Definition context.cc:476
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) override
assign_ternary_expr returns a statement which assigns ternary expression 'arg1 oper1 arg2 oper2 arg3'...
Definition context.cc:351
std::string assign(const std::string &name, const std::string &value) override
Implementation of CodeContext::assign()
Definition context.cc:247
std::string macro_define(const std::string &name) const override
Implementation of CodeContext::macro_define()
Definition context.cc:485
std::string std_function_header() const override
Implementation of CodeContext::std_function_header()
Definition context.cc:201
std::string label_to_name(const std::string &label) const override
Implementation of CodeContext::label_to_name(label)
Definition context.cc:209
std::string macro_if(const std::string &name) const override
Implementation of CodeContext::macro_if()
Definition context.cc:498
std::string declare(const std::string &type, const std::string &name) const override
Implementation of CodeContext::declare()
Definition context.cc:218
std::string std_header() const override
Implementation of CodeContext::std_header()
Definition context.cc:196
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) override
accumulate_ternary_expr returns a statement which accumulates ternary expression 'arg1 oper1 arg2 ope...
Definition context.cc:434
std::string open_block() const override
Implementation of CodeContext::open_block()
Definition context.cc:523
MemoryManager::Address Address
The address on the stack during computation is described using this type.
Definition dgvertex.h:47
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24