Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion modules/openfast-registry/src/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,11 @@ struct Registry
std::map<std::string, std::shared_ptr<InterfaceData>, ci_less> interface_map;
std::map<std::string, std::shared_ptr<Module>, ci_less> modules;
std::map<std::string, std::shared_ptr<DataType>, ci_less> data_types;
std::map<std::string, std::shared_ptr<DataType>, ci_less> data_types_isocbinding;
bool gen_c_code = false;
bool no_extrap_interp = false;
bool gen_inc_subs = false;
bool use_isocbinding = false;

Registry()
{
Expand All @@ -453,6 +455,10 @@ struct Registry
auto R8Ki = std::make_shared<DataType>("R8Ki", "REAL(R8Ki)", DataType::Tag::Real, 64);
auto DbKi = std::make_shared<DataType>("DbKi", "REAL(DbKi)", DataType::Tag::Real, 64);
auto logical = std::make_shared<DataType>("Logical", "LOGICAL", DataType::Tag::Logical);
auto c_int = std::make_shared<DataType>("c_int", "INTEGER(c_int)", DataType::Tag::Integer, 32);
auto c_float = std::make_shared<DataType>("c_float", "REAL(c_float)", DataType::Tag::Real, 32);
auto c_double = std::make_shared<DataType>("c_double","REAL(c_double)", DataType::Tag::Real, 64);
auto c_char = std::make_shared<DataType>("c_char", "CHARACTER(c_char)", DataType::Tag::Character);

// Derived types
auto mesh = std::make_shared<DataType>(nullptr, "MeshType", "MeshType", "MeshType");
Expand All @@ -473,6 +479,10 @@ struct Registry
{"logical", logical},
{"meshtype", mesh},
{"dll_type", dll},
{"c_int",c_int},
{"c_float",c_float},
{"c_double",c_double},
{"c_char",c_char},
};

this->interface_map = std::map<std::string, std::shared_ptr<InterfaceData>, ci_less>{
Expand Down Expand Up @@ -500,6 +510,15 @@ struct Registry
{"PartialConstrStatePInputType",
std::make_shared<InterfaceData>("PartialConstrStatePInputType", "dZdu", true)},
};

// Map of ISO_C_BINDING types (for checks only)
this->data_types_isocbinding = std::map<std::string, std::shared_ptr<DataType>, ci_less>{
{"c_int",c_int},
{"c_float",c_float},
{"c_double",c_double},
{"c_char",c_char},
};

}

// Parsing
Expand All @@ -512,12 +531,20 @@ struct Registry
// Pointer to type
std::shared_ptr<DataType> data_type;

// if using ISO_C_BINDING, search these types first
auto it = data_types_isocbinding.find(type_name);
if (it != data_types_isocbinding.end())
{
this->use_isocbinding = true;
return it->second;
}

// Get map of data types to search
// If module was provided, search it; otherwise, search registry
auto &data_types = mod == nullptr ? this->data_types : mod->data_types;

// Search for type in registry, return if found
auto it = data_types.find(type_name);
it = data_types.find(type_name);
if (it != data_types.end())
{
return it->second;
Expand Down
4 changes: 4 additions & 0 deletions modules/openfast-registry/src/registry_gen_fortran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ void Registry::gen_fortran_module(const Module &mod, const std::string &out_dir)
// Write preamble
w << std::regex_replace(FAST_preamble, std::regex("ModuleName"), mod.name);

// Output USE statements for literal passthroughs (i.e. ISO_C_BINDING)
if (this->use_isocbinding)
w << "USE ISO_C_BINDING\n";

// Output USE statements for non-root modules
for (auto const &mod : this->use_modules)
if (tolower(mod).compare("nwtc_library") != 0)
Expand Down