polserver/pol-core/bscript/compiler/codegen/CodeGenerator.h
Eric Swanson cf42b03e3c
New compiler: Add AST nodes for function calls. Can compile hello world. (#240)
Adds:
- ast/Argument: AST node for an argument passed to a function.
- ast/FunctionCall: AST node for a function call.
- codegen/ModuleDeclarationRegistrar: The code generator registers module function declarations with this in order to determine module indexes and function indexes for instructions.
- model/FunctionLink: this is a reference either:
  - from: a FunctionCall or a FunctionReference
  - to: a ModuleFunctionDeclaration or a UserFunction
- optimizer/ReferencedFunctionGatherer: a visitor that determines which module functions and user functions are referenced, by looking at function calls and function references.

Also:
- CodeGenerator registers module functions
- InstructionGenerator generates code for function calls
- InstructionEmitter generates TOK_FUNC instructions
- StoredTokenDecoder decodes TOK_FUNC instructions

After all of this, the compiler can compile print("hello, world");
2020-08-24 01:47:38 -07:00

42 lines
1.2 KiB
C++

#ifndef POLSERVER_CODEGENERATOR_H
#define POLSERVER_CODEGENERATOR_H
#include <memory>
namespace Pol::Bscript::Compiler
{
class CompiledScript;
class CompilerWorkspace;
class InstructionEmitter;
struct LegacyFunctionOrder;
class ModuleDeclarationRegistrar;
class CodeGenerator
{
public:
static std::unique_ptr<CompiledScript> generate( std::unique_ptr<CompilerWorkspace>,
const LegacyFunctionOrder* );
private:
CodeGenerator( InstructionEmitter& , ModuleDeclarationRegistrar& );
void generate_instructions( CompilerWorkspace& );
void register_module_functions( CompilerWorkspace&, const LegacyFunctionOrder* );
void register_module_functions_as_legacy( CompilerWorkspace& );
void register_module_functions_alphabetically( CompilerWorkspace& );
static void sort_module_functions_by_module_name( CompilerWorkspace& );
static void sort_module_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