Example #1
0
TEST_F(TestIRVisitor, TestWalker)
{
    IRTypes types;
    IRValue* condVar =
        new IRLocalVar("cond", types.GetBoolTy(), kIRUniform, NULL);
    IRStmt* thenStmt = MakeBlock(&types);
    IRStmt* elseStmt = MakeBlock(&types, true);
    IRIfStmt ifStmt(condVar, thenStmt, elseStmt, IRPos());
    Walker().Dispatch<void>(&ifStmt, 0);
}
Example #2
0
TEST_F(TestIRStmt, TestForStmtWithTwoCondStmts)
{
    IRTypes types;
    IRValue* condVar =
        new IRLocalVar("cond", types.GetBoolTy(), kIRUniform, NULL);
    IRStmt* condStmt = MakeBlock(&types, true);
    IRStmt* iterateStmt = new IRSeq();
    IRStmt* body = MakeBlock(&types, true);
    IRForLoop forStmt(condStmt, condVar, iterateStmt, body, IRPos());
    std::cout << forStmt;
}
Example #3
0
TEST_F(TestIRStmt, TestIlluminateStmt)
{
    IRTypes types;
    IRStmt* condStmt = MakeBlock(&types);
    IRGlobalVar pos("P", types.GetPointTy(), kIRVarying, NULL, false);
    IRValues args;
    args.push_back(&pos);
    IRStmt* body = MakeBlock(&types);
    IRIlluminateStmt illum(false, args, body, IRPos());
    std::cout << illum;
}
Example #4
0
TEST_F(TestIRStmt, TestIlluminanceStmt)
{
    IRTypes types;
    IRStmt* condStmt = MakeBlock(&types);
    IRValue* category = new IRStringConst("");
    IRGlobalVar pos("P", types.GetPointTy(), kIRVarying, NULL, false);
    IRValues args;
    args.push_back(&pos);
    IRStmt* body = MakeBlock(&types);
    IRIlluminanceLoop illum(category, args, body, IRPos());
    std::cout << illum;
}
Example #5
0
TEST_F(TestIRStmt, TestGatherStmt)
{
    IRTypes types;
    IRStmt* condStmt = MakeBlock(&types);
    IRValue* category = new IRStringConst("illuminance");
    IRGlobalVar pos("P", types.GetPointTy(), kIRVarying, NULL, false);
    IRValues args;
    args.push_back(&pos);
    IRStmt* body = MakeBlock(&types, true);
    IRStmt* elseStmt = MakeBlock(&types);
    IRGatherLoop gather(category, args, body, elseStmt, IRPos());
    std::cout << gather;
}
Example #6
0
TEST_F(TestIRStmt, TestBlock)
{
    IRTypes types;
    IRBlock* b = MakeBlock(&types);
    std::cout << *b;

    IRInsts insts = b->GetInsts();
    ASSERT_EQ(1U, insts.size());
    IRInsts::const_iterator it = insts.begin();
    IRInst* i1 = *it++;
    EXPECT_EQ(kIRBasicInst, i1->GetKind());
    EXPECT_EQ(types.GetFloatTy(), i1->GetType());
    EXPECT_EQ(kIRUniform, i1->GetDetail());

    // Test casting
    const IRStmt* s1 = UtStaticCast<const IRStmt*>(b);
    const IRStmt* s2 = UtCast<const IRStmt*>(b);
    EXPECT_TRUE(s2 != NULL);

    const IRStmt* s3 = UtStaticCast<const IRBlock*>(s1);
    const IRStmt* s4 = UtCast<const IRBlock*>(s2);
    EXPECT_TRUE(s4 != NULL);

    delete b;
}
Example #7
0
// 블럭 초기 설정
void Block::Init()
{
	int i, j;
	// 랜덤 seed 값 넣기
	srand( (unsigned)time( NULL ) );

	// 화면 배열 초기화
	for( i = 0; i < MAX_SIZE_Y - 1; ++i )
	{
		for( j = 0; j < MAX_SIZE_X; ++j )
		{
			if( (j == 0) || (j == MAX_SIZE_X - 1) )
			{
				m_total_block[i][j] = 1;
			}
			else {
				m_total_block[i][j] = 0;
			}
		}
	}

	// 화면 맨 밑줄을 1로 채운다.
	for( j = 0; j < MAX_SIZE_X; ++j )
		m_total_block[MAX_SIZE_Y - 1][j] = 1;

	m_shape = MakeBlock();
	block_start( &m_angle, &m_x, &m_y );
	m_block_state = 0;
	m_oldTime = clock();
	m_moveTime = 1000;
	screen = Screen::Instance();
}
Example #8
0
TEST_F(TestIRStmt, TestSeq)
{
    IRTypes types;
    IRStmts* stmts = new IRStmts;
    IRStmt* b1 = MakeBlock(&types);
    IRStmt* b2 = new IRBlock(new IRInsts); // empty block.
    stmts->push_back(b1);
    stmts->push_back(b2);
    IRSeq seq(stmts);
    std::cout << seq;

    IRStmts got = seq.GetStmts();
    ASSERT_EQ(2U, got.size());
    IRStmts::const_iterator it = got.begin();
    EXPECT_EQ(b1, *it++);
    EXPECT_EQ(b2, *it++);

    // Test casting
    const IRStmt* s1 = UtStaticCast<const IRStmt*>(&seq);
    const IRStmt* s2 = UtCast<const IRStmt*>(&seq);
    EXPECT_TRUE(s2 != NULL);

    const IRStmt* s3 = UtStaticCast<const IRSeq*>(s1);
    const IRStmt* s4 = UtCast<const IRSeq*>(s2);
    EXPECT_TRUE(s4 != NULL);
}
Example #9
0
Mat::Mat(Int rows, Int cols, Block k) : rows(rows), cols(cols)
{
    Assert(rows > 0 && cols > 0, "(Mat) illegal matrix size");

    data = new Real[rows * cols];

    MakeBlock(k);
}
Example #10
0
void Block::NextBlockInit()
{
	m_shape = next_block_shape;
	next_block_shape = MakeBlock();

	block_start( &m_angle, &m_x, &m_y );	//angle,x,y는 포인터임
	m_block_state = 0;
}
Example #11
0
TEST_F(TestIRStmt, TestForStmtWithComplexIterStmt)
{
    IRTypes types;

    IRValue* ifVar =
        new IRLocalVar("p", types.GetBoolTy(), kIRUniform, NULL);
    IRStmt* thenStmt = MakeBlock(&types);
    IRStmt* elseStmt = new IRSeq();
    IRIfStmt* ifStmt = new IRIfStmt(ifVar, thenStmt, elseStmt, IRPos());

    IRStmts* stmts = new IRStmts;
    stmts->push_back(ifStmt);
    stmts->push_back(MakeBlock(&types, true));
    IRStmt* seq = new IRSeq(stmts);

    IRValue* loopVar =
        new IRLocalVar("cond", types.GetBoolTy(), kIRUniform, NULL);
    IRStmt* condStmt = new IRSeq();
    IRStmt* iterateStmt = seq;
    IRStmt* body = MakeBlock(&types);
    IRForLoop forStmt(condStmt, loopVar, iterateStmt, body, IRPos());
    std::cout << forStmt;
}    
Example #12
0
/*
 * HeapCreate()
 *
 * Allocate a block of memory equal to (elementsize * numperblock) from
 * which smaller blocks can be suballocated.  This improves efficiency by
 * reducing multiple calls to malloc() during netjoins etc.
 * Returns a pointer to new heap
 */
