source: dev/trunk/abdev/BasicCompiler_Common/Diagnose.cpp@ 318

Last change on this file since 318 was 276, checked in by dai_9181, 17 years ago
File size: 4.4 KB
Line 
1#include "stdafx.h"
2
3#include <jenga/include/smoothie/Smoothie.h>
4
5#include <Compiler.h>
6#include <Program.h>
7
8#include "../BasicCompiler_Common/common.h"
9
10#ifdef _AMD64_
11#include "../BasicCompiler64/opcode.h"
12#else
13#include "../BasicCompiler32/opcode.h"
14#endif
15
16
17void Diagnose(){
18 char temporary[8192];
19
20 {
21 ///////////////////////////////////////////////////////////////////
22 // グローバル / ローカル コード領域のサイズを調べる
23 ///////////////////////////////////////////////////////////////////
24
25 extern int GlobalOpBufferSize;
26 sprintf(temporary, "%d", GlobalOpBufferSize/1024 );
27 trace_for_size( (string)"グローバル領域のコードサイズ: " + temporary + "KB" );
28 //sprintf(temporary, "%d", (obp-GlobalOpBufferSize)/1024 );
29 //trace_for_size( (string)"ローカル領域のコードサイズ: " + temporary + "KB" );
30 //sprintf(temporary, "%d", obp/1024 );
31 //trace_for_size( (string)"コードサイズ総量: " + temporary + "KB" );
32 }
33
34 {
35 ///////////////////////////////////////////////////////////////////
36 // グローバル関数、クラスメソッドのサイズを調べる
37 ///////////////////////////////////////////////////////////////////
38
39 int codeSizeOfGlobalProc = 0;
40 int codeSizeOfClassMethod = 0;
41 compiler.GetObjectModule().meta.GetUserProcs().Iterator_Reset();
42 while( compiler.GetObjectModule().meta.GetUserProcs().Iterator_HasNext() )
43 {
44 UserProc *pUserProc = compiler.GetObjectModule().meta.GetUserProcs().Iterator_GetNext();
45 if( pUserProc->IsCompiled() ){
46 if( pUserProc->HasParentClass() ){
47 codeSizeOfClassMethod += pUserProc->GetCodeSize();
48 }
49 else{
50 codeSizeOfGlobalProc += pUserProc->GetCodeSize();
51 }
52 }
53 }
54
55 sprintf(temporary, "%d", codeSizeOfGlobalProc/1024 );
56 trace_for_size( (string)"グローバル関数のコードサイズ総量: " + temporary + "KB" );
57 sprintf(temporary, "%d", codeSizeOfClassMethod/1024 );
58 trace_for_size( (string)"クラスメソッドのコードサイズ総量: " + temporary + "KB" );
59 }
60
61 {
62 ///////////////////////////////////////////////////////////////////
63 // Enumに必要なのコードサイズを調べる
64 ///////////////////////////////////////////////////////////////////
65 int codeSizeOfEnum = 0;
66
67 // イテレータをリセット
68 compiler.GetObjectModule().meta.GetClasses().Iterator_Reset();
69
70 while( compiler.GetObjectModule().meta.GetClasses().Iterator_HasNext() ){
71 int codeSizeOfClass = 0;
72
73 CClass &objClass = *compiler.GetObjectModule().meta.GetClasses().Iterator_GetNext();
74
75 if( !objClass.IsEnum() ){
76 // 列挙型以外は無視
77 continue;
78 }
79
80 // 動的メソッド
81 BOOST_FOREACH( const CMethod *pMethod, objClass.GetMethods() ){
82 if( pMethod->GetUserProc().IsCompiled() ){
83 codeSizeOfClass += pMethod->GetUserProc().GetCodeSize();
84 }
85 }
86
87 // 静的メソッド
88 BOOST_FOREACH( const CMethod *pMethod, objClass.GetStaticMethods() ){
89 codeSizeOfClass += pMethod->GetUserProc().GetCodeSize();
90 }
91
92 codeSizeOfEnum += codeSizeOfClass;
93 }
94
95 sprintf(temporary, "%d", codeSizeOfEnum/1024 );
96 trace_for_size( (string)"Enumのコードサイズ総量: " + temporary + "KB" );
97 }
98
99 trace_for_size( "\n\n" );
100
101 {
102 ///////////////////////////////////////////////////////////////////
103 // クラスのサイズを調べる
104 ///////////////////////////////////////////////////////////////////
105
106 // イテレータをリセット
107 compiler.GetObjectModule().meta.GetClasses().Iterator_Reset();
108
109 while( compiler.GetObjectModule().meta.GetClasses().Iterator_HasNext() ){
110 int codeSizeOfClass = 0;
111
112 CClass &objClass = *compiler.GetObjectModule().meta.GetClasses().Iterator_GetNext();
113
114 // 動的メソッド
115 BOOST_FOREACH( const CMethod *pMethod, objClass.GetMethods() ){
116 if( pMethod->GetUserProc().IsCompiled() ){
117 codeSizeOfClass += pMethod->GetUserProc().GetCodeSize();
118 }
119 }
120
121 // 静的メソッド
122 BOOST_FOREACH( const CMethod *pMethod, objClass.GetStaticMethods() ){
123 codeSizeOfClass += pMethod->GetUserProc().GetCodeSize();
124 }
125
126 if( codeSizeOfClass ){
127 temporary[0]=0;
128 lstrcat( temporary, "------------------------------------------------------------------\n" );
129 sprintf( temporary + lstrlen(temporary), "【 %s クラスのコード情報】\n", objClass.GetName().c_str() );
130 sprintf( temporary + lstrlen(temporary), "class code size: %d bytes\n", codeSizeOfClass );
131 lstrcat( temporary, "------------------------------------------------------------------\n" );
132 lstrcat( temporary, "\n" );
133 trace_for_size( temporary );
134 }
135 }
136 }
137}
Note: See TracBrowser for help on using the repository browser.