예제 #1
0
        void GLShader::create(Block* _mem) {
            moti::MemoryReader reader(_mem->m_ptr, _mem->m_length);
            uint32_t magic(0);
            moti::read(&reader, magic);


            switch (magic) {
            case MOTI_VERTEX_SHADER_MAGIC: m_type = GL_VERTEX_SHADER; break;
            case MOTI_FRAGMENT_SHADER_MAGIC: m_type = GL_FRAGMENT_SHADER; break;
            default:
                MOTI_ASSERT(0, "unkown shader format %x", magic);
                break;
            }

            int32_t shaderSize;
            moti::read(&reader, shaderSize);

            m_id = glCreateShader(m_type);
            const char* src = reinterpret_cast<const char*>(reader.getPointer());

            GL_CHECK(glShaderSource(m_id, 1, (const GLchar**)&src, NULL));
            GL_CHECK(glCompileShader(m_id));

            GLint compiled(0);
            GL_CHECK(glGetShaderiv(m_id, GL_COMPILE_STATUS, &compiled));

            if (compiled == 0) {
                GLsizei len;
                char log[1024];
                GL_CHECK(glGetShaderInfoLog(m_id, sizeof(log), &len, log));
                MOTI_TRACE("Failed to compile shader %d: %s", compiled, log);
                GL_CHECK(glDeleteShader(m_id));
                m_id = 0;
            }
        }
예제 #2
0
XmlXPathObjectHelper
XPathExpr::eval(xmlXPathContextPtr context, const Context *ctx) const {
    try {
        XmlXPathObjectHelper xpathObj;
        if (compiled()) {
            xpathObj = XmlXPathObjectHelper(xmlXPathCompiledEval(
                    compiled_expr_.get(), context));
        }
        else {
            const std::string expr = expression(ctx);
            if (stripAllOutput(expr)) {
                xpathObj = XmlXPathObjectHelper(xmlXPathEvalExpression(
                        (const xmlChar *)STRIP_XPOINTER.c_str(), context));
            }
            else {
                xpathObj = XmlXPathObjectHelper(xmlXPathEvalExpression(
                        (const xmlChar *)expr.c_str(), context));
            }
        }
        XmlUtils::throwUnless(NULL != xpathObj.get());
        return xpathObj;
    }
    catch(const std::exception &e) {
        std::string message = "XPath error with expression " + expression(ctx) + " : ";
        message.append(e.what());
        throw std::runtime_error(message);
    }
}
예제 #3
0
 bool
 frameless() const
 {
     assert(!empty());
     assert(compiled());
     return (frame_clobbered_ == 0);
 }
예제 #4
0
 void
 leave(symbol_type _symbol, symbols_type _arguments)
 {
     assert(!empty());
     assert(compiled());
     assert(!(st.depth < output_));
     assert(!(clobbered_ < output_));
     assert(!(clobbered_ < input_));
     assert(_symbol.valid());
     symbol_ = std::move(_symbol);
     arguments_ = std::move(_arguments);
     assert(!(frame_clobbered_ < arity()));
     assert(!(frame_clobbered_ < climbing_));
 }
