polserver/pol-core/bscript/compiler/Compiler.h
turleypol 7090c64840
Short Circuit Optimizer (#797)
* first working short curcuit for && and or
creates jumps after each expressions to skip the following

* fixed valuestack when short circuit jmp does not jump

* use specialized instructions for short circuit && and ||

1: lhs
2: logical jump if false/true goto 4 <- if jmp do logical convert
3: rhs
4: logical convert
5: rest

logical convert is needed since "normal" && || operations convert isTrue
to BLong

added BObjectRef BObjectImp set specialization to remove noise

* fixed converted objimp when jump on false values

* first version of short circuit warning
should be moved to analyzer
added whitelist of module functions which have no sideeffect to reduce
the number of warnings

* moved warning visitor to analyzer and added it as extra compile step
fixed sourceline print and cache the content

* missing include, unused member

* included the correct header

* ecompile.cfg to activate and warn
ecompile cmdline arg to activate it
run all tests also with it active
fixed that only the most right side statement was checked

* ecompile cmdline

* increase ecompile version
cleanup

* compilation error

* missing header

* allow -S- to deactivate shortcircuit like the other params do

* extended whitelist functions

* revert fileformat version increase
fixed escript test cmake

* use the correct arg

* escript testoutput can now be different if shortcircuit is active

* docs

* additional test

* addressed comments
2025-07-28 21:48:34 +02:00

56 lines
1.8 KiB
C++

#ifndef POLSERVER_COMPILER_H
#define POLSERVER_COMPILER_H
#include <memory>
#include <string>
#include "bscript/compiler/model/UserFunctionInclusion.h"
namespace Pol::Bscript::Compiler
{
class CompiledScript;
class CompilerWorkspace;
class SourceFileCache;
class Profile;
class Report;
class Compiler
{
public:
Compiler( SourceFileCache& em_cache, SourceFileCache& inc_cache, Profile& );
~Compiler();
Compiler( const Compiler& ) = delete;
Compiler& operator=( const Compiler& ) = delete;
bool compile_file( const std::string& filename );
bool write_ecl( const std::string& pathname );
void write_listing( const std::string& pathname );
void write_string_tree( const std::string& pathname );
void write_dbg( const std::string& pathname, bool include_debug_text );
void write_included_filenames( const std::string& pathname );
void set_include_compile_mode();
void compile_file_steps( const std::string& pathname, Report& );
bool format_file( const std::string& filename, bool is_module, bool inplace );
private:
std::unique_ptr<CompilerWorkspace> build_workspace( const std::string&, Report& );
void register_constants( CompilerWorkspace&, Report& );
void optimize( CompilerWorkspace&, Report& );
void disambiguate( CompilerWorkspace&, Report& );
void analyze( CompilerWorkspace&, Report& );
void check_short_circuit( CompilerWorkspace&, Report& );
std::unique_ptr<CompiledScript> generate( std::unique_ptr<CompilerWorkspace>, Report& );
void display_outcome( const std::string& filename, Report& );
SourceFileCache& em_cache;
SourceFileCache& inc_cache;
Profile& profile;
std::unique_ptr<CompiledScript> output;
UserFunctionInclusion user_function_inclusion = UserFunctionInclusion::ReferencedOnly;
};
} // namespace Pol::Bscript::Compiler
#endif // POLSERVER_COMPILER_H