Introspection: Add get_cells command

Signed-off-by: Tomasz Michalak <tmichalak@antmicro.com>
diff --git a/design_introspection-plugin/Makefile b/design_introspection-plugin/Makefile
index c9b43b3..181effb 100644
--- a/design_introspection-plugin/Makefile
+++ b/design_introspection-plugin/Makefile
@@ -5,7 +5,7 @@
 PLUGINS_DIR = $(shell yosys-config --datdir)/plugins
 
 NAME = design_introspection
-OBJS = $(NAME).o get_cmd.o get_nets.o get_ports.o
+OBJS = $(NAME).o get_cmd.o get_nets.o get_ports.o get_cells.o
 
 $(NAME).so: $(OBJS)
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
diff --git a/design_introspection-plugin/design_introspection.cc b/design_introspection-plugin/design_introspection.cc
index 3ebebf9..c14ca80 100644
--- a/design_introspection-plugin/design_introspection.cc
+++ b/design_introspection-plugin/design_introspection.cc
@@ -20,6 +20,7 @@
 
 #include "get_nets.h"
 #include "get_ports.h"
+#include "get_cells.h"
 
 USING_YOSYS_NAMESPACE
 
@@ -29,6 +30,7 @@
     DesignIntrospection(){}
     GetNets get_nets_cmd;
     GetPorts get_ports_cmd;
+    GetCells get_cells_cmd;
 } DesignIntrospection;
 
 
diff --git a/design_introspection-plugin/get_cells.cc b/design_introspection-plugin/get_cells.cc
new file mode 100644
index 0000000..8e9abe7
--- /dev/null
+++ b/design_introspection-plugin/get_cells.cc
@@ -0,0 +1,26 @@
+#include "get_cells.h"
+
+USING_YOSYS_NAMESPACE
+
+std::string GetCells::TypeName() { return "cell"; }
+
+std::string GetCells::SelectionType() { return "c"; }
+
+void GetCells::ExtractSelection(Tcl_Obj* tcl_list, RTLIL::Module* module,
+                               Filters& filters, bool is_quiet) {
+    for (auto cell : module->selected_cells()) {
+	if (filters.size() > 0) {
+	    Filter filter = filters.at(0);
+	    std::string attr_value = cell->get_string_attribute(
+	        RTLIL::IdString(RTLIL::escape_id(filter.first)));
+	    if (attr_value.compare(filter.second)) {
+		continue;
+	    }
+	}
+	if (!is_quiet) {
+	    log("%s ", id2cstr(cell->name));
+	}
+	Tcl_Obj* value_obj = Tcl_NewStringObj(id2cstr(cell->name), -1);
+	Tcl_ListObjAppendElement(yosys_get_tcl_interp(), tcl_list, value_obj);
+    }
+}
diff --git a/design_introspection-plugin/get_cells.h b/design_introspection-plugin/get_cells.h
new file mode 100644
index 0000000..ae7610b
--- /dev/null
+++ b/design_introspection-plugin/get_cells.h
@@ -0,0 +1,17 @@
+#ifndef _GET_CELLS_H_
+#define _GET_CELLS_H_
+
+#include "get_cmd.h"
+
+USING_YOSYS_NAMESPACE
+
+struct GetCells : public GetCmd {
+    GetCells() : GetCmd("get_cells", "Print matching cells") {}
+
+    std::string TypeName() override;
+    std::string SelectionType() override;
+    void ExtractSelection(Tcl_Obj* tcl_list, RTLIL::Module* module,
+                          Filters& filters, bool is_quiet) override;
+};
+
+#endif  // GET_CELLS_H_