| 1 | //===- ConnectionSpec.cpp - Connection spec parsing -----------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/ExecutionEngine/Orc/Shared/ConnectionSpec.h" |
| 10 | |
| 11 | using namespace llvm; |
| 12 | using namespace llvm::orc; |
| 13 | |
| 14 | static Error makeConnectionSpecError(StringRef Spec, const Twine &Msg) { |
| 15 | return make_error<StringError>(Args: "in connection spec '" + Spec.str() + |
| 16 | "': " + Msg, |
| 17 | Args: inconvertibleErrorCode()); |
| 18 | } |
| 19 | |
| 20 | Expected<ConnectionSpec> ConnectionSpec::parse(StringRef Spec) { |
| 21 | if (!Spec.contains(C: '=')) |
| 22 | return makeConnectionSpecError( |
| 23 | Spec, Msg: "expected '<transport>[:<action>]=<descriptor>', but found " |
| 24 | "no '='" ); |
| 25 | |
| 26 | auto [LHS, Descriptor] = Spec.split(Separator: '='); |
| 27 | auto [Transport, Action] = LHS.split(Separator: ':'); |
| 28 | |
| 29 | if (Transport.empty()) |
| 30 | return makeConnectionSpecError(Spec, Msg: "empty transport name" ); |
| 31 | |
| 32 | // An action is optional, but writing the ':' that introduces one and then |
| 33 | // omitting it is an error. |
| 34 | if (LHS.contains(C: ':') && Action.empty()) |
| 35 | return makeConnectionSpecError(Spec, Msg: "empty action name" ); |
| 36 | |
| 37 | return ConnectionSpec(Transport.str(), Action.str(), Descriptor.str()); |
| 38 | } |
| 39 | |