├── AUTHORS ├── .github ├── featured.webp ├── py_osx.sh └── workflows │ └── osx.yml ├── third-party └── spdlog-1.11.0.zip ├── bindings └── python │ ├── src │ ├── ObjC │ │ └── CMakeLists.txt │ ├── CMakeLists.txt │ ├── ObjC.hpp │ ├── iterator.hpp │ └── iCDump.cpp │ ├── examples │ └── api_examples.py │ ├── setup.cfg │ ├── description.rst │ └── CMakeLists.txt ├── cmake ├── spdlog.cmake └── iCDumpGit.cmake ├── src ├── llvm-swift │ └── swift │ │ ├── include │ │ └── swift │ │ │ ├── Basic │ │ │ ├── InitializeLibSwift.h │ │ │ ├── Sanitizers.h │ │ │ ├── Edit.h │ │ │ ├── Feature.h │ │ │ ├── Sanitizers.def │ │ │ ├── OptimizationMode.h │ │ │ ├── Dwarf.h │ │ │ ├── TargetInfo.h │ │ │ ├── FunctionBodySkipping.h │ │ │ ├── TypeIDZones.def │ │ │ ├── Unreachable.h │ │ │ ├── ProfileCounter.h │ │ │ ├── ColorUtils.h │ │ │ ├── Debug.h │ │ │ ├── LLVMInitialize.h │ │ │ ├── QuotedString.h │ │ │ ├── Program.h │ │ │ ├── ThreadSafeRefCounted.h │ │ │ ├── Defer.h │ │ │ ├── PrimitiveParsing.h │ │ │ ├── Malloc.h │ │ │ ├── SmallPtrSetVector.h │ │ │ ├── EditorPlaceholder.h │ │ │ ├── PrettyStackTrace.h │ │ │ ├── AnyValue.h │ │ │ ├── APIntMap.h │ │ │ ├── CTypeIDZone.def │ │ │ ├── ImplementTypeIDZone.h │ │ │ ├── ScopedTracking.h │ │ │ ├── GraphNodeWorklist.h │ │ │ ├── Unicode.h │ │ │ ├── type_traits.h │ │ │ ├── IndexTrie.h │ │ │ └── PrimarySpecificPaths.h │ │ │ ├── AST │ │ │ ├── SILGenTypeIDZone.def │ │ │ ├── SILOptimizerTypeIDZone.def │ │ │ ├── KnownSDKDecls.def │ │ │ ├── IRGenTypeIDZone.def │ │ │ ├── DiagnosticsIDE.h │ │ │ ├── SemanticAttrs.h │ │ │ ├── DiagnosticsIRGen.h │ │ │ ├── DiagnosticsSIL.h │ │ │ ├── DiagnosticsFrontend.h │ │ │ ├── ObjCSelectorFamily.def │ │ │ ├── DiagnosticsRefactoring.h │ │ │ ├── DiagnosticsClangImporter.h │ │ │ ├── DiagnosticsModuleDiffer.h │ │ │ ├── AccessTypeIDZone.def │ │ │ ├── TBDGenTypeIDZone.def │ │ │ ├── DiagnosticsDriver.h │ │ │ ├── ForeignInfo.h │ │ │ ├── DiagnosticsParse.h │ │ │ ├── ParseTypeIDZone.def │ │ │ ├── DiagnosticsAll.def │ │ │ ├── KnownFoundationEntities.def │ │ │ ├── TypeWalker.h │ │ │ ├── ClangSwiftTypeCorrespondence.h │ │ │ ├── DiagnosticsSema.h │ │ │ ├── TypeResolutionStage.h │ │ │ ├── DiagnosticSuppression.h │ │ │ ├── KnownProtocols.h │ │ │ ├── LinkLibrary.h │ │ │ ├── FileSystem.h │ │ │ ├── IfConfigClause.h │ │ │ ├── PlatformConditionKinds.def │ │ │ ├── LayoutConstraintKind.h │ │ │ ├── PlatformKinds.def │ │ │ ├── DefaultArgumentKind.h │ │ │ ├── FunctionRefKind.h │ │ │ ├── DefineDiagnosticMacros.h │ │ │ ├── TypeOrExtensionDecl.h │ │ │ ├── PatternNodes.def │ │ │ ├── DiagnosticsCommon.h │ │ │ ├── DiagnosticsIDE.def │ │ │ ├── TypeVisitor.h │ │ │ ├── SwiftNameTranslation.h │ │ │ ├── ReferenceCounting.h │ │ │ ├── ResilienceExpansion.h │ │ │ ├── KnownSDKTypes.def │ │ │ ├── SynthesizedFileUnit.h │ │ │ ├── TypeMemberVisitor.h │ │ │ ├── TypeReprNodes.def │ │ │ ├── RawComment.h │ │ │ └── StmtNodes.def │ │ │ └── Demangling │ │ │ ├── NamespaceMacros.h │ │ │ └── ValueWitnessMangling.def │ │ └── lib │ │ └── Demangling │ │ ├── CMakeLists.txt │ │ ├── DemanglerAssert.h │ │ └── NodeDumper.cpp ├── ClangAST │ ├── utils.hpp │ └── ASTGen.hpp ├── MachOStream.hpp ├── log_public.cpp ├── ObjC │ ├── Metadata.cpp │ ├── Property.cpp │ └── IVar.cpp ├── iCDump.cpp ├── MachOStream.cpp └── log.hpp ├── include └── iCDump │ ├── config.hpp.in │ ├── Logging.hpp │ ├── ObjC.hpp │ ├── NonCopyable.hpp │ ├── version.h.in │ ├── iCDump.hpp │ └── ObjC │ ├── Property.hpp │ ├── IVar.hpp │ ├── Method.hpp │ ├── Metadata.hpp │ ├── Parser.hpp │ └── Protocol.hpp ├── scripts └── docker │ ├── compile_icdump.sh │ ├── compile_llvm.sh │ └── compile_lief.sh ├── README.md └── iCDumpConfig.cmake.in /AUTHORS: -------------------------------------------------------------------------------- 1 | Authors: 2 | 3 | Romain Thomas 4 | -------------------------------------------------------------------------------- /.github/featured.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/romainthomas/iCDump/HEAD/.github/featured.webp -------------------------------------------------------------------------------- /third-party/spdlog-1.11.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/romainthomas/iCDump/HEAD/third-party/spdlog-1.11.0.zip -------------------------------------------------------------------------------- /bindings/python/src/ObjC/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(iCDump PRIVATE 2 | ${CMAKE_CURRENT_LIST_DIR}/init.cpp 3 | ${CMAKE_CURRENT_LIST_DIR}/types_encoding.cpp 4 | ) 5 | -------------------------------------------------------------------------------- /bindings/python/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(iCDump PRIVATE 2 | ${CMAKE_CURRENT_LIST_DIR}/iCDump.cpp 3 | ) 4 | include(${CMAKE_CURRENT_LIST_DIR}/ObjC/CMakeLists.txt) 5 | -------------------------------------------------------------------------------- /bindings/python/examples/api_examples.py: -------------------------------------------------------------------------------- 1 | import icdump 2 | 3 | metadata: icdump.objc.Metadata = icdump.objc.parse("./RNCryptor.bin") 4 | 5 | for cls in metadata.classes: 6 | print(cls.demangled_name) 7 | 8 | icdump.set_log_level(icdump.LOG_LEVEL.DEBUG) 9 | 10 | for protocol in metadata.protocols: 11 | print(protocol.mangled_name, len(protocol.properties)) 12 | 13 | print(metadata.to_decl()) 14 | -------------------------------------------------------------------------------- /.github/py_osx.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sh 2 | set -ex 3 | python $GITHUB_WORKSPACE/bindings/python/setup.py --ninja --osx-arch=arm64 \ 4 | --lief-dir=/tmp/third-party/LIEF-0.13.0-Darwin/share/LIEF/cmake \ 5 | --llvm-dir=/tmp/third-party/LLVM-14.0.6-Darwin/lib/cmake/llvm \ 6 | build --build-temp=/tmp/arm64 bdist_wheel --skip-build \ 7 | --plat-name=macosx_${MACOSX_DEPLOYMENT_TARGET}_arm64 8 | 9 | -------------------------------------------------------------------------------- /bindings/python/setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = icdump 3 | author = Romain Thomas 4 | author_email = me@romainthomas.fr 5 | description = A modern Objective-C class dump 6 | keywords = reverse-engineering, objective-c 7 | license = Apache License 2.0 8 | long_description = file: description.rst 9 | long_description_content_type = text/x-rst; charset=UTF-8 10 | url = https://github.com/romainthomas/iCDump 11 | classifiers = 12 | Development Status :: 4 - Beta 13 | Programming Language :: Python 14 | Programming Language :: C++ 15 | Topic :: Software Development :: Libraries 16 | 17 | [options] 18 | zip_safe = False 19 | packages = find: 20 | include_package_data = True 21 | python_requires = >=3.8 22 | scripts = 23 | tools/readobjc.py 24 | 25 | [build_ext] 26 | inplace=1 27 | -------------------------------------------------------------------------------- /cmake/spdlog.cmake: -------------------------------------------------------------------------------- 1 | if(__add_spdlog) 2 | return() 3 | endif() 4 | set(__add_spdlog ON) 5 | include(ExternalProject) 6 | 7 | # spdlog 8 | # ====== 9 | set(SPDLOG_VERSION 1.11.0) 10 | set(SPDLOG_URL "${ICDUMP_READER_THIRD_PARTY_DIRECTORY}/spdlog-${SPDLOG_VERSION}.zip") 11 | set(SPDLOG_SHA256 SHA256=33f83c6b86ec0fbbd0eb0f4e980da6767494dc0ad063900bcfae8bc3e9c75f21) 12 | ExternalProject_Add(spdlog-project 13 | URL ${SPDLOG_URL} 14 | URL_HASH ${SPDLOG_SHA256} 15 | CONFIGURE_COMMAND "" 16 | BUILD_COMMAND "" 17 | INSTALL_COMMAND "") 18 | ExternalProject_get_property(spdlog-project SOURCE_DIR) 19 | set(SPDLOG_SOURCE_DIR "${SOURCE_DIR}") 20 | 21 | add_library(spdlog INTERFACE) 22 | add_dependencies(spdlog spdlog-project) 23 | target_include_directories(spdlog SYSTEM INTERFACE "$") 24 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/InitializeLibSwift.h: -------------------------------------------------------------------------------- 1 | //===--- InitializeLibSwift.h -----------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_INITIALIZELIBSWIFT_H 14 | #define SWIFT_BASIC_INITIALIZELIBSWIFT_H 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | void initializeLibSwift(); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif // SWIFT_BASIC_INITIALIZELIBSWIFT_H 27 | -------------------------------------------------------------------------------- /bindings/python/src/ObjC.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef PY_ICDUMP_OBJC_H 16 | #define PY_ICDUMP_OBJC_H 17 | namespace nanobind { 18 | class module_; 19 | } 20 | namespace iCDump::py::ObjC { 21 | void init(nanobind::module_& m); 22 | void init_types_encoding(nanobind::module_& m); 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /include/iCDump/config.hpp.in: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef ICDUMP_CONFIG_H 16 | #define ICDUMP_CONFIG_H 17 | #cmakedefine ICDUMP_LLVM_SUPPORT @ICDUMP_LLVM_SUPPORT@ 18 | 19 | #ifdef __cplusplus 20 | 21 | static constexpr bool icdump_llvm_support = @ICDUMP_LLVM_SUPPORT@; 22 | 23 | #endif // __cplusplus 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/Sanitizers.h: -------------------------------------------------------------------------------- 1 | //===--- Sanitizers.h - Helpers related to sanitizers -----------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_SANITIZERS_H 14 | #define SWIFT_BASIC_SANITIZERS_H 15 | 16 | namespace swift { 17 | 18 | // Enabling bitwise masking. 19 | enum class SanitizerKind : unsigned { 20 | #define SANITIZER(enum_bit, kind, name, file) kind = (1 << enum_bit), 21 | #include "Sanitizers.def" 22 | }; 23 | 24 | } // end namespace swift 25 | 26 | #endif // SWIFT_BASIC_SANITIZERS_H 27 | -------------------------------------------------------------------------------- /include/iCDump/Logging.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef ICDUMP_LOGGING_PUBLIC_H_ 16 | #define ICDUMP_LOGGING_PUBLIC_H_ 17 | namespace iCDump { 18 | 19 | enum class LOG_LEVEL { 20 | TRACE, 21 | DEBUG, 22 | INFO, 23 | WARN, 24 | ERR, 25 | CRITICAL, 26 | }; 27 | 28 | void disable_log(); 29 | void enable_log(); 30 | 31 | void set_log_level(LOG_LEVEL lvl); 32 | 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /scripts/docker/compile_icdump.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sh 2 | set -ex 3 | 4 | cp /third-party/LIEF-0.13.0-Linux-x86_64.tar.gz /tmp/ 5 | cp /third-party/LLVM-14.0.6-Linux-slim.tar.gz /tmp/ 6 | 7 | cd /tmp 8 | tar xzvf LIEF-0.13.0-Linux-x86_64.tar.gz 9 | tar xzvf LLVM-14.0.6-Linux-slim.tar.gz 10 | 11 | export CXXFLAGS='-ffunction-sections -fdata-sections -fvisibility-inlines-hidden -static-libgcc -fvisibility=hidden' 12 | export CFLAGS='-ffunction-sections -fdata-sections -static-libgcc' 13 | export LDFLAGS='-Wl,--gc-sections' 14 | 15 | cd /icdump/bindings/python 16 | 17 | $PYTHON_BINARY setup.py --ninja \ 18 | --lief-dir=/tmp/LIEF-0.13.0-Linux-x86_64/share/LIEF/cmake \ 19 | --llvm-dir=/tmp/LLVM-14.0.6-Linux/lib/cmake/llvm \ 20 | build \ 21 | bdist_wheel --skip-build --dist-dir wheel_stage 22 | 23 | find wheel_stage -iname "*-cp${PYTHON_VERSION}-*" -exec auditwheel repair -w dist --plat manylinux_2_27_x86_64 {} \; 24 | 25 | chown -R 1000:1000 build dist wheel_stage 26 | 27 | -------------------------------------------------------------------------------- /src/ClangAST/utils.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #include 16 | namespace iCDump { 17 | namespace ObjC { 18 | class Protocol; 19 | class Class; 20 | class Property; 21 | } 22 | 23 | namespace ClangAST { 24 | 25 | std::string generate(const ObjC::Protocol& protocol); 26 | std::string generate(const ObjC::Class& protocol); 27 | std::string generate(const ObjC::Property& property); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /include/iCDump/ObjC.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef ICDUMP_OBJC_H_ 16 | #define ICDUMP_OBJC_H_ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #endif 26 | -------------------------------------------------------------------------------- /scripts/docker/compile_llvm.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sh 2 | set -ex 3 | 4 | LLVM_TARGET="X86" 5 | 6 | export CXXFLAGS="-ffunction-sections -fdata-sections -fvisibility-inlines-hidden -fvisibility=hidden" 7 | 8 | cmake -GNinja -S /LLVM/llvm -B /tmp/build_llvm \ 9 | -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \ 10 | -DCMAKE_CXX_COMPILER=clang++-11 \ 11 | -DCMAKE_C_COMPILER=clang-11 \ 12 | -DCMAKE_BUILD_TYPE=Release \ 13 | -DCMAKE_INSTALL_PREFIX=/llvm-install \ 14 | -DLLVM_ENABLE_LTO=OFF \ 15 | -DLLVM_ENABLE_TERMINFO=OFF \ 16 | -DLLVM_ENABLE_THREADS=ON \ 17 | -DLLVM_USE_NEWPM=ON \ 18 | -DLLVM_TARGET_ARCH=${LLVM_TARGET} \ 19 | -DLLVM_TARGETS_TO_BUILD=${LLVM_TARGET} \ 20 | -DLLVM_ENABLE_PROJECTS="clang;llvm" 21 | 22 | ninja -C /tmp/build_llvm package 23 | cp /tmp/build_llvm/LLVM-14.0.6-Linux.tar.gz /LLVM/ 24 | -------------------------------------------------------------------------------- /include/iCDump/NonCopyable.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef ICDUMP_NON_COPYABLE_H_ 16 | #define ICDUMP_NON_COPYABLE_H_ 17 | namespace iCDump { 18 | class NonCopyable { 19 | // Inspired from boost::noncopyable 20 | protected: 21 | constexpr NonCopyable() = default; 22 | ~NonCopyable() = default; 23 | NonCopyable(const NonCopyable&) = delete; 24 | NonCopyable& operator=(const NonCopyable&) = delete; 25 | }; 26 | 27 | } 28 | #endif 29 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/lib/Demangling/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_swift_host_library(swiftDemangling STATIC 2 | Demangler.cpp 3 | Context.cpp 4 | ManglingUtils.cpp 5 | NodeDumper.cpp 6 | NodePrinter.cpp 7 | OldDemangler.cpp 8 | OldRemangler.cpp 9 | Punycode.cpp 10 | Remangler.cpp) 11 | target_compile_definitions(swiftDemangling PRIVATE 12 | LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1 13 | SWIFT_SUPPORT_OLD_MANGLING=1) 14 | 15 | # NOTE: Runtime libraries that depend on swiftDemangling should define 16 | # SWIFT_INLINE_NAMESPACE to specify the identifier that will be used for an 17 | # inline namespace that will be added around the symbols defined by this 18 | # library. This keeps the demangling symbols in those libraries distinct 19 | # from those in the compiler, which prevents ODR violations in certain 20 | # contexts; for example, on platforms that support statically linking the 21 | # Swift standard library, it allows this to happen safely when the binary 22 | # also links in compiler libraries that may not match exactly with the 23 | # runtime version. 24 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/Edit.h: -------------------------------------------------------------------------------- 1 | //===--- Edit.h - Misc edit utilities ---------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_EDIT_H 14 | #define SWIFT_BASIC_EDIT_H 15 | 16 | #include "swift/Basic/LLVM.h" 17 | #include "swift/Basic/SourceLoc.h" 18 | 19 | namespace swift { 20 | class SourceManager; 21 | class CharSourceRange; 22 | 23 | struct SingleEdit { 24 | SourceManager &SM; 25 | CharSourceRange Range; 26 | std::string Text; 27 | }; 28 | 29 | void writeEditsInJson(ArrayRef Edits, llvm::raw_ostream &OS); 30 | } 31 | 32 | #endif // SWIFT_BASIC_EDIT_H 33 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/SILGenTypeIDZone.def: -------------------------------------------------------------------------------- 1 | //===--- SILGenTypeIDZone.def -----------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2020 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This definition file describes the requests in SILGen's zone. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | SWIFT_REQUEST(SILGen, ASTLoweringRequest, 18 | std::unique_ptr(ASTLoweringDescriptor), 19 | Uncached, NoLocationInfo) 20 | SWIFT_REQUEST(SILGen, ParseSILModuleRequest, 21 | std::unique_ptr(ASTLoweringDescriptor), 22 | Uncached, NoLocationInfo) 23 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/SILOptimizerTypeIDZone.def: -------------------------------------------------------------------------------- 1 | //===--- SILOptimizerTypeIDZone.def -----------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2020 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This definition file describes the requests in SILOptimizer's zone. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | SWIFT_REQUEST(SILOptimizer, ExecuteSILPipelineRequest, 18 | evaluator::SideEffect(SILPipelineExecutionDescriptor), 19 | Uncached, NoLocationInfo) 20 | SWIFT_REQUEST(SILOptimizer, LoweredSILRequest, 21 | std::unique_ptr(ASTLoweringDescriptor), 22 | Uncached, NoLocationInfo) 23 | -------------------------------------------------------------------------------- /include/iCDump/version.h.in: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #if defined(NDEBUG) 16 | #define ICDUMP_NAME "@PROJECT_NAME@" 17 | #else 18 | #define ICDUMP_NAME "@PROJECT_NAME@ (Debug)" 19 | #endif 20 | 21 | #define ICDUMP_VERSION "@ICDUMP_VERSION_MAJOR@.@ICDUMP_VERSION_MINOR@.@ICDUMP_VERSION_PATCH@-@ICDUMP_COMMIT_HASH@" 22 | #define ICDUMP_TAGGED @ICDUMP_IS_TAGGED@ 23 | #define ICDUMP_TAG "@ICDUMP_GIT_TAG@" 24 | #define ICDUMP_COMMIT "@ICDUMP_COMMIT_HASH@" 25 | 26 | #define HUMAN_VERSION " v" ICDUMP_VERSION 27 | #define HUMAN_NAME NAME HUMAN_VERSION 28 | -------------------------------------------------------------------------------- /include/iCDump/iCDump.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef ICDUMP_MAIN_H_ 16 | #define ICDUMP_MAIN_H_ 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | namespace iCDump { 24 | 25 | enum class ARCH { 26 | AUTO = 0, 27 | AARCH64, 28 | ARM, 29 | X86_64, 30 | X86, 31 | }; 32 | 33 | namespace ObjC { 34 | std::unique_ptr parse(const std::string& file_path, 35 | ARCH arch = ARCH::AUTO); 36 | } 37 | 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /scripts/docker/compile_lief.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sh 2 | COMMIT=d8f42d74bfeb5d0a4d30472698e1fc0151f4844e 3 | pushd /tmp 4 | curl -LO https://github.com/lief-project/LIEF/archive/$COMMIT.tar.gz 5 | tar xzvf $COMMIT.tar.gz 6 | 7 | export CXXFLAGS="-ffunction-sections -fdata-sections -fvisibility-inlines-hidden -fvisibility=hidden" 8 | 9 | cmake -GNinja -S /tmp/LIEF-$COMMIT -B /tmp/build_lief \ 10 | -DCMAKE_CXX_COMPILER=clang++-11 \ 11 | -DCMAKE_C_COMPILER=clang-11 \ 12 | -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \ 13 | -DCMAKE_BUILD_TYPE=Release \ 14 | -DLIEF_ELF=off \ 15 | -DLIEF_PE=off \ 16 | -DLIEF_OAT=off \ 17 | -DLIEF_VDEX=off \ 18 | -DLIEF_ART=off \ 19 | -DLIEF_DEX=off \ 20 | -DLIEF_ENABLE_JSON=off \ 21 | -DLIEF_EXAMPLES=off 22 | 23 | ninja -C /tmp/build_lief package 24 | # cp /tmp/build_lief/LIEF-0.13.0-Linux-x86_64.tar.gz /LLVM/ 25 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/KnownSDKDecls.def: -------------------------------------------------------------------------------- 1 | //===--- KnownSDKDecls.def - Compiler decl metaprogramming --*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines macros used for macro-metaprogramming with compiler-known 14 | // declarations, in modules other than the standard library. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef KNOWN_SDK_FUNC_DECL 19 | # define KNOWN_SDK_FUNC_DECL(Module, Name, Id) 20 | #endif 21 | 22 | KNOWN_SDK_FUNC_DECL(Distributed, MissingDistributedActorSystem, "_missingDistributedActorSystem") 23 | KNOWN_SDK_FUNC_DECL(Distributed, IsRemoteDistributedActor, "__isRemoteActor") 24 | 25 | #undef KNOWN_SDK_FUNC_DECL 26 | 27 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/Feature.h: -------------------------------------------------------------------------------- 1 | //===--- Feature.h - Helpers related to Swift features ----------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_FEATURES_H 14 | #define SWIFT_BASIC_FEATURES_H 15 | 16 | #include "llvm/ADT/StringRef.h" 17 | 18 | namespace swift { 19 | 20 | class LangOptions; 21 | 22 | /// Enumeration describing all of the named features. 23 | enum class Feature { 24 | #define LANGUAGE_FEATURE(FeatureName, SENumber, Description, Option) \ 25 | FeatureName, 26 | #include "swift/Basic/Features.def" 27 | }; 28 | 29 | /// Determine the in-source name of the given feature. 30 | llvm::StringRef getFeatureName(Feature feature); 31 | 32 | } 33 | 34 | #endif // SWIFT_BASIC_FEATURES_H 35 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/Sanitizers.def: -------------------------------------------------------------------------------- 1 | //===--- Sanitizers.def - Swift Sanitizers ß----------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines the sanitizers supported by Swift. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | #ifndef SANITIZER 18 | #error "Define SANITIZER prior to including this file!" 19 | #endif 20 | 21 | // SANITIZER(enum_bit, kind, name, file) 22 | 23 | SANITIZER(0, Address, address, asan) 24 | SANITIZER(1, Thread, thread, tsan) 25 | SANITIZER(2, Undefined, undefined, ubsan) 26 | SANITIZER(3, Fuzzer, fuzzer, fuzzer) 27 | SANITIZER(4, Scudo, scudo, scudo) 28 | 29 | #undef SANITIZER 30 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/IRGenTypeIDZone.def: -------------------------------------------------------------------------------- 1 | //===--- IRGenTypeIDZone.def ------------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2020 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This definition file describes the requests in IRGen's zone. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | SWIFT_REQUEST(IRGen, IRGenRequest, 18 | GeneratedModule(IRGenDescriptor), 19 | Uncached, NoLocationInfo) 20 | SWIFT_REQUEST(IRGen, OptimizedIRRequest, 21 | GeneratedModule(IRGenDescriptor), 22 | Uncached, NoLocationInfo) 23 | SWIFT_REQUEST(IRGen, SymbolObjectCodeRequest, 24 | StringRef(SymbolsToEmit, IRGenDescriptor), 25 | Cached, NoLocationInfo) 26 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsIDE.h: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsIDE.h - Diagnostic Definitions --------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2021 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file 14 | /// This file defines diagnostics used only in IDE. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_DIAGNOSTICSIDE_H 19 | #define SWIFT_DIAGNOSTICSIDE_H 20 | 21 | #include "swift/AST/DiagnosticsCommon.h" 22 | 23 | namespace swift { 24 | namespace diag { 25 | // Declare common diagnostics objects with their appropriate types. 26 | #define DIAG(KIND,ID,Options,Text,Signature) \ 27 | extern detail::DiagWithArguments::type ID; 28 | #include "DiagnosticsIDE.def" 29 | } 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/SemanticAttrs.h: -------------------------------------------------------------------------------- 1 | //===--- Semantics.h - Semantics Attribute Definitions -------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | /// 13 | /// \file 14 | /// Implementation of the matching definition file. 15 | /// This file holds all semantics attributes as constant string literals. 16 | /// 17 | //===----------------------------------------------------------------------===// 18 | 19 | #ifndef SWIFT_SEMANTICS_H 20 | #define SWIFT_SEMANTICS_H 21 | 22 | #include "swift/Basic/LLVM.h" 23 | #include "llvm/ADT/StringRef.h" 24 | 25 | namespace swift { 26 | namespace semantics { 27 | #define SEMANTICS_ATTR(NAME, C_STR) constexpr static const StringLiteral NAME = C_STR; 28 | #include "SemanticAttrs.def" 29 | } 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsIRGen.h: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsIRGen.h - Diagnostic Definitions ------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file 14 | /// This file defines diagnostics for IR generation. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_DIAGNOSTICSIRGEN_H 19 | #define SWIFT_DIAGNOSTICSIRGEN_H 20 | 21 | #include "swift/AST/DiagnosticsCommon.h" 22 | 23 | namespace swift { 24 | namespace diag { 25 | // Declare common diagnostics objects with their appropriate types. 26 | #define DIAG(KIND,ID,Options,Text,Signature) \ 27 | extern detail::DiagWithArguments::type ID; 28 | #include "DiagnosticsIRGen.def" 29 | } 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsSIL.h: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsSIL.h - Diagnostic Definitions --------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file 14 | /// This file defines diagnostics for SIL generation and analysis. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_DIAGNOSTICSSIL_H 19 | #define SWIFT_DIAGNOSTICSSIL_H 20 | 21 | #include "swift/AST/DiagnosticsCommon.h" 22 | 23 | namespace swift { 24 | namespace diag { 25 | // Declare common diagnostics objects with their appropriate types. 26 | #define DIAG(KIND,ID,Options,Text,Signature) \ 27 | extern detail::DiagWithArguments::type ID; 28 | #include "DiagnosticsSIL.def" 29 | } 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsFrontend.h: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsFrontend.h - Diagnostic Definitions ---------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file 14 | /// This file defines diagnostics for the frontend. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_DIAGNOSTICSFRONTEND_H 19 | #define SWIFT_DIAGNOSTICSFRONTEND_H 20 | 21 | #include "swift/AST/DiagnosticsCommon.h" 22 | 23 | namespace swift { 24 | namespace diag { 25 | // Declare common diagnostics objects with their appropriate types. 26 | #define DIAG(KIND,ID,Options,Text,Signature) \ 27 | extern detail::DiagWithArguments::type ID; 28 | #include "DiagnosticsFrontend.def" 29 | } 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/ObjCSelectorFamily.def: -------------------------------------------------------------------------------- 1 | //===--- ObjCSelectorFamily.def - Objective-C Selector Families - C++ ---*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines macros used for macro-metaprogramming with Objective-C 14 | // selector families, categories of Objective-C methods with special ARC 15 | // semantics. 16 | // 17 | //===----------------------------------------------------------------------===// 18 | 19 | #ifndef OBJC_SELECTOR_FAMILY 20 | #define OBJC_SELECTOR_FAMILY(LABEL, PREFIX) 21 | #endif 22 | 23 | OBJC_SELECTOR_FAMILY(Alloc, "alloc") 24 | OBJC_SELECTOR_FAMILY(Copy, "copy") 25 | OBJC_SELECTOR_FAMILY(Init, "init") 26 | OBJC_SELECTOR_FAMILY(MutableCopy, "mutableCopy") 27 | OBJC_SELECTOR_FAMILY(New, "new") 28 | 29 | #undef OBJC_SELECTOR_FAMILY 30 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsRefactoring.h: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsRefactoring.h - Diagnostic Definitions -----*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file 14 | /// This file defines diagnostics for refactoring. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_DIAGNOSTICSREFACTORING_H 19 | #define SWIFT_DIAGNOSTICSREFACTORING_H 20 | 21 | #include "swift/AST/DiagnosticsCommon.h" 22 | 23 | namespace swift { 24 | namespace diag { 25 | // Declare common diagnostics objects with their appropriate types. 26 | #define DIAG(KIND,ID,Options,Text,Signature) \ 27 | extern detail::DiagWithArguments::type ID; 28 | #include "DiagnosticsRefactoring.def" 29 | } 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsClangImporter.h: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsClangImporter.h - Diagnostic Definitions ----*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file 14 | /// This file defines diagnostics for the Clang importer. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_DIAGNOSTICSCLANGIMPORTER_H 19 | #define SWIFT_DIAGNOSTICSCLANGIMPORTER_H 20 | 21 | #include "swift/AST/DiagnosticsCommon.h" 22 | 23 | namespace swift { 24 | namespace diag { 25 | // Declare common diagnostics objects with their appropriate types. 26 | #define DIAG(KIND,ID,Options,Text,Signature) \ 27 | extern detail::DiagWithArguments::type ID; 28 | #include "DiagnosticsClangImporter.def" 29 | } 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsModuleDiffer.h: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsModuleDiffer.h - Diagnostic Definitions ----*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file 14 | /// This file defines diagnostics for the Swift module differ. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_DIAGNOSTICS_MODULE_DIFFER_H 19 | #define SWIFT_DIAGNOSTICS_MODULE_DIFFER_H 20 | 21 | #include "swift/AST/DiagnosticsCommon.h" 22 | 23 | namespace swift { 24 | namespace diag { 25 | // Declare common diagnostics objects with their appropriate types. 26 | #define DIAG(KIND,ID,Options,Text,Signature) \ 27 | extern detail::DiagWithArguments::type ID; 28 | #include "DiagnosticsModuleDiffer.def" 29 | } 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/AccessTypeIDZone.def: -------------------------------------------------------------------------------- 1 | //===--- AccessTypeIDZone.def -----------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This definition file describes the types in the access-control 14 | // TypeID zone, for use with the TypeID template. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | SWIFT_REQUEST(AccessControl, AccessLevelRequest, AccessLevel(ValueDecl *), 19 | SeparatelyCached, NoLocationInfo) 20 | SWIFT_REQUEST(AccessControl, DefaultAndMaxAccessLevelRequest, 21 | DefaultAndMax(ExtensionDecl *), SeparatelyCached, NoLocationInfo) 22 | SWIFT_REQUEST(AccessControl, SetterAccessLevelRequest, 23 | AccessLevel(AbstractStorageDecl *), SeparatelyCached, 24 | NoLocationInfo) 25 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/TBDGenTypeIDZone.def: -------------------------------------------------------------------------------- 1 | //===--- TBDGenTypeIDZone.def -----------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2020 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This definition file describes the requests in TBDGen's zone. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | SWIFT_REQUEST(TBDGen, GenerateTBDRequest, TBDFile(TBDGenDescriptor), 18 | Uncached, NoLocationInfo) 19 | SWIFT_REQUEST(TBDGen, PublicSymbolsRequest, 20 | std::vector(TBDGenDescriptor), 21 | Uncached, NoLocationInfo) 22 | SWIFT_REQUEST(TBDGen, SymbolSourceMapRequest, 23 | SymbolSourceMap(TBDGenDescriptor), 24 | Cached, NoLocationInfo) 25 | SWIFT_REQUEST(TBDGen, APIGenRequest, apigen::API(TBDGenDescriptor), Uncached, 26 | NoLocationInfo) 27 | -------------------------------------------------------------------------------- /src/MachOStream.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef ICDUMP_MACHO_STREAM_H_ 17 | #define ICDUMP_MACHO_STREAM_H_ 18 | #include 19 | 20 | namespace LIEF::MachO { 21 | class Binary; 22 | } 23 | 24 | namespace iCDump { 25 | class MachOStream : public LIEF::BinaryStream { 26 | public: 27 | MachOStream(const LIEF::MachO::Binary& bin); 28 | uint64_t size() const override; 29 | 30 | LIEF::result read_at(uint64_t offset, uint64_t size) const override; 31 | 32 | inline const LIEF::MachO::Binary& bin() const { 33 | return *binary_; 34 | } 35 | 36 | private: 37 | const LIEF::MachO::Binary* binary_ = nullptr; 38 | }; 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsDriver.h: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsDriver.h - Diagnostic Definitions -----------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file 14 | /// This file defines diagnostics for the driver. 15 | /// \note Diagnostics shared between the driver and frontend are defined in 16 | /// \ref DiagnosticsFrontend.h. 17 | // 18 | //===----------------------------------------------------------------------===// 19 | 20 | #ifndef SWIFT_DIAGNOSTICSDRIVER_H 21 | #define SWIFT_DIAGNOSTICSDRIVER_H 22 | 23 | #include "swift/AST/DiagnosticsCommon.h" 24 | 25 | namespace swift { 26 | namespace diag { 27 | // Declare common diagnostics objects with their appropriate types. 28 | #define DIAG(KIND,ID,Options,Text,Signature) \ 29 | extern detail::DiagWithArguments::type ID; 30 | #include "DiagnosticsDriver.def" 31 | } 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/ForeignInfo.h: -------------------------------------------------------------------------------- 1 | //===--- ForeignInfo.h - Declaration import information ---------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines the ForeignInfo structure, which includes 14 | // structural information about how a foreign API's physical type 15 | // maps into the Swift type system. 16 | // 17 | //===----------------------------------------------------------------------===// 18 | 19 | #ifndef SWIFT_FOREIGN_INFO_H 20 | #define SWIFT_FOREIGN_INFO_H 21 | 22 | #include "swift/AST/ForeignAsyncConvention.h" 23 | #include "swift/AST/ForeignErrorConvention.h" 24 | #include "swift/AST/Decl.h" 25 | 26 | namespace swift { 27 | 28 | struct ForeignInfo { 29 | ImportAsMemberStatus self; 30 | Optional error; 31 | Optional async; 32 | }; 33 | 34 | } // end namespace swift 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsParse.h: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsParse.h - Diagnostic Definitions ------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file 14 | /// This file defines diagnostics for lexing and parsing. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_DIAGNOSTICSPARSE_H 19 | #define SWIFT_DIAGNOSTICSPARSE_H 20 | 21 | #include "swift/AST/DiagnosticsCommon.h" 22 | 23 | namespace swift { 24 | namespace diag { 25 | // Declare common diagnostics objects with their appropriate types. 26 | #define DIAG(KIND,ID,Options,Text,Signature) \ 27 | extern detail::DiagWithArguments::type ID; 28 | #define FIXIT(ID,Text,Signature) \ 29 | extern detail::StructuredFixItWithArguments::type ID; 30 | #include "DiagnosticsParse.def" 31 | } 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/OptimizationMode.h: -------------------------------------------------------------------------------- 1 | //===-------- OptimizationMode.h - Swift optimization modes -----*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_OPTIMIZATIONMODE_H 14 | #define SWIFT_BASIC_OPTIMIZATIONMODE_H 15 | 16 | #include "swift/Basic/InlineBitfield.h" 17 | #include "llvm/Support/DataTypes.h" 18 | 19 | namespace swift { 20 | 21 | // The optimization mode specified on the command line or with function 22 | // attributes. 23 | enum class OptimizationMode : uint8_t { 24 | NotSet = 0, 25 | NoOptimization = 1, // -Onone 26 | ForSpeed = 2, // -Ospeed == -O 27 | ForSize = 3, // -Osize 28 | LastMode = ForSize 29 | }; 30 | 31 | enum : unsigned { NumOptimizationModeBits = 32 | countBitsUsed(static_cast(OptimizationMode::LastMode)) }; 33 | 34 | } // end namespace swift 35 | 36 | #endif // SWIFT_BASIC_OPTIMIZATIONMODE_H 37 | -------------------------------------------------------------------------------- /include/iCDump/ObjC/Property.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef ICDUMP_OBJC_PROPERTY_H_ 16 | #define ICDUMP_OBJC_PROPERTY_H_ 17 | #include 18 | #include 19 | 20 | namespace iCDump::ObjC { 21 | class Parser; 22 | 23 | class Property { 24 | public: 25 | friend class Parser; 26 | 27 | Property() = default; 28 | static std::unique_ptr create(Parser& parser); 29 | 30 | inline const std::string& name() const { 31 | return name_; 32 | } 33 | 34 | inline const std::string& attribute() const { 35 | return attributes_; 36 | } 37 | 38 | std::string to_string() const; 39 | std::string to_decl() const; 40 | 41 | private: 42 | std::string name_; 43 | std::string attributes_; 44 | }; 45 | 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/Dwarf.h: -------------------------------------------------------------------------------- 1 | //===--- Dwarf.h - DWARF constants ------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines several temporary Swift-specific DWARF constants. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | #ifndef SWIFT_BASIC_DWARF_H 18 | #define SWIFT_BASIC_DWARF_H 19 | 20 | #include "llvm/BinaryFormat/Dwarf.h" 21 | 22 | namespace swift { 23 | /// The DWARF version emitted by the Swift compiler. 24 | const unsigned DWARFVersion = 4; 25 | 26 | static const char MachOASTSegmentName[] = "__DWARF"; 27 | static const char MachOASTSectionName[] = "__swift_ast"; 28 | static const char ELFASTSectionName[] = ".swift_ast"; 29 | static const char COFFASTSectionName[] = "swiftast"; 30 | static const char WasmASTSectionName[] = ".swift_ast"; 31 | } // end namespace swift 32 | 33 | #endif // SWIFT_BASIC_DWARF_H 34 | -------------------------------------------------------------------------------- /bindings/python/description.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | This project aims at providing a cross-platform utility to dump Objective-C and Swift metadata 5 | from 64-bits Mach-O binaries. 6 | 7 | Getting Started 8 | =============== 9 | 10 | .. code-block:: python 11 | 12 | import icdump 13 | metadata = icdump.objc.parse("./RNCryptor.bin") 14 | 15 | # Iterate over all the Objective-C interfaces (classes) 16 | for cls in metadata.classes: 17 | print(cls.demangled_name) 18 | 19 | .. code-block:: console 20 | 21 | PodsDummy_RNCryptor_iOS 22 | RNCryptor.RNCryptor.Encryptor 23 | RNCryptor.RNCryptor.Decryptor 24 | RNCryptor.RNCryptor.FormatV3 25 | RNCryptor.RNCryptor.EncryptorV3 26 | RNCryptor.RNCryptor.DecryptorV3 27 | RNCryptor.Engine 28 | RNCryptor.(DecryptorEngineV3 in _FFCD8353248C1C3EE416689E2680CC5C) 29 | RNCryptor.(HMACV3 in _FFCD8353248C1C3EE416689E2680CC5C) 30 | RNCryptor.OverflowingBuffer 31 | 32 | .. code-block:: python 33 | 34 | # Dump the metadata as a header declaration 35 | print(metadata.to_decl()) 36 | 37 | .. code-block:: console 38 | 39 | @interface RNCryptor.RNCryptor.Encryptor{ 40 | NSObject * encryptor; 41 | } 42 | @end 43 | @interface RNCryptor.RNCryptor.Decryptor{ 44 | NSObject * decryptors; 45 | NSObject * buffer; 46 | NSObject * decryptor; 47 | NSObject * password; 48 | } 49 | @end 50 | ... 51 | -------------------------------------------------------------------------------- /include/iCDump/ObjC/IVar.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef ICDUMP_IVAR_H_ 16 | #define ICDUMP_IVAR_H_ 17 | #include 18 | #include 19 | 20 | namespace iCDump::ObjC { 21 | class Parser; 22 | struct Type; 23 | 24 | class IVar { 25 | public: 26 | friend class Parser; 27 | 28 | IVar() = default; 29 | static std::unique_ptr create(Parser& parser); 30 | 31 | inline const std::string& name() const { 32 | return name_; 33 | } 34 | 35 | inline const std::string& mangled_type() const { 36 | return mangled_type_; 37 | } 38 | 39 | std::unique_ptr type() const; 40 | 41 | std::string to_string() const; 42 | std::string to_decl() const; 43 | 44 | private: 45 | std::string name_; 46 | std::string mangled_type_; 47 | }; 48 | 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/ParseTypeIDZone.def: -------------------------------------------------------------------------------- 1 | //===--- ParseTypeIDZone.def ------------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This definition file describes the requests in the parser's zone. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | SWIFT_REQUEST(Parse, CodeCompletionSecondPassRequest, 18 | bool (SourceFile *, CodeCompletionCallbacksFactory *), 19 | Uncached, NoLocationInfo) 20 | SWIFT_REQUEST(Parse, ParseMembersRequest, 21 | FingerprintAndMembers(IterableDeclContext *), Cached, NoLocationInfo) 22 | SWIFT_REQUEST(Parse, ParseAbstractFunctionBodyRequest, 23 | BraceStmt *(AbstractFunctionDecl *), SeparatelyCached, 24 | NoLocationInfo) 25 | SWIFT_REQUEST(Parse, ParseSourceFileRequest, 26 | SourceFileParsingResult(SourceFile *), SeparatelyCached, 27 | NoLocationInfo) 28 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/TargetInfo.h: -------------------------------------------------------------------------------- 1 | //===--- TargetInfo.h - Target Info Output ---------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file provides a high-level API for emitting target info 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | #ifndef SWIFT_TARGETINFO_H 18 | #define SWIFT_TARGETINFO_H 19 | 20 | #include "swift/Basic/LLVM.h" 21 | 22 | namespace llvm { 23 | class Triple; 24 | class VersionTuple; 25 | } 26 | 27 | namespace swift { 28 | class CompilerInvocation; 29 | 30 | namespace targetinfo { 31 | void printTargetInfo(const CompilerInvocation &invocation, 32 | llvm::raw_ostream &out); 33 | 34 | void printTripleInfo(const llvm::Triple &triple, 35 | llvm::Optional runtimeVersion, 36 | llvm::raw_ostream &out); 37 | } // namespace targetinfo 38 | } // namespace swift 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsAll.def: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsAll.def - Diagnostics Text Index ------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file imports all the other diagnostic files. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | #define DEFINE_DIAGNOSTIC_MACROS 18 | #include "DefineDiagnosticMacros.h" 19 | 20 | #define DIAG_NO_UNDEF 21 | 22 | #include "DiagnosticsCommon.def" 23 | #include "DiagnosticsIDE.def" 24 | #include "DiagnosticsParse.def" 25 | #include "DiagnosticsSema.def" 26 | #include "DiagnosticsClangImporter.def" 27 | #include "DiagnosticsSIL.def" 28 | #include "DiagnosticsIRGen.def" 29 | #include "DiagnosticsFrontend.def" 30 | #include "DiagnosticsDriver.def" 31 | #include "DiagnosticsRefactoring.def" 32 | #include "DiagnosticsModuleDiffer.def" 33 | 34 | #undef DIAG_NO_UNDEF 35 | 36 | #define UNDEFINE_DIAGNOSTIC_MACROS 37 | #include "DefineDiagnosticMacros.h" 38 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/FunctionBodySkipping.h: -------------------------------------------------------------------------------- 1 | //===------------------- FunctionBodySkipping.h -----------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_FUNCTIONBODYSKIPPING_H 14 | #define SWIFT_BASIC_FUNCTIONBODYSKIPPING_H 15 | 16 | #include "llvm/Support/DataTypes.h" 17 | 18 | namespace swift { 19 | 20 | /// Describes the function bodies that can be skipped in type-checking. 21 | enum class FunctionBodySkipping : uint8_t { 22 | /// Do not skip type-checking for any function bodies. 23 | None, 24 | /// Only non-inlinable function bodies should be skipped. 25 | NonInlinable, 26 | /// Only non-inlinable functions bodies without type definitions should 27 | /// be skipped. 28 | NonInlinableWithoutTypes, 29 | /// All function bodies should be skipped, where not otherwise required 30 | /// for type inference. 31 | All 32 | }; 33 | 34 | } // end namespace swift 35 | 36 | #endif // SWIFT_BASIC_FUNCTIONBODYSKIPPING_H 37 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/TypeIDZones.def: -------------------------------------------------------------------------------- 1 | //===--- TypeIDZones.def - List of TypeID Zones -----------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This definition file describes the zones for TypeID. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | SWIFT_TYPEID_ZONE(C, 0) 18 | SWIFT_TYPEID_ZONE(AST, 1) 19 | 20 | SWIFT_TYPEID_ZONE(Parse, 8) 21 | SWIFT_TYPEID_ZONE(NameLookup, 9) 22 | 23 | SWIFT_TYPEID_ZONE(TypeChecker, 10) 24 | SWIFT_TYPEID_ZONE(AccessControl, 11) 25 | SWIFT_TYPEID_ZONE(SILGen, 12) 26 | SWIFT_TYPEID_ZONE(SILOptimizer, 13) 27 | SWIFT_TYPEID_ZONE(TBDGen, 14) 28 | 29 | SWIFT_TYPEID_ZONE(IRGen, 20) 30 | 31 | SWIFT_TYPEID_ZONE(IDETypeChecking, 97) 32 | 33 | SWIFT_TYPEID_ZONE(IDETypes, 136) 34 | SWIFT_TYPEID_ZONE(IDE, 137) 35 | 36 | SWIFT_TYPEID_ZONE(ClangImporter, 139) 37 | 38 | // N.B. This is not a formal zone and exists solely to support the unit tests. 39 | SWIFT_TYPEID_ZONE(ArithmeticEvaluator, 255) 40 | -------------------------------------------------------------------------------- /src/log_public.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #include "iCDump/Logging.hpp" 16 | #include "log.hpp" 17 | 18 | namespace iCDump { 19 | void disable_log() { 20 | Logger::disable(); 21 | } 22 | 23 | void enable_log() { 24 | Logger::enable(); 25 | } 26 | 27 | void set_log_level(LOG_LEVEL lvl) { 28 | switch (lvl) { 29 | case LOG_LEVEL::TRACE: Logger::set_level(Logger::LEVEL::TRACE); break; 30 | case LOG_LEVEL::DEBUG: Logger::set_level(Logger::LEVEL::DEBUG); break; 31 | case LOG_LEVEL::INFO: Logger::set_level(Logger::LEVEL::INFO); break; 32 | case LOG_LEVEL::WARN: Logger::set_level(Logger::LEVEL::WARN); break; 33 | case LOG_LEVEL::ERR: Logger::set_level(Logger::LEVEL::ERR); break; 34 | case LOG_LEVEL::CRITICAL: Logger::set_level(Logger::LEVEL::CRITICAL); break; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Demangling/NamespaceMacros.h: -------------------------------------------------------------------------------- 1 | //===--- NamespaceMacros.h - Macros for inline namespaces -------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // Macros that conditionally define an inline namespace so that symbols used in 14 | // multiple places (such as in the compiler and in the runtime library) can be 15 | // given distinct mangled names in different contexts without affecting client 16 | // usage in source. 17 | // 18 | //===----------------------------------------------------------------------===// 19 | 20 | #ifndef SWIFT_DEMANGLING_NAMESPACE_MACROS_H 21 | #define SWIFT_DEMANGLING_NAMESPACE_MACROS_H 22 | 23 | #if defined(__cplusplus) 24 | 25 | #if defined(SWIFT_INLINE_NAMESPACE) 26 | #define SWIFT_BEGIN_INLINE_NAMESPACE inline namespace SWIFT_INLINE_NAMESPACE { 27 | #define SWIFT_END_INLINE_NAMESPACE } 28 | #else 29 | #define SWIFT_BEGIN_INLINE_NAMESPACE 30 | #define SWIFT_END_INLINE_NAMESPACE 31 | #endif 32 | 33 | #endif 34 | 35 | #endif // SWIFT_DEMANGLING_NAMESPACE_MACROS_H 36 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/KnownFoundationEntities.def: -------------------------------------------------------------------------------- 1 | //===--- KnownFoundationEntities.def - Objective-C Foundation ---*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines macros used for macro-metaprogramming with 14 | // compiler-known entities in the Objective-C Foundation module (and 15 | // the ObjectiveC module it depends on). 16 | // 17 | //===----------------------------------------------------------------------===// 18 | #ifndef FOUNDATION_ENTITY 19 | # error define FOUNDATION_ENTITY(Name) 20 | #endif 21 | 22 | FOUNDATION_ENTITY(NSArray) 23 | FOUNDATION_ENTITY(NSDictionary) 24 | FOUNDATION_ENTITY(NSError) 25 | FOUNDATION_ENTITY(NSErrorPointer) 26 | FOUNDATION_ENTITY(NSInteger) 27 | FOUNDATION_ENTITY(NSNumber) 28 | FOUNDATION_ENTITY(NSObject) 29 | FOUNDATION_ENTITY(NSRange) 30 | FOUNDATION_ENTITY(NSSet) 31 | FOUNDATION_ENTITY(NSString) 32 | FOUNDATION_ENTITY(NSUInteger) 33 | FOUNDATION_ENTITY(NSURL) 34 | FOUNDATION_ENTITY(NSValue) 35 | FOUNDATION_ENTITY(NSZone) 36 | 37 | #undef FOUNDATION_ENTITY 38 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/TypeWalker.h: -------------------------------------------------------------------------------- 1 | //===--- TypeWalker.h - Class for walking a Type ----------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_AST_TYPEWALKER_H 14 | #define SWIFT_AST_TYPEWALKER_H 15 | 16 | #include "swift/AST/Type.h" 17 | 18 | namespace swift { 19 | 20 | /// An abstract class used to traverse a Type. 21 | class TypeWalker { 22 | public: 23 | enum class Action { 24 | Continue, 25 | SkipChildren, 26 | Stop 27 | }; 28 | 29 | /// This method is called when first visiting a type before walking into its 30 | /// children. 31 | virtual Action walkToTypePre(Type ty) { return Action::Continue; } 32 | 33 | /// This method is called after visiting a type's children. 34 | virtual Action walkToTypePost(Type ty) { return Action::Continue; } 35 | 36 | protected: 37 | TypeWalker() = default; 38 | TypeWalker(const TypeWalker &) = default; 39 | virtual ~TypeWalker() = default; 40 | 41 | virtual void anchor(); 42 | }; 43 | 44 | } // end namespace swift 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /bindings/python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(FetchContent) 2 | find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) 3 | 4 | FetchContent_Declare( 5 | nanobind 6 | GIT_REPOSITORY https://github.com/wjakob/nanobind.git 7 | GIT_TAG a7d8dc08657ada946e174b849686dc969376ffc6 8 | ) 9 | FetchContent_GetProperties(nanobind) 10 | if(NOT nanobind_POPULATED) 11 | FetchContent_Populate(nanobind) 12 | add_subdirectory(${nanobind_SOURCE_DIR} ${nanobind_BINARY_DIR} 13 | EXCLUDE_FROM_ALL) 14 | endif() 15 | 16 | 17 | 18 | nanobind_add_module( 19 | iCDump 20 | NB_STATIC 21 | ) 22 | 23 | include(${CMAKE_CURRENT_SOURCE_DIR}/src/CMakeLists.txt) 24 | 25 | 26 | target_include_directories(iCDump 27 | PUBLIC 28 | ${CMAKE_CURRENT_SOURCE_DIR}/src 29 | ) 30 | 31 | target_link_libraries(iCDump PRIVATE LIB_ICDUMP) 32 | 33 | set(_PY_ICDUMP_SUFFIX ) 34 | 35 | if(UNIX) 36 | set(_PY_ICDUMP_SUFFIX ".so") 37 | elseif(WIN32) 38 | set(_PY_ICDUMP_SUFFIX ".pyd") 39 | else() 40 | message(FATAL_ERROR "Platform unknown") 41 | endif() 42 | 43 | set_target_properties(iCDump PROPERTIES 44 | CXX_STANDARD 17 45 | CXX_VISIBILITY_PRESET hidden 46 | C_VISIBILITY_PRESET hidden 47 | POSITION_INDEPENDENT_CODE ON 48 | OUTPUT_NAME "icdump" 49 | PREFIX "" 50 | SUFFIX ${_PY_ICDUMP_SUFFIX} 51 | ) 52 | 53 | target_compile_options(iCDump PRIVATE 54 | -fdata-sections -ffunction-sections 55 | -fvisibility-inlines-hidden 56 | ) 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/ClangSwiftTypeCorrespondence.h: -------------------------------------------------------------------------------- 1 | //=- ClangSwiftTypeCorrespondence.h - Relations between Clang & Swift types -=// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2019 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file describes some common relations between Clang types and Swift 14 | // types that are need by the ClangTypeConverter and parts of ClangImporter. 15 | // 16 | // Since ClangTypeConverter is an implementation detail, ClangImporter should 17 | // not depend on ClangTypeConverter.h. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | 21 | #ifndef SWIFT_AST_CLANG_SWIFT_TYPE_CORRESPONDENCE_H 22 | #define SWIFT_AST_CLANG_SWIFT_TYPE_CORRESPONDENCE_H 23 | 24 | namespace clang { 25 | class Type; 26 | } 27 | 28 | namespace swift { 29 | /// Checks whether a Clang type can be imported as a Swift Optional type. 30 | /// 31 | /// For example, a `const uint8_t *` could be imported as 32 | /// `Optional>`. 33 | bool canImportAsOptional(const clang::Type *type); 34 | } 35 | 36 | #endif /* SWIFT_AST_CLANG_SWIFT_TYPE_CORRESPONDENCE_H */ 37 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/Unreachable.h: -------------------------------------------------------------------------------- 1 | //===--- Unreachable.h - Implements swift_unreachable ---*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines swift_unreachable, which provides the 14 | // functionality of llvm_unreachable without necessarily depending on 15 | // the LLVM support libraries. 16 | // 17 | //===----------------------------------------------------------------------===// 18 | 19 | #ifndef SWIFT_BASIC_UNREACHABLE_H 20 | #define SWIFT_BASIC_UNREACHABLE_H 21 | 22 | #ifdef SWIFT_LLVM_SUPPORT_IS_AVAILABLE 23 | 24 | // The implementation when LLVM is available. 25 | 26 | #include "llvm/Support/ErrorHandling.h" 27 | #define swift_unreachable llvm_unreachable 28 | 29 | #else 30 | 31 | // The implementation when LLVM is not available. 32 | 33 | #include 34 | #include 35 | 36 | #include "swift/Runtime/Config.h" 37 | 38 | SWIFT_RUNTIME_ATTRIBUTE_NORETURN 39 | inline static void swift_unreachable(const char *msg) { 40 | assert(false && msg); 41 | (void)msg; 42 | abort(); 43 | } 44 | 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsSema.h: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsSema.h - Diagnostic Definitions -------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file 14 | /// This file defines diagnostics for semantic analysis. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_DIAGNOSTICSSEMA_H 19 | #define SWIFT_DIAGNOSTICSSEMA_H 20 | 21 | #include "swift/AST/DiagnosticsCommon.h" 22 | 23 | namespace swift { 24 | class SwitchStmt; 25 | namespace diag { 26 | 27 | /// Describes the kind of requirement in a protocol. 28 | enum class RequirementKind : uint8_t { 29 | Constructor, 30 | Func, 31 | Var, 32 | Subscript 33 | }; 34 | 35 | // Declare common diagnostics objects with their appropriate types. 36 | #define DIAG(KIND,ID,Options,Text,Signature) \ 37 | extern detail::DiagWithArguments::type ID; 38 | #define FIXIT(ID,Text,Signature) \ 39 | extern detail::StructuredFixItWithArguments::type ID; 40 | #include "DiagnosticsSema.def" 41 | } 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/TypeResolutionStage.h: -------------------------------------------------------------------------------- 1 | //===--- TypeResolutionStage.h - Type Resolution Stage ----------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | #ifndef SWIFT_AST_TYPE_RESOLUTION_STAGE_H 13 | #define SWIFT_AST_TYPE_RESOLUTION_STAGE_H 14 | 15 | namespace llvm { 16 | class raw_ostream; 17 | } 18 | 19 | namespace swift { 20 | 21 | /// Describes the stage at which a particular type should be computed. 22 | /// 23 | /// Later stages compute more information about the type, requiring more 24 | /// complete analysis. 25 | enum class TypeResolutionStage : uint8_t { 26 | /// Produces an interface type describing its structure, but without 27 | /// performing semantic analysis to resolve (e.g.) references to members of 28 | /// type parameters. 29 | Structural, 30 | 31 | /// Produces a complete interface type where all member references have been 32 | /// resolved. 33 | Interface, 34 | }; 35 | 36 | /// Display a type resolution stage. 37 | void simple_display(llvm::raw_ostream &out, const TypeResolutionStage &value); 38 | 39 | } // end namespace swift 40 | 41 | #endif // SWIFT_AST_TYPE_RESOLUTION_STAGE_H 42 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/ProfileCounter.h: -------------------------------------------------------------------------------- 1 | //===------------ ProfileCounter.h - PGO Propfile counter -------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file Declares ProfileCounter, a convenient type for PGO 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | #ifndef SWIFT_BASIC_PROFILECOUNTER_H 18 | #define SWIFT_BASIC_PROFILECOUNTER_H 19 | 20 | #include 21 | #include 22 | 23 | namespace swift { 24 | /// A class designed to be smaller than using Optional for PGO 25 | class ProfileCounter { 26 | private: 27 | uint64_t count; 28 | 29 | public: 30 | explicit ProfileCounter() : count(UINT64_MAX) {} 31 | ProfileCounter(uint64_t Count) : count(Count) { 32 | if (Count == UINT64_MAX) { 33 | count = UINT64_MAX - 1; 34 | } 35 | } 36 | 37 | bool hasValue() const { return count != UINT64_MAX; } 38 | uint64_t getValue() const { 39 | assert(hasValue()); 40 | return count; 41 | } 42 | explicit operator bool() const { return hasValue(); } 43 | }; 44 | } // end namespace swift 45 | 46 | #endif // SWIFT_BASIC_PROFILECOUNTER_H 47 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/ColorUtils.h: -------------------------------------------------------------------------------- 1 | //===--- ColorUtils.h - -----------------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines an 'OSColor' class for helping printing colorful outputs 14 | // to the terminal. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_BASIC_COLORUTILS_H 19 | #define SWIFT_BASIC_COLORUTILS_H 20 | 21 | #include "llvm/Support/raw_ostream.h" 22 | 23 | namespace swift { 24 | 25 | /// RAII class for setting a color for a raw_ostream and resetting when it goes 26 | /// out-of-scope. 27 | class OSColor { 28 | llvm::raw_ostream &OS; 29 | bool HasColors; 30 | public: 31 | OSColor(llvm::raw_ostream &OS, llvm::raw_ostream::Colors Color) : OS(OS) { 32 | HasColors = OS.has_colors(); 33 | if (HasColors) 34 | OS.changeColor(Color); 35 | } 36 | ~OSColor() { 37 | if (HasColors) 38 | OS.resetColor(); 39 | } 40 | 41 | OSColor &operator<<(char C) { OS << C; return *this; } 42 | OSColor &operator<<(llvm::StringRef Str) { OS << Str; return *this; } 43 | }; 44 | 45 | } // namespace swift 46 | 47 | #endif // SWIFT_BASIC_COLORUTILS_H 48 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticSuppression.h: -------------------------------------------------------------------------------- 1 | //===--- InstrumenterSupport.cpp - Instrumenter Support -------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file implements the supporting functions for writing instrumenters of 14 | // the Swift AST. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_AST_DIAGNOSTIC_SUPPRESSION_H 19 | #define SWIFT_AST_DIAGNOSTIC_SUPPRESSION_H 20 | 21 | #include 22 | 23 | namespace swift { 24 | 25 | class DiagnosticConsumer; 26 | class DiagnosticEngine; 27 | 28 | /// RAII class that suppresses diagnostics by temporarily disabling all of 29 | /// the diagnostic consumers. 30 | class DiagnosticSuppression { 31 | DiagnosticEngine &diags; 32 | std::vector consumers; 33 | 34 | DiagnosticSuppression(const DiagnosticSuppression &) = delete; 35 | DiagnosticSuppression &operator=(const DiagnosticSuppression &) = delete; 36 | 37 | public: 38 | explicit DiagnosticSuppression(DiagnosticEngine &diags); 39 | ~DiagnosticSuppression(); 40 | static bool isEnabled(const DiagnosticEngine &diags); 41 | }; 42 | 43 | } 44 | #endif // SWIFT_AST_DIAGNOSTIC_SUPPRESSION_H 45 | -------------------------------------------------------------------------------- /src/ObjC/Metadata.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #include "iCDump/ObjC/Metadata.hpp" 16 | #include "iCDump/ObjC/Class.hpp" 17 | #include "iCDump/ObjC/Protocol.hpp" 18 | 19 | namespace iCDump::ObjC { 20 | const Class* Metadata::get_class(const std::string& name) const { 21 | if (auto it = classes_lookup_.find(name); it != std::end(classes_lookup_)) { 22 | return it->second; 23 | } 24 | return nullptr; 25 | } 26 | 27 | const Protocol* Metadata::get_protocol(const std::string& name) const { 28 | if (auto it = protocol_lookup_.find(name); it != std::end(protocol_lookup_)) { 29 | return it->second; 30 | } 31 | return nullptr; 32 | } 33 | 34 | std::string Metadata::to_decl() const { 35 | std::string out; 36 | 37 | // First declare the protocols 38 | for (const auto& protocol : protocols_) { 39 | out += protocol->to_decl(); 40 | } 41 | 42 | for (const auto& cls : classes_) { 43 | out += cls->to_decl(); 44 | } 45 | 46 | return out; 47 | } 48 | 49 | std::string Metadata::to_string() const { 50 | return ""; 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/Debug.h: -------------------------------------------------------------------------------- 1 | //===--- Debug.h - Compiler debugging helpers -------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | #ifndef SWIFT_BASIC_DEBUG_H 13 | #define SWIFT_BASIC_DEBUG_H 14 | 15 | #include "llvm/Support/Compiler.h" 16 | 17 | 18 | /// Adds attributes to the provided method signature indicating that it is a 19 | /// debugging helper that should never be called directly from compiler code. 20 | /// This deprecates the method so it won't be called directly and marks it as 21 | /// used so it won't be eliminated as dead code. 22 | #define SWIFT_DEBUG_HELPER(method) \ 23 | LLVM_ATTRIBUTE_DEPRECATED(method LLVM_ATTRIBUTE_USED, \ 24 | "only for use in the debugger") 25 | 26 | /// Declares a const void instance method with the name and parameters provided. 27 | /// Methods declared with this macro should never be called except in the 28 | /// debugger. 29 | #define SWIFT_DEBUG_DUMPER(nameAndParams) \ 30 | SWIFT_DEBUG_HELPER(void nameAndParams const) 31 | 32 | /// Declares an instance `void dump() const` method. Methods declared with this 33 | /// macro should never be called except in the debugger. 34 | #define SWIFT_DEBUG_DUMP \ 35 | SWIFT_DEBUG_DUMPER(dump()) 36 | 37 | #endif 38 | 39 | 40 | -------------------------------------------------------------------------------- /bindings/python/src/iterator.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef PY_ICDUMP_ITERATOR_H 16 | #define PY_ICDUMP_ITERATOR_H 17 | #include 18 | 19 | namespace nb = nanobind; 20 | 21 | template 22 | void init_iterator(nb::handle& m, const char* name) { 23 | nb::class_(m, name) 24 | .def("__getitem__", 25 | [] (T& self, size_t i) -> typename T::reference { 26 | if (i >= self.size()) { 27 | throw nb::index_error(); 28 | } 29 | return self[i]; 30 | }, nb::rv_policy::reference_internal) 31 | 32 | .def("__len__", 33 | [] (T& self) { 34 | return self.size(); 35 | }) 36 | 37 | .def("__iter__", 38 | [] (const T& self) { 39 | return std::begin(self); 40 | }, nb::rv_policy::move) 41 | 42 | .def("__next__", 43 | [] (T& self) -> typename T::reference { 44 | if (self == std::end(self)) { 45 | throw nb::stop_iteration(); 46 | } 47 | return *(self++); 48 | }, nb::rv_policy::reference_internal); 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/KnownProtocols.h: -------------------------------------------------------------------------------- 1 | //===--- KnownProtocols.h - Working with compiler protocols -----*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_AST_KNOWNPROTOCOLS_H 14 | #define SWIFT_AST_KNOWNPROTOCOLS_H 15 | 16 | #include "swift/Basic/InlineBitfield.h" 17 | #include "swift/Config.h" 18 | 19 | namespace llvm { 20 | class StringRef; 21 | } 22 | 23 | namespace swift { 24 | 25 | /// The set of known protocols. 26 | enum class KnownProtocolKind : uint8_t { 27 | #define PROTOCOL_WITH_NAME(Id, Name) Id, 28 | #include "swift/AST/KnownProtocols.def" 29 | }; 30 | 31 | enum : uint8_t { 32 | // This uses a preprocessor trick to count all the protocols. The enum value 33 | // expression below expands to "+1+1+1...". (Note that the first plus 34 | // is parsed as a unary operator.) 35 | #define PROTOCOL_WITH_NAME(Id, Name) +1 36 | /// The number of known protocols. 37 | NumKnownProtocols = 38 | #include "swift/AST/KnownProtocols.def" 39 | }; 40 | 41 | enum : unsigned { NumKnownProtocolKindBits = 42 | countBitsUsed(static_cast(NumKnownProtocols - 1)) }; 43 | 44 | /// Retrieve the name of the given known protocol. 45 | llvm::StringRef getProtocolName(KnownProtocolKind kind); 46 | 47 | } // end namespace swift 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/LLVMInitialize.h: -------------------------------------------------------------------------------- 1 | //===--- LLVMInitialize.h ---------------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // A file that declares macros for initializing all parts of LLVM that various 14 | // binaries in swift use. Please call PROGRAM_START in the main routine of all 15 | // binaries, and INITIALIZE_LLVM in anything that uses Clang or LLVM IR. 16 | // 17 | //===----------------------------------------------------------------------===// 18 | 19 | #ifndef SWIFT_BASIC_LLVMINITIALIZE_H 20 | #define SWIFT_BASIC_LLVMINITIALIZE_H 21 | 22 | #include "llvm/Support/InitLLVM.h" 23 | #include "llvm/Support/ManagedStatic.h" 24 | #include "llvm/Support/PrettyStackTrace.h" 25 | #include "llvm/Support/Signals.h" 26 | #include "llvm/Support/TargetSelect.h" 27 | 28 | #define PROGRAM_START(argc, argv) \ 29 | llvm::InitLLVM _INITIALIZE_LLVM(argc, argv) 30 | 31 | #define INITIALIZE_LLVM() \ 32 | do { \ 33 | llvm::InitializeAllTargets(); \ 34 | llvm::InitializeAllTargetMCs(); \ 35 | llvm::InitializeAllAsmPrinters(); \ 36 | llvm::InitializeAllAsmParsers(); \ 37 | llvm::InitializeAllDisassemblers(); \ 38 | llvm::InitializeAllTargetInfos(); \ 39 | } while (0) 40 | 41 | #endif // SWIFT_BASIC_LLVMINITIALIZE_H 42 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/QuotedString.h: -------------------------------------------------------------------------------- 1 | //===--- QuotedString.h - Print a string in double-quotes -------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file Declares QuotedString, a convenient type for printing a 14 | /// string as a string literal. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_BASIC_QUOTEDSTRING_H 19 | #define SWIFT_BASIC_QUOTEDSTRING_H 20 | 21 | #include "llvm/ADT/StringRef.h" 22 | 23 | namespace llvm { 24 | class raw_ostream; 25 | } 26 | 27 | namespace swift { 28 | /// Print the given string as if it were a quoted string. 29 | void printAsQuotedString(llvm::raw_ostream &out, llvm::StringRef text); 30 | 31 | /// A class designed to make it easy to write a string to a stream 32 | /// as a quoted string. 33 | class QuotedString { 34 | llvm::StringRef Text; 35 | public: 36 | explicit QuotedString(llvm::StringRef text) : Text(text) {} 37 | 38 | friend llvm::raw_ostream &operator<<(llvm::raw_ostream &out, 39 | QuotedString string) { 40 | printAsQuotedString(out, string.Text); 41 | return out; 42 | } 43 | }; 44 | } // end namespace swift 45 | 46 | #endif // SWIFT_BASIC_QUOTEDSTRING_H 47 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/LinkLibrary.h: -------------------------------------------------------------------------------- 1 | //===--- LinkLibrary.h - A module-level linker dependency -------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_AST_LINKLIBRARY_H 14 | #define SWIFT_AST_LINKLIBRARY_H 15 | 16 | #include "swift/Basic/LLVM.h" 17 | #include "llvm/ADT/StringRef.h" 18 | #include 19 | 20 | namespace swift { 21 | 22 | // Must be kept in sync with diag::error_immediate_mode_missing_library. 23 | enum class LibraryKind { 24 | Library = 0, 25 | Framework 26 | }; 27 | 28 | /// Represents a linker dependency for an imported module. 29 | // FIXME: This is basically a slightly more generic version of Clang's 30 | // Module::LinkLibrary. 31 | class LinkLibrary { 32 | private: 33 | std::string Name; 34 | unsigned Kind : 1; 35 | unsigned ForceLoad : 1; 36 | 37 | public: 38 | LinkLibrary(StringRef N, LibraryKind K, bool forceLoad = false) 39 | : Name(N), Kind(static_cast(K)), ForceLoad(forceLoad) { 40 | assert(getKind() == K && "not enough bits for the kind"); 41 | } 42 | 43 | LibraryKind getKind() const { return static_cast(Kind); } 44 | StringRef getName() const { return Name; } 45 | bool shouldForceLoad() const { return ForceLoad; } 46 | }; 47 | 48 | } // end namespace swift 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/Program.h: -------------------------------------------------------------------------------- 1 | //===--- Program.h ----------------------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_PROGRAM_H 14 | #define SWIFT_BASIC_PROGRAM_H 15 | 16 | namespace swift { 17 | 18 | /// This function executes the program using the arguments provided, 19 | /// preferring to reexecute the current process, if supported. 20 | /// 21 | /// \param Program Path of the program to be executed 22 | /// \param args A vector of strings that are passed to the program. The first 23 | /// element should be the name of the program. The list *must* be terminated by 24 | /// a null char * entry. 25 | /// \param env An optional vector of strings to use for the program's 26 | /// environment. If not provided, the current program's environment will be 27 | /// used. 28 | /// 29 | /// \returns Typically, this function will not return, as the current process 30 | /// will no longer exist, or it will call exit() if the program was successfully 31 | /// executed. In the event of an error, this function will return a negative 32 | /// value indicating a failure to execute. 33 | int ExecuteInPlace(const char *Program, const char **args, 34 | const char **env = nullptr); 35 | 36 | } // end namespace swift 37 | 38 | #endif // SWIFT_BASIC_PROGRAM_H 39 | -------------------------------------------------------------------------------- /src/iCDump.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #include "iCDump/iCDump.hpp" 16 | #include "iCDump/ObjC.hpp" 17 | #include "log.hpp" 18 | #include "MachOStream.hpp" 19 | 20 | #include "LIEF/MachO.hpp" 21 | 22 | using namespace LIEF::MachO; 23 | 24 | namespace iCDump { 25 | 26 | namespace ObjC { 27 | std::unique_ptr parse(const std::string& file_path, ARCH arch) { 28 | static const ParserConfig PARSER_CONFIG = { 29 | .parse_dyld_exports = true, .parse_dyld_bindings = true, .parse_dyld_rebases = false 30 | }; 31 | 32 | auto fat_bin = LIEF::MachO::Parser::parse(file_path, PARSER_CONFIG); 33 | if (!fat_bin || fat_bin->empty()) { 34 | ICDUMP_ERR("Can't parse {}", file_path); 35 | return nullptr; 36 | } 37 | // Look for the best architecture according to the arch parameter 38 | if (auto arm64_bin = fat_bin->take(CPU_TYPES::CPU_TYPE_ARM64)) { 39 | return ObjC::Parser::parse(*arm64_bin); 40 | } 41 | 42 | if (auto x86_64_bin = fat_bin->take(CPU_TYPES::CPU_TYPE_X86_64)) { 43 | return ObjC::Parser::parse(*x86_64_bin); 44 | } 45 | 46 | ICDUMP_ERR("Can't find a supported architecture"); 47 | return nullptr; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/FileSystem.h: -------------------------------------------------------------------------------- 1 | //===--- FileSystem.h - File helpers that interact with Diags ---*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_AST_FILESYSTEM_H 14 | #define SWIFT_AST_FILESYSTEM_H 15 | 16 | #include "swift/Basic/FileSystem.h" 17 | #include "swift/AST/DiagnosticEngine.h" 18 | #include "swift/AST/DiagnosticsCommon.h" 19 | 20 | namespace swift { 21 | 22 | /// A wrapper around swift::atomicallyWritingToFile that handles diagnosing any 23 | /// filesystem errors and asserts the output path is nonempty. 24 | /// 25 | /// \returns true if there were any errors, either from the filesystem 26 | /// operations or from \p action returning true. 27 | inline bool 28 | withOutputFile(DiagnosticEngine &diags, StringRef outputPath, 29 | llvm::function_ref action) { 30 | assert(!outputPath.empty()); 31 | 32 | bool actionFailed = false; 33 | std::error_code EC = swift::atomicallyWritingToFile( 34 | outputPath, 35 | [&](llvm::raw_pwrite_stream &out) { actionFailed = action(out); }); 36 | if (EC) { 37 | diags.diagnose(SourceLoc(), diag::error_opening_output, outputPath, 38 | EC.message()); 39 | return true; 40 | } 41 | return actionFailed; 42 | } 43 | } // end namespace swift 44 | 45 | #endif // SWIFT_AST_FILESYSTEM_H 46 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/ThreadSafeRefCounted.h: -------------------------------------------------------------------------------- 1 | //===--- ThreadSafeRefCounted.h - Thread-safe Refcounting Base --*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_THREADSAFEREFCOUNTED_H 14 | #define SWIFT_BASIC_THREADSAFEREFCOUNTED_H 15 | 16 | #include 17 | #include 18 | #include "llvm/ADT/IntrusiveRefCntPtr.h" 19 | 20 | namespace swift { 21 | 22 | /// A class that has the same function as \c ThreadSafeRefCountedBase, but with 23 | /// a virtual destructor. 24 | /// 25 | /// Should be used instead of \c ThreadSafeRefCountedBase for classes that 26 | /// already have virtual methods to enforce dynamic allocation via 'new'. 27 | /// FIXME: This should eventually move to llvm. 28 | class ThreadSafeRefCountedBaseVPTR { 29 | mutable std::atomic ref_cnt; 30 | virtual void anchor(); 31 | 32 | protected: 33 | ThreadSafeRefCountedBaseVPTR() : ref_cnt(0) {} 34 | virtual ~ThreadSafeRefCountedBaseVPTR() {} 35 | 36 | public: 37 | void Retain() const { 38 | ref_cnt += 1; 39 | } 40 | 41 | void Release() const { 42 | int refCount = static_cast(--ref_cnt); 43 | assert(refCount >= 0 && "Reference count was already zero."); 44 | if (refCount == 0) delete this; 45 | } 46 | }; 47 | 48 | } // end namespace swift 49 | 50 | #endif // SWIFT_BASIC_THREADSAFEREFCOUNTED_H 51 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/Defer.h: -------------------------------------------------------------------------------- 1 | //===--- Defer.h - 'defer' helper macro -------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines a 'SWIFT_DEFER' macro for performing a cleanup on any exit 14 | // out of a scope. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_BASIC_DEFER_H 19 | #define SWIFT_BASIC_DEFER_H 20 | 21 | #include "llvm/ADT/ScopeExit.h" 22 | 23 | namespace swift { 24 | namespace detail { 25 | struct DeferTask {}; 26 | template 27 | auto operator+(DeferTask, F &&fn) -> 28 | decltype(llvm::make_scope_exit(std::forward(fn))) { 29 | return llvm::make_scope_exit(std::forward(fn)); 30 | } 31 | } 32 | } // end namespace swift 33 | 34 | 35 | #define DEFER_CONCAT_IMPL(x, y) x##y 36 | #define DEFER_MACRO_CONCAT(x, y) DEFER_CONCAT_IMPL(x, y) 37 | 38 | /// This macro is used to register a function / lambda to be run on exit from a 39 | /// scope. Its typical use looks like: 40 | /// 41 | /// SWIFT_DEFER { 42 | /// stuff 43 | /// }; 44 | /// 45 | #define SWIFT_DEFER \ 46 | auto DEFER_MACRO_CONCAT(defer_func, __COUNTER__) = \ 47 | ::swift::detail::DeferTask() + [&]() 48 | 49 | #endif // SWIFT_BASIC_DEFER_H 50 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Demangling/ValueWitnessMangling.def: -------------------------------------------------------------------------------- 1 | //===-- ValueWitnessMangling.def - VW Mangling Metaprogramming --*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | /// VALUE_WITNESS(MANGLING, NAME) 14 | /// The 2-character MANGLING for a value witness NAME. 15 | 16 | VALUE_WITNESS(al, AllocateBuffer) 17 | VALUE_WITNESS(ca, AssignWithCopy) 18 | VALUE_WITNESS(ta, AssignWithTake) 19 | VALUE_WITNESS(de, DeallocateBuffer) 20 | VALUE_WITNESS(xx, Destroy) 21 | VALUE_WITNESS(XX, DestroyBuffer) 22 | VALUE_WITNESS(Xx, DestroyArray) 23 | VALUE_WITNESS(CP, InitializeBufferWithCopyOfBuffer) 24 | VALUE_WITNESS(Cp, InitializeBufferWithCopy) 25 | VALUE_WITNESS(cp, InitializeWithCopy) 26 | VALUE_WITNESS(Tk, InitializeBufferWithTake) 27 | VALUE_WITNESS(tk, InitializeWithTake) 28 | VALUE_WITNESS(pr, ProjectBuffer) 29 | VALUE_WITNESS(TK, InitializeBufferWithTakeOfBuffer) 30 | VALUE_WITNESS(Cc, InitializeArrayWithCopy) 31 | VALUE_WITNESS(Tt, InitializeArrayWithTakeFrontToBack) 32 | VALUE_WITNESS(tT, InitializeArrayWithTakeBackToFront) 33 | VALUE_WITNESS(xs, StoreExtraInhabitant) 34 | VALUE_WITNESS(xg, GetExtraInhabitantIndex) 35 | VALUE_WITNESS(ug, GetEnumTag) 36 | VALUE_WITNESS(up, DestructiveProjectEnumData) 37 | VALUE_WITNESS(ui, DestructiveInjectEnumTag) 38 | VALUE_WITNESS(et, GetEnumTagSinglePayload) 39 | VALUE_WITNESS(st, StoreEnumTagSinglePayload) 40 | 41 | #undef VALUE_WITNESS 42 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/IfConfigClause.h: -------------------------------------------------------------------------------- 1 | //===--- IfConfigClause.h ---------------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines the IfConfigClause. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | #ifndef SWIFT_AST_IFCONFIGCLAUSE_H 18 | #define SWIFT_AST_IFCONFIGCLAUSE_H 19 | 20 | #include "llvm/ADT/ArrayRef.h" 21 | 22 | namespace swift { 23 | class Expr; 24 | class SourceLoc; 25 | struct ASTNode; 26 | 27 | /// This represents one part of a #if block. If the condition field is 28 | /// non-null, then this represents a #if or a #elseif, otherwise it represents 29 | /// an #else block. 30 | struct IfConfigClause { 31 | /// The location of the #if, #elseif, or #else keyword. 32 | SourceLoc Loc; 33 | 34 | /// The condition guarding this #if or #elseif block. If this is null, this 35 | /// is a #else clause. 36 | Expr *Cond; 37 | 38 | /// Elements inside the clause 39 | ArrayRef Elements; 40 | 41 | /// True if this is the active clause of the #if block. 42 | const bool isActive; 43 | 44 | IfConfigClause(SourceLoc Loc, Expr *Cond, 45 | ArrayRef Elements, bool isActive) 46 | : Loc(Loc), Cond(Cond), Elements(Elements), isActive(isActive) { 47 | } 48 | }; 49 | 50 | } // end namespace swift 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/ObjC/Property.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #include "iCDump/ObjC/Property.hpp" 16 | #include "iCDump/ObjC/Parser.hpp" 17 | #include "iCDump/ObjC/Types.hpp" 18 | #include "iCDump/config.hpp" 19 | #include "log.hpp" 20 | 21 | #include "ClangAST/utils.hpp" 22 | 23 | #include 24 | 25 | namespace iCDump::ObjC { 26 | std::unique_ptr Property::create(Parser& parser) { 27 | LIEF::BinaryStream& stream = parser.stream(); 28 | const auto raw_prop = stream.peek(); 29 | if (!raw_prop) { 30 | return nullptr; 31 | } 32 | 33 | auto prop = std::make_unique(); 34 | 35 | if (auto res = stream.peek_string_at(parser.decode_ptr(raw_prop->name))) { 36 | prop->name_ = std::move(*res); 37 | } 38 | 39 | if (auto res = stream.peek_string_at(parser.decode_ptr(raw_prop->attributes))) { 40 | prop->attributes_ = std::move(*res); 41 | } 42 | return prop; 43 | } 44 | 45 | 46 | std::string Property::to_string() const { 47 | return ""; 48 | } 49 | 50 | std::string Property::to_decl() const { 51 | if constexpr (icdump_llvm_support) { 52 | return ClangAST::generate(*this); 53 | } else { 54 | return ""; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/PrimitiveParsing.h: -------------------------------------------------------------------------------- 1 | //===--- PrimitiveParsing.h - Primitive parsing routines --------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | /// 13 | /// \file 14 | /// Primitive parsing routines useful in various places in the compiler. 15 | /// 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_BASIC_PRIMITIVEPARSING_H 19 | #define SWIFT_BASIC_PRIMITIVEPARSING_H 20 | 21 | #include "llvm/ADT/StringRef.h" 22 | #include "swift/Basic/LLVM.h" 23 | 24 | namespace swift { 25 | 26 | unsigned measureNewline(const char *BufferPtr, const char *BufferEnd); 27 | 28 | static inline unsigned measureNewline(StringRef S) { 29 | return measureNewline(S.data(), S.data() + S.size()); 30 | } 31 | 32 | static inline bool startsWithNewline(StringRef S) { 33 | return S.startswith("\n") || S.startswith("\r\n"); 34 | } 35 | 36 | /// Breaks a given string to lines and trims leading whitespace from them. 37 | void trimLeadingWhitespaceFromLines(StringRef Text, unsigned WhitespaceToTrim, 38 | SmallVectorImpl &Lines); 39 | 40 | static inline void splitIntoLines(StringRef Text, 41 | SmallVectorImpl &Lines) { 42 | trimLeadingWhitespaceFromLines(Text, 0, Lines); 43 | } 44 | 45 | } // end namespace swift 46 | 47 | #endif // SWIFT_BASIC_PRIMITIVEPARSING_H 48 | 49 | -------------------------------------------------------------------------------- /include/iCDump/ObjC/Method.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef ICDUMP_OBJCMETHOD_H_ 16 | #define ICDUMP_OBJCMETHOD_H_ 17 | #include 18 | #include 19 | #include 20 | 21 | namespace iCDump::ObjC { 22 | class Parser; 23 | class Protocol; 24 | class Class; 25 | struct Type; 26 | 27 | class Method { 28 | public: 29 | friend class Parser; 30 | friend class Protocol; 31 | friend class Class; 32 | 33 | struct prototype_t { 34 | std::unique_ptr rtype; 35 | std::vector> params; 36 | }; 37 | 38 | Method() = default; 39 | static std::unique_ptr create(Parser& parser, bool is_small); 40 | 41 | inline const std::string& name() const { 42 | return name_; 43 | } 44 | 45 | inline const std::string& mangled_type() const { 46 | return mangled_type_; 47 | } 48 | 49 | inline uintptr_t address() const { 50 | return addr_; 51 | } 52 | 53 | inline bool is_instance() const { 54 | return is_instance_; 55 | } 56 | 57 | prototype_t prototype() const; 58 | 59 | std::string to_string() const; 60 | 61 | private: 62 | std::string name_; 63 | std::string mangled_type_; 64 | uintptr_t addr_ = 0; 65 | 66 | bool is_instance_ = true; 67 | }; 68 | 69 | } 70 | #endif 71 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/PlatformConditionKinds.def: -------------------------------------------------------------------------------- 1 | //===--- PlatformConditionKinds.def - Kinds of Platform Conditions - C++ ---*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines macros used for macro-metaprogramming with the kinds of 14 | // platform conditions that can be used for conditional compilation. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef PLATFORM_CONDITION 19 | #define PLATFORM_CONDITION(LABEL, IDENTIFIER) 20 | #endif 21 | #ifndef PLATFORM_CONDITION_ 22 | #define PLATFORM_CONDITION_(LABEL, IDENTIFIER) PLATFORM_CONDITION(LABEL, "_" IDENTIFIER) 23 | #endif 24 | 25 | /// The active os target (OSX, iOS, Linux, etc.) 26 | PLATFORM_CONDITION(OS, "os") 27 | 28 | /// The active arch target (x86_64, i386, arm, arm64, etc.) 29 | PLATFORM_CONDITION(Arch, "arch") 30 | 31 | /// The active endianness target (big or little) 32 | PLATFORM_CONDITION_(Endianness, "endian") 33 | 34 | /// Runtime support (_ObjC or _Native) 35 | PLATFORM_CONDITION_(Runtime, "runtime") 36 | 37 | /// Conditional import of module 38 | PLATFORM_CONDITION(CanImport, "canImport") 39 | 40 | /// Target Environment (currently just 'simulator' or absent) 41 | PLATFORM_CONDITION(TargetEnvironment, "targetEnvironment") 42 | 43 | /// Pointer authentication enabled 44 | PLATFORM_CONDITION_(PtrAuth, "ptrauth") 45 | 46 | #undef PLATFORM_CONDITION 47 | #undef PLATFORM_CONDITION_ 48 | -------------------------------------------------------------------------------- /src/MachOStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "LIEF/MachO.hpp" 17 | #include "MachOStream.hpp" 18 | #include "log.hpp" 19 | 20 | using namespace LIEF::MachO; 21 | namespace iCDump { 22 | 23 | MachOStream::MachOStream(const LIEF::MachO::Binary& bin) : 24 | binary_{&bin} 25 | {} 26 | 27 | uint64_t MachOStream::size() const { 28 | // TODO(romain): To fix 29 | return static_cast(-1); 30 | } 31 | 32 | LIEF::result MachOStream::read_at(uint64_t offset, uint64_t size) const { 33 | uint64_t r_offset = offset; 34 | if (binary_->memory_base_address() > 0 && offset > binary_->memory_base_address()) { 35 | ICDUMP_DEBUG(" 0x{:010x} -> 0x{:010x})", offset, offset - binary_->memory_base_address() + binary_->imagebase()); 36 | r_offset -= binary_->memory_base_address(); 37 | r_offset += binary_->imagebase(); 38 | } 39 | const SegmentCommand* seg = binary_->segment_from_virtual_address(r_offset); 40 | if (seg == nullptr) { 41 | ICDUMP_DEBUG("Can't find segment with offset: 0x{:010x}", r_offset); 42 | return make_error_code(lief_errors::read_error); 43 | } 44 | LIEF::span content = seg->content(); 45 | uintptr_t delta = r_offset - seg->virtual_address(); 46 | return content.data() + delta; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/Malloc.h: -------------------------------------------------------------------------------- 1 | //===--- Malloc.h - Aligned malloc interface --------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file provides an implementation of C11 aligned_alloc(3) for platforms 14 | // that don't have it yet, using posix_memalign(3). 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_BASIC_MALLOC_H 19 | #define SWIFT_BASIC_MALLOC_H 20 | 21 | #include 22 | #if defined(_WIN32) 23 | #include 24 | #else 25 | #include 26 | #endif 27 | 28 | namespace swift { 29 | 30 | // FIXME: Use C11 aligned_alloc if available. 31 | inline void *AlignedAlloc(size_t size, size_t align) { 32 | // posix_memalign only accepts alignments greater than sizeof(void*). 33 | // 34 | if (align < sizeof(void*)) 35 | align = sizeof(void*); 36 | 37 | #if defined(_WIN32) 38 | void *r = _aligned_malloc(size, align); 39 | assert(r && "_aligned_malloc failed"); 40 | #else 41 | void *r = nullptr; 42 | int res = posix_memalign(&r, align, size); 43 | assert(res == 0 && "posix_memalign failed"); 44 | (void)res; // Silence the unused variable warning. 45 | #endif 46 | return r; 47 | } 48 | 49 | inline void AlignedFree(void *p) { 50 | #if defined(_WIN32) 51 | _aligned_free(p); 52 | #else 53 | free(p); 54 | #endif 55 | } 56 | 57 | } // end namespace swift 58 | 59 | #endif // SWIFT_BASIC_MALLOC_H 60 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/LayoutConstraintKind.h: -------------------------------------------------------------------------------- 1 | //===-- LayoutConstraintKind.h - Layout constraints kinds -------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines types and APIs for layout constraints. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | #include 18 | 19 | #ifndef SWIFT_LAYOUT_CONSTRAINTKIND_H 20 | #define SWIFT_LAYOUT_CONSTRAINTKIND_H 21 | 22 | /// Describes a layout constraint information. 23 | enum class LayoutConstraintKind : uint8_t { 24 | // It is not a known layout constraint. 25 | UnknownLayout, 26 | // It is a layout constraint representing a trivial type of a known size. 27 | TrivialOfExactSize, 28 | // It is a layout constraint representing a trivial type of a size known to 29 | // be no larger than a given size. 30 | TrivialOfAtMostSize, 31 | // It is a layout constraint representing a trivial type of an unknown size. 32 | Trivial, 33 | // It is a layout constraint representing a reference counted class instance. 34 | Class, 35 | // It is a layout constraint representing a reference counted native class 36 | // instance. 37 | NativeClass, 38 | // It is a layout constraint representing a reference counted object. 39 | RefCountedObject, 40 | // It is a layout constraint representing a native reference counted object. 41 | NativeRefCountedObject, 42 | LastLayout = NativeRefCountedObject, 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/PlatformKinds.def: -------------------------------------------------------------------------------- 1 | //===--- PlatformKinds.def - Swift PlatformKind Metaprogramming -*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines macros used for macro-metaprogramming with platform kinds. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | /// AVAILABILITY_PLATFORM(X, PrettyName) 18 | /// X - The name of the platform 19 | /// PrettyName - A string with the platform name for pretty printing 20 | #ifndef AVAILABILITY_PLATFORM 21 | #define AVAILABILITY_PLATFORM(X, PrettyName) 22 | #endif 23 | 24 | // Reordering these platforms will break serialization. 25 | AVAILABILITY_PLATFORM(iOS, "iOS") 26 | AVAILABILITY_PLATFORM(tvOS, "tvOS") 27 | AVAILABILITY_PLATFORM(watchOS, "watchOS") 28 | AVAILABILITY_PLATFORM(macOS, "macOS") 29 | AVAILABILITY_PLATFORM(iOSApplicationExtension, "application extensions for iOS") 30 | AVAILABILITY_PLATFORM(tvOSApplicationExtension, "application extensions for tvOS") 31 | AVAILABILITY_PLATFORM(watchOSApplicationExtension, "application extensions for watchOS") 32 | AVAILABILITY_PLATFORM(macOSApplicationExtension, "application extensions for macOS") 33 | AVAILABILITY_PLATFORM(macCatalyst, "Mac Catalyst") 34 | AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions for Mac Catalyst") 35 | AVAILABILITY_PLATFORM(OpenBSD, "OpenBSD") 36 | AVAILABILITY_PLATFORM(Windows, "Windows") 37 | 38 | #undef AVAILABILITY_PLATFORM 39 | -------------------------------------------------------------------------------- /bindings/python/src/iCDump.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "ObjC.hpp" 21 | 22 | namespace nb = nanobind; 23 | 24 | using namespace nb::literals; 25 | using namespace iCDump; 26 | 27 | NB_MODULE(icdump, m) { 28 | 29 | m.attr("__version__") = nb::str(ICDUMP_VERSION); 30 | m.attr("__tag__") = nb::str(ICDUMP_TAG); 31 | m.attr("__commit__") = nb::str(ICDUMP_COMMIT); 32 | 33 | nb::enum_(m, "LOG_LEVEL") 34 | .value("TRACE", LOG_LEVEL::TRACE) 35 | .value("DEBUG", LOG_LEVEL::DEBUG) 36 | .value("INFO", LOG_LEVEL::INFO) 37 | .value("WARN", LOG_LEVEL::WARN) 38 | .value("ERR", LOG_LEVEL::ERR) 39 | .value("CRITICAL", LOG_LEVEL::CRITICAL); 40 | 41 | nb::enum_(m, "ARCH") 42 | .value("AUTO", ARCH::AUTO) 43 | .value("AARCH64", ARCH::AARCH64) 44 | .value("ARM", ARCH::ARM) 45 | .value("X86_64", ARCH::X86_64) 46 | .value("X86", ARCH::X86); 47 | 48 | m.def("disable_log", &disable_log); 49 | m.def("enable_log", &enable_log); 50 | m.def("set_log_level", &set_log_level); 51 | 52 | 53 | nb::module_ m_objc = m.def_submodule("objc", "iCDump Objective-C module"); 54 | py::ObjC::init(m_objc); 55 | } 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |
3 |

