From 6e67dc7866b89096ce20b5a180a47b221f8331f6 Mon Sep 17 00:00:00 2001 From: Alexander Penev Date: Wed, 20 Mar 2024 03:02:52 +0000 Subject: [PATCH] Export symbols in Windows DLL --- include/clang/Interpreter/CppInterOp.h | 233 +++++++++++++------------ 1 file changed, 120 insertions(+), 113 deletions(-) diff --git a/include/clang/Interpreter/CppInterOp.h b/include/clang/Interpreter/CppInterOp.h index 96345ffb6..273627875 100644 --- a/include/clang/Interpreter/CppInterOp.h +++ b/include/clang/Interpreter/CppInterOp.h @@ -15,6 +15,13 @@ #include #include +// The cross-platform DllExport macro definition +#ifdef _WIN32 +#define DllExport __declspec(dllexport) +#else +#define DllExport __attribute__((visibility("default"))) +#endif + namespace Cpp { using TCppIndex_t = size_t; using TCppScope_t = void*; @@ -118,317 +125,317 @@ namespace Cpp { }; ///\returns the version string information of the library. - std::string GetVersion(); + DllExport std::string GetVersion(); /// Enables or disables the debugging printouts on stderr. /// Debugging output can be enabled also by the environment variable /// CPPINTEROP_EXTRA_INTERPRETER_ARGS. For example, /// CPPINTEROP_EXTRA_INTERPRETER_ARGS="-mllvm -debug-only=jitcall" to produce /// only debug output for jitcall events. - void EnableDebugOutput(bool value = true); + DllExport void EnableDebugOutput(bool value = true); ///\returns true if the debugging printouts on stderr are enabled. - bool IsDebugOutputEnabled(); + DllExport bool IsDebugOutputEnabled(); /// Checks if the given class represents an aggregate type). ///\returns true if \c scope is an array or a C++ tag (as per C++ ///[dcl.init.aggr]) \returns true if the scope supports aggregate /// initialization. - bool IsAggregate(TCppScope_t scope); + DllExport bool IsAggregate(TCppScope_t scope); /// Checks if the scope is a namespace or not. - bool IsNamespace(TCppScope_t scope); + DllExport bool IsNamespace(TCppScope_t scope); /// Checks if the scope is a class or not. - bool IsClass(TCppScope_t scope); + DllExport bool IsClass(TCppScope_t scope); // See TClingClassInfo::IsLoaded /// Checks if the class definition is present, or not. Performs a /// template instantiation if necessary. - bool IsComplete(TCppScope_t scope); + DllExport bool IsComplete(TCppScope_t scope); - size_t SizeOf(TCppScope_t scope); + DllExport size_t SizeOf(TCppScope_t scope); /// Checks if it is a "built-in" or a "complex" type. - bool IsBuiltin(TCppType_t type); + DllExport bool IsBuiltin(TCppType_t type); /// Checks if it is a templated class. - bool IsTemplate(TCppScope_t handle); + DllExport bool IsTemplate(TCppScope_t handle); /// Checks if it is a class template specialization class. - bool IsTemplateSpecialization(TCppScope_t handle); + DllExport bool IsTemplateSpecialization(TCppScope_t handle); /// Checks if \c handle introduces a typedef name via \c typedef or \c using. - bool IsTypedefed(TCppScope_t handle); + DllExport bool IsTypedefed(TCppScope_t handle); - bool IsAbstract(TCppType_t klass); + DllExport bool IsAbstract(TCppType_t klass); /// Checks if it is an enum name (EnumDecl represents an enum name). - bool IsEnumScope(TCppScope_t handle); + DllExport bool IsEnumScope(TCppScope_t handle); /// Checks if it is an enum's value (EnumConstantDecl represents /// each enum constant that is defined). - bool IsEnumConstant(TCppScope_t handle); + DllExport bool IsEnumConstant(TCppScope_t handle); /// Checks if the passed value is an enum type or not. - bool IsEnumType(TCppType_t type); + DllExport bool IsEnumType(TCppType_t type); /// Extracts enum declarations from a specified scope and stores them in /// vector - void GetEnums(TCppScope_t scope, std::vector& Result); + DllExport void GetEnums(TCppScope_t scope, std::vector& Result); /// We assume that smart pointer types define both operator* and /// operator->. - bool IsSmartPtrType(TCppType_t type); + DllExport bool IsSmartPtrType(TCppType_t type); /// For the given "class", get the integer type that the enum /// represents, so that you can store it properly in your specific /// language. - TCppType_t GetIntegerTypeFromEnumScope(TCppScope_t handle); + DllExport TCppType_t GetIntegerTypeFromEnumScope(TCppScope_t handle); /// For the given "type", this function gets the integer type that the enum /// represents, so that you can store it properly in your specific /// language. - TCppType_t GetIntegerTypeFromEnumType(TCppType_t handle); + DllExport TCppType_t GetIntegerTypeFromEnumType(TCppType_t handle); /// Gets a list of all the enum constants for an enum. - std::vector GetEnumConstants(TCppScope_t scope); + DllExport std::vector GetEnumConstants(TCppScope_t scope); /// Gets the enum name when an enum constant is passed. - TCppType_t GetEnumConstantType(TCppScope_t scope); + DllExport TCppType_t GetEnumConstantType(TCppScope_t scope); /// Gets the index value (0,1,2, etcetera) of the enum constant /// that was passed into this function. - TCppIndex_t GetEnumConstantValue(TCppScope_t scope); + DllExport TCppIndex_t GetEnumConstantValue(TCppScope_t scope); /// Gets the size of the "type" that is passed in to this function. - size_t GetSizeOfType(TCppType_t type); + DllExport size_t GetSizeOfType(TCppType_t type); /// Checks if the passed value is a variable. - bool IsVariable(TCppScope_t scope); + DllExport bool IsVariable(TCppScope_t scope); /// Gets the name of any named decl (a class, /// namespace, variable, or a function). - std::string GetName(TCppScope_t klass); + DllExport std::string GetName(TCppScope_t klass); /// This is similar to GetName() function, but besides /// the name, it also gets the template arguments. - std::string GetCompleteName(TCppType_t klass); + DllExport std::string GetCompleteName(TCppType_t klass); /// Gets the "qualified" name (including the namespace) of any /// named decl (a class, namespace, variable, or a function). - std::string GetQualifiedName(TCppType_t klass); + DllExport std::string GetQualifiedName(TCppType_t klass); /// This is similar to GetQualifiedName() function, but besides /// the "qualified" name (including the namespace), it also /// gets the template arguments. - std::string GetQualifiedCompleteName(TCppType_t klass); + DllExport std::string GetQualifiedCompleteName(TCppType_t klass); /// Gets the list of namespaces utilized in the supplied scope. - std::vector GetUsingNamespaces(TCppScope_t scope); + DllExport std::vector GetUsingNamespaces(TCppScope_t scope); /// Gets the global scope of the whole C++ instance. - TCppScope_t GetGlobalScope(); + DllExport TCppScope_t GetGlobalScope(); /// Strips the typedef and returns the underlying class, and if the /// underlying decl is not a class it returns the input unchanged. - TCppScope_t GetUnderlyingScope(TCppScope_t scope); + DllExport TCppScope_t GetUnderlyingScope(TCppScope_t scope); /// Gets the namespace or class (by stripping typedefs) for the name /// passed as a parameter, and if the parent is not passed, /// then global scope will be assumed. - TCppScope_t GetScope(const std::string &name, TCppScope_t parent = 0); + DllExport TCppScope_t GetScope(const std::string &name, TCppScope_t parent = 0); /// When the namespace is known, then the parent doesn't need /// to be specified. This will probably be phased-out in /// future versions of the interop library. - TCppScope_t GetScopeFromCompleteName(const std::string &name); + DllExport TCppScope_t GetScopeFromCompleteName(const std::string &name); /// This function performs a lookup within the specified parent, /// a specific named entity (functions, enums, etcetera). - TCppScope_t GetNamed(const std::string &name, + DllExport TCppScope_t GetNamed(const std::string &name, TCppScope_t parent = nullptr); /// Gets the parent of the scope that is passed as a parameter. - TCppScope_t GetParentScope(TCppScope_t scope); + DllExport TCppScope_t GetParentScope(TCppScope_t scope); /// Gets the scope of the type that is passed as a parameter. - TCppScope_t GetScopeFromType(TCppType_t type); + DllExport TCppScope_t GetScopeFromType(TCppType_t type); /// Gets the number of Base Classes for the Derived Class that /// is passed as a parameter. - TCppIndex_t GetNumBases(TCppType_t klass); + DllExport TCppIndex_t GetNumBases(TCppType_t klass); /// Gets a specific Base Class using its index. Typically GetNumBases() /// is used to get the number of Base Classes, and then that number /// can be used to iterate through the index value to get each specific /// base class. - TCppScope_t GetBaseClass(TCppType_t klass, TCppIndex_t ibase); + DllExport DllExport TCppScope_t GetBaseClass(TCppType_t klass, TCppIndex_t ibase); /// Checks if the supplied Derived Class is a sub-class of the /// provided Base Class. - bool IsSubclass(TCppScope_t derived, TCppScope_t base); + DllExport bool IsSubclass(TCppScope_t derived, TCppScope_t base); /// Each base has its own offset in a Derived Class. This offset can be /// used to get to the Base Class fields. - int64_t GetBaseClassOffset(TCppScope_t derived, TCppScope_t base); + DllExport int64_t GetBaseClassOffset(TCppScope_t derived, TCppScope_t base); /// Gets a list of all the Methods that are in the Class that is /// supplied as a parameter. - std::vector GetClassMethods(TCppScope_t klass); + DllExport std::vector GetClassMethods(TCppScope_t klass); ///\returns if a class has a default constructor. - bool HasDefaultConstructor(TCppScope_t scope); + DllExport bool HasDefaultConstructor(TCppScope_t scope); ///\returns the default constructor of a class, if any. - TCppFunction_t GetDefaultConstructor(TCppScope_t scope); + DllExport TCppFunction_t GetDefaultConstructor(TCppScope_t scope); ///\returns the class destructor, if any. - TCppFunction_t GetDestructor(TCppScope_t scope); + DllExport TCppFunction_t GetDestructor(TCppScope_t scope); /// Looks up all the functions that have the name that is /// passed as a parameter in this function. - std::vector GetFunctionsUsingName( + DllExport std::vector GetFunctionsUsingName( TCppScope_t scope, const std::string& name); /// Gets the return type of the provided function. - TCppType_t GetFunctionReturnType(TCppFunction_t func); + DllExport TCppType_t GetFunctionReturnType(TCppFunction_t func); /// Gets the number of Arguments for the provided function. - TCppIndex_t GetFunctionNumArgs(TCppFunction_t func); + DllExport TCppIndex_t GetFunctionNumArgs(TCppFunction_t func); /// Gets the number of Required Arguments for the provided function. - TCppIndex_t GetFunctionRequiredArgs(TCppConstFunction_t func); + DllExport TCppIndex_t GetFunctionRequiredArgs(TCppConstFunction_t func); /// For each Argument of a function, you can get the Argument Type /// by providing the Argument Index, based on the number of arguments /// from the GetFunctionNumArgs() function. - TCppType_t GetFunctionArgType(TCppFunction_t func, TCppIndex_t iarg); + DllExport TCppType_t GetFunctionArgType(TCppFunction_t func, TCppIndex_t iarg); ///\returns a stringified version of a given function signature in the form: /// void N::f(int i, double d, long l = 0, char ch = 'a'). - std::string GetFunctionSignature(TCppFunction_t func); + DllExport std::string GetFunctionSignature(TCppFunction_t func); ///\returns if a function was marked as \c =delete. - bool IsFunctionDeleted(TCppConstFunction_t function); + DllExport bool IsFunctionDeleted(TCppConstFunction_t function); - bool IsTemplatedFunction(TCppFunction_t func); + DllExport bool IsTemplatedFunction(TCppFunction_t func); /// This function performs a lookup to check if there is a /// templated function of that type. - bool ExistsFunctionTemplate(const std::string& name, + DllExport bool ExistsFunctionTemplate(const std::string& name, TCppScope_t parent = 0); /// Checks if the provided parameter is a method. - bool IsMethod(TCppConstFunction_t method); + DllExport bool IsMethod(TCppConstFunction_t method); /// Checks if the provided parameter is a 'Public' method. - bool IsPublicMethod(TCppFunction_t method); + DllExport bool IsPublicMethod(TCppFunction_t method); /// Checks if the provided parameter is a 'Protected' method. - bool IsProtectedMethod(TCppFunction_t method); + DllExport bool IsProtectedMethod(TCppFunction_t method); /// Checks if the provided parameter is a 'Private' method. - bool IsPrivateMethod(TCppFunction_t method); + DllExport bool IsPrivateMethod(TCppFunction_t method); /// Checks if the provided parameter is a Constructor. - bool IsConstructor(TCppConstFunction_t method); + DllExport bool IsConstructor(TCppConstFunction_t method); /// Checks if the provided parameter is a Destructor. - bool IsDestructor(TCppConstFunction_t method); + DllExport bool IsDestructor(TCppConstFunction_t method); /// Checks if the provided parameter is a 'Static' method. - bool IsStaticMethod(TCppConstFunction_t method); + DllExport bool IsStaticMethod(TCppConstFunction_t method); ///\returns the address of the function given its potentially mangled name. - TCppFuncAddr_t GetFunctionAddress(const char* mangled_name); + DllExport TCppFuncAddr_t GetFunctionAddress(const char* mangled_name); ///\returns the address of the function given its function declaration. - TCppFuncAddr_t GetFunctionAddress(TCppFunction_t method); + DllExport TCppFuncAddr_t GetFunctionAddress(TCppFunction_t method); /// Checks if the provided parameter is a 'Virtual' method. - bool IsVirtualMethod(TCppFunction_t method); + DllExport bool IsVirtualMethod(TCppFunction_t method); /// Gets all the Fields/Data Members of a Class. For now, it /// only gets non-static data members but in a future update, /// it may support getting static data members as well. - std::vector GetDatamembers(TCppScope_t scope); + DllExport std::vector GetDatamembers(TCppScope_t scope); /// This is a Lookup function to be used specifically for data members. - TCppScope_t LookupDatamember(const std::string& name, TCppScope_t parent); + DllExport TCppScope_t LookupDatamember(const std::string& name, TCppScope_t parent); /// Gets the type of the variable that is passed as a parameter. - TCppType_t GetVariableType(TCppScope_t var); + DllExport TCppType_t GetVariableType(TCppScope_t var); /// Gets the address of the variable, you can use it to get the /// value stored in the variable. - intptr_t GetVariableOffset(TCppScope_t var); + DllExport intptr_t GetVariableOffset(TCppScope_t var); /// Checks if the provided variable is a 'Public' variable. - bool IsPublicVariable(TCppScope_t var); + DllExport bool IsPublicVariable(TCppScope_t var); /// Checks if the provided variable is a 'Protected' variable. - bool IsProtectedVariable(TCppScope_t var); + DllExport bool IsProtectedVariable(TCppScope_t var); /// Checks if the provided variable is a 'Private' variable. - bool IsPrivateVariable(TCppScope_t var); + DllExport bool IsPrivateVariable(TCppScope_t var); /// Checks if the provided variable is a 'Static' variable. - bool IsStaticVariable(TCppScope_t var); + DllExport bool IsStaticVariable(TCppScope_t var); /// Checks if the provided variable is a 'Constant' variable. - bool IsConstVariable(TCppScope_t var); + DllExport bool IsConstVariable(TCppScope_t var); /// Checks if the provided parameter is a Record (struct). - bool IsRecordType(TCppType_t type); + DllExport bool IsRecordType(TCppType_t type); /// Checks if the provided parameter is a Plain Old Data Type (POD). - bool IsPODType(TCppType_t type); + DllExport bool IsPODType(TCppType_t type); /// Gets the pure, Underlying Type (as opposed to the Using Type). - TCppType_t GetUnderlyingType(TCppType_t type); + DllExport TCppType_t GetUnderlyingType(TCppType_t type); /// Gets the Type (passed as a parameter) as a String value. - std::string GetTypeAsString(TCppType_t type); + DllExport std::string GetTypeAsString(TCppType_t type); /// Gets the Canonical Type string from the std string. A canonical type /// is the type with any typedef names, syntactic sugars or modifiers stripped /// out of it. - TCppType_t GetCanonicalType(TCppType_t type); + DllExport TCppType_t GetCanonicalType(TCppType_t type); /// Used to either get the built-in type of the provided string, or /// use the name to lookup the actual type. - TCppType_t GetType(const std::string &type); + DllExport TCppType_t GetType(const std::string &type); ///\returns the complex of the provided type. - TCppType_t GetComplexType(TCppType_t element_type); + DllExport TCppType_t GetComplexType(TCppType_t element_type); /// This will convert a class into its type, so for example, you can /// use it to declare variables in it. - TCppType_t GetTypeFromScope(TCppScope_t klass); + DllExport TCppType_t GetTypeFromScope(TCppScope_t klass); /// Checks if a C++ type derives from another. - bool IsTypeDerivedFrom(TCppType_t derived, TCppType_t base); + DllExport bool IsTypeDerivedFrom(TCppType_t derived, TCppType_t base); /// Creates a trampoline function by using the interpreter and returns a /// uniform interface to call it from compiled code. - JitCall MakeFunctionCallable(TCppConstFunction_t func); + DllExport JitCall MakeFunctionCallable(TCppConstFunction_t func); /// Checks if a function declared is of const type or not. - bool IsConstMethod(TCppFunction_t method); + DllExport bool IsConstMethod(TCppFunction_t method); ///\returns the default argument value as string. - std::string GetFunctionArgDefault(TCppFunction_t func, TCppIndex_t param_index); + DllExport std::string GetFunctionArgDefault(TCppFunction_t func, TCppIndex_t param_index); ///\returns the argument name of function as string. - std::string GetFunctionArgName(TCppFunction_t func, TCppIndex_t param_index); + DllExport std::string GetFunctionArgName(TCppFunction_t func, TCppIndex_t param_index); /// Creates an instance of the interpreter we need for the various interop /// services. ///\param[in] Args - the list of arguments for interpreter constructor. ///\param[in] CPPINTEROP_EXTRA_INTERPRETER_ARGS - an env variable, if defined, /// adds additional arguments to the interpreter. - extern "C" TInterp_t + extern "C" DllExport TInterp_t CreateInterpreter(const std::vector& Args = {}, const std::vector& GpuArgs = {}); @@ -436,44 +443,44 @@ namespace Cpp { /// Clang-REPL, etcetera). In practice, the selected interpreter should not /// matter, since the library will function in the same way. ///\returns the current interpreter instance, if any. - TInterp_t GetInterpreter(); + DllExport TInterp_t GetInterpreter(); /// Adds a Search Path for the Interpreter to get the libraries. - void AddSearchPath(const char *dir, bool isUser = true, bool prepend = false); + DllExport void AddSearchPath(const char *dir, bool isUser = true, bool prepend = false); /// Returns the resource-dir path (for headers). - const char* GetResourceDir(); + DllExport const char* GetResourceDir(); /// Uses the underlying clang compiler to detect the resource directory. /// In essence calling clang -print-resource-dir and checks if it ends with /// a compatible to CppInterOp version. ///\param[in] ClangBinaryName - the name (or the full path) of the compiler /// to ask. - std::string DetectResourceDir(const char* ClangBinaryName = "clang"); + DllExport std::string DetectResourceDir(const char* ClangBinaryName = "clang"); /// Asks the system compiler for its default include paths. ///\param[out] Paths - the list of include paths returned by eg. /// `c++ -xc++ -E -v /dev/null 2>&1` ///\param[in] CompilerName - the name (or the full path) of the compiler /// binary file. - void DetectSystemCompilerIncludePaths(std::vector& Paths, + DllExport void DetectSystemCompilerIncludePaths(std::vector& Paths, const char* CompilerName = "c++"); /// Secondary search path for headers, if not found using the /// GetResourceDir() function. - void AddIncludePath(const char *dir); + DllExport void AddIncludePath(const char *dir); /// Only Declares a code snippet in \c code and does not execute it. ///\returns 0 on success - int Declare(const char* code, bool silent = false); + DllExport int Declare(const char* code, bool silent = false); /// Declares and executes a code snippet in \c code. ///\returns 0 on success - int Process(const char *code); + DllExport int Process(const char *code); /// Declares, executes and returns the execution result as a intptr_t. ///\returns the expression results as a intptr_t. - intptr_t Evaluate(const char *code, bool *HadError = nullptr); + DllExport intptr_t Evaluate(const char *code, bool *HadError = nullptr); /// Looks up the library if access is enabled. ///\returns the path to the library. @@ -482,17 +489,17 @@ namespace Cpp { /// Finds \c lib_stem considering the list of search paths and loads it by /// calling dlopen. /// \returns true on success. - bool LoadLibrary(const char* lib_stem, bool lookup = true); + DllExport bool LoadLibrary(const char* lib_stem, bool lookup = true); /// Finds \c lib_stem considering the list of search paths and unloads it by /// calling dlclose. /// function. - void UnloadLibrary(const char* lib_stem); + DllExport void UnloadLibrary(const char* lib_stem); /// Scans all libraries on the library search path for a given potentially /// mangled symbol name. ///\returns the path to the first library that contains the symbol definition. - std::string SearchLibrariesForSymbol(const char* mangled_name, + DllExport std::string SearchLibrariesForSymbol(const char* mangled_name, bool search_system /*true*/); /// Inserts or replaces a symbol in the JIT with the one provided. This is @@ -503,11 +510,11 @@ namespace Cpp { ///\param[in] address - the new address of the symbol. /// ///\returns true on failure. - bool InsertOrReplaceJitSymbol(const char* linker_mangled_name, + DllExport bool InsertOrReplaceJitSymbol(const char* linker_mangled_name, uint64_t address); /// Tries to load provided objects in a string format (prettyprint). - std::string ObjToString(const char *type, void *obj); + DllExport std::string ObjToString(const char *type, void *obj); struct TemplateArgInfo { TCppType_t m_Type; @@ -515,23 +522,23 @@ namespace Cpp { TemplateArgInfo(TCppScope_t type, const char* integral_value = nullptr) : m_Type(type), m_IntegralValue(integral_value) {} }; - TCppScope_t InstantiateClassTemplate(TCppScope_t tmpl, + DllExport TCppScope_t InstantiateClassTemplate(TCppScope_t tmpl, TemplateArgInfo* template_args, size_t template_args_size); /// Returns the class template instantiation arguments of \c templ_instance. - void GetClassTemplateInstantiationArgs(TCppScope_t templ_instance, + DllExport void GetClassTemplateInstantiationArgs(TCppScope_t templ_instance, std::vector &args); /// Instantiates a function template from a given string representation. This /// function also does overload resolution. ///\returns the instantiated function template declaration. - TCppFunction_t + DllExport TCppFunction_t InstantiateTemplateFunctionFromString(const char* function_template); - std::vector GetAllCppNames(TCppScope_t scope); + DllExport std::vector GetAllCppNames(TCppScope_t scope); - void DumpScope(TCppScope_t scope); + DllExport void DumpScope(TCppScope_t scope); namespace DimensionValue { enum : long int { @@ -540,22 +547,22 @@ namespace Cpp { } /// Gets the size/dimensions of a multi-dimension array. - std::vector GetDimensions(TCppType_t type); + DllExport std::vector GetDimensions(TCppType_t type); /// Allocates memory for a given class. - TCppObject_t Allocate(TCppScope_t scope); + DllExport TCppObject_t Allocate(TCppScope_t scope); /// Deallocates memory for a given class. - void Deallocate(TCppScope_t scope, TCppObject_t address); + DllExport void Deallocate(TCppScope_t scope, TCppObject_t address); /// Creates an object of class \c scope and calls its default constructor. If /// \c arena is set it uses placement new. - TCppObject_t Construct(TCppScope_t scope, + DllExport TCppObject_t Construct(TCppScope_t scope, void* arena = nullptr); /// Calls the destructor of object of type \c type. When withFree is true it /// calls operator delete/free. - void Destruct(TCppObject_t This, TCppScope_t type, + DllExport void Destruct(TCppObject_t This, TCppScope_t type, bool withFree = true); /// @name Stream Redirection @@ -571,10 +578,10 @@ namespace Cpp { /// Begins recording the given standard stream. ///\param[fd_kind] - The stream to be captured - void BeginStdStreamCapture(CaptureStreamKind fd_kind); + DllExport void BeginStdStreamCapture(CaptureStreamKind fd_kind); /// Ends recording the standard stream and returns the result as a string. - std::string EndStdStreamCapture(); + DllExport std::string EndStdStreamCapture(); ///@} } // end namespace Cpp