Exemplo n.º 1
0
void ClipLine( POINT &Start, POINT &End )
{
	INT32 ThisSector = GetSector( End ) ;
	switch ( CaseTable[(INT32)LastSector][(INT32)ThisSector] )
	{
	case 01 : GenLineToBelowLeft()	; break ;
	case 02 : GenLineToBelowRight()	; break ;
	case 03 : GenLineToAboveLeft()	; break ;
	case 04 : GenLineToAboveRight()	; break ;
	case 05 : GenLine(Start)		;
			  GenLine(End)			; break ;
	case 06 : if ( OFirstPoint )
				  GenLine(Start) ;
			  GenLine(End)			; break ;
	case 07 :
		POINT Middle ;
		Middle.x = (Start.x+End.x) >> 1 ;
		Middle.y = (Start.y+End.y) >> 1 ;
		ClipLine( Start,Middle ) ;
		ClipLine( Middle,End ) ;
		return ;
	case 10 : GenLineToBelowLeft()	; GenLineToBelowRight()	; break ;
	case 11 : GenLineToBelowLeft()	; GenLineToAboveLeft()	; break ;
	case 12 : GenLineToBelowRight()	; GenLineToAboveRight()	; break ;
	case 13 : GenLineToBelowRight()	; GenLineToBelowLeft()	; break ;
	case 14 : GenLineToAboveLeft()	; GenLineToAboveRight()	; break ;
	case 15 : GenLineToAboveLeft()	; GenLineToBelowLeft()	; break ;
	case 16 : GenLineToAboveRight()	; GenLineToBelowRight()	; break ;
	case 17 : GenLineToAboveRight()	; GenLineToAboveLeft()	; break ;
	}
	LastSector = ThisSector ;
}
Exemplo n.º 2
0
void CodeGenerator::GenProgramStart()
{
   GenLine( ".386P" );
   GenLine( ".MODEL FLAT" );
   GenLine( "INCLUDELIB LIBCMT" );
   GenLine( "EXTRN _printf : NEAR" );
   GenLine( ".code\n" );
}
Exemplo n.º 3
0
void CodeGenerator::GenFuncCall( std::string funcName, int paramCountCall )
{
   GenReverseStack( paramCountCall );
   GenBlockHeader( "Call " + funcName + " Function" );
   GenLine( "CALL _" + funcName );
   GenLine( "add esp, " + toString( 4 * paramCountCall ) + "d" );
   GenPush( "eax" );
}
Exemplo n.º 4
0
int CodeGenerator::GenWhileMiddle()
{
   int whileFinishLabel = CreateLabel();
   GenPop( "eax" );
   GenLine( "cmp eax, 0" );
   GenLine( "JE L" + toString( whileFinishLabel ) );
   return whileFinishLabel;
}
Exemplo n.º 5
0
void CodeGenerator::GenStringPush( std::string str )
{
   std::string strVar = "S" + toString( mStrCount++ );
   GenLine( ".data" );
   GenLine( strVar + " BYTE \"" + str + "\", 00h" );
   GenLine( ".code" );
   GenPush( "OFFSET " + strVar );
}
Exemplo n.º 6
0
void CodeGenerator::GenDivision()
{
   GenBlockHeader( "Divide" );
   GenPop( "ecx" );
   GenPop( "eax" );
   GenLine( "CDQ" );
   GenLine( "idiv ecx" );
   GenPush( "eax" );
}
Exemplo n.º 7
0
int CodeGenerator::GenIfStart()
{
   GenBlockHeader( "If statement" );
   GenPop( "eax" );
   GenLine( "cmp eax, 0" );
   int endIflabel = CreateLabel();
   GenLine( "JE L" + toString( endIflabel ) );
   return endIflabel;
}
Exemplo n.º 8
0
void CodeGenerator::GenFuncEnd( std::string funcName, int retLabel )
{
   funcName = '_' + funcName;
   GenLine();
   GenLabel( retLabel );
   GenMov( "esp", "ebp" );
   GenPop( "ebp" );
   GenLine( "RET" );
   GenLine( funcName + " ENDP" );
}
Exemplo n.º 9
0
int CodeGenerator::GenFuncStart( std::string funcName )
{
   GenBlockHeader( "Function " + funcName + " Declaration" );
   funcName = '_' + funcName;
   GenLine( "PUBLIC " + funcName );
   GenLine( funcName + " PROC" );
   GenPush( "ebp" );
   GenMov( "ebp","esp" );
   GenLine();
   return CreateLabel();
}
Exemplo n.º 10
0
void CodeGenerator::GenNot()
{
   GenBlockHeader( "Not" );
   GenPop( "eax" );
   GenMov( "edx", "0" );
   GenLine( "cmp eax, 0" );
   GenLine( "JNE L" + toString( ++mLabelCount ) );
   GenLine( "inc edx" );
   GenLabel( mLabelCount );
   GenPush( "edx" );
}
Exemplo n.º 11
0
void CodeGenerator::GenOr()
{
   GenBlockHeader( "Or" );
   GenPop( "ecx" );
   GenPop( "eax" );
   GenMov( "edx", "0" );
   GenLine( "or eax, ecx" );
   GenLine( "cmp eax, 0" );
   GenLine( "JE L" + toString( ++mLabelCount ) );
   GenLine( "inc edx" );
   GenLabel( mLabelCount );
   GenPush( "edx" );
}
Exemplo n.º 12
0
void CodeGenerator::GenAnd()
{
   GenBlockHeader( "And" );
   GenPop( "ecx" );
   GenPop( "eax" );
   GenLine( "imul ecx" );
   GenMov( "edx", "0" );
   GenLine( "cmp eax, 0" );
   mAsmCode += "JE";
   mAsmCode += " L" + toString( ++mLabelCount ) + "\n";
   GenLine( "inc edx" );
   GenLabel( mLabelCount );
   GenPush( "edx" );
}
Exemplo n.º 13
0
void CodeGenerator::GenNegate()
{
   GenBlockHeader( "Negate" );
   GenPop( "eax" );
   GenLine( "neg eax" );
   GenPush( "eax" );
}
Exemplo n.º 14
0
int _tmain(int argc, _TCHAR* argv[])
{
	GenLine();

//	char utf8Buf[256];
	// CommonLib::CString str = "string";

//	 str.exportToUTF8(utf8Buf, 255);
//	CompressShape();
//	TestTableWks();
	//testLoadXML1();
	//return 1;
//	TestShapeIndex();
//	

	/*CommonLib::CString s1(L"vfdgggf");
	CommonLib::CString s2(s1);

	ITest *pTest = new ITest(s1);
	delete pTest;*/
	//TestShapeIndex();
//	TestSQLiteWks();
  //TestEmbDBWks();
	//TestXML();
	/*for(int i =0; i < 100000000; ++i)
	{
		CommonLib::CString s1 = L"vfdgggf";
		CommonLib::CString s2 = s1;
	}*/
	return 0;
}
Exemplo n.º 15
0
// GenBinaryOperation
void CodeGenerator::GenBinaryOperation( std::string operationName )
{
   GenBlockHeader( operationName );
   GenPop( "ecx" );
   GenPop( "eax" );
   GenLine( operationName + " eax, ecx" );
   GenPush( "eax" );
}
Exemplo n.º 16
0
void CodeGenerator::GenMultiplication()
{
   GenBlockHeader( "Multiply" );
   GenPop( "ecx" );
   GenPop( "eax" );
   GenLine( "imul ecx" );
   GenPush( "eax" );
}
Exemplo n.º 17
0
void CodeGenerator::GenCompare( std::string sign )
{
   GenBlockHeader( "Compare" );
   GenPop( "ecx" );
   GenPop( "eax" );
   GenMov( "edx", "0" );
   GenLine( "cmp eax, ecx" );
   if( sign == "==" ) mAsmCode += "JNE ";
   if( sign == "!=" ) mAsmCode += "JE";
   if( sign == ">" ) mAsmCode += "JLE";
   if( sign == "<" ) mAsmCode += "JGE";
   if( sign == ">=" ) mAsmCode += "JL";
   if( sign == "<=" ) mAsmCode += "JG";
   mAsmCode += " L" + toString( ++mLabelCount ) + "\n";
   GenLine( "inc edx" );
   GenLabel( mLabelCount );
   GenPush( "edx" );
}
Exemplo n.º 18
0
void CodeGenerator::GenReverseStack( int depth )
{
   if( depth < 2 ) return;
   GenBlockHeader( "Reversing last " + toString( depth ) + " stack items" );
   GenLine( ".data" );
   // allocate enough memory
   for( int i = 1; i <= depth; ++i )
   {
      GenLine( "stackReveseVar" + toString( mStackReverseCount++ ) + " DWORD ?" );
   }
   GenLine( ".code" );
   // pop into memory
   for( int i = depth; i >= 1; --i )
   {
      GenPop( "stackReveseVar" + toString( mStackReverseCount - i ) );
   }
   for( int i = depth; i >= 1; --i )
   {
      GenPush( "stackReveseVar" + toString( mStackReverseCount - i ) );
   }
}
Exemplo n.º 19
0
void ClipCurve( POINT &C0, POINT &C1, POINT &C2, POINT &C3 )
{
	INT32 C1Sector	= GetSector( C1 ) ;
	INT32 C2Sector	= GetSector( C2 ) ;
	INT32 ThisSector	= GetSector( C3 ) ;
//	if ( ( ( C1Sector==LastSector || C1Sector==ThisSector ) &&
//		   ( C2Sector==LastSector || C2Sector==ThisSector ) ) ||
//		 ( Region[LastSector] & Region[C1Sector] & Region[C2Sector] & Region[ThisSector] ) )
	INT32 RegionUnion = Region[LastSector] & Region[C1Sector] & Region[C2Sector] & Region[ThisSector];
	if ( ( RegionUnion & 0x0ff ) ||
		 ( (RegionUnion & 0x300) && (LastSector!=ThisSector || LastSector==12) ) ||
		 ( (C1Sector==LastSector || C1Sector==ThisSector) && (C2Sector==LastSector || C2Sector==ThisSector) ) )
	{
		switch ( CaseTable[(INT32)LastSector][(INT32)ThisSector] )
		{
		case 01 : GenLineToBelowLeft()	; break ;
		case 02 : GenLineToBelowRight()	; break ;
		case 03 : GenLineToAboveLeft()	; break ;
		case 04 : GenLineToAboveRight()	; break ;
		case 05 : GenLine(C0,FALSE) ;
				  GenCurve(C1,C2,C3)	; break ;
		case 06 : if ( OFirstPoint )
					  GenLine(C0,FALSE) ;
				  GenCurve(C1,C2,C3)	; break ;
		case 07 : SplitCurve(C0,C1,C2,C3) ; return ;
		case 10 : GenLineToBelowLeft()	; GenLineToBelowRight()	; break ;
		case 11 : GenLineToBelowLeft()	; GenLineToAboveLeft()	; break ;
		case 12 : GenLineToBelowRight()	; GenLineToAboveRight()	; break ;
		case 13 : GenLineToBelowRight()	; GenLineToBelowLeft()	; break ;
		case 14 : GenLineToAboveLeft()	; GenLineToAboveRight()	; break ;
		case 15 : GenLineToAboveLeft()	; GenLineToBelowLeft()	; break ;
		case 16 : GenLineToAboveRight()	; GenLineToBelowRight()	; break ;
		case 17 : GenLineToAboveRight()	; GenLineToAboveLeft()	; break ;
		}
		LastSector = ThisSector ;
	}
	else
		SplitCurve(C0,C1,C2,C3) ;
}
Exemplo n.º 20
0
void CodeGenerator::GenLabel( int labelNum )
{
   GenLine( "L" + toString( labelNum ) + ":" ); 
}
Exemplo n.º 21
0
void CodeGenerator::GenPop( std::string reg )
{
   GenLine( "pop " + reg );
}
Exemplo n.º 22
0
void CodeGenerator::GenMov( std::string toStr, std::string fromStr )
{
   GenLine( "mov " + toStr + ", " + fromStr );
}
Exemplo n.º 23
0
void CodeGenerator::GenBlockHeader( std::string blockName )
{
   GenLine( "\n;--------------- " + blockName + " ---------------" );
}
Exemplo n.º 24
0
void CodeGenerator::GenProgramEnd()
{
   GenLine( "\nEND" );
}
Exemplo n.º 25
0
void CodeGenerator::GenGlobalVarDef( std::string varName )
{
   GenLine( ".data" );
   GenLine( '_' + varName + " DWORD ?" );
   GenLine( ".code" );
}
Exemplo n.º 26
0
void CodeGenerator::GenLocalVarDef()
{
   GenLine( "sub esp, 4" );
}
Exemplo n.º 27
0
void CodeGenerator::GenDoMiddle( int doStartLabel )
{
   GenPop( "eax" );
   GenLine( "cmp eax, 0" );
   GenLine( "JNE L" + toString( doStartLabel ) );
}
Exemplo n.º 28
0
void CodeGenerator::GenPush( std::string reg )
{
   GenLine( "push " + reg );
}
Exemplo n.º 29
0
void CodeGenerator::GenPush( int n )
{
   GenLine( "push " + toString( n ) + "d" );
}
Exemplo n.º 30
0
void CodeGenerator::GenJmp( int label )
{
   GenLine( "JMP L" + toString( label ) );
}