Skip to content

Commit d0995a3

Browse files
committed
Make ThunkBuilder into a more extensible class
In preparation for creating a JitBuilder extension for ThunkBuilder, to facilitate the client API creation, the ThunkBuilder class needs to become more like a fully extensible with an independent header. Signed-off-by: Mark Stoodley <mstoodle@ca.ibm.com>
1 parent 153fd66 commit d0995a3

File tree

6 files changed

+92
-77
lines changed

6 files changed

+92
-77
lines changed

compiler/ilgen/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ compiler_library(ilgen
2828
${CMAKE_CURRENT_LIST_DIR}/OMRBytecodeBuilder.cpp
2929
${CMAKE_CURRENT_LIST_DIR}/OMRIlType.cpp
3030
${CMAKE_CURRENT_LIST_DIR}/OMRTypeDictionary.cpp
31-
${CMAKE_CURRENT_LIST_DIR}/ThunkBuilder.cpp
31+
${CMAKE_CURRENT_LIST_DIR}/OMRThunkBuilder.cpp
3232
${CMAKE_CURRENT_LIST_DIR}/VirtualMachineOperandStack.cpp
3333
)

compiler/ilgen/ThunkBuilder.cpp renamed to compiler/ilgen/OMRThunkBuilder.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@
4141
* different method signatures.
4242
*/
4343

44-
namespace OMR
45-
{
46-
47-
ThunkBuilder::ThunkBuilder(TR::TypeDictionary *types, const char *name, TR::IlType *returnType,
48-
uint32_t numCalleeParams, TR::IlType **calleeParamTypes)
44+
OMR::ThunkBuilder::ThunkBuilder(TR::TypeDictionary *types, const char *name, TR::IlType *returnType,
45+
uint32_t numCalleeParams, TR::IlType **calleeParamTypes)
4946
: TR::MethodBuilder(types),
5047
_numCalleeParams(numCalleeParams),
5148
_calleeParamTypes(calleeParamTypes)
@@ -67,7 +64,7 @@ ThunkBuilder::ThunkBuilder(TR::TypeDictionary *types, const char *name, TR::IlTy
6764
}
6865

6966
bool
70-
ThunkBuilder::buildIL()
67+
OMR::ThunkBuilder::buildIL()
7168
{
7269
TR::IlType *pWord = typeDictionary()->PointerTo(Word);
7370

@@ -97,5 +94,3 @@ ThunkBuilder::buildIL()
9794

9895
return true;
9996
}
100-
101-
} // namespace OMR