Heap *HeapCreate(size_t elementsize, int numperblock)
{
  Heap *hptr;

  hptr = (Heap *) MyMalloc(sizeof(Heap));

  hptr->ElementSize = elementsize;
  hptr->ElementsPerBlock = numperblock;
  hptr->NumSubBlocks = 0;
  hptr->FreeElements = 0;
  hptr->base = (SubBlock *) NULL;

  /* Now create the first sub block in our heap; hptr->base will point to
   * it */
  MakeBlock(hptr);

  return(hptr);
} /* HeapCreate() */
Example #13
0
//=============================================================================
//	eTape::ParseTAP
//-----------------------------------------------------------------------------
bool eTape::ParseTAP(const void* data, size_t data_size)
{
	const byte* ptr = (const byte*)data;
	CloseTape();
	while(ptr < (const byte*)data + data_size)
	{
		dword size = Word(ptr);
		ptr += 2;
		if(!size)
			break;
		AllocInfocell();
		Desc(ptr, size, tapeinfo[tape_infosize].desc);
		tape_infosize++;
		MakeBlock(ptr, size, 2168, 667, 735, 855, 1710, (*ptr < 4) ? 8064
				: 3220, 1000);
		ptr += size;
	}
	FindTapeSizes();
	return (ptr == (const byte*)data + data_size);
}
Example #14
0
TEST_F(TestIRStmt, TestIfStmt)
{
    IRTypes types;
    IRValue* condVar =
        new IRLocalVar("cond", types.GetBoolTy(), kIRUniform, NULL);
    IRStmt* thenStmt = MakeBlock(&types);
    IRStmt* elseStmt = new IRSeq();
    IRIfStmt ifStmt(condVar, thenStmt, elseStmt, IRPos());
    std::cout << ifStmt;

    EXPECT_EQ(condVar, ifStmt.GetCond());
    EXPECT_EQ(thenStmt, ifStmt.GetThen());
    EXPECT_EQ(elseStmt, ifStmt.GetElse());

    // Test casting
    const IRStmt* s1 = UtStaticCast<const IRStmt*>(&ifStmt);
    const IRStmt* s2 = UtCast<const IRStmt*>(&ifStmt);
    EXPECT_TRUE(s2 != NULL);

    const IRStmt* s3 = UtStaticCast<const IRIfStmt*>(s1);
    const IRStmt* s4 = UtCast<const IRIfStmt*>(s2);
    EXPECT_TRUE(s4 != NULL);
}
Example #15
0
TSparseMat::TSparseMat(Int rows, Int cols, Block k) : row(0)
{
	SetSize(rows, cols);
	MakeBlock(k);
}
Example #16
0
/*
 * BlockSubAllocate()
 *
 * Find an unused chunk of memory to use for a structure, in one of
 * heapptr's sub blocks, and return a pointer to it; If there are no free
 * elements in the current sub blocks, allocate a new block
 */
