Fabcoin Core  0.16.2
P2P Digital Currency
Type.cpp
Go to the documentation of this file.
1 #include "Type.h"
2 
3 #include <llvm/IR/MDBuilder.h>
4 
5 #include "RuntimeManager.h"
6 
7 namespace dev
8 {
9 namespace eth
10 {
11 namespace jit
12 {
13 
14 llvm::IntegerType* Type::Word;
15 llvm::PointerType* Type::WordPtr;
16 llvm::IntegerType* Type::Bool;
17 llvm::IntegerType* Type::Size;
18 llvm::IntegerType* Type::Gas;
19 llvm::PointerType* Type::GasPtr;
20 llvm::IntegerType* Type::Byte;
21 llvm::PointerType* Type::BytePtr;
22 llvm::Type* Type::Void;
23 llvm::IntegerType* Type::MainReturn;
24 llvm::PointerType* Type::EnvPtr;
25 llvm::PointerType* Type::RuntimeDataPtr;
26 llvm::PointerType* Type::RuntimePtr;
27 llvm::ConstantInt* Constant::gasMax;
28 llvm::MDNode* Type::expectTrue;
29 
30 void Type::init(llvm::LLVMContext& _context)
31 {
32  if (!Word) // Do init only once
33  {
34  Word = llvm::Type::getIntNTy(_context, 256);
35  WordPtr = Word->getPointerTo();
36  Bool = llvm::Type::getInt1Ty(_context);
37  Size = llvm::Type::getInt64Ty(_context);
38  Gas = Size;
39  GasPtr = Gas->getPointerTo();
40  Byte = llvm::Type::getInt8Ty(_context);
41  BytePtr = Byte->getPointerTo();
42  Void = llvm::Type::getVoidTy(_context);
43  MainReturn = llvm::Type::getInt32Ty(_context);
44 
45  EnvPtr = llvm::StructType::create(_context, "Env")->getPointerTo();
47  RuntimePtr = RuntimeManager::getRuntimeType()->getPointerTo();
48 
49  Constant::gasMax = llvm::ConstantInt::getSigned(Type::Gas, std::numeric_limits<int64_t>::max());
50 
51  expectTrue = llvm::MDBuilder{_context}.createBranchWeights(1, 0);
52  }
53 }
54 
55 llvm::ConstantInt* Constant::get(int64_t _n)
56 {
57  return llvm::ConstantInt::getSigned(Type::Word, _n);
58 }
59 
60 llvm::ConstantInt* Constant::get(llvm::APInt const& _n)
61 {
62  return llvm::ConstantInt::get(Type::Word->getContext(), _n);
63 }
64 
65 llvm::ConstantInt* Constant::get(ReturnCode _returnCode)
66 {
67  return llvm::ConstantInt::get(Type::MainReturn, static_cast<uint64_t>(_returnCode));
68 }
69 
70 }
71 }
72 }
73 
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
static llvm::Type * Void
Definition: Type.h:32
static llvm::PointerType * RuntimePtr
Definition: Type.h:39
static llvm::PointerType * WordPtr
Definition: Type.h:22
static llvm::StructType * getRuntimeType()
static llvm::PointerType * BytePtr
Definition: Type.h:30
static llvm::StructType * getRuntimeDataType()
ExecStats::duration max
Definition: ExecStats.cpp:36
static llvm::IntegerType * Word
Definition: Type.h:21
static llvm::ConstantInt * gasMax
Definition: Type.h:49
static llvm::ConstantInt * get(int64_t _n)
Returns word-size constant.
Definition: Type.cpp:55
static llvm::IntegerType * MainReturn
Main function return type.
Definition: Type.h:35
static llvm::PointerType * RuntimeDataPtr
Definition: Type.h:38
static llvm::PointerType * GasPtr
Definition: Type.h:27
ReturnCode
Definition: JIT.h:86
static llvm::IntegerType * Bool
Definition: Type.h:24
static llvm::IntegerType * Size
Definition: Type.h:25
static void init(llvm::LLVMContext &_context)
Definition: Type.cpp:30
static llvm::MDNode * expectTrue
Definition: Type.h:42
static llvm::IntegerType * Gas
Definition: Type.h:26
static llvm::PointerType * EnvPtr
Definition: Type.h:37
static llvm::IntegerType * Byte
Definition: Type.h:29