systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
Model.cpp
Go to the documentation of this file.
1#include "Model.h"
2
3#include <string>
4
5using namespace systemc_clang;
6
7Model::Model() : root_module_inst_{nullptr} {}
8
10 for (ModuleInstance *inst : module_instances_) {
11 ModuleInstanceType instance_info{inst->getInstanceInfo()};
12 instance_info.dump();
13
14 ModuleInstance *parent{getInstance(instance_info.getParentDecl())};
15
16 if ((parent != nullptr) && (parent != inst)) {
17 parent->addNestedModule(inst);
18 } else {
22 llvm::errs() << "Multiple root module instances are not allowed\n";
23 }
24 root_module_inst_ = inst;
25 }
26 }
27}
28
32
34 for (auto &inst : module_instances_) {
35 // auto incomplete_decl{inst.first};
36 // auto instance_list{inst.second};
37 LLVM_DEBUG(llvm::dbgs() << "Delete instances for " << inst->getName(););
38 // for (ModuleInstance *inst_in_list : instance_list) {
39 // This is a ModuleInstance*
40 LLVM_DEBUG(llvm::dbgs() << "- delete instance: " << inst->getInstanceName()
41 << ", pointer: " << inst << "\n";);
42 //
43 // IMPORTANT
44 // The current design creates an incomplete ModuleInstance in Matchers. The
45 // ports are populated there. Then, for each instance that is recognized,
46 // a new ModuleInstance is created, and information from the incomplete
47 // ModuleInstance is copied into the new instance-specific ModuleInstance.
48 // When deleting an instance of ModuleInstance, we have to be careful. This
49 // is because we do not want to delete the instance-specific ModuleInstance,
50 // which has structures with pointers in it (PortDecl), and then delete
51 // the incomplete ModuleInstance because the latter will cause a double free
52 // memory error. This is because the deletion of the instance-specific
53 // ModuleInstance will free the objects identified in the incomplete
54 // ModuleInstance.
55 //
56 // The current solution is to clear the information for the
57 // instance-specific ModuleInstance before deleting it. Then, the deletion
58 // of the incomplete ModuleInstance will free the other objects such as
59 // PortDecl. clearOnlyGlobal does exactly this.
60 //
61 // TODO: ENHANCEMENT: This is one major refactoring that should be done at
62 // some point.
63 //
64 inst->clearOnlyGlobal();
65 delete inst;
66
67 // This is deleted in the vector.
68 root_module_inst_ = nullptr;
69 }
70
71 LLVM_DEBUG(llvm::dbgs() << "Done with delete\n";);
72}
73//
74// Model::Model(const Model &from) { modules_ = from.modules_; }
75//
77 module_instances_.push_back(mod);
78}
79
83
86 llvm::errs() << " \n Size : " << entry_function_gpu_macro_map_.size() << " "
87 << e.size();
88}
89
91 for (FindGlobalEvents::globalEventMapType::iterator it = eventMap.begin();
92 it != eventMap.end(); it++) {
93 std::string eventName = it->first;
94 EventContainer *event{new EventContainer(eventName, it->second)};
95
96 event_map_.insert(eventPairType(eventName, event));
97 }
98}
99
100void Model::addSCMain(FunctionDecl *fnDecl) { scmain_function_decl_ = fnDecl; }
101
102ModuleInstance *Model::getInstance(const std::string &instance_name) {
103 auto test_module_it =
104 std::find_if(module_instances_.begin(), module_instances_.end(),
105 [instance_name](const auto &instance) {
106 return (instance->getInstanceName() == instance_name);
107 });
108
109 if (test_module_it != module_instances_.end()) {
110 return *test_module_it;
111 }
112 return nullptr;
113}
114
115// Must provide the Instance decl.
116ModuleInstance *Model::getInstance(Decl *instance_decl) {
117
118 auto test_module_it =
119 std::find_if(module_instances_.begin(), module_instances_.end(),
120 [instance_decl](const auto &instance) {
121 return (instance->getInstanceDecl() == instance_decl);
122 });
123 if (test_module_it != module_instances_.end()) {
124 return *test_module_it;
125 }
126 return nullptr;
127}
128
132
133std::vector<ModuleInstance *> &Model::getInstances() {
134 return module_instances_;
135}
136
138
139unsigned int Model::getNumEvents() { return (event_map_.size() - 3); }
140
141void Model::dump(llvm::raw_ostream &os) {
142 os << "sc_module instances [" << module_instances_.size() << "]: ";
143
144 for (const auto &inst : module_instances_) {
145 os << inst->getInstanceName() << " ";
146 }
147 os << "\n";
148
149 os << "Print out instance information";
150 for (const auto &inst : module_instances_) {
151 inst->dump(os);
152 }
153}
std::map< std::string, clang::VarDecl * > globalEventMapType
map< string, string > simulationTimeMapType
Definition FindSimTime.h:18
ModuleInstance * getRootModuleInstance() const
Definition Model.cpp:29
void populateNestedModules()
Definition Model.cpp:9
ModuleInstance * root_module_inst_
Definition Model.h:70
map< EntryFunctionContainer *, FindGPUMacro::forStmtGPUMacroMapType > entryFunctionGPUMacroMapType
Definition Model.h:40
eventMapType getEventMapType()
Definition Model.cpp:137
std::pair< std::string, EventContainer * > eventPairType
Definition Model.h:29
FunctionDecl * scmain_function_decl_
Definition Model.h:74
entryFunctionGPUMacroMapType entry_function_gpu_macro_map_
Definition Model.h:79
void addGlobalEvents(FindGlobalEvents::globalEventMapType)
Definition Model.cpp:90
void addSimulationTime(FindSimTime::simulationTimeMapType)
Definition Model.cpp:80
std::map< std::string, EventContainer * > eventMapType
Definition Model.h:30
void addSCMain(FunctionDecl *)
Definition Model.cpp:100
void dump(raw_ostream &)
Definition Model.cpp:141
entryFunctionGPUMacroMapType getEntryFunctionGPUMacroMap()
Definition Model.cpp:129
ModuleInstance * getInstance(const std::string &instance_name)
Definition Model.cpp:102
void addInstance(ModuleInstance *)
Definition Model.cpp:76
FindSimTime::simulationTimeMapType simulation_time_
Definition Model.h:72
std::vector< ModuleInstance * > & getInstances()
Definition Model.cpp:133
eventMapType event_map_
Definition Model.h:73
void addEntryFunctionGPUMacroMap(entryFunctionGPUMacroMapType)
Definition Model.cpp:84
unsigned int getNumEvents()
Definition Model.cpp:139
virtual ~Model()
Definition Model.cpp:33
std::vector< ModuleInstance * > module_instances_
Definition Model.h:69
Forward declarations.