Skip to content
Closed
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
32 changes: 14 additions & 18 deletions api_compat_check.sh → build_binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

# Usage message
usage() {
echo "Usage: $0 [--package]"
echo "Usage: $0 [--build]"
echo ""
echo "Options:"
echo " --package Generate the Debian package after building"
echo " --build Force rebuild the binary"
echo " --help Show this help message"
echo ""
echo "Default behaviour: Build the binary only"
echo "Default behaviour: Use existing binary if available, otherwise build"
exit 1
}

Expand All @@ -17,14 +17,14 @@ if [[ "$1" == "--help" || "$1" == "-h" ]]; then
usage
fi

PACKAGE=false
FORCE_BUILD=false

# Parse arguments
if [[ "$1" == "--package" ]]; then
PACKAGE=true
if [[ "$1" == "--build" ]]; then
FORCE_BUILD=true
shift
if [[ "$#" -ne 0 ]]; then
echo "Error: --package does not take any additional arguments."
echo "Error: --build does not take any additional arguments."
usage
fi
elif [[ "$#" -ne 0 ]]; then
Expand All @@ -33,16 +33,15 @@ elif [[ "$#" -ne 0 ]]; then
fi

BUILD_DIR="build"
BINARY_NAME="armor"
BINARY_PATH="$BUILD_DIR/$BINARY_NAME"
BINARY_PATH="$BUILD_DIR/src/armor/armor"

build_binary() {
echo "🔧 Building binary..."
rm -rf "$BUILD_DIR"
cmake -S . -B "$BUILD_DIR" \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_COMPILER=/usr/bin/g++-11
cmake --build "$BUILD_DIR" --parallel
cmake --build "$BUILD_DIR" --parallel $(nproc)

if [ -f "$BINARY_PATH" ]; then
echo "✅ Binary built successfully at $BINARY_PATH"
Expand All @@ -52,16 +51,13 @@ build_binary() {
fi
}

# Check if binary exists
if [ ! -f "$BINARY_PATH" ]; then
# Check if binary exists or force build
if $FORCE_BUILD; then
echo "🔄 Force rebuild requested..."
build_binary
elif [ ! -f "$BINARY_PATH" ]; then
echo "⚠️ Binary not found at $BINARY_PATH. Building now..."
build_binary
else
echo "✅ Binary already exists at $BINARY_PATH."
fi

# Package if requested
if $PACKAGE; then
echo "📦 Packaging with CPack..."
cpack --config "$BUILD_DIR/CPackConfig.cmake"
fi
24 changes: 0 additions & 24 deletions include/diffengine.hpp

This file was deleted.

133 changes: 0 additions & 133 deletions include/node.hpp

This file was deleted.

17 changes: 0 additions & 17 deletions include/tree_builder_utils.hpp

This file was deleted.

51 changes: 51 additions & 0 deletions src/alpha/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
cmake_minimum_required(VERSION 3.14)
project(armor)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CLANG_EXTRA_FLAGS
"-xc++ -isystem /usr/include/c++/11 -isystem /usr/include -isystem /usr/local/include -isystem /usr/include/x86_64-linux-gnu/c++/11 -I/usr/lib/llvm-14/include -I/usr/lib/clang/14/include"
)

string(REPLACE "\"" "\\\"" CLANG_EXTRA_FLAGS_ESCAPED "${CLANG_EXTRA_FLAGS}")

add_compile_definitions(CLANG_FLAGS="${CLANG_EXTRA_FLAGS_ESCAPED}")

find_package(LLVM REQUIRED CONFIG)
find_package(Clang REQUIRED CONFIG)

include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${CLANG_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})

message(STATUS "LLVM include dirs: ${LLVM_INCLUDE_DIRS}")
message(STATUS "Clang include dirs: ${CLANG_INCLUDE_DIRS}")
message(STATUS "Detected compiler version: ${DETECTED_GCC_VERSION}")
message(STATUS "Injected Clang flags: ${CLANG_EXTRA_FLAGS}")

file(GLOB_RECURSE ALPHA_SOURCES "src/*.cpp")

add_library(alpha_lib STATIC
${ALPHA_SOURCES}
)

target_include_directories(alpha_lib PUBLIC
${CMAKE_SOURCE_DIR}/src/alpha/include
${CMAKE_SOURCE_DIR}/src/common/include
)

llvm_map_components_to_libnames(LLVM_LIBS
support
core
option
)

target_link_libraries(alpha_lib
${LLVM_LIBS}
clangTooling
clangIndex
common_lib
nlohmann_json::nlohmann_json
CLI11::CLI11
)
88 changes: 88 additions & 0 deletions src/alpha/include/ast_normalized_context.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// SPDX-License-Identifier: BSD-3-Clause
#pragma once

#include "node.hpp"
#include "clang/AST/ASTContext.h"
#include <llvm-14/llvm/ADT/StringRef.h>
#include <llvm-14/llvm/ADT/StringSet.h>

/**
* @class ASTNormalizedContext
* @brief Manages a collection of API nodes parsed from an Abstract Syntax Tree (AST).
*
* This class serves as the central repository for all unique API nodes found during
* an AST traversal. It maintains two primary data structures:
*
* 1. A map (`normalizedTree`) from a unique identifier (like a USR) to the
* corresponding `APINode`. This ensures that each API entity is represented by
* a single, unique object, preventing duplication.
*
* 2. A vector (`rootApiNodes`) of nodes that are considered top-level or
* "root" elements of the API (e.g., free functions, global variables, or
* classes in the global namespace).
*/
namespace alpha{

class ASTNormalizedContext {
public:

/**
* @brief Constructs an empty ASTNormalizedContext.
*/
ASTNormalizedContext();

/**
* @brief Adds a new node to the normalized tree.
*
* If a node with the same key already exists, it is not replaced.
* Use addOrUpdateNode if overwriting is desired.
*
* @param key The unique string identifier for the node (e.g., USR).
* @param node A shared pointer to the APINode.
*/
void addNode(llvm::StringRef key,const std::shared_ptr<const APINode> node);

/**
* @brief Adds a node to the list of root API nodes.
*
* @param rootNode A const shared pointer to the APINode.
*/
void addRootNode(const std::shared_ptr<const APINode> rootNode);

/**
* @brief Returns a const reference to the entire normalized tree map.
*/
const llvm::StringMap<std::shared_ptr<const APINode>>& getTree() const;

/**
* @brief Returns a const reference to the list of root API nodes.
*/
const llvm::SmallVector<std::shared_ptr<const APINode>,64>& getRootNodes() const;

/**
* @brief Checks if the context contains any nodes.
* @return True if both the tree and root nodes list are empty, false otherwise.
*/
bool empty() const;

/**
* @brief Clears all stored nodes, resetting the context to an empty state.
*/
void clear();

void addClangASTContext(clang::ASTContext *ASTContext);

clang::ASTContext* getClangASTContext() const;

llvm::StringSet<> excludeNodes;
llvm::StringSet<> hashSet;

private:
llvm::StringMap<std::shared_ptr<const APINode>> apiNodesMap;
llvm::SmallVector<std::shared_ptr<const APINode>,64> apiNodes;

clang::ASTContext* clangContext;
};

}
Loading
Loading