LibreOffice Module bridges (master) 1
gcc3_linux_loongarch64/abi.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <sal/config.h>
21
22#include "abi.hxx"
23
25{
26 const typelib_CompoundTypeDescription* p
27 = reinterpret_cast<const typelib_CompoundTypeDescription*>(pTypeDescr);
28 int sum = p->nMembers;
29 for (sal_Int32 i = 0; i < p->nMembers; ++i)
30 {
31 typelib_TypeDescriptionReference* pTypeInStruct = p->ppTypeRefs[i];
32
33 switch (pTypeInStruct->eTypeClass)
34 {
35 case typelib_TypeClass_STRUCT:
36 {
38 TYPELIB_DANGER_GET(&t, pTypeInStruct);
39 sum--;
40 sum += flatten_struct(t, regs);
41 TYPELIB_DANGER_RELEASE(t);
42 }
43 break;
44 case typelib_TypeClass_CHAR:
45 case typelib_TypeClass_BOOLEAN:
46 case typelib_TypeClass_BYTE:
47 case typelib_TypeClass_SHORT:
48 case typelib_TypeClass_UNSIGNED_SHORT:
49 case typelib_TypeClass_LONG:
50 case typelib_TypeClass_UNSIGNED_LONG:
51 case typelib_TypeClass_HYPER:
52 case typelib_TypeClass_UNSIGNED_HYPER:
53 case typelib_TypeClass_ENUM:
54 regs.nr_int++;
55 if (!regs.priorInt && !regs.priorFp)
56 regs.priorInt = true;
57 break;
58 case typelib_TypeClass_FLOAT:
59 case typelib_TypeClass_DOUBLE:
60 regs.nr_fp++;
61 if (!regs.priorInt && !regs.priorFp)
62 regs.priorFp = true;
63 break;
64 default:
65 break;
66 }
67 }
68 return sum;
69}
70
71loongarch64::ReturnKind loongarch64::getReturnKind(typelib_TypeDescriptionReference* pTypeRef)
72{
73 switch (pTypeRef->eTypeClass)
74 {
75 case typelib_TypeClass_CHAR:
76 case typelib_TypeClass_BOOLEAN:
77 case typelib_TypeClass_BYTE:
78 case typelib_TypeClass_SHORT:
79 case typelib_TypeClass_UNSIGNED_SHORT:
80 case typelib_TypeClass_LONG:
81 case typelib_TypeClass_UNSIGNED_LONG:
82 case typelib_TypeClass_HYPER:
83 case typelib_TypeClass_UNSIGNED_HYPER:
84 case typelib_TypeClass_ENUM:
85 return ReturnKind::RegistersInt;
86 case typelib_TypeClass_FLOAT:
87 case typelib_TypeClass_DOUBLE:
88 return ReturnKind::RegistersFp;
89 case typelib_TypeClass_STRUCT:
90 {
91 Registers regs = { 0, 0, false, false };
92 typelib_TypeDescription* pTypeDescr = nullptr;
93 TYPELIB_DANGER_GET(&pTypeDescr, pTypeRef);
94 int sum = flatten_struct(pTypeDescr, regs);
95 TYPELIB_DANGER_RELEASE(pTypeDescr);
96 if ((sum == 1 || sum == 2) && sum == regs.nr_fp)
97 return ReturnKind::RegistersFp;
98 if (sum == 2 && regs.nr_fp == regs.nr_int)
99 {
100 if (regs.priorInt)
101 return ReturnKind::RegistersIntFp;
102 if (regs.priorFp)
103 return ReturnKind::RegistersFpInt;
104 }
105 return ReturnKind::RegistersInt;
106 }
107 default:
108 return ReturnKind::RegistersInt;
109 }
110}
111
112void loongarch64::fillReturn(typelib_TypeDescriptionReference* pTypeRef, sal_Int64* gret,
113 double* fret, void* pRegisterReturn)
114{
115 ReturnKind returnKind = getReturnKind(pTypeRef);
116 switch (returnKind)
117 {
118 case ReturnKind::RegistersFp:
119 reinterpret_cast<double*>(pRegisterReturn)[0] = fret[0];
120 reinterpret_cast<double*>(pRegisterReturn)[1] = fret[1];
121 break;
122 case ReturnKind::RegistersFpInt:
123 reinterpret_cast<double*>(pRegisterReturn)[0] = fret[0];
124 reinterpret_cast<sal_Int64*>(pRegisterReturn)[1] = gret[0];
125 break;
126 case ReturnKind::RegistersIntFp:
127 reinterpret_cast<sal_Int64*>(pRegisterReturn)[0] = gret[0];
128 reinterpret_cast<double*>(pRegisterReturn)[1] = fret[0];
129 break;
130 default:
131 reinterpret_cast<sal_Int64*>(pRegisterReturn)[0] = gret[0];
132 reinterpret_cast<sal_Int64*>(pRegisterReturn)[1] = gret[1];
133 break;
134 }
135}
136
137/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
XPropertyListType t
void * p
struct _typelib_TypeDescription typelib_TypeDescription
Definition: msvc/except.hxx:53
ReturnKind getReturnKind(typelib_TypeDescription const *type)
int i
ReturnKind getReturnKind(typelib_TypeDescriptionReference *type)
void fillReturn(typelib_TypeDescriptionReference *pTypeRef, sal_Int64 *gret, double *fret, void *pRegisterReturn)
int flatten_struct(typelib_TypeDescription *pTypeDescr, Registers &regs)