Skip to content

Commit 5a20324

Browse files
authored
Basic implementation of playground (#3)
1 parent 73f958a commit 5a20324

42 files changed

Lines changed: 2573 additions & 234 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.devcontainer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"name": "GraphAlg",
3-
"build": {
4-
"dockerfile": "docker/Dockerfile"
5-
},
3+
"image": "ghcr.io/wildarch/graphalg",
64
"remoteUser": "ubuntu",
75
"runArgs": [
86
// Allow GDB to disable address space layout randomization.

.github/workflows/ci.yml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,37 @@ jobs:
99
# Build job
1010
build:
1111
runs-on: ubuntu-latest
12+
container: ghcr.io/wildarch/graphalg-ci
1213
steps:
1314
- name: Checkout
1415
uses: actions/checkout@v5
15-
- name: Setup Ruby
16-
uses: ruby/setup-ruby@v1
17-
with:
18-
ruby-version: '3.3' # Not needed with a .ruby-version file
19-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
20-
cache-version: 0 # Increment this number if you need to re-download cached gems
21-
- name: Build with Jekyll
22-
run: bundle exec jekyll build
16+
- name: Build codemirror-lang-graphalg
17+
shell: bash
18+
run: |
19+
source /root/emsdk/emsdk_env.sh
20+
npm --workspace=codemirror-lang-graphalg install
21+
npm --workspace=codemirror-lang-graphalg run prepare
22+
- name: Build compiler (native)
23+
shell: bash
24+
run: |
25+
./compiler/configure.sh
26+
cmake --build ./compiler/build
27+
cmake --build ./compiler/build --target check
28+
- name: Build compiler (wasm)
29+
shell: bash
30+
run: |
31+
source /root/emsdk/emsdk_env.sh
32+
./compiler/configure-wasm.sh
33+
cmake --build ./compiler/build-wasm
34+
- name: Build playground
35+
shell: bash
36+
run: |
37+
source /root/emsdk/emsdk_env.sh
38+
npm --workspace=playground install
39+
npm --workspace=playground run prepare
40+
- name: Build website
41+
env:
42+
GEM_HOME: /root/gems
43+
run: |
44+
/root/gems/bin/bundle install
45+
/root/gems/bin/bundle exec jekyll build

.github/workflows/pages.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,31 @@ jobs:
2828
# Build job
2929
build:
3030
runs-on: ubuntu-latest
31+
container: ghcr.io/wildarch/graphalg
3132
steps:
3233
- name: Checkout
3334
uses: actions/checkout@v5
35+
36+
# The playground and its dependencies, because they are used in pages.
37+
- name: Build codemirror-lang-graphalg
38+
shell: bash
39+
run: |
40+
source /root/emsdk/emsdk_env.sh
41+
npm --workspace=codemirror-lang-graphalg install
42+
npm --workspace=codemirror-lang-graphalg run prepare
43+
- name: Build compiler (wasm)
44+
shell: bash
45+
run: |
46+
source /root/emsdk/emsdk_env.sh
47+
./compiler/configure-wasm.sh
48+
cmake --build ./compiler/build-wasm
49+
- name: Build playground
50+
shell: bash
51+
run: |
52+
source /root/emsdk/emsdk_env.sh
53+
npm --workspace=playground install
54+
npm --workspace=playground run prepare
55+
3456
- name: Setup Ruby
3557
uses: ruby/setup-ruby@v1
3658
with:

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ npm --workspace=codemirror-lang-graphalg run prepare
1616
cmake --build ./compiler/build
1717
cmake --build ./compiler/build --target check
1818

19-
npm --workspace=website install
20-
npm --workspace=website run prepare
21-
# To start a simple server to test the website:
22-
# (cd website/ && python3 -m http.server)
19+
./compiler/configure-wasm.sh
20+
cmake --build ./compiler/build-wasm
21+
22+
npm --workspace=playground install
23+
npm --workspace=playground run prepare
24+
# To start a simple server to test the playground:
25+
# (cd playground/ && python3 -m http.server)
2326

2427
bundle install
2528
# Or bundle exec jekyll serve to start a server

_config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ callouts:
1111

1212
warning:
1313
title: Warning
14+
color: yellow
15+
16+
error:
17+
title: Error
18+
color: red
19+
20+
error-titled:
1421
color: red
1522

1623
exclude:

compiler/CMakeLists.txt

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ project(
77
DESCRIPTION "Compiler for the GraphAlg language"
88
LANGUAGES CXX)
99

10-
# LLVM
10+
# =============================== BEGIN OPTIONS ================================
11+
# NOTE: If LLVM is built with RTTI disabled (the default), we must also disable
12+
# it. If the LLVM build enables RTTI, we are free to choose.
13+
option(GRAPHALG_ENABLE_RTTI "Enable run time type information" OFF)
14+
15+
option(ENABLE_WASM "Enable wasm-only targets" OFF)
16+
# ================================ END OPTIONS =================================
17+
18+
# ================================= BEGIN LLVM =================================
19+
1120
find_package(LLVM REQUIRED CONFIG)
1221
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
1322
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
@@ -20,7 +29,9 @@ include(AddLLVM)
2029

2130
llvm_map_components_to_libnames(llvm_libs support)
2231

23-
# MLIR
32+
# ================================== END LLVM ==================================
33+
34+
# ================================= BEGIN MLIR =================================
2435
find_package(MLIR ${LLVM_PACKAGE_VERSION} REQUIRED CONFIG
2536
HINTS "${LLVM_INSTALL_PREFIX}/lib/cmake"
2637
)
@@ -35,6 +46,7 @@ if(DEFINED SET_MLIR_TABLEGEN_PATH)
3546
endif()
3647

3748
include(AddMLIR)
49+
# ================================== END MLIR ==================================
3850

3951
# Directories with MLIR dialects
4052
add_subdirectory(include/graphalg)
@@ -87,6 +99,9 @@ target_link_libraries(
8799
# Suppress -Wdangling-assignment-gsl for generated code from MLIR tablegen
88100
# The warning is triggered by template instantiations in GraphAlgOps.cpp.inc
89101
target_compile_options(graphalg_lib PRIVATE -Wno-dangling-assignment-gsl)
102+
if(NOT GRAPHALG_ENABLE_RTTI)
103+
target_compile_options(graphalg_lib PUBLIC -fno-rtti)
104+
endif()
90105

91106
add_library(graphalg_parse STATIC
92107
src/graphalg/parse/Lexer.cpp
@@ -123,17 +138,45 @@ target_link_libraries(graphalg-exec PRIVATE
123138
MLIRParser
124139
)
125140

126-
set(ENABLE_WASM OFF CACHE BOOL "Enable wasm-only targets" FORCE)
141+
add_executable(graphalg-playground src/graphalg-playground.cpp)
142+
target_link_libraries(graphalg-playground PRIVATE
143+
${llvm_libs}
144+
graphalg_lib
145+
graphalg_parse
146+
)
127147

128148
if(ENABLE_WASM)
129-
add_executable(wasm_parse src/wasm_parse.cpp)
130-
target_link_libraries(wasm_parse PRIVATE
131-
${llvm_libs}
132-
graphalg_lib
133-
graphalg_parse
149+
set(PLAYGROUND_EXPORTED_FUNCTIONS
150+
_ga_new
151+
_ga_free
152+
_ga_parse
153+
_ga_diag_count
154+
_ga_diag_line_start
155+
_ga_diag_line_end
156+
_ga_diag_col_start
157+
_ga_diag_col_end
158+
_ga_diag_msg
159+
_ga_desugar
160+
_ga_add_arg
161+
_ga_set_dims
162+
_ga_set_arg_bool
163+
_ga_set_arg_int
164+
_ga_set_arg_real
165+
_ga_evaluate
166+
_ga_get_res_ring
167+
_ga_get_res_rows
168+
_ga_get_res_cols
169+
_ga_get_res_bool
170+
_ga_get_res_int
171+
_ga_get_res_real
172+
_ga_get_res_inf
134173
)
135-
target_link_options(wasm_parse PRIVATE
136-
-sEXPORTED_FUNCTIONS=_ga_parse
137-
-sEXPORTED_RUNTIME_METHODS=cwrap
138-
-sMODULARIZE)
174+
string (REPLACE ";" "," PLAYGROUND_EXPORTED_FUNCTIONS_STR "${PLAYGROUND_EXPORTED_FUNCTIONS}")
175+
176+
177+
target_link_options(graphalg-playground PRIVATE
178+
-sEXPORTED_FUNCTIONS=${PLAYGROUND_EXPORTED_FUNCTIONS_STR}
179+
-sEXPORTED_RUNTIME_METHODS=cwrap,UTF8ToString
180+
-sMODULARIZE
181+
-sEXPORT_ES6)
139182
endif()

compiler/configure-wasm.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ BUILD_DIR=$WORKSPACE_ROOT/build-wasm
44
rm -rf $BUILD_DIR
55
emcmake cmake -S $WORKSPACE_ROOT -B $BUILD_DIR -G Ninja \
66
-DCMAKE_BUILD_TYPE=Debug \
7-
-DCMAKE_CXX_FLAGS="-fno-rtti" \
87
-DSET_MLIR_TABLEGEN_PATH="/usr/bin/mlir-tblgen-20" \
9-
-DLLVM_DIR="$(pwd)/third-party/llvm-wasm-install/lib/cmake/llvm" \
10-
-DMLIR_DIR="$(pwd)/third-party/llvm-wasm-install/lib/cmake/mlir" \
8+
-DLLVM_DIR="/opt/llvm-wasm/lib/cmake/llvm" \
9+
-DMLIR_DIR="/opt/llvm-wasm/lib/cmake/mlir" \
1110
-DENABLE_WASM=ON \

compiler/configure.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ cmake -S $WORKSPACE_ROOT -B $BUILD_DIR -G Ninja \
88
-DCMAKE_CXX_COMPILER=clang++-20 \
99
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
1010
-DCMAKE_LINKER_TYPE=MOLD \
11-
-DLLVM_ROOT="/opt/llvm-debug"
11+
-DLLVM_ROOT="/opt/llvm-debug" \
12+
-DSET_LLVM_TOOLS_BINARY_DIR="/usr/lib/llvm-20/bin"

compiler/src/graphalg-exec.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ static graphalg::MatrixAttr parseMatrix(llvm::StringRef filename,
134134
}
135135

136136
valueAttr = mlir::FloatAttr::get(type.getSemiring(), value);
137+
} else if (type.getSemiring() ==
138+
graphalg::SemiringTypes::forTropReal(ctx)) {
139+
double value;
140+
if (parts.size() != 3) {
141+
emitError() << "expected 3 parts, got " << parts.size();
142+
return nullptr;
143+
}
144+
145+
if (!llvm::to_float(parts[2], value)) {
146+
emitError() << "invalid float value";
147+
return nullptr;
148+
}
149+
150+
valueAttr = graphalg::TropFloatAttr::get(
151+
ctx, type.getSemiring(),
152+
mlir::FloatAttr::get(graphalg::SemiringTypes::forReal(ctx), value));
137153
} else {
138154
emitError() << "unsupported semiring: " << type.getSemiring();
139155
return nullptr;

0 commit comments

Comments
 (0)