summaryrefslogtreecommitdiff
path: root/editors/openoffice-2.0-devel/files/patch-bridges+source+cpp_uno+gcc3_freebsd_intel+cpp2uno.cxx
blob: e6e306b99efd1b14a1ef14c62edec51240b5ac16 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
Issutracker : #iXXXXX#
CWS         : N/A
Author      : NAKATA Maho <maho@openoffice.org> (JCA)
Description : catch up recent version of cpp_uno

--- bridges/source/cpp_uno/gcc3_freebsd_intel/cpp2uno.cxx	Wed Jan 19 00:06:09 2005
+++ bridges/source/cpp_uno/gcc3_freebsd_intel/cpp2uno.cxx	Mon Feb 21 21:13:28 2005
@@ -77,7 +77,7 @@
 {
 
 //==================================================================================================
-static typelib_TypeClass cpp2uno_call(
+void cpp2uno_call(
 	bridges::cpp_uno::shared::CppInterfaceProxy * pThis,
 	const typelib_TypeDescription * pMemberTypeDescr,
 	typelib_TypeDescriptionReference * pReturnTypeRef, // 0 indicates void return
@@ -209,8 +209,6 @@
 		CPPU_CURRENT_NAMESPACE::raiseException(
             &aUnoExc, pThis->getBridge()->getUno2Cpp() );
             // has to destruct the any
-		// is here for dummy
-		return typelib_TypeClass_VOID;
 	}
 	else // else no exception occured...
 	{
@@ -247,22 +245,16 @@
 		}
 		if (pReturnTypeDescr)
 		{
-			typelib_TypeClass eRet = (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
 			TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
-			return eRet;
 		}
-		else
-			return typelib_TypeClass_VOID;
 	}
 }
 
 
 //==================================================================================================
-static typelib_TypeClass cpp_mediate(
-	sal_Int32 nFunctionIndex,
-    sal_Int32 nVtableOffset,
-	void ** pCallStack,
-	sal_Int64 * pRegisterReturn /* space for register return */ )
+extern "C" void cpp_vtable_call(
+    int nFunctionIndex, int nVtableOffset, void** pCallStack,
+    sal_Int64 nRegReturn )
 {
 	OSL_ENSURE( sizeof(sal_Int32)==sizeof(void *), "### unexpected!" );
 	
@@ -298,7 +290,6 @@
 
 	TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
     
-	typelib_TypeClass eRet;
 	switch (aMemberDescr.get()->eTypeClass)
 	{
 	case typelib_TypeClass_INTERFACE_ATTRIBUTE:
@@ -306,11 +297,11 @@
 		if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex)
 		{
 			// is GET method
-			eRet = cpp2uno_call(
+			cpp2uno_call(
 				pCppI, aMemberDescr.get(),
 				((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
 				0, 0, // no params
-				pCallStack, pRegisterReturn );
+				pCallStack, &nRegReturn );
 		}
 		else
 		{
@@ -321,11 +312,11 @@
 			aParam.bIn		= sal_True;
 			aParam.bOut		= sal_False;
 			
-			eRet = cpp2uno_call(
+			cpp2uno_call(
 				pCppI, aMemberDescr.get(),
 				0, // indicates void return
 				1, &aParam,
-				pCallStack, pRegisterReturn );
+				pCallStack, &nRegReturn );
 		}
 		break;
 	}
@@ -336,11 +327,9 @@
 		{
 		case 1: // acquire()
 			pCppI->acquireProxy(); // non virtual call!
-			eRet = typelib_TypeClass_VOID;
 			break;
 		case 2: // release()
 			pCppI->releaseProxy(); // non virtual call!
-			eRet = typelib_TypeClass_VOID;
 			break;
 		case 0: // queryInterface() opt
 		{
@@ -361,20 +350,19 @@
                         &pInterface, pTD, cpp_acquire );
                     pInterface->release();
                     TYPELIB_DANGER_RELEASE( pTD );
-                    *(void **)pRegisterReturn = pCallStack[1];
-                    eRet = typelib_TypeClass_ANY;
+                    *(void **)&nRegReturn = pCallStack[1];
                     break;
                 }
                 TYPELIB_DANGER_RELEASE( pTD );
             }
 		} // else perform queryInterface()
 		default:
-			eRet = cpp2uno_call(
+			cpp2uno_call(
 				pCppI, aMemberDescr.get(),
 				((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
 				((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
 				((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
-				pCallStack, pRegisterReturn );
+				pCallStack, &nRegReturn );
 		}
 		break;
 	}
@@ -383,72 +371,55 @@
 		throw RuntimeException(
             rtl::OUString::createFromAscii("no member description found!"),
             (XInterface *)pThis );
-		// is here for dummy
-		eRet = typelib_TypeClass_VOID;
 	}
 	}
-
-	return eRet;
 }
 
 //==================================================================================================
-/**
- * is called on incoming vtable calls
- * (called by asm snippets)
- */
-static void cpp_vtable_call(
-    int nFunctionIndex, int nVtableOffset, void** pCallStack )
-    __attribute__((regparm(3)));
-
-void cpp_vtable_call( int nFunctionIndex, int nVtableOffset, void** pCallStack )
-{
-	volatile long nRegReturn[2];
-	typelib_TypeClass aType = cpp_mediate(
-        nFunctionIndex, nVtableOffset, pCallStack, (sal_Int64*)nRegReturn );
-    
-	switch( aType )
-	{
-		case typelib_TypeClass_HYPER:
-		case typelib_TypeClass_UNSIGNED_HYPER:
-			__asm__( "movl %1, %%edx\n\t"
-					 "movl %0, %%eax\n"
-					 : : "m"(nRegReturn[0]), "m"(nRegReturn[1]) );
-			break;
-		case typelib_TypeClass_FLOAT:
-			__asm__( "flds %0\n\t"
-					 "fstp %%st(0)\n\t"
-					 "flds %0\n"
-					 : : "m"(*(float *)nRegReturn) );
-			break;
-		case typelib_TypeClass_DOUBLE:
-			__asm__( "fldl %0\n\t"
-					 "fstp %%st(0)\n\t"
-					 "fldl %0\n"
-					 : : "m"(*(double *)nRegReturn) );
-			break;
-// 		case typelib_TypeClass_UNSIGNED_SHORT:
-// 		case typelib_TypeClass_SHORT:
-// 			__asm__( "movswl %0, %%eax\n"
-// 					 : : "m"(nRegReturn) );
-// 		break;
-		default:
-			__asm__( "movl %0, %%eax\n"
-					 : : "m"(nRegReturn[0]) );
-			break;
-	}
-}
-
+extern "C" void privateSnippetExecutorGeneral();
+extern "C" void privateSnippetExecutorVoid();
+extern "C" void privateSnippetExecutorHyper();
+extern "C" void privateSnippetExecutorFloat();
+extern "C" void privateSnippetExecutorDouble();
+extern "C" void privateSnippetExecutorClass();
+extern "C" typedef void (*PrivateSnippetExecutor)();
 
-//==================================================================================================
-int const codeSnippetSize = 20;
+int const codeSnippetSize = 16;
 
 unsigned char * codeSnippet(
     unsigned char * code, sal_Int32 functionIndex, sal_Int32 vtableOffset,
-    bool simpleRetType)
+    typelib_TypeClass returnTypeClass)
 {
-    if (!simpleRetType) {
+    if (!bridges::cpp_uno::shared::isSimpleType(returnTypeClass)) {
         functionIndex |= 0x80000000;
     }
+    PrivateSnippetExecutor exec;
+    switch (returnTypeClass) {
+    case typelib_TypeClass_VOID:
+        exec = privateSnippetExecutorVoid;
+        break;
+    case typelib_TypeClass_HYPER:
+    case typelib_TypeClass_UNSIGNED_HYPER:
+        exec = privateSnippetExecutorHyper;
+        break;
+    case typelib_TypeClass_FLOAT:
+        exec = privateSnippetExecutorFloat;
+        break;
+    case typelib_TypeClass_DOUBLE:
+        exec = privateSnippetExecutorDouble;
+        break;
+    case typelib_TypeClass_STRING:
+    case typelib_TypeClass_TYPE:
+    case typelib_TypeClass_ANY:
+    case typelib_TypeClass_SEQUENCE:
+    case typelib_TypeClass_STRUCT:
+    case typelib_TypeClass_INTERFACE:
+        exec = privateSnippetExecutorClass;
+        break;
+    default:
+        exec = privateSnippetExecutorGeneral;
+        break;
+    }
     unsigned char * p = code;
     OSL_ASSERT(sizeof (sal_Int32) == 4);
     // mov function_index, %eax:
@@ -459,13 +430,10 @@
     *p++ = 0xBA;
     *reinterpret_cast< sal_Int32 * >(p) = vtableOffset;
     p += sizeof (sal_Int32);
-    // mov %esp, %ecx:
-    *p++ = 0x89;
-    *p++ = 0xE1;
-    // jmp cpp_vtable_call:
+    // jmp privateSnippetExecutor:
     *p++ = 0xE9;
     *reinterpret_cast< sal_Int32 * >(p)
-        = ((unsigned char *) cpp_vtable_call) - p - sizeof (sal_Int32);
+        = ((unsigned char *) exec) - p - sizeof (sal_Int32);
     p += sizeof (sal_Int32);
     OSL_ASSERT(p - code <= codeSnippetSize);
     return code + codeSnippetSize;
@@ -504,17 +472,17 @@
             *slots++ = code;
             code = codeSnippet(
                 code, functionOffset++, vtableOffset,
-                bridges::cpp_uno::shared::isSimpleType(
-                    reinterpret_cast<
-                    typelib_InterfaceAttributeTypeDescription * >(
-                        member)->pAttributeTypeRef));
+                reinterpret_cast< typelib_InterfaceAttributeTypeDescription * >(
+                    member)->pAttributeTypeRef->eTypeClass);
             // Setter:
             if (!reinterpret_cast<
                 typelib_InterfaceAttributeTypeDescription * >(
                     member)->bReadOnly)
             {
                 *slots++ = code;
-                code = codeSnippet(code, functionOffset++, vtableOffset, true);
+                code = codeSnippet(
+                    code, functionOffset++, vtableOffset,
+                    typelib_TypeClass_VOID);
             }
             break;
 
@@ -522,10 +490,8 @@
             *slots++ = code;
             code = codeSnippet(
                 code, functionOffset++, vtableOffset,
-                bridges::cpp_uno::shared::isSimpleType(
-                    reinterpret_cast<
-                    typelib_InterfaceMethodTypeDescription * >(
-                        member)->pReturnTypeRef));
+                reinterpret_cast< typelib_InterfaceMethodTypeDescription * >(
+                    member)->pReturnTypeRef->eTypeClass);
             break;
 
         default: