@@ -103,6 +103,7 @@ class JitCall {
103103 enum Kind : char {
104104 kUnknown = 0 ,
105105 kGenericCall ,
106+ kConstructorCall ,
106107 kDestructorCall ,
107108 };
108109 struct ArgList {
@@ -116,20 +117,25 @@ class JitCall {
116117 // FIXME: Hide these implementation details by moving wrapper generation in
117118 // this class.
118119 // (self, nargs, args, result, nary)
119- using GenericCall = void (*)(void *, size_t , void **, void *, size_t );
120+ using GenericCall = void (*)(void *, size_t , void **, void *);
121+ // (result, nary, nargs, args, is_arena)
122+ using ConstructorCall = void (*)(void *, size_t , size_t , void **, int );
120123 // (self, nary, withFree)
121124 using DestructorCall = void (*)(void *, size_t , int );
122125
123126private:
124127 union {
125128 GenericCall m_GenericCall;
129+ ConstructorCall m_ConstructorCall;
126130 DestructorCall m_DestructorCall;
127131 };
128132 Kind m_Kind;
129133 TCppConstFunction_t m_FD;
130134 JitCall () : m_GenericCall(nullptr ), m_Kind(kUnknown ), m_FD(nullptr ) {}
131135 JitCall (Kind K, GenericCall C, TCppConstFunction_t FD)
132136 : m_GenericCall(C), m_Kind(K), m_FD(FD) {}
137+ JitCall (Kind K, ConstructorCall C, TCppConstFunction_t Ctor)
138+ : m_ConstructorCall(C), m_Kind(K), m_FD(Ctor) {}
133139 JitCall (Kind K, DestructorCall C, TCppConstFunction_t Dtor)
134140 : m_DestructorCall(C), m_Kind(K), m_FD(Dtor) {}
135141
@@ -164,20 +170,24 @@ class JitCall {
164170 // self can go in the end and be nullptr by default; result can be a nullptr
165171 // by default. These changes should be synchronized with the wrapper if we
166172 // decide to directly.
167- void Invoke (void * result, ArgList args = {}, void * self = nullptr ,
168- size_t nary = 0UL ) const {
173+ void Invoke (void * result, ArgList args = {}, void * self = nullptr ) const {
169174 // NOLINTBEGIN(*-type-union-access)
170175 // Forward if we intended to call a dtor with only 1 parameter.
171176 if (m_Kind == kDestructorCall && result && !args.m_Args ) {
172- InvokeDestructor (result, nary, /* withFree=*/ true );
177+ InvokeDestructor (result, /* nary=*/ 0UL , /* withFree=*/ true );
178+ return ;
179+ }
180+
181+ else if (m_Kind == kConstructorCall && result && !args.m_Args ) {
182+ InvokeConstructor (result, /* nary=*/ 1UL , args, false );
173183 return ;
174184 }
175185
176186#ifndef NDEBUG
177187 assert (AreArgumentsValid (result, args, self) && " Invalid args!" );
178188 ReportInvokeStart (result, args, self);
179189#endif // NDEBUG
180- m_GenericCall (self, args.m_ArgSize , args.m_Args , result, nary );
190+ m_GenericCall (self, args.m_ArgSize , args.m_Args , result);
181191 // NOLINTEND(*-type-union-access)
182192 }
183193 // / Makes a call to a destructor.
@@ -195,6 +205,22 @@ class JitCall {
195205#endif // NDEBUG
196206 m_DestructorCall (object, nary, withFree);
197207 }
208+
209+ // / Makes a call to a constructor.
210+ // /\param[in] result - the memory address at which we construct the object
211+ // /(placement new). \param[in] nary - Use array new if we have to construct an
212+ // /array of objects (nary > 1). \param[in] args - a pointer to a argument list
213+ // /and argument size.
214+ // FIXME: Change the type of withFree from int to bool in the wrapper code.
215+ void InvokeConstructor (void * result, unsigned long nary = 1 ,
216+ ArgList args = {}, bool is_arena = false ) const {
217+ assert (m_Kind == kConstructorCall && " Wrong overload!" );
218+ #ifndef NDEBUG
219+ assert (AreArgumentsValid (result, args, nullptr , nary) && " Invalid args!" );
220+ ReportInvokeStart (result, args, nullptr );
221+ #endif // NDEBUG
222+ m_ConstructorCall (result, nary, args.m_ArgSize , args.m_Args , (int )is_arena);
223+ }
198224};
199225
200226// /\returns the version string information of the library.
0 commit comments