Commit: 2ade7d581584a36680742d1d7cd094cfe5228c32
Author: Lukas Tönne
Date:   Wed May 18 07:45:52 2016 +0200
Branches: object_nodes
https://developer.blender.org/rB2ade7d581584a36680742d1d7cd094cfe5228c32

Type system refactor: Use a global type definition map instead of defining each 
type locally.

===================================================================

M       source/blender/blenvm/compile/bvm_codegen.cc
M       source/blender/blenvm/compile/bvm_function.cc
M       source/blender/blenvm/compile/node_graph.cc
M       source/blender/blenvm/compile/node_graph.h
M       source/blender/blenvm/compile/node_value.h
M       source/blender/blenvm/compile/typedesc.cc
M       source/blender/blenvm/compile/typedesc.h
M       source/blender/blenvm/intern/bvm_api.cc
M       source/blender/blenvm/llvm/llvm_codegen.cc
M       source/blender/blenvm/llvm/llvm_modules.cc
M       source/blender/blenvm/llvm/llvm_types.cc
M       source/blender/blenvm/llvm/llvm_types.h

===================================================================

diff --git a/source/blender/blenvm/compile/bvm_codegen.cc 
b/source/blender/blenvm/compile/bvm_codegen.cc
index ef021cf..1b88564 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -150,7 +150,8 @@ StackIndex BVMCompilerBase::find_stack_index(int size) const
 
 StackIndex BVMCompilerBase::assign_stack_index(const TypeDesc &typedesc)
 {
-       int stack_size = EvalStack::stack_size(typedesc.size());
+       const TypeSpec *typespec = typedesc.get_typespec();
+       int stack_size = EvalStack::stack_size(typespec->size());
        
        StackIndex stack_offset = find_stack_index(stack_size);
        for (int i = 0; i < stack_size; ++i) {
@@ -234,8 +235,10 @@ void BVMCompilerBase::resolve_symbols(const NodeGraph 
&graph)
 
 void BVMCompilerBase::push_constant(const NodeValue *value) const
 {
+       const TypeSpec *typespec = value->typedesc().get_typespec();
+       
        BLI_assert(value != NULL);
-       switch (value->typedesc().base_type()) {
+       switch (typespec->base_type()) {
                case BVM_FLOAT: {
                        float f = 0.0f;
                        value->get(&f);
@@ -296,7 +299,9 @@ void BVMCompilerBase::push_constant(const NodeValue *value) 
const
 
 void BVMCompilerBase::codegen_value(const NodeValue *value, StackIndex offset) 
const
 {
-       switch (value->typedesc().base_type()) {
+       const TypeSpec *typespec = value->typedesc().get_typespec();
+       
+       switch (typespec->base_type()) {
                case BVM_FLOAT: {
                        float f = 0.0f;
                        value->get(&f);
@@ -370,9 +375,11 @@ void BVMCompilerBase::codegen_value(const NodeValue 
*value, StackIndex offset) c
        }
 }
 
-static OpCode ptr_init_opcode(const TypeDesc &typedesc)
+static OpCode ptr_init_opcode(const TypeDesc &td)
 {
-       switch (typedesc.base_type()) {
+       const TypeSpec *typespec = td.get_typespec();
+       
+       switch (typespec->base_type()) {
                case BVM_FLOAT:
                case BVM_FLOAT3:
                case BVM_FLOAT4:
@@ -390,9 +397,11 @@ static OpCode ptr_init_opcode(const TypeDesc &typedesc)
        return OP_NOOP;
 }
 
-static OpCode ptr_release_opcode(const TypeDesc &typedesc)
+static OpCode ptr_release_opcode(const TypeDesc &td)
 {
-       switch (typedesc.base_type()) {
+       const TypeSpec *typespec = td.get_typespec();
+       
+       switch (typespec->base_type()) {
                case BVM_FLOAT:
                case BVM_FLOAT3:
                case BVM_FLOAT4:
diff --git a/source/blender/blenvm/compile/bvm_function.cc 
b/source/blender/blenvm/compile/bvm_function.cc
index ba0c282..6142361 100644
--- a/source/blender/blenvm/compile/bvm_function.cc
+++ b/source/blender/blenvm/compile/bvm_function.cc
@@ -97,8 +97,9 @@ void FunctionBVM::eval(EvalContext *context, const 
EvalGlobals *globals, const v
                const Argument &arg = argument(i);
                if (arg.stack_offset != BVM_STACK_INVALID) {
                        EvalStack *value = &stack[arg.stack_offset];
+                       const TypeSpec *typespec = arg.typedesc.get_typespec();
                        
-                       arg.typedesc.copy_value((void *)value, arguments[i]);
+                       typespec->copy_value((void *)value, arguments[i]);
                }
        }
        
@@ -108,8 +109,9 @@ void FunctionBVM::eval(EvalContext *context, const 
EvalGlobals *globals, const v
        for (int i = 0; i < num_return_values(); ++i) {
                const Argument &rval = return_value(i);
                EvalStack *value = &stack[rval.stack_offset];
+               const TypeSpec *typespec = rval.typedesc.get_typespec();
                
-               rval.typedesc.copy_value(results[i], (void *)value);
+               typespec->copy_value(results[i], (void *)value);
        }
 }
 
diff --git a/source/blender/blenvm/compile/node_graph.cc 
b/source/blender/blenvm/compile/node_graph.cc
index ba6f922..ea1af34 100644
--- a/source/blender/blenvm/compile/node_graph.cc
+++ b/source/blender/blenvm/compile/node_graph.cc
@@ -215,8 +215,7 @@ const NodeInput *NodeType::add_input(const string &name,
                                      BVMInputValueType value_type)
 {
        BLI_assert(!find_input(name));
-       BLI_assert(NodeGraph::has_typedef(type));
-       m_inputs.push_back(NodeInput(name, NodeGraph::find_typedef(type), 
default_value, value_type));
+       m_inputs.push_back(NodeInput(name, TypeDesc(type), default_value, 
value_type));
        return &m_inputs.back();
 }
 
@@ -225,10 +224,11 @@ const NodeOutput *NodeType::add_output(const string &name,
                                        BVMOutputValueType value_type)
 {
        BLI_assert(!find_output(name));
-       BLI_assert(NodeGraph::has_typedef(type));
+       
        /* local outputs only allowed for kernel nodes */
        BLI_assert(m_kind == NODE_TYPE_KERNEL || value_type != OUTPUT_VARIABLE);
-       m_outputs.push_back(NodeOutput(name, NodeGraph::find_typedef(type), 
value_type));
+       
+       m_outputs.push_back(NodeOutput(name, TypeDesc(type), value_type));
        return &m_outputs.back();
 }
 
@@ -514,8 +514,10 @@ bool NodeInstance::link_set(const string &name, const 
OutputKey &from)
 {
        const NodeInput *socket = type->find_input(name);
        InputInstance &input = inputs[name];
+       const TypeSpec *fromtype = from.socket->typedesc.get_typespec();
+       const TypeSpec *totype = socket->typedesc.get_typespec();
        
-       if (socket->typedesc.assignable(from.socket->typedesc)) {
+       if (totype->assignable(*fromtype)) {
                input.link = from;
                return true;
        }
@@ -587,51 +589,8 @@ void NodeBlock::prune(const NodeSet &used_nodes)
 
 /* ------------------------------------------------------------------------- */
 
-NodeGraph::TypeDefMap NodeGraph::typedefs;
 NodeGraph::NodeTypeMap NodeGraph::node_types;
 
-const TypeDesc &NodeGraph::find_typedef(const string &name)
-{
-       return typedefs.at(name);
-}
-
-bool NodeGraph::has_typedef(const string &name)
-{
-       return typedefs.find(name) != typedefs.end();
-}
-
-TypeDesc *NodeGraph::add_typedef(const string &name, BVMType base_type, 
BVMBufferType buffer_type)
-{
-       std::pair<TypeDefMap::iterator, bool> result =
-               typedefs.insert(TypeDefPair(name, TypeDesc(base_type, 
buffer_type)));
-       if (result.second) {
-               TypeDesc *typedesc = &result.first->second;
-               return typedesc;
-       }
-       else
-               return NULL;
-}
-
-TypeDesc *NodeGraph::add_typedef_struct(const string &name)
-{
-       std::pair<TypeDefMap::iterator, bool> result =
-               typedefs.insert(TypeDefPair(name, TypeDesc(BVM_INT)));
-       if (result.second) {
-               TypeDesc *typedesc = &result.first->second;
-               typedesc->make_structure();
-               return typedesc;
-       }
-       else
-               return NULL;
-}
-
-void NodeGraph::remove_typedef(const string &name)
-{
-       TypeDefMap::iterator it = typedefs.find(name);
-       if (it != typedefs.end())
-               typedefs.erase(it);
-}
-
 const NodeType *NodeGraph::find_node_type(const string &name)
 {
        NodeTypeMap::const_iterator it = node_types.find(name);
@@ -758,27 +717,29 @@ void NodeGraph::set_output_socket(const string &name, 
const OutputKey &key)
 const NodeGraph::Input *NodeGraph::add_input(const string &name, const string 
&type)
 {
        BLI_assert(!get_input(name));
-       const TypeDesc &typedesc = find_typedef(type);
-       inputs.push_back(Input(name, typedesc, add_argument_node(typedesc)));
+       TypeDesc td(type);
+       inputs.push_back(Input(name, td, add_argument_node(td)));
        return &inputs.back();
 }
 
 const NodeGraph::Output *NodeGraph::add_output(const string &name, const 
string &type, NodeValue *default_value)
 {
        BLI_assert(!get_output(name));
-       const TypeDesc &typedesc = find_typedef(type);
-       outputs.push_back(Output(name, typedesc, add_proxy(typedesc, 
default_value)->output(0)));
+       TypeDesc td(type);
+       outputs.push_back(Output(name, td, add_proxy(td, 
default_value)->output(0)));
        return &outputs.back();
 }
 
 /* ------------------------------------------------------------------------- */
 
-NodeInstance *NodeGraph::add_proxy(const TypeDesc &typedesc, NodeValue 
*default_value)
+NodeInstance *NodeGraph::add_proxy(const TypeDesc &td, NodeValue 
*default_value)
 {
+       const TypeSpec *typespec = td.get_typespec();
+       
        NodeInstance *node = NULL;
-       switch (typedesc.buffer_type()) {
+       switch (typespec->buffer_type()) {
                case BVM_BUFFER_SINGLE:
-                       switch (typedesc.base_type()) {
+                       switch (typespec->base_type()) {
                                case BVM_FLOAT: node = add_node("PASS_FLOAT"); 
break;
                                case BVM_FLOAT3: node = 
add_node("PASS_FLOAT3"); break;
                                case BVM_FLOAT4: node = 
add_node("PASS_FLOAT4"); break;
@@ -791,7 +752,7 @@ NodeInstance *NodeGraph::add_proxy(const TypeDesc 
&typedesc, NodeValue *default_
                        }
                        break;
                case BVM_BUFFER_ARRAY:
-                       switch (typedesc.base_type()) {
+                       switch (typespec->base_type()) {
                                case BVM_FLOAT: node = 
add_node("PASS_FLOAT_ARRAY"); break;
                                case BVM_FLOAT3: node = 
add_node("PASS_FLOAT3_ARRAY"); break;
                                case BVM_FLOAT4: node = 
add_node("PASS_FLOAT4_ARRAY"); break;
@@ -804,7 +765,7 @@ NodeInstance *NodeGraph::add_proxy(const TypeDesc 
&typedesc, NodeValue *default_
                        }
                        break;
                case BVM_BUFFER_IMAGE:
-                       switch (typedesc.base_type()) {
+                       switch (typespec->base_type()) {
                                case BVM_FLOAT: node = 
add_node("PASS_FLOAT_IMAGE"); break;
                                case BVM_INT: node = 
add_node("PASS_INT_IMAGE"); break;
                        }
@@ -817,8 +778,10 @@ NodeInstance *NodeGraph::add_proxy(const TypeDesc 
&typedesc, NodeValue *default_
 
 OutputKey NodeGraph::add_value_node(NodeValue *value)
 {
+       const TypeSpec *typespec = value->typedesc().get_typespec();
+       
        NodeInstance *node = NULL;
-       switch (value->typedesc().base_type()) {
+       switch (typespec->base_type()) {
                case BVM_FLOAT: node = add_node("VALUE_FLOAT"); break;
                case BVM_FLOAT3: node = add_node("VALUE_FLOAT3"); break;
                case BVM_FLOAT4: node = add_node("VALUE_FLOAT4"); break;
@@ -834,10 +797,12 @@ OutputKey NodeGraph::add_value_node(NodeValue *value)
        return OutputKey(node, "value");
 }
 
-OutputKey NodeGraph::add_argument_node(const TypeDesc &typedesc)
+OutputKey NodeGraph::add_argument_node(const TypeDesc &td)
 {
+       const TypeSpec *typespec = td.get_typespec();
+       
        NodeInstance *node = NULL;
-       switch (typedesc.base_type()) {
+       switch (typespec->base_type()) {
                case BVM_FLOAT: node = add_node("ARG_FLOAT"); break;
                case BVM_FLOAT3: node = add_node("ARG_FLOAT3"); break;
                case BVM_FLOAT4: node = add_node("ARG_FLOAT4"); break;
@@ -1254,44 +1219,44 @@ void NodeGraph::finalize()
 
 static void register_typedefs()
 {
-       TypeDesc *t;
+       TypeSpec *t;
        
-       t = NodeGraph::add_typedef("FLOAT", BVM_FLOAT);
+       t = TypeSpec::add_typedef("FLOAT", BVM_FLOAT);
        
-       t = NodeGraph::add_typedef("FLOAT3", BVM_FLOAT3);
+       t = TypeSpec::add_typedef("FLOAT3", BVM_FLOAT3);
        
-       t = NodeGraph::add_typedef("FLOAT4", BVM_FLOAT4);
+       t = TypeSpec::add_type

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to