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
/
Copy pathScillaExecImpl.h
80 lines (71 loc) · 3.25 KB
/
ScillaExecImpl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Copyright (C) 2021 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/>.
*/
#include <json/json.h>
#include <memory>
#include "ObjManager.h"
#include "ScillaRTL/ScillaExec.h"
namespace ScillaRTL {
class SharedObject;
class TransitionState;
class ScillaExecImpl {
private:
void initContrParams(const Json::Value &CP, bool DoDynamicTypechecks);
std::unique_ptr<ScillaTypes::TypParserPartialCache> TPPC;
// Get the type descriptors table and its length.
std::pair<const ScillaTypes::Typ **, int> getTypeDescrTable() const;
const std::unique_ptr<SharedObject> SO;
uint64_t *const GasRemPtr;
friend bool dynamicTypecheck(const ScillaExecImpl *SJ,
const ScillaTypes::Typ *TargetT,
const ScillaTypes::Typ *ParsedT, const void *Val,
bool ChargeGas);
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`.
ScillaExecImpl(const ScillaParams &SPs, const std::string &ContrBin);
~ScillaExecImpl();
// Get address for @Symbol inside the compiled IR, ready to be used.
void *getAddressFor(const std::string &Symbol) const;
// Initialize gas-remaining field in the code and initialize libraries.
void initGasAndLibs(uint64_t GasRem);
// 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;
// Parse a string into a Scilla type. Raises error on failure.
const ScillaTypes::Typ *parseTypeString(const std::string &) const;
// Raise an out-of-gas exception.
static void outOfGasException(void);
// Consume N units of gas. Raise an error if we're out of gas.
void consumeGas(uint64_t N) const;
// Scilla values dynamically allocated and owned by the JIT engine.
ObjManager OM;
// Scilla configuration parameters.
const ScillaParams SPs;
// The state of execution specific to a transition.
std::unique_ptr<TransitionState> TS;
// If the Scilla code wants to print something, that goes here.
std::string ScillaStdout;
};
} // namespace ScillaRTL