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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# The compiler fixtures are byte exact: expected diagnostics give byte offsets into them.
fixtures/** -text
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ jobs:
cmake --build consumer/build
./consumer/build/consumer

windows:
name: build and test (MSVC)
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Configure
run: cmake -S . -B build
- name: Build
run: cmake --build build --config Release
- name: Tests
run: ctest --test-dir build -C Release --output-on-failure

emscripten:
name: library (Emscripten)
runs-on: ubuntu-latest
Expand Down
19 changes: 13 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ target_include_directories(adlib PUBLIC
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/generated/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_compile_features(adlib PUBLIC cxx_std_17)
target_compile_options(adlib PRIVATE -Wall -Wextra -Wno-unused-parameter)
# Lockstep determinism (the runtime does a little float math, e.g. id_SET_InteractorLatency):
# no FMA contraction, no fast-math, SSE on x86. Hosts that need bit-identical simulation across
# builds should use the same flags.
target_compile_options(adlib PRIVATE -ffp-contract=off -fno-fast-math)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64" AND NOT EMSCRIPTEN)
target_compile_options(adlib PRIVATE -mfpmath=sse -msse2)
# builds should use the same flags. MSVC's /fp:precise contracts nothing and x64 is always SSE2.
if(MSVC)
target_compile_options(adlib PRIVATE /W4 /wd4100 /fp:precise)
else()
target_compile_options(adlib PRIVATE -Wall -Wextra -Wno-unused-parameter -ffp-contract=off -fno-fast-math)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64" AND NOT EMSCRIPTEN)
target_compile_options(adlib PRIVATE -mfpmath=sse -msse2)
endif()
endif()
set_target_properties(adlib PROPERTIES VERSION ${PROJECT_VERSION} EXPORT_NAME adlib)

Expand All @@ -59,7 +62,11 @@ if(ADLIB_BUILD_TOOLS)
src/tools/trace.cpp)
add_library(adlib::tools ALIAS adlib_tools)
target_link_libraries(adlib_tools PUBLIC adlib)
target_compile_options(adlib_tools PRIVATE -Wall -Wextra -Wno-unused-parameter)
if(MSVC)
target_compile_options(adlib_tools PRIVATE /W4 /wd4100)
else()
target_compile_options(adlib_tools PRIVATE -Wall -Wextra -Wno-unused-parameter)
endif()
set_target_properties(adlib_tools PROPERTIES EXPORT_NAME tools)

add_executable(adlibc tools/adlibc.cpp)
Expand Down
24 changes: 11 additions & 13 deletions src/compiler/symbols.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// CPlanCompiler_ctor (0x487790) tables and CPlanCompiler_LoadSymbols (0x48a240), emulated.
#include <cstdio>
#include <dirent.h>
#include <filesystem>
#include <fstream>
#include <sstream>
#include <stdexcept>
Expand Down Expand Up @@ -31,23 +31,21 @@ const CompilerKeyword kKeywordTable[] = {
bool readFileCI(const std::string &dir, const std::string &name, std::string &out) {
// Case-insensitive lookup of `name` (may contain one '/' level) under dir.
std::string d = dir, n = name;
auto findCI = [](const std::string &in, const std::string &want) {
std::error_code ec;
for (const auto &e : std::filesystem::directory_iterator(in, ec)) {
const std::string fileName = e.path().filename().string();
if (msvcStricmp(fileName.c_str(), want.c_str()) == 0) return fileName;
}
return std::string();
};
size_t slash = n.find('/');
if (slash != std::string::npos) {
std::string sub;
DIR *h = opendir(d.c_str());
if (!h) return false;
while (dirent *e = readdir(h))
if (msvcStricmp(e->d_name, n.substr(0, slash).c_str()) == 0) { sub = e->d_name; break; }
closedir(h);
std::string sub = findCI(d, n.substr(0, slash));
if (sub.empty()) return false;
return readFileCI(d + "/" + sub, n.substr(slash + 1), out);
}
DIR *h = opendir(d.c_str());
if (!h) return false;
std::string found;
while (dirent *e = readdir(h))
if (msvcStricmp(e->d_name, n.c_str()) == 0) { found = e->d_name; break; }
closedir(h);
std::string found = findCI(d, n);
if (found.empty()) return false;
std::ifstream f(d + "/" + found, std::ios::binary);
if (!f) return false;
Expand Down
2 changes: 2 additions & 0 deletions src/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ struct PlanError : std::runtime_error {
using std::runtime_error::runtime_error;
};

#if defined(__GNUC__)
std::string fmt(const char *f, ...) __attribute__((format(printf, 1, 2)));
#endif
std::string fmt(const char *f, ...) {
char buf[512];
va_list ap;
Expand Down
12 changes: 5 additions & 7 deletions tests/adlibc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <dirent.h>
#include <filesystem>
#include <fstream>
#include <map>
#include <memory>
Expand Down Expand Up @@ -41,12 +41,10 @@ bool readFile(const std::string &p, std::string &out) {
}
std::vector<std::string> listDir(const std::string &d, const std::string &ext) {
std::vector<std::string> v;
if (DIR *h = opendir(d.c_str())) {
while (dirent *e = readdir(h)) {
std::string n = e->d_name;
if (n.size() > ext.size() && n.compare(n.size() - ext.size(), ext.size(), ext) == 0) v.push_back(n);
}
closedir(h);
std::error_code ec;
for (const auto &e : std::filesystem::directory_iterator(d, ec)) {
std::string n = e.path().filename().string();
if (n.size() > ext.size() && n.compare(n.size() - ext.size(), ext.size(), ext) == 0) v.push_back(n);
}
std::sort(v.begin(), v.end());
return v;
Expand Down
12 changes: 6 additions & 6 deletions tools/adlibc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// [--compat=adlib|adlib1996] [--plans-dir DIR] [--strict] [--Werror] [-o out.pbn] [-q] file.txt
#include <cstdio>
#include <cstring>
#include <dirent.h>
#include <filesystem>
#include <fstream>
#include <sstream>
#include <string>
Expand Down Expand Up @@ -58,12 +58,12 @@ std::string lower(std::string s) {
}

std::optional<std::string> findPlan(const std::string &dir, const std::string &name) {
DIR *h = opendir(dir.empty() ? "." : dir.c_str());
if (!h) return std::nullopt;
std::string want = lower(name + ".txt"), found;
while (dirent *e = readdir(h))
if (lower(e->d_name) == want) { found = e->d_name; break; }
closedir(h);
std::error_code ec;
for (const auto &e : std::filesystem::directory_iterator(dir.empty() ? "." : dir, ec)) {
const std::string fileName = e.path().filename().string();
if (lower(fileName) == want) { found = fileName; break; }
}
if (found.empty()) return std::nullopt;
std::string text;
if (!readFile((dir.empty() ? "." : dir) + "/" + found, text)) return std::nullopt;
Expand Down