#ifndef _CODEGEN_H_ #define _CODEGEN_H_ #include #include #include #include #include #include #include #include class Node; class NBlock; class NIdentifier; // this is one generated block of LLVM code, containing also // all local variables known in this scope class CodeGenBlock { public: llvm::BasicBlock *m_block; std::map m_locals; }; // this class we pass along our ADT structure class CodeGenContext { public: typedef std::map Locals; private: std::stack m_blocks; llvm::Module *m_module; llvm::Function *m_mainFunction; Locals m_locals; public: CodeGenContext( ); void printGeneratedCode( ); std::string getGeneratedCode( ); void generateCode( NBlock& _root ); llvm::GenericValue runCode( ); static llvm::Type *variableType( const NIdentifier& _type ); void pushBlock( llvm::BasicBlock *_block ); void popBlock( ); llvm::BasicBlock *currentBlock( ); Locals& locals( ) { return m_blocks.top( )->m_locals; } llvm::Module *module( ) { return m_module; } }; #endif // _CODEGEN_H_