Skip to content

Commit c5fee8b

Browse files
committed
Elaborate root tasks/functions.
1 parent e1ec27e commit c5fee8b

12 files changed

+182
-38
lines changed

PTask.h

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class PTaskFunc : public PScope, public LineInfo {
4949
// to the class type.
5050
inline class_type_t* method_of() const { return this_type_; }
5151

52+
53+
virtual void elaborate_sig(Design*des, NetScope*scope) const =0;
54+
virtual void elaborate(Design*des, NetScope*scope) const =0;
55+
56+
virtual void dump(std::ostream&, unsigned) const =0;
57+
5258
protected:
5359
// Elaborate the ports list. Write into the ports vector the
5460
// NetNet pointers for the ports, and write into the pdefs the

design_dump.cc

+6
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,12 @@ void Design::dump(ostream&o) const
18851885
cur->second->dump_scope(o);
18861886
}
18871887

1888+
o << "$ROOT TASKS/FUNCTIONS:" << endl;
1889+
for (map<NetScope*,PTaskFunc*>::const_iterator cur = root_tasks_.begin()
1890+
; cur != root_tasks_.end() ; ++ cur) {
1891+
cur->first->dump(o);
1892+
}
1893+
18881894
o << "SCOPES:" << endl;
18891895
for (list<NetScope*>::const_iterator scope = root_scopes_.begin();
18901896
scope != root_scopes_.end(); ++ scope ) {

elab_scope.cc

+61-17
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,25 @@ static void elaborate_scope_events_(Design*des, NetScope*scope,
559559
}
560560
}
561561

562+
static void elaborate_scope_task(Design*des, NetScope*scope, PTask*task)
563+
{
564+
hname_t use_name( task->pscope_name() );
565+
566+
NetScope*task_scope = new NetScope(scope, use_name, NetScope::TASK);
567+
task_scope->is_auto(task->is_auto());
568+
task_scope->set_line(task);
569+
570+
if (scope==0)
571+
des->add_root_task(task_scope, task);
572+
573+
if (debug_scopes) {
574+
cerr << task->get_fileline() << ": elaborate_scope_task: "
575+
<< "Elaborate task scope " << scope_path(task_scope) << endl;
576+
}
577+
578+
task->elaborate_scope(des, task_scope);
579+
}
580+
562581
static void elaborate_scope_tasks(Design*des, NetScope*scope,
563582
const map<perm_string,PTask*>&tasks)
564583
{
@@ -600,17 +619,28 @@ static void elaborate_scope_tasks(Design*des, NetScope*scope,
600619
des->errors += 1;
601620
}
602621

603-
NetScope*task_scope = new NetScope(scope, use_name,
604-
NetScope::TASK);
605-
task_scope->is_auto((*cur).second->is_auto());
606-
task_scope->set_line((*cur).second);
622+
elaborate_scope_task(des, scope, cur->second);
623+
}
607624

608-
if (debug_scopes)
609-
cerr << cur->second->get_fileline() << ": debug: "
610-
<< "Elaborate task scope " << scope_path(task_scope) << endl;
611-
(*cur).second->elaborate_scope(des, task_scope);
625+
}
626+
627+
static void elaborate_scope_func(Design*des, NetScope*scope, PFunction*task)
628+
{
629+
hname_t use_name( task->pscope_name() );
630+
631+
NetScope*task_scope = new NetScope(scope, use_name, NetScope::FUNC);
632+
task_scope->is_auto(task->is_auto());
633+
task_scope->set_line(task);
634+
635+
if (scope==0)
636+
des->add_root_task(task_scope, task);
637+
638+
if (debug_scopes) {
639+
cerr << task->get_fileline() << ": elaborate_scope_func: "
640+
<< "Elaborate task scope " << scope_path(task_scope) << endl;
612641
}
613642

643+
task->elaborate_scope(des, task_scope);
614644
}
615645

616646
static void elaborate_scope_funcs(Design*des, NetScope*scope,
@@ -655,19 +685,33 @@ static void elaborate_scope_funcs(Design*des, NetScope*scope,
655685
des->errors += 1;
656686
}
657687

658-
NetScope*func_scope = new NetScope(scope, use_name,
659-
NetScope::FUNC);
660-
func_scope->is_auto((*cur).second->is_auto());
661-
func_scope->set_line((*cur).second);
662-
663-
if (debug_scopes)
664-
cerr << cur->second->get_fileline() << ": debug: "
665-
<< "Elaborate function scope " << scope_path(func_scope) << endl;
666-
(*cur).second->elaborate_scope(des, func_scope);
688+
elaborate_scope_func(des, scope, cur->second);
667689
}
668690

669691
}
670692

