Skip to content
Open
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
94 changes: 47 additions & 47 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

name: Test debug ll generation

jobs:
test-debug-ll-generation:
runs-on: [ubuntu-22.04]
timeout-minutes: 90
env:
LLVM_VERSION: 18
steps:
- uses: actions/checkout@v3

- name: Check if CMakeLists.txt is in sync with our LLVM_VERSION
run: |
grep -q "set(DEBUGIR_LLVM_VERSION $LLVM_VERSION" CMakeLists.txt

- name: Check if README is in sync with our LLVM_VERSION
run: |
grep -q "LLVM-$LLVM_VERSION" README.md

- name: install LLVM
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh $LLVM_VERSION

- name: build debugir
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ../
cmake --build .

- name: generate hello.ll
run: |
cd test-files
clang-$LLVM_VERSION -emit-llvm -o hello.ll -S hello.c

- name: test generating hello dbg ll
run: |
./build/debugir ./test-files/hello.ll
test -e ./test-files/hello.dbg.ll
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
name: Test debug ll generation
jobs:
test-debug-ll-generation:
runs-on: [ubuntu-22.04]
timeout-minutes: 90
env:
LLVM_VERSION: 18
steps:
- uses: actions/checkout@v3
- name: Check if CMakeLists.txt is in sync with our LLVM_VERSION
run: |
grep -q "set(DEBUGIR_LLVM_VERSION $LLVM_VERSION" CMakeLists.txt
- name: Check if README is in sync with our LLVM_VERSION
run: |
grep -q "LLVM-$LLVM_VERSION" README.md
- name: install LLVM
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh $LLVM_VERSION
- name: build debugir
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ../
cmake --build .
- name: generate hello.ll
run: |
cd test-files
clang-$LLVM_VERSION -emit-llvm -o hello.ll -S hello.c
- name: test generating hello dbg ll
run: |
./build/debugir ./test-files/hello.ll
test -e ./test-files/hello.dbg.ll
24 changes: 12 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
build/
cscope.out
TAGS
GTAGS
GRTAGS
GPATH
.vscode
compile_commands.json
.gdbinit
hello.ll
hello.dbg.ll
.cache/
build/
cscope.out
TAGS
GTAGS
GRTAGS
GPATH
.vscode
compile_commands.json
.gdbinit
hello.ll
hello.dbg.ll
.cache/
157 changes: 93 additions & 64 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,64 +1,93 @@
cmake_minimum_required(VERSION 3.5.1)

project(DebugIR LANGUAGES C CXX)

option(LINK_LLVM_SHARED "Control whether debugir links to a shared LLVM library, or individual static components" ON)

# export compile commands
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# C++ standard
set(CMAKE_CXX_STANDARD 20)

# detect operating system
message(STATUS "We are on a ${CMAKE_SYSTEM_NAME} system")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

