Commits

RomanGol committed 4eee066

Style Modified

fix bad style

Comments (0)

Files changed (4)

parser/Readtrace.cpp

 
 typedef void (*Handler)( loccs_opcode lo, FILE* fpw );
 
-void output_opcode( loccs_opcode lo, FILE* fpw )
+void output_opcode( const loccs_opcode& lo, FILE* fpw )
 {
 	fprintf( fpw, "\n---------------------------------------------------------------\n");
 	//fprintf( fpw, "Thread ID : %x\n",lo.threadId);
 	//fprintf( fpw, "string : %s\n",lo.extraData);
 	
 	fprintf( fpw, "pc = %08x\n", lo.pc);
-	fprintf( fpw, "class : %s\n",lo.methodDescriptor);
-	fprintf( fpw, "method : %s\n",lo.methodName);
-	fprintf( fpw, "logcontent:%s\n",lo.logcontent);
+	fprintf( fpw, "class : %s\n", lo.methodDescriptor);
+	fprintf( fpw, "method : %s\n", lo.methodName);
+	fprintf( fpw, "logcontent:%s\n", lo.logcontent);
 	
 	for( size_t i = 0; i < 16; i++ )
 	{
 		fprintf( fpw, "Reg[%lu] = [%04x],",i,lo.reg[i]);
 	}
+	
 	fprintf( fpw, "\n" );
 	
+	// using handler function to deal with opcode's details
 	uint16_t inst = lo.inst[0];
-	Handler handler = (Handler) gDvmMterpHandlers[inst & 0xff];
-	(*handler)( lo, fpw );	
+	Handler deal_opcode = (Handler) opcodeHandlers[inst & 0xff];
+	(*deal_opcode)( lo, fpw );
 }
 
-int main()
+int main( int argc, char* argv[] )
 {
-	uint32_t inst_num = 0;
-    FILE* fp = fopen( "E:/ftp/opcodes.bin", "rb" );//��¼�ļ�
-    FILE* fpw = fopen( "E:/ftp/opcodes_parse.bin", "wb");//����֮����ļ�
+	if ( argc != 3 )
+	{
+		puts("Usage: parser record_file result_file");
+		return -1;
+	}
+	
 
-    if( fp != NULL )
-    {
-		loccs_opcode lo;
-		int t = 0;
-        //while ( 0 != fread( &lo, sizeof(loccs_opcode), 1, fp ) ){
-		while ( !feof(fp) )
-		{
-			if ( fread( &lo, sizeof(loccs_opcode), 1, fp ) == 1 )
-			{
-				output_opcode( lo, fpw );
-				++inst_num;
-			}
-		}
-		
-		printf( "\nparse instruction finished\ninstruction number %d", inst_num );
-		fclose( fp );
-		fclose( fpw );
-    }
-	else
+    FILE* fp = fopen( argv[1], "rb" ); // DIAOS opcode record binary file
+    FILE* fpw = fopen( argv[2], "wb"); // after parsing
+
+	if ( fp == NULL )
 	{
-		fprintf( fpw, "the instruction file does not exit\n");
-		printf("\nthe instruction file does not exit\n");
+		printf( "the record file does not exist\n");
+		return -1;
 	}
-	system("PAUSE");
-	return 0;
-}
 
+	if ( fpw == NULL )
+	{
+		printf( "fail to open result file\n");
+		return -1;
+	}
 
-		/*
-		fp = fopen( funct, "rb" );
-		fpw = fopen( functres, "wb");
+	uint32_t inst_num = 0;
+	loccs_opcode lo;
 
-		char tem[128];
-		if (fp!=NULL)
-		{
-			while (!feof(fp))
-			{
-				if (fread( &tem, sizeof(tem), 1, fp )==1)
-				{
-					fprintf( fpw, "---------------------------------------------------------------\n");
-					fprintf( fpw, "%s\n",tem);
-				}
-			}
-			printf("\nparse function call finished\n");
-			fclose(fp);
-			fclose(fpw);
-		}
-		else
+	while ( !feof(fp) )
+	{
+		if ( fread( &lo, sizeof(loccs_opcode), 1, fp ) == 1 )
 		{
-			fprintf( fpw, "the function call file does not exit\n");
-			printf("\nthe function call file does not exit\n");
+			output_opcode( lo, fpw );
+			++inst_num;
 		}
-		*/
+	}
+	
+	puts( "parse instruction finished\n" );
+	printf( "instruction number %d", inst_num );
+
+	fclose( fp );
+	fclose( fpw );
 
+	return 0;
+}
 
-		/*
-    char inst[FILE_PATH],instres[FILE_PATH],funct[FILE_PATH],functres[FILE_PATH];
-	printf("Enter the original instruction file path you got from DIAOS :");
-	scanf("%[^'\n']",inst);
-	fflush(stdin);
-	printf("Enter the instruction result file path after parsed :");
-	scanf("%[^'\n']",instres);
-	fflush(stdin);
-	printf("Enter the original function call file path you got from DIAOS :");
-	scanf("%[^'\n']",funct);
-	fflush(stdin);
-	printf("Enter the function call result file path after parsed :");
-	scanf("%[^'\n']",functres);
-	fflush(stdin);
-	*/

parser/SConstruct

 Lib_list = ['']
 Inc_list = ['']
 Def_list = ['']
-ccflags_str = ''
+ccflags_str = '/EHsc'
 
 
 env = Environment( ENV = os.environ )
 #env.Append( LIBS = Lib_list )
 #env.Append( CPPPATH = Inc_list )
 #env.Append( CPPDEFINES = Def_list )
-#env.Append( CCFLAGS = ccflags_str )
-env.Program( target = 'bin/trace_parser', source = Src_list )
+env.Append( CCFLAGS = ccflags_str )
+env.Program( target = 'bin/parser', source = Src_list )
 void ldvm_OP_SPUT_OBJECT_VOLATILE_JUMBO(const loccs_opcode lo ,FILE* fpw);
 void ldvm_OP_THROW_VERIFICATION_ERROR_JUMBO(const loccs_opcode lo ,FILE* fpw);
 
-static void (*gDvmMterpHandlers[0x200])(const loccs_opcode lo ,FILE* fpw) = 
+static void (*opcodeHandlers[0x200])(const loccs_opcode lo ,FILE* fpw) = 
 {
     /* BEGIN(libdex-goto-table); GENERATED AUTOMATICALLY BY opcode-gen */
     ldvm_OP_NOP,                                  
 typedef int32_t s4;
 typedef int64_t s8;
 
-const static uint32_t instNumInLo = 5;//shujunliang
+const static uint32_t instNumInLo = 5; // add according to shujunliang
 const static uint32_t logContentLen = 128;
 const static uint32_t regNum = 16;
 const static uint32_t methDescLen = 128;