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;
|
2024-08-06 20:29:02 +02:00
|
|
|
class FunctionReferenceRegistrar;
|
2020-08-11 00:08:48 -07:00
|
|
|
class InstructionEmitter;
|
2020-08-24 01:47:38 -07:00
|
|
|
class ModuleDeclarationRegistrar;
|
2024-08-19 19:57:31 +02:00
|
|
|
class Report;
|
2020-08-11 00:08:48 -07:00
|
|
|
|
|
|
|
|
class CodeGenerator
|
|
|
|
|
{
|
|
|
|
|
public:
|
2024-08-19 19:57:31 +02:00
|
|
|
static std::unique_ptr<CompiledScript> generate( std::unique_ptr<CompilerWorkspace>,
|
2025-07-23 23:00:34 +02:00
|
|
|
Report& report, bool generate_ast_string );
|
2020-08-11 00:08:48 -07:00
|
|
|
|
|
|
|
|
private:
|
2024-08-06 20:29:02 +02: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
|