Skip to content

Commit

Permalink
Create new base class for all named items that can be added to a scope.
Browse files Browse the repository at this point in the history
Provide a helper function to identify the derived classes when reporting
errors.
  • Loading branch information
martinwhitaker committed Sep 27, 2019
1 parent 269ec2f commit b88d91c
Show file tree
Hide file tree
Showing 26 changed files with 330 additions and 48 deletions.
6 changes: 3 additions & 3 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ O = main.o async.o design_dump.o discipline.o dup_expr.o elaborate.o \
pform_disciplines.o pform_dump.o pform_package.o pform_pclass.o \
pform_class_type.o pform_string_type.o pform_struct_type.o pform_types.o \
symbol_search.o sync.o sys_funcs.o verinum.o verireal.o target.o \
Attrib.o HName.o Module.o PClass.o PDelays.o PEvent.o PExpr.o PGate.o \
PGenerate.o PModport.o PPackage.o PScope.o PSpec.o PTask.o PUdp.o \
PFunction.o PWire.o Statement.o AStatement.o $M $(FF) $(TT)
Attrib.o HName.o Module.o PClass.o PDelays.o PEvent.o PExpr.o PFunction.o \
PGate.o PGenerate.o PModport.o PNamedItem.o PPackage.o PScope.o PSpec.o \
PTask.o PUdp.o PWire.o Statement.o AStatement.o $M $(FF) $(TT)

all: dep config.h _pli_types.h version_tag.h ivl@EXEEXT@ version.exe iverilog-vpi.man
$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@ && ) true
Expand Down
12 changes: 11 additions & 1 deletion Module.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998-2017 Stephen Williams ([email protected])
* Copyright (c) 1998-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -122,3 +122,13 @@ const list<PGate*>& Module::get_gates() const
{
return gates_;
}

PNamedItem::SymbolType Module::symbol_type() const
{
if (program_block)
return PROGRAM;
if (is_interface)
return INTERFACE;

return MODULE;
}
8 changes: 5 additions & 3 deletions Module.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef IVL_Module_H
#define IVL_Module_H
/*
* Copyright (c) 1998-2017 Stephen Williams ([email protected])
* Copyright (c) 1998-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand All @@ -28,7 +28,7 @@
# include "HName.h"
# include "named.h"
# include "PScope.h"
# include "LineInfo.h"
# include "PNamedItem.h"
# include "netlist.h"
# include "pform_types.h"
class PExpr;
Expand All @@ -54,7 +54,7 @@ class NetScope;
* these containers as well.
*/

