Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F2731019
compilepass.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Mar 14, 2:42 AM
Size
4 KB
Mime Type
text/x-c++
Expires
Mon, Mar 16, 2:42 AM (1 d, 7 h)
Engine
blob
Format
Raw Data
Handle
243784
Attached To
rXR Xreate
compilepass.h
View Options
#ifndef COMPILEPASS_H
#define COMPILEPASS_H
#include "abstractpass.h"
#include "llvm/IR/Function.h"
namespace xreate {
class AdhocScheme;
class ClaspLayer;
class ContextQuery;
class LLVMLayer;
}
//namespace llvm {
// class Function;
// class Value;
// class Type;
//}
namespace xreate {
class CompilePass;
namespace compilation {
class AbstractCodeScopeUnit;
class FunctionUnit;
class TargetInterpretation;
class TransformationsManager;
struct Context{
AbstractCodeScopeUnit* scope;
FunctionUnit* function;
CompilePass* pass;
};
class CallStatement {
public:
virtual llvm::Value* operator() (std::vector<llvm::Value *>&& args, const std::string& hintDecl="") = 0;
};
class CallStatementRaw: public CallStatement{
public:
CallStatementRaw(llvm::Function* callee, LLVMLayer* l)
: __callee(callee), __calleeTy(callee->getFunctionType()), llvm(l) {}
CallStatementRaw(llvm::Value* callee, llvm::FunctionType* ty, LLVMLayer* l)
: __callee(callee), __calleeTy(ty), llvm(l) {}
llvm::Value* operator() (std::vector<llvm::Value *>&& args, const std::string& hintDecl="");
private:
llvm::Value* __callee;
llvm::FunctionType* __calleeTy;
LLVMLayer* llvm;
};
class AbstractCodeScopeUnit{
public:
CompilePass* const pass;
FunctionUnit* const function;
CodeScope* const scope;
AbstractCodeScopeUnit(CodeScope* codeScope, FunctionUnit* f, CompilePass* compilePass);
virtual ~AbstractCodeScopeUnit();
virtual llvm::Value* compile(const std::string& hintBlockDecl="")=0;
virtual llvm::Value* processSymbol(const Symbol& s, std::string hintRetVar="")=0;
virtual llvm::Value* process(const Expression& expr, const std::string& hintVarDecl="")=0;
virtual void bindArg(llvm::Value* value, std::string&& alias)=0;
virtual void bindArg(llvm::Value* value, const ScopedSymbol& s)=0;
protected:
virtual CallStatement* findFunction(const std::string& callee)=0;
};
class BasicCodeScopeUnit: public AbstractCodeScopeUnit{
public:
BasicCodeScopeUnit(CodeScope* codeScope, FunctionUnit* f, CompilePass* compilePass);
llvm::Value* processSymbol(const Symbol& s, std::string hintRetVar="");
llvm::Value* process(const Expression& expr, const std::string& hintVarDecl="");
llvm::Value* compile(const std::string& hintBlockDecl="");
protected:
CallStatement* findFunction(const std::string& callee);
};
class IFunctionDecorator {
protected:
virtual std::string prepareName() = 0;
virtual std::vector<llvm::Type*> prepareArguments() = 0;
virtual llvm::Type* prepareResult() = 0;
virtual llvm::Function::arg_iterator prepareBindings() = 0;
virtual ~IFunctionDecorator(){}
};
class FunctionUnit: public IFunctionDecorator{
public:
FunctionUnit(ManagedFnPtr f, CompilePass* p)
: function(f), pass(p) {}
~FunctionUnit();
llvm::Function* compile();
AbstractCodeScopeUnit* getEntry();
AbstractCodeScopeUnit* getScopeUnit(CodeScope* scope);
AbstractCodeScopeUnit* getScopeUnit(ManagedScpPtr scope);
ManagedFnPtr function;
llvm::Function* raw = nullptr;
protected:
CompilePass* pass=nullptr;
private:
std::map<CodeScope*, std::weak_ptr<AbstractCodeScopeUnit>> __scopes;
std::list<std::shared_ptr<AbstractCodeScopeUnit>> __orphanedScopes;
};
class BasicFunctionDecorator: public FunctionUnit{
public:
BasicFunctionDecorator(ManagedFnPtr f, CompilePass* p)
: FunctionUnit(f, p) {}
protected:
std::string prepareName();
virtual std::vector<llvm::Type*> prepareArguments();
virtual llvm::Type* prepareResult();
virtual llvm::Function::arg_iterator prepareBindings();
};
} // end of namespace `xreate::compilation`
class CompilePass : public AbstractPass<void> {
friend class LateContextCompiler;
friend class LateContextCompiler2;
friend class compilation::BasicCodeScopeUnit;
friend class compilation::FunctionUnit;
public:
compilation::TransformationsManager* managerTransformations;
compilation::TargetInterpretation* targetInterpretation;
CompilePass(PassManager* manager): AbstractPass<void>(manager) {}
compilation::FunctionUnit* getFunctionUnit(const ManagedFnPtr& function);
void run() override;
llvm::Function* getEntryFunction();
static void prepareQueries(ClaspLayer* clasp);
private:
//TODO free `functions` in destructor
std::map<unsigned int, compilation::FunctionUnit*> functions;
llvm::Function* entry = 0;
ContextQuery* queryContext;
};
}
#endif // COMPILEPASS_H
Event Timeline
Log In to Comment