Skip to content
Merged
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ jobs:
- name: Test
run: |
wasmtime \
-W threads=y -S threads=y \
--dir ${{github.workspace}}/build.wasi/install::/ \
--dir tests::tests \
${{github.workspace}}/build.wasi/install/usr/bin/cxx.wasm -v tests/manual/source.cc
Expand All @@ -205,6 +206,7 @@ jobs:
for i in src/parser/cxx/*.cc src/lsp/cxx/lsp/*.cc src/frontend/cxx/*.cc; do
echo "Parsing $i"
wasmtime \
-W threads=y -S threads=y \
--dir=src::/src \
--dir=build.wasi/_deps::/build.wasi/_deps \
--dir=build.wasi/src/parser::build.wasi/src/parser \
Expand Down
35 changes: 29 additions & 6 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
"displayName": "emscripten",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build.em",
"toolchainFile": "$env{EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "YES",
"CMAKE_TOOLCHAIN_FILE": "$env{EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build.em/install/usr",
"CMAKE_INTERPROCEDURAL_OPTIMIZATION": "YES",
Expand All @@ -48,9 +48,9 @@
"displayName": "wasi",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build.wasi",
"toolchainFile": "$env{WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "YES",
"CMAKE_TOOLCHAIN_FILE": "$env{WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build.wasi/install/usr",
"CMAKE_INTERPROCEDURAL_OPTIMIZATION": "YES",
Expand All @@ -62,6 +62,11 @@
"lhs": "$env{WASI_SDK_PATH}",
"rhs": ""
}
},
{
"name": "wasi-threads",
"inherits": "wasi",
"toolchainFile": "$env{WASI_SDK_PATH}/share/cmake/wasi-sdk-pthread.cmake"
}
],
"buildPresets": [
Expand Down Expand Up @@ -95,6 +100,15 @@
"name": "install-wasi",
"configurePreset": "wasi",
"targets": ["install"]
},
{
"name": "build-wasi-threads",
"configurePreset": "wasi-threads"
},
{
"name": "install-wasi-threads",
"configurePreset": "wasi-threads",
"targets": ["install"]
}
],
"testPresets": [
Expand All @@ -109,10 +123,6 @@
{
"name": "emscripten",
"configurePreset": "emscripten"
},
{
"name": "wasi",
"configurePreset": "wasi"
}
],
"workflowPresets": [
Expand Down Expand Up @@ -166,6 +176,19 @@
"name": "install-wasi"
}
]
},
{
"name": "wasi-threads",
"steps": [
{
"type": "configure",
"name": "wasi-threads"
},
{
"type": "build",
"name": "install-wasi-threads"
}
]
}
]
}
2 changes: 1 addition & 1 deletion Dockerfile.emsdk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM emscripten/emsdk:3.1.69 as em
FROM emscripten/emsdk:3.1.70 as em

RUN apt-get update && apt-get install -y \
ninja-build \
Expand Down
18 changes: 8 additions & 10 deletions packages/cxx-gen-ast/src/gen_ast_encoder_cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,36 +264,34 @@ auto ASTEncoder::encodeSourceLocation(const SourceLocation& loc)
return {};
}

std::string_view fileName;
std::uint32_t line = 0, column = 0;
unit_->getTokenStartPosition(loc, &line, &column, &fileName);
const auto start = unit_->tokenStartPosition(loc);

flatbuffers::Offset<io::SourceLine> sourceLineOffset;

auto key = std::tuple(fileName, line);
auto key = std::tuple(start.fileName, start.line);

if (sourceLines_.contains(key)) {
sourceLineOffset = sourceLines_.at(key).o;
} else {
flatbuffers::Offset<flatbuffers::String> fileNameOffset;

if (sourceFiles_.contains(fileName)) {
fileNameOffset = sourceFiles_.at(fileName);
if (sourceFiles_.contains(start.fileName)) {
fileNameOffset = sourceFiles_.at(start.fileName);
} else {
fileNameOffset = fbb_.CreateString(fileName);
sourceFiles_.emplace(fileName, fileNameOffset.o);
fileNameOffset = fbb_.CreateString(start.fileName);
sourceFiles_.emplace(start.fileName, fileNameOffset.o);
}

io::SourceLineBuilder sourceLineBuilder{fbb_};
sourceLineBuilder.add_file_name(fileNameOffset);
sourceLineBuilder.add_line(line);
sourceLineBuilder.add_line(start.line);
sourceLineOffset = sourceLineBuilder.Finish();
sourceLines_.emplace(std::move(key), sourceLineOffset.o);
}

io::SourceLocationBuilder sourceLocationBuilder{fbb_};
sourceLocationBuilder.add_source_line(sourceLineOffset);
sourceLocationBuilder.add_column(column);
sourceLocationBuilder.add_column(start.column);

auto offset = sourceLocationBuilder.Finish();

Expand Down
6 changes: 5 additions & 1 deletion scripts/cxx-wasmtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ const cxxWasiPrefixPath = path.join(workspacePath, "build.wasi/install");
const wasmtime = await which("wasmtime");

const cxxArgs = [
"-W",
"threads=y",
"-S",
"threads=y",
`--dir=${cxxWasiPrefixPath}/usr::/usr`,
`--dir=${process.cwd()}::/`,
`${cxxWasiPrefixPath}/usr/bin/cxx.wasm`,
];

try {
const result = await $`${wasmtime} ${cxxArgs} ${process.argv.slice(
3,
3
)}`.quiet();

echo`${result}`;
Expand Down
8 changes: 8 additions & 0 deletions src/frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ endif()

if (CMAKE_SYSTEM_NAME STREQUAL "WASI")
set_target_properties(cxx PROPERTIES SUFFIX ".wasm")

if (Threads_FOUND)
target_link_options(cxx PRIVATE
"SHELL:-Wl,--import-memory"
"SHELL:-Wl,--export-memory"
"SHELL:-Wl,--max-memory=134217728"
)
endif()
endif()

if(CXX_INTERPROCEDURAL_OPTIMIZATION)
Expand Down
22 changes: 6 additions & 16 deletions src/frontend/cxx/cxx_document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,17 @@ struct Diagnostics final : cxx::DiagnosticsClient {
Vector<lsp::Diagnostic> diagnostics{messages};

void report(const cxx::Diagnostic& diag) override {
std::string_view fileName;
std::uint32_t line = 0;
std::uint32_t column = 0;

preprocessor()->getTokenStartPosition(diag.token(), &line, &column,
&fileName);

std::uint32_t endLine = 0;
std::uint32_t endColumn = 0;

preprocessor()->getTokenEndPosition(diag.token(), &endLine, &endColumn,
nullptr);
auto start = preprocessor()->tokenStartPosition(diag.token());
auto end = preprocessor()->tokenEndPosition(diag.token());

auto tmp = json::object();

auto d = diagnostics.emplace_back();

int s = std::max(int(line) - 1, 0);
int sc = std::max(int(column) - 1, 0);
int e = std::max(int(endLine) - 1, 0);
int ec = std::max(int(endColumn) - 1, 0);
int s = std::max(int(start.line) - 1, 0);
int sc = std::max(int(start.column) - 1, 0);
int e = std::max(int(end.line) - 1, 0);
int ec = std::max(int(end.column) - 1, 0);

d.message(diag.message());
d.range().start(lsp::Position(tmp).line(s).character(sc));
Expand Down
11 changes: 2 additions & 9 deletions src/frontend/cxx/lsp_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,7 @@ void Server::Text::computeLineStartOffsets() {
}

Server::Server(const CLI& cli)
: cli(cli), input(std::cin), output(std::cout), log(std::cerr) {
// create workers
const auto workerCount = 4;

auto worker = [] {

};
}
: cli(cli), input(std::cin), output(std::cout), log(std::cerr) {}

Server::~Server() {}

Expand Down Expand Up @@ -138,7 +131,7 @@ auto Server::nextRequest() -> std::optional<json> {

if (it == headers.end()) {
return std::nullopt;
};
}

const auto contentLength = std::stoi(it->second);

Expand Down
21 changes: 8 additions & 13 deletions src/frontend/cxx/verify_diagnostics_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "verify_diagnostics_client.h"

#include <cxx/source_location.h>

namespace cxx {

auto VerifyDiagnosticsClient::verify() const -> bool { return verify_; }
Expand All @@ -46,11 +48,8 @@ void VerifyDiagnosticsClient::handleComment(Preprocessor* preprocessor,
return;
}

std::string_view fileName;
unsigned line = 0;
unsigned column = 0;

preprocessor->getTokenStartPosition(token, &line, &column, &fileName);
const auto pos = preprocessor->tokenStartPosition(token);
auto line = pos.line;

Severity severity = Severity::Error;

Expand All @@ -67,7 +66,7 @@ void VerifyDiagnosticsClient::handleComment(Preprocessor* preprocessor,
const auto& message = match[3];

expectedDiagnostics_.push_back(
{token, severity, std::string(fileName), message, line});
{token, severity, std::string(pos.fileName), message, line});
}

auto VerifyDiagnosticsClient::hasErrors() const -> bool {
Expand Down Expand Up @@ -121,15 +120,11 @@ auto VerifyDiagnosticsClient::findDiagnostic(const ExpectedDiagnostic& expected)
return false;
}

unsigned line = 0;
unsigned column = 0;
std::string_view fileName;

preprocessor()->getTokenStartPosition(d.token(), &line, &column, &fileName);
const auto pos = preprocessor()->tokenStartPosition(d.token());

if (line != expected.line) return false;
if (pos.line != expected.line) return false;

if (fileName != expected.fileName) return false;
if (pos.fileName != expected.fileName) return false;

if (d.message() != expected.message) return false;

Expand Down
41 changes: 13 additions & 28 deletions src/js/cxx/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,15 @@ struct DiagnosticsClient final : cxx::DiagnosticsClient {
val messages = val::array();

void report(const cxx::Diagnostic& diag) override {
std::string_view fileName;
std::uint32_t line = 0;
std::uint32_t column = 0;

preprocessor()->getTokenStartPosition(diag.token(), &line, &column,
&fileName);

std::uint32_t endLine = 0;
std::uint32_t endColumn = 0;

preprocessor()->getTokenEndPosition(diag.token(), &endLine, &endColumn,
nullptr);
const auto start = preprocessor()->tokenStartPosition(diag.token());
const auto end = preprocessor()->tokenEndPosition(diag.token());

val d = val::object();
d.set("fileName", val(std::string(fileName)));
d.set("startLine", val(line));
d.set("startColumn", val(column));
d.set("endLine", val(endLine));
d.set("endColumn", val(endColumn));
d.set("fileName", val(std::string(start.fileName)));
d.set("startLine", val(start.line));
d.set("startColumn", val(start.column));
d.set("endLine", val(end.line));
d.set("endColumn", val(end.column));
d.set("message", val(diag.message()));
messages.call<void>("push", d);
}
Expand Down Expand Up @@ -113,20 +103,15 @@ val getTokenLocation(std::intptr_t handle, std::intptr_t unitHandle) {

cxx::SourceLocation loc(handle);

unsigned startLine = 0, startColumn = 0;

unit->getTokenStartPosition(loc, &startLine, &startColumn);

unsigned endLine = 0, endColumn = 0;

unit->getTokenEndPosition(loc, &endLine, &endColumn);
const auto start = unit->tokenStartPosition(loc);
const auto end = unit->tokenEndPosition(loc);

val result = val::object();

result.set("startLine", startLine);
result.set("startColumn", startColumn);
result.set("endLine", endLine);
result.set("endColumn", endColumn);
result.set("startLine", start.line);
result.set("startColumn", start.column);
result.set("endLine", end.line);
result.set("endColumn", end.column);

return result;
}
Expand Down
15 changes: 6 additions & 9 deletions src/parser/cxx/diagnostics_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

// cxx
#include <cxx/preprocessor.h>
#include <cxx/source_location.h>

#include <cctype>
#include <cstdlib>
Expand Down Expand Up @@ -50,19 +51,15 @@ void DiagnosticsClient::report(const Diagnostic& diag) {
break;
} // switch

std::string_view fileName;
std::uint32_t line = 0;
std::uint32_t column = 0;
const auto pos = preprocessor_->tokenStartPosition(diag.token());

preprocessor_->getTokenStartPosition(diag.token(), &line, &column, &fileName);

if (!fileName.empty()) {
std::cerr << std::format("{}:{}:{}: {}\n", fileName, line, column,
diag.message());
if (!pos.fileName.empty()) {
std::cerr << std::format("{}:{}:{}: {}\n", pos.fileName, pos.line,
pos.column, diag.message());

const auto textLine = preprocessor_->getTextLine(diag.token());

const auto end = std::max(0, static_cast<int>(column) - 1);
const auto end = std::max(0, static_cast<int>(pos.column) - 1);

std::string indent{textLine.substr(0, end)};

Expand Down
Loading