diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..add15db --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.13) + +project(LLVMSharp VERSION 20.1.2) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +add_subdirectory(sources) diff --git a/LLVMSharp.sln b/LLVMSharp.sln index b519407..d2d0d27 100644 --- a/LLVMSharp.sln +++ b/LLVMSharp.sln @@ -100,6 +100,41 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libLLVM.runtime.osx-arm64", packages\libLLVM\libLLVM.runtime.osx-arm64\libLLVM.runtime.osx-arm64.nuspec = packages\libLLVM\libLLVM.runtime.osx-arm64\libLLVM.runtime.osx-arm64.nuspec EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libLLVMSharp", "libLLVMSharp", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libLLVMSharp", "libLLVMSharp", "{0682D98B-82C9-4EC9-8207-70C142418BB2}" + ProjectSection(SolutionItems) = preProject + packages\libLLVMSharp\libLLVMSharp\libLLVMSharp.nuspec = packages\libLLVMSharp\libLLVMSharp\libLLVMSharp.nuspec + packages\libLLVMSharp\libLLVMSharp\LICENSE.TXT = packages\libLLVMSharp\libLLVMSharp\LICENSE.TXT + packages\libLLVMSharp\libLLVMSharp\NOTICE.txt = packages\libLLVMSharp\libLLVMSharp\NOTICE.txt + packages\libLLVMSharp\libLLVMSharp\runtime.json = packages\libLLVMSharp\libLLVMSharp\runtime.json + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libLLVMSharp.runtime.linux-arm64", "libLLVMSharp.runtime.linux-arm64", "{50AABB72-FDA0-417B-875D-3DB2EE7C3BAF}" + ProjectSection(SolutionItems) = preProject + packages\libLLVMSharp\libLLVMSharp.runtime.linux-arm64\libLLVMSharp.runtime.linux-arm64.nuspec = packages\libLLVMSharp\libLLVMSharp.runtime.linux-arm64\libLLVMSharp.runtime.linux-arm64.nuspec + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libLLVMSharp.runtime.linux-x64", "libLLVMSharp.runtime.linux-x64", "{C7FC1228-24FC-4353-8676-F48CBAAB39F2}" + ProjectSection(SolutionItems) = preProject + packages\libLLVMSharp\libLLVMSharp.runtime.linux-x64\libLLVMSharp.runtime.linux-x64.nuspec = packages\libLLVMSharp\libLLVMSharp.runtime.linux-x64\libLLVMSharp.runtime.linux-x64.nuspec + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libLLVMSharp.runtime.osx-arm64", "libLLVMSharp.runtime.osx-arm64", "{5C3AF6C4-561B-4261-9E7C-6643F95253AF}" + ProjectSection(SolutionItems) = preProject + packages\libLLVMSharp\libLLVMSharp.runtime.osx-arm64\libLLVMSharp.runtime.osx-arm64.nuspec = packages\libLLVMSharp\libLLVMSharp.runtime.osx-arm64\libLLVMSharp.runtime.osx-arm64.nuspec + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libLLVMSharp.runtime.win-arm64", "libLLVMSharp.runtime.win-arm64", "{DD215D09-65A9-4CA2-8D08-1451193194C1}" + ProjectSection(SolutionItems) = preProject + packages\libLLVMSharp\libLLVMSharp.runtime.win-arm64\libLLVMSharp.runtime.win-arm64.nuspec = packages\libLLVMSharp\libLLVMSharp.runtime.win-arm64\libLLVMSharp.runtime.win-arm64.nuspec + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libLLVMSharp.runtime.win-x64", "libLLVMSharp.runtime.win-x64", "{AB31A11D-2B8A-405A-A70A-FD94E99689E5}" + ProjectSection(SolutionItems) = preProject + packages\libLLVMSharp\libLLVMSharp.runtime.win-x64\libLLVMSharp.runtime.win-x64.nuspec = packages\libLLVMSharp\libLLVMSharp.runtime.win-x64\libLLVMSharp.runtime.win-x64.nuspec + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -134,6 +169,13 @@ Global {706334B8-BB91-49A4-BC9C-DFFDF3DCD770} = {E8ADE5A7-4363-43B7-B104-6B0E5510CAF0} {C8508256-2EC1-4C88-B61D-AFB86569FBCD} = {9D46FF1C-E09F-4063-A97D-C09F26310B67} {3870145D-F6DC-4082-A3F5-2316D49ADD43} = {9D46FF1C-E09F-4063-A97D-C09F26310B67} + {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {CD611531-75EA-4328-8C25-8D0496E61EC2} + {0682D98B-82C9-4EC9-8207-70C142418BB2} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} + {50AABB72-FDA0-417B-875D-3DB2EE7C3BAF} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} + {C7FC1228-24FC-4353-8676-F48CBAAB39F2} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} + {5C3AF6C4-561B-4261-9E7C-6643F95253AF} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} + {DD215D09-65A9-4CA2-8D08-1451193194C1} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} + {AB31A11D-2B8A-405A-A70A-FD94E99689E5} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {75550D8C-A492-4ED3-8387-206830F8B21E} diff --git a/packages/libLLVMSharp/libLLVMSharp.runtime.linux-arm64/libLLVMSharp.runtime.linux-arm64.nuspec b/packages/libLLVMSharp/libLLVMSharp.runtime.linux-arm64/libLLVMSharp.runtime.linux-arm64.nuspec new file mode 100644 index 0000000..bb0ddb5 --- /dev/null +++ b/packages/libLLVMSharp/libLLVMSharp.runtime.linux-arm64/libLLVMSharp.runtime.linux-arm64.nuspec @@ -0,0 +1,20 @@ + + + + libLLVMSharp.runtime.linux-arm64 + 20.1.2 + .NET Foundation and Contributors + .NET Foundation and Contributors + true + MIT + https://github.com/dotnet/llvmsharp + linux arm64 native library for libLLVMSharp. + Copyright © .NET Foundation and Contributors + + + + + + + + diff --git a/packages/libLLVMSharp/libLLVMSharp.runtime.linux-x64/libLLVMSharp.runtime.linux-x64.nuspec b/packages/libLLVMSharp/libLLVMSharp.runtime.linux-x64/libLLVMSharp.runtime.linux-x64.nuspec new file mode 100644 index 0000000..43c5969 --- /dev/null +++ b/packages/libLLVMSharp/libLLVMSharp.runtime.linux-x64/libLLVMSharp.runtime.linux-x64.nuspec @@ -0,0 +1,20 @@ + + + + libLLVMSharp.runtime.linux-x64 + 20.1.2 + .NET Foundation and Contributors + .NET Foundation and Contributors + true + MIT + https://github.com/dotnet/llvmsharp + linux x64 native library for libLLVMSharp. + Copyright © .NET Foundation and Contributors + + + + + + + + diff --git a/packages/libLLVMSharp/libLLVMSharp.runtime.osx-arm64/libLLVMSharp.runtime.osx-arm64.nuspec b/packages/libLLVMSharp/libLLVMSharp.runtime.osx-arm64/libLLVMSharp.runtime.osx-arm64.nuspec new file mode 100644 index 0000000..dd24de8 --- /dev/null +++ b/packages/libLLVMSharp/libLLVMSharp.runtime.osx-arm64/libLLVMSharp.runtime.osx-arm64.nuspec @@ -0,0 +1,20 @@ + + + + libLLVMSharp.runtime.osx-arm64 + 20.1.2 + .NET Foundation and Contributors + .NET Foundation and Contributors + true + MIT + https://github.com/dotnet/llvmsharp + osx arm64 native library for libLLVMSharp. + Copyright © .NET Foundation and Contributors + + + + + + + + diff --git a/packages/libLLVMSharp/libLLVMSharp.runtime.win-arm64/libLLVMSharp.runtime.win-arm64.nuspec b/packages/libLLVMSharp/libLLVMSharp.runtime.win-arm64/libLLVMSharp.runtime.win-arm64.nuspec new file mode 100644 index 0000000..a07482c --- /dev/null +++ b/packages/libLLVMSharp/libLLVMSharp.runtime.win-arm64/libLLVMSharp.runtime.win-arm64.nuspec @@ -0,0 +1,20 @@ + + + + libLLVMSharp.runtime.win-arm64 + 20.1.2 + .NET Foundation and Contributors + .NET Foundation and Contributors + true + MIT + https://github.com/dotnet/llvmsharp + win arm64 native library for libLLVMSharp. + Copyright © .NET Foundation and Contributors + + + + + + + + diff --git a/packages/libLLVMSharp/libLLVMSharp.runtime.win-x64/libLLVMSharp.runtime.win-x64.nuspec b/packages/libLLVMSharp/libLLVMSharp.runtime.win-x64/libLLVMSharp.runtime.win-x64.nuspec new file mode 100644 index 0000000..ab2ed2e --- /dev/null +++ b/packages/libLLVMSharp/libLLVMSharp.runtime.win-x64/libLLVMSharp.runtime.win-x64.nuspec @@ -0,0 +1,20 @@ + + + + libLLVMSharp.runtime.win-x64 + 20.1.2 + .NET Foundation and Contributors + .NET Foundation and Contributors + true + MIT + https://github.com/dotnet/llvmsharp + win x64 native library for libLLVMSharp. + Copyright © .NET Foundation and Contributors + + + + + + + + diff --git a/packages/libLLVMSharp/libLLVMSharp/LICENSE.TXT b/packages/libLLVMSharp/libLLVMSharp/LICENSE.TXT new file mode 100644 index 0000000..c33cc0b --- /dev/null +++ b/packages/libLLVMSharp/libLLVMSharp/LICENSE.TXT @@ -0,0 +1,12 @@ +University of Illinois/NCSA Open Source License +Copyright (c) .NET Foundation and Contributors +All rights reserved. + +Developed by: .NET Foundation and Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution. +Neither the names of Microsoft, nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. diff --git a/packages/libLLVMSharp/libLLVMSharp/NOTICE.txt b/packages/libLLVMSharp/libLLVMSharp/NOTICE.txt new file mode 100644 index 0000000..d6e4cf8 --- /dev/null +++ b/packages/libLLVMSharp/libLLVMSharp/NOTICE.txt @@ -0,0 +1,280 @@ +# The LLVM Project + +============================================================================== +The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: +============================================================================== + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +---- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may redistribute such embedded portions in such Object form without complying +with the conditions of Sections 4(a), 4(b) and 4(d) of the License. + +In addition, if you combine or link compiled forms of this Software with +software that is licensed under the GPLv2 ("Combined Software") and if a +court of competent jurisdiction determines that the patent provision (Section +3), the indemnity provision (Section 9) or other Section of the License +conflicts with the conditions of the GPLv2, you may retroactively and +prospectively choose to deem waived or otherwise exclude such Section(s) of +the License, but only in their entirety and only with respect to the Combined +Software. + +============================================================================== +Software from third parties included in the LLVM Project: +============================================================================== +The LLVM Project contains third party software which is under different license +terms. All such code will be identified clearly using at least one of two +mechanisms: +1) It will be in a separate directory tree with its own `LICENSE.txt` or + `LICENSE` file at the top containing the specific license and restrictions + which apply to that software, or +2) It will contain specific license and restriction terms at the top of every + file. + +============================================================================== +Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): +============================================================================== +University of Illinois/NCSA +Open Source License + +Copyright (c) 2007-2019 University of Illinois at Urbana-Champaign. +All rights reserved. + +Developed by: + + LLVM Team + + University of Illinois at Urbana-Champaign + + http://llvm.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimers. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimers in the + documentation and/or other materials provided with the distribution. + + * Neither the names of the LLVM Team, University of Illinois at + Urbana-Champaign, nor the names of its contributors may be used to + endorse or promote products derived from this Software without specific + prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE +SOFTWARE. diff --git a/packages/libLLVMSharp/libLLVMSharp/libLLVMSharp.nuspec b/packages/libLLVMSharp/libLLVMSharp/libLLVMSharp.nuspec new file mode 100644 index 0000000..a0d13c3 --- /dev/null +++ b/packages/libLLVMSharp/libLLVMSharp/libLLVMSharp.nuspec @@ -0,0 +1,22 @@ + + + + libLLVMSharp + 20.1.2 + .NET Foundation and Contributors + .NET Foundation and Contributors + true + MIT + https://github.com/dotnet/llvmsharp + Multi-platform native library for libLLVMSharp. + Copyright © .NET Foundation and Contributors + + + + + + + + + + diff --git a/packages/libLLVMSharp/libLLVMSharp/runtime.json b/packages/libLLVMSharp/libLLVMSharp/runtime.json new file mode 100644 index 0000000..dc7bb5a --- /dev/null +++ b/packages/libLLVMSharp/libLLVMSharp/runtime.json @@ -0,0 +1,29 @@ +{ + "runtimes": { + "linux-arm64": { + "libLLVMSharp": { + "libLLVMSharp.runtime.linux-arm64": "20.1.2" + } + }, + "linux-x64": { + "libLLVMSharp": { + "libLLVMSharp.runtime.linux-x64": "20.1.2" + } + }, + "osx-arm64": { + "libLLVMSharp": { + "libLLVMSharp.runtime.osx-arm64": "20.1.2" + } + }, + "win-arm64": { + "libLLVMSharp": { + "libLLVMSharp.runtime.win-arm64": "20.1.2" + } + }, + "win-x64": { + "libLLVMSharp": { + "libLLVMSharp.runtime.win-x64": "20.1.2" + } + } + } +} diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt new file mode 100644 index 0000000..e24c8f3 --- /dev/null +++ b/sources/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(libLLVMSharp) diff --git a/sources/GenerateLLVM-LICENSE.txt b/sources/GenerateLLVM-LICENSE.txt new file mode 100644 index 0000000..b2de2be --- /dev/null +++ b/sources/GenerateLLVM-LICENSE.txt @@ -0,0 +1,4 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/llvm/include/llvm-c +// Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. diff --git a/sources/GenerateLLVM.rsp b/sources/GenerateLLVM.rsp new file mode 100644 index 0000000..b4bc465 --- /dev/null +++ b/sources/GenerateLLVM.rsp @@ -0,0 +1,103 @@ +--additional +-m64 +--config +exclude-com-proxies +exclude-empty-records +exclude-enum-operators +generate-aggressive-inlining +generate-callconv-member-function +generate-cpp-attributes +generate-disable-runtime-marshalling +generate-file-scoped-namespaces +generate-guid-member +generate-macro-bindings +generate-marker-interfaces +generate-native-inheritance-attribute +generate-setslastsystemerror-attribute +generate-tests-nunit +generate-unmanaged-constants +generate-vtbl-index-attribute +log-potential-typedef-remappings +multi-file +preview-codegen +trimmable-vtbls +unix-types +--exclude +LLVMInitializeNativeAsmParser +LLVMInitializeNativeAsmPrinter +LLVMInitializeNativeDisassembler +LLVMInitializeNativeTarget +LLVM_ATTRIBUTE_C_DEPRECATED +LLVM_DECLARE_VALUE_CAST +LLVM_FOR_EACH_VALUE_SUBCLASS +--file +llvm-c/Analysis.h +llvm-c/BitReader.h +llvm-c/BitWriter.h +llvm-c/blake3.h +llvm-c/Comdat.h +llvm-c/Core.h +llvm-c/DataTypes.h +llvm-c/DebugInfo.h +llvm-c/Deprecated.h +llvm-c/Disassembler.h +llvm-c/DisassemblerTypes.h +llvm-c/Error.h +llvm-c/ErrorHandling.h +llvm-c/ExecutionEngine.h +llvm-c/ExternC.h +llvm-c/IRReader.h +llvm-c/Linker.h +llvm-c/LLJIT.h +llvm-c/lto.h +llvm-c/Object.h +llvm-c/Orc.h +llvm-c/OrcEE.h +llvm-c/Remarks.h +llvm-c/Support.h +llvm-c/Target.h +llvm-c/TargetMachine.h +llvm-c/Types.h +llvm-c/Transforms/PassBuilder.h +--headerFile +./sources/GenerateLLVM-LICENSE.txt +--include-directory +../llvm-project/artifacts/install/include +--methodClassName +LLVM +--namespace +LLVMSharp.Interop +--output +./sources/LLVMSharp.Interop/llvm +--prefixStrip +LLVM +--remap +LLVMAttributeIndex=LLVMAttributeIndex +LLVM_BLAKE3_BLOCK_LEN=@BLAKE3_BLOCK_LEN +LLVM_BLAKE3_CHUNK_LEN=@BLAKE3_CHUNK_LEN +llvm_blake3_hasher_finalize=@blake3_hasher_finalize +llvm_blake3_hasher_finalize_seek=@blake3_hasher_finalize_seek +llvm_blake3_hasher_init=@blake3_hasher_init +llvm_blake3_hasher_init_derive_key=@blake3_hasher_init_derive_key +llvm_blake3_hasher_init_derive_key_raw=@blake3_hasher_init_derive_key_raw +llvm_blake3_hasher_init_keyed=@blake3_hasher_init_keyed +llvm_blake3_hasher_reset=@blake3_hasher_reset +llvm_blake3_hasher_update=@blake3_hasher_update +LLVM_BLAKE3_KEY_LEN=@BLAKE3_KEY_LEN +LLVM_BLAKE3_MAX_DEPTH=@BLAKE3_MAX_DEPTH +LLVM_BLAKE3_OUT_LEN=@BLAKE3_OUT_LEN +llvm_blake3_version=@blake3_version +LLVM_BLAKE3_VERSION_STRING=@BLAKE3_VERSION_STRING +LLVMOpaqueValueMetadataEntry=LLVMValueMetadataEntry +LLVMOpaqueModuleFlagEntry=LLVMModuleFlagEntry +__AnonymousEnum_Core_L462_C1=@LLVMAttributeIndex +__AnonymousEnum_Core_L486_C1=@LLVMFastMathFlags +__AnonymousEnum_DebugInfo_L147_C1=@LLVMMetadataKind +--test-output +./tests/LLVMSharp.UnitTests/Interop +--with-attribute +LLVMDIFlags=Flags +LLVMJITSymbolGenericFlags=Flags +LLVMFastMathFlags=Flags +LLVMOrcJITDylibLookupFlags=Flags +LLVMOrcSymbolLookupFlags=Flags diff --git a/sources/GenerateLLVMSharp-LICENSE.txt b/sources/GenerateLLVMSharp-LICENSE.txt new file mode 100644 index 0000000..43abbec --- /dev/null +++ b/sources/GenerateLLVMSharp-LICENSE.txt @@ -0,0 +1,2 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. +// Ported from https://github.com/dotnet/llvmsharp/blob/main/sources/libLLVMSharp diff --git a/sources/GenerateLLVMSharp.rsp b/sources/GenerateLLVMSharp.rsp new file mode 100644 index 0000000..443d5e9 --- /dev/null +++ b/sources/GenerateLLVMSharp.rsp @@ -0,0 +1,50 @@ +--additional +-m64 +-std=c++17 +--config +exclude-com-proxies +exclude-empty-records +exclude-enum-operators +generate-aggressive-inlining +generate-callconv-member-function +generate-cpp-attributes +generate-disable-runtime-marshalling +generate-file-scoped-namespaces +generate-guid-member +generate-macro-bindings +generate-marker-interfaces +generate-native-inheritance-attribute +generate-setslastsystemerror-attribute +generate-tests-nunit +generate-unmanaged-constants +generate-vtbl-index-attribute +log-potential-typedef-remappings +multi-file +preview-codegen +trimmable-vtbls +unix-types +--define-macro +_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING +LLVMSharp_EXPORTS +--file +./sources/libLLVMSharp/LLVMSharp.h +--headerFile +./sources/GenerateLLVMSharp-LICENSE.txt +--include-directory +./artifacts/bin/native/sources/libLLVMSharp +--include-directory +../llvm-project/artifacts/install/include +--methodClassName +llvmsharp +--namespace +LLVMSharp.Interop +--libraryPath +libLLVMSharp +--output +./sources/LLVMSharp.Interop/llvmsharp +--prefixStrip +llvmsharp_ +--remap +MSGuidDeclParts=@Guid +--test-output +./tests/LLVMSharp.UnitTests/InteropTests diff --git a/sources/LLVMSharp.Interop/Extensions/LLVM.Manual.cs b/sources/LLVMSharp.Interop/Extensions/LLVM.Manual.cs index e17eca0..1f0d1f4 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVM.Manual.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVM.Manual.cs @@ -3,12 +3,46 @@ // Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/llvm/include/llvm-c // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. +using System; using System.Runtime.InteropServices; namespace LLVMSharp.Interop; public static unsafe partial class LLVM { + public static string DIFileGetDirectory(LLVMMetadataRef file) + { + uint length = 0; + sbyte* directory = DIFileGetDirectory(file, &length); + if (directory == null) + { + return ""; + } + return new ReadOnlySpan(directory, (int)length).AsString(); + } + + public static string DIFileGetFilename(LLVMMetadataRef file) + { + uint length = 0; + sbyte* filename = DIFileGetFilename(file, &length); + if (filename == null) + { + return ""; + } + return new ReadOnlySpan(filename, (int)length).AsString(); + } + + public static string DITypeGetName(LLVMMetadataRef type) + { + nuint length = 0; + sbyte* name = DITypeGetName(type, &length); + if (name == null) + { + return ""; + } + return new ReadOnlySpan(name, (int)length).AsString(); + } + [DllImport("libLLVM", CallingConvention = CallingConvention.Cdecl, EntryPoint = "LLVMInitializeAArch64TargetInfo", ExactSpelling = true)] public static extern void InitializeAArch64TargetInfo(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs index 09c5f9e..45db15b 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs @@ -8,103 +8,313 @@ public unsafe partial struct LLVMMetadataRef(IntPtr handle) : IEquatable IsType ? LLVM.DITypeGetAlignInBits(this) : default; - - public readonly uint Column => Kind switch { - LLVMMetadataKind.LLVMDILocationMetadataKind => LLVM.DILocationGetColumn(this), - _ => default, - }; - - public readonly LLVMMetadataRef Expression => Kind switch { - LLVMMetadataKind.LLVMDIGlobalVariableExpressionMetadataKind => LLVM.DIGlobalVariableExpressionGetExpression(this), - _ => default, - }; - - public readonly LLVMMetadataRef File => Kind switch { - LLVMMetadataKind.LLVMDIFileMetadataKind => this, - LLVMMetadataKind.LLVMDISubprogramMetadataKind => LLVM.DIScopeGetFile(this), - _ when IsVariable => LLVM.DIVariableGetFile(this), - _ => default, - }; - - public readonly LLVMDIFlags Flags => IsType ? LLVM.DITypeGetFlags(this) : default; - - public readonly LLVMMetadataRef InlinedAt => Kind switch { - LLVMMetadataKind.LLVMDILocationMetadataKind => LLVM.DILocationGetInlinedAt(this), - _ => default, - }; - - public readonly bool IsDINode => Kind is >= LLVMMetadataKind.LLVMDILocationMetadataKind and <= LLVMMetadataKind.LLVMDIAssignIDMetadataKind; - - public readonly bool IsTemplateParameter => Kind switch { - LLVMMetadataKind.LLVMDITemplateTypeParameterMetadataKind => true, - LLVMMetadataKind.LLVMDITemplateValueParameterMetadataKind => true, - _ => false, - }; - - public readonly bool IsType => Kind switch { - LLVMMetadataKind.LLVMDICompositeTypeMetadataKind => true, - LLVMMetadataKind.LLVMDIDerivedTypeMetadataKind => true, - LLVMMetadataKind.LLVMDIStringTypeMetadataKind => true, - LLVMMetadataKind.LLVMDIBasicTypeMetadataKind => true, - LLVMMetadataKind.LLVMDISubroutineTypeMetadataKind => true, - _ => false, - }; - - public readonly bool IsVariable => Kind switch { - LLVMMetadataKind.LLVMDILocalVariableMetadataKind => true, - LLVMMetadataKind.LLVMDIGlobalVariableMetadataKind => true, - _ => false, - }; - - public readonly LLVMMetadataKind Kind => Handle == default - ? (LLVMMetadataKind)(-1) // 0 is a valid kind, so we use -1 to indicate a null metadata reference - : (LLVMMetadataKind)LLVM.GetMetadataKind(this); - - public readonly uint Line => Kind switch { - LLVMMetadataKind.LLVMDISubprogramMetadataKind => LLVM.DISubprogramGetLine(this), - LLVMMetadataKind.LLVMDILocationMetadataKind => LLVM.DILocationGetLine(this), - _ when IsType => LLVM.DITypeGetLine(this), - _ when IsVariable => LLVM.DIVariableGetLine(this), - _ => default, - }; + public readonly uint AlignInBits => (IsADIType != null) ? LLVM.DITypeGetAlignInBits(this) : default; + + public readonly uint AlignInBytes => AlignInBits / 8; + + public readonly LLVMMetadataRef BaseType + { + get + { + if (IsADIDerivedType != null) + { + return llvmsharp.DIDerivedType_getBaseType(this); + } + if (IsADICompositeType != null) + { + return llvmsharp.DICompositeType_getBaseType(this); + } + return default; + } + } + + public readonly uint Column => (IsADILocation != null) ? LLVM.DILocationGetColumn(this) : default; + + public readonly LLVMMetadataRef ContainingType => (IsADISubprogram != null) ? llvmsharp.DISubprogram_getContainingType(this) : default; + + public readonly LLVMValueRef Count => (IsADISubrange != null) ? llvmsharp.DISubrange_getCount(this) : default; + + public readonly string Directory => (IsADIFile != null) ? LLVM.DIFileGetDirectory(this) : ""; + + public readonly uint Encoding => (IsADIBasicType != null) ? llvmsharp.DIBasicType_getEncoding(this) : default; + + public readonly LLVMMetadataRef Entity => (IsADIImportedEntity != null) ? llvmsharp.DIImportedEntity_getEntity(this) : default; + + public readonly LLVMMetadataRef Expression => (IsADIGlobalVariableExpression != null) ? LLVM.DIGlobalVariableExpressionGetExpression(this) : default; + + public readonly LLVMMetadataRef ExtraData => (IsADIDerivedType != null) ? llvmsharp.DIDerivedType_getExtraData(this) : default; + + public readonly LLVMMetadataRef File + { + get + { + if (IsADIScope != null) + { + return LLVM.DIScopeGetFile(this); + } + if (IsADIVariable != null) + { + return LLVM.DIVariableGetFile(this); + } + if (IsADIImportedEntity != null) + { + return llvmsharp.DIImportedEntity_getFile(this); + } + return default; + } + } + + public readonly string Filename => (IsADIFile != null) ? LLVM.DIFileGetFilename(this) : ""; + + public readonly LLVMDIFlags Flags + { + get + { + if (IsADIType != null) + { + return LLVM.DITypeGetFlags(this); + } + if (IsADISubprogram != null) + { + return (LLVMDIFlags)llvmsharp.DISubprogram_getFlags(this); + } + return default; + } + } + + public readonly string Identifier => (IsADICompositeType != null) ? llvmsharp.DICompositeType_getIdentifier(this) : ""; + + public readonly LLVMMetadataRef InlinedAt => (IsADILocation != null) ? LLVM.DILocationGetInlinedAt(this) : default; + + #region IsA* Properties + public readonly LLVMMetadataRef IsAConstantAsMetadata => llvmsharp.Metadata_IsAConstantAsMetadata(this); + + public readonly LLVMMetadataRef IsADIArgList => llvmsharp.Metadata_IsADIArgList(this); + + public readonly LLVMMetadataRef IsADIAssignID => llvmsharp.Metadata_IsADIAssignID(this); + + public readonly LLVMMetadataRef IsADIBasicType => llvmsharp.Metadata_IsADIBasicType(this); + + public readonly LLVMMetadataRef IsADICommonBlock => llvmsharp.Metadata_IsADICommonBlock(this); + + public readonly LLVMMetadataRef IsADICompileUnit => llvmsharp.Metadata_IsADICompileUnit(this); + + public readonly LLVMMetadataRef IsADICompositeType => llvmsharp.Metadata_IsADICompositeType(this); + + public readonly LLVMMetadataRef IsADIDerivedType => llvmsharp.Metadata_IsADIDerivedType(this); + + public readonly LLVMMetadataRef IsADIEnumerator => llvmsharp.Metadata_IsADIEnumerator(this); + + public readonly LLVMMetadataRef IsADIExpression => llvmsharp.Metadata_IsADIExpression(this); + + public readonly LLVMMetadataRef IsADIFile => llvmsharp.Metadata_IsADIFile(this); + + public readonly LLVMMetadataRef IsADIGenericSubrange => llvmsharp.Metadata_IsADIGenericSubrange(this); + + public readonly LLVMMetadataRef IsAGenericDINode => llvmsharp.Metadata_IsAGenericDINode(this); + + public readonly LLVMMetadataRef IsADIGlobalVariable => llvmsharp.Metadata_IsADIGlobalVariable(this); + + public readonly LLVMMetadataRef IsADIGlobalVariableExpression => llvmsharp.Metadata_IsADIGlobalVariableExpression(this); + + public readonly LLVMMetadataRef IsADIImportedEntity => llvmsharp.Metadata_IsADIImportedEntity(this); + + public readonly LLVMMetadataRef IsADILabel => llvmsharp.Metadata_IsADILabel(this); + + public readonly LLVMMetadataRef IsADILexicalBlock => llvmsharp.Metadata_IsADILexicalBlock(this); + + public readonly LLVMMetadataRef IsADILexicalBlockFile => llvmsharp.Metadata_IsADILexicalBlockFile(this); + + public readonly LLVMMetadataRef IsADILocation => llvmsharp.Metadata_IsADILocation(this); + + public readonly LLVMMetadataRef IsADILocalVariable => llvmsharp.Metadata_IsADILocalVariable(this); + + public readonly LLVMMetadataRef IsADIMacro => llvmsharp.Metadata_IsADIMacro(this); + + public readonly LLVMMetadataRef IsADIMacroFile => llvmsharp.Metadata_IsADIMacroFile(this); + + public readonly LLVMMetadataRef IsADIModule => llvmsharp.Metadata_IsADIModule(this); + + public readonly LLVMMetadataRef IsADINamespace => llvmsharp.Metadata_IsADINamespace(this); + + public readonly LLVMMetadataRef IsADINode => llvmsharp.Metadata_IsADINode(this); + + public readonly LLVMMetadataRef IsADIObjCProperty => llvmsharp.Metadata_IsADIObjCProperty(this); + + public readonly LLVMMetadataRef IsADistinctMDOperandPlaceholder => llvmsharp.Metadata_IsADistinctMDOperandPlaceholder(this); + + public readonly LLVMMetadataRef IsADIScope => llvmsharp.Metadata_IsADIScope(this); + + public readonly LLVMMetadataRef IsADIStringType => llvmsharp.Metadata_IsADIStringType(this); + + public readonly LLVMMetadataRef IsADISubprogram => llvmsharp.Metadata_IsADISubprogram(this); + + public readonly LLVMMetadataRef IsADISubrange => llvmsharp.Metadata_IsADISubrange(this); + + public readonly LLVMMetadataRef IsADISubroutineType => llvmsharp.Metadata_IsADISubroutineType(this); + + public readonly LLVMMetadataRef IsADITemplateParameter => llvmsharp.Metadata_IsADITemplateParameter(this); + + public readonly LLVMMetadataRef IsADITemplateTypeParameter => llvmsharp.Metadata_IsADITemplateTypeParameter(this); + + public readonly LLVMMetadataRef IsADITemplateValueParameter => llvmsharp.Metadata_IsADITemplateValueParameter(this); + + public readonly LLVMMetadataRef IsADIType => llvmsharp.Metadata_IsADIType(this); + + public readonly LLVMMetadataRef IsADIVariable => llvmsharp.Metadata_IsADIVariable(this); + + public readonly LLVMMetadataRef IsALocalAsMetadata => llvmsharp.Metadata_IsALocalAsMetadata(this); + + public readonly LLVMMetadataRef IsAMDNode => llvmsharp.Metadata_IsAMDNode(this); + + public readonly LLVMMetadataRef IsAMDString => llvmsharp.Metadata_IsAMDString(this); + + public readonly LLVMMetadataRef IsAMDTuple => llvmsharp.Metadata_IsAMDTuple(this); + #endregion + + public readonly bool IsUnsigned => (IsADIEnumerator != null) && (llvmsharp.DIEnumerator_isUnsigned(this) != 0); + + public readonly LLVMMetadataKind Kind => (Handle != default) ? (LLVMMetadataKind)LLVM.GetMetadataKind(this) : default; + + public readonly uint Line + { + get + { + if (IsADISubprogram != null) + { + return LLVM.DISubprogramGetLine(this); + } + if (IsADILocation != null) + { + return LLVM.DILocationGetLine(this); + } + if (IsADIType != null) + { + return LLVM.DITypeGetLine(this); + } + if (IsADIVariable != null) + { + return LLVM.DIVariableGetLine(this); + } + if (IsADIImportedEntity != null) + { + return llvmsharp.DIImportedEntity_getLine(this); + } + if (IsADILexicalBlock != null) + { + return llvmsharp.DILexicalBlock_getLine(this); + } + return default; + } + } + + public readonly string LinkageName => (IsADISubprogram != null) ? llvmsharp.DISubprogram_getLinkageName(this) : ""; public readonly string Name { get { - if (!IsType) + if (IsADIType != null) + { + return LLVM.DITypeGetName(this); + } + if (IsADISubprogram != null) + { + return llvmsharp.DISubprogram_getName(this); + } + if (IsADIVariable != null) + { + return llvmsharp.DIVariable_getName(this); + } + if (IsADINamespace != null) + { + return llvmsharp.DINamespace_getName(this); + } + if (IsADIEnumerator != null) { - return ""; + return llvmsharp.DIEnumerator_getName(this); } + return ""; + } + } + + public readonly uint NumOperands => (IsAMDNode != null) ? llvmsharp.MDNode_getNumOperands(this) : 0; + + public readonly ulong OffsetInBits => (IsADIType != null) ? LLVM.DITypeGetOffsetInBits(this) : default; + + public readonly ulong OffsetInBytes => OffsetInBits / 8; - nuint nameLength = 0; - sbyte* namePtr = LLVM.DITypeGetName(this, &nameLength); - if (namePtr == null) + public readonly LLVMMetadataRef Scope + { + get + { + if (IsADILocation != null) + { + return LLVM.DILocationGetScope(this); + } + if (IsADIVariable != null) { - return ""; + return LLVM.DIVariableGetScope(this); } + if (IsADILexicalBlock != null) + { + return llvmsharp.DILexicalBlock_getScope(this); + } + if (IsADIImportedEntity != null) + { + return llvmsharp.DIImportedEntity_getScope(this); + } + if (IsADINamespace != null) + { + return llvmsharp.DINamespace_getScope(this); + } + return default; + } + } + + public readonly uint ScopeLine => (IsADISubprogram != null) ? llvmsharp.DISubprogram_getScopeLine(this) : default; + + public readonly ulong SizeInBits => (IsADIType != null) ? LLVM.DITypeGetSizeInBits(this) : default; + + public readonly ulong SizeInBytes => SizeInBits / 8; - return new ReadOnlySpan(namePtr, (int)nameLength).AsString(); + public readonly uint SPFlags => (IsADISubprogram != null) ? llvmsharp.DISubprogram_getSPFlags(this) : default; + + public readonly string String => (IsAMDString != null) ? llvmsharp.MDString_getString(this) : ""; + + public readonly ushort Tag => (IsADINode != null) ? LLVM.GetDINodeTag(this) : default; + + public readonly string TagString => (IsADINode != null) ? llvmsharp.DINode_getTagString(this) : ""; + + public readonly LLVMMetadataRef Type + { + get + { + if (IsADIVariable != null) + { + return llvmsharp.DIVariable_getType(this); + } + if (IsADISubprogram != null) + { + return llvmsharp.DISubprogram_getType(this); + } + if (IsADITemplateParameter != null) + { + return llvmsharp.DITemplateParameter_getType(this); + } + return default; } } - public readonly ulong OffsetInBits => IsType ? LLVM.DITypeGetOffsetInBits(this) : default; + public readonly LLVMMetadataRef Value => (IsADITemplateValueParameter != null) ? llvmsharp.DITemplateValueParameter_getValue(this) : default; - public readonly LLVMMetadataRef Scope => Kind switch { - LLVMMetadataKind.LLVMDILocationMetadataKind => LLVM.DILocationGetScope(this), - _ when IsVariable => LLVM.DIVariableGetScope(this), - _ => default, - }; + public readonly long ValueSExt => (IsADIEnumerator != null) ? llvmsharp.DIEnumerator_getValue_SExt(this) : default; - public readonly ulong SizeInBits => IsType ? LLVM.DITypeGetSizeInBits(this) : default; + public readonly ulong ValueZExt => (IsADIEnumerator != null) ? llvmsharp.DIEnumerator_getValue_ZExt(this) : default; - public readonly ushort Tag => IsDINode ? LLVM.GetDINodeTag(this) : default; + public readonly uint VirtualIndex => (IsADISubprogram != null) ? llvmsharp.DISubprogram_getVirtualIndex(this) : default; - public readonly LLVMMetadataRef Variable => Kind switch { - LLVMMetadataKind.LLVMDIGlobalVariableExpressionMetadataKind => LLVM.DIGlobalVariableExpressionGetVariable(this), - _ => default, - }; + public readonly LLVMMetadataRef Variable => (IsADIGlobalVariableExpression != null) ? LLVM.DIGlobalVariableExpressionGetVariable(this) : default; public static implicit operator LLVMMetadataRef(LLVMOpaqueMetadata* value) => new LLVMMetadataRef((IntPtr)value); @@ -120,12 +330,42 @@ public readonly string Name public readonly bool Equals(LLVMMetadataRef other) => this == other; + public readonly LLVMMetadataRef[] GetElements() + { + return (IsADICompositeType != null) ? llvmsharp.DICompositeType_getElements(this) : []; + } + public override readonly int GetHashCode() => Handle.GetHashCode(); - public readonly string GetMDString(LLVMContextRef context, out uint length) + public readonly LLVMMetadataRef GetOperand(uint index) + { + return llvmsharp.MDNode_getOperand(this, index); + } + + public readonly LLVMMetadataRef[] GetOperands() + { + uint numOperands = NumOperands; + if (numOperands == 0) + { + return []; + } + + var operands = new LLVMMetadataRef[numOperands]; + for (uint i = 0; i < numOperands; i++) + { + operands[i] = GetOperand(i); + } + return operands; + } + + public readonly LLVMMetadataRef[] GetTemplateParams() + { + return (IsADISubprogram != null) ? llvmsharp.DISubprogram_getTemplateParams(this) : []; + } + + public readonly LLVMMetadataRef[] GetTypeArray() { - var value = context.MetadataAsValue(this); - return value.GetMDString(out length); + return (IsADISubroutineType != null) ? llvmsharp.DISubroutineType_getTypeArray(this) : []; } public override readonly string ToString() => $"{nameof(LLVMMetadataRef)}: {Handle:X}"; diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs index 27b6890..a820e00 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs @@ -262,6 +262,8 @@ public void Dispose() public readonly bool Equals(LLVMModuleRef other) => this == other; + public readonly LLVMTypeRef[] GetIdentifiedStructTypes() => llvmsharp.Module_GetIdentifiedStructTypes(this); + public readonly LLVMValueRef GetNamedFunction(string Name) => GetNamedFunction(Name.AsSpan()); public readonly LLVMValueRef GetNamedFunction(ReadOnlySpan Name) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMPassManagerRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMPassManagerRef.cs index 3ea5055..276a0b9 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMPassManagerRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMPassManagerRef.cs @@ -16,6 +16,8 @@ public unsafe partial struct LLVMPassManagerRef(IntPtr handle) : IDisposable, IE public static bool operator !=(LLVMPassManagerRef left, LLVMPassManagerRef right) => !(left == right); + public readonly void Add(LLVMPassRef passRef) => llvmsharp.PassManager_add(this, passRef); + public static LLVMPassManagerRef Create() => LLVM.CreatePassManager(); public void Dispose() diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMPassRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMPassRef.cs new file mode 100644 index 0000000..5a26af0 --- /dev/null +++ b/sources/LLVMSharp.Interop/Extensions/LLVMPassRef.cs @@ -0,0 +1,26 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; + +namespace LLVMSharp.Interop; + +public unsafe partial struct LLVMPassRef(IntPtr handle) : IEquatable +{ + public IntPtr Handle = handle; + + public static implicit operator LLVMPassRef(LLVMOpaquePass* value) => new LLVMPassRef((IntPtr)value); + + public static implicit operator LLVMOpaquePass*(LLVMPassRef value) => (LLVMOpaquePass*)value.Handle; + + public static bool operator ==(LLVMPassRef left, LLVMPassRef right) => left.Handle == right.Handle; + + public static bool operator !=(LLVMPassRef left, LLVMPassRef right) => !(left == right); + + public override readonly bool Equals(object? obj) => (obj is LLVMPassRef other) && Equals(other); + + public readonly bool Equals(LLVMPassRef other) => this == other; + + public override readonly int GetHashCode() => Handle.GetHashCode(); + + public override readonly string ToString() => $"{nameof(LLVMPassRef)}: {Handle:X}"; +} diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index 87db789..255a902 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -63,6 +63,28 @@ public readonly LLVMValueRef Condition public readonly LLVMContextRef Context => (Handle != IntPtr.Zero) ? LLVM.GetValueContext(this) : default; + public readonly ReadOnlySpan Data => (IsAConstantDataArray != null) ? llvmsharp.ConstantDataArray_getData(this) : default; + + public readonly string? DemangledName + { + get + { + if (Handle == IntPtr.Zero) + { + return null; + } + + nuint length = 0; + sbyte* ptr = LLVM.GetValueName2(this, &length); + if (ptr is null || length == 0) + { + return ""; + } + + return llvmsharp.Demangle(new ReadOnlySpan(ptr, (int)length)); + } + } + public readonly LLVMDLLStorageClass DLLStorageClass { get @@ -99,6 +121,8 @@ public readonly uint FunctionCallConv } } + public readonly LLVMTypeRef FunctionType => (IsAFunction != null) ? llvmsharp.Function_getFunctionType(this) : default; + public readonly string GC { get @@ -127,8 +151,14 @@ public readonly string GC public readonly LLVMModuleRef GlobalParent => (IsAGlobalValue != null) ? LLVM.GetGlobalParent(this) : default; + public readonly LLVMMetadataRef GlobalVariableExpression => (IsAGlobalVariable != null) ? llvmsharp.GlobalVariable_getGlobalVariableExpression(this) : default; + public readonly bool HasMetadata => (IsAInstruction != null) && LLVM.HasMetadata(this) != 0; + public readonly bool HasNoSignedWrap => (IsAInstruction != null) && llvmsharp.Instruction_hasNoSignedWrap(this) != 0; + + public readonly bool HasNoUnsignedWrap => (IsAInstruction != null) && llvmsharp.Instruction_hasNoUnsignedWrap(this) != 0; + public readonly bool HasPersonalityFn => (IsAFunction != null) && LLVM.HasPersonalityFn(this) != 0; public readonly bool HasUnnamedAddr @@ -540,6 +570,8 @@ public readonly LLVMValueRef PersonalityFn public readonly LLVMValueRef PreviousFunction => (IsAFunction != null) ? LLVM.GetPreviousFunction(this) : default; + public readonly LLVMTypeRef ReturnType => (IsAFunction != null) ? llvmsharp.Function_getReturnType(this) : default; + public readonly string Section { get diff --git a/sources/LLVMSharp.Interop/Extensions/llvmsharp.Manual.cs b/sources/LLVMSharp.Interop/Extensions/llvmsharp.Manual.cs new file mode 100644 index 0000000..e18cd26 --- /dev/null +++ b/sources/LLVMSharp.Interop/Extensions/llvmsharp.Manual.cs @@ -0,0 +1,176 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Diagnostics; +using System.Text; + +namespace LLVMSharp.Interop; + +public static unsafe partial class llvmsharp +{ + public static ReadOnlySpan ConstantDataArray_getData(LLVMValueRef array) + { + int length = 0; + byte* buffer = (byte*)ConstantDataArray_getData(array, &length); + return new ReadOnlySpan(buffer, (int)length); + } + + public static LLVMMetadataRef[] DICompositeType_getElements(LLVMMetadataRef type) + { + LLVMMetadataRef* buffer = null; + int size = 0; + DICompositeType_getElements(type, (LLVMOpaqueMetadata***)&buffer, &size); + var result = new ReadOnlySpan(buffer, size).ToArray(); + Free(buffer); + return result; + } + + public static string DICompositeType_getIdentifier(LLVMMetadataRef type) + { + int length = 0; + sbyte* identifier = DICompositeType_getIdentifier(type, &length); + if (identifier == null) + { + return ""; + } + return new ReadOnlySpan(identifier, length).AsString(); + } + + public static string DIEnumerator_getName(LLVMMetadataRef enumerator) + { + int length = 0; + sbyte* name = DIEnumerator_getName(enumerator, &length); + if (name == null) + { + return ""; + } + return new ReadOnlySpan(name, length).AsString(); + } + + public static string DINamespace_getName(LLVMMetadataRef node) + { + int length = 0; + sbyte* name = DINamespace_getName(node, &length); + if (name == null) + { + return ""; + } + return new ReadOnlySpan(name, length).AsString(); + } + + public static string DINode_getTagString(LLVMMetadataRef node) + { + int length = 0; + sbyte* tagString = DINode_getTagString(node, &length); + if (tagString == null) + { + return ""; + } + return new ReadOnlySpan(tagString, length).AsString(); + } + + public static string DISubprogram_getLinkageName(LLVMMetadataRef subprogram) + { + int length = 0; + sbyte* name = DISubprogram_getLinkageName(subprogram, &length); + if (name == null) + { + return ""; + } + return new ReadOnlySpan(name, length).AsString(); + } + + public static string DISubprogram_getName(LLVMMetadataRef subprogram) + { + int length = 0; + sbyte* name = DISubprogram_getName(subprogram, &length); + if (name == null) + { + return ""; + } + return new ReadOnlySpan(name, length).AsString(); + } + + public static LLVMMetadataRef[] DISubprogram_getTemplateParams(LLVMMetadataRef type) + { + LLVMMetadataRef* buffer = null; + int size = 0; + DISubprogram_getTemplateParams(type, (LLVMOpaqueMetadata***)&buffer, &size); + var result = new ReadOnlySpan(buffer, size).ToArray(); + Free(buffer); + return result; + } + + public static LLVMMetadataRef[] DISubroutineType_getTypeArray(LLVMMetadataRef type) + { + LLVMMetadataRef* buffer = null; + int size = 0; + DISubroutineType_getTypeArray(type, (LLVMOpaqueMetadata***)&buffer, &size); + var result = new ReadOnlySpan(buffer, size).ToArray(); + Free(buffer); + return result; + } + + public static string DIVariable_getName(LLVMMetadataRef variable) + { + int length = 0; + sbyte* name = DIVariable_getName(variable, &length); + if (name == null) + { + return ""; + } + return new ReadOnlySpan(name, length).AsString(); + } + + public static string MDString_getString(LLVMMetadataRef mdstring) + { + int length = 0; + sbyte* stringPtr = MDString_getString(mdstring, &length); + if (stringPtr == null) + { + return ""; + } + return new ReadOnlySpan(stringPtr, length).AsString(); + } + + public static LLVMTypeRef[] Module_GetIdentifiedStructTypes(LLVMModuleRef module) + { + LLVMOpaqueType** buffer; + int size; + Module_GetIdentifiedStructTypes(module, &buffer, &size); + var result = new ReadOnlySpan(buffer, size).ToArray(); + Free(buffer); + return result; + } + + public static int Demangle(ReadOnlySpan mangled_string, Span buffer) + { + fixed (byte* mangledPtr = mangled_string) + fixed (byte* bufferPtr = buffer) + { + return Demangle((sbyte*)mangledPtr, mangled_string.Length, (sbyte*)bufferPtr, buffer.Length); + } + } + + public static string Demangle(ReadOnlySpan mangledString) + { + const int MaxLength = 4096; + Span buffer = stackalloc byte[MaxLength]; + int length = Demangle(mangledString, buffer); + if (length > MaxLength) + { + buffer = new byte[length]; + length = Demangle(mangledString, buffer); + } + return Encoding.UTF8.GetString(buffer[..length]); + } + + public static string Demangle(string mangledString) + { + int byteCount = Encoding.UTF8.GetByteCount(mangledString); + Span mangledBytes = byteCount <= 4096 ? stackalloc byte[byteCount] : new byte[byteCount]; + int bytesWritten = Encoding.UTF8.GetBytes(mangledString, mangledBytes); + Debug.Assert(bytesWritten == byteCount); + return Demangle(mangledBytes); + } +} diff --git a/sources/LLVMSharp.Interop/LLVMSharp.Interop.csproj b/sources/LLVMSharp.Interop/LLVMSharp.Interop.csproj index d5cf7b9..eda23ac 100644 --- a/sources/LLVMSharp.Interop/LLVMSharp.Interop.csproj +++ b/sources/LLVMSharp.Interop/LLVMSharp.Interop.csproj @@ -29,7 +29,8 @@ - $(NoWarn);CA1003;CA1008;CA1027;CA1031;CA1034;CA1041;CA1051;CA1069;CA1305;CA1508;CA1700;CA1707;CA1708;CA1710;CA1711;CA1712;CA1715;CA1720;CA1721;CA1724;CA1815;CA2201;CA2225 + + $(NoWarn);CA1003;CA1008;CA1027;CA1031;CA1034;CA1041;CA1051;CA1069;CA1305;CA1508;CA1700;CA1707;CA1708;CA1710;CA1711;CA1712;CA1715;CA1720;CA1721;CA1724;CA1815;CA2201;CA2225;8981 diff --git a/sources/LLVMSharp.Interop/Manual/LLVMOpaquePass.cs b/sources/LLVMSharp.Interop/Manual/LLVMOpaquePass.cs new file mode 100644 index 0000000..29ce5b6 --- /dev/null +++ b/sources/LLVMSharp.Interop/Manual/LLVMOpaquePass.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from https://github.com/llvm/llvm-project/tree/llvmorg-20.1.2/llvm/include/llvm-c +// Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. + +namespace LLVMSharp.Interop; + +public partial struct LLVMOpaquePass +{ +} diff --git a/sources/LLVMSharp.Interop/llvmsharp/llvmsharp.cs b/sources/LLVMSharp.Interop/llvmsharp/llvmsharp.cs new file mode 100644 index 0000000..b713c47 --- /dev/null +++ b/sources/LLVMSharp.Interop/llvmsharp/llvmsharp.cs @@ -0,0 +1,427 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. +// Ported from https://github.com/dotnet/llvmsharp/blob/main/sources/libLLVMSharp + +using System.Runtime.InteropServices; + +namespace LLVMSharp.Interop; + +public static unsafe partial class llvmsharp +{ + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_ConstantDataArray_getData", ExactSpelling = true)] + [return: NativeTypeName("const char *")] + public static extern sbyte* ConstantDataArray_getData([NativeTypeName("LLVMValueRef")] LLVMOpaqueValue* array, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIBasicType_getEncoding", ExactSpelling = true)] + [return: NativeTypeName("uint32_t")] + public static extern uint DIBasicType_getEncoding([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* type); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DICompositeType_getBaseType", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DICompositeType_getBaseType([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* type); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DICompositeType_getElements", ExactSpelling = true)] + public static extern void DICompositeType_getElements([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* type, [NativeTypeName("LLVMMetadataRef **")] LLVMOpaqueMetadata*** out_buffer, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DICompositeType_getIdentifier", ExactSpelling = true)] + [return: NativeTypeName("const char *")] + public static extern sbyte* DICompositeType_getIdentifier([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* type, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIDerivedType_getBaseType", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DIDerivedType_getBaseType([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* type); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIDerivedType_getExtraData", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DIDerivedType_getExtraData([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* type); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIEnumerator_getName", ExactSpelling = true)] + [return: NativeTypeName("const char *")] + public static extern sbyte* DIEnumerator_getName([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* enumerator, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIEnumerator_getValue_SExt", ExactSpelling = true)] + [return: NativeTypeName("int64_t")] + public static extern long DIEnumerator_getValue_SExt([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* enumerator); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIEnumerator_getValue_ZExt", ExactSpelling = true)] + [return: NativeTypeName("uint64_t")] + public static extern ulong DIEnumerator_getValue_ZExt([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* enumerator); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIEnumerator_isUnsigned", ExactSpelling = true)] + [return: NativeTypeName("uint8_t")] + public static extern byte DIEnumerator_isUnsigned([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* enumerator); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIImportedEntity_getEntity", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DIImportedEntity_getEntity([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* node); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIImportedEntity_getFile", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DIImportedEntity_getFile([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* node); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIImportedEntity_getLine", ExactSpelling = true)] + [return: NativeTypeName("uint32_t")] + public static extern uint DIImportedEntity_getLine([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* node); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIImportedEntity_getScope", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DIImportedEntity_getScope([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* node); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DILexicalBlock_getLine", ExactSpelling = true)] + [return: NativeTypeName("uint32_t")] + public static extern uint DILexicalBlock_getLine([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* block); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DILexicalBlock_getScope", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DILexicalBlock_getScope([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* block); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DINamespace_getName", ExactSpelling = true)] + [return: NativeTypeName("const char *")] + public static extern sbyte* DINamespace_getName([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* node, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DINamespace_getScope", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DINamespace_getScope([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* node); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DINode_getTagString", ExactSpelling = true)] + [return: NativeTypeName("const char *")] + public static extern sbyte* DINode_getTagString([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* node, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DISubprogram_getContainingType", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DISubprogram_getContainingType([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* subprogram); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DISubprogram_getFlags", ExactSpelling = true)] + [return: NativeTypeName("uint32_t")] + public static extern uint DISubprogram_getFlags([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* subprogram); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DISubprogram_getLinkageName", ExactSpelling = true)] + [return: NativeTypeName("const char *")] + public static extern sbyte* DISubprogram_getLinkageName([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* subprogram, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DISubprogram_getName", ExactSpelling = true)] + [return: NativeTypeName("const char *")] + public static extern sbyte* DISubprogram_getName([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* subprogram, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DISubprogram_getScopeLine", ExactSpelling = true)] + [return: NativeTypeName("uint32_t")] + public static extern uint DISubprogram_getScopeLine([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* subprogram); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DISubprogram_getSPFlags", ExactSpelling = true)] + [return: NativeTypeName("uint32_t")] + public static extern uint DISubprogram_getSPFlags([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* subprogram); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DISubprogram_getTemplateParams", ExactSpelling = true)] + public static extern void DISubprogram_getTemplateParams([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* subprogram, [NativeTypeName("LLVMMetadataRef **")] LLVMOpaqueMetadata*** out_buffer, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DISubprogram_getType", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DISubprogram_getType([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* subprogram); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DISubprogram_getVirtualIndex", ExactSpelling = true)] + [return: NativeTypeName("uint32_t")] + public static extern uint DISubprogram_getVirtualIndex([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* subprogram); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DISubrange_getCount", ExactSpelling = true)] + [return: NativeTypeName("LLVMValueRef")] + public static extern LLVMOpaqueValue* DISubrange_getCount([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* subrange); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DISubroutineType_getTypeArray", ExactSpelling = true)] + public static extern void DISubroutineType_getTypeArray([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* subroutine_type, [NativeTypeName("LLVMMetadataRef **")] LLVMOpaqueMetadata*** out_buffer, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DITemplateParameter_getType", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DITemplateParameter_getType([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* parameter); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DITemplateValueParameter_getValue", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DITemplateValueParameter_getValue([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* parameter); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIVariable_getName", ExactSpelling = true)] + [return: NativeTypeName("const char *")] + public static extern sbyte* DIVariable_getName([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* variable, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_DIVariable_getType", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* DIVariable_getType([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* variable); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Function_getFunctionType", ExactSpelling = true)] + [return: NativeTypeName("LLVMTypeRef")] + public static extern LLVMOpaqueType* Function_getFunctionType([NativeTypeName("LLVMValueRef")] LLVMOpaqueValue* function); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Function_getReturnType", ExactSpelling = true)] + [return: NativeTypeName("LLVMTypeRef")] + public static extern LLVMOpaqueType* Function_getReturnType([NativeTypeName("LLVMValueRef")] LLVMOpaqueValue* function); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_GlobalVariable_getGlobalVariableExpression", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* GlobalVariable_getGlobalVariableExpression([NativeTypeName("LLVMValueRef")] LLVMOpaqueValue* global_variable); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_GlobalVariable_getMetadata", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* GlobalVariable_getMetadata([NativeTypeName("LLVMValueRef")] LLVMOpaqueValue* global_variable, [NativeTypeName("uint32_t")] uint KindID); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Instruction_hasNoSignedWrap", ExactSpelling = true)] + [return: NativeTypeName("uint8_t")] + public static extern byte Instruction_hasNoSignedWrap([NativeTypeName("LLVMValueRef")] LLVMOpaqueValue* instruction); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Instruction_hasNoUnsignedWrap", ExactSpelling = true)] + [return: NativeTypeName("uint8_t")] + public static extern byte Instruction_hasNoUnsignedWrap([NativeTypeName("LLVMValueRef")] LLVMOpaqueValue* instruction); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_MDNode_getNumOperands", ExactSpelling = true)] + [return: NativeTypeName("uint32_t")] + public static extern uint MDNode_getNumOperands([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_MDNode_getOperand", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* MDNode_getOperand([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata, [NativeTypeName("uint32_t")] uint index); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_MDString_getString", ExactSpelling = true)] + [return: NativeTypeName("const char *")] + public static extern sbyte* MDString_getString([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* mdstring, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsAMDNode", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsAMDNode([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADINode", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADINode([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIScope", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIScope([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADITemplateParameter", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADITemplateParameter([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIType", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIType([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIVariable", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIVariable([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsAMDString", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsAMDString([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsAConstantAsMetadata", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsAConstantAsMetadata([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsALocalAsMetadata", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsALocalAsMetadata([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADistinctMDOperandPlaceholder", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADistinctMDOperandPlaceholder([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsAMDTuple", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsAMDTuple([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADILocation", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADILocation([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIExpression", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIExpression([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIGlobalVariableExpression", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIGlobalVariableExpression([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsAGenericDINode", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsAGenericDINode([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADISubrange", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADISubrange([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIEnumerator", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIEnumerator([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIBasicType", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIBasicType([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIDerivedType", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIDerivedType([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADICompositeType", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADICompositeType([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADISubroutineType", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADISubroutineType([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIFile", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIFile([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADICompileUnit", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADICompileUnit([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADISubprogram", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADISubprogram([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADILexicalBlock", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADILexicalBlock([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADILexicalBlockFile", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADILexicalBlockFile([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADINamespace", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADINamespace([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIModule", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIModule([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADITemplateTypeParameter", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADITemplateTypeParameter([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADITemplateValueParameter", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADITemplateValueParameter([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIGlobalVariable", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIGlobalVariable([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADILocalVariable", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADILocalVariable([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADILabel", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADILabel([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIObjCProperty", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIObjCProperty([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIImportedEntity", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIImportedEntity([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIMacro", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIMacro([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIMacroFile", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIMacroFile([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADICommonBlock", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADICommonBlock([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIStringType", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIStringType([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIGenericSubrange", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIGenericSubrange([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIArgList", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIArgList([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Metadata_IsADIAssignID", ExactSpelling = true)] + [return: NativeTypeName("LLVMMetadataRef")] + public static extern LLVMOpaqueMetadata* Metadata_IsADIAssignID([NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* metadata); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Module_GetIdentifiedStructTypes", ExactSpelling = true)] + public static extern void Module_GetIdentifiedStructTypes([NativeTypeName("LLVMModuleRef")] LLVMOpaqueModule* module, [NativeTypeName("LLVMTypeRef **")] LLVMOpaqueType*** out_buffer, [NativeTypeName("int32_t *")] int* out_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_PassManager_add", ExactSpelling = true)] + public static extern void PassManager_add([NativeTypeName("LLVMPassManagerRef")] LLVMOpaquePassManager* pass_manager, [NativeTypeName("LLVMPassRef")] LLVMOpaquePass* pass); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createDeadCodeEliminationPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createDeadCodeEliminationPass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createSROAPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createSROAPass([NativeTypeName("uint8_t")] byte PreserveCFG); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createLICMPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createLICMPass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createLoopStrengthReducePass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createLoopStrengthReducePass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createReassociatePass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createReassociatePass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createFlattenCFGPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createFlattenCFGPass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createCFGSimplificationPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createCFGSimplificationPass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createTailCallEliminationPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createTailCallEliminationPass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createConstantHoistingPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createConstantHoistingPass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createLowerInvokePass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createLowerInvokePass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createLowerSwitchPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createLowerSwitchPass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createBreakCriticalEdgesPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createBreakCriticalEdgesPass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createLCSSAPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createLCSSAPass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createPromoteMemoryToRegisterPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createPromoteMemoryToRegisterPass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createLoopSimplifyPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createLoopSimplifyPass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_createUnifyLoopExitsPass", ExactSpelling = true)] + [return: NativeTypeName("LLVMPassRef")] + public static extern LLVMOpaquePass* createUnifyLoopExitsPass(); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Demangle", ExactSpelling = true)] + [return: NativeTypeName("int32_t")] + public static extern int Demangle([NativeTypeName("const char *")] sbyte* mangled_string, [NativeTypeName("int32_t")] int mangled_string_size, [NativeTypeName("char *")] sbyte* buffer, [NativeTypeName("int32_t")] int buffer_size); + + [DllImport("libLLVMSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "llvmsharp_Free", ExactSpelling = true)] + public static extern void Free(void* obj); +} diff --git a/sources/libLLVMSharp/CMakeLists.txt b/sources/libLLVMSharp/CMakeLists.txt new file mode 100644 index 0000000..e171ffa --- /dev/null +++ b/sources/libLLVMSharp/CMakeLists.txt @@ -0,0 +1,66 @@ +include(GenerateExportHeader) + +set(CMAKE_CXX_VISIBILITY_PRESET "hidden") +set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + LLVMSharp.cpp + + LLVMSharp.h +) + +set(LLVM_SEARCH_PATHS + ${PATH_TO_LLVM} + ${PATH_TO_LLVM}/lib/cmake + ${PATH_TO_LLVM}/lib/cmake/llvm + ${PATH_TO_LLVM}/lib/cmake/clang + ${PATH_TO_LLVM}/share/clang/cmake/ + ${PATH_TO_LLVM}/share/llvm/cmake/ +) + +find_package(Clang REQUIRED CONFIG + PATHS ${LLVM_SEARCH_PATHS} + NO_DEFAULT_PATH) + +add_library(LLVMSharp SHARED ${SOURCES}) + +target_link_libraries(LLVMSharp PRIVATE LLVM-C) + +target_link_libraries(LLVMSharp PRIVATE LLVMDemangle) + +target_link_libraries(LLVMSharp PRIVATE LLVMAggressiveInstCombine) +target_link_libraries(LLVMSharp PRIVATE LLVMCFGuard) +target_link_libraries(LLVMSharp PRIVATE LLVMInstCombine) +target_link_libraries(LLVMSharp PRIVATE LLVMInstrumentation) +target_link_libraries(LLVMSharp PRIVATE LLVMipo) +target_link_libraries(LLVMSharp PRIVATE LLVMObjCARCOpts) +target_link_libraries(LLVMSharp PRIVATE LLVMScalarOpts) +target_link_libraries(LLVMSharp PRIVATE LLVMTransformUtils) +target_link_libraries(LLVMSharp PRIVATE LLVMVectorize) + +target_include_directories(LLVMSharp PRIVATE ${LLVM_INCLUDE_DIRS}) + +set_target_properties(LLVMSharp PROPERTIES + PREFIX lib + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION} +) + +generate_export_header(LLVMSharp + EXPORT_MACRO_NAME "LLVMSHARP_LINKAGE" + EXPORT_FILE_NAME LLVMSharp_export.h +) + +set_property(TARGET LLVMSharp APPEND PROPERTY + PUBLIC_HEADER LLVMSharp.h "${CMAKE_CURRENT_BINARY_DIR}/LLVMSharp_export.h" +) + +include(GNUInstallDirs) + +install(TARGETS LLVMSharp + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT development + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT development +) diff --git a/sources/libLLVMSharp/LLVMSharp.cpp b/sources/libLLVMSharp/LLVMSharp.cpp new file mode 100644 index 0000000..5e6c450 --- /dev/null +++ b/sources/libLLVMSharp/LLVMSharp.cpp @@ -0,0 +1,524 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +#include "LLVMSharp.h" +// Other project includes + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) +#endif + +// Library includes (<> instead of "") +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +// Namespace usings +using namespace llvm; + +// Create wrappers for C Binding types (see CBindingWrapping.h). +DEFINE_ISA_CONVERSION_FUNCTIONS(Pass, LLVMPassRef) + +// Implementation code + +const char* llvmsharp_ConstantDataArray_getData(LLVMValueRef array, int32_t* out_size) +{ + ConstantDataArray* unwrapped = unwrap(array); + StringRef stringRef = unwrapped->getRawDataValues(); + *out_size = (int32_t)stringRef.size(); + return stringRef.data(); +} + +uint32_t llvmsharp_DIBasicType_getEncoding(LLVMMetadataRef type) +{ + DIBasicType* unwrapped = unwrap(type); + return unwrapped->getEncoding(); +} + +LLVMMetadataRef llvmsharp_DICompositeType_getBaseType(LLVMMetadataRef type) +{ + DICompositeType* unwrapped = unwrap(type); + return wrap(unwrapped->getBaseType()); +} + +void llvmsharp_DICompositeType_getElements(LLVMMetadataRef type, LLVMMetadataRef** out_buffer, int32_t* out_size) +{ + DICompositeType* unwrapped = unwrap(type); + DINodeArray array = unwrapped->getElements(); + int32_t size = array.size(); + + LLVMMetadataRef* buffer = (LLVMMetadataRef*)malloc(size * sizeof(LLVMMetadataRef)); + if (buffer == nullptr) + { + *out_buffer = nullptr; + *out_size = 0; + return; // Memory allocation failed + } + + for (int32_t i = 0; i < size; ++i) + { + buffer[i] = wrap(array[i]); + } + + *out_buffer = buffer; + *out_size = size; +} + +const char* llvmsharp_DICompositeType_getIdentifier(LLVMMetadataRef type, int32_t* out_size) +{ + DICompositeType* unwrapped = unwrap(type); + StringRef identifier = unwrapped->getIdentifier(); + *out_size = (int32_t)identifier.size(); + return identifier.data(); +} + +LLVMMetadataRef llvmsharp_DIDerivedType_getBaseType(LLVMMetadataRef type) +{ + DIDerivedType* unwrapped = unwrap(type); + return wrap(unwrapped->getBaseType()); +} + +LLVMMetadataRef llvmsharp_DIDerivedType_getExtraData(LLVMMetadataRef type) +{ + DIDerivedType* unwrapped = unwrap(type); + return wrap(unwrapped->getExtraData()); +} + +const char* llvmsharp_DIEnumerator_getName(LLVMMetadataRef enumerator, int32_t* out_size) +{ + DIEnumerator* unwrapped = unwrap(enumerator); + StringRef name = unwrapped->getName(); + *out_size = (int32_t)name.size(); + return name.data(); +} + +int64_t llvmsharp_DIEnumerator_getValue_SExt(LLVMMetadataRef enumerator) +{ + DIEnumerator* unwrapped = unwrap(enumerator); + return unwrapped->getValue().getSExtValue(); +} + +uint64_t llvmsharp_DIEnumerator_getValue_ZExt(LLVMMetadataRef enumerator) +{ + DIEnumerator* unwrapped = unwrap(enumerator); + return unwrapped->getValue().getZExtValue(); +} + +uint8_t llvmsharp_DIEnumerator_isUnsigned(LLVMMetadataRef enumerator) +{ + DIEnumerator* unwrapped = unwrap(enumerator); + return unwrapped->isUnsigned(); +} + +LLVMMetadataRef llvmsharp_DIImportedEntity_getEntity(LLVMMetadataRef node) +{ + DIImportedEntity* unwrapped = unwrap(node); + return wrap(unwrapped->getEntity()); +} + +LLVMMetadataRef llvmsharp_DIImportedEntity_getFile(LLVMMetadataRef node) +{ + DIImportedEntity* unwrapped = unwrap(node); + return wrap(unwrapped->getFile()); +} + +uint32_t llvmsharp_DIImportedEntity_getLine(LLVMMetadataRef node) +{ + DIImportedEntity* unwrapped = unwrap(node); + return unwrapped->getLine(); +} + +LLVMMetadataRef llvmsharp_DIImportedEntity_getScope(LLVMMetadataRef node) +{ + DIImportedEntity* unwrapped = unwrap(node); + return wrap(unwrapped->getScope()); +} + +uint32_t llvmsharp_DILexicalBlock_getLine(LLVMMetadataRef block) +{ + DILexicalBlock* unwrapped = unwrap(block); + return unwrapped->getLine(); +} + +LLVMMetadataRef llvmsharp_DILexicalBlock_getScope(LLVMMetadataRef block) +{ + DILexicalBlock* unwrapped = unwrap(block); + return wrap(unwrapped->getScope()); +} + +const char* llvmsharp_DINamespace_getName(LLVMMetadataRef node, int32_t* out_size) +{ + DINamespace* unwrapped = unwrap(node); + StringRef name = unwrapped->getName(); + *out_size = (int32_t)name.size(); + return name.data(); +} + +LLVMMetadataRef llvmsharp_DINamespace_getScope(LLVMMetadataRef node) +{ + DINamespace* unwrapped = unwrap(node); + return wrap(unwrapped->getScope()); +} + +const char* llvmsharp_DINode_getTagString(LLVMMetadataRef node, int32_t* out_size) +{ + DINode* unwrapped = unwrap(node); + uint16_t tag = unwrapped->getTag(); + StringRef name = dwarf::TagString(tag); + *out_size = (int32_t)name.size(); + return name.data(); +} + +LLVMMetadataRef llvmsharp_DISubprogram_getContainingType(LLVMMetadataRef subprogram) +{ + DISubprogram* unwrapped = unwrap(subprogram); + return wrap(unwrapped->getContainingType()); +} + +uint32_t llvmsharp_DISubprogram_getFlags(LLVMMetadataRef subprogram) +{ + DISubprogram* unwrapped = unwrap(subprogram); + return unwrapped->getFlags(); +} + +const char* llvmsharp_DISubprogram_getLinkageName(LLVMMetadataRef subprogram, int32_t* out_size) +{ + DISubprogram* unwrapped = unwrap(subprogram); + StringRef name = unwrapped->getLinkageName(); + *out_size = (int32_t)name.size(); + return name.data(); +} + +const char* llvmsharp_DISubprogram_getName(LLVMMetadataRef subprogram, int32_t* out_size) +{ + DISubprogram* unwrapped = unwrap(subprogram); + StringRef name = unwrapped->getName(); + *out_size = (int32_t)name.size(); + return name.data(); +} + +uint32_t llvmsharp_DISubprogram_getScopeLine(LLVMMetadataRef subprogram) +{ + DISubprogram* unwrapped = unwrap(subprogram); + return unwrapped->getScopeLine(); +} + +uint32_t llvmsharp_DISubprogram_getSPFlags(LLVMMetadataRef subprogram) +{ + DISubprogram* unwrapped = unwrap(subprogram); + return unwrapped->getSPFlags(); +} + +void llvmsharp_DISubprogram_getTemplateParams(LLVMMetadataRef subprogram, LLVMMetadataRef** out_buffer, int32_t* out_size) +{ + DISubprogram* unwrapped = unwrap(subprogram); + DITemplateParameterArray array = unwrapped->getTemplateParams(); + int32_t size = array.size(); + + LLVMMetadataRef* buffer = (LLVMMetadataRef*)malloc(size * sizeof(LLVMMetadataRef)); + if (buffer == nullptr) + { + *out_buffer = nullptr; + *out_size = 0; + return; // Memory allocation failed + } + + for (int32_t i = 0; i < size; ++i) + { + buffer[i] = wrap(array[i]); + } + + *out_buffer = buffer; + *out_size = size; +} + +LLVMMetadataRef llvmsharp_DISubprogram_getType(LLVMMetadataRef subprogram) +{ + DISubprogram* unwrapped = unwrap(subprogram); + return wrap(unwrapped->getType()); +} + +uint32_t llvmsharp_DISubprogram_getVirtualIndex(LLVMMetadataRef subprogram) +{ + DISubprogram* unwrapped = unwrap(subprogram); + return unwrapped->getVirtualIndex(); +} + +LLVMValueRef llvmsharp_DISubrange_getCount(LLVMMetadataRef subrange) +{ + DISubrange* unwrapped = unwrap(subrange); + Metadata* countNode = unwrapped->getRawCountNode(); + if (isa(countNode)) + { + ConstantAsMetadata* constantAsMetadata = cast(countNode); + Constant* constant = constantAsMetadata->getValue(); + return wrap(constant); + } + return nullptr; +} + +void llvmsharp_DISubroutineType_getTypeArray(LLVMMetadataRef subroutine_type, LLVMMetadataRef** out_buffer, int32_t* out_size) +{ + DISubroutineType* unwrapped = unwrap(subroutine_type); + DITypeRefArray array = unwrapped->getTypeArray(); + int32_t size = array.size(); + + LLVMMetadataRef* buffer = (LLVMMetadataRef*)malloc(size * sizeof(LLVMMetadataRef)); + if (buffer == nullptr) + { + *out_buffer = nullptr; + *out_size = 0; + return; // Memory allocation failed + } + + for (int32_t i = 0; i < size; ++i) + { + buffer[i] = wrap(array[i]); + } + + *out_buffer = buffer; + *out_size = size; +} + +LLVMMetadataRef llvmsharp_DITemplateParameter_getType(LLVMMetadataRef parameter) +{ + DITemplateParameter* unwrapped = unwrap(parameter); + return wrap(unwrapped->getType()); +} + +LLVMMetadataRef llvmsharp_DITemplateValueParameter_getValue(LLVMMetadataRef parameter) +{ + DITemplateValueParameter* unwrapped = unwrap(parameter); + return wrap(unwrapped->getValue()); +} + +const char* llvmsharp_DIVariable_getName(LLVMMetadataRef variable, int32_t* out_size) +{ + DIVariable* unwrapped = unwrap(variable); + StringRef name = unwrapped->getName(); + *out_size = (int32_t)name.size(); + return name.data(); +} + +LLVMMetadataRef llvmsharp_DIVariable_getType(LLVMMetadataRef variable) +{ + DIVariable* unwrapped = unwrap(variable); + return wrap(unwrapped->getType()); +} + +LLVMTypeRef llvmsharp_Function_getFunctionType(LLVMValueRef function) +{ + Function* unwrapped = unwrap(function); + Type* type = unwrapped->getFunctionType(); + return wrap(type); +} + +LLVMTypeRef llvmsharp_Function_getReturnType(LLVMValueRef function) +{ + Function* unwrapped = unwrap(function); + Type* type = unwrapped->getReturnType(); + return wrap(type); +} + +LLVMMetadataRef llvmsharp_GlobalVariable_getGlobalVariableExpression(LLVMValueRef global_variable) +{ + LLVMMetadataRef unwrapped = llvmsharp_GlobalVariable_getMetadata(global_variable, LLVMContext::MD_dbg); + if (isa(unwrap(unwrapped))) + { + return unwrapped; + } + else + { + return nullptr; + } +} + +LLVMMetadataRef llvmsharp_GlobalVariable_getMetadata(LLVMValueRef global_variable, uint32_t KindID) +{ + GlobalVariable* unwrapped = unwrap(global_variable); + return wrap(unwrapped->getMetadata(KindID)); +} + +uint8_t llvmsharp_Instruction_hasNoSignedWrap(LLVMValueRef instruction) +{ + Instruction* unwrapped = unwrap(instruction); + return unwrapped->hasNoSignedWrap() ? 1 : 0; +} + +uint8_t llvmsharp_Instruction_hasNoUnsignedWrap(LLVMValueRef instruction) +{ + Instruction* unwrapped = unwrap(instruction); + return unwrapped->hasNoUnsignedWrap() ? 1 : 0; +} + +uint32_t llvmsharp_MDNode_getNumOperands(LLVMMetadataRef metadata) +{ + MDNode* unwrapped = unwrap(metadata); + return unwrapped->getNumOperands(); +} + +LLVMMetadataRef llvmsharp_MDNode_getOperand(LLVMMetadataRef metadata, uint32_t index) +{ + MDNode* unwrapped = unwrap(metadata); + if (index >= unwrapped->getNumOperands()) + { + return nullptr; // Index out of bounds + } + return wrap(unwrapped->getOperand(index)); +} + +const char* llvmsharp_MDString_getString(LLVMMetadataRef mdstring, int32_t* out_size) +{ + MDString* unwrapped = unwrap(mdstring); + StringRef str = unwrapped->getString(); + *out_size = (int32_t)str.size(); + return str.data(); +} + +#define LLVMSHARP_METADATA_ISA(CPP_TYPE) \ +LLVMMetadataRef llvmsharp_Metadata_IsA##CPP_TYPE(LLVMMetadataRef metadata) \ +{ \ + return wrap(static_cast(dyn_cast_or_null(unwrap(metadata)))); \ +} + +LLVM_FOR_EACH_METADATA_SUBCLASS(LLVMSHARP_METADATA_ISA) + +#undef LLVMSHARP_METADATA_ISA + +void llvmsharp_Module_GetIdentifiedStructTypes(LLVMModuleRef module, LLVMTypeRef** out_buffer, int32_t* out_size) +{ + Module* unwrapped = unwrap(module); + std::vector types = unwrapped->getIdentifiedStructTypes(); + + LLVMTypeRef* buffer = (LLVMTypeRef*)malloc(types.size() * sizeof(LLVMTypeRef)); + if (buffer == nullptr) + { + *out_buffer = nullptr; + *out_size = 0; + return; // Memory allocation failed + } + + for (size_t i = 0; i < types.size(); ++i) + { + buffer[i] = wrap(types[i]); + } + + *out_buffer = buffer; + *out_size = (int32_t)types.size(); +} + +void llvmsharp_PassManager_add(LLVMPassManagerRef pass_manager, LLVMPassRef pass) +{ + unwrap(pass_manager)->add(unwrap(pass)); +} + +LLVMPassRef llvmsharp_createDeadCodeEliminationPass() +{ + return wrap((Pass*)createDeadCodeEliminationPass()); +} + +LLVMPassRef llvmsharp_createSROAPass(uint8_t PreserveCFG) +{ + return wrap((Pass*)createSROAPass((bool)PreserveCFG)); +} + +LLVMPassRef llvmsharp_createLICMPass() +{ + return wrap(createLICMPass()); +} + +LLVMPassRef llvmsharp_createLoopStrengthReducePass() +{ + return wrap(createLoopStrengthReducePass()); +} + +LLVMPassRef llvmsharp_createReassociatePass() +{ + return wrap((Pass*)createReassociatePass()); +} + +LLVMPassRef llvmsharp_createFlattenCFGPass() +{ + return wrap((Pass*)createFlattenCFGPass()); +} + +LLVMPassRef llvmsharp_createCFGSimplificationPass() +{ + return wrap((Pass*)createCFGSimplificationPass()); +} + +LLVMPassRef llvmsharp_createTailCallEliminationPass() +{ + return wrap((Pass*)createTailCallEliminationPass()); +} + +LLVMPassRef llvmsharp_createConstantHoistingPass() +{ + return wrap((Pass*)createConstantHoistingPass()); +} + +LLVMPassRef llvmsharp_createLowerInvokePass() +{ + return wrap((Pass*)createLowerInvokePass()); +} + +LLVMPassRef llvmsharp_createLowerSwitchPass() +{ + return wrap((Pass*)createLowerSwitchPass()); +} + +LLVMPassRef llvmsharp_createBreakCriticalEdgesPass() +{ + return wrap((Pass*)createBreakCriticalEdgesPass()); +} + +LLVMPassRef llvmsharp_createLCSSAPass() +{ + return wrap(createLCSSAPass()); +} + +LLVMPassRef llvmsharp_createPromoteMemoryToRegisterPass() +{ + return wrap((Pass*)createPromoteMemoryToRegisterPass()); +} + +LLVMPassRef llvmsharp_createLoopSimplifyPass() +{ + return wrap(createLoopSimplifyPass()); +} + +LLVMPassRef llvmsharp_createUnifyLoopExitsPass() +{ + return wrap((Pass*)createUnifyLoopExitsPass()); +} + +int32_t llvmsharp_Demangle(const char* mangled_string, int32_t mangled_string_size, char* buffer, int32_t buffer_size) +{ + std::string result = llvm::demangle(std::string_view(mangled_string, mangled_string_size)); + int32_t length = (int32_t)result.length(); + int32_t size = length < buffer_size ? length : buffer_size; + memcpy(buffer, result.c_str(), size); + return length; +} + +void llvmsharp_Free(void* obj) +{ + free(obj); +} diff --git a/sources/libLLVMSharp/LLVMSharp.h b/sources/libLLVMSharp/LLVMSharp.h new file mode 100644 index 0000000..30032a1 --- /dev/null +++ b/sources/libLLVMSharp/LLVMSharp.h @@ -0,0 +1,217 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +#ifndef LIBLLVMSHARP_LLVMSHARP_H +#define LIBLLVMSHARP_LLVMSHARP_H + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) +#endif + +// Include headers +#include +#include + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#include "LLVMSharp_export.h" + +// Copied from the LLVMMetadataKind enum +#define LLVM_FOR_EACH_METADATA_SUBCLASS(macro) \ + macro(MDNode) \ + macro(DINode) \ + macro(DIScope) \ + macro(DITemplateParameter) \ + macro(DIType) \ + macro(DIVariable) \ + macro(MDString) \ + macro(ConstantAsMetadata) \ + macro(LocalAsMetadata) \ + macro(DistinctMDOperandPlaceholder) \ + macro(MDTuple) \ + macro(DILocation) \ + macro(DIExpression) \ + macro(DIGlobalVariableExpression) \ + macro(GenericDINode) \ + macro(DISubrange) \ + macro(DIEnumerator) \ + macro(DIBasicType) \ + macro(DIDerivedType) \ + macro(DICompositeType) \ + macro(DISubroutineType) \ + macro(DIFile) \ + macro(DICompileUnit) \ + macro(DISubprogram) \ + macro(DILexicalBlock) \ + macro(DILexicalBlockFile) \ + macro(DINamespace) \ + macro(DIModule) \ + macro(DITemplateTypeParameter) \ + macro(DITemplateValueParameter) \ + macro(DIGlobalVariable) \ + macro(DILocalVariable) \ + macro(DILabel) \ + macro(DIObjCProperty) \ + macro(DIImportedEntity) \ + macro(DIMacro) \ + macro(DIMacroFile) \ + macro(DICommonBlock) \ + macro(DIStringType) \ + macro(DIGenericSubrange) \ + macro(DIArgList) \ + macro(DIAssignID) \ + +/** + * Represents an individual value in LLVM IR. + * + * This models llvm::Value. + */ +typedef struct LLVMOpaquePass* LLVMPassRef; + +// Enum definitions + +// Struct definitions + +LLVM_CLANG_C_EXTERN_C_BEGIN + +// Function declarations + +LLVMSHARP_LINKAGE const char* llvmsharp_ConstantDataArray_getData(LLVMValueRef array, int32_t* out_size); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_DIBasicType_getEncoding(LLVMMetadataRef type); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DICompositeType_getBaseType(LLVMMetadataRef type); + +LLVMSHARP_LINKAGE void llvmsharp_DICompositeType_getElements(LLVMMetadataRef type, LLVMMetadataRef** out_buffer, int32_t* out_size); + +LLVMSHARP_LINKAGE const char* llvmsharp_DICompositeType_getIdentifier(LLVMMetadataRef type, int32_t* out_size); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DIDerivedType_getBaseType(LLVMMetadataRef type); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DIDerivedType_getExtraData(LLVMMetadataRef type); + +LLVMSHARP_LINKAGE const char* llvmsharp_DIEnumerator_getName(LLVMMetadataRef enumerator, int32_t* out_size); + +LLVMSHARP_LINKAGE int64_t llvmsharp_DIEnumerator_getValue_SExt(LLVMMetadataRef enumerator); + +LLVMSHARP_LINKAGE uint64_t llvmsharp_DIEnumerator_getValue_ZExt(LLVMMetadataRef enumerator); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_DIEnumerator_isUnsigned(LLVMMetadataRef enumerator); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DIImportedEntity_getEntity(LLVMMetadataRef node); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DIImportedEntity_getFile(LLVMMetadataRef node); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_DIImportedEntity_getLine(LLVMMetadataRef node); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DIImportedEntity_getScope(LLVMMetadataRef node); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_DILexicalBlock_getLine(LLVMMetadataRef block); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DILexicalBlock_getScope(LLVMMetadataRef block); + +LLVMSHARP_LINKAGE const char* llvmsharp_DINamespace_getName(LLVMMetadataRef node, int32_t* out_size); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DINamespace_getScope(LLVMMetadataRef node); + +LLVMSHARP_LINKAGE const char* llvmsharp_DINode_getTagString(LLVMMetadataRef node, int32_t* out_size); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DISubprogram_getContainingType(LLVMMetadataRef subprogram); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_DISubprogram_getFlags(LLVMMetadataRef subprogram); + +LLVMSHARP_LINKAGE const char* llvmsharp_DISubprogram_getLinkageName(LLVMMetadataRef subprogram, int32_t* out_size); + +LLVMSHARP_LINKAGE const char* llvmsharp_DISubprogram_getName(LLVMMetadataRef subprogram, int32_t* out_size); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_DISubprogram_getScopeLine(LLVMMetadataRef subprogram); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_DISubprogram_getSPFlags(LLVMMetadataRef subprogram); + +LLVMSHARP_LINKAGE void llvmsharp_DISubprogram_getTemplateParams(LLVMMetadataRef subprogram, LLVMMetadataRef** out_buffer, int32_t* out_size); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DISubprogram_getType(LLVMMetadataRef subprogram); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_DISubprogram_getVirtualIndex(LLVMMetadataRef subprogram); + +LLVMSHARP_LINKAGE LLVMValueRef llvmsharp_DISubrange_getCount(LLVMMetadataRef subrange); + +LLVMSHARP_LINKAGE void llvmsharp_DISubroutineType_getTypeArray(LLVMMetadataRef subroutine_type, LLVMMetadataRef** out_buffer, int32_t* out_size); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DITemplateParameter_getType(LLVMMetadataRef parameter); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DITemplateValueParameter_getValue(LLVMMetadataRef parameter); + +LLVMSHARP_LINKAGE const char* llvmsharp_DIVariable_getName(LLVMMetadataRef variable, int32_t* out_size); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DIVariable_getType(LLVMMetadataRef variable); + +LLVMSHARP_LINKAGE LLVMTypeRef llvmsharp_Function_getFunctionType(LLVMValueRef function); + +LLVMSHARP_LINKAGE LLVMTypeRef llvmsharp_Function_getReturnType(LLVMValueRef function); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_GlobalVariable_getGlobalVariableExpression(LLVMValueRef global_variable); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_GlobalVariable_getMetadata(LLVMValueRef global_variable, uint32_t KindID); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Instruction_hasNoSignedWrap(LLVMValueRef instruction); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Instruction_hasNoUnsignedWrap(LLVMValueRef instruction); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_MDNode_getNumOperands(LLVMMetadataRef metadata); + +LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_MDNode_getOperand(LLVMMetadataRef metadata, uint32_t index); + +LLVMSHARP_LINKAGE const char* llvmsharp_MDString_getString(LLVMMetadataRef mdstring, int32_t* out_size); + +#define LLVMSHARP_METADATA_ISA(CPP_TYPE) LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_Metadata_IsA##CPP_TYPE(LLVMMetadataRef metadata); + +LLVM_FOR_EACH_METADATA_SUBCLASS(LLVMSHARP_METADATA_ISA) + +#undef LLVMSHARP_METADATA_ISA + +LLVMSHARP_LINKAGE void llvmsharp_Module_GetIdentifiedStructTypes(LLVMModuleRef module, LLVMTypeRef** out_buffer, int32_t* out_size); + +LLVMSHARP_LINKAGE void llvmsharp_PassManager_add(LLVMPassManagerRef pass_manager, LLVMPassRef pass); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createDeadCodeEliminationPass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createSROAPass(uint8_t PreserveCFG); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createLICMPass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createLoopStrengthReducePass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createReassociatePass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createFlattenCFGPass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createCFGSimplificationPass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createTailCallEliminationPass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createConstantHoistingPass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createLowerInvokePass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createLowerSwitchPass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createBreakCriticalEdgesPass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createLCSSAPass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createPromoteMemoryToRegisterPass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createLoopSimplifyPass(); + +LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createUnifyLoopExitsPass(); + +LLVMSHARP_LINKAGE int32_t llvmsharp_Demangle(const char* mangled_string, int32_t mangled_string_size, char* buffer, int32_t buffer_size); + +LLVMSHARP_LINKAGE void llvmsharp_Free(void* obj); + +LLVM_CLANG_C_EXTERN_C_END + +#endif