Ejemplo n.º 1
0
ogles_context_t *ogles_init(size_t extra)
{
    void* const base = malloc(extra + sizeof(ogles_context_t) + 32);
    if (!base) return 0;

    ogles_context_t *c =
            (ogles_context_t *)((ptrdiff_t(base) + extra + 31) & ~0x1FL);
    memset(c, 0, sizeof(ogles_context_t));
    ggl_init_context(&(c->rasterizer));

    // XXX: this should be passed as an argument
    sp<EGLSurfaceManager> smgr(new EGLSurfaceManager());
    c->surfaceManager = smgr.get();
    c->surfaceManager->incStrong(c);

    sp<EGLBufferObjectManager> bomgr(new EGLBufferObjectManager());
    c->bufferObjectManager = bomgr.get();
    c->bufferObjectManager->incStrong(c);

    ogles_init_array(c);
    ogles_init_matrix(c);
    ogles_init_vertex(c);
    ogles_init_light(c);
    ogles_init_texture(c);

    c->rasterizer.base = base;
    c->point.size = TRI_ONE;
    c->line.width = TRI_ONE;

    // in OpenGL, writing to the depth buffer is enabled by default.
    c->rasterizer.procs.depthMask(c, 1);

    // OpenGL enables dithering by default
    c->rasterizer.procs.enable(c, GL_DITHER);

    return c;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	int i;
	bool bScale = false;
	double fScale = 0.0f;
	char * newFName = 0;

	DiffSimu smgr( argc, argv );

	if (argc < 2) {
		printHelp();
		exit(-1);
	}
	
	i = 1;
	while (i<argc) {
		if (strcmp("-s", argv[i]) == 0) {
			bScale = true;
			fScale =  atof( argv[++i] );
			newFName = argv[++i];
		}

		i++;
	}
	
	if (bScale) {
		Grid * g = smgr.getGrid();
		if (g != 0) {
			scaleGrid(g,fScale);
			DpReader dpr;
			dpr.SaveToFile(g,newFName);
		}
	}
	
	return(0);
}
Ejemplo n.º 3
0
ogles_context_t *ogles_init(size_t extra)
{
    void* const base = malloc(extra + sizeof(ogles_context_t) + 32);
    if (!base) return 0;

    ogles_context_t *c =
            (ogles_context_t *)((ptrdiff_t(base) + extra + 31) & ~0x1FL);
    memset(c, 0, sizeof(ogles_context_t));
    ggl_init_context(&(c->rasterizer));

    // XXX: this should be passed as an argument
    sp<EGLSurfaceManager> smgr(new EGLSurfaceManager());
    c->surfaceManager = smgr.get();
    c->surfaceManager->incStrong(c);

    sp<EGLBufferObjectManager> bomgr(new EGLBufferObjectManager());
    c->bufferObjectManager = bomgr.get();
    c->bufferObjectManager->incStrong(c);

    ogles_init_array(c);
    ogles_init_matrix(c);
    ogles_init_vertex(c);
    ogles_init_light(c);
    ogles_init_texture(c);

    c->rasterizer.base = base;
    c->point.size = TRI_ONE;
    c->line.width = TRI_ONE;

    // in OpenGL, writing to the depth buffer is enabled by default.
    c->rasterizer.procs.depthMask(c, 1);

    // OpenGL enables dithering by default
    c->rasterizer.procs.enable(c, GL_DITHER);

    c->copybits.blitEngine = NULL;
    c->copybits.minScale = 0;
    c->copybits.maxScale = 0;
    c->copybits.drawSurfaceBuffer = 0;

#ifdef LIBAGL_USE_GRALLOC_COPYBITS
    hw_module_t const* module;
    if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) {
        struct copybit_device_t* copyBits;
        if (copybit_open(module, &copyBits) == 0) {
            c->copybits.blitEngine = copyBits;
            {
                int minLim = copyBits->get(copyBits,
                        COPYBIT_MINIFICATION_LIMIT);
                if (minLim != -EINVAL && minLim > 0) {
                    c->copybits.minScale = (1 << 16) / minLim;
                }
            }
            {
                int magLim = copyBits->get(copyBits,
                        COPYBIT_MAGNIFICATION_LIMIT);
                if (magLim != -EINVAL && magLim > 0) {
                    c->copybits.maxScale = min(32*1024-1, magLim) << 16;
                }
            }
        }
    }