예제 #5
0
Result FunctionCompiler::compile() {
	assert(initialized() && "You must initialize a FunctionCompiler before you compile it");
	assert(compiled() == false && "You cannot compile a FunctionCompiler twice");

	// compile the entry
	auto entry = function().entryNode();
	assert(entry != nullptr);

	std::deque<std::pair<NodeInstance*, size_t>> nodesToCompile;
	nodesToCompile.emplace_back(entry, 0);

	Result res;

	auto compilePureDependencies = [this](NodeInstance& node) {
		Result res;

		auto depPures = dependentPuresRecursive(node);
		for (auto pure : depPures) {
			auto compiler = getOrCreateNodeCompiler(*pure);
			res += compiler->compile_stage2({}, 0);

			if (!res) { return res; }
		}
		return res;
	};

	while (!nodesToCompile.empty()) {
		auto& node        = *nodesToCompile[0].first;
		auto  inputExecID = nodesToCompile[0].second;

		assert(!node.type().pure());

		auto compiler = getOrCreateNodeCompiler(node);
		if (compiler->compiled(inputExecID)) {
			nodesToCompile.pop_front();

			continue;
		}

		// compile dependent pures
		res += compilePureDependencies(node);
		if (!res) { return res; }

		std::vector<llvm::BasicBlock*> outputBlocks;
		// make sure the output nodes have done stage 1 and collect output blocks
		for (const auto& conn : node.outputExecConnections) {
			res += compilePureDependencies(*conn.first);
			if (!res) { return res; }

			auto depCompiler = getOrCreateNodeCompiler(*conn.first);
			depCompiler->compile_stage1(conn.second);

			outputBlocks.push_back(&depCompiler->firstBlock(conn.second));
		}

		// compile this one
		res += compiler->compile_stage2(outputBlocks, inputExecID);
		if (!res) { return res; }

		// recurse
		for (const auto& conn : node.outputExecConnections) {
			// add them to the end
			nodesToCompile.emplace_back(conn.first, conn.second);
		}

		// pop it off
		nodesToCompile.pop_front();
	}

	if (!res) { return res; }

	llvm::IRBuilder<> allocBuilder{&allocBlock()};
	allocBuilder.CreateBr(&nodeCompiler(*entry)->firstBlock(0));

	return res;
}
예제 #6
0
u32 SPURecompilerDecoder::DecodeMemory(const u32 address)
{
	if (spu.offset != address - spu.pc || spu.pc >= 0x40000 || spu.pc % 4)
	{
		throw EXCEPTION("Invalid address or PC (address=0x%x, PC=0x%05x)", address, spu.pc);
	}

	// get SPU LS pointer
	const auto _ls = vm::ps3::_ptr<u32>(spu.offset);

	// always validate (TODO)
	const auto func = db->analyse(_ls, spu.pc);

	// reset callstack if necessary
	if (func->does_reset_stack && spu.recursion_level)
	{
		spu.m_state |= CPU_STATE_RETURN;

		return 0;
	}

	if (!func->compiled)
	{
		rec->compile(*func);

		if (!func->compiled) throw EXCEPTION("Compilation failed");
	}

	const u32 res = func->compiled(&spu, _ls);

	if (const auto exception = spu.pending_exception)
	{
		spu.pending_exception = nullptr;
		std::rethrow_exception(exception);
	}

	if (res & 0x1000000)
	{
		spu.halt();
	}

	if (res & 0x2000000)
	{
	}

	if (res & 0x4000000)
	{
		if (res & 0x8000000)
		{
			throw EXCEPTION("Undefined behaviour");
		}

		spu.set_interrupt_status(true);
	}
	else if (res & 0x8000000)
	{
		spu.set_interrupt_status(false);
	}

	spu.pc = res & 0x3fffc;

	return 0;
}
예제 #7
0
파일: shader.cpp 프로젝트: hpohl/wheezy
void BasicShader::compile() {
    glCompileShader(mName);
    if (!compiled())
        throw Exception("Failed to compile shader. Log: \n" + infoLog());
}
예제 #8
0
	inline int info(int *optptr, int *firstcharptr) const {
		_ASSERTE(compiled());
		return pcre_info(_Code::get(), optptr, firstcharptr);
	}
예제 #9
0
	// regexp info
	inline int fullinfo(int what, void *where) const {
		_ASSERTE(compiled() && where != 0);
		return pcre_fullinfo(_Code::get(), _Extra::get(), what, where);
	}
예제 #10
0
	// named subpatterns
	int get_stringnumber(const char *stringname) const throw(std::exception) {
		_ASSERTE(compiled());
		check_stringname(stringname);
		return pcre_get_stringnumber(_Code::get(), stringname);
	}
예제 #11
0
	// implicit conversion
	inline operator bool() const throw() { return compiled(); }
예제 #12
0
	// construction
	regexp() throw() { _ASSERTE(!compiled()); }
예제 #13
0
파일: shader.hpp 프로젝트: Wassasin/nebula
	void compile() {
		try_compile();
		if (!compiled()) throw gl_error{"gl::compile_shader", "Unable to compile shader:\n" + log()};
	}