Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge changes I72d37b7c,I7d254a10,I2e967acf
Browse files Browse the repository at this point in the history
* changes:
  versioner: use a virtual filesystem for input files.
  versioner: cache -cc1 flags generated by the clang Driver.
  versioner: refactor to use CompilerInstance directly.
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Nov 15, 2016
2 parents cd9ce19 + 78b8a14 commit b3321c9
Show file tree
Hide file tree
Showing 22 changed files with 639 additions and 208 deletions.
3 changes: 2 additions & 1 deletion libc/include/android/legacy_termios_inlines.h
Expand Up @@ -29,11 +29,12 @@
#ifndef _ANDROID_LEGACY_TERMIOS_INLINES_H_
#define _ANDROID_LEGACY_TERMIOS_INLINES_H_

#include <linux/termios.h>
#include <sys/cdefs.h>
#include <sys/ioctl.h>
#include <sys/types.h>

#include <linux/termios.h>

#if __ANDROID_API__ < 21

__BEGIN_DECLS
Expand Down
3 changes: 2 additions & 1 deletion libc/include/elf.h
Expand Up @@ -29,11 +29,12 @@
#ifndef _ELF_H
#define _ELF_H

#include <sys/cdefs.h>

#include <linux/auxvec.h>
#include <linux/elf.h>
#include <linux/elf-em.h>
#include <machine/elf_machdep.h>
#include <sys/cdefs.h>

#define ELF32_R_INFO(sym, type) ((((Elf32_Word)sym) << 8) | ((type) & 0xff))
#define ELF64_R_INFO(sym, type) ((((Elf64_Xword)sym) << 32) | ((type) & 0xffffffff))
Expand Down
3 changes: 2 additions & 1 deletion libc/include/link.h
Expand Up @@ -28,10 +28,11 @@
#ifndef _LINK_H_
#define _LINK_H_

#include <elf.h>
#include <sys/cdefs.h>
#include <sys/types.h>

#include <elf.h>

__BEGIN_DECLS

#if defined(__LP64__)
Expand Down
5 changes: 3 additions & 2 deletions libc/include/signal.h
Expand Up @@ -29,12 +29,13 @@
#ifndef _SIGNAL_H_
#define _SIGNAL_H_

#include <sys/cdefs.h>
#include <sys/types.h>

#include <asm/sigcontext.h>
#include <bits/pthread_types.h>
#include <bits/timespec.h>
#include <limits.h>
#include <sys/cdefs.h>
#include <sys/types.h>

#if defined(__LP64__) || defined(__mips__)
/* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one,
Expand Down
5 changes: 3 additions & 2 deletions libc/include/sys/select.h
Expand Up @@ -29,11 +29,12 @@
#ifndef _SYS_SELECT_H_
#define _SYS_SELECT_H_

#include <linux/time.h>
#include <signal.h>
#include <sys/cdefs.h>
#include <sys/types.h>

#include <linux/time.h>
#include <signal.h>

__BEGIN_DECLS

#define FD_SETSIZE 1024
Expand Down
3 changes: 2 additions & 1 deletion libc/include/sys/signalfd.h
Expand Up @@ -29,9 +29,10 @@
#ifndef _SYS_SIGNALFD_H_
#define _SYS_SIGNALFD_H_

#include <sys/cdefs.h>

#include <linux/signalfd.h>
#include <signal.h>
#include <sys/cdefs.h>

__BEGIN_DECLS

Expand Down
3 changes: 2 additions & 1 deletion libc/include/sys/ucontext.h
Expand Up @@ -29,8 +29,9 @@
#ifndef _SYS_UCONTEXT_H_
#define _SYS_UCONTEXT_H_

#include <signal.h>
#include <sys/cdefs.h>

#include <signal.h>
#include <sys/user.h>

__BEGIN_DECLS
Expand Down
4 changes: 4 additions & 0 deletions libc/include/syslog.h
Expand Up @@ -89,7 +89,11 @@ void closelog(void);
void openlog(const char* _Nullable, int, int);
int setlogmask(int);
void syslog(int, const char* _Nonnull, ...) __printflike(2, 3);
#if defined(__arm__) || defined(__aarch64__) || defined(__x86_64__)
void vsyslog(int, const char* _Nonnull, va_list) __printflike(2, 0);
#else /* defined(__mips__) || defined(__i386__) */
void vsyslog(int, const char* _Nonnull, va_list _Nonnull) __printflike(2, 0);
#endif

__END_DECLS

