-
Notifications
You must be signed in to change notification settings - Fork 778
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
[WIP] Compile to buffer #3862
base: master
Are you sure you want to change the base?
[WIP] Compile to buffer #3862
Conversation
Hello, I am a code review agent on flows.network. Here are my reviews of changed source code files in this PR. include/api/wasmedge/wasmedge.hPotential issuesIssues:
Summary of changesSummary of Key Changes
include/llvm/codegen.hPotential issues
Summary of changes
lib/api/wasmedge.cppPotential issues
Summary of changes
lib/llvm/codegen.cppPotential issues
Summary of changes
test/api/APIAOTCoreTest.cppPotential issues
Summary of changes
|
@@ -1670,6 +1670,31 @@ WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_CompilerCompileFromBuffer( | |||
WasmEdge_CompilerContext *Cxt, const uint8_t *InBuffer, | |||
const uint64_t InBufferLen, const char *OutPath); | |||
|
|||
/// Compile the input WASM from the given buffer and output to another buffer. | |||
/// | |||
/// CAUTION: This function will be deprecated and replaced by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the following one will replace this function, why do we still need this now?
@@ -1685,6 +1710,24 @@ WASMEDGE_CAPI_EXPORT extern WasmEdge_Result | |||
WasmEdge_CompilerCompileFromBytes(WasmEdge_CompilerContext *Cxt, | |||
const WasmEdge_Bytes Bytes, | |||
const char *OutPath); | |||
/// Compile the input WASM from a WasmEdge_Bytes, and output it to a WasmEdge_Bytes./// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra ///
at the end of the line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also lost an empty line.
/// Compiling LLVM Module into loadable executable binary. | ||
class CodeGen { | ||
public: | ||
CodeGen(const Configure &Conf) noexcept : Conf(Conf) {} | ||
Expect<void> codegen(Span<const Byte> WasmData, Data D, | ||
std::filesystem::path OutputPath) noexcept; | ||
// returns number of bytes written to output buffer | ||
Expect<void> codegen_buffer(Span<const Byte> WasmData, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be codegenBuffer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think codegenToBuffer
is better.
|
||
private: | ||
Expect<LLVM::MemoryBuffer> codegen_osvec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe codegenMemBuf
or codegenOSVec
is better?
/// Compiling LLVM Module into loadable executable binary. | ||
class CodeGen { | ||
public: | ||
CodeGen(const Configure &Conf) noexcept : Conf(Conf) {} | ||
Expect<void> codegen(Span<const Byte> WasmData, Data D, | ||
std::filesystem::path OutputPath) noexcept; | ||
// returns number of bytes written to output buffer | ||
Expect<void> codegen_buffer(Span<const Byte> WasmData, | ||
Data D, Span<const Byte> OutByte, // not actually const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird. If the OutByte
is not actually const, then we should not use const Byte
here.
std::filesystem::path LLPath(OutputPath); | ||
LLPath.replace_extension("ll"sv); | ||
|
||
auto result = codegen_osvec(WasmData, D); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming style: Result
.
// TODO:return error | ||
// RH NOTE: the error values are all IllegalPath in this code when | ||
// I got here, I'm not sure if I should change the enum and update them | ||
// or if there's already a plan and scheme to do that... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are having the new release for 0.15, it's fine to update the enum and add more ErrCode
to show the real error value.
// avoiding a copy here would also involve modifying LLVM::MemoryBuffer. | ||
// Also trying to glue this function back to the CAPI proved annoying for | ||
// const preservation, so here is an ugly const cast. | ||
memcpy(const_cast<uint8_t*>(OutByte.data()), buf.data(), buf.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to use copy_n
instead of any memcpy
series function.
} | ||
|
||
LLVM::MemoryBuffer& buf = *result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming issue: Buf
.
|
||
*OutSize = 0; | ||
|
||
auto result = codegen_osvec(WasmData, D); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming issue: Result
.
Thanks for the reviews I'll get back to this hopefully in the coming week |
Hi guys!
We need this compile-to-buffer API for the Xahau blockchain (https://github.com/Xahau/xahaud ) which uses WasmEdge for smart contracts, specifically we want to use ahead of time compilation to cache execution of frequently used contracts.
I haven't had time to test, this is just a preliminary version of the PR. If someone else thinks this is a needed API change please feel free to assist.