polserver/pol-core/bscript/compiler/codegen/CodeGenerator.h
Kevin Eady 87e0c534f4
Add ecompile flag -Z to print AST (#796)
* Add -Z option to print string tree

* Simple test to print an AST

* Make CompiledScript owner of the tree

* some refactoring
- rename ecompile.cfg option
- rename AST generator class

* core-changes, docs

* fix warnings
2025-07-23 23:00:34 +02:00

43 lines
1.2 KiB
C++

#ifndef POLSERVER_CODEGENERATOR_H
#define POLSERVER_CODEGENERATOR_H
#include <memory>
namespace Pol::Bscript::Compiler
{
class CompiledScript;
class CompilerWorkspace;
class FunctionReferenceRegistrar;
class InstructionEmitter;
class ModuleDeclarationRegistrar;
class Report;
class CodeGenerator
{
public:
static std::unique_ptr<CompiledScript> generate( std::unique_ptr<CompilerWorkspace>,
Report& report, bool generate_ast_string );
private:
CodeGenerator( InstructionEmitter&, ModuleDeclarationRegistrar& );
void generate_instructions( CompilerWorkspace& );
void register_module_functions_alphabetically( CompilerWorkspace& );
static void sort_module_functions_by_module_name( CompilerWorkspace& );
static void sort_module_functions_alphabetically( CompilerWorkspace& );
static void sort_user_functions_alphabetically( CompilerWorkspace& );
private:
ModuleDeclarationRegistrar& module_declaration_registrar;
// Verb vs noun - see InstructionGenerator for reasoning
InstructionEmitter& emitter;
InstructionEmitter& emit;
};
} // namespace Pol::Bscript::Compiler
#endif // POLSERVER_CODEGENERATOR_H