Skip to content

Commit

Permalink
Merge branch 'master' into jelic/pyproject
Browse files Browse the repository at this point in the history
  • Loading branch information
JCGoran committed Feb 26, 2024
2 parents b396385 + bc913ef commit ca9d55a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 131 deletions.
18 changes: 4 additions & 14 deletions src/codegen/codegen_acc_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ namespace codegen {
* \brief %Visitor for printing C++ code with OpenACC backend
*/
class CodegenAccVisitor: public CodegenCoreneuronCppVisitor {
public:
using CodegenCoreneuronCppVisitor::CodegenCoreneuronCppVisitor;

protected:

/// name of the code generation backend
std::string backend_name() const override;

Expand Down Expand Up @@ -133,20 +137,6 @@ class CodegenAccVisitor: public CodegenCoreneuronCppVisitor {
/// Replace default implementation by a no-op
/// since the buffer cannot be grown up during gpu execution
void print_net_send_buffering_grow() override;


public:
CodegenAccVisitor(const std::string& mod_file,
const std::string& output_dir,
const std::string& float_type,
bool optimize_ionvar_copies)
: CodegenCoreneuronCppVisitor(mod_file, output_dir, float_type, optimize_ionvar_copies) {}

CodegenAccVisitor(const std::string& mod_file,
std::ostream& stream,
const std::string& float_type,
bool optimize_ionvar_copies)
: CodegenCoreneuronCppVisitor(mod_file, stream, float_type, optimize_ionvar_copies) {}
};

/** \} */ // end of codegen_backends
Expand Down
48 changes: 3 additions & 45 deletions src/codegen/codegen_coreneuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ using printer::CodePrinter;
* have removed return from verbatim block.
*/
class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {
public:
using CodegenCppVisitor::CodegenCppVisitor;

protected:
/****************************************************************************************/
/* Member variables */
Expand Down Expand Up @@ -1098,51 +1101,6 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {


public:
/**
* \brief Constructs the C++ code generator visitor
*
* This constructor instantiates an NMODL C++ code generator and allows writing generated code
* directly to a file in \c [output_dir]/[mod_filename].cpp.
*
* \note No code generation is performed at this stage. Since the code
* generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c
* visit_program in order to generate the C++ code corresponding to the AST.
*
* \param mod_filename The name of the model for which code should be generated.
* It is used for constructing an output filename.
* \param output_dir The directory where target C++ file should be generated.
* \param float_type The float type to use in the generated code. The string will be used
* as-is in the target code. This defaults to \c double.
*/
CodegenCoreneuronCppVisitor(std::string mod_filename,
const std::string& output_dir,
std::string float_type,
const bool optimize_ionvar_copies)
: CodegenCppVisitor(mod_filename, output_dir, float_type, optimize_ionvar_copies) {}

/**
* \copybrief nmodl::codegen::CodegenCoreneuronCppVisitor
*
* This constructor instantiates an NMODL C++ code generator and allows writing generated code
* into an output stream.
*
* \note No code generation is performed at this stage. Since the code
* generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c
* visit_program in order to generate the C++ code corresponding to the AST.
*
* \param mod_filename The name of the model for which code should be generated.
* It is used for constructing an output filename.
* \param stream The output stream onto which to write the generated code
* \param float_type The float type to use in the generated code. The string will be used
* as-is in the target code. This defaults to \c double.
*/
CodegenCoreneuronCppVisitor(std::string mod_filename,
std::ostream& stream,
std::string float_type,
const bool optimize_ionvar_copies)
: CodegenCppVisitor(mod_filename, stream, float_type, optimize_ionvar_copies) {}


/****************************************************************************************/
/* Public printing routines for code generation for use in unit tests */
/****************************************************************************************/
Expand Down
80 changes: 53 additions & 27 deletions src/codegen/codegen_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,59 @@ using printer::CodePrinter;
* have removed return from verbatim block.
*/
class CodegenCppVisitor: public visitor::ConstAstVisitor {
public:
/**
* \brief Constructs the C++ code generator visitor
*
* This constructor instantiates an NMODL C++ code generator and allows writing generated code
* directly to a file in \c [output_dir]/[mod_filename].cpp.
*
* \note No code generation is performed at this stage. Since the code
* generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c
* visit_program in order to generate the C++ code corresponding to the AST.
*
* \param mod_filename The name of the model for which code should be generated.
* It is used for constructing an output filename.
* \param output_dir The directory where target C++ file should be generated.
* \param float_type The float type to use in the generated code. The string will be used
* as-is in the target code. This defaults to \c double.
*/
CodegenCppVisitor(std::string mod_filename,
const std::string& output_dir,
std::string float_type,
const bool optimize_ionvar_copies)
: printer(std::make_unique<CodePrinter>(output_dir + "/" + mod_filename + ".cpp"))
, mod_filename(std::move(mod_filename))
, float_type(std::move(float_type))
, optimize_ionvar_copies(optimize_ionvar_copies) {}


/**
* \brief Constructs the C++ code generator visitor
*
* This constructor instantiates an NMODL C++ code generator and allows writing generated code
* into an output stream.
*
* \note No code generation is performed at this stage. Since the code
* generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c
* visit_program in order to generate the C++ code corresponding to the AST.
*
* \param mod_filename The name of the model for which code should be generated.
* It is used for constructing an output filename.
* \param stream The output stream onto which to write the generated code
* \param float_type The float type to use in the generated code. The string will be used
* as-is in the target code. This defaults to \c double.
*/
CodegenCppVisitor(std::string mod_filename,
std::ostream& stream,
std::string float_type,
const bool optimize_ionvar_copies)
: printer(std::make_unique<CodePrinter>(stream))
, mod_filename(std::move(mod_filename))
, float_type(std::move(float_type))
, optimize_ionvar_copies(optimize_ionvar_copies) {}


protected:
using SymbolType = std::shared_ptr<symtab::Symbol>;

Expand Down Expand Up @@ -1217,33 +1270,6 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
void print_nmodl_constants();


/****************************************************************************************/
/* Protected constructors */
/****************************************************************************************/


/// This constructor is private, only the derived classes' public constructors are public
CodegenCppVisitor(std::string mod_filename,
const std::string& output_dir,
std::string float_type,
const bool optimize_ionvar_copies)
: printer(std::make_unique<CodePrinter>(output_dir + "/" + mod_filename + ".cpp"))
, mod_filename(std::move(mod_filename))
, float_type(std::move(float_type))
, optimize_ionvar_copies(optimize_ionvar_copies) {}


/// This constructor is private, only the derived classes' public constructors are public
CodegenCppVisitor(std::string mod_filename,
std::ostream& stream,
std::string float_type,
const bool optimize_ionvar_copies)
: printer(std::make_unique<CodePrinter>(stream))
, mod_filename(std::move(mod_filename))
, float_type(std::move(float_type))
, optimize_ionvar_copies(optimize_ionvar_copies) {}


/****************************************************************************************/
/* Overloaded visitor routines */
/****************************************************************************************/
Expand Down
48 changes: 3 additions & 45 deletions src/codegen/codegen_neuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ enum InterpreterWrapper { HOC, Python };
* have removed return from verbatim block.
*/
class CodegenNeuronCppVisitor: public CodegenCppVisitor {
public:
using CodegenCppVisitor::CodegenCppVisitor;

protected:
/****************************************************************************************/
/* Member variables */
Expand Down Expand Up @@ -640,51 +643,6 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor {


public:
/**
* \brief Constructs the C++ code generator visitor
*
* This constructor instantiates an NMODL C++ code generator and allows writing generated code
* directly to a file in \c [output_dir]/[mod_filename].cpp.
*
* \note No code generation is performed at this stage. Since the code
* generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c
* visit_program in order to generate the C++ code corresponding to the AST.
*
* \param mod_filename The name of the model for which code should be generated.
* It is used for constructing an output filename.
* \param output_dir The directory where target C++ file should be generated.
* \param float_type The float type to use in the generated code. The string will be used
* as-is in the target code. This defaults to \c double.
*/
CodegenNeuronCppVisitor(std::string mod_filename,
const std::string& output_dir,
std::string float_type,
const bool optimize_ionvar_copies)
: CodegenCppVisitor(mod_filename, output_dir, float_type, optimize_ionvar_copies) {}

/**
* \copybrief nmodl::codegen::CodegenNeuronCppVisitor
*
* This constructor instantiates an NMODL C++ code generator and allows writing generated code
* into an output stream.
*
* \note No code generation is performed at this stage. Since the code
* generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c
* visit_program in order to generate the C++ code corresponding to the AST.
*
* \param mod_filename The name of the model for which code should be generated.
* It is used for constructing an output filename.
* \param stream The output stream onto which to write the generated code
* \param float_type The float type to use in the generated code. The string will be used
* as-is in the target code. This defaults to \c double.
*/
CodegenNeuronCppVisitor(std::string mod_filename,
std::ostream& stream,
std::string float_type,
const bool optimize_ionvar_copies)
: CodegenCppVisitor(mod_filename, stream, float_type, optimize_ionvar_copies) {}


/****************************************************************************************/
/* Public printing routines for code generation for use in unit tests */
/****************************************************************************************/
Expand Down

0 comments on commit ca9d55a

Please sign in to comment.