Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #15 from The-OpenROAD-Project-private/verilog-dup
Browse files Browse the repository at this point in the history
Module Hierarchy (1-level)
  • Loading branch information
maliberty authored Dec 7, 2020
2 parents ef0bff1 + f3e9495 commit 5522baa
Show file tree
Hide file tree
Showing 28 changed files with 1,704 additions and 58 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@
*.a
*.lib

# Logs
*.log

# Executables
*.exe
*.out
*.app

# python cache
__pycache__/
*.py[cod]

# build
build
lbuild
Expand Down
104 changes: 85 additions & 19 deletions include/opendb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ class dbStringProperty;
class dbIntProperty;
class dbDoubleProperty;

//Generator Code Begin 1
//Generator Code End 1

// Generator Code Begin 1
// Generator Code End 1

// Design objects
class dbChip;
Expand All @@ -100,9 +99,10 @@ class dbTechAntennaPinModel;
class dbBlockCallBackObj;
class dbRegion;
class dbBPin;
//Generator Code Begin 2
//Generator Code End 2

// Generator Code Begin 2
class dbModule;
class dbModInst;
// Generator Code End 2

// Lib objects
class dbLib;
Expand All @@ -111,8 +111,8 @@ class dbMaster;
class dbMTerm;
class dbMPin;
class dbTarget;
//Generator Code Begin 3
//Generator Code End 3
// Generator Code Begin 3
// Generator Code End 3

// Tech objects
class dbTech;
Expand All @@ -129,8 +129,8 @@ class dbTechMinCutRule;
class dbTechMinEncRule;
class dbTechV55InfluenceEntry;
class dbTechSameNetRule;
//Generator Code Begin 4
//Generator Code End 4
// Generator Code Begin 4
// Generator Code End 4

class dbViaParams;

Expand Down Expand Up @@ -518,13 +518,11 @@ class dbBox : public dbObject
uint getWidth(uint dir = 1);
uint getLength(uint dir = 1);


///
/// Get GeomShape Interface
///
GeomShape* getGeomShape();


///
/// Set temporary flag visited
///
Expand Down Expand Up @@ -684,7 +682,7 @@ class dbSBox : public dbBox
/// Get Oct Wire Shape
///
Oct getOct();

///
/// Add a rect to a dbSWire.
///
Expand All @@ -709,7 +707,7 @@ class dbSBox : public dbBox
int x2,
int y2,
dbWireShapeType type,
Direction dir = UNDEFINED,
Direction dir = UNDEFINED,
int width = 0);

///
Expand Down Expand Up @@ -849,12 +847,28 @@ class dbBlock : public dbObject
///
dbSet<dbInst> getInsts();

///
/// Get the modules of this block.
///
dbSet<dbModule> getModules();

///
/// Get the modinsts of this block.
///
dbSet<dbModInst> getModInsts();

///
/// Find a specific instance of this block.
/// Returns NULL if the object was not found.
///
dbInst* findInst(const char* name);

///
/// Find a specific module in this block.
/// Returns NULL if the object was not found.
///
dbModule* findModule(const char* name);

///
/// Find a set of insts. Each name can be real name, or Ixxx, or xxx,
/// where xxx is the inst oid.
Expand Down Expand Up @@ -2922,6 +2936,12 @@ class dbInst : public dbObject
///
dbRegion* getRegion();

///
/// Get the module this instance belongs to. Returns NULL if instance has no
/// assigned module.
///
dbModule* getModule();

///
/// Find the iterm of the given terminal name.
/// Returns NULL if no terminal was found.
Expand Down Expand Up @@ -3627,7 +3647,6 @@ class dbWire : public dbObject
///
void detach();


///
/// Copy the src wire to the desintation wire.
///
Expand Down Expand Up @@ -3741,7 +3760,6 @@ class dbSWire : public dbObject
/// Translate a database-id back to a pointer.
///
static dbSWire* getSWire(dbBlock* block, uint oid);

};

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3876,7 +3894,7 @@ class dbTrackGrid : public dbObject
/// Translate a database-id back to a pointer.
///
static dbTrackGrid* getTrackGrid(dbBlock* block, uint oid);

///
/// destroy a grid
///
Expand Down Expand Up @@ -7120,7 +7138,55 @@ class dbViaParams : private _dbViaParams
void setBottomLayer(dbTechLayer* layer);
};

//Generator Code Begin 5
//Generator Code End 5
// Generator Code Begin 5

class dbModule : public dbObject
{
public:
char* getName() const;

dbModInst* getModInst() const;

// User Code Begin dbModule
void addInst(dbInst* inst);

void removeInst(dbInst* inst);

dbSet<dbInst> getInsts();

dbSet<dbModInst> getChildren();

dbModInst* findModInst(const char* name);

static dbModule* create(dbBlock* block, const char* name);

static void destroy(dbModule* module);

dbModule* getModule(dbBlock* block_, uint dbid_);

// User Code End dbModule
};

class dbModInst : public dbObject
{
public:
dbModule* getParent() const;

dbModule* getMaster() const;

// User Code Begin dbModInst
static dbModInst* create(dbModule* parentModule,
dbModule* masterModule,
const char* name);

static void destroy(dbModInst* modinst);

static dbSet<dbModInst>::iterator destroy(dbSet<dbModInst>::iterator& itr);

char* getName() const;
// User Code End dbModInst
};

