[Bf-blender-cvs] [5a5dcc5] object_nodes: Copied the nodegraph classes from the llvm test branch.
Lukas Tönne
noreply at git.blender.org
Tue Nov 24 09:42:48 CET 2015
Commit: 5a5dcc509da6b4626d31f195ecbe953586b95f35
Author: Lukas Tönne
Date: Thu Oct 8 15:11:16 2015 +0200
Branches: object_nodes
https://developer.blender.org/rB5a5dcc509da6b4626d31f195ecbe953586b95f35
Copied the nodegraph classes from the llvm test branch.
===================================================================
M source/blender/blenvm/CMakeLists.txt
A source/blender/blenvm/intern/bvm_nodegraph.cc
A source/blender/blenvm/intern/bvm_nodegraph.h
A source/blender/blenvm/intern/bvm_type_desc.h
===================================================================
diff --git a/source/blender/blenvm/CMakeLists.txt b/source/blender/blenvm/CMakeLists.txt
index 39a78f5..953d22b 100644
--- a/source/blender/blenvm/CMakeLists.txt
+++ b/source/blender/blenvm/CMakeLists.txt
@@ -39,12 +39,15 @@ set(SRC
intern/bvm_expression.cc
intern/bvm_function.cc
intern/bvm_module.cc
+ intern/bvm_nodegraph.cc
intern/bvm_schedule.cc
intern/bvm_expression.h
intern/bvm_function.h
intern/bvm_module.h
+ intern/bvm_nodegraph.h
intern/bvm_schedule.h
+ intern/bvm_type_desc.h
util/bvm_util_hash.h
util/bvm_util_map.h
diff --git a/source/blender/blenvm/intern/bvm_nodegraph.cc b/source/blender/blenvm/intern/bvm_nodegraph.cc
new file mode 100644
index 0000000..8d8c5e1
--- /dev/null
+++ b/source/blender/blenvm/intern/bvm_nodegraph.cc
@@ -0,0 +1,518 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenvm/intern/bvm_nodegraph.cc
+ * \ingroup bvm
+ */
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "bvm_nodegraph.h"
+
+namespace bvm {
+
+NodeSocket::NodeSocket(const std::string &name, BVMType type, Value *default_value) :
+ name(name),
+ type(type),
+ default_value(default_value)
+{
+}
+
+NodeSocket::~NodeSocket()
+{
+}
+
+/* ------------------------------------------------------------------------- */
+
+NodeType::NodeType(const std::string &name) :
+ name(name)
+{
+}
+
+NodeType::~NodeType()
+{
+}
+
+const NodeSocket *NodeType::find_input(int index) const
+{
+ BLI_assert(index >= 0 && index < inputs.size());
+ return &inputs[index];
+}
+
+const NodeSocket *NodeType::find_output(int index) const
+{
+ BLI_assert(index >= 0 && index < outputs.size());
+ return &outputs[index];
+}
+
+const NodeSocket *NodeType::find_input(const std::string &name) const
+{
+ for (SocketList::const_iterator it = inputs.begin(); it != inputs.end(); ++it) {
+ const NodeSocket &socket = *it;
+ if (socket.name == name)
+ return &socket;
+ }
+ return NULL;
+}
+
+const NodeSocket *NodeType::find_output(const std::string &name) const
+{
+ for (SocketList::const_iterator it = outputs.begin(); it != outputs.end(); ++it) {
+ const NodeSocket &socket = *it;
+ if (socket.name == name)
+ return &socket;
+ }
+ return NULL;
+}
+
+/* stub implementation in case socket is passed directly */
+const NodeSocket *NodeType::find_input(const NodeSocket *socket) const
+{
+ return socket;
+}
+
+const NodeSocket *NodeType::find_output(const NodeSocket *socket) const
+{
+ return socket;
+}
+
+#if 0
+bool NodeType::verify_argument_socket(NodeSocket &socket, Type *type, int /*index*/,
+ Module *module, LLVMContext &context, raw_ostream &err)
+{
+ BVMType tid = bjit_find_llvm_typeid(type, context, module);
+ if (tid == BJIT_TYPE_UNKNOWN) {
+ err << "Unknown output type: ";
+ type->print(err);
+ err << "\n";
+ return false;
+ }
+
+ if (tid != socket.type) {
+ err << "Output type %d mismatch: ";
+ err << "argument type '" << bjit_get_socket_type_name(tid) << "' expected, ";
+ err << "got '" << bjit_get_socket_type_name(socket.type) << "'\n";
+ return false;
+ }
+
+ return true;
+}
+
+bool NodeType::verify_arguments(Module *module, LLVMContext &context, raw_ostream &err)
+{
+ Function *fn = bjit_find_external_function(module, name);
+ if (!fn)
+ return false;
+
+ int num_args = fn->arg_size();
+ int num_inputs = num_args;
+ int num_outputs = 1;
+ Type *rstruct = NULL;
+
+ Function::arg_iterator it = fn->arg_begin();
+ if (it != fn->arg_end()) {
+ Argument &arg = *it;
+ if (arg.hasStructRetAttr()) {
+ rstruct = arg.getType();
+ num_inputs = num_args - 1;
+ num_outputs = rstruct->getStructNumElements();
+
+ ++it;
+ }
+ }
+
+ /* add return fields as outputs */
+ if (num_inputs != inputs.size()) {
+ err << "Inputs number " << inputs.size() << " does not match arguments (" << num_inputs << ")\n";
+ return false;
+ }
+ if (num_outputs != outputs.size()) {
+ err << "Outputs number " << outputs.size() << " does not match return arguments (" << num_outputs << ")\n";
+ return false;
+ }
+
+ for (int i = 0; it != fn->arg_end(); ++it, ++i) {
+// Argument &arg = *it;
+
+ /* TODO fuzzy name check could help here? */
+// if (arg.getName() != inputs[i].name) ...
+
+ Type *type = rstruct->getStructElementType(i);
+ if (!verify_argument_socket(inputs[i], type, i, module, context, err))
+ return false;
+ }
+
+ for (int i = 0; i < num_outputs; ++i) {
+ Type *type = rstruct->getStructElementType(i);
+ if (!verify_argument_socket(outputs[i], type, i, module, context, err))
+ return false;
+ }
+
+ return true;
+}
+#endif
+
+const NodeSocket *NodeType::add_input(const std::string &name, BVMType type, Value *default_value)
+{
+ BLI_assert(!find_input(name));
+ inputs.push_back(NodeSocket(name, type, default_value));
+ return &inputs.back();
+}
+
+const NodeSocket *NodeType::add_output(const std::string &name, BVMType type, Value *default_value)
+{
+ BLI_assert(!find_output(name));
+ outputs.push_back(NodeSocket(name, type, default_value));
+ return &outputs.back();
+}
+
+/* ------------------------------------------------------------------------- */
+
+NodeInstance::NodeInstance(const NodeType *type, const std::string &name) :
+ type(type), name(name)
+{
+}
+
+NodeInstance::~NodeInstance()
+{
+}
+
+NodeInstance *NodeInstance::find_input_link_node(const std::string &name) const
+{
+ InputMap::const_iterator it = inputs.find(name);
+ return (it != inputs.end()) ? it->second.link_node : NULL;
+}
+
+NodeInstance *NodeInstance::find_input_link_node(int index) const
+{
+ const NodeSocket *socket = type->find_input(index);
+ return socket ? find_input_link_node(socket->name) : NULL;
+}
+
+const NodeSocket *NodeInstance::find_input_link_socket(const std::string &name) const
+{
+ InputMap::const_iterator it = inputs.find(name);
+ return (it != inputs.end()) ? it->second.link_socket : NULL;
+}
+
+const NodeSocket *NodeInstance::find_input_link_socket(int index) const
+{
+ const NodeSocket *socket = type->find_input(index);
+ return socket ? find_input_link_socket(socket->name) : NULL;
+}
+
+const NodeGraphInput *NodeInstance::find_input_extern(const std::string &name) const
+{
+ InputMap::const_iterator it = inputs.find(name);
+ return (it != inputs.end()) ? it->second.graph_input : NULL;
+}
+
+const NodeGraphInput *NodeInstance::find_input_extern(int index) const
+{
+ const NodeSocket *socket = type->find_input(index);
+ return socket ? find_input_extern(socket->name) : NULL;
+}
+
+Value *NodeInstance::find_input_value(const std::string &name) const
+{
+ InputMap::const_iterator it = inputs.find(name);
+ return (it != inputs.end()) ? it->second.value : NULL;
+}
+
+Value *NodeInstance::find_input_value(int index) const
+{
+ const NodeSocket *socket = type->find_input(index);
+ return socket ? find_input_value(socket->name) : NULL;
+}
+
+Value *NodeInstance::find_output_value(const std::string &name) const
+{
+ OutputMap::const_iterator it = outputs.find(name);
+ return (it != outputs.end()) ? it->second.value : NULL;
+}
+
+Value *NodeInstance::find_output_value(int index) const
+{
+ const NodeSocket *socket = type->find_output(index);
+ return socket ? find_output_value(socket->name) : NULL;
+}
+
+bool NodeInstance::set_input_value(const std::string &name, Value *value)
+{
+ InputInstance &input = inputs[name];
+ if (input.value)
+ return false;
+ input.value = value;
+ return true;
+}
+
+bool NodeInstance::set_input_link(const std::string &name, NodeInstance *from_node, const NodeSocket *from_socket)
+{
+ InputInstance &input = inputs[name];
+ if (input.link_node && input.link_socket)
+ return false;
+
+ input.link_node = from_node;
+ input.link_socket = from_socket;
+ return true;
+}
+
+bool NodeInstance::set_input_extern(const std::string &name, const NodeGraphInput *graph_input)
+{
+ InputInstance &input = inputs[name];
+ if (input.graph_input)
+ return false;
+
+ input.graph_input = graph_input;
+ return true;
+}
+
+bool NodeInstance::has_input_link(const std::string &name) const
+{
+ InputMap::const_iterator it = inputs.find(name);
+ if (it != inputs.end()) {
+ const InputInstance &input = it->second;
+ return (input.link_node && input.link_socket);
+ }
+ else
+ return false;
+}
+
+bool NodeInstance::has_input_link(int index) const
+{
+ const NodeSocket *socket = type->find_input(index);
+ return socket ? has_input_link(socket->name) : false;
+}
+
+bool NodeInstance::has_input_extern(const std::string &name) const
+{
+ InputMap::const_iterator it = inputs.find(name);
+ if (it != inputs.end()) {
+ const InputInstance &input = it->second;
+ return (input.graph_input);
+ }
+ else
+ return false;
+}
+
+bool NodeInstance::has_input_extern(int index) const
+{
+ const NodeSocket *socket = type->find_input(index);
+ return socket ? has_input_extern(socket->name) : false;
+}
+
+bool NodeInstance::has_input_value(const std::string &name) const
+{
+ InputMap::const_iterator it = inputs.find(name);
+ if (it != inputs.end()) {
+ const InputInstance &input = it->second;
+ return (input.value);
+ }
+ else
+ return false;
+}
+
+bool NodeInstance::has_input_value(int index) const
+{
+ const NodeSocket *socket = type->find_input(index);
+ return socket ? has_input_value(socket->name) : false;
+}
+
+bool NodeInstance::set_o
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list