forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from kyessenov/wasm_updates
implement expression evaluation in Wasm (#345)
- Loading branch information
Showing
18 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,17 @@ | ||
licenses(["notice"]) # Apache 2 | ||
|
||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_library", | ||
"envoy_package", | ||
) | ||
|
||
envoy_package() | ||
|
||
envoy_cc_library( | ||
name = "contrib_lib", | ||
hdrs = [ | ||
"proxy_expr.h", | ||
], | ||
) | ||
|
This file contains 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,75 @@ | ||
// Create an expression using a foreign function call. | ||
inline WasmResult createExpression(StringView expr, uint32_t* token) { | ||
std::string function = "expr_create"; | ||
char* out = nullptr; | ||
size_t out_size = 0; | ||
auto result = proxy_call_foreign_function(function.data(), function.size(), expr.data(), | ||
expr.size(), &out, &out_size); | ||
if (result == WasmResult::Ok && out_size == sizeof(uint32_t)) { | ||
*token = *reinterpret_cast<uint32_t*>(out); | ||
} | ||
::free(out); | ||
return result; | ||
} | ||
|
||
// Evaluate an expression using an expression token. | ||
inline Optional<WasmDataPtr> exprEvaluate(uint32_t token) { | ||
std::string function = "expr_evaluate"; | ||
char* out = nullptr; | ||
size_t out_size = 0; | ||
auto result = proxy_call_foreign_function(function.data(), function.size(), | ||
reinterpret_cast<const char*>(&token), sizeof(uint32_t), | ||
&out, &out_size); | ||
if (result != WasmResult::Ok) { | ||
return {}; | ||
} | ||
return std::make_unique<WasmData>(out, out_size); | ||
} | ||
|
||
// Delete an expression using an expression token. | ||
inline WasmResult exprDelete(uint32_t token) { | ||
std::string function = "expr_delete"; | ||
char* out = nullptr; | ||
size_t out_size = 0; | ||
auto result = proxy_call_foreign_function(function.data(), function.size(), | ||
reinterpret_cast<const char*>(&token), sizeof(uint32_t), | ||
&out, &out_size); | ||
::free(out); | ||
return result; | ||
} | ||
|
||
template <typename T> | ||
inline bool evaluateExpression(uint32_t token, T* out) { | ||
auto buf = exprEvaluate(token); | ||
if (!buf.has_value() || buf.value()->size() != sizeof(T)) { | ||
return false; | ||
} | ||
*out = *reinterpret_cast<const T*>(buf.value()->data()); | ||
return true; | ||
} | ||
|
||
template <> | ||
inline bool evaluateExpression<std::string>(uint32_t token, std::string* out) { | ||
auto buf = exprEvaluate(token); | ||
if (!buf.has_value()) { | ||
return false; | ||
} | ||
out->assign(buf.value()->data(), buf.value()->size()); | ||
return true; | ||
} | ||
|
||
// Specialization for message types (including struct value for lists and maps) | ||
template <typename T> | ||
inline bool evaluateMessage(uint32_t token, | ||
T* value_ptr) { | ||
auto buf = exprEvaluate(token); | ||
if (!buf.has_value()) { | ||
return false; | ||
} | ||
if (buf.value()->size() == 0) { | ||
// evaluates to null | ||
return true; | ||
} | ||
return value_ptr->ParseFromArray(buf.value()->data(), buf.value()->size()); | ||
} | ||
|
This file contains 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,26 @@ | ||
diff --git a/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp b/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp | ||
index c6cceda13..e86533759 100755 | ||
--- a/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp | ||
+++ b/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp | ||
@@ -104,7 +104,7 @@ void deserializeSets( | ||
|
||
} | ||
|
||
-ATNDeserializer::ATNDeserializer(): ATNDeserializer(ATNDeserializationOptions::getDefaultOptions()) { | ||
+ATNDeserializer::ATNDeserializer(): ATNDeserializer(ATNDeserializationOptions()) { | ||
} | ||
|
||
ATNDeserializer::ATNDeserializer(const ATNDeserializationOptions& dso): deserializationOptions(dso) { | ||
diff --git a/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp b/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp | ||
index 827c3d59f..62914cf55 100755 | ||
--- a/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp | ||
+++ b/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp | ||
@@ -69,7 +69,7 @@ void LexerATNSimulator::copyState(LexerATNSimulator *simulator) { | ||
} | ||
|
||
size_t LexerATNSimulator::match(CharStream *input, size_t mode) { | ||
- match_calls++; | ||
+ // match_calls++; | ||
_mode = mode; | ||
ssize_t mark = input->mark(); | ||
|
This file contains 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 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 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
Oops, something went wrong.