// Generator Code End 5

} // namespace odb
6 changes: 4 additions & 2 deletions include/opendb/dbObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ enum dbObjectType
dbRegionObj,
dbHierObj,
dbBPinObj,
//Generator Code Begin 1
//Generator Code End 1
// Generator Code Begin 1
dbModuleObj,
dbModInstObj,
// Generator Code End 1

// Lib Objects
dbLibObj,
Expand Down
2 changes: 1 addition & 1 deletion src/codeGenerator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This is an automatic code generation tool for OpenDB objects and Iterators. To test the tool you can use the following command

```bash
python3 gen.py --json schema.json --src_dir ../db --include_dir ../../include --impl impl
python3 gen.py --json schema-verilog.json --src_dir ../db --include_dir ../../include/opendb --impl impl
```

Where schema.json is the json file that includes the requirements, src is the source files directory, include is the include directory, and impl is the directory including the jinja templates for the classes.
13 changes: 7 additions & 6 deletions src/codeGenerator/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
inParentField['table'] = True
inParentField['dbSetGetter'] = True
inParentField['components'] = [inParentField['name']]
inParentField['flags'] = ["cmp","serial", "diff", "set", "get"]
inParentField['flags'] = ["cmp","serial", "diff", "no-set", "get"]

schema['classes'][parent]['fields'].append(inParentField)
schema['classes'][parent]['cpp_includes'].extend([
Expand Down Expand Up @@ -118,9 +118,10 @@
field['isHashTable'] = isHashTable(field['type'])
field['hashTableType'] = getHashTableType(field['type'])


# Check if a class is being used inside a template definition to add to the list of forward declared classes

####
#### This needs documentation
####
templateClassName = None
tmp = getTemplateType(field['type'])
while tmp is not None:
Expand All @@ -131,9 +132,9 @@
if templateClassName is not None:
if templateClassName not in klass['classes'] and klass['name'] != templateClassName[1:]:
klass['classes'].append(templateClassName)



####
####
####
if field.get('table', False):
if field['type'].startswith('db'):
field['functional_name'] = '{}s'.format(field['type'][2:])
Expand Down
8 changes: 4 additions & 4 deletions src/codeGenerator/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
'long',
'long long',
'long double',
'char*'
'char *',
'char*',
'char'
]

removable = [
Expand All @@ -39,7 +41,7 @@ def getStruct(name, structs):
return None

def components(structs, name, _type):
if(stem(_type) in comparable):
if(stem(_type) in comparable or isRef(_type)):
return [name]
idx = 0;
absType = _type.rstrip(' *')
Expand Down Expand Up @@ -124,8 +126,6 @@ def isTemplateType(type_name):
def getTemplateType(type_name):
if isTemplateType(type_name) == False:
return None


numBrackets = 1

openBracket = type_name.find("<")
Expand Down
8 changes: 4 additions & 4 deletions src/codeGenerator/impl/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class {{klass.name}} : public dbObject

{%endif%}
{%if 'no-get' not in field.flags%}
{{field.getterReturnType}} {{field.getterFunctionName}}() const;

{%endif%}
{%if field.dbSetGetter%}
dbSet<{{field.type}}> get{{field.functional_name}}() const;

{%else%}
{{field.getterReturnType}} {{field.getterFunctionName}}() const;
{%endif%}
{%endif%}

{%endfor%}


Expand Down
31 changes: 11 additions & 20 deletions src/codeGenerator/impl/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,40 +327,31 @@ namespace odb {
{%endif%}

{%if 'no-get' not in field.flags%}
{%if field.dbSetGetter%}
dbSet<{{field.type}}> {{klass.name}}::get{{field.functional_name}}() const
{
_{{klass.name}}* obj = (_{{klass.name}}*)this;
return dbSet<{{field.type}}>(obj, obj->{{field.name}});
}
{%else%}
{{field.getterReturnType}} {{klass.name}}::{{field.getterFunctionName}}({%if field.isHashTable%}const char* name{%endif%}) const
{
_{{klass.name}}* obj = (_{{klass.name}}*)this;

{%if field.isRef%}

_{{field.parent}} par = (_{{field.parent}}*) obj->getOwner();
if(obj->{{field.name}} == 0)
return NULL;
return ({{field.refType}}) par->_{{field.refType[2:-1].lower()}}_tbl->getPtr(obj->{{field.name}})


_{{field.parent}}* par = (_{{field.parent}}*) obj->getOwner();
return ({{field.refType}}) par->_{{field.refType[2:-1].lower()}}_tbl->getPtr(obj->{{field.name}});
{%elif field.isHashTable%}

return {{field.getterReturnType}} obj->{{field.name}}.find(name);


{%else%}


return obj->{{field.name}};


{%endif%}
}
{%endif%}

{%if field.dbSetGetter%}
dbSet<{{field.type}}> {{klass.name}}::get{{field.functional_name}}() const
{
_{{klass.name}}* obj = (_{{klass.name}}*)this;
return dbSet<{{field.type}}>(obj, obj->{{field.name}});
}
{%endif%}


{%endfor%}


Expand Down
3 changes: 3 additions & 0 deletions src/codeGenerator/impl/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ namespace odb {
class dbDiff;
class _dbDatabase;
{% for _class in klass.classes %}
{%if _class=="dbTable"%}
template <class T>
{%endif%}
class {{ _class }};
{% endfor %}
//User Code Begin Classes
Expand Down
Loading

0 comments on commit 5522baa

Please sign in to comment.