# Print build type: Debug/Release etc.
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
#
# check dependencies
#
# LLVM stuff
if(NOT DEFINED DEBUGIR_LLVM_VERSION)
set(DEBUGIR_LLVM_VERSION 18.1)
endif()
find_package(LLVM ${DEBUGIR_LLVM_VERSION} REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
if(LINK_LLVM_SHARED)
set(llvm_libs LLVM)
else()
# Find the libraries that correspond to the LLVM components we use
llvm_map_components_to_libnames(llvm_libs support core irreader transformutils Passes)
endif()

add_library(dbgir SHARED DebugIR.cpp)

# Match LLVM's RTTI build mode
if (NOT LLVM_ENABLE_RTTI)
message(STATUS "LLVM does not have RTTI enabled. Building with -fno-rtti")
target_compile_options(dbgir PUBLIC -fno-rtti)
endif()

set(DEBUGIR_WARN_FLAGS
-Wall
-Werror
-pedantic
-Wextra
-Wno-unknown-pragmas
-Wno-unused-parameter
)

# compiler and linker options
# PUBLIC because we apply the same to the debugir executable
target_compile_options(dbgir PRIVATE ${DEBUGIR_WARN_FLAGS})

separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
target_compile_definitions(dbgir PUBLIC ${LLVM_DEFINITIONS_LIST})
target_include_directories(dbgir PUBLIC ${PROJECT_SOURCE_DIR}/include/)
target_include_directories(dbgir PUBLIC ${LLVM_INCLUDE_DIRS})
target_link_libraries (dbgir PUBLIC ${llvm_libs})

add_executable(debugir Main.cpp)
target_compile_options(debugir PRIVATE ${DEBUGIR_WARN_FLAGS})
target_link_libraries(debugir dbgir)
cmake_minimum_required(VERSION 3.5.1)

project(DebugIR LANGUAGES C CXX)

option(LINK_LLVM_SHARED "Control whether debugir links to a shared LLVM library, or individual static components" ON)

# export compile commands
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# C++ standard
set(CMAKE_CXX_STANDARD 20)

# detect operating system
message(STATUS "We are on a ${CMAKE_SYSTEM_NAME} system")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

# Print build type: Debug/Release etc.
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
#
# check dependencies
#
# LLVM stuff
if(NOT DEFINED DEBUGIR_LLVM_VERSION)
set(DEBUGIR_LLVM_VERSION 18.1)
endif()
find_package(LLVM ${DEBUGIR_LLVM_VERSION} REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
if(LINK_LLVM_SHARED)
set(llvm_libs LLVM)
else()
# Find the libraries that correspond to the LLVM components we use
llvm_map_components_to_libnames(llvm_libs support core irreader transformutils Passes)
endif()

if (WIN32)
find_library(
DIA_GUIDS_LIB
NAMES diaguids
PATHS
"$ENV{VSINSTALLDIR}/DIA SDK/lib/amd64"
"$ENV{ProgramFiles}/Microsoft Visual Studio/2022/Community/DIA SDK/lib/amd64"
"$ENV{ProgramFiles}/Microsoft Visual Studio/2022/BuildTools/DIA SDK/lib/amd64"
"$ENV{ProgramFiles\(x86\)}/Microsoft Visual Studio/2022/Community/DIA SDK/lib/amd64"
"$ENV{ProgramFiles\(x86\)}/Microsoft Visual Studio/2022/BuildTools/DIA SDK/lib/amd64"
NO_DEFAULT_PATH
)
if (DIA_GUIDS_LIB)
list(APPEND llvm_libs ${DIA_GUIDS_LIB})
endif()
endif()

add_library(dbgir STATIC DebugIR.cpp)

# Match LLVM's RTTI build mode
if (NOT LLVM_ENABLE_RTTI)
message(STATUS "LLVM does not have RTTI enabled. Building with -fno-rtti")
target_compile_options(
dbgir
PUBLIC
$<$<CXX_COMPILER_ID:MSVC>:/GR->
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-fno-rtti>
)
endif()

if (MSVC)
set(DEBUGIR_WARN_FLAGS
/W4
/permissive-
)
else()
set(DEBUGIR_WARN_FLAGS
-Wall
-Werror
-pedantic
-Wextra
-Wno-unknown-pragmas
-Wno-unused-parameter
)
endif()

# compiler and linker options
# PUBLIC because we apply the same to the debugir executable
target_compile_options(dbgir PRIVATE ${DEBUGIR_WARN_FLAGS})

separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
target_compile_definitions(dbgir PUBLIC ${LLVM_DEFINITIONS_LIST})
target_include_directories(dbgir PUBLIC ${PROJECT_SOURCE_DIR}/include/)
target_include_directories(dbgir PUBLIC ${LLVM_INCLUDE_DIRS})
target_link_libraries (dbgir PUBLIC ${llvm_libs})

add_executable(debugir Main.cpp)
target_compile_options(debugir PRIVATE ${DEBUGIR_WARN_FLAGS})
target_link_libraries(debugir dbgir)
Loading