Skip to content

Commit 0829030

Browse files
authored
Merge pull request #457 from brianegge/python3
Python3
2 parents ad425f6 + 4c73396 commit 0829030

File tree

14 files changed

+254
-42
lines changed

14 files changed

+254
-42
lines changed

.devcontainer/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM mcr.microsoft.com/devcontainers/base:dev-ubuntu-22.04
2+
3+
# These dependencies are required by Nix.
4+
RUN apt update -y
5+
RUN apt -y install --no-install-recommends curl xz-utils cmake libreadline-dev libncurses-dev llvm-12 llvm-12-dev
6+
RUN [ -e /usr/bin/gmake ] || sudo ln -s /usr/bin/make /usr/bin/gmake
7+
8+
# Install Nix
9+
ARG NIX_INSTALL_SCRIPT=https://nixos.org/nix/install
10+
RUN curl -L ${NIX_INSTALL_SCRIPT} | sudo -u vscode NIX_INSTALLER_NO_MODIFY_PROFILE=1 sh
11+
12+
# Configuration for Nix from the repository shared amongst developers.
13+
RUN mkdir -p /etc/nix
14+
COPY .devcontainer/nix.conf /etc/nix/nix.conf
15+
# COPY nix.conf /etc/nix/nix.conf
16+
17+
# This loads the development environment when the container is started.
18+
COPY .devcontainer/profile.sh /etc/profile.d/devcontainer.sh
19+
20+
# COPY /home/vscode/.nix-profile/etc/profile.d/nix.sh /etc/profile.d/devcontainer.sh
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
3+
{
4+
"name": "Ubuntu",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"build": {
7+
"dockerfile": "../Dockerfile",
8+
"context": "../..",
9+
"args": {
10+
// Options
11+
"NODE_VERSION": "none"
12+
}
13+
},
14+
// Features to add to the dev container. More info: https://containers.dev/features.
15+
// "features": {},
16+
17+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
18+
// "forwardPorts": [],
19+
20+
// Use 'postCreateCommand' to run commands after the container is created.
21+
// "postCreateCommand": "uname -a",
22+
23+
// Configure tool-specific properties.
24+
// "customizations": {},
25+
26+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
27+
// "remoteUser": "root"
28+
"runArgs": [],
29+
"containerUser": "vscode",
30+
"updateRemoteUserUID": true,
31+
"containerEnv": {
32+
"HOME": "/home/vscode"
33+
},
34+
"customizations": {
35+
"vscode": {
36+
"extensions": [
37+
"github.vscode-github-actions",
38+
"GitHub.vscode-pull-request-github",
39+
"ms-azuretools.vscode-docker",
40+
"ms-vscode.cmake-tools"
41+
]
42+
}
43+
}
44+
}

.devcontainer/nix.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental-features = nix-command flakes
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
3+
{
4+
"name": "Ubuntu",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"build": {
7+
"dockerfile": "../Dockerfile",
8+
"context": "../..",
9+
"args": {
10+
// Options
11+
"NODE_VERSION": "none"
12+
}
13+
},
14+
// Features to add to the dev container. More info: https://containers.dev/features.
15+
// "features": {},
16+
17+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
18+
// "forwardPorts": [],
19+
20+
// Use 'postCreateCommand' to run commands after the container is created.
21+
// "postCreateCommand": "uname -a",
22+
23+
// Configure tool-specific properties.
24+
// "customizations": {},
25+
26+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
27+
// "remoteUser": "root"
28+
"runArgs": ["--userns=keep-id"],
29+
"containerUser": "vscode",
30+
"updateRemoteUserUID": true,
31+
"containerEnv": {
32+
"HOME": "/home/vscode"
33+
},
34+
"mounts": [
35+
"type=bind,readonly,source=/etc/localtime,target=/etc/localtime"
36+
],
37+
"customizations": {
38+
"vscode": {
39+
"extensions": [
40+
"github.vscode-github-actions",
41+
"GitHub.vscode-pull-request-github",
42+
"ms-vscode.cpptools-extension-pack",
43+
"ms-vscode.makefile-tools",
44+
"ms-azuretools.vscode-docker"
45+
]
46+
}
47+
}
48+
}

.devcontainer/profile.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
PROJECT_DIR=${PROJECT_DIR:-/workspace}
4+
5+
# Make Nix available as it's not installed system-wide.
6+
if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ] ; then
7+
. $HOME/.nix-profile/etc/profile.d/nix.sh
8+
fi
9+
10+
# Only load the development environment if this is a login shell so calling a
11+
# shell later on doesn't reload the environment again.
12+
if shopt -q login_shell; then
13+
pushd "${PROJECT_DIR}"
14+
eval "$(nix print-dev-env --profile "${PROJECT_DIR}/.devcontainer/.profile")"
15+
popd
16+
fi