void *BlockSubAllocate(Heap *heapptr)
{
  SubBlock *subptr;
  unsigned long offset;

  if (!heapptr)
    return(NULL);

  if (heapptr->FreeElements == 0)
  {
    /* There are no free slots left anywhere, allocate a new sub block */
    MakeBlock(heapptr);

    /* New sub block is inserted in the beginning of the chain */
    if (!(subptr = heapptr->base))
      return(NULL);

    subptr->FreeElements--;
    heapptr->FreeElements--;

    /* return the first slot */
    return(subptr->first);

  }

  /* Walk through each sub block trying to find a free slot */
  for (subptr = heapptr->base; subptr; subptr = subptr->next)
  {
    if (subptr->FreeElements == 0)
    {
      /* there are no unused slots in this sub block */
      continue;
    }

    if (subptr->LastSlotHole == 0)
    {
      /*
       * There are no "holes" in the block (ie: there are no empty slots
       * between elements in the block that need to be filled), so just
       * use the slot right after the last element in the block
       */
      offset = (unsigned long) ((heapptr->ElementsPerBlock
            - subptr->FreeElements) * heapptr->ElementSize);
    #if 0
      debug("ElsPerBlock-FreeEls=[%d], offset=[%d] addy=[%p]\n",
        heapptr->ElementsPerBlock - subptr->FreeElements, offset,
        (void *) ((unsigned long) subptr->first + offset));
    #endif

      heapptr->FreeElements--;
      subptr->FreeElements--;
      subptr->LastUsedSlot = (void *) ((unsigned long) subptr->first + offset);

      /* Why duplicating code? -kre */
      /* return((void *) ((unsigned long) subptr->first + offset)); */

      return(subptr->LastUsedSlot);
    }
    else
    {
      int ii;
      void *ptr = NULL;

      /*
       * There is one or more "holes" in the block, where an element was
       * previously deleted, so fill a hole in with this element.
       * subptr->SlotHoles contains pointers to all of the holes, so use
       * the last index of subptr->SlotHoles as the new slot
       */
    #if 0
      debug("there are [%d] holes in the sub block\n",
        subptr->LastSlotHole);
    #endif

      ptr = subptr->SlotHoles[subptr->LastSlotHole - 1];
      subptr->SlotHoles[subptr->LastSlotHole - 1] = NULL;

      if (!ptr)
      {
        for (ii = 0; ii < subptr->LastSlotHole; ii++)
        {
          if (subptr->SlotHoles[ii] != NULL)
          {
            ptr = subptr->SlotHoles[ii];
            subptr->SlotHoles[ii] = NULL;
            break;
          }
        }
      }

      /* Check if the pointer we're using is the only pointer in
       * subptr->SlotHoles[], if so, decrement subptr->LastSlotHole */
      while ((subptr->LastSlotHole >= 1) &&
             (subptr->SlotHoles[subptr->LastSlotHole - 1] == NULL))
        subptr->LastSlotHole--;
    #if 0
      debug("LastSlotHole is now equal to [%d]\n", subptr->LastSlotHole);
    #endif

      subptr->FreeElements--;
      heapptr->FreeElements--;

      /* ptr should NEVER be null, and if it is, subptr->LastSlotHole was
       * incorrectly calculated */
    #if 0
      debug("returning ptr [%p]\n", ptr);
    #endif
      return(ptr);
    }
  }

  /* we should never get here */
  return(NULL);
} /* BlockSubAllocate() */
Example #17
0
//=============================================================================
//	eTape::ParseTZX
//-----------------------------------------------------------------------------
bool eTape::ParseTZX(const void* data, size_t data_size)
{
	byte* ptr = (byte*)data;
	CloseTape();
	dword size, pause, i, j, n, t, t0;
	byte pl, last, *end;
	byte* p;
	dword loop_n = 0, loop_p = 0;
	char nm[512];
	while(ptr < (const byte*)data + data_size)
	{
		switch(*ptr++)
		{
		case 0x10: // normal block
			AllocInfocell();
			size = Word(ptr + 2);
			pause = Word(ptr);
			ptr += 4;
			Desc(ptr, size, tapeinfo[tape_infosize].desc);
			tape_infosize++;
			MakeBlock(ptr, size, 2168, 667, 735, 855, 1710, (*ptr < 4) ? 8064
					: 3220, pause);
			ptr += size;
			break;
		case 0x11: // turbo block
			AllocInfocell();
			size = 0xFFFFFF & Dword(ptr + 0x0F);
			Desc(ptr + 0x12, size, tapeinfo[tape_infosize].desc);
			tape_infosize++;
			MakeBlock(ptr + 0x12, size, Word(ptr), Word(ptr + 2),
					Word(ptr + 4), Word(ptr + 6), Word(ptr + 8),
					Word(ptr + 10), Word(ptr + 13), ptr[12]);
			// todo: test used bits - ptr+12
			ptr += size + 0x12;
			break;
		case 0x12: // pure tone
			CreateAppendableBlock();
			pl = FindPulse(Word(ptr));
			n = Word(ptr + 2);
			Reserve(n);
			for(i = 0; i < n; i++)
				tape_image[tape_imagesize++] = pl;
			ptr += 4;
			break;
		case 0x13: // sequence of pulses of different lengths
			CreateAppendableBlock();
			n = *ptr++;
			Reserve(n);
			for(i = 0; i < n; i++, ptr += 2)
				tape_image[tape_imagesize++] = FindPulse(Word(ptr));
			break;
		case 0x14: // pure data block
			CreateAppendableBlock();
			size = 0xFFFFFF & Dword(ptr + 7);
			MakeBlock(ptr + 0x0A, size, 0, 0, 0, Word(ptr),
					Word(ptr + 2), -1, Word(ptr + 5), ptr[4]);
			ptr += size + 0x0A;
			break;
		case 0x15: // direct recording
			size = 0xFFFFFF & Dword(ptr + 5);
			t0 = Word(ptr);
			pause = Word(ptr + 2);
			last = ptr[4];
			NamedCell("direct recording");
			ptr += 8;
			pl = 0;
			n = 0;
			for(i = 0; i < size; i++) // count number of pulses
				for(j = 0x80; j; j >>= 1)
					if((ptr[i] ^ pl) & j)
						n++, pl ^= -1;
			t = 0;
			pl = 0;
			Reserve(n + 2);
			for(i = 1; i < size; i++, ptr++) // find pulses
				for(j = 0x80; j; j >>= 1)
				{
					t += t0;
					if((*ptr ^ pl) & j)
					{
						tape_image[tape_imagesize++] = FindPulse(t);
						pl ^= -1;
						t = 0;
					}
				}
			// find pulses - last byte
			for(j = 0x80; j != (byte)(0x80 >> last); j >>= 1)
			{
				t += t0;
				if((*ptr ^ pl) & j)
				{
					tape_image[tape_imagesize++] = FindPulse(t);
					pl ^= -1;
					t = 0;
				}
			}
			ptr++;
			tape_image[tape_imagesize++] = FindPulse(t); // last pulse ???
			if(pause)
				tape_image[tape_imagesize++] = FindPulse(pause * 3500);
			break;
		case 0x20: // pause (silence) or 'stop the tape' command
			pause = Word(ptr);
			sprintf(nm, pause ? "pause %d ms" : "stop the tape", pause);
			NamedCell(nm);
			Reserve(2);
			ptr += 2;
			if(!pause)
			{ // at least 1ms pulse as specified in TZX 1.13
				tape_image[tape_imagesize++] = FindPulse(3500);
				pause = -1;
			}
			else
				pause *= 3500;
			tape_image[tape_imagesize++] = FindPulse(pause);
			break;
		case 0x21: // group start
			n = *ptr++;
			NamedCell(ptr, n);
			ptr += n;
			appendable = 1;
			break;
		case 0x22: // group end
			break;
		case 0x23: // jump to block
			NamedCell("* jump");
			ptr += 2;
			break;
		case 0x24: // loop start
			loop_n = Word(ptr);
			loop_p = tape_imagesize;
			ptr += 2;
			break;
		case 0x25: // loop end
			if(!loop_n)
				break;
			size = tape_imagesize - loop_p;
			Reserve((loop_n - 1) * size);
			for(i = 1; i < loop_n; i++)
				memcpy(tape_image + loop_p + i * size, tape_image + loop_p,
						size);
			tape_imagesize += (loop_n - 1) * size;
			loop_n = 0;
			break;
		case 0x26: // call
			NamedCell("* call");
			ptr += 2 + 2 * Word(ptr);
			break;
		case 0x27: // ret
			NamedCell("* return");
			break;
		case 0x28: // select block
			sprintf(nm, "* choice: ");
			n = ptr[2];
			p = ptr + 3;
			for(i = 0; i < n; i++)
			{
				if(i)
					strcat(nm, " / ");
				char *q = nm + strlen(nm);
				size = *(p + 2);
				memcpy(q, p + 3, size);
				q[size] = 0;
				p += size + 3;
			}
			NamedCell(nm);
			ptr += 2 + Word(ptr);
			break;
		case 0x2A: // stop if 48k
			NamedCell("* stop if 48K");
			ptr += 4 + Dword(ptr);
			break;
		case 0x30: // text description
			n = *ptr++;
			NamedCell(ptr, n);
			ptr += n;
			appendable = 1;
			break;
		case 0x31: // message block
			NamedCell("- MESSAGE BLOCK ");
			end = ptr + 2 + ptr[1];
			pl = *end;
			*end = 0;
			for(p = ptr + 2; p < end; p++)
				if(*p == 0x0D)
					*p = 0;
			for(p = ptr + 2; p < end; p += strlen((char*)p) + 1)
				NamedCell(p);
			*end = pl;
			ptr = end;
			NamedCell("-");
			break;
		case 0x32: // archive info
			NamedCell("- ARCHIVE INFO ");
			p = ptr + 3;
			for(i = 0; i < ptr[2]; i++)
			{
				const char *info;
				switch(*p++)
				{
				case 0:
					info = "Title";
					break;
				case 1:
					info = "Publisher";
					break;
				case 2:
					info = "Author";
					break;
				case 3:
					info = "Year";
					break;
				case 4:
					info = "Language";
					break;
				case 5:
					info = "Type";
					break;
				case 6:
					info = "Price";
					break;
				case 7:
					info = "Protection";
					break;
				case 8:
					info = "Origin";
					break;
				case 0xFF:
					info = "Comment";
					break;
				default:
					info = "info";
					break;
				}
				dword size = *p + 1;
				char tmp = p[size];
				p[size] = 0;
				sprintf(nm, "%s: %s", info, p + 1);
				p[size] = tmp;
				p += size;
				NamedCell(nm);
			}
			NamedCell("-");
			ptr += 2 + Word(ptr);
			break;
		case 0x33: // hardware type
			ParseHardware(ptr);
			ptr += 1 + 3 * *ptr;
			break;
		case 0x34: // emulation info
			NamedCell("* emulation info");
			ptr += 8;
			break;
		case 0x35: // custom info
			if(!memcmp(ptr, "POKEs           ", 16))
			{
				NamedCell("- POKEs block ");
				NamedCell(ptr + 0x15, ptr[0x14]);
				p = ptr + 0x15 + ptr[0x14];
				n = *p++;
				for(i = 0; i < n; i++)
				{
					NamedCell(p + 1, *p);
					p += *p + 1;
					t = *p++;
					strcpy(nm, "POKE ");
					for(j = 0; j < t; j++)
					{
						sprintf(nm + strlen(nm), "%d,", Word(p + 1));
						sprintf(nm + strlen(nm), *p & 0x10 ? "nn" : "%d",
								*(byte*)(p + 3));
						if(!(*p & 0x08))
							sprintf(nm + strlen(nm), "(page %d)", *p & 7);
						strcat(nm, "; ");
						p += 5;
					}
					NamedCell(nm);
				}
				nm[0] = '-';
				nm[1] = 0;
				nm[2] = 0;
				nm[3] = 0;
			}
			else
				sprintf(nm, "* custom info: %s", ptr), nm[15 + 16] = 0;
			NamedCell(nm);
			ptr += 0x14 + Dword(ptr + 0x10);
			break;
		case 0x40: // snapshot
			NamedCell("* snapshot");
			ptr += 4 + (0xFFFFFF & Dword(ptr + 1));
			break;
		case 0x5A: // 'Z'
			ptr += 9;
			break;
		default:
			ptr += data_size;
		}
	}
	for(i = 0; i < tape_infosize; i++)
	{
		if(tapeinfo[i].desc[0] == '*' && tapeinfo[i].desc[1] == ' ')
			strcat(tapeinfo[i].desc, " [UNSUPPORTED]");
		if(*tapeinfo[i].desc == '-')
			while(strlen(tapeinfo[i].desc) < sizeof(tapeinfo[i].desc) - 1)
				strcat(tapeinfo[i].desc, "-");
	}
	if(tape_imagesize && tape_pulse[tape_image[tape_imagesize - 1]] < 350000)
		Reserve(1), tape_image[tape_imagesize++] = FindPulse(350000); // small pause [rqd for 3ddeathchase]
	FindTapeSizes();
	return (ptr == (const byte*)data + data_size);
}