2 #ifndef HOBBES_EVAL_JITCC_HPP_INCLUDED 3 #define HOBBES_EVAL_JITCC_HPP_INCLUDED 38 llvm::IRBuilder<>* builder()
const;
39 llvm::Module* module();
42 void* getSymbolAddress(
const std::string&);
48 void defineGlobal(
const std::string& vname,
const ExprPtr& unsweetExp);
51 void bindGlobal(
const std::string& vn,
const MonoTypePtr& ty,
void* v);
54 bool isDefined(
const std::string&)
const;
59 llvm::Value*
compile(
const std::string& vname,
const ExprPtr& exp);
62 llvm::Value* compileAtGlobalScope(
const ExprPtr& exp);
65 llvm::Function* compileFunction(
const std::string& name,
const str::seq& argns,
const MonoTypes& argtys,
const ExprPtr& exp);
70 llvm::Value* compileAllocStmt(
size_t sz, llvm::Type* mty,
bool zeroMem =
false);
71 llvm::Value* compileAllocStmt(llvm::Value* sz, llvm::Type* mty,
bool zeroMem =
false);
74 llvm::Function* allocFunction(
const std::string& fname,
const MonoTypes& argl,
const MonoTypePtr& rty);
78 void bindScope(
const std::string& vn, llvm::Value* v);
83 void releaseMachineCode(
void*);
86 void bindInstruction(
const std::string&,
op*);
89 op* lookupOp(
const std::string&)
const;
92 llvm::Value* lookupVar(
const std::string&,
const MonoTypePtr&);
95 llvm::Function* lookupFunction(
const std::string&);
99 llvm::GlobalVariable* lookupVarRef(
const std::string&);
102 llvm::Value* internConstString(
const std::string&);
106 bytes machineCodeForExpr(
const ExprPtr&);
112 void* getMachineCode(llvm::Function*, llvm::JITEventListener* listener = 0);
123 #if LLVM_VERSION_MINOR == 6 || LLVM_VERSION_MINOR == 7 || LLVM_VERSION_MINOR == 8 124 llvm::legacy::PassManager* mpm;
127 typedef std::vector<llvm::ExecutionEngine*> ExecutionEngines;
128 ExecutionEngines eengines;
129 #elif LLVM_VERSION_MINOR == 3 130 llvm::PassManager* mpm;
131 llvm::ExecutionEngine* eengine;
132 llvm::FunctionPassManager* fpm;
133 #elif LLVM_VERSION_MINOR == 5 134 llvm::legacy::PassManager* mpm;
135 llvm::ExecutionEngine* eengine;
136 llvm::legacy::FunctionPassManager* fpm;
138 #error "This version of LLVM is not supported" 164 : name(name), argns(argns), argtys(argtys), exp(exp) { }
167 void unsafeCompileFunctions(UCFS*);
174 llvm::GlobalVariable*
var;
178 typedef std::map<std::string, Global>
Globals;
183 size_t pushGlobalRegion();
184 void popGlobalRegion(
size_t x);
191 llvm::GlobalVariable*
ref;
195 llvm::Value* loadConstant(
const std::string&);
202 llvm::GlobalVariable* maybeRefGlobal(
const std::string&);
203 llvm::GlobalVariable* refGlobal(
const std::string&, llvm::GlobalVariable*);
207 llvm::Value* maybeRefGlobalV(llvm::Value*);
216 typedef std::vector<llvm::Value*>
Values;
std::vector< llvm::Value * > Values
Definition: jitcc.H:216
Values compileArgs(jitcc *, const Exprs &)
Definition: jitcc.C:776
std::shared_ptr< PolyType > PolyTypePtr
Definition: type.H:23
void * value
Definition: jitcc.H:172
llvm::IRBuilder * irbuilder
Definition: jitcc.H:142
UCF(const std::string &name, const str::seq &argns, const MonoTypes &argtys, const ExprPtr &exp)
Definition: jitcc.H:163
Globals globals
Definition: jitcc.H:179
std::map< std::string, op * > FuncEnv
Definition: jitcc.H:145
GlobalExprs globalExprs
Definition: jitcc.H:212
llvm::Function * result
Definition: jitcc.H:161
llvm::GlobalVariable * var
Definition: jitcc.H:174
const std::string & name
Definition: jitcc.H:156
llvm::Constant * value
Definition: jitcc.H:188
std::vector< ExprPtr > Exprs
Definition: expr.H:59
FuncEnv fenv
Definition: jitcc.H:146
MonoTypePtr type
Definition: jitcc.H:171
MonoType::ptr MonoTypePtr
Definition: type.H:71
std::map< std::string, Global > Globals
Definition: jitcc.H:178
llvm::GlobalVariable * ref
Definition: jitcc.H:191
bool ignoreLocalScope
Definition: jitcc.H:152
std::vector< uint8_t > bytes
Definition: jitcc.H:105
MonoTypes argtys
Definition: jitcc.H:158
llvm::Function * fn
Definition: jitcc.H:175
std::shared_ptr< Expr > ExprPtr
Definition: expr.H:58
const ExprPtr & exp
Definition: jitcc.H:159
virtual PolyTypePtr type(typedb &) const =0
MonoTypePtr mtype
Definition: jitcc.H:190
std::vector< llvm::Module * > Modules
Definition: jitcc.H:120
std::vector< std::string > seq
Definition: str.H:19
llvm::Module * currentModule
Definition: jitcc.H:117
std::map< std::string, llvm::Value * > VarBindings
Definition: jitcc.H:149
std::vector< UCF > UCFS
Definition: jitcc.H:166
region globalData
Definition: jitcc.H:182
uint32_t result
Definition: regex.C:376
std::unordered_map< std::string, std::string > InternConstVars
Definition: jitcc.H:198
Constants constants
Definition: jitcc.H:194
std::map< std::string, Constant > Constants
Definition: jitcc.H:193
std::vector< VarBindings > VarBindingStack
Definition: jitcc.H:150
virtual llvm::Value * apply(jitcc *ev, const MonoTypes &tys, const MonoTypePtr &rty, const Exprs &es)=0
InternConstVars internConstVars
Definition: jitcc.H:199
virtual ~op()
Definition: jitcc.C:810
std::vector< MonoTypePtr > MonoTypes
Definition: type.H:72
std::vector< Binding > Bindings
Definition: expr.H:327
void compile(cc *, const ModulePtr &m)
Definition: cmodule.C:301
const str::seq & argns
Definition: jitcc.H:157
Modules modules
Definition: jitcc.H:121
llvm::Type * type
Definition: jitcc.H:189
VarBindingStack vtenv
Definition: jitcc.H:151
std::map< std::string, ExprPtr > GlobalExprs
Definition: jitcc.H:211