This repository has been archived by the owner on Oct 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Execute shared library. Do away with LLVM JIT (#29)
* Execute shared library. Do away with LLVM JIT * Minor header improvements * Rename ScillaVM to ScillaRTL and reorg * Rename DEBUG/dbgs logging to DLog/dlog * Use clang-10 explicitly when compiling to shared lib * Use clang-10 package in CI
- Loading branch information
1 parent
1de2bc3
commit 3523695
Showing
39 changed files
with
1,289 additions
and
1,581 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
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
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,123 @@ | ||
/* | ||
* Copyright (C) 2019 Zilliqa | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
#include <boost/any.hpp> | ||
#include <jsoncpp/json/json.h> | ||
|
||
// Forward declarations. | ||
namespace ScillaRTL { | ||
|
||
// Information that Scilla will need to execute contracts. | ||
struct ScillaParams { | ||
struct StateQuery { | ||
std::string Name; | ||
int MapDepth; | ||
std::vector<std::string> Indices; | ||
bool IgnoreVal; | ||
}; | ||
// A Scilla state contains either std::string or a MapValueT | ||
// We use boost::any to capture this. Using std::variant is | ||
// cumbersome because of the recursive type definition required. | ||
// https://stackoverflow.com/questions/43309468/recursive-data-structure-with-variant | ||
using MapValueT = std::unordered_map<std::string, boost::any>; | ||
|
||
using FetchState_Type = std::function<bool(const StateQuery &Query, | ||
boost::any &RetVal, bool &Found)>; | ||
using FetchRemoteState_Type = | ||
std::function<bool(const std::string &Addr, const StateQuery &Query, | ||
boost::any &RetVal, bool &Found, std::string &Type)>; | ||
using UpdateState_Type = | ||
std::function<bool(const StateQuery &Query, const boost::any &Val)>; | ||
|
||
FetchState_Type fetchStateValue; | ||
FetchRemoteState_Type fetchRemoteStateValue; | ||
UpdateState_Type updateStateValue; | ||
|
||
ScillaParams() | ||
: fetchStateValue(nullptr), fetchRemoteStateValue(nullptr), | ||
updateStateValue(nullptr){}; | ||
ScillaParams(FetchState_Type FS, FetchRemoteState_Type FRS, | ||
UpdateState_Type US) | ||
: fetchStateValue(FS), fetchRemoteStateValue(FRS), updateStateValue(US){}; | ||
}; | ||
|
||
class ScillaExecImpl; | ||
|
||
// Typical usage: | ||
// 1. ScillaContrExec SJ(...); | ||
// 2. (a) Deployment (b) Transition execution | ||
// a. auto Output = SJ.deploy(...); | ||
// OR | ||
// b. auto Output = SJ.execMsg(...); | ||
// 3. If ScillaError exception, check remaining gas with SJ.getGasRem(). | ||
class ScillaContrExec { | ||
private: | ||
std::unique_ptr<ScillaExecImpl> PImpl; | ||
|
||
public: | ||
// @ContrBin is the path to a contract's shared object `foo.so` | ||
// generated by compiling `foo.scilla` with scilla-llvm into `foo.bc` | ||
// and compiling this LLVM bitcode with `clang -shared foo.bc -o foo.so`. | ||
ScillaContrExec(const ScillaParams &SPs, const std::string &ContrBin); | ||
~ScillaContrExec(); | ||
|
||
// Execute a message. | ||
Json::Value execMsg(const std::string &Balance, uint64_t GasLimit, | ||
const Json::Value &InitJ, const Json::Value &Msg); | ||
|
||
// Initialize the contract state to field initialization values in the source. | ||
// This is to be called only during deployment of the contract. Never again. | ||
Json::Value deploy(const Json::Value &InitJ, uint64_t GasLimit); | ||
|
||
// What's the gas remaining from previous execution (deploy / execMsg). | ||
// Useful if execution was interrupted due to an exception. | ||
// Use with care if you don't want to end up with a stale value. | ||
uint64_t getGasRem() const; | ||
}; | ||
|
||
// Typical usage: | ||
// 1. ScillaExprExec SJ(...); | ||
// 2. auto Output = SJ.exec(); | ||
// 3. If ScillaError exception, check remaining gas with SJ.getGasRem(). | ||
class ScillaExprExec { | ||
private: | ||
std::unique_ptr<ScillaExecImpl> PImpl; | ||
|
||
public: | ||
// @ExprBin is the path to a pure scilla expressions's shared object `foo.so` | ||
// generated by compiling `foo.scilexp` with expr-llvm into `foo.bc` | ||
// and compiling this LLVM bitcode with `clang -shared foo.bc -o foo.so`. | ||
ScillaExprExec(const ScillaParams &SPs, const std::string &ExprBin); | ||
~ScillaExprExec(); | ||
|
||
// Execute the expression. | ||
std::string exec(uint64_t GasLimit); | ||
|
||
// What's the gas remaining from previous execution of exec(). | ||
// Useful if execution was interrupted due to an exception. | ||
// Use with care if you don't want to end up with a stale value. | ||
uint64_t getGasRem() const; | ||
}; | ||
|
||
} // namespace ScillaRTL |
Oops, something went wrong.