[Bf-blender-cvs] [9539b402b8a] functions: initial Execution Stack

Jacques Lucke noreply at git.blender.org
Tue Mar 26 11:22:16 CET 2019


Commit: 9539b402b8a068c312018eda82b5ede1a9c5ca70
Author: Jacques Lucke
Date:   Tue Mar 26 09:52:14 2019 +0100
Branches: functions
https://developer.blender.org/rB9539b402b8a068c312018eda82b5ede1a9c5ca70

initial Execution Stack

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

M	source/blender/blenlib/BLI_small_stack.hpp
M	source/blender/functions/CMakeLists.txt
M	source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
A	source/blender/functions/backends/tuple_call/execution_context.cpp
M	source/blender/functions/backends/tuple_call/execution_context.hpp
M	source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
M	source/blender/functions/c_wrapper.cpp

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

diff --git a/source/blender/blenlib/BLI_small_stack.hpp b/source/blender/blenlib/BLI_small_stack.hpp
index 51abdc5fd2d..922b08e2fce 100644
--- a/source/blender/blenlib/BLI_small_stack.hpp
+++ b/source/blender/blenlib/BLI_small_stack.hpp
@@ -38,6 +38,16 @@ namespace BLI {
 			BLI_assert(!this->empty());
 			return m_elements[this->size() - 1];
 		}
+
+		T *begin() const
+		{
+			return m_elements.begin();
+		}
+
+		T *end() const
+		{
+			return m_elements.end();
+		}
 	};
 
 } /* namespace BLI */
