Skip to content

[llvm] Import new LLVM support files #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions Utilities/import-llvm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# NOTE: We have slightly modified copies of some of the files, to reduce the
# dependency surface area, so if you run this to update the sources, please
# examine the diffs to remove things that don't make sense.
# examine the diffs to remove things that don't make sense and update 'llvm-patch.diff'.

import errno
import optparse
Expand All @@ -19,7 +19,7 @@ ADT_imports = ['EpochTracker', 'iterator', 'iterator_range', 'Hashing', 'None',
'Statistic', 'StringExtras', 'STLExtras', 'AllocatorList', 'Triple']

# ADT basic data structures.
ADT_imports += ['APFloat', 'APInt', 'APSInt', 'ArrayRef', 'PointerIntPair', 'SetVector', 'StringRef', 'StringSwitch',
ADT_imports += ['APFloat', 'APInt', 'APSInt', 'ArrayRef', 'bit', 'PointerIntPair', 'SetVector', 'StringRef', 'StringSwitch',
'Twine', 'IntrusiveRefCntPtr', 'ilist', 'ilist_base', 'ilist_node', 'ilist_node_base',
'ilist_node_options', 'ilist_iterator', 'simple_ilist', 'OptionSet', 'PointerUnion']

Expand All @@ -35,11 +35,11 @@ ADT_imports += ['edit_distance']
# Support types and infrastructure.
Support_imports = [
'AlignOf', 'Allocator', 'Atomic', 'CBindingWrapping', 'Casting', 'Capacity', 'CommandLine', 'Compiler',
'Endian', 'Errno', 'ErrorHandling', 'Errc', 'ErrorOr', 'Error', 'Format',
'Endian', 'Errno', 'ErrorHandling', 'Errc', 'ErrorOr', 'Error', 'Format', 'FormatAdapters',
'ManagedStatic', 'MathExtras', 'Mutex', 'MutexGuard', 'Memory',
'MemoryBuffer', 'PointerLikeTypeTraits', 'Recycler', 'SwapByteOrder',
'Timer', 'TimeValue', 'Threading', 'Unicode', 'UniqueLock', 'Unix', 'WindowsError',
'Valgrind', 'circular_raw_ostream', 'raw_ostream', 'type_traits', 'JSON']
'Valgrind', 'circular_raw_ostream', 'raw_ostream', 'Signposts', 'type_traits', 'JSON']

# Stuff we don't want, but have to pull in.
Support_imports += [
Expand All @@ -49,23 +49,24 @@ Support_imports += [
'MemAlloc', 'Chrono', 'FormatProviders', 'FormatVariadic', 'FormatCommon',
'FormatVariadicDetails', 'NativeFormatting', 'DJB', 'ReverseIteration', 'MD5',
'SmallVectorMemoryBuffer', 'WithColor', 'Options', 'PrettyStackTrace', 'Watchdog',
'TargetParser', 'ARMBuildAttributes', 'ARMTargetParser.def', 'AArch64TargetParser.def', 'X86TargetParser.def', 'LineIterator']
'TargetParser', 'ARMBuildAttributes', 'ARMTargetParser', 'AArch64TargetParser',
'ARMTargetParser.def', 'AArch64TargetParser.def', 'X86TargetParser.def', 'LineIterator']

# Dependencies from llvm-c needed by Support.
C_imports = ['Types', 'DataTypes', 'Support', 'ErrorHandling']
C_imports = ['Types', 'DataTypes', 'Support', 'Error', 'ErrorHandling']

# Support data structures.
Support_imports += ['YAMLParser', 'YAMLTraits']

# Source files to exclude.
Support_source_excludes = set(['Host'])
Support_source_excludes = set([])

llvm_srcroot = None
sourcekit_srcroot = None
indexstoredb_srcroot = None

def note(msg):
msg = msg.replace(llvm_srcroot, "<LLVM>")
msg = msg.replace(sourcekit_srcroot, "<INDEXSTOREDB>")
msg = msg.replace(indexstoredb_srcroot, "<INDEXSTOREDB>")
print >>sys.stderr, "note: %s" % (msg,)

def mkdir_p(path):
Expand Down Expand Up @@ -133,32 +134,32 @@ def main():
if len(args) != 1:
parser.error("unexpected number of arguments")

global llvm_srcroot, sourcekit_srcroot
global llvm_srcroot, indexstoredb_srcroot
llvm_srcroot, = args
sourcekit_srcroot = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
indexstoredb_srcroot = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

def import_header(dir, name):
src = os.path.join(llvm_srcroot, 'include', 'llvm', dir, name)
if os.path.exists(src):
dst = os.path.join(sourcekit_srcroot, 'include', 'llvm', dir, name)
dst = os.path.join(indexstoredb_srcroot, 'include', 'llvm', dir, name)
mkdir_p(os.path.dirname(dst))
copyfile(src, dst)

