/*
 * LateContextCompiler2.h
 *
 *  Created on: 10 февр. 2016
 *      Author: pgess
 */

//TOTEST compile several context arguments 
#ifndef LATECONTEXTCOMPILER2_H_
#define LATECONTEXTCOMPILER2_H_

#include "serialization.h"

namespace llvm {
	class Value;
	class Function;
}

namespace xreate {
	class CompilePass;

namespace compilation {
	class FunctionUnit;
}}

namespace xreate {

typedef unsigned int ScopePacked;
class LateContextCompiler2 {
public:
	llvm::Value* rawContextArgument = nullptr;

	LateContextCompiler2(compilation::FunctionUnit* f, CompilePass* p);
	llvm::Value* findFunction(const std::string& calleeName, llvm::Function* specializationDefault, ScopePacked scopeCaller);
	llvm::Value* compileContextArgument(const std::string& callee, ScopePacked scopeCaller);
        size_t getFunctionDemandSize() const;

private:
	//boost::bimap<size_t, std::string> __decisions;
	//std::vector<Domain> __scheme;

	compilation::FunctionUnit* function;
	CompilePass* pass;
        size_t __sizeOfDemand;
        
        llvm::Value* compileDependentDecision(const Expression& topic, ScopePacked scopeCaller);
        llvm::Value* compileDecisionSelectorAsSwitch(llvm::Value* selector, std::vector<llvm::Function*> vectorVariants, llvm::Function* variantDefault);
};
} /* namespace xreate */

#endif /* LATECONTEXTCOMPILER2_H_ */