#endif // LIBAGL_USE_GRALLOC_COPYBITS

    return c;
}
Ejemplo n.º 4
0
void
NasmInsnRunner::TestInsn(yasm::Insn* insn,
                         std::size_t golden_len,
                         const unsigned char* golden,
                         const llvm::StringRef& ew_msg)
{
    //
    // Turn the instruction into bytes
    //
    BytecodeContainer container(0);

    ::testing::StrictMock<MockDiagnosticString> mock_consumer;
    llvm::IntrusiveRefCntPtr<DiagnosticIDs> diagids(new DiagnosticIDs);
    DiagnosticsEngine diags(diagids, &mock_consumer, false);
    FileSystemOptions opts;
    FileManager fmgr(opts);
    SourceManager smgr(diags, fmgr);
    diags.setSourceManager(&smgr);

    if (!ew_msg.empty())
    {
        EXPECT_CALL(mock_consumer, DiagString(ew_msg))
            .Times(1);
    }
    else
    {
        // expect no diagnostic calls
        EXPECT_CALL(mock_consumer, DiagString(::testing::_))
            .Times(0);
    }

    insn->Append(container, SourceLocation(), diags);

    container.Finalize(diags);
    if (diags.hasErrorOccurred())
        return;

    container.bytecodes_front().CalcLen(AddSpanTest, diags);
    ASSERT_EQ(golden_len, container.bytecodes_front().getTotalLen());
    if (diags.hasErrorOccurred())
        return;

    container.UpdateOffsets(diags);
    if (diags.hasErrorOccurred())
        return;

    llvm::SmallString<64> outbytes;
    llvm::raw_svector_ostream outstream(outbytes);
    RawOutput outputter(outstream, *m_arch, diags);
    container.bytecodes_front().Output(outputter);
    outstream.flush();

    //
    // Compare the result against the golden result
    //
    if (golden_len != outbytes.size())
        goto bad;

    for (std::size_t i=0; i<golden_len; ++i)
    {
        if ((int)(golden[i] & 0xff) != (int)(outbytes[i] & 0xff))
            goto bad;
    }

    return;

bad:
    std::string golden_str, outbytes_str;
    llvm::raw_string_ostream golden_ss(golden_str), outbytes_ss(outbytes_str);

    for (std::size_t i=0; i<golden_len; ++i)
        golden_ss << llvm::format("%02x ", (int)(golden[i] & 0xff));
    golden_ss.flush();

    for (std::size_t i=0; i<outbytes.size(); ++i)
        outbytes_ss << llvm::format("%02x ", (int)(outbytes[i] & 0xff));
    outbytes_ss.flush();

    ASSERT_EQ(golden_str, outbytes_str);
}
Ejemplo n.º 5
0
void
NasmInsnRunner::ParseAndTestLine(const char* filename,
                                 const llvm::StringRef& line,
                                 int linenum)
{
    SCOPED_TRACE(llvm::format("%s:%d", filename, linenum));

    llvm::StringRef insn_in, golden_in;
    llvm::tie(insn_in, golden_in) = line.split(';');

    insn_in = strip(insn_in);
    golden_in = strip(golden_in);

    // Handle bits directive
    if (golden_in.empty() && insn_in.startswith("[bits "))
    {
        int bits = atoi(insn_in.substr(6, 2).str().c_str());
        if (bits == 64)
            m_arch->setMachine("amd64");
        else
            m_arch->setMachine("x86");
        m_arch->setVar("mode_bits", bits);
        return;
    }

    if (insn_in.empty() || golden_in.empty())
        return;     // skip lines that don't have both text and a comment

    //
    // parse the golden result
    //
    llvm::SmallVector<unsigned char, 64> golden;
    llvm::StringRef golden_errwarn;

    for (;;)
    {
        // strip whitespace
        golden_in = strip(golden_in);
        if (golden_in.empty() || !isxdigit(golden_in[0]))
            break;

        unsigned int byte_val = 0x100;
        llvm::StringRef byte_str;
        llvm::tie(byte_str, golden_in) = golden_in.split(' ');

        if (byte_str.size() == 2)   // assume hex
            byte_val = (fromhexdigit(byte_str[0]) << 4)
                | fromhexdigit(byte_str[1]);
        else if (byte_str.size() == 3)  // assume octal
            byte_val = (fromoctdigit(byte_str[0]) << 6)
                | (fromoctdigit(byte_str[1]) << 3)
                | fromoctdigit(byte_str[2]);

        ASSERT_LE(byte_val, 0xffU) << "invalid golden value";
        golden.push_back(byte_val);
    }

    // interpret string in [] as error/warning
    if (!golden_in.empty() && golden_in[0] == '[')
        llvm::tie(golden_errwarn, golden_in) = golden_in.substr(1).split(']');

    //
    // parse the instruction
    //
    ::testing::StrictMock<MockDiagnosticString> mock_consumer;
    llvm::IntrusiveRefCntPtr<DiagnosticIDs> diagids(new DiagnosticIDs);
    DiagnosticsEngine diags(diagids, &mock_consumer, false);
    FileSystemOptions opts;
    FileManager fmgr(opts);
    SourceManager smgr(diags, fmgr);
    diags.setSourceManager(&smgr);

    // instruction name is the first thing on the line
    llvm::StringRef insn_name;
    llvm::tie(insn_name, insn_in) = insn_in.split(' ');
    Arch::InsnPrefix insnprefix =
        m_arch->ParseCheckInsnPrefix(insn_name, SourceLocation(), diags);
    ASSERT_TRUE(insnprefix.isType(Arch::InsnPrefix::INSN));
    std::auto_ptr<Insn> insn = m_arch->CreateInsn(insnprefix.getInsn());
    ASSERT_TRUE(insn.get() != 0) << "unrecognized instruction '"
        << insn_name.str() << "'";

    // parse insn arguments
    unsigned int wsize = m_arch_module->getWordSize();

    // strip whitespace from arguments
    insn_in = strip(insn_in);

    while (!insn_in.empty())
    {
        llvm::StringRef arg_str;
        llvm::tie(arg_str, insn_in) = insn_in.split(',');

        // strip whitespace from arg
        arg_str = strip(arg_str);

        unsigned int size = 0;
        bool strict = false;
        for (;;)
        {
            int next;
            int nsize = 0;
            // operand overrides (size and strict)
            if (arg_str.startswith("byte ")) { nsize = 8; next = 5; }
            else if (arg_str.startswith("hword ")) { nsize = wsize/2; next = 6; }
            else if (arg_str.startswith("word ")) { nsize = wsize; next = 5; }
            else if (arg_str.startswith("dword ")) { nsize = wsize*2; next = 6; }
            else if (arg_str.startswith("qword ")) { nsize = wsize*4; next = 6; }
            else if (arg_str.startswith("tword ")) { nsize = 80; next = 6; }
            else if (arg_str.startswith("dqword ")) { nsize = wsize*8; next = 7; }
            else if (arg_str.startswith("oword ")) { nsize = wsize*8; next = 6; }
            else if (arg_str.startswith("yword ")) { nsize = 256; next = 6; }
            else if (arg_str.startswith("strict ")) { strict = true; next = 7; }
            else break;

            if (size == 0)
                size = nsize;
            arg_str = arg_str.substr(next);
        }

        if (arg_str[0] == '[')
        {
            // Very simple int/reg expression parser.  Does not handle parens or
            // order of operations; simply builds expr from left to right.
            // This means r8*4+r9 will have a different result than r9+r8*4!
            // Also only handles binary operators * and +.
            llvm::StringRef estr = arg_str.slice(1, arg_str.find(']')+1);
            std::auto_ptr<Expr> e(new Expr);

            char pendingop = '\0';
            std::size_t tokstart = 0;
            for (std::size_t pos = 0; pos < estr.size(); ++pos)
            {
                if (estr[pos] == '*' || estr[pos] == '+' || estr[pos] == ']')
                {
                    // figure out this token
                    llvm::StringRef tok = strip(estr.slice(tokstart, pos));
                    if (isdigit(estr[tokstart]))
                        e->Append(strtoint(tok));
                    else
                    {
                        Arch::RegTmod regtmod =
                            m_arch->ParseCheckRegTmod(tok,
                                                      SourceLocation(),
                                                      diags);
                        ASSERT_TRUE(regtmod.isType(Arch::RegTmod::REG))
                            << "cannot handle label '" << tok.str() << "'";
                        e->Append(*regtmod.getReg());
                    }

                    // append pending operator
                    if (pendingop == '*')
                        e->AppendOp(Op::MUL, 2);
                    else if (pendingop == '+')
                        e->AppendOp(Op::ADD, 2);

                    // store new operator
                    pendingop = estr[pos];
                    tokstart = pos+1;
                }
            }

            Operand operand(m_arch->CreateEffAddr(e));
            operand.setSize(size);
            operand.setStrict(strict);
            insn->AddOperand(operand);
            continue;
        }

        // TODO: split by space to allow target modifiers

        // Test for registers
        Arch::RegTmod regtmod =
            m_arch->ParseCheckRegTmod(arg_str, SourceLocation(), diags);
        if (const Register* reg = regtmod.getReg())
        {
            Operand operand(reg);
            operand.setSize(size);
            operand.setStrict(strict);
            insn->AddOperand(operand);
            continue;
        }
        else if (const SegmentRegister* segreg = regtmod.getSegReg())
        {
            Operand operand(segreg);
            operand.setSize(size);
            operand.setStrict(strict);
            insn->AddOperand(operand);
            continue;
        }
        else if (regtmod.getTargetMod())
        {
            FAIL() << "cannot handle target modifier";
        }
        else if (regtmod.getRegGroup())
        {
            FAIL() << "cannot handle register group";
        }

        // Can't handle labels
        ASSERT_TRUE(isdigit(arg_str[0]) || arg_str[0] == '-')
            << "cannot handle label '" << arg_str.str() << "'";

        // Convert to integer expression
        Operand intop(Expr::Ptr(new Expr(strtoint(arg_str))));
        intop.setSize(size);
        intop.setStrict(strict);
        insn->AddOperand(intop);
    }

    TestInsn(insn.get(), golden.size(), golden.data(), golden_errwarn);
}