-
Notifications
You must be signed in to change notification settings - Fork 31
Add option to start interactive server for Parser dialect conversion #768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
93eeaa2
server: Add JSON-RPC scaffolding code.
frabert ca110c2
pr: Pass a `function_op_interface` instead of a name to `parser_conve…
frabert 6be2588
pr: Add option to use interactive server in parser conversion pass.
frabert efeb970
pr: Unify function type legalization
xlauko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // Copyright (c) 2024-present, Trail of Bits, Inc. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <span> | ||
| #include <stdexcept> | ||
| #include <string> | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| #include <gap/core/crtp.hpp> | ||
|
|
||
| #include "vast/Util/Warnings.hpp" | ||
|
|
||
| namespace vast::server { | ||
| class connection_closed : public std::runtime_error | ||
| { | ||
| public: | ||
| connection_closed() : std::runtime_error("Connection closed") {} | ||
|
|
||
| connection_closed(const char *what) : std::runtime_error(what) {} | ||
| }; | ||
|
|
||
| struct io_adapter | ||
| { | ||
| virtual ~io_adapter() = default; | ||
|
|
||
| virtual void close() {} | ||
|
|
||
| virtual size_t read_some(std::span< char > dst) = 0; | ||
| virtual size_t write_some(std::span< const char > dst) = 0; | ||
|
|
||
| // Upon completion, `dst` is filled with data. | ||
| void read_all(std::span< char > dst) { | ||
| while (!dst.empty()) { | ||
| size_t nread = read_some(dst); | ||
| dst = dst.subspan(nread); | ||
| } | ||
| } | ||
|
|
||
| // Upon completion, all of the data in `src` is written to the client.. | ||
| void write_all(std::span< const char > src) { | ||
| while (!src.empty()) { | ||
| size_t nwritten = write_some(src); | ||
| src = src.subspan(nwritten); | ||
| } | ||
| } | ||
|
|
||
| char read() { | ||
| char res[1]; | ||
| read_all(res); | ||
| return res[0]; | ||
| } | ||
| }; | ||
|
|
||
| class file_adapter final : public io_adapter | ||
| { | ||
| FILE *ifd; | ||
| FILE *ofd; | ||
|
|
||
| public: | ||
| file_adapter(FILE *ifd = stdin, FILE *ofd = stdout) : ifd(ifd), ofd(ofd) { | ||
| VAST_ASSERT(ifd != nullptr); | ||
| VAST_ASSERT(ofd != nullptr); | ||
|
|
||
| setvbuf(ofd, NULL, _IONBF, 0); | ||
| } | ||
|
|
||
| size_t read_some(std::span< char > dst) override { | ||
| size_t nread = fread(dst.data(), 1, dst.size_bytes(), ifd); | ||
| if (nread == 0 && (feof(ifd) || ferror(ifd))) { | ||
| throw connection_closed{}; | ||
| } | ||
| return nread; | ||
| } | ||
|
|
||
| size_t write_some(std::span< const char > src) override { | ||
| size_t nwritten = fwrite(src.data(), 1, src.size_bytes(), ofd); | ||
| if (src.size() != 0 && nwritten == 0) { | ||
| throw connection_closed{}; | ||
| } | ||
| return nwritten; | ||
| } | ||
| }; | ||
|
|
||
| class sock_adapter final : public io_adapter | ||
| { | ||
| public: | ||
| struct impl; | ||
|
|
||
| size_t read_some(std::span< char > dst) override; | ||
| size_t write_some(std::span< const char > src) override; | ||
| ~sock_adapter(); | ||
| void close() override; | ||
|
|
||
| static std::unique_ptr< sock_adapter > create_unix_socket(const std::string &path); | ||
|
|
||
| private: | ||
| std::unique_ptr< struct impl > pimpl; | ||
| sock_adapter(std::unique_ptr< impl > pimpl); | ||
| }; | ||
| } // namespace vast::server | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.