Commit efee240e by lvzhengyang

add odb and utl module

parent d089a629
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(ppPlace) project(ppPlace)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
...@@ -10,7 +10,7 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") ...@@ -10,7 +10,7 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
set(ENV{TYPE_CALL} library) set(ENV{TYPE_CALL} library)
file(GLOB_RECURSE SRC file(GLOB_RECURSE SRC
src/* src/*.cpp
) )
add_executable(ppPlace main.cpp ${SRC}) add_executable(ppPlace main.cpp ${SRC})
...@@ -20,4 +20,25 @@ target_include_directories(ppPlace PUBLIC ${CMAKE_SOURCE_DIR}/module/CImg) ...@@ -20,4 +20,25 @@ target_include_directories(ppPlace PUBLIC ${CMAKE_SOURCE_DIR}/module/CImg)
#target_link_libraries(ppPlace X11 pthread) #target_link_libraries(ppPlace X11 pthread)
target_link_libraries(ppPlace pthread) target_link_libraries(ppPlace pthread)
set(HOME ${PROJECT_SOURCE_DIR})
set(ODB_HOME ${PROJECT_SOURCE_DIR}/module/odb)
set(MINIEDA_HOME /workspace/S/lvzhengyang/MiniEDA)
set(CMAKE_INSTALL_PREFIX "${HOME}/install")
install(
TARGETS
ppPlace
DESTINATION
bin
)
include_directories(
${MINIEDA_HOME}/pkgs
${MINIEDA_HOME}/pkgs/include
)
add_subdirectory(module)
#cmake .. -G "MinGW Makefiles" #cmake .. -G "MinGW Makefiles"
# include cmake functions defined in the path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/src/cmake")
# ------------------------- Set Packages
# Doxygen
set(DOXYGEN_EXECUTABLE "${MINIEDA_HOME}/pkgs/bin/doxygen")
# TCL
set(TCL_LIBRARY "${MINIEDA_HOME}/pkgs/lib/libtcl8.6.so")
set(TCL_INCLUDE_PATH "${MINIEDA_HOME}/pkgs/include")
set(TCL_TCLSH "${MINIEDA_HOME}/pkgs/bin/tclsh8.6")
set(TK_LIBRARY "${MINIEDA_HOME}/pkgs/lib/libtk8.6.so")
set(TK_INCLUDE_PATH "${MINIEDA_HOME}/pkgs/include/tk.h")
set(TK_WISH "${MINIEDA_HOME}/pkgs/bin/wish8.6")
find_package(TCL)
# TCL Readline
set(TCL_LIB_PATHS "${MINIEDA_HOME}/pkgs/lib/")
set(TCL_READLINE_POSSIBLE_NAMES tclreadline-2.1.0
tclreadline-2.3.2 tclreadline-2.3.6 tclreadline-2.3.7 tclreadline-2.3.8
)
find_library(TCL_READLINE_LIBRARY
NAMES tclreadline ${TCL_READLINE_POSSIBLE_NAMES}
PATHS ${TCL_LIB_PATHS}
)
if (TCL_READLINE_LIBRARY)
message(STATUS "TCL readline library: ${TCL_READLINE_LIBRARY}")
endif()
find_path(TCL_READLINE_H tclreadline.h)
if (TCL_READLINE_H)
message(STATUS "TCL readline header: ${TCL_READLINE_H}")
endif()
# TCL X
option(BUILD_TCLX "Build with tclX included" ON)
if (BUILD_TCLX AND TCLX_LIBRARY)
message(STATUS "TclX library: ${TCLX_LIBRARY}")
endif()
if (BUILD_TCLX AND TCLX_H)
message(STATUS "TclX header: ${TCLX_H}")
endif()
# Boost
# set(Boost_INCLUDE_DIRS "${MINIEDA_HOME}/pkgs/boost_1_78_0")
# set(Boost_LIBRARIES "${MINIEDA_HOME}/pkgs/boost_1_78_0/stage/lib")
find_package(Boost REQUIRED)
message(STATUS "boost: ${Boost_VERSION}")
# Threads
find_package(Threads REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG on)
# Swig
set(SWIG_EXECUTABLE "${MINIEDA_HOME}/pkgs/bin/swig")
set(SWIG_DIR "${MINIEDA_HOME}/pkgs/share/swig/4.0.2")
find_package(SWIG 3.0 REQUIRED)
include(UseSWIG)
# Zlib
include(FindZLIB)
if (ZLIB_FOUND)
set(ZLIB 1)
else()
set(ZLIB 0)
endif()
# spdlog
find_package(spdlog REQUIRED)
message(STATUS "spdlog: ${spdlog_VERSION}")
option(ALLOW_WARNINGS "Flag to allow compilation with compiler warnings: on by default" ON)
if (NOT ALLOW_WARNINGS)
add_compile_options(
$<$<CXX_COMPILER_ID:GNU>:-Werror>
)
endif()
add_compile_options(
-Wall
-Wredundant-decls
-Wformat-security
-Wno-sign-compare
-Wp,-D_GLIBCXX_ASSERTIONS
$<$<CXX_COMPILER_ID:Clang>:-Wno-gnu-zero-variadic-macro-arguments>
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-gnu-zero-variadic-macro-arguments>
)
# OpenMP
FIND_PACKAGE( OpenMP REQUIRED )
if(OPENMP_FOUND)
message(STATUS "OpenMP: ${OpenMP_VERSION}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
############################################
add_subdirectory(utl)
add_subdirectory(odb)
# add_subdirectory(grt)
# add_subdirectory(python)
# add_subdirectory(tmp)
#! /bin/sh
# The next line is executed by /bin/sh, but not Tcl \
exec tclsh $0 ${1+"$@"}
# OpenSTA, Static Timing Analyzer
# Copyright (c) 2022, Parallax Software, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Usage: TclEncode encoded_filename var_name tcl_init_dir tcl_filename...
# Encode the contents of tcl_filenames into a C character array
# named var_name in the file encoded_filename.
# Each TCL file is encoded as a separate string of three digit decimal numbers
# that is unencoded and evaled on startup of the application.
# The init variable character array is terminated with a NULL pointer.
set encoded_filename [lindex $argv 0]
set init_var [lindex $argv 1]
set init_filenames [lrange $argv 2 end]
# Microcruft Visual C-- ridiculously short max string constant length.
set max_string_length 2000
set out_stream [open $encoded_filename w]
puts $out_stream "// TCL init file encoded by TclEncode.tcl"
puts $out_stream "namespace eda {"
puts $out_stream "const char *$init_var\[\] = {"
puts -nonewline $out_stream "\""
set encoded_length 0
binary scan "\n" c newline_enc
proc encode_line { line } {
global encoded_length max_string_length
global newline_enc out_stream
set length [string length $line]
set i 0
while { $i < $length } {
set ch [string index $line $i]
binary scan $ch c enc
puts -nonewline $out_stream [format "%03d" $enc]
incr i
incr encoded_length 3
if { $encoded_length > $max_string_length } {
puts $out_stream "\","
puts -nonewline $out_stream "\""
set encoded_length 0
}
}
puts -nonewline $out_stream [format "%03d" $newline_enc]
incr encoded_length 3
}
proc encode_file { filename } {
set in_stream [open $filename r]
while {![eof $in_stream]} {
gets $in_stream line
encode_line $line
}
close $in_stream
}
foreach filename $init_filenames {
encode_file $filename
}
puts $out_stream "\","
# NULL string to terminate char* array.
puts $out_stream "0"
puts $out_stream "};"
puts $out_stream "} // namespace"
close $out_stream
# Sets up swig for a .i file and encode .tcl files
# Arguments
# NAME <library>: the generated library name
# I_FILE <file>: the .i file input to swig
# NAMESPACE <name>: the namespace prefix in TCL
# SWIG_INCLUDES <dir>* : optional list of include dirs for swig
# SCRIPTS <file>* : tcl files to encode
#
# The intention is that this will create a library target with the
# generated code in it. Additional c++ source will be added to the
# target with target_sources() afterwards.
function(swig_lib)
# Parse args
set(options "")
set(oneValueArgs I_FILE NAME NAMESPACE LANGUAGE RUNTIME_HEADER)
set(multiValueArgs SWIG_INCLUDES SCRIPTS)
cmake_parse_arguments(
ARG # prefix on the parsed args
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
# Validate args
if (DEFINED ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown argument(s) to swig_lib: ${ARG_UNPARSED_ARGUMENTS}")
endif()
if (DEFINED ARG_KEYWORDS_MISSING_VALUES)
message(FATAL_ERROR "Missing value for argument(s) to swig_lib: ${ARG_KEYWORDS_MISSING_VALUES}")
endif()
foreach(arg I_FILE NAME NAMESPACE)
if (NOT DEFINED ARG_${arg})
message(FATAL_ERROR "${arg} argument must be provided to swig_lib")
endif()
endforeach()
# Default to tcl if unspecified
if (NOT DEFINED ARG_LANGUAGE)
set(ARG_LANGUAGE tcl)
endif()
set_source_files_properties(${ARG_I_FILE} PROPERTIES CPLUSPLUS ON)
if (DEFINED ARG_SWIG_INCLUDES)
set_property(SOURCE ${ARG_I_FILE}
PROPERTY INCLUDE_DIRECTORIES ${ARG_SWIG_INCLUDES})
endif()
if (${ARG_LANGUAGE} STREQUAL "tcl")
set(LANGUAGE_OPTIONS -namespace -prefix ${ARG_NAMESPACE})
endif()
# Setup swig of I_FILE.
set_property(SOURCE ${ARG_I_FILE}
PROPERTY COMPILE_OPTIONS ${LANGUAGE_OPTIONS}
-Werror
-w317,325,378,401,402,467,472,503,509)
set_property(SOURCE ${ARG_I_FILE}
PROPERTY SWIG_MODULE_NAME ${ARG_NAME})
set_property(SOURCE ${ARG_I_FILE}
PROPERTY USE_SWIG_DEPENDENCIES TRUE)
swig_add_library(${ARG_NAME}
LANGUAGE ${ARG_LANGUAGE}
TYPE STATIC
SOURCES ${ARG_I_FILE}
)
# Disable problematic compiler warnings on generated files.
# At this point the only the swig generated sources are present.
get_target_property(GEN_SRCS ${ARG_NAME} SOURCES)
foreach(GEN_SRC ${GEN_SRCS})
set_source_files_properties(${GEN_SRC}
PROPERTIES
COMPILE_OPTIONS "-Wno-cast-qual;-Wno-missing-braces"
)
endforeach()
# These includes are always needed.
target_include_directories(${ARG_NAME}
PRIVATE
${MINIEDA_HOME}/src/main/include
)
if (${ARG_LANGUAGE} STREQUAL tcl)
target_include_directories(${ARG_NAME}
PRIVATE
${TCL_INCLUDE_PATH}
)
elseif (${ARG_LANGUAGE} STREQUAL python)
target_include_directories(${ARG_NAME}
PRIVATE
${Python3_INCLUDE_DIRS}
)
swig_link_libraries(${ARG_NAME}
PUBLIC
Python3::Python
)
endif()
if (DEFINED ARG_RUNTIME_HEADER)
add_custom_command(
OUTPUT ${ARG_RUNTIME_HEADER}
COMMAND ${SWIG_EXECUTABLE} -${ARG_LANGUAGE} -external-runtime ${ARG_RUNTIME_HEADER}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target(${ARG_NAME}_RUNTIME_HEADER
DEPENDS ${ARG_RUNTIME_HEADER}
)
add_dependencies(${ARG_NAME}
${ARG_NAME}_RUNTIME_HEADER
)
target_include_directories(${ARG_NAME}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
)
endif()
# Generate the encoded of the script files.
if (DEFINED ARG_SCRIPTS)
set(LANG_INIT ${CMAKE_CURRENT_BINARY_DIR}/${ARG_NAME}-${ARG_LANGUAGE}InitVar.cc)
add_custom_command(OUTPUT ${LANG_INIT}
COMMAND ${MINIEDA_HOME}/src/cmake/etc/TclEncode.tcl ${LANG_INIT} ${ARG_NAME}_${ARG_LANGUAGE}_inits ${ARG_SCRIPTS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${ARG_SCRIPTS} ${MINIEDA_HOME}/src/cmake/etc/TclEncode.tcl
)
target_sources(${ARG_NAME}
PRIVATE
${LANG_INIT}
)
endif()
endfunction()
# python cache
__pycache__/
*.py[cod]
*~
core
*.core
TAGS
defRWarning.log
test/results
############################################################################
########################### Project Setup ##################################
############################################################################
# Setting CMake version properly to ensure correct policies behavior
cmake_minimum_required(VERSION 3.14...3.16)
# Setting up OpenDB project
project(odb VERSION 0.0.1
LANGUAGES CXX)
# Configure build version
configure_file (
"${PROJECT_SOURCE_DIR}/include/odb/version.hh.in"
"${PROJECT_BINARY_DIR}/include/odb/version.hh"
)
############################################################################
################################# Targets ##################################
############################################################################
add_subdirectory(src/db)
add_subdirectory(src/defin)
add_subdirectory(src/defout)
add_subdirectory(src/lef)
add_subdirectory(src/lefin)
add_subdirectory(src/lefout)
add_subdirectory(src/def)
add_subdirectory(src/zutil)
add_subdirectory(src/tm)
add_subdirectory(src/cdl)
# add_subdirectory(src/upf)
add_subdirectory(test/cpp)
add_library(odb INTERFACE)
target_link_libraries(odb
INTERFACE
db
cdl
defin
defout
lefin
lefout
tm
zutil
utl
# ${TCL_LIBRARY}
)
############################################################################
################################# SWIG #####################################
############################################################################
# include(${SWIG_USE_FILE})
# add_subdirectory(src/swig/common)
# # if (Python3_FOUND AND BUILD_PYTHON)
# # add_subdirectory(src/swig/python)
# # endif()
# add_subdirectory(src/swig/tcl)
############################################################################
############################### DOXYGEN ####################################
############################################################################
find_package(Doxygen)
if (DOXYGEN_FOUND)
set(DOXYGEN_EXTRACT_STATIC YES)
set(DOXYGEN_REFERENCED_BY_RELATION YES)
set(DOXYGEN_REFERENCES_RELATION YES)
doxygen_add_docs(docs include)
endif()
FROM centos:centos7 AS base-dependencies
LABEL maintainer="Abdelrahman Hosny <abdelrahman_hosny@brown.edu>"
# Install dev and runtime dependencies
RUN yum group install -y "Development Tools" \
&& yum install -y https://repo.ius.io/ius-release-el7.rpm \
&& yum install -y centos-release-scl \
&& yum install -y wget devtoolset-8 \
devtoolset-8-libatomic-devel tcl-devel tcl tk libstdc++ tk-devel pcre-devel \
python36u python36u-libs python36u-devel python36u-pip && \
yum clean -y all && \
rm -rf /var/lib/apt/lists/*
ENV CC=/opt/rh/devtoolset-8/root/usr/bin/gcc \
CPP=/opt/rh/devtoolset-8/root/usr/bin/cpp \
CXX=/opt/rh/devtoolset-8/root/usr/bin/g++ \
PATH=/opt/rh/devtoolset-8/root/usr/bin:$PATH \
LD_LIBRARY_PATH=/opt/rh/devtoolset-8/root/usr/lib64:/opt/rh/devtoolset-8/root/usr/lib:/opt/rh/devtoolset-8/root/usr/lib64/dyninst:/opt/rh/devtoolset-8/root/usr/lib/dyninst:/opt/rh/devtoolset-8/root/usr/lib64:/opt/rh/devtoolset-8/root/usr/lib:$LD_LIBRARY_PATH
# Install CMake
RUN wget https://cmake.org/files/v3.14/cmake-3.14.0-Linux-x86_64.sh && \
chmod +x cmake-3.14.0-Linux-x86_64.sh && \
./cmake-3.14.0-Linux-x86_64.sh --skip-license --prefix=/usr/local && rm -rf cmake-3.14.0-Linux-x86_64.sh \
&& yum clean -y all
# Install epel repo
RUN wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && \
yum install -y epel-release-latest-7.noarch.rpm && rm -rf epel-release-latest-7.noarch.rpm \
&& yum clean -y all
# Install any git version > 2.6.5
RUN yum remove -y git* && yum install -y git224
# Install SWIG
RUN yum remove -y swig \
&& wget https://github.com/swig/swig/archive/rel-4.0.1.tar.gz \
&& tar xfz rel-4.0.1.tar.gz \
&& rm -rf rel-4.0.1.tar.gz \
&& cd swig-rel-4.0.1 \
&& ./autogen.sh && ./configure --prefix=/usr && make -j $(nproc) && make install \
&& cd .. \
&& rm -rf swig-rel-4.0.1
# boost
RUN wget https://sourceforge.net/projects/boost/files/boost/1.72.0/boost_1_72_0.tar.bz2/download && \
tar -xf download && \
cd boost_1_72_0 && \
./bootstrap.sh && \
./b2 install --with-iostreams --with-test -j $(nproc)
RUN pip3 install testtools
# spdlog for logging
RUN git clone -b v1.8.1 https://github.com/gabime/spdlog.git \
&& cd spdlog \
&& mkdir build \
&& cd build \
&& cmake .. \
&& make install -j
FROM base-dependencies AS builder
COPY . /OpenDB
WORKDIR /OpenDB
# Build
RUN mkdir build
RUN cd build && cmake .. && make -j 4
BSD 3-Clause License
Copyright (c) 2019, Nefelus Inc
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# OpenDB
OpenDB is a design database to support tools for physical chip design. It
was originally developed by Athena Design Systems. Nefelus, Inc. acquired
the rights to the code and open-sourced it with BSD-3 license in 2019 to support the DARPA
OpenROAD project.
The structure of OpenDB is based on the text file formats LEF
(library) and DEF (design) formats version 5.6. OpenDB supports a
binary file format to save and load the design much faster than using
LEF and DEF.
OpenDB is written in C++ 98 with standard library style iterators.
The classes are designed to be fast enough to base an application on without
having to copy them into application-specific structures.
## Directory structure
```
include/odb/db.h - public header for all database classes
src/db - private/internal database representations
src/lefin - LEF reader
src/lefout - LEF writer
src/defin - DEF reader
src/defout - DEF writer
```
## Database API
We are still working on documenting the APIs. We have over 1,800 objects
and functions that we are still documenting (for both TCL and Python).
**Contributions are very welcome in this effort**. Find starting points below.
### TCL
After building successfully, run OpenDB Tcl shell using
`../../build/src/odb/src/swig/tcl/odbtcl`. An example usage:
```
set db [dbDatabase_create]
set lef_parser [new_lefin $db true]
set tech [lefin_createTech $lef_parser ./src/odb/test/data/gscl45nm.lef]
```
You can find examples on using the API from Tcl under `test/tcl/` directory.
The full set of the Tcl commands exposed can be found under
`./build/src/swig/tcl/opendb_wrapper.cpp`. Search for `SWIG_prefix`.
### Python
After building successfully, run `openroad -python` to enable the Python
interpreter. You can find examples on using the API from Python under
`test/python/` directory.
To list the full set of the Python classes exposed run `openroad -python`
then:
```
import openroad
import odb
print(', '.join(dir(openroad)))
print(', '.join(dir(odb)))
```
### C++
All public database classes are defined in `db.h`. These class definitions
provide all functions for examining and modifying the database objects. The
database is an object itself, so multiple database objects can exist
simultaneously (no global state).
`dbTypes.h` defines types returned by database class member functions.
All database objects are in the `odb` namespace.
- `dbChip`
- `dbBlock`
- `dbTech`
- `dbLib`
All database objects have a 32bit object identifier accessed with the
`dbObject::getOID` base class member function that returns a `uint`. This
identifier is preserved across save/restores of the database so it should
be used to reference database object by data structures instead of pointers
if the reference lifetime is across database save/restores. OIDs allow the
database to have exactly the same layout across save/restores.
The database distance units are **nanometers** and use the type `uint`.
## Example scripts
## Regression tests
There are a set of regression tests in /test.
```
./test/regression-tcl.sh
./test/regression-py.sh
```
## Database Internals
The internal description included here is paraphrased from Lukas van Ginneken
by James Cherry.
The database separates the implementation from the interface, and as a result,
each class becomes two classes, a public one and a private one. For instance,
`dbInst` has the public API functions, while class `_dbInst` has the private
data fields.
The objects are allocated in dynamically resizable tables, the implementation
of which is in `dbTable.hpp`. Each table consists of a number of pages,
each containing 128 objects. The table contains the body of the `struct`,
not a set of pointers. This eliminates most of the pointer overhead while
iteration is accomplished by stepping through the table. Thus, grouping these
objects does not require a doubly-linked list and saves 16 bytes per object
(at the cost of some table overhead). Each object has an id, which is the
index into the table. The lowest 7 bits are the index in the page, while
the higher bits are the page number. Object id's are persistent when saving
and reading the data model to disk, even as pointer addresses may change.
Everything in the data model can be stored on disk and restored from disk
exactly the way it was. An extensive set of equality tests and diff functions
make it possible to check for even the smallest deviation. The capability
to save an exact copy of the state of the system makes it possible to create
a checkpoint. This is a necessary capability for debugging complex systems.
The code follows the definition of LEF and DEF closely and reflects many of
the idiosyncrasies of LEF and DEF. The code defines many types of objects
to reflect LEF and DEF constructs although it sometimes uses different
terminology, for instance, the object to represent a library cell is called
`dbMaster` while the LEF keyword is MACRO.
The data model supports the EEQ and LEQ keywords (i.e., electrically equivalent
and logically equivalent Masters), which could be useful for sizing. However,
it does not support any logic function representation. In general, there is
very limited support for synthesis-specific information: no way to represent
busses, no way to represent logic function, very limited understanding of
signal flow, limited support of timing information, and no support for high
level synthesis or test insertion.
The db represents routing as in DEF, representing a trace from point to point
with a given width. The layout for a net is stored in a class named `dbWire`
and it requires a special `dbWireDecoder` (which works like an iterator)
to unpack the data and another `dbWireEncoder` to pack it. The data model
does not support a region query and objects that are in the same layer are
scattered about the data model and are of different classes.
This means that whatever tool is using the layout information will have to
build its own data structures that are suitable to the layout operations
of that tool. For instance, the router, the extractor, and the DRC engine
would each have to build their unique data structures. This encourages
batch mode operation (route the whole chip, extract the whole chip, run
DRC on the whole chip).
## Limitations
## FAQs
Check out
[GitHub discussion](https://github.com/The-OpenROAD-Project/OpenROAD/discussions/categories/q-a?discussions_q=category%3AQ%26A+fastroute+in%3Atitle)
about this tool.
## LICENSE
BSD 3-Clause License. See [LICENSE](LICENSE) file.
# Adding new fields in DB Object
For example `add_pitchDiag` in object `DbTechLayer`.
| | Action | File | Source Code |
|---|--------------------------------------------------------|-------------------|------------------------------------------------------------------------------------|
| 1 | Add Fields at the .h file | `dbTechLayer.h` | |
| 2 | Define a keyword for db rev number | `dbDatabase.h` | `#define ADS_DB_DF58 52` |
| 3 | Set the current rev number same as | `dbDatabase.h` | `#define ADS_DB_SCHEMA_MINOR 52` |
| 4 | Stream in new fields Conditionally upon Schema number | `dbTechLayer.cpp` | `if ( stream.getDatabase()->isSchema(ADS_DB_DF58) ) { stream >> layer._pitchDiag;` |
| 5 | Stream out new fields Conditionally upon Schema number | `dbTechLayer.cpp` | `if ( stream.getDatabase()->isSchema(ADS_DB_DF58) ) { stream << layer._pitchDiag;` |
| 6 | Conditionally Diff new fields | `dbTechLayer.cpp` | `if ( stream.getDatabase()->isSchema(ADS_DB_DF58) ) { DIFF_FIELD(_pitchDiag);` |
| 7 | Conditionally Diff Out new fields | `dbTechLayer.cpp` | `if ( stream.getDatabase()->isSchema(ADS_DB_DF58) ) { DIFF_OUT_FIELD(_pitchDiag);` |
| 8 | Created access APIs to the fields | `dbTechLayer.cpp` | `"dbTechLayer::getPitchDiag(), dbTechLayer::setPitchDiag( int pitch )"` |
| 9 | Add new APIs in include/db.h | db.h | `class dbTechLayer` |
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "IZdcr.h"
#include "ZInterface.h"
#include "ZObject.h"
#include "array1.h"
#include "geom.h"
#include "gseq.h"
#include "odb.h"
#include "util.h"
#include "rcx.h"
namespace odb {
class Ath__gridTable;
class dbBox;
class dbBlock;
class dbTech;
class dbNet;
///
/// ISdb - Internal User Interface for ZRoute Area Search Infrastructure
///
///
class ISdb : public ZObject
{
public:
ZINTERFACE_ID(ISdb);
virtual void removeMarkedNetWires() = 0;
virtual void reMakeSdb(dbTech* tech, dbBlock* block) = 0;
virtual void cleanSdb() = 0;
virtual void dumpTrackCounts(FILE* fp) = 0;
virtual void setExtControl(dbBlock* block,
bool useDbSdb,
uint adj,
uint npsrc,
uint nptgt,
uint ccUp,
bool allNet,
uint contextDepth,
Ath__array1D<int>** contextArray,
uint* contextLength,
Ath__array1D<SEQ*>*** dgContextArray,
uint* dgContextDepth,
uint* dgContextPlanes,
uint* dgContextTracks,
uint* dgContextBaseLvl,
int* dgContextLowLvl,
int* dgContextHiLvl,
uint* dgContextBaseTrack,
int* dgContextLowTrack,
int* dgContextHiTrack,
int** dgContextTrackBase,
AthPool<SEQ>* seqPool)
= 0;
virtual void adjustOverlapMakerEnd() = 0;
virtual void adjustMetalFill() = 0;
virtual void setupForBoxes(Rect maxRect, uint minHeight, uint minWidth) = 0;
virtual void addBox(dbBox* bb, uint wtype, uint id) = 0;
virtual uint setExtrusionMarker(uint startRow, uint startCol) = 0;
virtual Ath__gridTable* getSearchPtr() = 0;
virtual void setDefaultWireType(uint v) = 0;
virtual uint addBox(int x1,
int y1,
int x2,
int y2,
uint level,
uint id1,
uint id2,
uint wtype)
= 0;
virtual void getBox(uint wid,
int* x1,
int* y1,
int* x2,
int* y2,
uint* level,
uint* id1,
uint* id2,
uint* wtype)
= 0;
virtual uint addBlockages(dbBlock* block) = 0;
virtual void initSearchForNets(dbTech* tech, dbBlock* block) = 0;
virtual uint addNetSBoxes(dbNet* net, uint wtype, bool skipVias) = 0;
virtual void addPowerNets(dbBlock* block, uint wtype, bool skipVias) = 0;
virtual void addSignalNets(dbBlock* block, uint wtype, uint vtype) = 0;
virtual void addSignalNets(dbBlock* block, uint wtype, bool wireVia) = 0;
virtual void searchWireIds(int x1,
int y1,
int x2,
int y2,
bool ignoreLayers,
bool* exludeTable)
= 0;
virtual void searchBoxIds(int x1, int y1, int x2, int y2) = 0;
virtual void setMaxArea(int x1, int y1, int x2, int y2) = 0;
virtual void resetMaxArea() = 0;
virtual uint couplingCaps(ZPtr<ISdb> ccSdb,
uint couplingDist,
ZInterface* Interface,
rcx::CoupleAndCompute coupleAndCompute,
void* compPtr)
= 0;
virtual uint startIterator() = 0;
virtual uint getNextWireId() = 0;
virtual bool getNextBox(int& x1,
int& y1,
int& x2,
int& y2,
uint& level,
uint& netId,
uint& shapeId)
= 0;
virtual void getCCdist(uint wid,
uint* width,
uint* level,
uint* id1,
uint* id2)
= 0;
virtual void getIds(uint wid, uint* id1, uint* id2, uint* wtype) = 0;
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "ZObject.h"
#include "geom.h"
#include "odb.h"
namespace odb {
///
/// IZdcr
///
///
class IZdcr : public ZObject
{
public:
ZINTERFACE_ID(IZdcr);
virtual uint getAppGuiCnt() = 0;
virtual void chip_get(const char* chip,
bool gridFlag,
int maxobjects,
FILE* outFP)
= 0;
virtual void chipAttr(char* layers, uint n, bool def) = 0;
virtual void init(ZContext& context,
bool dbEnv,
const char* name,
const char* module,
bool noStore)
= 0;
virtual char* setName(const char* name) = 0;
virtual char* getName() = 0;
// virtual Ath__zui *getZui()=0;
virtual void setBlockId(uint v) = 0;
virtual uint getBlockId() = 0;
virtual bool isBlockSelected(uint bid) = 0;
virtual char* getInspectName() = 0;
virtual uint addSubMenu(uint menuId, const char* name, uint boxId) = 0;
virtual uint getMenuId(const char* name) = 0;
virtual uint initDbMenus() = 0;
virtual uint setupModuleMenu(const char* moduleName,
const char* onechar,
uint id)
= 0;
virtual void getChipAttr(char* bbox,
char* layers,
char* menus,
char* blocks,
char* defTypes)
= 0;
virtual uint getMenuNames(char* buff) = 0;
virtual void writeToTcl(uint lineLimit, FILE* fp, bool w2l) = 0;
virtual uint setInspectEnv(const char* action,
const char* objectName,
const char* bb,
const char* selectType,
bool noclip)
= 0;
virtual void setFilters(const char* chip,
const char* layer,
const char* type,
const char* hier)
= 0;
virtual bool getPullDownMenu(const char* objectName) = 0;
virtual uint getSubmenuObjId(uint* id2) = 0;
virtual uint getPullDownActionId() = 0;
virtual bool msgAction() = 0;
virtual bool selectAction() = 0;
virtual bool isSelectedMenu(const char* name) = 0;
virtual uint getSelectIds(uint* id1, uint* id2, uint* id3) = 0;
virtual bool isSubmenuType(uint id) = 0;
virtual char* getMsgBuffer(bool setBuffFlag) = 0;
virtual void print_self(char* blk, char* name, char* extra) = 0;
virtual void wireMsg(int x1,
int y1,
int x2,
int y2,
uint level,
char* msg_buf)
= 0;
virtual void getBbox(int* x1, int* y1, int* x2, int* y2) = 0;
virtual char* getFirstTclBox(int* x1, int* y1, int* x2, int* y2, uint* layer)
= 0;
virtual void resetSearchParams(char* chip,
const char* bb,
const char* layer,
const char* hier,
const char* type,
bool noclip,
bool q)
= 0;
virtual int getCoords(const char* bb, int* x1, int* y1, int* x2, int* y2) = 0;
virtual uint addBox(uint id,
uint subMenuId,
uint menuId,
int layer,
int x1,
int y1,
int x2,
int y2,
uint ownId,
const char* boxType = NULL)
= 0;
virtual uint addArrow(bool right,
uint boxType,
uint hier,
int layer,
int labelCnt,
char** label,
double* val,
int x1,
int y1,
int x2,
int y2,
uint boxFilter)
= 0;
virtual uint addBoxAndMsg(uint id,
uint subMenuId,
uint menuId,
int layer,
int x1,
int y1,
int x2,
int y2,
uint ownId,
const char* special)
= 0;
virtual bool* getExcludeLayerTable() = 0;
virtual bool getSubMenuFlag(uint menuId, uint subMenuId) = 0;
virtual uint addPullDownMenu(uint menuId,
uint subMenuId,
const char* db_name,
const char* zui_action)
= 0;
virtual uint addPullDownMenu(const char* menu,
const char* subMenu,
const char* db_name,
const char* zui_action)
= 0;
virtual bool validSearchBbox() = 0;
virtual void setSearchBox(int x1, int y1, int x2, int y2) = 0;
virtual bool clipBox(int& x1, int& y1, int& x2, int& y2) = 0;
virtual bool invalidateSearchBox() = 0;
virtual bool isInspectMenu(uint menuId) = 0;
virtual bool isInspectSubMenu(uint subMenuId) = 0;
virtual bool isInspectSubMenu(uint menuId, uint subMenuId) = 0;
virtual void setContextMarker() = 0;
virtual void setSignalMarker() = 0;
virtual void setInstMarker() = 0;
virtual void resetMarker() = 0;
virtual void* getDpt() = 0;
virtual uint writeToDpt() = 0;
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "odb.h"
///
/// ZINTERFACE - Declare the interface identifier; add to adsInterfaces enum
/// in ZComponents.h
///
#define ZINTERFACE(INTERFACE) ZIID_##INTERFACE
///
/// ZCOMPONENT - Declare the component identifier; add to adsComponents enum
/// in ZComponents.h
///
#define ZCOMPONENT(COMPONENT) ZCID_##COMPONENT
namespace odb {
enum ZComponentID
{
ZCOMPONENT(Sdb),
ZCOMPONENT(Zdcr),
};
enum ZInterfaceID
{
ZIID_ZObject = 0,
// Place all entries after this line
ZINTERFACE(ISdb),
ZINTERFACE(IZdcr),
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <stdarg.h>
#include <stdexcept>
#include "odb.h"
#ifdef __GNUC__
#define ADS_FORMAT_PRINTF(F, A) __attribute__((format(printf, F, A)))
#else
#define ADS_FORMAT_PRINTF(F, A)
#endif
namespace odb {
inline
std::runtime_error ZException(const char* fmt, ...) // ADS_FORMAT_PRINTF(2, 3)
{
char buffer[8192];
va_list args;
va_start(args, fmt);
vsnprintf(buffer, 8192, fmt, args);
va_end(args);
return std::runtime_error(buffer);
}
// See http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert
// Avoids unused variable warnings.
#ifdef NDEBUG
#define ZASSERT(x) \
do { \
(void) sizeof(x); \
} while (0)
#else
#define ZASSERT(x) assert(x)
#endif
#define ZALLOCATED(expr) \
do { \
if ((expr) == NULL) \
throw std::runtime_error("Out of memory"); \
} while (0);
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "ZObject.h"
#include "odb.h"
namespace odb {
class ZContext;
class ZObject;
class ZFactory;
///
/// ZFactory - Class factory interface
///
class ZFactory
{
public:
//
// Return values:
// Z_OK - Object created
// Z_ERROR_NO_INTERFACE - Object not created because it does not
// support the specified interface.
//
virtual int create(const ZContext& context, ZInterfaceID iid, void** p) = 0;
};
///
/// ZFactoryImpl - A singleton class which creates instances of the
/// implementation class.
///
template <class IMPL, class INFC>
class ZFactoryImpl : public ZFactory
{
public:
int create(const ZContext& context, ZInterfaceID iid, void** p)
{
IMPL* o = new IMPL;
o->_context = context;
if (o->QueryInterface(iid, p) == Z_OK)
return Z_OK;
delete o;
*p = NULL;
return Z_ERROR_NO_INTERFACE;
}
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <vector>
#ifndef _TCL
#include <tcl.h>
#endif
#include "ZException.h"
#include "geom.h"
#include "odb.h"
namespace odb {
class dbDatabase;
class ZSession;
class ZObject;
class dbObject;
/////////////////////////////////
/// Event value types
/////////////////////////////////
enum ZValueType
{
Z_CHAR,
Z_UCHAR,
Z_SHORT,
Z_USHORT,
Z_INT,
Z_UINT,
Z_FLOAT,
Z_DOUBLE,
Z_STRING,
Z_BOOL,
Z_ZOBJECT,
Z_DBOBJECT
};
/////////////////////////////////////////////////////
/// ZContext - Context the software is running in.
/////////////////////////////////////////////////////
class ZContext
{
public:
Tcl_Interp* _interp;
ZSession* _session;
};
//////////////////////////////////////////////
/// Interface to zroute software architecture
//////////////////////////////////////////////
class ZInterface
{
public:
ZInterface();
virtual ~ZInterface();
//
// Post an event. This method specifies the event as a series of attribute
// value pairs. There must be a at least one attribute value pair. Furthermore
// the series of attribute value pairs must be terminated with a zero. For
// examples:
// int x, y;
// ...
// z->event("foo", "x", Z_INT, x, "y", Z_INT, y, 0 );
//
// Throws ZException
int event(const char* name, const char* attr1, int type, ...);
//
// Post an event. This method specifies the event as a series of attribute
// value pairs. There must be a at least one attribute value pair. Furthermore
// the series of attribute value pairs must be terminated with a zero. For
// examples:
// int x, y;
// ...
// z->event("foo", "x", "10", "y", "11", 0 );
// Throws ZException
int event(const char* name, const char* attr1, const char* val, ...);
// idle event
int idle(int level);
// ade event
int ade(int code, const char* fmt, ...) ADS_FORMAT_PRINTF(3, 4);
// milos event
int milos(int code, const char* fmt, ...) ADS_FORMAT_PRINTF(3, 4);
// warning message
int warning(int code, const char* fmt, ...) ADS_FORMAT_PRINTF(3, 4);
// informational message
int info(int code, const char* fmt, ...) ADS_FORMAT_PRINTF(3, 4);
// informational message
int notice(int code, const char* fmt, ...) ADS_FORMAT_PRINTF(3, 4);
// verbose/debugging message
int verbose(int code, const char* fmt, ...) ADS_FORMAT_PRINTF(3, 4);
// debug message
// void debug(const char *mod, const char *tag, const char * fmt, ... )
// ADS_FORMAT_PRINTF(4,5);
// error, Throws a ZException
void error(int code, const char* fmt, ...) ADS_FORMAT_PRINTF(3, 4);
// Get the name of this module
virtual const char* getModuleName() { return ""; }
public:
ZContext _context;
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <string.h>
#include <map>
#include <vector>
#include "odb.h"
namespace odb {
class ZObject;
class dbDatabase;
class dbObject;
////////////////////////////////////
/// ZNamespace
////////////////////////////////////
class ZNamespace
{
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
class ZEntry;
class dbEntry;
std::map<ZObject*, ZEntry*> _zobj_entries;
std::map<dbDatabase*, dbEntry*> _db_entries;
std::map<const char*, ZEntry*, ltstr> _zobj_names;
std::map<const char*, dbEntry*, ltstr> _db_names;
uint _unique_id;
public:
ZNamespace();
~ZNamespace();
// These functions may throw a ZException
const char* addZObject(ZObject* obj);
void removeZObject(ZObject* obj);
ZObject* resolveZObject(const char* zname);
void registerDb(dbDatabase* db);
void unregisterDb(dbDatabase* db);
dbObject* resolveDB(const char* dbname);
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "ZComponents.h"
#include "ZException.h"
#include "odb.h"
///
/// This file contains an implmentation of a component based software
/// architecture. This implementation is strictly for C++ interfaces. There is
/// no support for external language bindings. And there is no support for
/// multiple interfaces (QueryInterface: one interface is supported per
/// implementation).
///
namespace odb {
template <class T>
class ZPtr;
class ZContext;
class ZObject;
#define Z_SUCCEEDED(r) (r == Z_OK)
#define Z_FAILED(r) (r != Z_OK)
#define Z_OK 0
#define Z_ERROR_NO_INTERFACE 1
#define Z_ERROR_OUT_OF_MEMORY 2
#define Z_ERROR_NO_COMPONENT 3
///
/// ZINTERFACE_ID -
/// Associate the interface identifier this the interface. This macro
/// should be added to the public section of the interface class.
///
#define ZINTERFACE_ID(INTERFACE) \
enum \
{ \
ZIID = ZIID_##INTERFACE \
}
///
/// ZCID - Returns the component interface identifier. You must include
/// ZComponents.h to use this macro.
///
#define ZCID(COMPONENT) (ZCID_##COMPONENT)
///
/// ZIID - Returns the component interface identifier. You must include
/// ZComponents.h to use this macro.
///
#define ZIID(INTERFACE) (ZIID_##INTERFACE)
///
/// adsCreateComponent - Create a new instance of this compomnent, return a
/// pointer to the specified interface.
///
/// Returns: Z_OK, Z_ERROR_NO_COMPONENT, Z_ERROR_NO_INTERFACE
///
/// result is set to the interface pointer on success, otherwise it is set to
/// NULL.
///
int adsCreateComponent(const ZContext& context,
ZComponentID cid,
ZInterfaceID iid,
void** result);
///
/// adsNewComponent - Creates a component specified by the component-identifier.
/// The ZPtr is assigned the specified interface of this component. A run-time
/// error will occur if this component does not support the specified interface.
///
template <class INTERFACE>
inline int adsNewComponent(const ZContext& context,
ZComponentID cid,
ZPtr<INTERFACE>& ptr)
{
INTERFACE* p;
ZInterfaceID iid = (ZInterfaceID) INTERFACE::ZIID;
int r = adsCreateComponent(context, cid, iid, (void**) &p);
ptr = (INTERFACE*) p;
if (r == Z_OK)
p->Release();
return r;
}
///
/// ZObject - Base class of all interfaces.
///
class ZObject
{
public:
typedef ZObject _zobject_traits;
enum
{
ZIID = 0
};
ZObject();
virtual ~ZObject();
virtual uint AddRef() = 0;
virtual uint Release() = 0;
virtual int QueryInterface(ZInterfaceID iid, void** ref) = 0;
};
///
/// ZPtr - Smart pointer class to access methods of interface.
///
template <class T>
class ZPtr
{
T* _p;
void setPtr(T* p)
{
if (_p)
_p->Release();
_p = p;
}
T& operator*(); // Do not allow derefencing.
public:
ZPtr() { _p = NULL; }
ZPtr(ZObject* p)
{
if (p == NULL)
_p = NULL;
else {
void* v;
int r = p->QueryInterface((ZInterfaceID) T::ZIID, &v);
if (r != Z_OK) {
assert(r == Z_OK); // throw the assert in debug mode
throw ZException("ZPtr: Invalid interface assignment");
}
_p = (T*) v;
}
}
ZPtr(const ZPtr<T>& p)
{
_p = p._p;
if (_p)
_p->AddRef();
}
~ZPtr()
{
if (_p)
_p->Release();
}
ZPtr<T>& operator=(ZObject* p)
{
if (p == NULL)
setPtr(NULL);
else {
void* v;
int r = p->QueryInterface((ZInterfaceID) T::ZIID, &v);
if (r != Z_OK) {
assert(r == Z_OK); // throw the assert in debug mode
throw ZException("ZPtr: Invalid interface assignment");
}
setPtr((T*) v);
}
return *this;
}
ZPtr<T>& operator=(ZPtr<T>& p)
{
if (this != &p) {
setPtr(p._p);
if (_p)
_p->AddRef();
}
return *this;
}
bool operator==(const ZPtr<T>& p) const { return _p == p._p; }
bool operator!=(const ZPtr<T>& p) const { return _p != p._p; }
bool operator==(const T* p) const { return _p == p; }
bool operator!=(const T* p) const { return _p != p; }
// pointer operator
T* operator->() { return _p; }
// get the pointer
T* getPtr() { return _p; }
// cast operator to a ZObject
operator ZObject*() const { return (ZObject*) _p; }
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "ZInterface.h"
namespace odb {
class ZNamespace;
class ZSession : public ZInterface
{
public:
ZNamespace* _ns;
dbDatabase* _db;
ZSession();
~ZSession();
friend class ZInterface;
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
namespace odb {
template <class T>
class Ath__array1D
{
private:
T* _array;
int _size;
int _chunk;
int _current;
int _iterCnt;
public:
Ath__array1D(int chunk = 0)
{
_chunk = chunk;
if (_chunk <= 0)
_chunk = 1024;
_current = 0;
if (chunk > 0) {
_size = _chunk;
_array = (T*) realloc(NULL, _size * sizeof(T));
} else {
_size = 0;
_array = NULL;
}
_iterCnt = 0;
}
~Ath__array1D()
{
if (_array != NULL)
::free(_array);
}
int add(T t)
{
if (_current >= _size) {
_size += _chunk;
_array = (T*) realloc(_array, _size * sizeof(T));
}
int n = _current;
_array[_current++] = t;
return n;
}
int reSize(int maxSize)
{
if (maxSize < _size)
return _size;
_size = (maxSize / _chunk + 1) * _chunk;
_array = (T*) realloc(_array, _size * sizeof(T));
if (_array == NULL) {
fprintf(stderr, "Cannot allocate array of size %d\n", _size);
assert(0);
}
return _size;
}
T* getTable() { return _array; }
T& get(int i)
{
assert((i >= 0) && (i < _current));
return _array[i];
}
T& geti(int i)
{
if (i >= _size)
reSize(i + 1);
return _array[i];
}
T& getLast()
{
assert(_current - 1 >= 0);
return _array[_current - 1];
}
void clear(T t)
{
for (int ii = 0; ii < _size; ii++)
_array[ii] = t;
}
int findIndex(T t)
{
for (int ii = 0; ii < _current; ii++) {
if (_array[ii] == t) {
return ii;
}
}
return -1;
}
int findNextBiggestIndex(T t, int start = 0)
{
for (int ii = start; ii < _current; ii++) {
if (t == _array[ii])
return ii;
if (t < _array[ii])
return ii > 0 ? ii - 1 : 0;
}
return _current;
}
bool notEmpty()
{
if (_current > 0)
return true;
else
return false;
}
bool getNext(T& a)
{
if (_iterCnt < _current) {
a = _array[_iterCnt++];
return true;
} else
return false;
}
T& pop()
{
assert(_current > 0);
_current--;
return _array[_current];
}
unsigned int getSize(void) { return _size; }
void resetIterator(unsigned int v = 0) { _iterCnt = v; }
void resetCnt(unsigned int v = 0)
{
_current = v;
_iterCnt = v;
}
unsigned int getCnt(void) { return _current; }
void set(int ii, T t)
{
if (ii >= _size)
reSize(ii + 1);
_array[ii] = t;
}
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "name.h"
#include "parse.h"
#include "util.h"
namespace odb {
template <class T>
class Ath__array2d
{
private:
AthArray<T>** _array;
unsigned int _bankCnt;
uint _tmpBank;
uint _tmpCnt;
uint _current;
bool _doIteratorAll;
public:
Ath__array2d(
unsigned int bCnt) // for bCnt small and each bank= 10000 max, for quad
{
_bankCnt = 4;
if (bCnt > 0)
_bankCnt = bCnt;
_array = new AthArray<T>*[_bankCnt];
assert(_array);
unsigned int ii;
for (ii = 0; ii < bCnt; ii++) {
_array[ii] = new AthArray<T>(128);
assert(_array[ii]);
}
resetIteratorFlags();
}
void resetIteratorFlags()
{
_tmpBank = 0;
_tmpCnt = 0;
_current = 0;
_doIteratorAll = false;
}
Ath__array2d(int bCnt, bool) // for max 1024 and 128, for quad
{
_bankCnt = 32;
if (bCnt > 0)
_bankCnt = bCnt;
_array = new AthArray<T>*[_bankCnt];
assert(_array);
_array[0] = new AthArray<T>(3);
assert(_array[0]);
unsigned int halfCnt = _bankCnt / 2 + 1;
unsigned int ii;
for (ii = 1; ii < halfCnt; ii++) {
_array[ii] = new AthArray<T>(64);
assert(_array[ii]);
}
for (ii = halfCnt; ii < _bankCnt; ii++) {
_array[ii] = new AthArray<T>(4);
assert(_array[ii]);
}
resetIteratorFlags();
}
Ath__array2d(int bCnt, uint quarterSize1, uint quarterSize2, uint halfSize2)
{
_bankCnt = 32;
if (bCnt > 0)
_bankCnt = bCnt;
_array = new AthArray<T>*[_bankCnt];
assert(_array);
_array[0] = new AthArray<T>(4);
assert(_array[0]);
unsigned int halfCnt = _bankCnt / 2 + 1;
unsigned int quarterCnt = halfCnt / 2 + 1;
unsigned int ii;
for (ii = 1; ii < quarterCnt; ii++) {
_array[ii] = new AthArray<T>(quarterSize1);
assert(_array[ii]);
}
for (ii = quarterCnt; ii < halfCnt; ii++) {
_array[ii] = new AthArray<T>(quarterSize2);
assert(_array[ii]);
}
for (ii = halfCnt; ii < _bankCnt; ii++) {
_array[ii] = new AthArray<T>(halfSize2);
assert(_array[ii]);
}
resetIteratorFlags();
}
~Ath__array2d()
{
for (unsigned int ii = 0; ii < _bankCnt; ii++)
delete _array[ii];
delete _array;
}
uint getBankCnt() { return _bankCnt; }
uint getCnt()
{
uint cnt = 0;
for (unsigned int ii = 0; ii < _bankCnt; ii++)
cnt += getCnt(ii);
return cnt;
}
unsigned int add(unsigned int ii, T a)
{
if (ii >= _bankCnt)
ii = _bankCnt - 1;
return _array[ii]->add(a);
}
T get(int ii, int jj) { return _array[ii]->get(jj); }
unsigned int getCnt(unsigned int ii) { return _array[ii]->getLast(); }
unsigned int startIterator(unsigned int ii)
{
_doIteratorAll = false;
_tmpBank = ii;
_current = 0;
if (ii < _bankCnt)
_tmpCnt = _array[ii]->getLast();
else
_tmpCnt = 0;
return _tmpCnt;
}
unsigned int startIteratorAll()
{
uint cnt = startIterator(0);
_doIteratorAll = true;
return cnt;
}
int getNext(T* a)
{
if (_current < _tmpCnt) {
*a = _array[_tmpBank]->get(_current++);
return _current;
} else if (_doIteratorAll) {
_tmpBank++;
if (_tmpBank == _bankCnt)
return 0;
startIterator(_tmpBank);
_doIteratorAll = true;
return getNext(a);
} else {
return 0;
}
}
void printCnt(FILE* fp, uint ii, char* msg)
{
fprintf(fp, "%6d %s\n", getCnt(ii), msg);
}
void printAllCnts(FILE* fp, char* indexMsg, char* msg)
{
for (unsigned int ii = 0; ii < _bankCnt; ii++) {
if (getCnt(ii) <= 0)
continue;
fprintf(fp, "%s= %2d has ", indexMsg, ii);
printCnt(fp, ii, msg);
}
}
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <stdio.h>
#include <string.h>
#include "util.h"
namespace odb {
using uint = unsigned int;
bool Ath__intersect(int X1, int DX, int x1, int dx, int* ix1, int* ix2);
// TODO center line with width and length and direction
class Ath__box
{
public:
uint _layer : 4;
uint _valid : 1;
uint _id : 28;
public:
int _xlo;
int _ylo;
int _xhi;
int _yhi;
Ath__box* _next;
public:
Ath__box();
uint getDir();
int getYhi(int bound);
int getXhi(int bound);
int getXlo(int bound);
int getYlo(int bound);
uint getWidth(uint* dir);
Ath__box(int x1, int y1, int x2, int y2, uint units = 1);
void set(int x1, int y1, int x2, int y2, uint units = 1);
uint getDX();
uint getDY();
uint getLength();
void invalidateBox();
void set(Ath__box* bb);
bool outside(int x1, int y1, int x2, int y2);
uint getOwner();
};
} // namespace odb
/////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2019, The Regents of the University of California
// All rights reserved.
//
// BSD 3-Clause License
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <stdio.h>
#include <unistd.h>
#include <list>
#include <string>
#include "db.h"
#include "odb.h"
namespace odb {
class cdl
{
public:
static bool writeCdl(utl::Logger* logger,
dbBlock* block,
const char* outFileName,
const std::vector<const char*>& mastersFileNames,
bool includeFillers = 0);
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
/*-------------------------------------------------------------
//// AUTHOR: SANJEEV MAHAJAN
---------------------------------------------------------------*/
#pragma once
#include <stdlib.h>
#include "assert.h"
namespace odb {
template <class T>
class Darr
{
public:
Darr(int n = 0);
~Darr(void);
void insert(T el);
void remove(int i);
T pop();
T get(int i);
void set(int i, T el);
int n();
void dsort(int cmp(const void* a, const void* b));
void reset(int n = 0);
private:
T* _ar;
int _n;
int _tot;
};
template <class T>
Darr<T>::Darr(int n)
{
_n = 0;
_tot = n;
if (n == 0) {
_ar = NULL;
return;
}
_ar = new T[_tot];
}
template <class T>
void Darr<T>::insert(T el)
{
if (_n < _tot) {
_ar[_n++] = el;
return;
}
_tot = 2 * _tot + 1;
T* ara = new T[_tot];
int i;
for (i = 0; i < _n; i++)
ara[i] = _ar[i];
ara[_n++] = el;
if (_ar)
delete[] _ar;
_ar = ara;
return;
}
template <class T>
void Darr<T>::remove(int i)
{
assert(i < _n);
assert(i >= 0);
int j;
for (j = i + 1; j < _n; j++)
_ar[j - 1] = _ar[j];
_n--;
}
template <class T>
T Darr<T>::pop()
{
assert(_n > 0);
_n--;
return _ar[_n];
}
template <class T>
T Darr<T>::get(int i)
{
assert(i < _n);
assert(i >= 0);
return _ar[i];
}
template <class T>
void Darr<T>::set(int i, T el)
{
assert(i < _n);
assert(i >= 0);
_ar[i] = el;
}
template <class T>
void Darr<T>::reset(int n)
{
if (_n > n)
_n = n;
assert(_n <= _tot);
}
template <class T>
int Darr<T>::n(void)
{
return _n;
}
template <class T>
Darr<T>::~Darr(void)
{
if (_ar)
delete[] _ar;
}
template <class T>
void Darr<T>::dsort(int cmp(const void* a, const void* b))
{
qsort(_ar, _n, sizeof(T), cmp);
}
} // namespace odb
This source diff could not be displayed because it is too large. You can view the blob instead.
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <list>
#include "odb.h"
namespace odb {
class dbBlock;
class dbBox;
class dbFill;
class dbInst;
class dbMaster;
class dbNet;
class dbITerm;
class dbWire;
class dbBTerm;
class dbBPin;
class dbBlockage;
class dbPlacementStatus;
class dbObstruction;
class dbRegion;
class dbRow;
class dbSBox;
class dbSWire;
///////////////////////////////////////////////////////////////////////////////
///
/// dbBlockCallBackObj - An object comprising a list of stub routines
/// invoked by dbBlock.
/// Derived classes may implement these routines, causing external code
/// to be invoked from inside dbBlock methods.
///
///////////////////////////////////////////////////////////////////////////////
class dbBlockCallBackObj
{
public:
// dbInst Start
virtual void inDbInstCreate(dbInst*) {}
virtual void inDbInstCreate(dbInst*, dbRegion*) {}
virtual void inDbInstDestroy(dbInst*) {}
virtual void inDbInstPlacementStatusBefore(dbInst*, const dbPlacementStatus&) {}
virtual void inDbInstSwapMasterBefore(dbInst*, dbMaster*) {}
virtual void inDbInstSwapMasterAfter(dbInst*) {}
virtual void inDbPreMoveInst(dbInst*) {}
virtual void inDbPostMoveInst(dbInst*) {}
// dbInst End
// dbNet Start
virtual void inDbNetCreate(dbNet*) {}
virtual void inDbNetDestroy(dbNet*) {}
// dbNet End
// dbITerm Start
virtual void inDbITermCreate(dbITerm*) {}
virtual void inDbITermDestroy(dbITerm*) {} // Bugzilla #7 - payam
virtual void inDbITermPreDisconnect(dbITerm*) {}
virtual void inDbITermPostDisconnect(dbITerm*, dbNet*) {}
virtual void inDbITermPreConnect(dbITerm*, dbNet*) {}
virtual void inDbITermPostConnect(dbITerm*) {}
// dbITerm End
// dbBTerm Start
virtual void inDbBTermCreate(dbBTerm*) {}
virtual void inDbBTermDestroy(dbBTerm*) {}
virtual void inDbBTermPreConnect(dbBTerm*, dbNet*) {}
virtual void inDbBTermPostConnect(dbBTerm*) {}
virtual void inDbBTermPreDisconnect(dbBTerm*) {}
virtual void inDbBTermPostDisConnect(dbBTerm*, dbNet*) {}
// dbBTerm End
// dbBPin Start
virtual void inDbBPinCreate(dbBPin*) {}
virtual void inDbBPinDestroy(dbBPin*) {}
// dbBPin End
// dbBlockage Start
virtual void inDbBlockageCreate(dbBlockage*) {}
// dbBlockage End
// dbObstruction Start
virtual void inDbObstructionCreate(dbObstruction*) {}
virtual void inDbObstructionDestroy(dbObstruction*) {}
// dbObstruction End
// dbRegion Start
virtual void inDbRegionCreate(dbRegion*) {}
virtual void inDbRegionAddBox(dbRegion*, dbBox*) {}
virtual void inDbRegionDestroy(dbRegion*) {}
// dbRegion End
// dbRow Start
virtual void inDbRowCreate(dbRow*) {}
virtual void inDbRowDestroy(dbRow*) {}
// dbRow End
// dbWire Start
virtual void inDbWireCreate(dbWire*) {}
virtual void inDbWireDestroy(dbWire*) {}
virtual void inDbWirePreAttach(dbWire*, dbNet*) {}
virtual void inDbWirePostAttach(dbWire*) {}
virtual void inDbWirePreDetach(dbWire*) {}
virtual void inDbWirePostDetach(dbWire*, dbNet*) {}
virtual void inDbWirePreAppend(dbWire*, dbWire*) {
} // first is src, second is dst
virtual void inDbWirePostAppend(dbWire*, dbWire*) {
} // first is src, second is dst
virtual void inDbWirePreCopy(dbWire*, dbWire*) {
} // first is src, second is dst
virtual void inDbWirePostCopy(dbWire*, dbWire*) {
} // first is src, second is dst
// dbWire End
// dbSWire Start
virtual void inDbSWireCreate(dbSWire*) {}
virtual void inDbSWireDestroy(dbSWire*) {}
virtual void inDbSWireAddSBox(dbSBox*) {}
virtual void inDbSWireRemoveSBox(dbSBox*) {}
virtual void inDbSWirePreDestroySBoxes(dbSWire*) {}
virtual void inDbSWirePostDestroySBoxes(dbSWire*) {}
// dbSWire End
// dbFill Start
virtual void inDbFillCreate(dbFill*) {}
// dbFill End
virtual void inDbBlockStreamOutBefore(dbBlock*) {}
virtual void inDbBlockStreamOutAfter(dbBlock*) {}
virtual void inDbBlockReadNetsBefore(dbBlock*) {}
virtual void inDbBlockSetDieArea(dbBlock*) {}
// allow ECO client initialization - payam
virtual dbBlockCallBackObj& operator()() { return *this; }
// Manipulate _callback list of owner -- in journal.cpp
void addOwner(dbBlock* new_owner);
bool hasOwner() const { return (_owner != NULL); }
void removeOwner();
dbBlockCallBackObj() { _owner = NULL; }
virtual ~dbBlockCallBackObj() { removeOwner(); }
private:
dbBlock* _owner;
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "dbObject.h"
namespace odb {
class dbBlock;
template <>
class dbSetIterator<dbBlock>
{
friend class dbSet<dbBlock>;
dbIterator* _itr;
uint _cur;
dbObject* _parent;
dbSetIterator(dbIterator* itr, uint id, dbObject* parent)
{
_itr = itr;
_cur = id;
_parent = parent;
}
public:
typedef dbBlock* value_type;
typedef std::ptrdiff_t difference_type;
typedef dbBlock** pointer;
typedef dbBlock*& reference;
typedef std::input_iterator_tag iterator_category;
dbSetIterator()
{
_itr = NULL;
_cur = 0;
_parent = NULL;
}
dbSetIterator(const dbSetIterator& it)
{
_itr = it._itr;
_cur = it._cur;
_parent = it._parent;
}
bool operator==(const dbSetIterator<dbBlock>& it)
{
return (_itr == it._itr) && (_cur == it._cur) && (_parent == it._parent);
}
bool operator!=(const dbSetIterator<dbBlock>& it)
{
return (_itr != it._itr) || (_cur != it._cur) || (_parent != it._parent);
}
dbBlock* operator*() { return (dbBlock*) _itr->getObject(_cur, _parent); }
dbBlock* operator->() { return (dbBlock*) _itr->getObject(_cur, _parent); }
dbSetIterator<dbBlock>& operator++()
{
_cur = _itr->next(_cur);
return *this;
}
dbSetIterator<dbBlock> operator++(int)
{
dbSetIterator it(*this);
_cur = _itr->next(_cur);
return it;
}
};
template <>
class dbSet<dbBlock>
{
dbIterator* _itr;
dbObject* _parent;
public:
typedef dbSetIterator<dbBlock> iterator;
dbSet()
{
_itr = NULL;
_parent = NULL;
}
dbSet(dbObject* parent, dbIterator* itr)
{
_parent = parent;
_itr = itr;
}
dbSet(const dbSet<dbBlock>& c)
{
_itr = c._itr;
_parent = c._parent;
}
///
/// Returns the number of items in this set.
///
uint size() { return _itr->size(_parent); }
///
/// Return a begin() iterator.
///
iterator begin() { return iterator(_itr, _itr->begin(_parent), _parent); }
///
/// Return an end() iterator.
///
iterator end() { return iterator(_itr, _itr->end(_parent), _parent); }
///
/// Returns the maximum number sequential elements the this set
/// may iterate.
///
uint sequential() { return _itr->sequential(); }
///
/// Returns true if this set is reversible.
///
bool reversible() { return _itr->reversible(); }
///
/// Returns true if the is iterated in the reverse order that
/// it was created.
///
bool orderReversed() { return _itr->orderReversed(); }
///
/// Reverse the order of this set.
///
void reverse() { _itr->reverse(_parent); }
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "dbObject.h"
namespace odb {
class dbCCSeg;
template <>
class dbSetIterator<dbCCSeg>
{
friend class dbSet<dbCCSeg>;
dbIterator* _itr;
uint _cur;
uint _pid;
dbSetIterator(dbIterator* itr, uint id, uint pid)
{
_itr = itr;
_cur = id;
_pid = pid;
}
public:
typedef dbCCSeg* value_type;
typedef std::ptrdiff_t difference_type;
typedef dbCCSeg** pointer;
typedef dbCCSeg*& reference;
typedef std::input_iterator_tag iterator_category;
dbSetIterator()
{
_itr = NULL;
_cur = 0;
_pid = 0;
}
dbSetIterator(const dbSetIterator& it)
{
_itr = it._itr;
_cur = it._cur;
_pid = it._pid;
}
bool operator==(const dbSetIterator<dbCCSeg>& it)
{
return (_itr == it._itr) && (_cur == it._cur) && (_pid == it._pid);
}
bool operator!=(const dbSetIterator<dbCCSeg>& it)
{
return (_itr != it._itr) || (_cur != it._cur) || (_pid != it._pid);
}
dbCCSeg* operator*() { return (dbCCSeg*) _itr->getObject(_cur); }
dbCCSeg* operator->() { return (dbCCSeg*) _itr->getObject(_cur); }
dbSetIterator<dbCCSeg>& operator++()
{
_cur = _itr->next(_cur, _pid);
return *this;
}
dbSetIterator<dbCCSeg> operator++(int)
{
dbSetIterator it(*this);
_cur = _itr->next(_cur, _pid);
return it;
}
};
template <>
class dbSet<dbCCSeg>
{
dbIterator* _itr;
dbObject* _parent;
uint _pid;
public:
typedef dbSetIterator<dbCCSeg> iterator;
dbSet()
{
_itr = NULL;
_parent = NULL;
_pid = 0;
}
dbSet(dbObject* parent, dbIterator* itr)
{
_parent = parent;
_itr = itr;
_pid = parent->getId();
}
dbSet(const dbSet<dbCCSeg>& c)
{
_itr = c._itr;
_parent = c._parent;
_pid = c._pid;
}
///
/// Returns the number of items in this set.
///
uint size() { return _itr->size(_parent); }
///
/// Return a begin() iterator.
///
iterator begin() { return iterator(_itr, _itr->begin(_parent), _pid); }
///
/// Return an end() iterator.
///
iterator end() { return iterator(_itr, _itr->end(_parent), _pid); }
///
/// Returns the maximum number sequential elements the this set
/// may iterate.
///
uint sequential() { return _itr->sequential(); }
///
/// Returns true if this set is reversible.
///
bool reversible() { return _itr->reversible(); }
///
/// Returns true if the is iterated in the reverse order that
/// it was created.
///
bool orderReversed() { return _itr->orderReversed(); }
///
/// Reverse the order of this set.
///
void reverse() { _itr->reverse(_parent); }
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "db.h"
namespace odb {
class dbExtControl : public dbObject
{
public:
// PERSISTANT-MEMBERS
bool _independentExtCorners;
bool _foreign;
bool _wireStamped;
bool _rsegCoord;
bool _overCell;
bool _extracted;
bool _lefRC;
uint _cornerCnt;
uint _ccPreseveGeom;
uint _ccUp;
uint _couplingFlag;
double _coupleThreshold;
double _mergeResBound;
bool _mergeViaRes;
bool _mergeParallelCC;
bool _exttreePreMerg;
double _exttreeMaxcap;
bool _useDbSdb;
uint _CCnoPowerSource;
uint _CCnoPowerTarget;
bool _usingMetalPlanes;
std::string _ruleFileName;
std::string _extractedCornerList;
std::string _derivedCornerList;
std::string _cornerIndexList;
std::string _resFactorList;
std::string _gndcFactorList;
std::string
_ccFactorList;
dbExtControl();
};
dbOStream& operator<<(dbOStream& stream, const dbExtControl& extControl);
dbIStream& operator>>(dbIStream& stream, dbExtControl& extControl);
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "dbStream.h"
namespace odb {
class dbIdValidation
{
public:
static uint invalidId() { return 0; }
static bool isId(const char* inid);
};
//
// April 2006 twg -
//
// I removed the inheritance of empty class dbIdValidation from the
// inheritance list of dbId. The "C++" standard does not enforce an empty
// class to have zero bytes. It is up to the compiler to optimize the empty
// class.
//
// If the compiler does NOT optimize the empty class, then database index
// will increase from 32-bits to 64-bits! (the compiler will align the "_id"
// field to a 32-bit boundary.)
//
template <class T>
class dbId
{
unsigned int _id;
public:
typedef T _type;
dbId() { _id = 0; }
dbId(const dbId<T>& id) : _id(id._id) {}
dbId(unsigned int id) { _id = id; }
operator unsigned int() const { return _id; }
unsigned int& id() { return _id; }
bool isValid() { return _id > 0; }
friend dbOStream& operator<<(dbOStream& stream, const dbId<T>& id)
{
stream << id._id;
return stream;
}
friend dbIStream& operator>>(dbIStream& stream, dbId<T>& id)
{
stream >> id._id;
return stream;
}
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <iterator>
#include "odb.h"
namespace odb {
class dbObject;
class dbObjectTable;
class dbIterator
{
public:
virtual bool reversible() = 0;
virtual bool orderReversed() = 0;
virtual void reverse(dbObject* parent) = 0;
virtual uint sequential() = 0;
virtual uint size(dbObject* parent) = 0;
virtual uint begin(dbObject* parent) = 0;
virtual uint end(dbObject* parent) = 0;
virtual uint next(uint id, ...) = 0;
virtual dbObject* getObject(uint id, ...) = 0;
virtual ~dbIterator() {}
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <stdarg.h>
#include <stdio.h>
#include <sys/times.h>
#include "ZInterface.h"
#include "odb.h"
namespace odb {
int idle(int = 0);
int notice(int code, const char* msg, ...) ADS_FORMAT_PRINTF(2, 3);
int verbose(int code, const char* msg, ...) ADS_FORMAT_PRINTF(2, 3);
int info(int code, const char* msg, ...) ADS_FORMAT_PRINTF(2, 3);
void dumpWarn();
int checkWarning(const char* msg);
void resetWarningCount(const char* msg, int max, int cnt);
int warning(int code, const char* msg, ...) ADS_FORMAT_PRINTF(2, 3);
void error(int code, const char* msg, ...) ADS_FORMAT_PRINTF(2, 3);
int debug(const char* mod, const char* tag, const char* msg, ...)
ADS_FORMAT_PRINTF(3, 4);
int isDebug(const char* mod, const char* tag);
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <map>
#include <vector>
#include "dbSet.h"
#include "odb.h"
namespace odb {
///
/// This class creates a assocation between
/// the objects of dbSet<T> to a an object of type "D".
/// If "D" is a class object, then "D" must have a public default constructor
/// and a public destructor.
///
/// NOTE: The map becomes invalid if the dbSet membership changes, i.e.,
/// a member is added or deleted from the set.
///
/// If the map becomes invalid, access operations may fail.
///
template <class T, class D>
class dbMap
{
dbSet<T> _set;
std::map<T*, D>* _map; // map used if set is not sequential
std::vector<D>* _vector; // vector used if set is sequential
// Map cannot be assigned or copied!
dbMap(const dbMap&);
dbMap& operator=(const dbMap&);
public:
///
/// Create a new map from the set. The data-objects are initialized
/// to the default constructor of the object type.
///
dbMap(const dbSet<T>& set);
///
/// Destructor.
///
~dbMap();
///
/// D & operator[T *] const
/// Access to a data object of key "T *".
///
/// Example:
///
/// dbSet<dbNet> nets = block->getNets();
/// dbMap<dbNet, int> net_weight;
/// dbSet<dbNet>::iterator itr;
///
/// for( itr = nets.begin(); itr != nets.end(); ++itr )
/// {
/// dbNet * net = *itr;
/// net_weight[net] = 1;
/// }
///
D& operator[](T* object);
///
/// const D & operator[T *] const
/// Const access to a data object of key "T *".
///
/// Example:
///
/// dbSet<dbNet> nets = block->getNets();
/// dbMap<dbNet, int> net_weight;
/// dbSet<dbNet>::iterator itr;
///
/// for( itr = nets.begin(); itr != nets.end(); ++itr )
/// {
/// dbNet * net = *itr;
/// int weight = net_weight[net];
/// printf("net(%d) weight = %d\n", net->getId(), weight );
/// }
///
const D& operator[](T* object) const;
};
} // namespace odb
#include "dbMap.hpp"
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "ZException.h"
namespace odb {
template <class T, class D>
inline dbMap<T, D>::dbMap(const dbSet<T>& set)
{
_set = set;
// Use a vector if this set represents a sequential iterator
if (_set.sequential()) {
_vector = new std::vector<D>(_set.sequential() + 1);
_map = NULL;
}
// Use a map if this set represents random iterator
else {
_vector = NULL;
_map = new std::map<T*, D>;
typename dbSet<T>::iterator itr;
for (itr = _set.begin(); itr != _set.end(); ++itr) {
T* object = *itr;
(*_map)[object] = D();
}
}
}
template <class T, class D>
inline dbMap<T, D>::~dbMap()
{
if (_map)
delete _map;
if (_vector)
delete _vector;
}
template <class T, class D>
inline const D& dbMap<T, D>::operator[](T* object) const
{
if (_map) {
typename std::map<T*, D>::const_iterator itr = _map->find(object);
ZASSERT(itr != _map->end());
return (*itr).second;
}
uint idx = object->getId();
ZASSERT(idx && (idx < _vector->size()));
return (*_vector)[idx];
}
template <class T, class D>
inline D& dbMap<T, D>::operator[](T* object)
{
if (_map) {
typename std::map<T*, D>::iterator itr = _map->find(object);
ZASSERT(itr != _map->end());
return (*itr).second;
}
uint idx = object->getId();
ZASSERT(idx && (idx < _vector->size()));
return (*_vector)[idx];
}
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <vector>
#include "dbDiff.h"
#include "dbStream.h"
#include "odb.h"
namespace odb {
class dbDiff;
template <class T>
class dbMatrix
{
public:
uint _n;
uint _m;
std::vector<std::vector<T>> _matrix;
dbMatrix();
dbMatrix(uint n, uint m);
void resize(uint n, uint m);
uint numRows() const { return _n; }
uint numCols() const { return _m; }
void clear();
uint numElems() const;
dbMatrix(const dbMatrix<T>& incpy)
: _n(incpy._n), _m(incpy._m), _matrix(incpy._matrix)
{
}
dbMatrix<T>& operator=(const dbMatrix<T>& incpy)
{
_n = incpy._n;
_m = incpy._m;
_matrix.clear();
_matrix = incpy._matrix;
return *this;
}
const T& operator()(uint i, uint j) const;
T& operator()(uint i, uint j);
bool operator==(const dbMatrix<T>& rhs) const;
bool operator!=(const dbMatrix<T>& rhs) const { return !operator==(rhs); }
void differences(dbDiff& diff,
const char* field,
const dbMatrix<T>& rhs) const;
void out(dbDiff& diff, char side, const char* field) const;
};
template <class T>
inline dbOStream& operator<<(dbOStream& stream, const dbMatrix<T>& mat)
{
stream << mat._n;
stream << mat._m;
uint i, j;
for (i = 0; i < mat._n; ++i) {
for (j = 0; j < mat._m; ++j) {
const T& x = mat(i, j);
stream << x;
}
}
return stream;
}
template <class T>
inline dbIStream& operator>>(dbIStream& stream, dbMatrix<T>& mat)
{
uint n;
uint m;
stream >> n;
stream >> m;
mat.resize(n, m);
uint i, j;
for (i = 0; i < mat._n; ++i) {
for (j = 0; j < mat._m; ++j) {
T& x = mat(i, j);
stream >> x;
}
}
return stream;
}
template <class T>
inline dbMatrix<T>::dbMatrix()
{
_n = 0;
_m = 0;
}
template <class T>
inline dbMatrix<T>::dbMatrix(uint n, uint m)
{
_n = n;
_m = m;
resize(n, m);
}
template <class T>
inline void dbMatrix<T>::clear()
{
_n = _m = 0;
_matrix.clear();
}
template <class T>
inline uint dbMatrix<T>::numElems() const
{
return (_n * _m);
}
template <class T>
inline void dbMatrix<T>::resize(uint n, uint m)
{
uint i;
_n = n;
_m = m;
_matrix.resize(n);
for (i = 0; i < _n; ++i)
_matrix[i].resize(m);
}
template <class T>
inline const T& dbMatrix<T>::operator()(uint i, uint j) const
{
assert((i >= 0) && (i < _n) && (j >= 0) && (j < _m));
const std::vector<T>& v = _matrix[i];
return v[j];
}
template <class T>
inline T& dbMatrix<T>::operator()(uint i, uint j)
{
assert((i >= 0) && (i < _n) && (j >= 0) && (j < _m));
std::vector<T>& v = _matrix[i];
return v[j];
}
template <class T>
inline bool dbMatrix<T>::operator==(const dbMatrix<T>& rhs) const
{
return _matrix == rhs._matrix;
}
template <class T>
inline void dbMatrix<T>::differences(dbDiff& diff,
const char* field,
const dbMatrix<T>& rhs) const
{
uint i, j;
for (i = 0; i < _n && i < rhs._n; ++i) {
for (j = 0; j < _m && j < rhs._m; ++j) {
const T& o1 = (*this) (i, j);
const T& o2 = rhs(i, j);
if (o1 != o2) {
diff.report("< %s[%d][%d] = ", field, i, j);
diff << o1;
diff << "\n";
diff.report("> %s[%d][%d] = ", field, i, j);
diff << o2;
diff << "\n";
}
}
if (j < _m) {
for (j = 0; j < _m; ++j) {
const T& o1 = (*this) (i, j);
diff.report("< %s[%d][%d] = ", field, i, j);
diff << o1;
diff << "\n";
}
}
if (j < rhs._m) {
for (j = 0; j < rhs._m; ++j) {
const T& o2 = rhs(i, j);
diff.report("> %s[%d][%d] = ", field, i, j);
diff << o2;
diff << "\n";
}
}
}
if (i < _n) {
for (; i < _n; ++i) {
for (j = 0; j < _m; ++j) {
const T& o1 = (*this) (i, j);
diff.report("< %s[%d][%d] = ", field, i, j);
diff << o1;
diff << "\n";
}
}
}
if (i < rhs._n) {
for (; i < rhs._n; ++i) {
for (j = 0; j < rhs._m; ++j) {
const T& o2 = rhs(i, j);
diff.report("> %s[%d][%d] = ", field, i, j);
diff << o2;
diff << "\n";
}
}
}
}
template <class T>
inline void dbMatrix<T>::out(dbDiff& diff, char side, const char* field) const
{
uint i, j;
for (i = 0; i < _n; ++i) {
for (j = 0; j < _m; ++j) {
const T& o1 = (*this) (i, j);
diff.report("%c %s[%d][%d] = ", side, field, i, j);
diff << o1;
diff << "\n";
}
}
}
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2020, The Regents of the University of California
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "dbObject.h"
namespace odb {
class dbNet;
template <>
class dbSetIterator<dbNet>
{
friend class dbSet<dbNet>;
dbIterator* _itr;
uint _cur;
dbObject* _parent;
dbSetIterator(dbIterator* itr, uint id, dbObject* parent)
{
_itr = itr;
_cur = id;
_parent = parent;
}
public:
typedef dbNet* value_type;
typedef std::ptrdiff_t difference_type;
typedef dbNet** pointer;
typedef dbNet*& reference;
typedef std::input_iterator_tag iterator_category;
dbSetIterator()
{
_itr = NULL;
_cur = 0;
_parent = NULL;
}
dbSetIterator(const dbSetIterator& it)
{
_itr = it._itr;
_cur = it._cur;
_parent = it._parent;
}
bool operator==(const dbSetIterator<dbNet>& it)
{
return (_itr == it._itr) && (_cur == it._cur) && (_parent == it._parent);
}
bool operator!=(const dbSetIterator<dbNet>& it)
{
return (_itr != it._itr) || (_cur != it._cur) || (_parent != it._parent);
}
dbNet* operator*() { return (dbNet*) _itr->getObject(_cur, _parent); }
dbNet* operator->() { return (dbNet*) _itr->getObject(_cur, _parent); }
dbSetIterator<dbNet>& operator++()
{
_cur = _itr->next(_cur);
return *this;
}
dbSetIterator<dbNet> operator++(int)
{
dbSetIterator it(*this);
_cur = _itr->next(_cur);
return it;
}
};
template <>
class dbSet<dbNet>
{
dbIterator* _itr;
dbObject* _parent;
public:
typedef dbSetIterator<dbNet> iterator;
dbSet()
{
_itr = NULL;
_parent = NULL;
}
dbSet(dbObject* parent, dbIterator* itr)
{
_parent = parent;
_itr = itr;
}
dbSet(const dbSet<dbNet>& c)
{
_itr = c._itr;
_parent = c._parent;
}
///
/// Returns the number of items in this set.
///
uint size() { return _itr->size(_parent); }
///
/// Return a begin() iterator.
///
iterator begin() { return iterator(_itr, _itr->begin(_parent), _parent); }
///
/// Return an end() iterator.
///
iterator end() { return iterator(_itr, _itr->end(_parent), _parent); }
///
/// Returns the maximum number sequential elements the this set
/// may iterate.
///
uint sequential() { return _itr->sequential(); }
///
/// Returns true if this set is reversible.
///
bool reversible() { return _itr->reversible(); }
///
/// Returns true if the is iterated in the reverse order that
/// it was created.
///
bool orderReversed() { return _itr->orderReversed(); }
///
/// Reverse the order of this set.
///
void reverse() { _itr->reverse(_parent); }
///
/// Returns true if set is empty
///
bool empty() { return begin() == end(); }
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "odb.h"
namespace utl {
class Logger;
}
namespace odb {
///
/// When adding a new database object, you must add a dbObjectType enumerator
/// and edit dbObject.cpp and assign an unique "character" code for its
/// database-name. See the methods:
/// void getDbName( char name[max_name_length] );
/// static dbObject * resolveDbName( dbDatabase * db, const char * name );
/// in dbObject.cpp
///
class _dbDatabase;
class dbOStream;
class dbIStream;
class dbObjectPage;
class dbObjectTable;
class dbDiff;
class _dbObject;
///
/// Steps to add new objects -
/// - add the "name_tbl" entry in dbObject.cpp
/// - add the table entry to the getObjectTable method of the container
/// object.
///
enum dbObjectType
{
dbDatabaseObj,
// Design Objects
dbChipObj,
dbBlockObj,
dbInstHdrObj,
dbInstObj,
dbNetObj,
dbBTermObj,
dbITermObj,
dbBoxObj,
dbViaObj,
dbTrackGridObj,
dbObstructionObj,
dbBlockageObj,
dbWireObj,
dbSWireObj,
dbSBoxObj,
dbCapNodeObj,
dbRSegObj,
dbCCSegObj,
dbRowObj,
dbFillObj,
dbRegionObj,
dbHierObj,
dbBPinObj,
// Generator Code Begin DbObjectType
dbTechLayerObj,
dbTechLayerSpacingEolRuleObj,
dbTechLayerMinStepRuleObj,
dbTechLayerCornerSpacingRuleObj,
dbTechLayerSpacingTablePrlRuleObj,
dbTechLayerEolKeepOutRuleObj,
dbTechLayerCutClassRuleObj,
dbTechLayerCutSpacingRuleObj,
dbTechLayerCutSpacingTableOrthRuleObj,
dbTechLayerCutSpacingTableDefRuleObj,
dbTechLayerCutEnclosureRuleObj,
dbTechLayerEolExtensionRuleObj,
dbTechLayerArraySpacingRuleObj,
dbTechLayerWidthTableRuleObj,
dbTechLayerMinCutRuleObj,
dbGuideObj,
dbMetalWidthViaMapObj,
dbTechLayerAreaRuleObj,
dbModuleObj,
dbModInstObj,
dbGroupObj,
dbGCellGridObj,
dbAccessPointObj,
dbGlobalConnectObj,
dbPowerDomainObj,
dbLogicPortObj,
dbPowerSwitchObj,
dbIsolationObj,
// Generator Code End DbObjectType
// Lib Objects
dbLibObj,
dbSiteObj,
dbMasterObj,
dbMPinObj,
dbMTermObj,
dbTargetObj,
dbTechAntennaPinModelObj,
// Tech Objects
dbTechObj,
dbTechViaObj,
dbTechNonDefaultRuleObj, // also a design object
dbTechLayerRuleObj, // also a design object
dbTechSameNetRuleObj,
dbTechLayerSpacingRuleObj,
dbTechMinCutRuleObj,
dbTechMinEncRuleObj,
dbTechV55InfluenceEntryObj,
dbTechLayerAntennaRuleObj,
dbTechViaRuleObj,
dbTechViaGenerateRuleObj,
dbTechViaLayerRuleObj,
// Property
dbPropertyObj,
dbNameObj
};
class dbDatabase;
class dbObject
{
public:
dbObjectType getObjectType() const;
dbDatabase* getDb() const;
uint getId() const;
static const int max_name_length = 256;
void getDbName(char name[max_name_length]) const;
const char* getObjName() const;
static dbObject* resolveDbName(dbDatabase* db, const char* name);
static const char* getObjName(dbObjectType type);
// These are not intended for client use as the returned class is
// not exported. They are for internal db convenience.
_dbObject* getImpl();
const _dbObject* getImpl() const;
protected:
dbObject() {}
~dbObject() {}
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "dbTypes.h"
#include "geom.h"
#include "odb.h"
#include "odbDList.h"
namespace odb {
class dbVia;
class dbTechVia;
class dbTechLayerRule;
class dbRtTree;
class dbRtNode;
// EndStyle - Defines the end style of a segment
class dbRtEndStyle
{
public:
// End-Types:
// EXTENDED - segment extended 1/2 path-width
// VARIABLE - segment extended variable amount
enum Type
{
EXTENDED,
VARIABLE
};
private:
Type _type;
int _ext;
public:
dbRtEndStyle() : _type(EXTENDED), _ext(0) {}
void setExtended()
{
_type = EXTENDED;
_ext = 0;
}
void setVariable(int ext)
{
_type = VARIABLE;
_ext = ext;
}
Type getType() const { return _type; }
int getExt() const { return _ext; }
bool operator==(const dbRtEndStyle& s) const
{
return (_type == s._type) && (_ext == s._ext);
}
bool operator!=(const dbRtEndStyle& s) const
{
return (_type != s._type) || (_ext != s._ext);
}
friend class dbRtTree;
};
// dbRtEdge - represents an edge in the routing tree.
class dbRtEdge
{
friend class dbRtTree;
friend class dbRtNode;
friend class dbRtNodeEdgeIterator;
public:
// If new edge types are added, the corresponding allocator/deallocator code
// must be updated in dbRtTree.cpp
enum Type
{
SEGMENT = 0,
TECH_VIA = 1,
VIA = 2,
SHORT = 3,
VWIRE = 4
};
protected:
Type _type;
dbRtNode* _src;
dbRtNode* _tgt;
dbWireType::Value _wire_type;
dbTechLayerRule* _non_default_rule;
double _r;
double _c;
dbRtTree* _rt_tree;
dbRtEdge* _next[2];
dbRtEdge* _prev[2];
DListEntry<dbRtEdge> _rt_edge;
int _shape_id;
uint _property;
bool _visited;
dbRtEdge(Type type, dbWireType::Value wire_type, dbTechLayerRule* rule)
: _type(type),
_src(NULL),
_tgt(NULL),
_wire_type(wire_type),
_non_default_rule(rule),
_r(0.0),
_c(0.0),
_rt_tree(NULL),
_shape_id(-1),
_property(0),
_visited(false)
{
_next[0] = NULL;
_next[1] = NULL;
_prev[0] = NULL;
_prev[1] = NULL;
}
dbRtNode* opposite(dbRtNode* n) const { return n == _src ? _tgt : _src; }
dbRtEdge*& prev(dbRtNode* node) { return node == _src ? _prev[0] : _prev[1]; }
dbRtEdge*& next(dbRtNode* node) { return node == _src ? _next[0] : _next[1]; }
public:
virtual ~dbRtEdge() {}
virtual void getBBox(Rect& bbox) = 0;
// Get the type of this node
Type getType() const { return _type; }
// Get the source edge of this node (A source node has NO directional
// significance)
dbRtNode* getSource() const { return _src; }
// Get the target edge of this node (A target node has NO directional
// significance)
dbRtNode* getTarget() const { return _tgt; }
// Get the opposite node of this node, assumes n == src or n == tgt
dbRtNode* getOpposite(dbRtNode* n) const { return opposite(n); }
// Set the wire-type of this edge.
void setWireType(dbWireType::Value value) { _wire_type = value; }
// Get the wire-type of this edge.
dbWireType::Value getWireType() const { return _wire_type; }
// Get the NonDefaultRule of this edge (returns NULL is there is no
// non-default-rule);
void setNonDefaultRule(dbTechLayerRule* rule) { _non_default_rule = rule; }
// Get the NonDefaultRule of this edge (returns NULL is there is no
// non-default-rule);
dbTechLayerRule* getNonDefaultRule() const { return _non_default_rule; }
// Set the resistance of this edge
void setResistance(double r) { _r = r; }
// Get the resistance of this edge
double getResistance() const { return _r; }
// Set the capacitance of this edge
void setCapacitance(double c) { _c = c; }
// Get the capacitance of this edge
double getCapacitance() const { return _c; }
// Get the value of the visited flag.
bool isVisited() const { return _visited; }
// Set the value of the visited flag.
void setVisited(bool value) { _visited = value; }
// Assign a property to this edge
void setProperty(uint property) { _property = property; }
// Assign a property to this edge
uint getProperty() { return _property; }
static DListEntry<dbRtEdge>* rtEdge(dbRtEdge* edge)
{
return &edge->_rt_edge;
}
};
// VIA edge
class dbRtVia : public dbRtEdge
{
dbVia* _via;
dbRtVia(dbVia* via, dbWireType::Value wire_type, dbTechLayerRule* rule)
: dbRtEdge(VIA, wire_type, rule), _via(via)
{
}
public:
virtual void getBBox(Rect& bbox);
// Get the via of this edge
dbVia* getVia() const { return _via; }
void setVia(dbVia* via) { _via = via; }
friend class dbRtTree;
};
// TECH-VIA edge
class dbRtTechVia : public dbRtEdge
{
dbTechVia* _via;
public:
dbRtTechVia(dbTechVia* via,
dbWireType::Value wire_type,
dbTechLayerRule* rule)
: dbRtEdge(TECH_VIA, wire_type, rule), _via(via)
{
}
public:
virtual void getBBox(Rect& bbox);
// Get the via of this edge
dbTechVia* getVia() const { return _via; }
friend class dbRtTree;
};
// Wire segment
class dbRtSegment : public dbRtEdge
{
dbRtEndStyle _src_style;
dbRtEndStyle _tgt_style;
dbRtSegment(dbRtEndStyle src,
dbRtEndStyle tgt,
dbWireType::Value wire_type,
dbTechLayerRule* rule)
: dbRtEdge(SEGMENT, wire_type, rule), _src_style(src), _tgt_style(tgt)
{
}
public:
virtual void getBBox(Rect& bbox);
// Set the end-syle of the source node of this edge
void setSourceEndStyle(dbRtEndStyle style) { _src_style = style; }
// Get the end-syle of the source node of this edge
dbRtEndStyle getSourceEndStyle() const { return _src_style; }
// Set the end-syle of the target node of this edge
void setTargetEndStyle(dbRtEndStyle style) { _tgt_style = style; }
// Get the end-syle of the target node of this edge
dbRtEndStyle getTargetEndStyle() const { return _tgt_style; }
int getWidth() const;
friend class dbRtTree;
};
// Virtual short to node
class dbRtShort : public dbRtEdge
{
dbRtShort(dbWireType::Value wire_type, dbTechLayerRule* rule)
: dbRtEdge(SHORT, wire_type, rule)
{
}
public:
virtual void getBBox(Rect& bbox);
friend class dbRtTree;
};
// Virtual wire between nodes
class dbRtVWire : public dbRtEdge
{
public:
dbRtVWire(dbWireType::Value wire_type, dbTechLayerRule* rule)
: dbRtEdge(VWIRE, wire_type, rule)
{
}
public:
virtual void getBBox(Rect& bbox);
friend class dbRtTree;
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <vector>
#include "dbRtEdge.h"
#include "geom.h"
#include "odb.h"
#include "odbDList.h"
namespace odb {
class dbObject;
class dbTechLayer;
class dbRtTree;
class dbRtEdge;
class dbWireEncoder;
class dbRtNodeEdgeIterator
{
dbRtNode* _node;
dbRtEdge* _cur;
void incr() { _cur = _cur->next(_node); }
public:
dbRtNodeEdgeIterator()
{
_node = NULL;
_cur = NULL;
}
dbRtNodeEdgeIterator(dbRtNode* node, dbRtEdge* cur)
{
_node = node;
_cur = cur;
}
dbRtNodeEdgeIterator(const dbRtNodeEdgeIterator& i)
{
_node = i._node;
_cur = i._cur;
}
dbRtNodeEdgeIterator& operator=(const dbRtNodeEdgeIterator& i)
{
_node = i._node;
_cur = i._cur;
return *this;
}
bool operator==(const dbRtNodeEdgeIterator& i) const
{
return _cur == i._cur;
}
bool operator!=(const dbRtNodeEdgeIterator& i) const
{
return _cur != i._cur;
}
dbRtEdge* operator*() { return _cur; }
dbRtNodeEdgeIterator& operator++()
{
incr();
return *this;
}
dbRtNodeEdgeIterator operator++(int)
{
dbRtNodeEdgeIterator i = *this;
incr();
return i;
}
};
// Node - A Node represents a physical point in the graph.
class dbRtNode
{
private:
int _x;
int _y;
int _jct_id;
dbTechLayer* _layer;
std::vector<dbObject*> _objects;
dbRtTree* _rt_tree;
dbRtEdge* _head;
dbRtEdge* _tail;
DListEntry<dbRtNode> _rt_node;
bool _visited;
void add_edge(dbRtEdge* edge)
{
assert(edge->_src == this || edge->_tgt == this);
if (_head == NULL) {
_head = _tail = edge;
edge->next(this) = NULL;
edge->prev(this) = NULL;
} else {
edge->prev(this) = _tail;
_tail->next(this) = edge;
edge->next(this) = NULL;
_tail = edge;
}
}
void remove_edge(dbRtEdge* edge)
{
dbRtEdge* n = edge->next(this);
dbRtEdge* p = edge->prev(this);
if (p)
p->next(this) = n;
else
_head = n;
if (n)
n->prev(this) = p;
else
_tail = p;
}
public:
typedef dbRtNodeEdgeIterator edge_iterator;
typedef std::vector<dbObject*>::iterator object_iterator;
dbRtNode(int x, int y, dbTechLayer* layer)
: _x(x),
_y(y),
_jct_id(-1),
_layer(layer),
_rt_tree(NULL),
_head(NULL),
_tail(NULL),
_visited(false)
{
}
// Set the x/y location of this node
void setPoint(int x, int y)
{
_x = x;
_y = y;
}
// Set the x/y location of this node
void setPoint(Point& p)
{
_x = p.x();
_y = p.y();
}
// Set the x/y location of this node
void getPoint(int& x, int& y) const
{
x = _x;
y = _y;
}
// Set the x/y location of this node
void getPoint(Point& p) const { p = Point(_x, _y); }
// Get the x-coordinate of this point
int x() const { return _x; }
// Get the x-coordinate of this point
int y() const { return _y; }
// Set the layer of this node
void setLayer(dbTechLayer* layer) { _layer = layer; }
// Get the layer of this node
dbTechLayer* getLayer() const { return _layer; }
// begin iterating edges of this node
edge_iterator begin() { return edge_iterator(this, _head); }
// end iterating edges of this node
edge_iterator end() { return edge_iterator(this, NULL); }
// Add database object to this node
void addObject(dbObject* object) { _objects.push_back(object); }
// Get the database object assigned to this node
void getObjects(std::vector<dbObject*>& objects) const { objects = _objects; }
// Get the value of the visited flag.
bool isVisited() const { return _visited; }
// Set the value of the visited flag.
void setVisited(bool value) { _visited = value; }
// returns true if this node has no edges
bool isOrphan() const { return _head == NULL; }
// returns true if this node is not an orphan and has a single edge
bool isLeaf() const { return (_head != NULL) && (_head == _tail); }
object_iterator begin_objects() { return _objects.begin(); }
object_iterator end_objects() { return _objects.end(); }
static DListEntry<dbRtNode>* rtNode(dbRtNode* node)
{
return &node->_rt_node;
}
friend class dbRtTree;
friend class dbRtEdge;
friend class dbRtSegment;
friend class dbRtVia;
friend class dbRtTechVia;
friend class dbRtShort;
friend class dbRtVWire;
};
} // namespace odb
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2019, Nefelus Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <vector>
#include "dbRtEdge.h"
#include "dbRtNode.h"
#include "dbTypes.h"
#include "odb.h"
#include "odbDList.h"
namespace odb {
class dbWire;
class dbVia;
class dbTechVia;
class dbObject;
class dbTechLayer;
class dbTechLayerRule;
class dbWireEncoder;
class dbRtEdge;
class dbRtNode;
class dbRtSegment;
class dbRtTechVia;
class dbRtBlockVia;
class dbRtShort;
class dbRtVWire;
//
// dbRtTree - This class is used to represent an encoded dbWire as a graph.
//
// The graph is undirected and cannot contain cycles.
//
// Patch wires (rects) are not exposed in the tree.
//
class dbRtTree
{
public:
dbRtTree();
~dbRtTree();
// Clear this graph.
void clear();
// Decode a dbWire into this graph. Overwrites previous graph.
void decode(dbWire* wire, bool decode_bterm_iterms = true);
// Encode this graph into the dbWire. The contents of the dbWire are over
// written.
void encode(dbWire* wire, bool encode_bterm_iterms = true);
// Get the edge of this shape_id.
// PRECONDITION: The "target" node of this edge must exist (do not delete this
// node!).
dbRtEdge* getEdge(uint shape_id);
// Node Create Method
dbRtNode* createNode(int x, int y, dbTechLayer* l);
// Create a via edge.
// Returns NULL, if the "tgt" node already has an in-edge.
// Returns NULL, if the src and tgt layers are not the respective upper and
// lower layers of this via.
dbRtVia* createVia(dbRtNode* src,
dbRtNode* tgt,
dbVia* via,
dbWireType::Value type = dbWireType::NONE,
dbTechLayerRule* rule = NULL);
// Create a tech-via edge.
// Returns NULL, if the "tgt" node already has an in-edge.
// Returns NULL, if the src and tgt layers are not the respective upper and
// lower layers of this via.
dbRtTechVia* createTechVia(dbRtNode* src,
dbRtNode* tgt,
dbTechVia* via,
dbWireType::Value type = dbWireType::NONE,
dbTechLayerRule* rule = NULL);
// Create a segment edge with the default (EXTENDED) end style.
// Returns NULL, if the "tgt" node already has an in-edge.
// Returns NULL, if the src and tgt layer are not the same.
// Returns NULL, if the src and tgt point do not form an orthogonal
// segment.
dbRtSegment* createSegment(dbRtNode* src,
dbRtNode* tgt,
dbWireType::Value type = dbWireType::NONE,
dbTechLayerRule* rule = NULL);
// Create a segment edge.
// Returns NULL, if the "tgt" node already has an in-edge.
// Returns NULL, if the src and tgt layer are not the same.
// Returns NULL, if the src and tgt point do not form an orthogonal
// segment.
dbRtSegment* createSegment(dbRtNode* src,
dbRtNode* tgt,
dbRtEndStyle src_style,
dbRtEndStyle tgt_style,
dbWireType::Value type = dbWireType::NONE,
dbTechLayerRule* rule = NULL);
// Create a short edge.
// Returns NULL, if the "tgt" node already has an in-edge.
dbRtShort* createShort(dbRtNode* src,
dbRtNode* tgt,
dbWireType::Value type = dbWireType::NONE,
dbTechLayerRule* rule = NULL);
// Create a vwire edge.
// Returns NULL, if the "tgt" node already has an in-edge.
dbRtVWire* createVWire(dbRtNode* src,
dbRtNode* tgt,
dbWireType::Value type = dbWireType::NONE,
dbTechLayerRule* rule = NULL);
// Node iterator
typedef DList<dbRtNode, &dbRtNode::rtNode>::iterator node_iterator;
node_iterator begin_nodes() { return _nodes.begin(); }
node_iterator end_nodes() { return _nodes.end(); }
// Edge iterator
typedef DList<dbRtEdge, &dbRtEdge::rtEdge>::iterator edge_iterator;
edge_iterator begin_edges() { return _edges.begin(); }
edge_iterator end_edges() { return _edges.end(); }
// Delete the specified node
void deleteNode(dbRtNode* n);
// Delete the specified edge, does not delete orphan nodes
void deleteEdge(dbRtEdge* e);
// Delete the specified edge, does not delete orphan nodes
edge_iterator deleteEdge(edge_iterator itr)
{
dbRtEdge* e = *itr;
++itr;
deleteEdge(e);
return itr;
}
// Delete the specified edge, optionally deletes orphan nodes
void deleteEdge(dbRtEdge* e, bool destroy_orphan_nodes);
// Delete the specified edge, optionally deletes orphan nodes
edge_iterator deleteEdge(edge_iterator itr, bool destroy_orphan_nodes)
{
dbRtEdge* e = *itr;
++itr;
deleteEdge(e, destroy_orphan_nodes);
return itr;
}
// Make a copy of this graph
dbRtTree* duplicate();
// Move the tree "T" into this tree
// All the nodes/edges of "T" will be moved to this tree.
void move(dbRtTree* T);
// Copy the tree "T" into this tree
// All the nodes/edges of "T" will be copied to this tree.
void copy(dbRtTree* T);
// Make a duplicate copy of this node (does not duplicate edges) in the
// specified tree
static dbRtNode* duplicate(dbRtTree* G,
dbRtNode* node,
bool copy_objects = true);
// Make a duplicate copy of this edge between src and target in the specified
// tree
static dbRtEdge* duplicate(dbRtTree* G,
dbRtEdge* edge,
dbRtNode* src,
dbRtNode* tgt);
private:
void encodePath(dbWireEncoder& encoder,
std::vector<dbRtEdge*>& path,
dbRtNode* src,
dbWireType::Value cur_type,
dbTechLayerRule* cur_rule,
bool encode_bterms_iterms);
void encodePath(dbWireEncoder& encoder,
std::vector<dbRtEdge*>& path,
bool encode_bterms_iterms);
void add_node(dbRtNode* node);
void add_edge(dbRtEdge* edge);
void remove_node(dbRtNode* node);
void remove_edge(dbRtEdge* edge);
void addObjects(dbWireEncoder& encoder, dbRtNode* node);
static void copyNode(dbRtTree* G,
dbRtNode* node,
dbRtNode* src,
bool copy_edge_map);
static void copyEdge(dbRtTree* G,
dbRtNode* src,
dbRtNode* tgt,
dbRtEdge* edge,
bool copy_edge_map);
std::vector<dbRtEdge*> _edge_map;
DList<dbRtNode, &dbRtNode::rtNode> _nodes;
DList<dbRtEdge, &dbRtEdge::rtEdge> _edges;
};
inline dbRtSegment* dbRtTree::createSegment(dbRtNode* src,
dbRtNode* tgt,
dbWireType::Value type,
dbTechLayerRule* rule)
{
return createSegment(src, tgt, dbRtEndStyle(), dbRtEndStyle(), type, rule);
}
} // namespace odb
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment