Goose  module.h at [443351dafe]

File bs/codegen/module.h artifact 02069afd34 part of check-in 443351dafe


#ifndef EMPATHY_CODEGEN_MODULE_H
#define EMPATHY_CODEGEN_MODULE_H

namespace empathy::codegen
{
    class Module
    {
        public:
            Module( const string& name );

            void dumpAsLlvmIr( const string& filename ) const;

            llvm::FunctionType* getOrCreateFuncType( const Context& c, const builtins::FuncType& ftype );

            llvm::Function* buildFuncProto( const Context& c, const builtins::Func& func, const string& name );

            llvm::Function* getOrCreateFunc( const Context& c, const builtins::Func& func );
            llvm::Function* getOrCreateFunc( const Context& c, const builtins::Func& func, const string& name );

        private:
            llvm::BasicBlock* buildBasicBlock( const Context& c, llvm::Function* pllvmFunc, const ptr< llr::BasicBlock >& pBB );

            llvm::Value* buildValue( const Context& c, llvm::Function* pllvmFunc, const Value& val );

            llvm::Value* buildInstruction( const Context& c, llvm::Function* pllvmFunc, const llr::Instruction& instr );
            llvm::Value* buildInstruction( const Context& c, llvm::Function* pllvmFunc, const llr::GetArg& ga );
            llvm::Value* buildInstruction( const Context& c, llvm::Function* pllvmFunc, const llr::Call& call );
            llvm::Value* buildInstruction( const Context& c, llvm::Function* pllvmFunc, const llr::LoadConstInt& lci );
            llvm::Value* buildInstruction( const Context& c, llvm::Function* pllvmFunc, const llr::LoadConstStr& lcs );

            bool buildTerminator( const Context& c, llvm::Function* pllvmFunc, const llr::Terminator& terminator );
            bool buildTerminator( const Context& c, llvm::Function* pllvmFunc, const llr::Ret& r );

            llvm::Module m_llvmModule;
            llvm::IRBuilder<> m_llvmBuilder;
    };
}

#endif