[Bf-blender-cvs] [2f2dd113efe] nodes_playground: ExecuteFunctionNode
Jacques Lucke
noreply at git.blender.org
Sun Jan 6 17:25:45 CET 2019
Commit: 2f2dd113efe66e8aad25322e9667648b03ee0620
Author: Jacques Lucke
Date: Sat Jan 5 15:45:25 2019 +0100
Branches: nodes_playground
https://developer.blender.org/rB2f2dd113efe66e8aad25322e9667648b03ee0620
ExecuteFunctionNode
===================================================================
M source/blender/modifiers/intern/node_compiler.hpp
M source/blender/modifiers/intern/node_compiler_testing.cpp
===================================================================
diff --git a/source/blender/modifiers/intern/node_compiler.hpp b/source/blender/modifiers/intern/node_compiler.hpp
index f0b8f8514cc..29a4dc69ca6 100644
--- a/source/blender/modifiers/intern/node_compiler.hpp
+++ b/source/blender/modifiers/intern/node_compiler.hpp
@@ -153,6 +153,47 @@ class SingleBuilderNode : public Node {
}
};
+class ExecuteFunctionNode : public Node {
+ virtual void *getExecuteFunction() = 0;
+
+ void buildLLVMIR(
+ std::vector<llvm::Value *> &inputs, llvm::IRBuilder<> *builder,
+ std::vector<llvm::Value *> &r_outputs, llvm::IRBuilder<> **r_builder)
+ {
+ llvm::LLVMContext &context = builder->getContext();
+
+ std::vector<llvm::Type *> arg_types;
+ for (auto socket : this->inputs()) {
+ arg_types.push_back(socket.type->getLLVMType(context));
+ }
+ std::vector<llvm::Value *> arguments = inputs;
+ std::vector<llvm::Value *> output_pointers;
+ for (auto socket : this->outputs()) {
+ llvm::Type *type = socket.type->getLLVMType(context);
+ arg_types.push_back(type->getPointerTo());
+ llvm::Value *alloced_ptr = builder->CreateAlloca(type);
+ output_pointers.push_back(alloced_ptr);
+ arguments.push_back(alloced_ptr);
+ }
+
+ llvm::FunctionType *ftype = llvm::FunctionType::get(
+ llvm::Type::getVoidTy(context), arg_types, false);
+
+ void *pointer = this->getExecuteFunction();
+ auto address_int = builder->getInt64((size_t)pointer);
+ auto address = builder->CreateIntToPtr(address_int, llvm::PointerType::get(ftype, 0));
+
+ builder->CreateCall(address, arguments);
+
+ for (auto output_pointer : output_pointers) {
+ llvm::Value *result = builder->CreateLoad(output_pointer);
+ r_outputs.push_back(result);
+ }
+
+ *r_builder = builder;
+ }
+};
+
struct Link {
AnySocket from, to;
diff --git a/source/blender/modifiers/intern/node_compiler_testing.cpp b/source/blender/modifiers/intern/node_compiler_testing.cpp
index cbe2ad7683e..9eaf9227346 100644
--- a/source/blender/modifiers/intern/node_compiler_testing.cpp
+++ b/source/blender/modifiers/intern/node_compiler_testing.cpp
@@ -1,3 +1,4 @@
+#include <iostream>
#include "node_compiler.hpp"
#include "BLI_utildefines.h"
@@ -5,8 +6,6 @@ extern "C" {
void WM_clipboard_text_set(const char *buf, bool selection);
}
-#include <iostream>
-
namespace NC = LLVMNodeCompiler;
class IntegerType : public NC::Type {
@@ -85,12 +84,13 @@ public:
}
};
-static void print_number(int number)
+static void print_number(int number, int *r_number)
{
std::cout << "The number is: " << number << std::endl;
+ *r_number = number + 42;
}
-class PrintIntegerNode : public NC::SingleBuilderNode {
+class PrintIntegerNode : public NC::ExecuteFunctionNode {
public:
PrintIntegerNode()
{
@@ -98,19 +98,9 @@ public:
this->m_outputs.add("Out", type_int32);
}
- void buildLLVMIR(
- llvm::IRBuilder<> *builder,
- std::vector<llvm::Value *> &inputs,
- std::vector<llvm::Value *> &r_outputs)
+ void *getExecuteFunction()
{
- llvm::LLVMContext &context = builder->getContext();
- llvm::FunctionType *ftype = llvm::FunctionType::get(
- llvm::Type::getVoidTy(context), {type_int32->getLLVMType(context)});
-
- auto address_int = builder->getInt64((size_t)&print_number);
- auto address = builder->CreateIntToPtr(address_int, llvm::PointerType::get(ftype, 0));
- builder->CreateCall(address, inputs[0]);
- r_outputs.push_back(inputs[0]);
+ return (void *)print_number;
}
};
More information about the Bf-blender-cvs
mailing list