.github/workflows/build.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
runs-on: ${{matrix.os}}
66
strategy:
77
matrix:
8-
os: [ubuntu-20.04]
8+
os: [ubuntu-22.04]
99
clang: [8]
1010
steps:
1111
- uses: actions/checkout@v4
@@ -14,9 +14,11 @@ jobs:
1414
fetch-depth: 0
1515
- uses: cachix/install-nix-action@v30
1616
with:
17-
install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-2.4pre20201221_9fab14a/install
1817
extra_nix_config: |
1918
experimental-features = nix-command flakes ca-references
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.10'
2022
- name: nix build hobbesPackages/clang-${{ matrix.clang }}-ASanAndUBSan/hobbes
2123
run: |
2224
nix build .#hobbesPackages/clang-${{ matrix.clang }}-ASanAndUBSan/hobbes
@@ -34,7 +36,7 @@ jobs:
3436
runs-on: ${{matrix.os}}
3537
strategy:
3638
matrix:
37-
os: [ubuntu-20.04]
39+
os: [ubuntu-22.04]
3840
clang: [6, 8, 10, 11, 12]
3941
steps:
4042
- uses: actions/checkout@v4
@@ -43,9 +45,11 @@ jobs:
4345
fetch-depth: 0
4446
- uses: cachix/install-nix-action@v30
4547
with:
46-
install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-2.4pre20201221_9fab14a/install
4748
extra_nix_config: |
4849
experimental-features = nix-command flakes ca-references
50+
- uses: actions/setup-python@v5
51+
with:
52+
python-version: '3.10'
4953
- name: nix build hobbesPackages/clang-${{ matrix.clang }}/hobbes
5054
run: |
5155
nix build .#hobbesPackages/clang-${{ matrix.clang }}/hobbes
@@ -63,7 +67,7 @@ jobs:
6367
runs-on: ${{matrix.os}}
6468
strategy:
6569
matrix:
66-
os: [ubuntu-20.04]
70+
os: [ubuntu-22.04]
6771
gcc: [10]
6872
llvm: [6, 8, 10, 11, 12]
6973
steps:
@@ -73,9 +77,11 @@ jobs:
7377
fetch-depth: 0
7478
- uses: cachix/install-nix-action@v30
7579
with:
76-
install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-2.4pre20201221_9fab14a/install
7780
extra_nix_config: |
7881
experimental-features = nix-command flakes ca-references
82+
- uses: actions/setup-python@v5
83+
with:
84+
python-version: '3.10'
7985
- name: nix build hobbesPackages/gcc-${{ matrix.gcc }}/llvm-${{ matrix.llvm }}/hobbes
8086
run: |
8187
nix build .#hobbesPackages/gcc-${{ matrix.gcc }}/llvm-${{ matrix.llvm }}/hobbes

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.sw?
22
/build/
3-
scripts/*.pyc
3+
__pycache__/
4+
*.py[cod]
45
CMakeCache.txt
56
CMakeFiles/
67
/doc/en/_build/

CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,35 @@ set(CURSES_NEED_NCURSES TRUE)
1313
find_package(Curses REQUIRED)
1414
include_directories(${CURSES_INCLUDE_DIRS})
1515

16+
find_package(LLVM 12 CONFIG QUIET)
1617
find_package(LLVM REQUIRED CONFIG)
1718
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
1819
add_definitions(${LLVM_DEFINITIONS})
1920

2021
set(CMAKE_CXX_STANDARD 14)
2122

23+
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
24+
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
25+
message(STATUS "Using LLVM binary dir: ${LLVM_TOOLS_BINARY_DIR}")
26+
2227
if (${LLVM_PACKAGE_VERSION} VERSION_LESS "3.6")
2328
set(jit_lib jit)
2429
elseif(${LLVM_PACKAGE_VERSION} VERSION_LESS "11.0")
2530
set(jit_lib mcjit)
2631
else()
2732
set(jit_lib mcjit orcjit)
2833
endif()
34+
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
35+
set(llvm_arch_lib x86)
36+
ELSEIF(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
37+
set(llvm_arch_lib aarch64)
38+
ENDIF()
2939

3040
find_program(llvm-config llvm-config PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
3141
find_program(llvm-config llvm-config)
42+
message(STATUS "Using LLVM config: ${llvm-config}")
3243
if (${LLVM_PACKAGE_VERSION} VERSION_LESS "4.0")
33-
execute_process(COMMAND ${llvm-config} --libs x86 ipo ${jit_lib}
44+
execute_process(COMMAND ${llvm-config} --libs ipo ${llvm_arch_lib} ${jit_lib}
3445
OUTPUT_VARIABLE llvm_libs
3546
OUTPUT_STRIP_TRAILING_WHITESPACE)
3647
execute_process(COMMAND ${llvm-config} --ldflags
@@ -40,9 +51,10 @@ if (${LLVM_PACKAGE_VERSION} VERSION_LESS "4.0")
4051
OUTPUT_VARIABLE sys_libs
4152
OUTPUT_STRIP_TRAILING_WHITESPACE)
4253
else()
43-
execute_process(COMMAND ${llvm-config} --libs x86 ipo ${jit_lib} --link-static
54+
execute_process(COMMAND ${llvm-config} --libs ipo ${llvm_arch_lib} ${jit_lib} --link-static
4455
OUTPUT_VARIABLE llvm_libs
45-
OUTPUT_STRIP_TRAILING_WHITESPACE)
56+
OUTPUT_STRIP_TRAILING_WHITESPACE
57+
COMMAND_ERROR_IS_FATAL ANY)
4658
execute_process(COMMAND ${llvm-config} --ldflags
4759
OUTPUT_VARIABLE llvm_ldflags
4860
OUTPUT_STRIP_TRAILING_WHITESPACE)
@@ -110,8 +122,9 @@ add_executable(mock-proc test/mocks/proc.C)
110122
add_executable(hobbes-test ${test_files})
111123
target_link_libraries(hobbes-test PRIVATE hobbes)
112124
add_test(hobbes-test hobbes-test)
113-
find_package(PythonInterp 2.7 REQUIRED)
114-
set_property(TARGET hobbes-test PROPERTY COMPILE_FLAGS "-DPYTHON_EXECUTABLE=\"${PYTHON_EXECUTABLE}\" -DSCRIPT_DIR=\"${CMAKE_SOURCE_DIR}/scripts/\"")
125+
find_package(Python COMPONENTS Interpreter)
126+
message("Python_EXECUTABLE " ${Python_EXECUTABLE})
127+
set_property(TARGET hobbes-test PROPERTY COMPILE_FLAGS "-DPYTHON_EXECUTABLE=\"${Python_EXECUTABLE}\" -DSCRIPT_DIR=\"${CMAKE_SOURCE_DIR}/scripts/\"")
115128

116129
install(TARGETS hobbes hobbes-pic DESTINATION "lib")
117130
install(TARGETS hi hog hobbes-test DESTINATION "bin")

cmake/FindReadline.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if(Readline_INCLUDE_DIRS AND Readline_LIBRARIES AND Ncurses_LIBRARY)
1919
else()
2020
find_library(Readline_LIBRARIES NAMES readline)
2121
include(FindPackageHandleStandardArgs)
22-
find_package_handle_standard_args(readline DEFAULT_MSG Readline_INCLUDE_DIRS Readline_LIBRARIES)
22+
find_package_handle_standard_args(Readline DEFAULT_MSG Readline_INCLUDE_DIRS Readline_LIBRARIES)
2323
mark_as_advanced(Readline_INCLUDE_DIRS Readline_LIBRARIES)
2424
endif()
2525

include/hobbes/storage.H

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,57 @@ static inline unsigned spin(unsigned count) {
262262
return (count << 1);
263263
}
264264

265+
#if defined(__aarch64__)
266+
//https://docs.huihoo.com/doxygen/linux/kernel/3.7/arch_2arm64_2include_2asm_2cmpxchg_8h_source.html
267+
#define uxchg(ptr,x) \
268+
__xchg((x),(ptr),sizeof(*(ptr)))
269+
270+
static inline void __xchg(volatile unsigned long x, volatile void *ptr, std::size_t size)
271+
{
272+
unsigned long ret, tmp;
273+
274+
switch (size) {
275+
case 1:
276+
asm volatile("// __xchg1\n"
277+
"1: ldaxrb %w0, [%3]\n"
278+
" stlxrb %w1, %w2, [%3]\n"
279+
" cbnz %w1, 1b\n"
280+
: "=&r" (ret), "=&r" (tmp)
281+
: "r" (x), "r" (ptr)
282+
: "memory", "cc");
283+
break;
284+
case 2:
285+
asm volatile("// __xchg2\n"
286+
"1: ldaxrh %w0, [%3]\n"
287+
" stlxrh %w1, %w2, [%3]\n"
288+
" cbnz %w1, 1b\n"
289+
: "=&r" (ret), "=&r" (tmp)
290+
: "r" (x), "r" (ptr)
291+
: "memory", "cc");
292+
break;
293+
case 4:
294+
asm volatile("// __xchg4\n"
295+
"1: ldaxr %w0, [%3]\n"
296+
" stlxr %w1, %w2, [%3]\n"
297+
" cbnz %w1, 1b\n"
298+
: "=&r" (ret), "=&r" (tmp)
299+
: "r" (x), "r" (ptr)
300+
: "memory", "cc");
301+
break;
302+
case 8:
303+
asm volatile("// __xchg8\n"
304+
"1: ldaxr %0, [%3]\n"
305+
" stlxr %w1, %2, [%3]\n"
306+
" cbnz %w1, 1b\n"
307+
: "=&r" (ret), "=&r" (tmp)
308+
: "r" (x), "r" (ptr)
309+
: "memory", "cc");
310+
break;
311+
default:
312+
assert(0);
313+
}
314+
}
315+
#else
265316
static inline void uxchg(volatile uint32_t* px, uint32_t nx) {
266317
__asm__ __volatile__(
267318
"xchgl %0,%1"
@@ -270,6 +321,8 @@ static inline void uxchg(volatile uint32_t* px, uint32_t nx) {
270321
:"memory"
271322
);
272323
}
324+
#endif
325+
273326
#define xchg __sync_lock_test_and_set
274327

275328
// define a local socket for registering new storage queues

0 commit comments

Comments
 (0)