compiler/ilgen/OMRThunkBuilder.hpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2016, 2018 IBM Corp. and others
3+
*
4+
* This program and the accompanying materials are made available under
5+
* the terms of the Eclipse Public License 2.0 which accompanies this
6+
* distribution and is available at http://eclipse.org/legal/epl-2.0
7+
* or the Apache License, Version 2.0 which accompanies this distribution
8+
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
9+
*
10+
* This Source Code may also be made available under the following Secondary
11+
* Licenses when the conditions for such availability set forth in the
12+
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
13+
* version 2 with the GNU Classpath Exception [1] and GNU General Public
14+
* License, version 2 with the OpenJDK Assembly Exception [2].
15+
*
16+
* [1] https://www.gnu.org/software/classpath/license.html
17+
* [2] http://openjdk.java.net/legal/assembly-exception.html
18+
*
19+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
20+
*******************************************************************************/
21+
22+
#ifndef OMR_THUNKBUILDER_INCL
23+
#define OMR_THUNKBUILDER_INCL
24+
25+
26+
#include "ilgen/ThunkBuilder.hpp"
27+
#include "ilgen/MethodBuilder.hpp"
28+
29+
namespace OMR
30+
{
31+
32+
/**
33+
* @brief provide mechanism to call arbitrary C functions by signature passing array of arguments
34+
*
35+
* ThunkBuilder provides a mechanism like libffi to be able to construct a call to any C function
36+
* by passing arguments in an array. It is not an uncommon scenario when writing a languge runtime
37+
* that you have to call a native function, but you cannot write a direct call to it. For example,
38+
* a language may provide the name of a native call target along with its signature and arguments,
39+
* but the runtime still needs to pass those arguments to particular native function. The runtime
40+
* code needs to be able to handle any kind of native call signature: any number of arguments and
41+
* any combination of parameter types and any return type. ThunkBuilder provides a convenient way
42+
* to generalize the calling of native functions assuming you can describe the signature and have
43+
* a function address to call.
44+
*
45+
* When creating a ThunkBuilder instance, you provide the set of parameters and the return type. After
46+
* compiling the ThunkBuilder instance, the resulting thunk can be used to call any function with that
47+
* signature. You pass the address of the function as well as a properly sized array of Word sized
48+
* arguments. The thunk will convert each argument to the type of its corresponding parameter as it
49+
* calls the given function, and will return the return value as expected.
50+
*/
51+
52+
class ThunkBuilder : public TR::MethodBuilder
53+
{
54+
public:
55+
TR_ALLOC(TR_Memory::IlGenerator)
56+
57+
/**
58+
* @brief construct a ThunkBuilder for a particular signature
59+
* @param types TypeDictionary object that will be used by the ThunkBuilder object
60+
* @param name primarily used for debug purposes and will appear in the compilation log
61+
* @param returnType return type for the thunk's signature
62+
* @param numCalleeParams number of parameters in the thunk's signature
63+
* @param calleeParamTypes array of parameter types in the thunk's signature, must have numCalleeParams elements
64+
*/
65+
ThunkBuilder(TR::TypeDictionary *types, const char *name, TR::IlType *returnType,
66+
uint32_t numCalleeParams, TR::IlType **calleeParamTypes);
67+
virtual ~ThunkBuilder() { }
68+
69+
virtual bool buildIL();
70+
71+
private:
72+
uint32_t _numCalleeParams;
73+
TR::IlType ** _calleeParamTypes;
74+
};
75+
76+
} // namespace OMR
77+
78+
#endif // !defined(OMR_THUNKBUILDER_INCL)

compiler/ilgen/ThunkBuilder.hpp

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2016 IBM Corp. and others
2+
* Copyright (c) 2016, 2018 IBM Corp. and others
33
*
44
* This program and the accompanying materials are made available under
55
* the terms of the Eclipse Public License 2.0 which accompanies this
@@ -19,70 +19,10 @@
1919
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
2020
*******************************************************************************/
2121

22-
#ifndef OMR_THUNKBUILDER_INCL
23-
#define OMR_THUNKBUILDER_INCL
22+
#ifndef TR_THUNKBUILDER_INCL
23+
#define TR_THUNKBUILDER_INCL
2424

25-
26-
#ifndef TR_THUNKBUILDER_DEFINED
27-
#define TR_THUNKBUILDER_DEFINED
28-
#define PUT_OMR_THUNKBUILDER_INTO_TR
29-
#endif
30-
31-
32-
#include "ilgen/MethodBuilder.hpp"
33-
34-
35-
namespace OMR
36-
{
37-
38-
/**
39-
* @brief provide mechanism to call arbitrary C functions by signature passing array of arguments
40-
*
41-
* ThunkBuilder provides a mechanism like libffi to be able to construct a call to any C function
42-
* by passing arguments in an array. It is not an uncommon scenario when writing a languge runtime
43-
* that you have to call a native function, but you cannot write a direct call to it. For example,
44-
* a language may provide the name of a native call target along with its signature and arguments,
45-
* but the runtime still needs to pass those arguments to particular native function. The runtime
46-
* code needs to be able to handle any kind of native call signature: any number of arguments and
47-
* any combination of parameter types and any return type. ThunkBuilder provides a convenient way
48-
* to generalize the calling of native functions assuming you can describe the signature and have
49-
* a function address to call.
50-
*
51-
* When creating a ThunkBuilder instance, you provide the set of parameters and the return type. After
52-
* compiling the ThunkBuilder instance, the resulting thunk can be used to call any function with that
53-
* signature. You pass the address of the function as well as a properly sized array of Word sized
54-
* arguments. The thunk will convert each argument to the type of its corresponding parameter as it
55-
* calls the given function, and will return the return value as expected.
56-
*/
57-
58-
class ThunkBuilder : public TR::MethodBuilder
59-
{
60-
public:
61-
TR_ALLOC(TR_Memory::IlGenerator)
62-
63-
/**
64-
* @brief construct a ThunkBuilder for a particular signature
65-
* @param types TypeDictionary object that will be used by the ThunkBuilder object
66-
* @param name primarily used for debug purposes and will appear in the compilation log
67-
* @param returnType return type for the thunk's signature
68-
* @param numCalleeParams number of parameters in the thunk's signature
69-
* @param calleeParamTypes array of parameter types in the thunk's signature, must have numCalleeParams elements
70-
*/
71-
ThunkBuilder(TR::TypeDictionary *types, const char *name, TR::IlType *returnType,
72-
uint32_t numCalleeParams, TR::IlType **calleeParamTypes);
73-
virtual ~ThunkBuilder() { }
74-
75-
virtual bool buildIL();
76-
77-
private:
78-
uint32_t _numCalleeParams;
79-
TR::IlType ** _calleeParamTypes;
80-
};
81-
82-
} // namespace OMR
83-
84-
85-
#if defined(PUT_OMR_THUNKBUILDER_INTO_TR)
25+
#include "ilgen/OMRThunkBuilder.hpp"
8626