class Module : public PScopeExtra, public LineInfo {
class Module : public PScopeExtra, public PNamedItem {

/* The module ports are in general a vector of port_t
objects. Each port has a name and an ordered list of
Expand Down Expand Up @@ -160,6 +160,8 @@ class Module : public PScopeExtra, public LineInfo {

bool elaborate_sig(Design*, NetScope*scope) const;

SymbolType symbol_type() const;

private:
void dump_specparams_(ostream&out, unsigned indent) const;
list<PGate*> gates_;
Expand Down
7 changes: 6 additions & 1 deletion PClass.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Stephen Williams ([email protected])
* Copyright (c) 2012-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -28,3 +28,8 @@ PClass::PClass(perm_string name, LexicalScope*parent)
PClass::~PClass()
{
}

PNamedItem::SymbolType PClass::symbol_type() const
{
return CLASS;
}
8 changes: 5 additions & 3 deletions PClass.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef IVL_PClass_H
#define IVL_PClass_H
/*
* Copyright (c) 2012-2014 Stephen Williams ([email protected])
* Copyright (c) 2012-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand All @@ -20,7 +20,7 @@
*/

# include "PScope.h"
# include "LineInfo.h"
# include "PNamedItem.h"
# include "StringHeap.h"
# include <iostream>

Expand All @@ -32,14 +32,16 @@ class PChainConstructor;
* collected.
*/

class PClass : public PScopeExtra, public LineInfo {
class PClass : public PScopeExtra, public PNamedItem {

public:
explicit PClass (perm_string name, LexicalScope*parent);
~PClass();

void dump(std::ostream&out, unsigned indent) const;

SymbolType symbol_type() const;

public:
class_type_t*type;
};
Expand Down
6 changes: 5 additions & 1 deletion PEvent.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004 Stephen Williams ([email protected])
* Copyright (c) 2004-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -35,3 +35,7 @@ perm_string PEvent::name() const
return name_;
}

PNamedItem::SymbolType PEvent::symbol_type() const
{
return EVENT;
}
8 changes: 5 additions & 3 deletions PEvent.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef IVL_PEvent_H
#define IVL_PEvent_H
/*
* Copyright (c) 2000-2014 Stephen Williams ([email protected])
* Copyright (c) 2000-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand All @@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

# include "LineInfo.h"
# include "PNamedItem.h"
# include "StringHeap.h"
# include <string>

Expand All @@ -31,7 +31,7 @@ class NetScope;
* are declared in Verilog as ``event foo;'' The name passed to the
* constructor is the "foo" part of the declaration.
*/
class PEvent : public LineInfo {
class PEvent : public PNamedItem {

public:
// The name is a perm-allocated string. It is the simple name
Expand All @@ -43,6 +43,8 @@ class PEvent : public LineInfo {

void elaborate_scope(Design*des, NetScope*scope) const;

SymbolType symbol_type() const;

private:
perm_string name_;

Expand Down
7 changes: 6 additions & 1 deletion PFunction.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999-2013 Stephen Williams ([email protected])
* Copyright (c) 1999-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -83,3 +83,8 @@ PChainConstructor* PFunction::extract_chain_constructor()

return res;
}

PNamedItem::SymbolType PFunction::symbol_type() const
{
return FUNCTION;
}
7 changes: 6 additions & 1 deletion PGate.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999-2013 Stephen Williams ([email protected])
* Copyright (c) 1999-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -117,6 +117,11 @@ unsigned PGate::delay_count() const
return delay_.delay_count();
}

PNamedItem::SymbolType PGate::symbol_type() const
{
return INSTANCE;
}

PGAssign::PGAssign(list<PExpr*>*pins)
: PGate(perm_string(), pins)
{
Expand Down
8 changes: 5 additions & 3 deletions PGate.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef IVL_PGate_H
#define IVL_PGate_H
/*
* Copyright (c) 1998-2014 Stephen Williams ([email protected])
* Copyright (c) 1998-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand All @@ -22,7 +22,7 @@
# include "svector.h"
# include "StringHeap.h"
# include "named.h"
# include "LineInfo.h"
# include "PNamedItem.h"
# include "PDelays.h"
# include "netlist.h"
# include <map>
Expand All @@ -47,7 +47,7 @@ class Module;
* single strength pair. There is a strength of the 0 drive, and a
* strength of the 1 drive.
*/
class PGate : public LineInfo {
class PGate : public PNamedItem {

public:
explicit PGate(perm_string name, list<PExpr*>*pins,
Expand Down Expand Up @@ -88,6 +88,8 @@ class PGate : public LineInfo {
virtual void elaborate_scope(Design*des, NetScope*sc) const;
virtual bool elaborate_sig(Design*des, NetScope*scope) const;

SymbolType symbol_type() const;

protected:
const vector<PExpr*>& get_pins() const { return pins_; }

Expand Down
7 changes: 6 additions & 1 deletion PGenerate.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2011 Stephen Williams ([email protected])
* Copyright (c) 2006-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -112,3 +112,8 @@ ostream& operator << (ostream&out, PGenerate::scheme_t type)
}
return out;
}

PNamedItem::SymbolType PGenerate::symbol_type() const
{
return GENBLOCK;
}
8 changes: 5 additions & 3 deletions PGenerate.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef IVL_PGenerate_H
#define IVL_PGenerate_H
/*
* Copyright (c) 2006-2014 Stephen Williams ([email protected])
* Copyright (c) 2006-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand All @@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

# include "LineInfo.h"
# include "PNamedItem.h"
# include "StringHeap.h"
# include "HName.h"
# include "PScope.h"
Expand Down Expand Up @@ -50,7 +50,7 @@ class PWire;
* The parent points to the GS_CASE that contains this item.
* the loop_test is compared with the parent->loop_test expression.
*/
class PGenerate : public LineInfo, public LexicalScope {
class PGenerate : public PNamedItem, public LexicalScope {

public:
explicit PGenerate(LexicalScope*parent, unsigned id_number);
Expand Down Expand Up @@ -107,6 +107,8 @@ class PGenerate : public LineInfo, public LexicalScope {

void dump(ostream&out, unsigned indent) const;

SymbolType symbol_type() const;

private:
bool generate_scope_loop_(Design*des, NetScope*container);
bool generate_scope_condit_(Design*des, NetScope*container, bool else_flag);
Expand Down
7 changes: 6 additions & 1 deletion PModport.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Stephen Williams ([email protected])
* Copyright (c) 2015-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -29,3 +29,8 @@ PModport::PModport(perm_string n)
PModport::~PModport()
{
}

PNamedItem::SymbolType PModport::symbol_type() const
{
return MODPORT;
}
8 changes: 5 additions & 3 deletions PModport.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef IVL_PModport_H
#define IVL_PModport_H
/*
* Copyright (c) 2015 Stephen Williams ([email protected])
* Copyright (c) 2015-2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand All @@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

# include "LineInfo.h"
# include "PNamedItem.h"
# include "PScope.h"
# include "StringHeap.h"
# include "netlist.h"
Expand All @@ -28,7 +28,7 @@
/*
* The PModport class represents a parsed SystemVerilog modport list.
*/
class PModport : public LineInfo {
class PModport : public PNamedItem {

public:
// The name is a perm-allocated string. It is the simple name
Expand All @@ -41,6 +41,8 @@ class PModport : public LineInfo {
typedef pair <NetNet::PortType,PExpr*> simple_port_t;
map<perm_string,simple_port_t> simple_ports;

SymbolType symbol_type() const;

private:
perm_string name_;

Expand Down
Loading

0 comments on commit b88d91c

Please sign in to comment.