\ No newline at end of file
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index ed8daf5d283..d92519da7b9 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -44,6 +44,7 @@ set(SRC
 	backends/tuple_call/lazy_to_normal.hpp
 	backends/tuple_call/lazy_to_normal.cpp
 	backends/tuple_call/execution_context.hpp
+	backends/tuple_call/execution_context.cpp
 
 	backends/dependencies/dependencies.hpp
 	backends/dependencies/dependencies.cpp
diff --git a/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp b/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
index cb301d9ed26..a96d6c65e4d 100644
--- a/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
+++ b/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
@@ -23,7 +23,8 @@ namespace FN {
 
 		fn_in.set_all_initialized();
 
-		ExecutionContext ctx;
+		ExecutionStack stack;
+		ExecutionContext ctx(stack);
 		body->call(fn_in, fn_out, ctx);
 
 		/* This way the data is not freed with the tuples. */
diff --git a/source/blender/functions/backends/tuple_call/execution_context.cpp b/source/blender/functions/backends/tuple_call/execution_context.cpp
new file mode 100644
index 00000000000..9ca4a219957
--- /dev/null
+++ b/source/blender/functions/backends/tuple_call/execution_context.cpp
@@ -0,0 +1,13 @@
+#include "FN_tuple_call.hpp"
+
+namespace FN {
+
+	void ExecutionStack::print_traceback() const
+	{
+		std::cout << "Traceback:" << std::endl;
+		for (const char *info : m_stack) {
+			std::cout << " > " << info << std::endl;
+		}
+	}
+
+} /* namespace FN */
\ No newline at end of file
diff --git a/source/blender/functions/backends/tuple_call/execution_context.hpp b/source/blender/functions/backends/tuple_call/execution_context.hpp
index e7b10ae1e02..f83d8dea2f6 100644
--- a/source/blender/functions/backends/tuple_call/execution_context.hpp
+++ b/source/blender/functions/backends/tuple_call/execution_context.hpp
@@ -1,9 +1,41 @@
 #pragma once
 
+#include "FN_core.hpp"
+
 namespace FN {
 
+	class ExecutionStack {
+	private:
+		SmallStack<const char *> m_stack;
+
+	public:
+		ExecutionStack() = default;
+
+		void push(const char *info)
+		{
+			m_stack.push(info);
+		}
+
+		void pop()
+		{
+			m_stack.pop();
+		}
+
+		void print_traceback() const;
+	};
+
 	class ExecutionContext {
+	private:
+		ExecutionStack &m_stack;
+
+	public:
+		ExecutionContext(ExecutionStack &stack)
+			: m_stack(stack) {}
 
+		ExecutionStack &stack() const
+		{
+			return m_stack;
+		}
 	};
 
 } /* namespace FN */
\ No newline at end of file
diff --git a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
index 9a760e88915..fc9233ee679 100644
--- a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
+++ b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
@@ -356,12 +356,17 @@ namespace FN {
 			auto *context = new llvm::LLVMContext();
 
 			for (Node *node : m_graph->all_nodes()) {
-				if (node->function()->has_body<TupleCallBody>()) {
+				SharedFunction &fn = node->function();
+				if (fn->has_body<TupleCallBody>()) {
 					continue;
 				}
 
-				if (node->function()->has_body<LLVMBuildIRBody>()) {
-					derive_TupleCallBody_from_LLVMBuildIRBody(node->function(), *context);
+				if (fn->has_body<LazyInTupleCallBody>()) {
+					derive_TupleCallBody_from_LazyInTupleCallBody(fn);
+				}
+
+				if (fn->has_body<LLVMBuildIRBody>()) {
+					derive_TupleCallBody_from_LLVMBuildIRBody(fn, *context);
 				}
 			}
 		}
@@ -386,7 +391,8 @@ namespace FN {
 			}
 			else {
 				Node *node = socket.node();
-				TupleCallBody *body = node->function()->body<TupleCallBody>();
+				SharedFunction &fn = node->function();
+				TupleCallBody *body = fn->body<TupleCallBody>();
 
 				FN_TUPLE_STACK_ALLOC(tmp_in, body->meta_in());
 				FN_TUPLE_STACK_ALLOC(tmp_out, body->meta_out());
@@ -395,7 +401,9 @@ namespace FN {
 					this->compute_socket(fn_in, tmp_in, i, node->input(i), ctx);
 				}
 
+				ctx.stack().push(fn->name().c_str());
 				body->call(tmp_in, tmp_out, ctx);
+				ctx.stack().pop();
 
 				Tuple::copy_element(tmp_out, socket.index(), out, out_index);
 			}
@@ -561,9 +569,9 @@ namespace FN {
 		SharedFunction &fn,
 		FunctionGraph &fgraph)
 	{
-		// fn->add_body(new ExecuteGraph(fgraph));
+		fn->add_body(new ExecuteGraph(fgraph));
 		// fn->add_body(new InterpretFGraph(fgraph));
-		fn->add_body(new LazyExecFGraph(fgraph));
+		// fn->add_body(new LazyExecFGraph(fgraph));
 	}
 
 } /* namespace FN */
\ No newline at end of file
diff --git a/source/blender/functions/c_wrapper.cpp b/source/blender/functions/c_wrapper.cpp
index bae6bc9ad79..a15781baf55 100644
--- a/source/blender/functions/c_wrapper.cpp
+++ b/source/blender/functions/c_wrapper.cpp
@@ -141,14 +141,17 @@ void FN_list_free_float(FnFloatList list)
 WRAPPERS(Tuple *, FnTuple);
 WRAPPERS(TupleCallBody *, FnTupleCallBody);
 
-void FN_tuple_call_invoke(FnTupleCallBody fn_call, FnTuple fn_in, FnTuple fn_out)
+void FN_tuple_call_invoke(FnTupleCallBody body, FnTuple fn_in, FnTuple fn_out)
 {
 	Tuple &fn_in_ = *unwrap(fn_in);
 	Tuple &fn_out_ = *unwrap(fn_out);
+	TupleCallBody *body_ = unwrap(body);
 
 	BLI_assert(fn_in_.all_initialized());
-	ExecutionContext ctx;
-	unwrap(fn_call)->call(fn_in_, fn_out_, ctx);
+	ExecutionStack stack;
+	stack.push(body_->owner()->name().c_str());
+	ExecutionContext ctx(stack);
+	body_->call(fn_in_, fn_out_, ctx);
 	BLI_assert(fn_out_.all_initialized());
 }



More information about the Bf-blender-cvs mailing list