8727
namespace TR
8828
{
@@ -97,6 +37,4 @@ namespace TR
9737

9838
} // namespace TR
9939

100-
#endif // defined(PUT_OMR_THUNKBUILDER_INTO_TR)
101-
102-
#endif // !defined(OMR_THUNKBUILDER_INCL)
40+
#endif // !defined(TR_THUNKBUILDER_INCL)

jitbuilder/build/files/common.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ JIT_PRODUCT_BACKEND_SOURCES+=\
227227
$(JIT_OMR_DIRTY_DIR)/ilgen/OMRIlType.cpp \
228228
$(JIT_OMR_DIRTY_DIR)/ilgen/OMRIlValue.cpp \
229229
$(JIT_OMR_DIRTY_DIR)/ilgen/OMRMethodBuilder.cpp \
230-
$(JIT_OMR_DIRTY_DIR)/ilgen/ThunkBuilder.cpp \
230+
$(JIT_OMR_DIRTY_DIR)/ilgen/OMRThunkBuilder.cpp \
231231
$(JIT_OMR_DIRTY_DIR)/ilgen/OMRTypeDictionary.cpp \
232232
$(JIT_OMR_DIRTY_DIR)/ilgen/VirtualMachineOperandArray.cpp \
233233
$(JIT_OMR_DIRTY_DIR)/ilgen/VirtualMachineOperandStack.cpp \

jitbuilder/build/rules/common.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ $(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/OMRMethodBuilder.hpp: $(FIXED_SRCB
120120
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/MethodBuilder.hpp: $(FIXED_SRCBASE)/$(JIT_OMR_DIRTY_DIR)/ilgen/MethodBuilder.hpp $(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen
121121
cp $< $@ || cp $< $@
122122

123+
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/OMRThunkBuilder.hpp: $(FIXED_SRCBASE)/$(JIT_OMR_DIRTY_DIR)/ilgen/OMRThunkBuilder.hpp $(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen
124+
cp $< $@ || cp $< $@
125+
123126
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/ThunkBuilder.hpp: $(FIXED_SRCBASE)/$(JIT_OMR_DIRTY_DIR)/ilgen/ThunkBuilder.hpp $(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen
124127
cp $< $@ || cp $< $@
125128

@@ -178,6 +181,7 @@ JITBUILDER_FILES=$(RELEASE_DIR)/Makefile \
178181
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/IlBuilder.hpp \
179182
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/OMRMethodBuilder.hpp \
180183
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/MethodBuilder.hpp \
184+
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/OMRThunkBuilder.hpp \
181185
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/ThunkBuilder.hpp \
182186
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/OMRBytecodeBuilder.hpp \
183187
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/BytecodeBuilder.hpp \

0 commit comments

Comments
 (0)