693+
void elaborate_rootscope_tasks(Design*des)
694+
{
695+
for (map<perm_string,PTaskFunc*>::iterator cur = pform_tasks.begin()
696+
; cur != pform_tasks.end() ; ++ cur) {
697+
698+
if (PTask*task = dynamic_cast<PTask*> (cur->second)) {
699+
elaborate_scope_task(des, 0, task);
700+
continue;
701+
}
702+
703+
if (PFunction*func = dynamic_cast<PFunction*>(cur->second)) {
704+
elaborate_scope_func(des, 0, func);
705+
continue;
706+
}
707+
708+
cerr << cur->second->get_fileline() << ": internal error: "
709+
<< "elabortae_rootscope_tasks does not understand "
710+
<< "this object," << endl;
711+
des->errors += 1;
712+
}
713+
}
714+
671715
class generate_schemes_work_item_t : public elaborator_work_item_t {
672716
public:
673717
generate_schemes_work_item_t(Design*des__, NetScope*scope, Module*mod)

elab_sig.cc

+11
Original file line numberDiff line numberDiff line change
@@ -1316,4 +1316,15 @@ void Design::root_elaborate_sig(void)
13161316

13171317
cur_class->elaborate_sig(this, cur_pclass);
13181318
}
1319+
1320+
for (map<NetScope*,PTaskFunc*>::iterator cur = root_tasks_.begin()
1321+
; cur != root_tasks_.end() ; ++ cur) {
1322+
1323+
if (debug_elaborate) {
1324+
cerr << cur->second->get_fileline() << ": root_elaborate_sig: "
1325+
<< "Elaborate_sig for root task/func " << scope_path(cur->first) << endl;
1326+
}
1327+
1328+
cur->second->elaborate_sig(this, cur->first);
1329+
}
13191330
}

elaborate.cc

+15
Original file line numberDiff line numberDiff line change
@@ -5989,6 +5989,18 @@ void Design::root_elaborate(void)
59895989
PClass*cur_pclass = class_to_pclass_[cur_class];
59905990
cur_class->elaborate(this, cur_pclass);
59915991
}
5992+
5993+
for (map<NetScope*,PTaskFunc*>::iterator cur = root_tasks_.begin()
5994+
; cur != root_tasks_.end() ; ++ cur) {
5995+
5996+
if (debug_elaborate) {
5997+
cerr << cur->second->get_fileline() << ": Design::root_elaborate: "
5998+
<< "Elaborate for root task/func " << scope_path(cur->first) << endl;
5999+
}
6000+
6001+
cur->second->elaborate(this, cur->first);
6002+
}
6003+
59926004
}
59936005

