diff --git a/vhdlpp/architec_elaborate.cc b/vhdlpp/architec_elaborate.cc index eba3ec49e..7430bae83 100644 --- a/vhdlpp/architec_elaborate.cc +++ b/vhdlpp/architec_elaborate.cc @@ -59,6 +59,14 @@ int Architecture::elaborate(Entity*entity) cur->second->elaborate_init_expr(entity, this); } + // Create 'initial' and 'final' blocks for implicit + // initalization and clean-up actions + if(!initializers_.empty()) + statements_.push_front(new InitialStatement(&initializers_)); + + if(!finalizers_.empty()) + statements_.push_front(new FinalStatement(&finalizers_)); + for (list::iterator cur = statements_.begin() ; cur != statements_.end() ; ++cur) { diff --git a/vhdlpp/scope.cc b/vhdlpp/scope.cc index b178547c7..bc1e42979 100644 --- a/vhdlpp/scope.cc +++ b/vhdlpp/scope.cc @@ -63,6 +63,9 @@ ScopeBase::ScopeBase(const ActiveScope&ref) use_enums_ = ref.use_enums_; + initializers_ = ref.initializers_; + finalizers_ = ref.finalizers_; + // This constructor is invoked when the parser is finished with // an active scope and is making the actual scope. At this point // we know that "this" is the parent scope for the subprograms, diff --git a/vhdlpp/scope.h b/vhdlpp/scope.h index f7742e716..444583d09 100644 --- a/vhdlpp/scope.h +++ b/vhdlpp/scope.h @@ -34,6 +34,7 @@ class ComponentBase; class Package; class SubprogramHeader; class VType; +class SequentialStmt; template struct delete_object{ @@ -75,6 +76,20 @@ class ScopeBase { cur_subprograms_[name] = obj; } + // Adds a statement to implicit initializers list + // (emitted in a 'initial block). + void add_initializer(SequentialStmt* s) + { + initializers_.push_back(s); + } + + // Adds a statement to implicit finalizers list + // (emitted in a 'final' block). + void add_finalizer(SequentialStmt* s) + { + finalizers_.push_back(s); + } + protected: void cleanup(); @@ -122,6 +137,12 @@ class ScopeBase { std::list use_enums_; + // List of statements that should be emitted in a 'initial' block + std::list initializers_; + + // List of statements that should be emitted in a 'final' block + std::list finalizers_; + void do_use_from(const ScopeBase*that); };