2020-08-11 00:08:48 -07:00
|
|
|
#ifndef POLSERVER_CODEGENERATOR_H
|
|
|
|
|
#define POLSERVER_CODEGENERATOR_H
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
|
|
|
{
|
|
|
|
|
class CompiledScript;
|
2020-08-24 01:47:38 -07:00
|
|
|
class CompilerWorkspace;
|
2020-08-11 00:08:48 -07:00
|
|
|
class InstructionEmitter;
|
2020-08-24 01:47:38 -07:00
|
|
|
class ModuleDeclarationRegistrar;
|
2020-08-11 00:08:48 -07:00
|
|
|
|
|
|
|
|
class CodeGenerator
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-03-06 01:39:26 +01:00
|
|
|
static std::unique_ptr<CompiledScript> generate( std::unique_ptr<CompilerWorkspace> );
|
2020-08-11 00:08:48 -07:00
|
|
|
|
|
|
|
|
private:
|
2020-08-24 01:47:38 -07:00
|
|
|
CodeGenerator( InstructionEmitter& , ModuleDeclarationRegistrar& );
|
2020-08-11 00:08:48 -07:00
|
|
|
|
|
|
|
|
void generate_instructions( CompilerWorkspace& );
|
2020-08-12 01:30:06 -07:00
|
|
|
|
2020-08-24 01:47:38 -07:00
|
|
|
void register_module_functions_alphabetically( CompilerWorkspace& );
|
|
|
|
|
|
|
|
|
|
static void sort_module_functions_by_module_name( CompilerWorkspace& );
|
|
|
|
|
static void sort_module_functions_alphabetically( CompilerWorkspace& );
|
|
|
|
|
|
2020-08-31 18:46:27 -07:00
|
|
|
static void sort_user_functions_alphabetically( CompilerWorkspace& );
|
|
|
|
|
|
2020-08-12 01:30:06 -07:00
|
|
|
private:
|
2020-08-24 01:47:38 -07:00
|
|
|
ModuleDeclarationRegistrar& module_declaration_registrar;
|
|
|
|
|
|
2020-08-12 01:30:06 -07:00
|
|
|
// Verb vs noun - see InstructionGenerator for reasoning
|
|
|
|
|
InstructionEmitter& emitter;
|
|
|
|
|
InstructionEmitter& emit;
|
2020-08-11 00:08:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Pol::Bscript::Compiler
|
|
|
|
|
|
|
|
|
|
#endif // POLSERVER_CODEGENERATOR_H
|