59946006
/*
@@ -6022,6 +6034,9 @@ Design* elaborate(list<perm_string>roots)
60226034
// Elaborate enum sets in $root scope.
60236035
elaborate_rootscope_enumerations(des);
60246036

6037+
// Elaborate tasks and functions in $root scope.
6038+
elaborate_rootscope_tasks(des);
6039+
60256040
// Elaborate classes in $root scope.
60266041
elaborate_rootscope_classes(des);
60276042

main.cc

+10
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,16 @@ int main(int argc, char*argv[])
10191019
; cur != disciplines.end() ; ++ cur ) {
10201020
pform_dump(out, (*cur).second);
10211021
}
1022+
out << "PFORM DUMP $ROOT TASKS/FUNCTIONS:" << endl;
1023+
for (map<perm_string,PTaskFunc*>::iterator cur = pform_tasks.begin()
1024+
; cur != pform_tasks.end() ; ++ cur) {
1025+
pform_dump(out, cur->second);
1026+
}
1027+
out << "PFORM DUMP $ROOT CLASSES:" << endl;
1028+
for (map<perm_string,PClass*>::iterator cur = pform_classes.begin()
1029+
; cur != pform_classes.end() ; ++ cur) {
1030+
pform_dump(out, cur->second);
1031+
}
10221032
out << "PFORM DUMP PACKAGES:" << endl;
10231033
for (map<perm_string,PPackage*>::iterator pac = pform_packages.begin()
10241034
; pac != pform_packages.end() ; ++ pac) {

net_design.cc

+23
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,25 @@ NetScope* Design::find_scope(const std::list<hname_t>&path) const
197197

198198
tmp.pop_front();
199199
}
200+
}
201+
202+
for (map<NetScope*,PTaskFunc*>::const_iterator root = root_tasks_.begin()
203+
; root != root_tasks_.end() ; ++ root) {
204+
205+
NetScope*cur = root->first;
206+
if (path.front() != cur->fullname())
207+
continue;
208+
209+
std::list<hname_t> tmp = path;
210+
tmp.pop_front();
211+
212+
while (cur) {
213+
if (tmp.empty()) return cur;
200214

215+
cur = cur->child( tmp.front() );
216+
217+
tmp.pop_front();
218+
}
201219
}
202220

203221
return 0;
@@ -831,6 +849,11 @@ NetScope* Design::find_task(NetScope*scope, const pform_name_t&name)
831849
return 0;
832850
}
833851

852+
void Design::add_root_task(NetScope*tscope, PTaskFunc*tf)
853+
{
854+
root_tasks_[tscope] = tf;
855+
}
856+
834857
void Design::add_node(NetNode*net)
835858
{
836859
assert(net->design_ == 0);

net_scope.cc

-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ NetScope::NetScope(NetScope*up, const hname_t&n, NetScope::TYPE t, bool nest, bo
135135
time_unit_ = 0;
136136
time_prec_ = 0;
137137
time_from_timescale_ = false;
138-
assert(t==MODULE || t==PACKAGE || t==CLASS);
139138
}
140139

141140
switch (t) {

netlist.h

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class NetEvWait;
7777
class PClass;
7878
class PExpr;
7979
class PFunction;
80+
class PTaskFunc;
8081
struct enum_type_t;
8182
class netclass_t;
8283
class netdarray_t;
@@ -4813,6 +4814,7 @@ class Design : public Definitions {
48134814

48144815
// Tasks
48154816
NetScope* find_task(NetScope*scope, const pform_name_t&name);
4817+
void add_root_task(NetScope*tscope, PTaskFunc*tf);
48164818

48174819
// Find a class in the $root scope.
48184820
void add_class(netclass_t*cl, PClass*pclass);
@@ -4852,6 +4854,9 @@ class Design : public Definitions {
48524854
// packages do not nest.
48534855
std::map<perm_string,NetScope*>packages_;
48544856

4857+
// Tasks in the $root scope
4858+
std::map<NetScope*,PTaskFunc*>root_tasks_;
4859+
48554860
// Need this for elaboration of $root scope pclass objects.
48564861
std::map<netclass_t*,PClass*> class_to_pclass_;
48574862

parse_api.h

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Design;
3030
class Module;
3131
class PClass;
3232
class PPackage;
33+
class PTaskFunc;
3334
class PUdp;
3435
class data_type_t;
3536
struct enum_type_t;
@@ -43,13 +44,17 @@ extern std::map<perm_string,Module*> pform_modules;
4344
extern std::map<perm_string,PUdp*> pform_primitives;
4445
extern std::map<perm_string,data_type_t*> pform_typedefs;
4546
extern std::set<enum_type_t*> pform_enum_sets;
47+
extern std::map<perm_string,PTaskFunc*> pform_tasks;
4648
extern std::map<perm_string,PClass*> pform_classes;
4749
extern std::map<perm_string,PPackage*> pform_packages;
4850

51+
extern void pform_dump(std::ostream&out, const PClass*pac);
4952
extern void pform_dump(std::ostream&out, const PPackage*pac);
53+
extern void pform_dump(std::ostream&out, const PTaskFunc*tf);
5054

5155
extern void elaborate_rootscope_enumerations(Design*des);
5256
extern void elaborate_rootscope_classes(Design*des);
57+
extern void elaborate_rootscope_tasks(Design*des);
5358

5459
/*
5560
* This code actually invokes the parser to make modules. The first

pform.cc

+15-6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ set<enum_type_t*>pform_enum_sets;
7171
*/
7272
map<perm_string,PClass*> pform_classes;
7373

74+
/*
75+
* Task and function definitions in the $root scope go here.
76+
*/
77+
map<perm_string,PTaskFunc*> pform_tasks;
78+
7479
std::string vlltype::get_fileline() const
7580
{
7681
ostringstream buf;
@@ -371,16 +376,11 @@ PTask* pform_push_task_scope(const struct vlltype&loc, char*name, bool is_auto)
371376
FILE_NAME(task, loc);
372377

373378
PScopeExtra*scopex = find_nearest_scopex(lexical_scope);
374-
if ((scopex == 0) && (generation_flag < GN_VER2005_SV)) {
379+
if ((scopex == 0) && !gn_system_verilog()) {
375380
cerr << task->get_fileline() << ": error: task declarations "
376381
"must be contained within a module." << endl;
377382
error_count += 1;
378383
}
379-
if ((scopex == 0) && (generation_flag >= GN_VER2005_SV)) {
380-
cerr << task->get_fileline() << ": sorry: task declarations "
381-
"in the compilation unit scope are not yet supported." << endl;
382-
error_count += 1;
383-
}
384384

385385
if (pform_cur_generate) {
386386
// Check if the task is already in the dictionary.
@@ -402,6 +402,15 @@ PTask* pform_push_task_scope(const struct vlltype&loc, char*name, bool is_auto)
402402
error_count += 1;
403403
}
404404
scopex->tasks[task->pscope_name()] = task;
405+
406+
} else {
407+
if (pform_tasks.find(task_name) != pform_tasks.end()) {
408+
cerr << task->get_fileline() << ": error: "
409+
<< "Duplicate definition for task '" << name
410+
<< "' in $root scope." << endl;
411+
error_count += 1;
412+
}
413+
pform_tasks[task_name] = task;
405414
}
406415

407416
lexical_scope = task;

0 commit comments

Comments
 (0)