4 | 5 |
6 |
7 |

iCDump is now part of LIEF extended

8 |
9 |
10 | 11 | # iCDump 12 | 13 | iCDump is a modern and cross-platform Objective-C class dump. 14 | Compared to existing tools, iCDump can run independently from the Apple ecosystem and it exposes 15 | Python bindings. 16 | 17 | It relies on [LIEF](https://lief-project.github.io/) to access the Objective-C metadata 18 | and [LLVM](https://llvm.org) to output the results. 19 | 20 | Swift support is on-going but not public yet. 21 | 22 | ## Python API 23 | 24 | iCDump exposes a Python API through [nanobind](https://github.com/wjakob/nanobind). One can 25 | dump Objective-C metadata as follows: 26 | 27 | ```python 28 | import icdump 29 | metadata = icdump.objc.parse("./RNCryptor.bin") 30 | 31 | print(metadata.to_decl()) 32 | ``` 33 | 34 | ```text 35 | @interface RNCryptor.RNCryptor.Encryptor{ 36 | NSObject * encryptor; 37 | } 38 | @end 39 | @interface RNCryptor.RNCryptor.Decryptor{ 40 | NSObject * decryptors; 41 | NSObject * buffer; 42 | NSObject * decryptor; 43 | NSObject * password; 44 | } 45 | @end 46 | ... 47 | ``` 48 | 49 | Or inspect Objective-C structures using the different properties: 50 | 51 | ``` 52 | for cls in metadata.classes: 53 | print(cls.demangled_name) 54 | for prop in cls.properties: 55 | print(prop.name) 56 | ``` 57 | 58 | ### Contact 59 | 60 | - [Romain Thomas](https://www.romainthomas.fr): [@rh0main](https://twitter.com/rh0main) - `me@romainthomas.fr` 61 | 62 | #### Credits 63 | 64 | - [LLVM](https://llvm.org/) 65 | - [rellic](https://github.com/lifting-bits/rellic) by [Trail of Bits](https://www.trailofbits.com/) 66 | - [DerekSelander/dsdump](https://github.com/DerekSelander/dsdump) 67 | 68 | ### License 69 | 70 | iCDump is released under the [Apache License, Version 2.0](./LICENSE) 71 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/SmallPtrSetVector.h: -------------------------------------------------------------------------------- 1 | //===--- SmallPtrSetVector.h ----------------------------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_SMALLPTRSETVECTOR_H 14 | #define SWIFT_BASIC_SMALLPTRSETVECTOR_H 15 | 16 | #include "swift/Basic/LLVM.h" 17 | #include "llvm/ADT/SetVector.h" 18 | #include "llvm/ADT/SmallPtrSet.h" 19 | #include "llvm/ADT/SmallVector.h" 20 | 21 | namespace swift { 22 | 23 | /// A SetVector that performs no allocations if smaller than a certain 24 | /// size. Uses a SmallPtrSet/SmallVector internally. 25 | template 26 | class SmallPtrSetVector : public llvm::SetVector, 27 | SmallPtrSet> { 28 | public: 29 | SmallPtrSetVector() = default; 30 | 31 | /// Initialize a SmallPtrSetVector with a range of elements 32 | template SmallPtrSetVector(It Start, It End) { 33 | this->insert(Start, End); 34 | } 35 | }; 36 | 37 | } // namespace swift 38 | 39 | namespace std { 40 | 41 | /// Implement std::swap in terms of SmallSetVector swap. 42 | /// 43 | /// This matches llvm's implementation for SmallSetVector. 44 | template 45 | inline void swap(swift::SmallPtrSetVector &LHS, 46 | swift::SmallPtrSetVector &RHS) { 47 | LHS.swap(RHS); 48 | } 49 | 50 | } // end namespace std 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/EditorPlaceholder.h: -------------------------------------------------------------------------------- 1 | //===--- EditorPlaceholder.h - Handling for editor placeholders -*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | /// 13 | /// \file 14 | /// Provides info about editor placeholders, <#such as this#>. 15 | /// 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_BASIC_EDITORPLACEHOLDER_H 19 | #define SWIFT_BASIC_EDITORPLACEHOLDER_H 20 | 21 | #include "llvm/ADT/StringRef.h" 22 | #include "swift/Basic/LLVM.h" 23 | 24 | namespace swift { 25 | 26 | enum class EditorPlaceholderKind { 27 | Basic, 28 | Typed, 29 | }; 30 | 31 | struct EditorPlaceholderData { 32 | /// Placeholder kind. 33 | EditorPlaceholderKind Kind; 34 | /// The part that is displayed in the editor. 35 | StringRef Display; 36 | /// If kind is \c Typed, this is the type string for the placeholder. 37 | StringRef Type; 38 | /// If kind is \c Typed, this is the type string to be considered for 39 | /// placeholder expansion. 40 | /// It can be same as \c Type or different if \c Type is a typealias. 41 | StringRef TypeForExpansion; 42 | }; 43 | 44 | /// Deconstructs a placeholder string and returns info about it. 45 | /// \returns None if the \c PlaceholderText is not a valid placeholder string. 46 | Optional 47 | parseEditorPlaceholder(StringRef PlaceholderText); 48 | 49 | /// Checks if an identifier with the given text is an editor placeholder 50 | bool isEditorPlaceholder(StringRef IdentifierText); 51 | } // end namespace swift 52 | 53 | #endif // SWIFT_BASIC_EDITORPLACEHOLDER_H 54 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DefaultArgumentKind.h: -------------------------------------------------------------------------------- 1 | //===--- DefaultArgumentKind.h - Default Argument Kind Enum -----*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines the DefaultArgumentKind enumeration. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | #ifndef SWIFT_DEFAULTARGUMENTKIND_H 18 | #define SWIFT_DEFAULTARGUMENTKIND_H 19 | 20 | #include 21 | 22 | namespace llvm { 23 | class StringRef; 24 | } 25 | 26 | namespace swift { 27 | 28 | class Expr; 29 | 30 | /// Describes the kind of default argument a tuple pattern element has. 31 | enum class DefaultArgumentKind : uint8_t { 32 | /// No default argument. 33 | None, 34 | /// A normal default argument. 35 | Normal, 36 | /// The default argument is inherited from the corresponding argument of the 37 | /// overridden declaration. 38 | Inherited, 39 | /// The "nil" literal. 40 | NilLiteral, 41 | /// An empty array literal. 42 | EmptyArray, 43 | /// An empty dictionary literal. 44 | EmptyDictionary, 45 | /// A reference to the stored property. This is a special default argument 46 | /// kind for the synthesized memberwise constructor to emit a call to the 47 | /// property's initializer. 48 | StoredProperty, 49 | // Magic identifier literals expanded at the call site: 50 | #define MAGIC_IDENTIFIER(NAME, STRING, SYNTAX_KIND) NAME, 51 | #include "swift/AST/MagicIdentifierKinds.def" 52 | }; 53 | enum { NumDefaultArgumentKindBits = 4 }; 54 | 55 | } // end namespace swift 56 | 57 | #endif // LLVM_SWIFT_DEFAULTARGUMENTKIND_H 58 | 59 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/PrettyStackTrace.h: -------------------------------------------------------------------------------- 1 | //===--- PrettyStackTrace.h - Generic stack-trace prettifiers ---*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_PRETTYSTACKTRACE_H 14 | #define SWIFT_BASIC_PRETTYSTACKTRACE_H 15 | 16 | #include "llvm/Support/PrettyStackTrace.h" 17 | #include "llvm/ADT/StringRef.h" 18 | 19 | namespace llvm { 20 | class MemoryBuffer; 21 | } 22 | 23 | namespace swift { 24 | 25 | /// A PrettyStackTraceEntry for performing an action involving a StringRef. 26 | /// 27 | /// The message is: 28 | /// While ""\n 29 | class PrettyStackTraceStringAction : public llvm::PrettyStackTraceEntry { 30 | const char *Action; 31 | llvm::StringRef TheString; 32 | public: 33 | PrettyStackTraceStringAction(const char *action, llvm::StringRef string) 34 | : Action(action), TheString(string) {} 35 | void print(llvm::raw_ostream &OS) const override; 36 | }; 37 | 38 | /// A PrettyStackTraceEntry to dump the contents of a file. 39 | class PrettyStackTraceFileContents : public llvm::PrettyStackTraceEntry { 40 | const llvm::MemoryBuffer &Buffer; 41 | public: 42 | explicit PrettyStackTraceFileContents(const llvm::MemoryBuffer &buffer) 43 | : Buffer(buffer) {} 44 | void print(llvm::raw_ostream &OS) const override; 45 | }; 46 | 47 | /// A PrettyStackTraceEntry to print the version of the compiler. 48 | class PrettyStackTraceSwiftVersion : public llvm::PrettyStackTraceEntry { 49 | public: 50 | void print(llvm::raw_ostream &OS) const override; 51 | }; 52 | 53 | } // end namespace swift 54 | 55 | #endif // SWIFT_BASIC_PRETTYSTACKTRACE_H 56 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/AnyValue.h: -------------------------------------------------------------------------------- 1 | //===--- AnyValue.h ---------------------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines some miscellaneous overloads of hash_value() and 14 | // simple_display(). 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_BASIC_ANYVALUE_H 19 | #define SWIFT_BASIC_ANYVALUE_H 20 | 21 | #include "swift/Basic/SimpleDisplay.h" 22 | #include "swift/Basic/TypeID.h" 23 | #include "llvm/ADT/PointerUnion.h" // to define hash_value 24 | #include "llvm/ADT/TinyPtrVector.h" 25 | 26 | namespace llvm { 27 | // FIXME: Belongs in LLVM itself 28 | template 29 | hash_code hash_value(const llvm::PointerUnion &ptr) { 30 | return hash_value(ptr.getOpaqueValue()); 31 | } 32 | 33 | template 34 | bool operator==(const TinyPtrVector &lhs, const TinyPtrVector &rhs) { 35 | if (lhs.size() != rhs.size()) 36 | return false; 37 | 38 | for (unsigned i = 0, n = lhs.size(); i != n; ++i) { 39 | if (lhs[i] != rhs[i]) 40 | return false; 41 | } 42 | 43 | return true; 44 | } 45 | 46 | template 47 | bool operator!=(const TinyPtrVector &lhs, const TinyPtrVector &rhs) { 48 | return !(lhs == rhs); 49 | } 50 | 51 | template 52 | void simple_display(raw_ostream &out, const Optional &opt) { 53 | if (opt) { 54 | simple_display(out, *opt); 55 | } else { 56 | out << "None"; 57 | } 58 | } 59 | } // end namespace llvm 60 | 61 | #endif // 62 | 63 | 64 | -------------------------------------------------------------------------------- /.github/workflows/osx.yml: -------------------------------------------------------------------------------- 1 | name: 'macOS' 2 | on: push 3 | 4 | jobs: 5 | osx-sdk: 6 | runs-on: macos-12.0 7 | strategy: 8 | matrix: 9 | python-version: ['3.10'] 10 | steps: 11 | - uses: actions/checkout@v2 12 | with: 13 | fetch-depth: 0 14 | - name: Set up Python ${{ matrix.python-version }} 15 | uses: actions/setup-python@v4 16 | with: 17 | python-version: ${{ matrix.python-version }} 18 | - name: Install system dependencies 19 | run: | 20 | brew install cmake ninja ccache 21 | python -m pip install --upgrade pip setuptools wheel 22 | - name: Get Date 23 | id: get-date 24 | run: | 25 | echo "::set-output name=date::$(/bin/date -u "+%Y-%m-%d-%H;%M;%S")" 26 | shell: bash 27 | - name: Setup cache dir 28 | shell: bash 29 | run: | 30 | mkdir -p ~/.ccache 31 | - name: ccache cache files 32 | uses: actions/cache@v1.1.0 33 | with: 34 | path: ~/.ccache 35 | key: osx-${{ runner.os }}-${{ steps.get-date.outputs.date }} 36 | restore-keys: | 37 | osx-${{ runner.os }}- 38 | - name: Upgrade pip 39 | shell: bash 40 | run: | 41 | python -m pip install --upgrade pip 42 | - name: Prepare dependencies 43 | shell: bash 44 | run: | 45 | mkdir -p /tmp/third-party && cd /tmp/third-party 46 | curl -LO https://data.romainthomas.fr/icdump/LLVM-14.0.6-Darwin-slim.tar.gz 47 | curl -LO https://data.romainthomas.fr/icdump/LIEF-0.13.0-Darwin.tar.gz 48 | tar xzvf LLVM-14.0.6-Darwin-slim.tar.gz 49 | tar xzvf LIEF-0.13.0-Darwin.tar.gz 50 | - name: Build Python ${{ matrix.python-version }} wheel (arm64) 51 | shell: bash 52 | env: 53 | MACOSX_DEPLOYMENT_TARGET: "10.7" 54 | CCACHE_DIR: ~/.ccache 55 | CCACHE_MAXSIZE: 10.0G 56 | CCACHE_CPP2: 1 57 | CCACHE_COMPRESS: 1 58 | run: | 59 | bash $GITHUB_WORKSPACE/.github/py_osx.sh 60 | 61 | 62 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/APIntMap.h: -------------------------------------------------------------------------------- 1 | //===--- APIntMap.h - A map with APInts as the keys -------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // LLVM does not allow arbitrary APInts to be the keys of a DenseMap because 14 | // APInts are only comparable if they have the same bit-width. This map 15 | // implementation assumes that its keys will always be constrained to their 16 | // minimum width, so it's not a general-purpose structure, but it does work. 17 | // 18 | //===----------------------------------------------------------------------===// 19 | 20 | #ifndef SWIFT_BASIC_APINTMAP_H 21 | #define SWIFT_BASIC_APINTMAP_H 22 | 23 | #include "llvm/ADT/APInt.h" 24 | #include "llvm/ADT/DenseMap.h" 25 | #include "swift/Basic/LLVM.h" 26 | 27 | namespace swift { 28 | 29 | struct WidthPreservingAPIntDenseMapInfo { 30 | // For the special values, we use -1 with a bit-width that isn't minimal 31 | // for the value, then use a parser that always produces values with 32 | // minimal bit-widths so that we don't get a conflict. 33 | static inline APInt getEmptyKey() { 34 | return APInt::getAllOnesValue(/*bitwidth*/2); 35 | } 36 | static inline APInt getTombstoneKey() { 37 | return APInt::getAllOnesValue(/*bitwidth*/3); 38 | } 39 | 40 | static unsigned getHashValue(const APInt &Key) { 41 | return static_cast(hash_value(Key)); 42 | } 43 | 44 | static bool isEqual(const APInt &LHS, const APInt &RHS) { 45 | return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS; 46 | } 47 | }; 48 | 49 | template 50 | using APIntMap = llvm::DenseMap; 51 | 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/FunctionRefKind.h: -------------------------------------------------------------------------------- 1 | //===--- FunctionRefKind.h - Function reference kind ------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines the FunctionRefKind enum, which is used to describe how 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | #ifndef SWIFT_AST_FUNCTION_REF_KIND_H 18 | #define SWIFT_AST_FUNCTION_REF_KIND_H 19 | 20 | #include "llvm/ADT/StringRef.h" 21 | 22 | namespace swift { 23 | 24 | /// Describes how a function is referenced within an expression node, 25 | /// which dictates whether argument labels are part of the resulting 26 | /// function type or not. 27 | /// 28 | /// How a function is referenced comes down to how it was spelled in 29 | /// the source code, e.g., was it called in the source code and was it 30 | /// spelled as a compound name. 31 | enum class FunctionRefKind : unsigned { 32 | /// The function was referenced using a bare function name (e.g., 33 | /// 'f') and not directly called. 34 | Unapplied, 35 | /// The function was referenced using a bare function name and was 36 | /// directly applied once, e.g., "f(a: 1, b: 2)". 37 | SingleApply, 38 | /// The function was referenced using a bare function name and was 39 | /// directly applied two or more times, e.g., "g(x)(y)". 40 | DoubleApply, 41 | /// The function was referenced using a compound function name, 42 | /// e.g., "f(a:b:)". 43 | Compound, 44 | }; 45 | 46 | /// Produce a string describing a function reference kind, for 47 | /// debugging purposes. 48 | llvm::StringRef getFunctionRefKindStr(FunctionRefKind refKind); 49 | 50 | } 51 | 52 | #endif // SWIFT_AST_FUNCTION_REF_KIND_H 53 | -------------------------------------------------------------------------------- /include/iCDump/ObjC/Metadata.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef ICDUMP_OBJC_METADATA_H_ 16 | #define ICDUMP_OBJC_METADATA_H_ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "iCDump/iterators.hpp" 22 | 23 | namespace iCDump::ObjC { 24 | 25 | // Forward definitions 26 | class Class; 27 | class Parser; 28 | class Protocol; 29 | 30 | class Metadata { 31 | friend class Parser; 32 | public: 33 | Metadata() = default; 34 | ~Metadata() = default; 35 | 36 | Metadata(const Metadata&) = delete; 37 | Metadata& operator=(const Metadata&) = delete; 38 | 39 | using classes_t = std::vector>; 40 | using protocols_t = std::vector>; 41 | 42 | using classes_it_t = const_ref_iterator; 43 | using protocol_it_t = const_ref_iterator; 44 | 45 | inline classes_it_t classes() const { 46 | return classes_; 47 | } 48 | 49 | inline protocol_it_t protocols() const { 50 | return protocols_; 51 | } 52 | 53 | const Class* get_class(const std::string& name) const; 54 | const Protocol* get_protocol(const std::string& name) const; 55 | 56 | std::string to_decl() const; 57 | std::string to_string() const; 58 | 59 | private: 60 | classes_t classes_; 61 | std::unordered_map classes_lookup_; 62 | 63 | protocols_t protocols_; 64 | std::unordered_map protocol_lookup_; 65 | 66 | }; 67 | 68 | } 69 | #endif 70 | -------------------------------------------------------------------------------- /include/iCDump/ObjC/Parser.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef ICDUMP_OBJC_PARSER_H_ 16 | #define ICDUMP_OBJC_PARSER_H_ 17 | #include 18 | #include 19 | #include "iCDump/NonCopyable.hpp" 20 | namespace LIEF { 21 | class BinaryStream; 22 | namespace MachO { 23 | class Binary; 24 | } 25 | } 26 | 27 | namespace iCDump::ObjC { 28 | class Metadata; 29 | class Class; 30 | class Method; 31 | class Protocol; 32 | class Parser : protected NonCopyable { 33 | public: 34 | static std::unique_ptr parse(const LIEF::MachO::Binary& bin); 35 | 36 | inline LIEF::BinaryStream& stream() { 37 | return *stream_; 38 | } 39 | 40 | inline const LIEF::MachO::Binary& bin() const { 41 | return *bin_; 42 | } 43 | 44 | inline uintptr_t imagebase() const { 45 | return imagebase_; 46 | } 47 | 48 | Protocol* get_or_create_protocol(uintptr_t offset); 49 | 50 | uintptr_t decode_ptr(uintptr_t ptr); 51 | 52 | private: 53 | Parser& process_classes(); 54 | Parser& process_classes(LIEF::BinaryStream& mstream, LIEF::BinaryStream& classlist); 55 | Parser& process_protocols(); 56 | Parser& process_protocols(LIEF::BinaryStream& mstream, LIEF::BinaryStream& protolist); 57 | 58 | 59 | Parser(); 60 | Parser(const LIEF::MachO::Binary* bin); 61 | const LIEF::MachO::Binary* bin_ = nullptr; 62 | uintptr_t imagebase_ = 0; 63 | std::unique_ptr stream_; 64 | std::unique_ptr metadata_; 65 | 66 | std::unordered_map protocols_; 67 | }; 68 | 69 | } 70 | #endif 71 | -------------------------------------------------------------------------------- /src/ClangAST/ASTGen.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef ICDUMP_ASTGEN_H_ 16 | #define ICDUMP_ASTGEN_H_ 17 | #include 18 | namespace clang { 19 | class ASTContext; 20 | class CompilerInstance; 21 | class DeclContext; 22 | class ObjCContainerDecl; 23 | class ObjCInterfaceDecl; 24 | class ObjCIvarDecl; 25 | class ObjCMethodDecl; 26 | class ObjCPropertyDecl; 27 | class ObjCProtocolDecl; 28 | class ParmVarDecl; 29 | class QualType; 30 | } 31 | 32 | namespace iCDump { 33 | namespace ObjC { 34 | class Class; 35 | class IVar; 36 | class Method; 37 | class Property; 38 | class Protocol; 39 | } 40 | 41 | namespace ClangAST { 42 | 43 | // Wrapper over clang::ASTContext 44 | class ASTGen { 45 | public: 46 | static ASTGen& get(); 47 | 48 | clang::ObjCProtocolDecl* decl_protocol(const ObjC::Protocol& protocol, clang::DeclContext* DC); 49 | clang::ObjCMethodDecl* decl_method(const ObjC::Method& method, clang::DeclContext* DC); 50 | clang::ObjCInterfaceDecl* decl_class(const ObjC::Class& cls, clang::DeclContext* DC); 51 | clang::ObjCPropertyDecl* decl_property(const ObjC::Property& prop, clang::DeclContext* DC); 52 | clang::ObjCIvarDecl* decl_ivar(const ObjC::IVar& ivar, clang::ObjCContainerDecl* DC); 53 | //clang::ParmVarDecl* decl_parameter(const ObjCMethod& protocol, clang::DeclContext* DC); 54 | clang::ASTContext& ast_ctx(); 55 | 56 | static void destroy(); 57 | private: 58 | ASTGen(); 59 | inline static ASTGen* instance_ = nullptr; 60 | std::unique_ptr ci_; 61 | }; 62 | 63 | } 64 | } 65 | #endif 66 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/CTypeIDZone.def: -------------------------------------------------------------------------------- 1 | //===--- CTypeIDZone.def - Define the C++ TypeID Zone -----------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This definition file describes the types in the "C++" TypeID zone, 14 | // for use with the TypeID template. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | // C types. 19 | SWIFT_TYPEID_NAMED(unsigned char, UnsignedChar) 20 | SWIFT_TYPEID_NAMED(signed char, SignedChar) 21 | SWIFT_TYPEID_NAMED(char, Char) 22 | SWIFT_TYPEID_NAMED(short, Short) 23 | SWIFT_TYPEID_NAMED(unsigned short, UnsignedShort) 24 | SWIFT_TYPEID_NAMED(int, Int) 25 | SWIFT_TYPEID_NAMED(unsigned int, UnsignedInt) 26 | SWIFT_TYPEID_NAMED(long, Long) 27 | SWIFT_TYPEID_NAMED(unsigned long, UnsignedLong) 28 | SWIFT_TYPEID_NAMED(long long, LongLong) 29 | SWIFT_TYPEID_NAMED(unsigned long long, UnsignedLongLong) 30 | SWIFT_TYPEID_NAMED(float, Float) 31 | SWIFT_TYPEID_NAMED(double, Double) 32 | SWIFT_TYPEID_NAMED(bool, Bool) 33 | SWIFT_TYPEID_NAMED(decltype(nullptr), NullPtr) 34 | SWIFT_TYPEID_NAMED(void, Void) 35 | SWIFT_TYPEID_NAMED(std::string, String) 36 | 37 | // C++ standard library types. 38 | SWIFT_TYPEID_NAMED(evaluator::SideEffect, SideEffect) 39 | SWIFT_TYPEID_TEMPLATE1_NAMED(std::vector, Vector, typename T, T) 40 | SWIFT_TYPEID_TEMPLATE1_NAMED(std::unique_ptr, UniquePtr, typename T, T) 41 | SWIFT_TYPEID_TEMPLATE2_NAMED(std::pair, Pair, typename T1, T1, typename T2, T2) 42 | 43 | // LLVM ADT types. 44 | SWIFT_TYPEID_TEMPLATE1_NAMED(llvm::TinyPtrVector, TinyPtrVector, typename T, T) 45 | SWIFT_TYPEID_TEMPLATE1_NAMED(llvm::ArrayRef, ArrayRef, typename T, T) 46 | SWIFT_TYPEID_TEMPLATE1_NAMED(llvm::Optional, Optional, typename T, T) 47 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/ImplementTypeIDZone.h: -------------------------------------------------------------------------------- 1 | //===--- ImplementTypeIDZone.h - Implement a TypeID Zone --------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file should be #included to implement the TypeIDs for a given zone 14 | // in a C++ file. 15 | // Two macros should be #define'd before inclusion, and will be #undef'd at 16 | // the end of this file: 17 | // 18 | // SWIFT_TYPEID_ZONE: The ID number of the Zone being defined, which must 19 | // be unique. 0 is reserved for basic C and LLVM types; 255 is reserved 20 | // for test cases. 21 | // 22 | // SWIFT_TYPEID_HEADER: A (quoted) name of the header to be 23 | // included to define the types in the zone. 24 | // 25 | //===----------------------------------------------------------------------===// 26 | 27 | #ifndef SWIFT_TYPEID_ZONE 28 | # error Must define the value of the TypeID zone with the given name. 29 | #endif 30 | 31 | #ifndef SWIFT_TYPEID_HEADER 32 | # error Must define the TypeID header name with SWIFT_TYPEID_HEADER 33 | #endif 34 | 35 | // Define a TypeID where the type name and internal name are the same. 36 | #define SWIFT_REQUEST(Zone, Type, Sig, Caching, LocOptions) SWIFT_TYPEID_NAMED(Type, Type) 37 | #define SWIFT_TYPEID(Type) SWIFT_TYPEID_NAMED(Type, Type) 38 | 39 | // Out-of-line definitions. 40 | #define SWIFT_TYPEID_NAMED(Type, Name) \ 41 | const uint64_t TypeID::value; 42 | 43 | #define SWIFT_TYPEID_TEMPLATE1_NAMED(Template, Name, Param1, Arg1) 44 | 45 | #include SWIFT_TYPEID_HEADER 46 | 47 | #undef SWIFT_REQUEST 48 | 49 | #undef SWIFT_TYPEID_NAMED 50 | #undef SWIFT_TYPEID_TEMPLATE1_NAMED 51 | 52 | #undef SWIFT_TYPEID 53 | #undef SWIFT_TYPEID_ZONE 54 | #undef SWIFT_TYPEID_HEADER 55 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DefineDiagnosticMacros.h: -------------------------------------------------------------------------------- 1 | //===--- DefineDiagnosticMacros.h - Shared Diagnostic Macros ----*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2020 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines macros shared across diagnostic definition files. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | // Define macros 18 | #ifdef DEFINE_DIAGNOSTIC_MACROS 19 | 20 | #if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE) && \ 21 | defined(REMARK))) 22 | #error Must define either DIAG or the set {ERROR,WARNING,NOTE,REMARK} 23 | #endif 24 | 25 | #ifndef ERROR 26 | #define ERROR(ID, Options, Text, Signature) \ 27 | DIAG(ERROR, ID, Options, Text, Signature) 28 | #endif 29 | 30 | #ifndef WARNING 31 | #define WARNING(ID, Options, Text, Signature) \ 32 | DIAG(WARNING, ID, Options, Text, Signature) 33 | #endif 34 | 35 | #ifndef NOTE 36 | #define NOTE(ID, Options, Text, Signature) \ 37 | DIAG(NOTE, ID, Options, Text, Signature) 38 | #endif 39 | 40 | #ifndef REMARK 41 | #define REMARK(ID, Options, Text, Signature) \ 42 | DIAG(REMARK, ID, Options, Text, Signature) 43 | #endif 44 | 45 | #ifndef FIXIT 46 | #define FIXIT(ID, Text, Signature) 47 | #endif 48 | 49 | #undef DEFINE_DIAGNOSTIC_MACROS 50 | #endif 51 | 52 | // Undefine macros 53 | #ifdef UNDEFINE_DIAGNOSTIC_MACROS 54 | 55 | #ifndef DIAG_NO_UNDEF 56 | 57 | #if defined(DIAG) 58 | #undef DIAG 59 | #endif 60 | 61 | #undef REMARK 62 | #undef NOTE 63 | #undef WARNING 64 | #undef ERROR 65 | #undef FIXIT 66 | 67 | #endif 68 | 69 | #undef UNDEFINE_DIAGNOSTIC_MACROS 70 | #endif 71 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/TypeOrExtensionDecl.h: -------------------------------------------------------------------------------- 1 | //===- TypeOrExtensionDecl.h - Swift Language Declaration ASTs -*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines the TypeOrExtensionDecl struct, separately to Decl.h so 14 | // that this can be included in files that Decl.h includes. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_TYPE_OR_EXTENSION_DECL_H 19 | #define SWIFT_TYPE_OR_EXTENSION_DECL_H 20 | 21 | #include "swift/AST/TypeAlignments.h" 22 | #include "llvm/ADT/PointerUnion.h" 23 | 24 | namespace swift { 25 | 26 | /// Describes either a nominal type declaration or an extension 27 | /// declaration. 28 | struct TypeOrExtensionDecl { 29 | // (The definitions are in Decl.cpp.) 30 | llvm::PointerUnion Decl; 31 | 32 | TypeOrExtensionDecl() = default; 33 | 34 | TypeOrExtensionDecl(NominalTypeDecl *D); 35 | TypeOrExtensionDecl(ExtensionDecl *D); 36 | 37 | /// Return the contained *Decl as the Decl superclass. 38 | class Decl *getAsDecl() const; 39 | /// Return the contained *Decl as the DeclContext superclass. 40 | DeclContext *getAsDeclContext() const; 41 | /// Return the contained NominalTypeDecl or that of the extended type 42 | /// in the ExtensionDecl. 43 | NominalTypeDecl *getBaseNominal() const; 44 | 45 | /// Is the contained pointer null? 46 | bool isNull() const; 47 | explicit operator bool() const { return !isNull(); } 48 | 49 | bool operator==(TypeOrExtensionDecl rhs) { return Decl == rhs.Decl; } 50 | bool operator!=(TypeOrExtensionDecl rhs) { return Decl != rhs.Decl; } 51 | bool operator<(TypeOrExtensionDecl rhs) { return Decl < rhs.Decl; } 52 | }; 53 | 54 | } // end namespace swift 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/iCDump/ObjC/Protocol.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef ICDUMP_OBJC_PROTOCOL_H_ 16 | #define ICDUMP_OBJC_PROTOCOL_H_ 17 | #include 18 | #include 19 | #include 20 | 21 | #include "iCDump/iterators.hpp" 22 | 23 | namespace iCDump::ObjC { 24 | class Method; 25 | class Parser; 26 | class Property; 27 | 28 | //! Mirror of protcol_t 29 | class Protocol { 30 | public: 31 | friend class Parser; 32 | using methods_t = std::vector>; 33 | using properties_t = std::vector>; 34 | 35 | using methods_it_t = const_ref_iterator; 36 | using properties_it_t = const_ref_iterator; 37 | 38 | static std::unique_ptr create(Parser& parser); 39 | 40 | Protocol(); 41 | Protocol(const Protocol&) = delete; 42 | Protocol& operator=(const Protocol&) = delete; 43 | 44 | inline const std::string& mangled_name() const { 45 | return mangled_name_; 46 | } 47 | 48 | inline methods_it_t optional_methods() const { 49 | return opt_methods_; 50 | } 51 | 52 | inline methods_it_t required_methods() const { 53 | return required_methods_; 54 | } 55 | 56 | inline properties_it_t properties() const { 57 | return properties_; 58 | } 59 | 60 | // TODO: demangled version 61 | //std::string name() const; 62 | 63 | std::string to_string() const; 64 | std::string to_decl() const; 65 | private: 66 | std::string mangled_name_; 67 | 68 | methods_t opt_methods_; 69 | methods_t required_methods_; 70 | properties_t properties_; 71 | }; 72 | 73 | } 74 | #endif 75 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/PatternNodes.def: -------------------------------------------------------------------------------- 1 | //===--- PatternNodes.def - Swift Pattern AST Metaprogramming ---*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines macros used for macro-metaprogramming with patterns. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | /// PATTERN(Id, Parent) 18 | /// The pattern's enumerator value is PatternKind::Id. The pattern's 19 | /// class name is Id##Pattern, and the name of its base class is Parent. 20 | #ifndef PATTERN 21 | # error Included PatternNodes.def without defining PATTERN! 22 | #endif 23 | 24 | /// REFUTABLE_PATTERN(Id, Parent) 25 | /// Matching this pattern can fail. These patterns cannot appear syntactically 26 | /// in variable declarations, assignments, or function declarations. 27 | #ifndef REFUTABLE_PATTERN 28 | # define REFUTABLE_PATTERN(Id, Parent) PATTERN(Id, Parent) 29 | #endif 30 | 31 | #ifndef LAST_PATTERN 32 | #define LAST_PATTERN(Id) 33 | #endif 34 | 35 | // Metavars: x (variable binding), pat (pattern), e (expression) 36 | PATTERN(Paren, Pattern) // (pat) 37 | PATTERN(Tuple, Pattern) // (pat1, ..., patN), N >= 1 38 | PATTERN(Named, Pattern) // let pat, var pat 39 | PATTERN(Any, Pattern) // _ 40 | PATTERN(Typed, Pattern) // pat : type 41 | PATTERN(Binding, Pattern) // x 42 | REFUTABLE_PATTERN(Is, Pattern) // x is myclass 43 | REFUTABLE_PATTERN(EnumElement, Pattern) // .mycase(pat1, ..., patN) 44 | // MyType.mycase(pat1, ..., patN) 45 | REFUTABLE_PATTERN(OptionalSome, Pattern) // pat? nil 46 | REFUTABLE_PATTERN(Bool, Pattern) // true, false 47 | REFUTABLE_PATTERN(Expr, Pattern) // e 48 | LAST_PATTERN(Expr) 49 | 50 | #undef REFUTABLE_PATTERN 51 | #undef PATTERN 52 | #undef LAST_PATTERN 53 | -------------------------------------------------------------------------------- /src/ObjC/IVar.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #include "iCDump/ObjC/IVar.hpp" 16 | #include "iCDump/ObjC/Parser.hpp" 17 | #include "iCDump/ObjC/Types.hpp" 18 | #include "iCDump/ObjC/TypesEncoding.hpp" 19 | #include "log.hpp" 20 | 21 | #include 22 | 23 | namespace iCDump::ObjC { 24 | 25 | std::unique_ptr IVar::create(Parser& parser) { 26 | LIEF::BinaryStream& stream = parser.stream(); 27 | const auto raw_ivar = stream.peek(); 28 | 29 | if (!raw_ivar) { 30 | return nullptr; 31 | } 32 | 33 | auto ivar = std::make_unique(); 34 | if (auto res = stream.peek_string_at(parser.decode_ptr(raw_ivar->name))) { 35 | ivar->name_ = std::move(*res); 36 | } else { 37 | ICDUMP_ERR("Can't read ivar.name at 0x{:x}", parser.decode_ptr(raw_ivar->name)); 38 | } 39 | 40 | if (auto res = stream.peek_string_at(parser.decode_ptr(raw_ivar->type))) { 41 | ivar->mangled_type_ = std::move(*res); 42 | } else { 43 | ICDUMP_ERR("Can't read ivar.type at 0x{:x}", parser.decode_ptr(raw_ivar->type)); 44 | } 45 | 46 | return ivar; 47 | } 48 | 49 | 50 | std::unique_ptr IVar::type() const { 51 | if (mangled_type_.empty()) { 52 | return nullptr; 53 | } 54 | std::vector> types = decode_type(mangled_type()); 55 | if (types.size() != 1) { 56 | ICDUMP_ERR("Error while parsing type: {}", mangled_type()); 57 | return nullptr; 58 | } 59 | return std::move(types.back()); 60 | } 61 | 62 | 63 | std::string IVar::to_string() const { 64 | return fmt::format("{} {}", mangled_type(), name()); 65 | } 66 | 67 | std::string IVar::to_decl() const { 68 | return ""; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/ScopedTracking.h: -------------------------------------------------------------------------------- 1 | //===--- ScopedTracking.h - Utilities for scoped tracking -------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines some miscellaneous utilities that are useful when 14 | // working with tracked values that can be saved and restored in a scoped 15 | // fashion. 16 | // 17 | //===----------------------------------------------------------------------===// 18 | 19 | #ifndef SWIFT_BASIC_SCOPEDTRACKING_H 20 | #define SWIFT_BASIC_SCOPEDTRACKING_H 21 | 22 | namespace llvm { 23 | template 24 | class ScopedHashTable; 25 | template 26 | class ScopedHashTableScope; 27 | } 28 | 29 | namespace swift { 30 | 31 | /// Must declare a nested type scope_type which can be initialized 32 | /// with an l-value reference to the tracker type. 33 | template 34 | struct ScopedTrackingTraits; 35 | 36 | template 37 | struct ScopedTrackingTraits> { 38 | using scope_type = llvm::ScopedHashTableScope; 39 | }; 40 | 41 | /// A class which stores scopes for multiple trackers. Can be 42 | /// initialized with a pack of l-value references to the trackers. 43 | template 44 | class TrackingScopes; 45 | 46 | template <> 47 | class TrackingScopes<> { 48 | public: 49 | TrackingScopes() {} 50 | }; 51 | 52 | template 53 | class TrackingScopes { 54 | typename ScopedTrackingTraits::scope_type Scope; 55 | TrackingScopes OtherScopes; 56 | public: 57 | TrackingScopes(Tracker &tracker, OtherTrackers &...otherTrackers) 58 | : Scope(tracker), OtherScopes(otherTrackers...) {} 59 | }; 60 | 61 | } // end namespace swift 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/GraphNodeWorklist.h: -------------------------------------------------------------------------------- 1 | //===--- GraphNodeWorklist.h ------------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_GRAPHNODEWORKLIST_H 14 | #define SWIFT_BASIC_GRAPHNODEWORKLIST_H 15 | 16 | #include "swift/Basic/LLVM.h" 17 | #include "llvm/ADT/SmallPtrSet.h" 18 | #include "llvm/ADT/SmallVector.h" 19 | 20 | /// Worklist of pointer-like things that have an invalid default value. This not 21 | /// only avoids duplicates in the worklist, but also avoids revisiting 22 | /// already-popped nodes. This makes it suitable for DAG traversal. This can 23 | /// also be used within hybrid worklist/recursive traversal by recording the 24 | /// size of the worklist at each level of recursion. 25 | /// 26 | /// The primary API has two methods: intialize() and pop(). Others are provided 27 | /// for flexibility. 28 | template 29 | struct GraphNodeWorklist { 30 | llvm::SmallPtrSet nodeVisited; 31 | llvm::SmallVector nodeVector; 32 | 33 | GraphNodeWorklist() = default; 34 | 35 | GraphNodeWorklist(const GraphNodeWorklist &) = delete; 36 | 37 | void initialize(T t) { 38 | clear(); 39 | insert(t); 40 | } 41 | 42 | template 43 | void initializeRange(R &&range) { 44 | clear(); 45 | nodeVisited.insert(range.begin(), range.end()); 46 | nodeVector.append(range.begin(), range.end()); 47 | } 48 | 49 | T pop() { return empty() ? T() : nodeVector.pop_back_val(); } 50 | 51 | bool empty() const { return nodeVector.empty(); } 52 | 53 | unsigned size() const { return nodeVector.size(); } 54 | 55 | void clear() { 56 | nodeVector.clear(); 57 | nodeVisited.clear(); 58 | } 59 | 60 | void insert(T t) { 61 | if (nodeVisited.insert(t).second) 62 | nodeVector.push_back(t); 63 | } 64 | }; 65 | 66 | #endif // SWIFT_BASIC_GRAPHNODEWORKLIST_H 67 | -------------------------------------------------------------------------------- /cmake/iCDumpGit.cmake: -------------------------------------------------------------------------------- 1 | if(__add_icdump_git) 2 | return() 3 | endif() 4 | set(__add_icdump_git ON) 5 | 6 | execute_process( 7 | COMMAND ${GIT_EXECUTABLE} log -1 --format=%h 8 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 9 | OUTPUT_VARIABLE ICDUMP_COMMIT_HASH 10 | OUTPUT_STRIP_TRAILING_WHITESPACE 11 | ) 12 | 13 | execute_process( 14 | COMMAND ${GIT_EXECUTABLE} rev-list --count ${ICDUMP_COMMIT_HASH} 15 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 16 | OUTPUT_VARIABLE ICDUMP_COMMIT_COUNT 17 | OUTPUT_STRIP_TRAILING_WHITESPACE 18 | ) 19 | 20 | execute_process( 21 | COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 --tags HEAD --always 22 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 23 | OUTPUT_VARIABLE ICDUMP_GIT_TAG 24 | OUTPUT_STRIP_TRAILING_WHITESPACE 25 | ) 26 | 27 | execute_process( 28 | COMMAND ${GIT_EXECUTABLE} tag --list --points-at=HEAD 29 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 30 | OUTPUT_VARIABLE ICDUMP_GIT_COMMIT_TAGGED 31 | OUTPUT_STRIP_TRAILING_WHITESPACE 32 | ) 33 | 34 | execute_process( 35 | COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD 36 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 37 | OUTPUT_VARIABLE ICDUMP_GIT_BRANCH 38 | OUTPUT_STRIP_TRAILING_WHITESPACE 39 | ) 40 | 41 | string(COMPARE NOTEQUAL "${ICDUMP_GIT_COMMIT_TAGGED}" "" ICDUMP_IS_TAGGED) 42 | 43 | string(REGEX MATCHALL "([0-9]+)" VERSION_STRING "${ICDUMP_GIT_TAG}") 44 | 45 | message(STATUS "Tagged: ${ICDUMP_IS_TAGGED}") 46 | if (${ICDUMP_IS_TAGGED}) 47 | message(STATUS "Tag: ${ICDUMP_GIT_TAG}") 48 | else() 49 | if(ICDUMP_GIT_BRANCH MATCHES "^release-") 50 | string(REGEX MATCHALL "([0-9]+)" VERSION_STRING "${ICDUMP_GIT_BRANCH}") 51 | message(STATUS "${VERSION_STRING}") 52 | endif() 53 | endif() 54 | message(STATUS "Current branch: ${ICDUMP_GIT_BRANCH}") 55 | 56 | 57 | if (VERSION_STRING) 58 | list(GET VERSION_STRING 0 ICDUMP_VERSION_MAJOR) 59 | list(GET VERSION_STRING 1 ICDUMP_VERSION_MINOR) 60 | list(GET VERSION_STRING 2 ICDUMP_VERSION_PATCH) 61 | 62 | if (NOT ${ICDUMP_IS_TAGGED}) 63 | if(ICDUMP_GIT_BRANCH MATCHES "^release-") 64 | message(STATUS "Release branch") 65 | else() 66 | MATH(EXPR ICDUMP_VERSION_MINOR "${ICDUMP_VERSION_MINOR}+1") 67 | set(ICDUMP_VERSION_PATCH 0) 68 | endif() 69 | endif() 70 | else() 71 | set(ICDUMP_VERSION_MAJOR 0) 72 | set(ICDUMP_VERSION_MINOR 0) 73 | set(ICDUMP_VERSION_PATCH 0) 74 | endif() 75 | 76 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsCommon.h: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsCommon.h - Shared Diagnostic Definitions ----*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | /// \file 14 | /// This file defines common diagnostics for the whole compiler, as well 15 | /// as some diagnostic infrastructure. 16 | // 17 | //===----------------------------------------------------------------------===// 18 | 19 | #ifndef SWIFT_DIAGNOSTICSCOMMON_H 20 | #define SWIFT_DIAGNOSTICSCOMMON_H 21 | 22 | #include "swift/AST/DiagnosticEngine.h" 23 | #include "swift/Basic/LLVM.h" 24 | #include "swift/Config.h" 25 | 26 | namespace swift { 27 | template 28 | struct Diag; 29 | 30 | namespace detail { 31 | // These templates are used to help extract the type arguments of the 32 | // DIAG/ERROR/WARNING/NOTE/REMARK/FIXIT macros. 33 | template 34 | struct DiagWithArguments; 35 | 36 | template 37 | struct DiagWithArguments { 38 | typedef Diag type; 39 | }; 40 | 41 | template 42 | struct StructuredFixItWithArguments; 43 | 44 | template 45 | struct StructuredFixItWithArguments { 46 | typedef StructuredFixIt type; 47 | }; 48 | } // end namespace detail 49 | 50 | enum class StaticSpellingKind : uint8_t; 51 | 52 | namespace diag { 53 | 54 | enum class RequirementKind : uint8_t; 55 | 56 | using DeclAttribute = const DeclAttribute *; 57 | 58 | // Declare common diagnostics objects with their appropriate types. 59 | #define DIAG(KIND,ID,Options,Text,Signature) \ 60 | extern detail::DiagWithArguments::type ID; 61 | #define FIXIT(ID, Text, Signature) \ 62 | extern detail::StructuredFixItWithArguments::type ID; 63 | #include "DiagnosticsCommon.def" 64 | } // end namespace diag 65 | } // end namespace swift 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/DiagnosticsIDE.def: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticsIDE.def - Diagnostics Text ------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2021 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #define DEFINE_DIAGNOSTIC_MACROS 14 | #include "DefineDiagnosticMacros.h" 15 | 16 | //===----------------------------------------------------------------------===// 17 | 18 | ERROR(ide_async_in_nonasync_context, none, 19 | "async %0 used in a context that does not support concurrency", 20 | (DeclName)) 21 | 22 | // NOTE: This is WARNING because this is emitted for cross actor references with 23 | // non-'Sendable' types. That is optionally ('-warn-concurrency') warning in 24 | // Swift 5.5. 25 | WARNING(ide_cross_actor_reference_swift5, none, 26 | "actor-isolated %0 should only be referenced from inside the actor", 27 | (DeclName)) 28 | 29 | WARNING(ide_redundant_import, none, 30 | "module %0 is already imported", (DeclName)) 31 | 32 | // FIXME: Inform which other 'import' this module came from. 33 | NOTE(ide_redundant_import_indirect, none, 34 | "module %0 is already imported via another module import", (DeclName)) 35 | 36 | WARNING(ide_availability_softdeprecated, Deprecation, 37 | "%select{getter for |setter for |}0%1 will be deprecated" 38 | " in %select{a future version|%select{a future version of %3|%3 %5}4}2" 39 | "%select{|: %6}6", 40 | (unsigned, DeclName, bool, StringRef, bool, llvm::VersionTuple, 41 | StringRef)) 42 | 43 | WARNING(ide_availability_softdeprecated_rename, Deprecation, 44 | "%select{getter for |setter for |}0%1 will be deprecated" 45 | " in %select{a future version|%select{a future version of %3|%3 %5}4}2" 46 | ": renamed to '%6'", 47 | (unsigned, DeclName, bool, StringRef, bool, llvm::VersionTuple, StringRef)) 48 | 49 | //===----------------------------------------------------------------------===// 50 | 51 | #define UNDEFINE_DIAGNOSTIC_MACROS 52 | #include "DefineDiagnosticMacros.h" 53 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/TypeVisitor.h: -------------------------------------------------------------------------------- 1 | //===--- TypeVisitor.h - Type Visitor ---------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines the TypeVisitor class. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | #ifndef SWIFT_AST_TYPEVISITOR_H 18 | #define SWIFT_AST_TYPEVISITOR_H 19 | 20 | #include "swift/AST/Types.h" 21 | #include "llvm/Support/ErrorHandling.h" 22 | 23 | namespace swift { 24 | 25 | /// TypeVisitor - This is a simple visitor class for Swift types. 26 | template 27 | class TypeVisitor { 28 | public: 29 | 30 | RetTy visit(Type T, Args... args) { 31 | switch (T->getKind()) { 32 | #define TYPE(CLASS, PARENT) \ 33 | case TypeKind::CLASS: \ 34 | return static_cast(this) \ 35 | ->visit##CLASS##Type(static_cast(T.getPointer()), \ 36 | ::std::forward(args)...); 37 | #include "swift/AST/TypeNodes.def" 38 | } 39 | llvm_unreachable("Not reachable, all cases handled"); 40 | } 41 | 42 | // Provide default implementations of abstract "visit" implementations that 43 | // just chain to their base class. This allows visitors to just implement 44 | // the base behavior and handle all subclasses if they desire. Since this is 45 | // a template, it will only instantiate cases that are used and thus we still 46 | // require full coverage of the AST nodes by the visitor. 47 | #define ABSTRACT_TYPE(CLASS, PARENT) \ 48 | RetTy visit##CLASS##Type(CLASS##Type *T, Args... args) { \ 49 | return static_cast(this) \ 50 | ->visit##PARENT(T, std::forward(args)...); \ 51 | } 52 | #define TYPE(CLASS, PARENT) ABSTRACT_TYPE(CLASS, PARENT) 53 | #include "swift/AST/TypeNodes.def" 54 | 55 | }; 56 | 57 | } // end namespace swift 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/SwiftNameTranslation.h: -------------------------------------------------------------------------------- 1 | //===--- SwiftNameTranslation.h - Swift Name Translation --------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_NAME_TRANSLATION_H 14 | #define SWIFT_NAME_TRANSLATION_H 15 | 16 | #include "swift/AST/Identifier.h" 17 | #include "swift/AST/AttrKind.h" 18 | 19 | namespace swift { 20 | class ValueDecl; 21 | class EnumDecl; 22 | class EnumElementDecl; 23 | 24 | namespace objc_translation { 25 | enum CustomNamesOnly_t : bool { 26 | Normal = false, 27 | CustomNamesOnly = true, 28 | }; 29 | 30 | StringRef getNameForObjC(const ValueDecl *VD, 31 | CustomNamesOnly_t customNamesOnly = Normal); 32 | 33 | std::string getErrorDomainStringForObjC(const EnumDecl *ED); 34 | 35 | /// Print the ObjC name of an enum element decl to OS, also allowing the client 36 | /// to specify a preferred name other than the decl's original name. 37 | /// 38 | /// Returns true if the decl has a custom ObjC name (@objc); false otherwise. 39 | bool printSwiftEnumElemNameInObjC(const EnumElementDecl *EL, 40 | llvm::raw_ostream &OS, 41 | Identifier PreferredName = Identifier()); 42 | 43 | /// Get the name for a value decl D if D is exported to ObjC, PreferredName is 44 | /// specified to perform what-if analysis, shadowing D's original name during 45 | /// computation. 46 | /// 47 | /// Returns a pair of Identifier and ObjCSelector, only one of which is valid. 48 | std::pair 49 | getObjCNameForSwiftDecl(const ValueDecl *VD, DeclName PreferredName = DeclName()); 50 | 51 | /// Returns true if the given value decl D is visible to ObjC of its 52 | /// own accord (i.e. without considering its context) 53 | bool isVisibleToObjC(const ValueDecl *VD, AccessLevel minRequiredAccess, 54 | bool checkParent = true); 55 | 56 | } // end namespace objc_translation 57 | } // end namespace swift 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /iCDumpConfig.cmake.in: -------------------------------------------------------------------------------- 1 | 2 | # Process known components 3 | set(iCDump_known_comps STATIC SHARED) 4 | set(iCDump_comp_STATIC NO) 5 | set(iCDump_comp_SHARED NO) 6 | foreach(_comp ${iCDump_FIND_COMPONENTS}) 7 | if(";${iCDump_known_comps};" MATCHES ";${_comp};") 8 | set(iCDump_comp_${_comp} YES) 9 | else() 10 | set(iCDump_NOT_FOUND_MESSAGE 11 | "iCDump does not recognize component `${_comp}`.") 12 | set(iCDump_FOUND FALSE) 13 | return() 14 | endif() 15 | endforeach() 16 | 17 | # Validate component selection makes sense 18 | if(iCDump_comp_STATIC AND iCDump_comp_SHARED) 19 | set(iCDump_NOT_FOUND_MESSAGE 20 | "iCDump `STATIC` and `SHARED` components are mutually exclusive.") 21 | set(iCDump_FOUND FALSE) 22 | return() 23 | endif() 24 | 25 | # These files are generated by CMake and hold the iCDump library target(s). 26 | set(iCDump_static_export "${CMAKE_CURRENT_LIST_DIR}/iCDumpExport-static.cmake") 27 | set(iCDump_shared_export "${CMAKE_CURRENT_LIST_DIR}/iCDumpExport-shared.cmake") 28 | 29 | # Helper macro to load the requested targets, where `lib_type` is `static` or 30 | # `shared` 31 | macro(iCDump_load_targets lib_type) 32 | if(NOT EXISTS "${iCDump_${lib_type}_export}") 33 | set(iCDump_NOT_FOUND_MESSAGE 34 | "iCDump `${lib_type}` libraries were requested but not found.") 35 | set(iCDump_FOUND FALSE) 36 | return() 37 | endif () 38 | 39 | # Include the respective targets file 40 | include("${iCDump_${lib_type}_export}") 41 | endmacro() 42 | 43 | # Run the logic to choose static or shared libraries 44 | # 1. Check components 45 | if(iCDump_comp_STATIC) 46 | iCDump_load_targets("static") 47 | elseif(iCDump_comp_SHARED) 48 | iCDump_load_targets("shared") 49 | # 2. Check iCDump-only library selection 50 | elseif(DEFINED iCDump_SHARED_LIBS AND iCDump_SHARED_LIBS) 51 | iCDump_load_targets("shared") 52 | elseif(DEFINED iCDump_SHARED_LIBS AND NOT iCDump_SHARED_LIBS) 53 | iCDump_load_targets("static") 54 | # 3. Check CMake build type and choose what's available 55 | elseif(BUILD_SHARED_LIBS) 56 | if(EXISTS "${iCDump_shared_export}") 57 | iCDump_load_targets("shared") 58 | else() 59 | iCDump_load_targets("static") 60 | endif() 61 | else() 62 | if(EXISTS "${iCDump_static_export}") 63 | iCDump_load_targets("static") 64 | else() 65 | iCDump_load_targets("shared") 66 | endif() 67 | endif() 68 | 69 | set(iCDump_LIBRARIES iCDump::iCDump) 70 | get_target_property(iCDump_INCLUDE_DIRS iCDump::iCDump INTERFACE_INCLUDE_DIRECTORIES) 71 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/lib/Demangling/DemanglerAssert.h: -------------------------------------------------------------------------------- 1 | //===--- DemanglerAssert.h - Assertions for de/re-mangling ------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file implements a macro, DEMANGLE_ASSERT(), which will assert in the 14 | // compiler, but in the runtime will return a ManglingError on failure. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_DEMANGLING_ASSERT_H 19 | #define SWIFT_DEMANGLING_ASSERT_H 20 | 21 | #include "llvm/Support/Compiler.h" 22 | #include "swift/Demangling/Demangle.h" 23 | #include "swift/Demangling/NamespaceMacros.h" 24 | 25 | #if SWIFT_RUNTIME 26 | 27 | // In the runtime, DEMANGLER_ASSERT() returns an error 28 | #define DEMANGLER_ASSERT(expr, node) \ 29 | do { \ 30 | if (!(expr)) \ 31 | return ManglingError(ManglingError::AssertionFailed, (node), __LINE__); \ 32 | } while (0) 33 | 34 | #elif !defined(NDEBUG) 35 | 36 | // If NDEBUG is not defined, DEMANGLER_ASSERT() works like assert() 37 | #define DEMANGLER_ASSERT(expr, node) \ 38 | do { \ 39 | if (!(expr)) \ 40 | swift::Demangle::failAssert(__FILE__, __LINE__, node, #expr); \ 41 | } while (0) 42 | 43 | #else 44 | 45 | // Otherwise, DEMANGLER_ASSERT() does nothing 46 | #define DEMANGLER_ASSERT(expr, node) 47 | 48 | #endif // SWIFT_RUNTIME 49 | 50 | namespace swift { 51 | namespace Demangle { 52 | SWIFT_BEGIN_INLINE_NAMESPACE 53 | 54 | LLVM_ATTRIBUTE_NORETURN void failAssert(const char *file, unsigned line, 55 | NodePointer node, const char *expr); 56 | 57 | SWIFT_END_INLINE_NAMESPACE 58 | } // end namespace Demangle 59 | } // end namespace swift 60 | 61 | #endif // SWIFT_DEMANGLING_ASSERT_H 62 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/Unicode.h: -------------------------------------------------------------------------------- 1 | //===--- Unicode.h - Unicode utilities --------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_UNICODE_H 14 | #define SWIFT_BASIC_UNICODE_H 15 | 16 | #include "swift/Basic/LLVM.h" 17 | #include "llvm/ADT/StringRef.h" 18 | 19 | namespace swift { 20 | namespace unicode { 21 | 22 | StringRef extractFirstExtendedGraphemeCluster(StringRef S); 23 | 24 | static inline bool isSingleExtendedGraphemeCluster(StringRef S) { 25 | StringRef First = extractFirstExtendedGraphemeCluster(S); 26 | if (First.empty()) 27 | return false; 28 | return First == S; 29 | } 30 | 31 | enum class GraphemeClusterBreakProperty : uint8_t { 32 | Other, 33 | CR, 34 | LF, 35 | Control, 36 | Extend, 37 | Regional_Indicator, 38 | Prepend, 39 | SpacingMark, 40 | L, 41 | V, 42 | T, 43 | LV, 44 | LVT, 45 | }; 46 | 47 | /// Extended grapheme cluster boundary rules, represented as a matrix. Indexed 48 | /// by first code point, then by second code point in least-significant-bit 49 | /// order. A set bit means that a boundary is prohibited between two code 50 | /// points. 51 | extern const uint16_t ExtendedGraphemeClusterNoBoundaryRulesMatrix[]; 52 | 53 | /// Returns the value of the Grapheme_Cluster_Break property for a given code 54 | /// point. 55 | GraphemeClusterBreakProperty getGraphemeClusterBreakProperty(uint32_t C); 56 | 57 | /// Determine if there is an extended grapheme cluster boundary between code 58 | /// points with given Grapheme_Cluster_Break property values. 59 | static inline bool 60 | isExtendedGraphemeClusterBoundary(GraphemeClusterBreakProperty GCB1, 61 | GraphemeClusterBreakProperty GCB2) { 62 | auto RuleRow = 63 | ExtendedGraphemeClusterNoBoundaryRulesMatrix[static_cast(GCB1)]; 64 | return !(RuleRow & (1 << static_cast(GCB2))); 65 | } 66 | 67 | bool isSingleUnicodeScalar(StringRef S); 68 | 69 | unsigned extractFirstUnicodeScalar(StringRef S); 70 | 71 | } // end namespace unicode 72 | } // end namespace swift 73 | 74 | #endif // SWIFT_BASIC_UNICODE_H 75 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/ReferenceCounting.h: -------------------------------------------------------------------------------- 1 | //===--- ReferenceCounting.h ------------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_AST_REFERENCE_COUNTING_H 14 | #define SWIFT_AST_REFERENCE_COUNTING_H 15 | 16 | namespace swift { 17 | 18 | /// The kind of reference counting implementation a heap object uses. 19 | enum class ReferenceCounting : uint8_t { 20 | /// The object uses native Swift reference counting. 21 | Native, 22 | 23 | /// The object uses ObjC reference counting. 24 | /// 25 | /// When ObjC interop is enabled, native Swift class objects are also ObjC 26 | /// reference counting compatible. Swift non-class heap objects are never 27 | /// ObjC reference counting compatible. 28 | /// 29 | /// Blocks are always ObjC reference counting compatible. 30 | ObjC, 31 | 32 | /// The object has no reference counting. This is used by foreign reference 33 | /// types. 34 | None, 35 | 36 | /// The object uses _Block_copy/_Block_release reference counting. 37 | /// 38 | /// This is a strict subset of ObjC; all blocks are also ObjC reference 39 | /// counting compatible. The block is assumed to have already been moved to 40 | /// the heap so that _Block_copy returns the same object back. 41 | Block, 42 | 43 | /// The object has an unknown reference counting implementation. 44 | /// 45 | /// This uses maximally-compatible reference counting entry points in the 46 | /// runtime. 47 | Unknown, 48 | 49 | /// Cases prior to this one are binary-compatible with Unknown reference 50 | /// counting. 51 | LastUnknownCompatible = Unknown, 52 | 53 | /// The object has an unknown reference counting implementation and 54 | /// the reference value may contain extra bits that need to be masked. 55 | /// 56 | /// This uses maximally-compatible reference counting entry points in the 57 | /// runtime, with a masking layer on top. A bit inside the pointer is used 58 | /// to signal native Swift refcounting. 59 | Bridge, 60 | 61 | /// The object uses ErrorType's reference counting entry points. 62 | Error, 63 | }; 64 | 65 | } // end namespace swift 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/ResilienceExpansion.h: -------------------------------------------------------------------------------- 1 | //===--- ResilienceExpansion.h ----------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_AST_RESILIENCE_EXPANSION_H 14 | #define SWIFT_AST_RESILIENCE_EXPANSION_H 15 | 16 | #include "llvm/Support/raw_ostream.h" 17 | 18 | namespace swift { 19 | 20 | /// A specification for how much to expand resilient types. 21 | /// 22 | /// Right now, this is just a placeholder; a proper expansion 23 | /// specification will probably need to be able to express things like 24 | /// 'expand any type that was fragile in at least such-and-such 25 | /// version'. 26 | enum class ResilienceExpansion : unsigned { 27 | /// A minimal expansion does not expand types that do not have a 28 | /// universally fragile representation. This provides a baseline 29 | /// for what all components can possibly support. 30 | /// - All exported functions must be compiled to at least provide 31 | /// a minimally-expanded entrypoint, or else it will be 32 | /// impossible for components that do not have that type 33 | /// to call the function. 34 | /// - Similarly, any sort of abstracted function call must go through 35 | /// a minimally-expanded entrypoint. 36 | /// 37 | /// Minimal expansion will generally pass all resilient types indirectly. 38 | Minimal, 39 | 40 | /// A maximal expansion expands all types with fragile 41 | /// representation, even when they're not universally fragile. This 42 | /// is better when internally manipulating values or when working 43 | /// with specialized entry points for a function. 44 | Maximal, 45 | 46 | Last_ResilienceExpansion = Maximal 47 | }; 48 | 49 | inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os, 50 | ResilienceExpansion expansion) { 51 | switch (expansion) { 52 | case ResilienceExpansion::Minimal: 53 | return os << "Minimal"; 54 | case ResilienceExpansion::Maximal: 55 | return os << "Maximal"; 56 | } 57 | llvm_unreachable("Unhandled ResilienceExpansion in switch"); 58 | } 59 | 60 | } // namespace swift 61 | 62 | #endif // LLVM_SWIFT_AST_CAPTURE_INFO_H 63 | 64 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/KnownSDKTypes.def: -------------------------------------------------------------------------------- 1 | //===--- KnownSDKTypes.def - Common SDK types -----------------------------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2019 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This xmacro generates code for common SDK types the 14 | // compiler has special knowledge of. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef KNOWN_SDK_TYPE_DECL 19 | /// KNOWN_SDK_TYPE_DECL(MODULE, NAME, DECL_CLASS, NUM_GENERIC_ARGS) 20 | /// 21 | /// The macro is expanded for each known SDK type. MODULE is 22 | /// bound to the name of the module the type comes from. NAME is bound to the 23 | /// unqualified name of the type. DECL_CLASS is bound to the Decl subclass it 24 | /// is expected to be an instance of. NUM_GENERIC_ARGS is the number of generic 25 | /// parameters the decl ought to have. 26 | #define KNOWN_SDK_TYPE_DECL(MODULE, NAME, DECL_CLASS, NUM_GENERIC_ARGS) 27 | #endif 28 | 29 | KNOWN_SDK_TYPE_DECL(Foundation, NSCopying, ProtocolDecl, 0) 30 | KNOWN_SDK_TYPE_DECL(Foundation, NSError, ClassDecl, 0) 31 | KNOWN_SDK_TYPE_DECL(Foundation, NSNumber, ClassDecl, 0) 32 | KNOWN_SDK_TYPE_DECL(Foundation, NSValue, ClassDecl, 0) 33 | 34 | KNOWN_SDK_TYPE_DECL(ObjectiveC, NSObject, ClassDecl, 0) 35 | KNOWN_SDK_TYPE_DECL(ObjectiveC, Selector, StructDecl, 0) 36 | KNOWN_SDK_TYPE_DECL(ObjectiveC, ObjCBool, StructDecl, 0) 37 | 38 | // TODO(async): These might move to the stdlib module when concurrency is 39 | // standardized 40 | KNOWN_SDK_TYPE_DECL(Concurrency, UnsafeContinuation, NominalTypeDecl, 2) 41 | KNOWN_SDK_TYPE_DECL(Concurrency, MainActor, NominalTypeDecl, 0) 42 | KNOWN_SDK_TYPE_DECL(Concurrency, UnownedSerialExecutor, NominalTypeDecl, 0) 43 | 44 | KNOWN_SDK_TYPE_DECL(Concurrency, TaskLocal, ClassDecl, 1) 45 | 46 | // Distributed actors 47 | KNOWN_SDK_TYPE_DECL(Distributed, DistributedActor, ProtocolDecl, 0) 48 | KNOWN_SDK_TYPE_DECL(Distributed, ActorIdentity, ProtocolDecl, 0) 49 | KNOWN_SDK_TYPE_DECL(Distributed, AnyActorIdentity, StructDecl, 0) 50 | 51 | // String processing 52 | KNOWN_SDK_TYPE_DECL(StringProcessing, Regex, StructDecl, 1) 53 | KNOWN_SDK_TYPE_DECL(StringProcessing, DynamicCaptures, EnumDecl, 0) 54 | 55 | #undef KNOWN_SDK_TYPE_DECL 56 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/SynthesizedFileUnit.h: -------------------------------------------------------------------------------- 1 | //===--- SynthesizedFileUnit.h - A synthesized file unit --------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2020 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_AST_SYNTHESIZEDFILEUNIT_H 14 | #define SWIFT_AST_SYNTHESIZEDFILEUNIT_H 15 | 16 | #include "swift/AST/FileUnit.h" 17 | #include "swift/Basic/Debug.h" 18 | 19 | namespace swift { 20 | 21 | /// A container for synthesized declarations, attached to a `SourceFile`. 22 | /// 23 | /// Currently, only module-level synthesized declarations are supported. 24 | class SynthesizedFileUnit final : public FileUnit { 25 | /// The parent source file. 26 | FileUnit &FU; 27 | 28 | /// Synthesized top level declarations. 29 | TinyPtrVector TopLevelDecls; 30 | 31 | /// A unique identifier representing this file; used to mark private decls 32 | /// within the file to keep them from conflicting with other files in the 33 | /// same module. 34 | mutable Identifier PrivateDiscriminator; 35 | 36 | public: 37 | SynthesizedFileUnit(FileUnit &FU); 38 | ~SynthesizedFileUnit() = default; 39 | 40 | /// Returns the parent source file. 41 | FileUnit &getFileUnit() const { return FU; } 42 | 43 | /// Add a synthesized top-level declaration. 44 | void addTopLevelDecl(Decl *D) { TopLevelDecls.push_back(D); } 45 | 46 | virtual void lookupValue(DeclName name, NLKind lookupKind, 47 | SmallVectorImpl &result) const override; 48 | 49 | void lookupObjCMethods( 50 | ObjCSelector selector, 51 | SmallVectorImpl &results) const override; 52 | 53 | Identifier getDiscriminatorForPrivateValue(const ValueDecl *D) const override; 54 | 55 | void getTopLevelDecls(SmallVectorImpl &results) const override; 56 | 57 | ArrayRef getTopLevelDecls() const { 58 | return TopLevelDecls; 59 | }; 60 | 61 | static bool classof(const FileUnit *file) { 62 | return file->getKind() == FileUnitKind::Synthesized; 63 | } 64 | static bool classof(const DeclContext *DC) { 65 | return isa(DC) && classof(cast(DC)); 66 | } 67 | }; 68 | 69 | } // namespace swift 70 | 71 | #endif // SWIFT_AST_SYNTHESIZEDFILEUNIT_H 72 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/type_traits.h: -------------------------------------------------------------------------------- 1 | //===--- type_traits.h - Type traits ----------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_TYPETRAITS_H 14 | #define SWIFT_BASIC_TYPETRAITS_H 15 | 16 | #include 17 | #include "swift/Basic/Compiler.h" 18 | 19 | #ifndef __has_feature 20 | #define SWIFT_DEFINED_HAS_FEATURE 21 | #define __has_feature(x) 0 22 | #endif 23 | 24 | namespace swift { 25 | 26 | /// Same as \c std::is_trivially_copyable, which we cannot use directly 27 | /// because it is not implemented yet in all C++11 standard libraries. 28 | /// 29 | /// Unlike \c llvm::isPodLike, this trait should produce a precise result and 30 | /// is not intended to be specialized. 31 | template 32 | struct IsTriviallyCopyable { 33 | #if defined(_LIBCPP_VERSION) || SWIFT_COMPILER_IS_MSVC 34 | // libc++ and MSVC implement is_trivially_copyable. 35 | static const bool value = std::is_trivially_copyable::value; 36 | #elif __has_feature(is_trivially_copyable) || __GNUC__ >= 5 37 | static const bool value = __is_trivially_copyable(T); 38 | #else 39 | # error "Not implemented" 40 | #endif 41 | }; 42 | 43 | template 44 | struct IsTriviallyConstructible { 45 | #if defined(_LIBCPP_VERSION) || SWIFT_COMPILER_IS_MSVC 46 | // libc++ and MSVC implement is_trivially_constructible. 47 | static const bool value = std::is_trivially_constructible::value; 48 | #elif __has_feature(has_trivial_constructor) || __GNUC__ >= 5 49 | static const bool value = __has_trivial_constructor(T); 50 | #else 51 | # error "Not implemented" 52 | #endif 53 | }; 54 | 55 | template 56 | struct IsTriviallyDestructible { 57 | #if defined(_LIBCPP_VERSION) || SWIFT_COMPILER_IS_MSVC 58 | // libc++ and MSVC implement is_trivially_destructible. 59 | static const bool value = std::is_trivially_destructible::value; 60 | #elif __has_feature(has_trivial_destructor) || __GNUC__ >= 5 61 | static const bool value = __has_trivial_destructor(T); 62 | #else 63 | # error "Not implemented" 64 | #endif 65 | }; 66 | 67 | } // end namespace swift 68 | 69 | #ifdef SWIFT_DEFINED_HAS_FEATURE 70 | #undef __has_feature 71 | #endif 72 | 73 | #endif // SWIFT_BASIC_TYPETRAITS_H 74 | -------------------------------------------------------------------------------- /src/log.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 R. Thomas 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #pragma once 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define ICDUMP_TRACE(...) iCDump::Logger::trace(__VA_ARGS__) 23 | #define ICDUMP_DEBUG(...) iCDump::Logger::debug(__VA_ARGS__) 24 | #define ICDUMP_INFO(...) iCDump::Logger::info(__VA_ARGS__) 25 | #define ICDUMP_WARN(...) iCDump::Logger::warn(__VA_ARGS__) 26 | #define ICDUMP_ERR(...) iCDump::Logger::err(__VA_ARGS__) 27 | 28 | namespace iCDump { 29 | class Logger { 30 | public: 31 | enum class LEVEL { 32 | TRACE, 33 | DEBUG, 34 | INFO, 35 | WARN, 36 | ERR, 37 | CRITICAL, 38 | }; 39 | Logger(const Logger&) = delete; 40 | Logger& operator=(const Logger&) = delete; 41 | 42 | static Logger& instance(); 43 | 44 | static void set_level(LEVEL lvl); 45 | 46 | static void disable(); 47 | 48 | static void enable(); 49 | 50 | template 51 | static void trace(const char *fmt, const Args &... args) { 52 | Logger::instance().sink_->trace(fmt, args...); 53 | } 54 | 55 | template 56 | static void debug(const char *fmt, const Args &... args) { 57 | Logger::instance().sink_->debug(fmt, args...); 58 | } 59 | 60 | template 61 | static void info(const char *fmt, const Args &... args) { 62 | Logger::instance().sink_->info(fmt, args...); 63 | } 64 | 65 | template 66 | static void err(const char *fmt, const Args &... args) { 67 | Logger::instance().sink_->error(fmt, args...); 68 | } 69 | 70 | template 71 | static void warn(const char *fmt, const Args &... args) { 72 | Logger::instance().sink_->warn(fmt, args...); 73 | } 74 | 75 | ~Logger(); 76 | private: 77 | Logger(void); 78 | Logger(Logger&&); 79 | Logger& operator=(Logger&&); 80 | 81 | static void destroy(void); 82 | inline static Logger* instance_ = nullptr; 83 | std::shared_ptr sink_; 84 | }; 85 | } 86 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/TypeMemberVisitor.h: -------------------------------------------------------------------------------- 1 | //===--- TypeMemberVisitor.h - ASTVisitor specialization --------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines the curiously-recursive TypeMemberVisitor class 14 | // and a few specializations thereof. 15 | // 16 | //===----------------------------------------------------------------------===// 17 | 18 | #ifndef SWIFT_AST_TYPEMEMBERVISITOR_H 19 | #define SWIFT_AST_TYPEMEMBERVISITOR_H 20 | 21 | #include "swift/AST/ASTVisitor.h" 22 | 23 | namespace swift { 24 | 25 | /// TypeMemberVisitor - This is a convenience adapter of DeclVisitor 26 | /// which filters out a few common declaration kinds that are never 27 | /// members of nominal types. 28 | template 29 | class TypeMemberVisitor : public DeclVisitor { 30 | protected: 31 | ImplClass &asImpl() { return static_cast(*this); } 32 | 33 | public: 34 | #define BAD_MEMBER(KIND) \ 35 | RetTy visit##KIND##Decl(KIND##Decl *D) { \ 36 | llvm_unreachable(#KIND "Decls cannot be members of nominal types"); \ 37 | } 38 | BAD_MEMBER(Extension) 39 | BAD_MEMBER(Import) 40 | BAD_MEMBER(Protocol) 41 | BAD_MEMBER(TopLevelCode) 42 | BAD_MEMBER(Operator) 43 | BAD_MEMBER(PrecedenceGroup) 44 | 45 | // The children of these are automatically inserted into the 46 | // surrounding context. 47 | RetTy visitIfConfigDecl(IfConfigDecl *D) { 48 | return RetTy(); 49 | } 50 | 51 | // These decls are disregarded. 52 | RetTy visitPoundDiagnosticDecl(PoundDiagnosticDecl *D) { 53 | return RetTy(); 54 | } 55 | 56 | /// A convenience method to visit all the members. 57 | void visitMembers(NominalTypeDecl *D) { 58 | for (Decl *member : D->getMembers()) { 59 | asImpl().visit(member); 60 | } 61 | } 62 | }; 63 | 64 | template 65 | class ClassMemberVisitor : public TypeMemberVisitor { 66 | public: 67 | BAD_MEMBER(EnumElement) 68 | BAD_MEMBER(EnumCase) 69 | 70 | void visitMembers(ClassDecl *D) { 71 | TypeMemberVisitor::visitMembers(D); 72 | } 73 | }; 74 | 75 | #undef BAD_MEMBER 76 | 77 | } // end namespace swift 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/lib/Demangling/NodeDumper.cpp: -------------------------------------------------------------------------------- 1 | //===--- NodeDumper.cpp - Swift Demangling Debug Dump Functions -----------===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #include "swift/Demangling/Demangle.h" 14 | #include "swift/Demangling/Demangler.h" 15 | #include 16 | 17 | using namespace swift; 18 | using namespace Demangle; 19 | 20 | const char *Demangle::getNodeKindString(swift::Demangle::Node::Kind k) { 21 | switch (k) { 22 | #define NODE(ID) \ 23 | case Node::Kind::ID: \ 24 | return #ID; 25 | #include "swift/Demangling/DemangleNodes.def" 26 | } 27 | return "Demangle::Node::Kind::???"; 28 | } 29 | 30 | static void printNode(DemanglerPrinter &Out, const Node *node, unsigned depth) { 31 | // Indent two spaces per depth. 32 | for (unsigned i = 0; i < depth * 2; ++i) { 33 | Out << ' '; 34 | } 35 | if (!node) { 36 | Out << "<>"; 37 | return; 38 | } 39 | Out << "kind=" << getNodeKindString(node->getKind()); 40 | if (node->hasText()) { 41 | Out << ", text=\"" << node->getText() << '\"'; 42 | } 43 | if (node->hasIndex()) { 44 | Out << ", index=" << node->getIndex(); 45 | } 46 | Out << '\n'; 47 | for (auto &child : *node) { 48 | printNode(Out, child, depth + 1); 49 | } 50 | } 51 | 52 | std::string Demangle::getNodeTreeAsString(NodePointer Root) { 53 | DemanglerPrinter Printer; 54 | printNode(Printer, Root, 0); 55 | return std::move(Printer).str(); 56 | } 57 | 58 | void swift::Demangle::Node::dump() { 59 | std::string TreeStr = getNodeTreeAsString(this); 60 | fputs(TreeStr.c_str(), stderr); 61 | } 62 | 63 | void Demangler::dump() { 64 | for (unsigned Idx = 0; Idx < Substitutions.size(); ++Idx) { 65 | fprintf(stderr, "Substitution[%c]:\n", Idx + 'A'); 66 | Substitutions[Idx]->dump(); 67 | fprintf(stderr, "\n"); 68 | } 69 | 70 | for (unsigned Idx = 0; Idx < NodeStack.size(); ++Idx) { 71 | fprintf(stderr, "NodeStack[%u]:\n", Idx); 72 | NodeStack[Idx]->dump(); 73 | fprintf(stderr, "\n"); 74 | } 75 | fprintf(stderr, "Position = %zd:\n%.*s\n%*s\n", Pos, 76 | (int)Text.size(), Text.data(), (int)Pos + 1, "^"); 77 | } 78 | 79 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/TypeReprNodes.def: -------------------------------------------------------------------------------- 1 | //===--- TypeReprNodes.def - Swift TypeRepr AST Metaprogramming -*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines macros used for macro-metaprogramming with TypeReprs. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | /// TYPEREPR(Id, Parent) 18 | /// The TypeRepr's enumerator value is TypeReprKind::Id. The TypeRepr's 19 | /// class name is Id##TypeRepr, and the name of its base class is Parent. 20 | #ifndef TYPEREPR 21 | # error Included TypeReprNodes.def without defining TYPEREPR! 22 | #endif 23 | 24 | /// An abstract node is an abstract base class in the hierarchy; 25 | /// it is never a most-derived type, and it does not have an enumerator in 26 | /// TypeReprKind. 27 | /// 28 | /// Most metaprograms do not care about abstract classes, so the default 29 | /// is to ignore them. 30 | #ifndef ABSTRACT_TYPEREPR 31 | #define ABSTRACT_TYPEREPR(Id, Parent) 32 | #endif 33 | 34 | #ifndef LAST_TYPEREPR 35 | #define LAST_TYPEREPR(Id) 36 | #endif 37 | 38 | TYPEREPR(Error, TypeRepr) 39 | TYPEREPR(Attributed, TypeRepr) 40 | 41 | ABSTRACT_TYPEREPR(Ident, TypeRepr) 42 | ABSTRACT_TYPEREPR(ComponentIdent, IdentTypeRepr) 43 | TYPEREPR(SimpleIdent, ComponentIdentTypeRepr) 44 | TYPEREPR(GenericIdent, ComponentIdentTypeRepr) 45 | TYPEREPR(CompoundIdent, IdentTypeRepr) 46 | 47 | TYPEREPR(Function, TypeRepr) 48 | TYPEREPR(Array, TypeRepr) 49 | TYPEREPR(Dictionary, TypeRepr) 50 | TYPEREPR(Optional, TypeRepr) 51 | TYPEREPR(ImplicitlyUnwrappedOptional, TypeRepr) 52 | TYPEREPR(Tuple, TypeRepr) 53 | TYPEREPR(Composition, TypeRepr) 54 | TYPEREPR(Metatype, TypeRepr) 55 | TYPEREPR(Protocol, TypeRepr) 56 | TYPEREPR(OpaqueReturn, TypeRepr) 57 | TYPEREPR(NamedOpaqueReturn, TypeRepr) 58 | TYPEREPR(Existential, TypeRepr) 59 | TYPEREPR(Placeholder, TypeRepr) 60 | ABSTRACT_TYPEREPR(Specifier, TypeRepr) 61 | TYPEREPR(InOut, SpecifierTypeRepr) 62 | TYPEREPR(Shared, SpecifierTypeRepr) 63 | TYPEREPR(Owned, SpecifierTypeRepr) 64 | TYPEREPR(Isolated, SpecifierTypeRepr) 65 | TYPEREPR(CompileTimeConst, SpecifierTypeRepr) 66 | TYPEREPR(Fixed, TypeRepr) 67 | TYPEREPR(SILBox, TypeRepr) 68 | LAST_TYPEREPR(SILBox) 69 | 70 | #undef ABSTRACT_TYPEREPR 71 | #undef TYPEREPR 72 | #undef LAST_TYPEREPR 73 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/RawComment.h: -------------------------------------------------------------------------------- 1 | //===--- RawComment.h - Extraction of raw comments --------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_AST_RAW_COMMENT_H 14 | #define SWIFT_AST_RAW_COMMENT_H 15 | 16 | #include "swift/Basic/SourceLoc.h" 17 | #include "llvm/ADT/ArrayRef.h" 18 | #include "llvm/ADT/StringRef.h" 19 | 20 | namespace swift { 21 | 22 | class SourceFile; 23 | class SourceManager; 24 | 25 | struct SingleRawComment { 26 | enum class CommentKind { 27 | OrdinaryLine, ///< Any normal // comments 28 | OrdinaryBlock, ///< Any normal /* */ comment 29 | LineDoc, ///< \code /// stuff \endcode 30 | BlockDoc, ///< \code /** stuff */ \endcode 31 | }; 32 | 33 | CharSourceRange Range; 34 | StringRef RawText; 35 | 36 | unsigned Kind : 8; 37 | unsigned ColumnIndent : 16; 38 | 39 | SingleRawComment(CharSourceRange Range, const SourceManager &SourceMgr); 40 | SingleRawComment(StringRef RawText, unsigned ColumnIndent); 41 | 42 | SingleRawComment(const SingleRawComment &) = default; 43 | SingleRawComment &operator=(const SingleRawComment &) = default; 44 | 45 | CommentKind getKind() const LLVM_READONLY { 46 | return static_cast(Kind); 47 | } 48 | 49 | bool isOrdinary() const LLVM_READONLY { 50 | return getKind() == CommentKind::OrdinaryLine || 51 | getKind() == CommentKind::OrdinaryBlock; 52 | } 53 | 54 | bool isLine() const LLVM_READONLY { 55 | return getKind() == CommentKind::OrdinaryLine || 56 | getKind() == CommentKind::LineDoc; 57 | } 58 | 59 | bool isGyb() const { 60 | return RawText.startswith("// ###"); 61 | } 62 | }; 63 | 64 | struct RawComment { 65 | ArrayRef Comments; 66 | 67 | RawComment() {} 68 | RawComment(ArrayRef Comments) : Comments(Comments) {} 69 | 70 | RawComment(const RawComment &) = default; 71 | RawComment &operator=(const RawComment &) = default; 72 | 73 | bool isEmpty() const { 74 | return Comments.empty(); 75 | } 76 | 77 | CharSourceRange getCharSourceRange(); 78 | }; 79 | 80 | struct CommentInfo { 81 | StringRef Brief; 82 | RawComment Raw; 83 | uint32_t Group; 84 | uint32_t SourceOrder; 85 | }; 86 | 87 | } // namespace swift 88 | 89 | #endif // LLVM_SWIFT_AST_RAW_COMMENT_H 90 | 91 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/AST/StmtNodes.def: -------------------------------------------------------------------------------- 1 | //===--- StmtNodes.def - Swift Statement AST Metaprogramming ----*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | // 13 | // This file defines macros used for macro-metaprogramming with statements. 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | /// STMT(Id, Parent) 18 | /// If the statement node is not abstract, its enumerator value is 19 | /// StmtKind::Id. The node's class name is Id##Stmt, and the name of 20 | /// its base class (in the Stmt hierarchy) is Parent. 21 | 22 | /// An abstract statement node is an abstract base class in the hierarchy; 23 | /// it is never a most-derived type, and it does not have an enumerator in 24 | /// StmtKind. 25 | /// 26 | /// Most metaprograms do not care about abstract statements, so the default 27 | /// is to ignore them. 28 | #ifndef ABSTRACT_STMT 29 | #define ABSTRACT_STMT(Id, Parent) 30 | #endif 31 | 32 | /// A subclass of LabeledStmt. Forwards to STMT by default. 33 | #ifndef LABELED_STMT 34 | #define LABELED_STMT(Id, Parent) STMT(Id, Parent) 35 | #endif 36 | 37 | /// A convenience for determining the range of statements. These will always 38 | /// appear immediately after the last member. 39 | #ifndef STMT_RANGE 40 | #define STMT_RANGE(Id, First, Last) 41 | #endif 42 | 43 | #ifndef LAST_STMT 44 | #define LAST_STMT(Id) 45 | #endif 46 | 47 | STMT(Brace, Stmt) 48 | STMT(Return, Stmt) 49 | STMT(Yield, Stmt) 50 | STMT(Defer, Stmt) 51 | ABSTRACT_STMT(Labeled, Stmt) 52 | ABSTRACT_STMT(LabeledConditional, LabeledStmt) 53 | LABELED_STMT(If, LabeledConditionalStmt) 54 | LABELED_STMT(Guard, LabeledConditionalStmt) 55 | LABELED_STMT(While, LabeledConditionalStmt) 56 | STMT_RANGE(LabeledConditional, If, While) 57 | LABELED_STMT(Do, LabeledStmt) 58 | LABELED_STMT(DoCatch, LabeledStmt) 59 | LABELED_STMT(RepeatWhile, LabeledStmt) 60 | LABELED_STMT(ForEach, LabeledStmt) 61 | LABELED_STMT(Switch, LabeledStmt) 62 | STMT_RANGE(Labeled, If, Switch) 63 | STMT(Case, Stmt) 64 | STMT(Break, Stmt) 65 | STMT(Continue, Stmt) 66 | STMT(Fallthrough, Stmt) 67 | STMT(Fail, Stmt) 68 | STMT(Throw, Stmt) 69 | STMT(PoundAssert, Stmt) 70 | LAST_STMT(PoundAssert) 71 | 72 | #undef STMT_RANGE 73 | #undef LABELED_STMT 74 | #undef ABSTRACT_STMT 75 | #undef STMT 76 | #undef LAST_STMT 77 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/IndexTrie.h: -------------------------------------------------------------------------------- 1 | //===--- IndexTrie - Trie for a sequence of integer indices ----*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_SILOPTIMIZER_UTILS_INDEXTREE_H 14 | #define SWIFT_SILOPTIMIZER_UTILS_INDEXTREE_H 15 | 16 | #include "swift/Basic/LLVM.h" 17 | #include "llvm/ADT/ArrayRef.h" 18 | #include "llvm/ADT/SmallVector.h" 19 | #include 20 | 21 | namespace swift { 22 | 23 | // Trie node representing a sequence of unsigned integer indices. 24 | class IndexTrieNode { 25 | public: 26 | static const int RootIndex = std::numeric_limits::min(); 27 | 28 | private: 29 | int Index; 30 | llvm::SmallVector Children; 31 | IndexTrieNode *Parent; 32 | 33 | public: 34 | IndexTrieNode() : Index(RootIndex), Parent(nullptr) {} 35 | 36 | explicit IndexTrieNode(int V, IndexTrieNode *P) : Index(V), Parent(P) {} 37 | 38 | IndexTrieNode(IndexTrieNode &) =delete; 39 | IndexTrieNode &operator=(const IndexTrieNode&) =delete; 40 | 41 | ~IndexTrieNode() { 42 | for (auto *N : Children) 43 | delete N; 44 | } 45 | 46 | bool isRoot() const { return Index == RootIndex; } 47 | 48 | bool isLeaf() const { return Children.empty(); } 49 | 50 | int getIndex() const { return Index; } 51 | 52 | IndexTrieNode *getChild(int Idx) { 53 | assert(Idx != RootIndex); 54 | 55 | auto I = 56 | std::lower_bound(Children.begin(), Children.end(), Idx, 57 | [](IndexTrieNode *a, int i) { return a->Index < i; }); 58 | if (I != Children.end() && (*I)->Index == Idx) 59 | return *I; 60 | auto *N = new IndexTrieNode(Idx, this); 61 | Children.insert(I, N); 62 | return N; 63 | } 64 | 65 | ArrayRef getChildren() const { return Children; } 66 | 67 | IndexTrieNode *getParent() const { return Parent; } 68 | 69 | /// Returns true when the sequence of indices represented by this 70 | /// node is a prefix of the sequence represented by the passed-in node. 71 | bool isPrefixOf(const IndexTrieNode *Other) const { 72 | const IndexTrieNode *I = Other; 73 | 74 | do { 75 | if (this == I) 76 | return true; 77 | 78 | I = I->getParent(); 79 | } while (I); 80 | 81 | return false; 82 | } 83 | }; 84 | 85 | } // end namespace swift 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/llvm-swift/swift/include/swift/Basic/PrimarySpecificPaths.h: -------------------------------------------------------------------------------- 1 | //===--- PrimarySpecificPaths.h ---------------------------------*- C++ -*-===// 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See https://swift.org/LICENSE.txt for license information 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef SWIFT_BASIC_PRIMARYSPECIFICPATHS_H 14 | #define SWIFT_BASIC_PRIMARYSPECIFICPATHS_H 15 | 16 | #include "swift/Basic/LLVM.h" 17 | #include "swift/Basic/SupplementaryOutputPaths.h" 18 | #include "llvm/ADT/StringRef.h" 19 | 20 | #include 21 | 22 | namespace swift { 23 | 24 | /// Holds all of the output paths, and debugging-info path that are 25 | /// specific to which primary file is being compiled at the moment. 26 | 27 | class PrimarySpecificPaths { 28 | public: 29 | /// The name of the main output file, 30 | /// that is, the .o file for this input (or a file specified by -o). 31 | /// If there is no such file, contains an empty string. If the output 32 | /// is to be written to stdout, contains "-". 33 | std::string OutputFilename; 34 | 35 | /// The name to report the main output file as being in the index store. 36 | /// This is equivalent to OutputFilename, unless -index-store-output-path 37 | /// was specified. 38 | std::string IndexUnitOutputFilename; 39 | 40 | SupplementaryOutputPaths SupplementaryOutputs; 41 | 42 | /// The name of the "main" input file, used by the debug info. 43 | std::string MainInputFilenameForDebugInfo; 44 | 45 | PrimarySpecificPaths(StringRef OutputFilename = StringRef(), 46 | StringRef IndexUnitOutputFilename = StringRef(), 47 | StringRef MainInputFilenameForDebugInfo = StringRef(), 48 | SupplementaryOutputPaths SupplementaryOutputs = 49 | SupplementaryOutputPaths()) 50 | : OutputFilename(OutputFilename), 51 | IndexUnitOutputFilename(IndexUnitOutputFilename), 52 | SupplementaryOutputs(SupplementaryOutputs), 53 | MainInputFilenameForDebugInfo(MainInputFilenameForDebugInfo) {} 54 | 55 | bool haveModuleOrModuleDocOutputPaths() const { 56 | return !SupplementaryOutputs.ModuleOutputPath.empty() || 57 | !SupplementaryOutputs.ModuleDocOutputPath.empty(); 58 | } 59 | bool haveModuleSummaryOutputPath() const { 60 | return !SupplementaryOutputs.ModuleSummaryOutputPath.empty(); 61 | } 62 | }; 63 | } // namespace swift 64 | 65 | #endif // SWIFT_BASIC_PRIMARYSPECIFICPATHS_H 66 | --------------------------------------------------------------------------------