def import_c_header(name):
src = os.path.join(llvm_srcroot, 'include', 'llvm-c', name)
if os.path.exists(src):
dst = os.path.join(sourcekit_srcroot, 'include', 'llvm-c', name)
dst = os.path.join(indexstoredb_srcroot, 'include', 'llvm-c', name)
mkdir_p(os.path.dirname(dst))
copyfile(src, dst)

def import_source(dir, name):
src = os.path.join(llvm_srcroot, 'lib', dir, name)
if os.path.exists(src):
dst = os.path.join(sourcekit_srcroot, 'lib', 'LLVMSupport', dir, name)
dst = os.path.join(indexstoredb_srcroot, 'lib', 'LLVMSupport', dir, name)
mkdir_p(os.path.dirname(dst))
copyfile(src, dst)

print "note: importing from %r to %r" % (llvm_srcroot, sourcekit_srcroot)
print "note: importing from %r to %r" % (llvm_srcroot, indexstoredb_srcroot)

for name in ADT_imports:
import_header('ADT', name+'.h')
Expand All @@ -175,6 +176,8 @@ def main():
import_source('Support', name+'.cpp')
import_source('Support', os.path.join('Unix', name+'.h'))
import_source('Support', os.path.join('Unix', name+'.inc'))
import_source('Support', os.path.join('Windows', name+'.h'))
import_source('Support', os.path.join('Windows', name+'.inc'))

for name in C_imports:
import_c_header(name + '.h')
Expand All @@ -183,17 +186,23 @@ def main():
print "Adding prefix header includes"

base_dirs = [
os.path.join(sourcekit_srcroot, 'include', 'llvm'),
os.path.join(sourcekit_srcroot, 'include', 'llvm-c'),
os.path.join(sourcekit_srcroot, 'lib', 'LLVMSupport'),
os.path.join(indexstoredb_srcroot, 'include', 'llvm'),
os.path.join(indexstoredb_srcroot, 'include', 'llvm-c'),
os.path.join(indexstoredb_srcroot, 'lib', 'LLVMSupport'),
]

include_dir = os.path.join(sourcekit_srcroot, 'include')
include_dir = os.path.join(indexstoredb_srcroot, 'include')

for base in base_dirs:
for root, dirs, files in os.walk(base):
for file in files:
maybe_add_prefix(os.path.join(root, file), include_dir)

print ""
print "Applying patch"

patch_path = os.path.join(indexstoredb_srcroot, 'Utilities', 'llvm-patch.diff'),
subprocess.call("patch -p1 < '%s'" % patch_path, shell=True)

if __name__ == '__main__':
main()
41 changes: 41 additions & 0 deletions Utilities/llvm-patch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
diff --git a/lib/LLVMSupport/Support/AArch64TargetParser.cpp b/lib/LLVMSupport/Support/AArch64TargetParser.cpp
index faf8385c..8772d213 100644
--- a/lib/LLVMSupport/Support/AArch64TargetParser.cpp
+++ b/lib/LLVMSupport/Support/AArch64TargetParser.cpp
@@ -31,7 +31,7 @@ unsigned AArch64::getDefaultFPU(StringRef CPU, AArch64::ArchKind AK) {
return StringSwitch<unsigned>(CPU)
#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
.Case(NAME, ARM::DEFAULT_FPU)
-#include "../../include/llvm/Support/AArch64TargetParser.def"
+#include "llvm/Support/AArch64TargetParser.def"
.Default(ARM::FK_INVALID);
}

@@ -44,7 +44,7 @@ unsigned AArch64::getDefaultExtensions(StringRef CPU, AArch64::ArchKind AK) {
.Case(NAME, AArch64ARCHNames[static_cast<unsigned>(ArchKind::ID)] \
.ArchBaseExtensions | \
DEFAULT_EXT)
-#include "../../include/llvm/Support/AArch64TargetParser.def"
+#include "llvm/Support/AArch64TargetParser.def"
.Default(AArch64::AEK_INVALID);
}

@@ -55,7 +55,7 @@ AArch64::ArchKind AArch64::getCPUArchKind(StringRef CPU) {
return StringSwitch<AArch64::ArchKind>(CPU)
#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
.Case(NAME, ArchKind::ID)
-#include "../../include/llvm/Support/AArch64TargetParser.def"
+#include "llvm/Support/AArch64TargetParser.def"
.Default(ArchKind::INVALID);
}

