| 21 | |
| 22 | template<typename CodeCompiler> |
| 23 | bool SetSource(sd::ShaderType stage, const std::string& src, const std::string& entry, bv_stack* args = NULL, bv_library* library = NULL) |
| 24 | { |
| 25 | m_clear(); |
| 26 | |
| 27 | m_compiler = new CodeCompiler(); |
| 28 | m_compiler->SetImmediate(false); |
| 29 | |
| 30 | m_immCompiler = new CodeCompiler(); |
| 31 | m_immCompiler->SetImmediate(true); |
| 32 | |
| 33 | m_entry = entry; |
| 34 | m_library = library; |
| 35 | m_args = args; |
| 36 | m_prog = nullptr; |
| 37 | m_stepper = nullptr; |
| 38 | m_discarded = false; |
| 39 | |
| 40 | m_type = stage; |
| 41 | |
| 42 | bool done = m_compiler->Parse(stage, src, entry); |
| 43 | m_bytecode = m_compiler->GetBytecode(); |
| 44 | |
| 45 | if (done && m_bytecode.size() > 0) { |
| 46 | m_prog = bv_program_create(m_bytecode.data()); |
| 47 | if (m_prog == nullptr) |
| 48 | return false; // invalid bytecode |
| 49 | |
| 50 | m_prog->user_data = (void*)this; |
| 51 | bv_program_add_function(m_prog, "$$discard", Common::Discard); |
| 52 | |
| 53 | m_prog->property_getter = m_compiler->PropertyGetter; |
| 54 | m_prog->default_constructor = m_compiler->ObjectConstructor; |
| 55 | |
| 56 | bv_function* entryPtr = bv_program_get_function(m_prog, entry.c_str()); |
| 57 | if (entryPtr == nullptr) |
| 58 | return false; |
| 59 | |
| 60 | m_stepper = bv_function_stepper_create(m_prog, entryPtr, NULL, m_args); |
| 61 | |
| 62 | if (m_library != nullptr) |
| 63 | bv_program_add_library(m_prog, library); |
| 64 | } else return false; |
| 65 | |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | inline Compiler* GetCompiler() { return m_compiler; } |
| 70 |
nothing calls this directly
no test coverage detected