Expand Down
7 changes: 5 additions & 2 deletions tools/versioner/src/Android.mk
Expand Up @@ -26,12 +26,15 @@ TBLGEN_TABLES := \
LOCAL_SRC_FILES := \
versioner.cpp \
Arch.cpp \
CompilationType.cpp \
DeclarationDatabase.cpp \
Driver.cpp \
Preprocessor.cpp \
SymbolDatabase.cpp \
Utils.cpp
Utils.cpp \
VFS.cpp

LOCAL_SHARED_LIBRARIES := libclang libLLVM
LOCAL_SHARED_LIBRARIES := libclang libLLVM libbase

include $(CLANG_HOST_BUILD_MK)
include $(CLANG_TBLGEN_RULES_MK)
Expand Down
26 changes: 26 additions & 0 deletions tools/versioner/src/CompilationType.cpp
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "CompilationType.h"

#include <sstream>
#include <string>

std::string to_string(const CompilationType& type) {
std::stringstream ss;
ss << to_string(type.arch) << "-" << type.api_level << " [fob = " << type.file_offset_bits << "]";
return ss.str();
}
67 changes: 67 additions & 0 deletions tools/versioner/src/CompilationType.h
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <stdint.h>

#include <functional>
#include <utility>

#include "Arch.h"

struct CompilationType {
Arch arch;
int api_level;
int file_offset_bits;

private:
auto tie() const {
return std::tie(arch, api_level, file_offset_bits);
}

public:
bool operator<(const CompilationType& other) const {
return tie() < other.tie();
}

bool operator==(const CompilationType& other) const {
return tie() == other.tie();
}
};

namespace std {
template <>
struct hash<CompilationType> {
size_t operator()(CompilationType type) const {
struct {
int32_t arch : 3;
int32_t api_level : 6;
int32_t file_offset_bits : 1;
int32_t padding : 22;
} packed;
packed.arch = static_cast<int32_t>(type.arch);
packed.api_level = type.api_level;
packed.file_offset_bits = (type.file_offset_bits == 64);
packed.padding = 0;
int32_t value;
memcpy(&value, &packed, sizeof(value));
return std::hash<int32_t>()(value);
}
};
}

std::string to_string(const CompilationType& type);
9 changes: 1 addition & 8 deletions tools/versioner/src/DeclarationDatabase.cpp
Expand Up @@ -284,19 +284,12 @@ bool Symbol::hasDeclaration(const CompilationType& type) const {
return false;
}

void HeaderDatabase::parseAST(CompilationType type, ASTUnit* ast) {
void HeaderDatabase::parseAST(CompilationType type, ASTContext& ctx) {
std::unique_lock<std::mutex> lock(this->mutex);
ASTContext& ctx = ast->getASTContext();
Visitor visitor(*this, type, ctx);
visitor.TraverseDecl(ctx.getTranslationUnitDecl());
}

std::string to_string(const CompilationType& type) {
std::stringstream ss;
ss << to_string(type.arch) << "-" << type.api_level << " [fob = " << type.file_offset_bits << "]";
return ss.str();
}

std::string to_string(const AvailabilityValues& av) {
std::stringstream ss;

Expand Down
27 changes: 3 additions & 24 deletions tools/versioner/src/DeclarationDatabase.h
Expand Up @@ -27,10 +27,11 @@
#include <llvm/ADT/StringRef.h>

#include "Arch.h"
#include "CompilationType.h"
#include "Utils.h"

namespace clang {
class ASTUnit;
class ASTContext;
class Decl;
}

Expand All @@ -40,28 +41,6 @@ enum class DeclarationType {
inconsistent,
};

struct CompilationType {
Arch arch;
int api_level;
int file_offset_bits;

private:
auto tie() const {
return std::tie(arch, api_level, file_offset_bits);
}

public:
bool operator<(const CompilationType& other) const {
return tie() < other.tie();
}

bool operator==(const CompilationType& other) const {
return tie() == other.tie();
}
};

std::string to_string(const CompilationType& type);

struct AvailabilityValues {
bool future = false;
int introduced = 0;
Expand Down Expand Up @@ -219,7 +198,7 @@ class HeaderDatabase {
public:
std::map<std::string, Symbol> symbols;

void parseAST(CompilationType type, clang::ASTUnit* ast);
void parseAST(CompilationType type, clang::ASTContext& ast);

void dump(const std::string& base_path = "", FILE* out = stdout) const {
fprintf(out, "HeaderDatabase contains %zu symbols:\n", symbols.size());
Expand Down

0 comments on commit b3321c9

Please sign in to comment.