--- a/include/llvm/Support/YAMLTraits.h
+++ b/include/llvm/Support/YAMLTraits.h
@@ -18,7 +18,6 @@
#include "llvm/Support/AlignOf.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Endian.h"
-#include "llvm/Support/Regex.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/YAMLParser.h"
#include "llvm/Support/raw_ostream.h"
8 changes: 4 additions & 4 deletions include/llvm-c/DataTypes.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*===-- include/llvm-c/DataTypes.h - Define fixed size types ------*- C -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
|* This file is distributed under the University of Illinois Open Source *|
|* License. See LICENSE.TXT for details. *|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|* Exceptions. *|
|* See https://llvm.org/LICENSE.txt for license information. *|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
Expand Down
71 changes: 71 additions & 0 deletions include/llvm-c/Error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*===------- llvm-c/Error.h - llvm::Error class C Interface -------*- C -*-===*\
|* *|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|* Exceptions. *|
|* See https://llvm.org/LICENSE.txt for license information. *|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
|* This file defines the C interface to LLVM's Error class. *|
|* *|
\*===----------------------------------------------------------------------===*/

#ifndef LLVM_C_ERROR_H
#define LLVM_C_ERROR_H

#include "llvm/Config/indexstoredb-prefix.h"

#ifdef __cplusplus
extern "C" {
#endif

#define LLVMErrorSuccess 0

/**
* Opaque reference to an error instance. Null serves as the 'success' value.
*/
typedef struct LLVMOpaqueError *LLVMErrorRef;

/**
* Error type identifier.
*/
typedef const void *LLVMErrorTypeId;

/**
* Returns the type id for the given error instance, which must be a failure
* value (i.e. non-null).
*/
LLVMErrorTypeId LLVMGetErrorTypeId(LLVMErrorRef Err);

/**
* Dispose of the given error without handling it. This operation consumes the
* error, and the given LLVMErrorRef value is not usable once this call returns.
* Note: This method *only* needs to be called if the error is not being passed
* to some other consuming operation, e.g. LLVMGetErrorMessage.
*/
void LLVMConsumeError(LLVMErrorRef Err);

/**
* Returns the given string's error message. This operation consumes the error,
* and the given LLVMErrorRef value is not usable once this call returns.
* The caller is responsible for disposing of the string by calling
* LLVMDisposeErrorMessage.
*/
char *LLVMGetErrorMessage(LLVMErrorRef Err);

/**
* Dispose of the given error message.
*/
void LLVMDisposeErrorMessage(char *ErrMsg);

/**
* Returns the type id for llvm StringError.
*/
LLVMErrorTypeId LLVMGetStringErrorTypeId();

#ifdef __cplusplus
}
#endif

#endif
8 changes: 4 additions & 4 deletions include/llvm-c/ErrorHandling.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*===-- llvm-c/ErrorHandling.h - Error Handling C Interface -------*- C -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
|* This file is distributed under the University of Illinois Open Source *|
|* License. See LICENSE.TXT for details. *|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|* Exceptions. *|
|* See https://llvm.org/LICENSE.txt for license information. *|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
Expand Down
8 changes: 4 additions & 4 deletions include/llvm-c/Support.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*===-- llvm-c/Support.h - Support C Interface --------------------*- C -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
|* This file is distributed under the University of Illinois Open Source *|
|* License. See LICENSE.TXT for details. *|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|* Exceptions. *|
|* See https://llvm.org/LICENSE.txt for license information. *|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
Expand Down
27 changes: 23 additions & 4 deletions include/llvm-c/Types.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*===-- llvm-c/Support.h - C Interface Types declarations ---------*- C -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
|* This file is distributed under the University of Illinois Open Source *|
|* License. See LICENSE.TXT for details. *|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|* Exceptions. *|
|* See https://llvm.org/LICENSE.txt for license information. *|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
Expand Down Expand Up @@ -89,6 +89,20 @@ typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
*/
typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;

/**
* Represents an LLVM Named Metadata Node.
*
* This models llvm::NamedMDNode.
*/
typedef struct LLVMOpaqueNamedMDNode *LLVMNamedMDNodeRef;

/**
* Represents an entry in a Global Object's metadata attachments.
*
* This models std::pair<unsigned, MDNode *>
*/
typedef struct LLVMOpaqueValueMetadataEntry LLVMValueMetadataEntry;

/**
* Represents an LLVM basic block builder.
*
Expand Down Expand Up @@ -149,6 +163,11 @@ typedef struct LLVMOpaqueModuleFlagEntry LLVMModuleFlagEntry;
*/
typedef struct LLVMOpaqueJITEventListener *LLVMJITEventListenerRef;

/**
* @see llvm::object::Binary
*/
typedef struct LLVMOpaqueBinary *LLVMBinaryRef;

/**
* @}
*/
Expand Down
Loading