From c571535e556999b94d0faddc890683553873f746 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 29 Dec 2018 23:48:31 +0100 Subject: [PATCH] WIP: standard device classes, added GSI binding plus tests. --- src/db/db/db.pro | 4 +- src/db/db/gsiDeclDbNetlistDeviceClasses.cc | 232 +++++++++++++ src/db/db/gsiDeclDbNetlistDeviceExtractor.cc | 0 src/rba/unit_tests/rba.cc | 1 + testdata/ruby/dbNetlistDeviceClasses.rb | 331 +++++++++++++++++++ 5 files changed, 567 insertions(+), 1 deletion(-) create mode 100644 src/db/db/gsiDeclDbNetlistDeviceClasses.cc create mode 100644 src/db/db/gsiDeclDbNetlistDeviceExtractor.cc create mode 100644 testdata/ruby/dbNetlistDeviceClasses.rb diff --git a/src/db/db/db.pro b/src/db/db/db.pro index 65b36ade9..25cbb07b3 100644 --- a/src/db/db/db.pro +++ b/src/db/db/db.pro @@ -147,7 +147,9 @@ SOURCES = \ gsiDeclDbNetlist.cc \ dbNetlistDeviceClasses.cc \ dbNetlistDeviceExtractor.cc \ - dbNetlistExtractor.cc + dbNetlistExtractor.cc \ + gsiDeclDbNetlistDeviceClasses.cc \ + gsiDeclDbNetlistDeviceExtractor.cc HEADERS = \ dbArray.h \ diff --git a/src/db/db/gsiDeclDbNetlistDeviceClasses.cc b/src/db/db/gsiDeclDbNetlistDeviceClasses.cc new file mode 100644 index 000000000..8ce4a554c --- /dev/null +++ b/src/db/db/gsiDeclDbNetlistDeviceClasses.cc @@ -0,0 +1,232 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2018 Matthias Koefferlein + + 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 2 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, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "gsiDecl.h" +#include "dbNetlistDeviceClasses.h" + +namespace gsi +{ + +// TODO: move this to gsiMethods.h + +template +class ConstantValueGetter + : public StaticMethodBase +{ +public: + ConstantValueGetter (const std::string &name, const R &v, const std::string &doc) + : StaticMethodBase (name, doc, true), m_v (v) + { + } + + void initialize () + { + this->clear (); + // Note: a constant must not return a reference to an existing object, hence "set_return_new": + this->template set_return_new (); + } + + virtual MethodBase *clone () const + { + return new ConstantValueGetter (*this); + } + + virtual void call (void *, SerialArgs &, SerialArgs &ret) const + { + mark_called (); + ret.write (m_v); + } + +private: + R m_v; +}; + +template +Methods +constant (const std::string &name, const R &v, const std::string &doc = std::string ()) +{ + return Methods (new ConstantValueGetter (name, v, doc)); +} + + +extern Class decl_dbDeviceClass; + +Class decl_dbDeviceClassResistor (decl_dbDeviceClass, "db", "DeviceClassResistor", + gsi::constant ("TERMINAL_A", db::DeviceClassResistor::terminal_id_A, + "@brief A constant giving the terminal ID for terminal A" + ) + + gsi::constant ("TERMINAL_B", db::DeviceClassResistor::terminal_id_B, + "@brief A constant giving the terminal ID for terminal B" + ) + + gsi::constant ("PARAM_R", db::DeviceClassResistor::param_id_R, + "@brief A constant giving the parameter ID for parameter R" + ), + "@brief A device class for a resistor.\n" + "This class can be used to describe resistors. Resistors are defined by their combination behavior and " + "the basic parameter 'R' which is the resistance in Ohm.\n" + "\n" + "A resistor has two terminals, A and B.\n" + "\n" + "This class has been introduced in version 0.26." +); + +Class decl_dbDeviceClassCapacitor (decl_dbDeviceClass, "db", "DeviceClassCapacitor", + gsi::constant ("TERMINAL_A", db::DeviceClassCapacitor::terminal_id_A, + "@brief A constant giving the terminal ID for terminal A" + ) + + gsi::constant ("TERMINAL_B", db::DeviceClassCapacitor::terminal_id_B, + "@brief A constant giving the terminal ID for terminal B" + ) + + gsi::constant ("PARAM_C", db::DeviceClassCapacitor::param_id_C, + "@brief A constant giving the parameter ID for parameter C" + ), + "@brief A device class for a capacitor.\n" + "This class can be used to describe capacitors. Capacitors are defined by their combination behavior and " + "the basic parameter 'C' which is the capacitance in Farad.\n" + "\n" + "A capacitor has two terminals, A and B.\n" + "\n" + "This class has been introduced in version 0.26." +); + +Class decl_dbDeviceClassInductor (decl_dbDeviceClass, "db", "DeviceClassInductor", + gsi::constant ("TERMINAL_A", db::DeviceClassInductor::terminal_id_A, + "@brief A constant giving the terminal ID for terminal A" + ) + + gsi::constant ("TERMINAL_B", db::DeviceClassInductor::terminal_id_B, + "@brief A constant giving the terminal ID for terminal B" + ) + + gsi::constant ("PARAM_L", db::DeviceClassInductor::param_id_L, + "@brief A constant giving the parameter ID for parameter L" + ), + "@brief A device class for an inductor.\n" + "This class can be used to describe inductors. Inductors are defined by their combination behavior and " + "the basic parameter 'L' which is the inductance in Henry.\n" + "\n" + "An inductor has two terminals, A and B.\n" + "\n" + "This class has been introduced in version 0.26." +); + +Class decl_dbDeviceClassDiode (decl_dbDeviceClass, "db", "DeviceClassDiode", + gsi::constant ("TERMINAL_A", db::DeviceClassDiode::terminal_id_A, + "@brief A constant giving the terminal ID for terminal A" + ) + + gsi::constant ("TERMINAL_C", db::DeviceClassDiode::terminal_id_C, + "@brief A constant giving the terminal ID for terminal C" + ) + + gsi::constant ("PARAM_A", db::DeviceClassDiode::param_id_A, + "@brief A constant giving the parameter ID for parameter A" + ), + "@brief A device class for a diode.\n" + "This class can be used to describe diodes. Diodes are defined by their combination behavior and " + "the basic parameter 'A' which is their area in square micrometers.\n" + "\n" + "Diodes only combine when parallel and in the same direction. In this case, their areas are added." + "\n" + "An inductor has two terminals, A (anode) and C (cathode).\n" + "\n" + "This class has been introduced in version 0.26." +); + +Class decl_dbDeviceClassMOS3Transistor (decl_dbDeviceClass, "db", "DeviceClassMOS3Transistor", + gsi::constant ("TERMINAL_S", db::DeviceClassMOS3Transistor::terminal_id_S, + "@brief A constant giving the terminal ID for terminal S" + ) + + gsi::constant ("TERMINAL_D", db::DeviceClassMOS3Transistor::terminal_id_D, + "@brief A constant giving the terminal ID for terminal D" + ) + + gsi::constant ("TERMINAL_G", db::DeviceClassMOS3Transistor::terminal_id_G, + "@brief A constant giving the terminal ID for terminal G" + ) + + gsi::constant ("PARAM_L", db::DeviceClassMOS3Transistor::param_id_L, + "@brief A constant giving the parameter ID for parameter L" + ) + + gsi::constant ("PARAM_W", db::DeviceClassMOS3Transistor::param_id_W, + "@brief A constant giving the parameter ID for parameter W" + ) + + gsi::constant ("PARAM_AS", db::DeviceClassMOS3Transistor::param_id_AS, + "@brief A constant giving the parameter ID for parameter AS" + ) + + gsi::constant ("PARAM_AD", db::DeviceClassMOS3Transistor::param_id_AD, + "@brief A constant giving the parameter ID for parameter AD" + ), + "@brief A device class for a 3-terminal MOS transistor.\n" + "This class can be used to describe MOS transistors without a bulk terminal. " + "A device class for a MOS transistor with a bulk terminal is \\DeviceClassMOS4Transistor. " + "MOS transistors are defined by their combination behavior and the basic parameters.\n" + "\n" + "The parameters are L, W, AS and AD for the gate length and width in micrometers and source and drain area " + "in square micrometers.\n" + "\n" + "The terminals are S, G and D for source, gate and drain.\n" + "\n" + "MOS transistors combine in parallel mode, when both gate lengths are identical and " + "their gates are connected (source and drain can be swapped). In this case, their widths and source and drain " + "areas are added.\n" + "\n" + "This class has been introduced in version 0.26." +); + +Class decl_dbDeviceClassMOS4Transistor (decl_dbDeviceClass, "db", "DeviceClassMOS4Transistor", + gsi::constant ("TERMINAL_S", db::DeviceClassMOS4Transistor::terminal_id_S, + "@brief A constant giving the terminal ID for terminal S" + ) + + gsi::constant ("TERMINAL_D", db::DeviceClassMOS4Transistor::terminal_id_D, + "@brief A constant giving the terminal ID for terminal D" + ) + + gsi::constant ("TERMINAL_G", db::DeviceClassMOS4Transistor::terminal_id_G, + "@brief A constant giving the terminal ID for terminal G" + ) + + gsi::constant ("TERMINAL_B", db::DeviceClassMOS4Transistor::terminal_id_B, + "@brief A constant giving the terminal ID for terminal B" + ) + + gsi::constant ("PARAM_L", db::DeviceClassMOS4Transistor::param_id_L, + "@brief A constant giving the parameter ID for parameter L" + ) + + gsi::constant ("PARAM_W", db::DeviceClassMOS4Transistor::param_id_W, + "@brief A constant giving the parameter ID for parameter W" + ) + + gsi::constant ("PARAM_AS", db::DeviceClassMOS4Transistor::param_id_AS, + "@brief A constant giving the parameter ID for parameter AS" + ) + + gsi::constant ("PARAM_AD", db::DeviceClassMOS4Transistor::param_id_AD, + "@brief A constant giving the parameter ID for parameter AD" + ), + "@brief A device class for a 4-terminal MOS transistor.\n" + "This class can be used to describe MOS transistors with a bulk terminal. " + "A device class for a MOS transistor without a bulk terminal is \\DeviceClassMOS3Transistor. " + "MOS transistors are defined by their combination behavior and the basic parameters.\n" + "\n" + "The parameters are L, W, AS and AD for the gate length and width in micrometers and source and drain area " + "in square micrometers.\n" + "\n" + "The terminals are S, G, D and B for source, gate, drain and bulk.\n" + "\n" + "MOS transistors combine in parallel mode, when both gate lengths are identical and " + "their gates and bulk terminals are connected (source and drain can be swapped). In this case, their widths and source and drain " + "areas are added.\n" + "\n" + "This class has been introduced in version 0.26." +); + +} diff --git a/src/db/db/gsiDeclDbNetlistDeviceExtractor.cc b/src/db/db/gsiDeclDbNetlistDeviceExtractor.cc new file mode 100644 index 000000000..e69de29bb diff --git a/src/rba/unit_tests/rba.cc b/src/rba/unit_tests/rba.cc index 51020ae1e..2df8e38bb 100644 --- a/src/rba/unit_tests/rba.cc +++ b/src/rba/unit_tests/rba.cc @@ -110,6 +110,7 @@ RUBYTEST (dbLayoutDiff, "dbLayoutDiff.rb") RUBYTEST (dbLayoutQuery, "dbLayoutQuery.rb") RUBYTEST (dbMatrix, "dbMatrix.rb") RUBYTEST (dbNetlist, "dbNetlist.rb") +RUBYTEST (dbNetlistDeviceClasses, "dbNetlistDeviceClasses.rb") RUBYTEST (dbPathTest, "dbPathTest.rb") RUBYTEST (dbPCells, "dbPCells.rb") RUBYTEST (dbPointTest, "dbPointTest.rb") diff --git a/testdata/ruby/dbNetlistDeviceClasses.rb b/testdata/ruby/dbNetlistDeviceClasses.rb new file mode 100644 index 000000000..cfd51b421 --- /dev/null +++ b/testdata/ruby/dbNetlistDeviceClasses.rb @@ -0,0 +1,331 @@ +# encoding: UTF-8 + +# KLayout Layout Viewer +# Copyright (C) 2006-2018 Matthias Koefferlein +# +# 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 2 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, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +if !$:.member?(File::dirname($0)) + $:.push(File::dirname($0)) +end + +load("test_prologue.rb") + +class DBNetlist_TestClass < TestBase + + def test_1_Resistors + + cls = RBA::DeviceClassResistor::new + + nl = RBA::Netlist::new + nl.add(cls) + + circuit = RBA::Circuit::new + nl.add(circuit) + + r1 = circuit.create_device(cls, "r1") + r1.set_parameter(RBA::DeviceClassResistor::PARAM_R, 1.0) + r2 = circuit.create_device(cls, "r2") + r2.set_parameter("R", 3.0) + + pin_a = circuit.create_pin ("A") + pin_b = circuit.create_pin ("B") + + n1 = circuit.create_net("n1") + circuit.connect_pin(pin_a, n1) + r1.connect_terminal(RBA::DeviceClassResistor::TERMINAL_A, n1) + + n2 = circuit.create_net("n2") + r1.connect_terminal(RBA::DeviceClassResistor::TERMINAL_B, n2) + r2.connect_terminal(RBA::DeviceClassResistor::TERMINAL_A, n2) + + n3 = circuit.create_net("n3") + r2.connect_terminal(RBA::DeviceClassResistor::TERMINAL_B, n3) + circuit.connect_pin(pin_b, n3) + + assert_equal(nl.to_s, <