From 6e8c7ad074ed22f83a28ff112c2649c490395721 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Tue, 4 Aug 2020 22:42:46 -0700 Subject: [PATCH] Add stub for new compiler, with -g and UseCompiler2020 options to select. (#184) --- pol-core/bscript/CMakeSources.cmake | 2 ++ pol-core/bscript/compiler/Compiler.cpp | 37 ++++++++++++++++++++++++++ pol-core/bscript/compiler/Compiler.h | 32 ++++++++++++++++++++++ pol-core/bscript/compilercfg.cpp | 2 ++ pol-core/bscript/compilercfg.h | 1 + pol-core/ecompile/ECompileMain.cpp | 33 +++++++++++++++++------ 6 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 pol-core/bscript/compiler/Compiler.cpp create mode 100644 pol-core/bscript/compiler/Compiler.h diff --git a/pol-core/bscript/CMakeSources.cmake b/pol-core/bscript/CMakeSources.cmake index 09e986b87a..565460344e 100644 --- a/pol-core/bscript/CMakeSources.cmake +++ b/pol-core/bscript/CMakeSources.cmake @@ -7,6 +7,8 @@ set (bscript_sources # sorted ! ../../lib/EscriptGrammar/EscriptParserBaseListener.h ../../lib/EscriptGrammar/EscriptParserListener.cpp ../../lib/EscriptGrammar/EscriptParserListener.h + compiler/Compiler.cpp + compiler/Compiler.h CMakeSources.cmake StdAfx.h StoredToken.cpp diff --git a/pol-core/bscript/compiler/Compiler.cpp b/pol-core/bscript/compiler/Compiler.cpp new file mode 100644 index 0000000000..b5cd35e8d8 --- /dev/null +++ b/pol-core/bscript/compiler/Compiler.cpp @@ -0,0 +1,37 @@ +#include "Compiler.h" + +namespace Pol +{ +namespace Bscript +{ +namespace Compiler +{ +Compiler::Compiler() = default; + +Compiler::~Compiler() = default; + +bool Compiler::compile_file( const std::string& /*filename*/ ) +{ + return false; +} + +bool Compiler::write_ecl( const std::string& /*pathname*/ ) +{ + return false; +} + +void Compiler::write_listing( const std::string& /*pathname*/ ) +{ +} + +void Compiler::write_dbg( const std::string& /*pathname*/, bool /*include_debug_text*/ ) +{ +} + +void Compiler::write_included_filenames( const std::string& /*pathname*/ ) +{ +} + +} // namespace Compiler +} // namespace Bscript +} // namespace Pol diff --git a/pol-core/bscript/compiler/Compiler.h b/pol-core/bscript/compiler/Compiler.h new file mode 100644 index 0000000000..2719c02f70 --- /dev/null +++ b/pol-core/bscript/compiler/Compiler.h @@ -0,0 +1,32 @@ +#ifndef POLSERVER_COMPILER_H +#define POLSERVER_COMPILER_H + +#include "../facility/Compiler.h" + +namespace Pol +{ +namespace Bscript +{ +namespace Compiler +{ + +class Compiler : public Pol::Bscript::Facility::Compiler +{ +public: + Compiler(); + ~Compiler() override; + Compiler( const Compiler& ) = delete; + Compiler& operator=( const Compiler& ) = delete; + + bool compile_file( const std::string& filename ) override; + bool write_ecl( const std::string& pathname ) override; + void write_listing( const std::string& pathname ) override; + void write_dbg( const std::string& pathname, bool include_debug_text ) override; + void write_included_filenames( const std::string& pathname ) override; +}; + +} // namespace Compiler +} // namespace Bscript +} // namespace Pol + +#endif // POLSERVER_COMPILER_H diff --git a/pol-core/bscript/compilercfg.cpp b/pol-core/bscript/compilercfg.cpp index 8f2dd6f9d0..0418eab7aa 100644 --- a/pol-core/bscript/compilercfg.cpp +++ b/pol-core/bscript/compilercfg.cpp @@ -59,6 +59,8 @@ void CompilerConfig::Read( const std::string& path ) ParanoiaWarnings = elem.remove_bool( "ParanoiaWarnings", false ); ErrorOnFileCaseMissmatch = elem.remove_bool( "ErrorOnFileCaseMissmatch", false ); + UseCompiler2020 = elem.remove_bool( "UseCompiler2020", false ); + // This is where we TRY to validate full paths from what was provided in the // ecompile.cfg. Maybe Turley or Shini can find the best way to do this in *nix. #ifdef WIN32 diff --git a/pol-core/bscript/compilercfg.h b/pol-core/bscript/compilercfg.h index c0fa54e99b..6ad2f3379f 100644 --- a/pol-core/bscript/compilercfg.h +++ b/pol-core/bscript/compilercfg.h @@ -38,6 +38,7 @@ struct CompilerConfig int NumberOfThreads; bool ParanoiaWarnings; bool ErrorOnFileCaseMissmatch; + bool UseCompiler2020; void Read( const std::string& path ); void SetDefaults(); diff --git a/pol-core/ecompile/ECompileMain.cpp b/pol-core/ecompile/ECompileMain.cpp index c399dc21a1..24ee9b4ebe 100644 --- a/pol-core/ecompile/ECompileMain.cpp +++ b/pol-core/ecompile/ECompileMain.cpp @@ -6,8 +6,10 @@ #include #include #include +#include #include "../bscript/compiler.h" +#include "../bscript/compiler/Compiler.h" #include "../bscript/compilercfg.h" #include "../bscript/escriptv.h" #include "../bscript/executor.h" @@ -68,6 +70,8 @@ void ECompileMain::showHelp() #ifdef WIN32 << " -Ecfgpath set or change the ECOMPILE_CFG_PATH evironment variable\n" #endif + << " -g Use ANTLR-grammar-driven compiler\n" + << " -i include intrusive debug info in .ecl file\n" << " -l generate listfile\n" << " -m don't optimize object members\n" @@ -224,12 +228,21 @@ bool compile_file( const char* path ) if ( !quiet ) INFO_PRINT << "Compiling: " << path << "\n"; - Legacy::Compiler C; + std::unique_ptr compiler; + + if ( compilercfg.UseCompiler2020 ) + { + compiler = boost::make_unique(); + } + else + { + auto og_compiler = boost::make_unique(); + og_compiler->setQuiet( !debug ); + compiler = std::move( og_compiler ); + } - C.setQuiet( !debug ); - Facility::Compiler& compiler = C; - bool success = compiler.compile_file( path ); + bool success = compiler->compile_file( path ); if ( expect_compile_failure ) { @@ -253,7 +266,7 @@ bool compile_file( const char* path ) if ( !quiet ) INFO_PRINT << "Writing: " << filename_ecl << "\n"; - if ( !compiler.write_ecl( filename_ecl ) ) + if ( !compiler->write_ecl( filename_ecl ) ) { throw std::runtime_error( "Error writing output file" ); } @@ -262,7 +275,7 @@ bool compile_file( const char* path ) { if ( !quiet ) INFO_PRINT << "Writing: " << filename_lst << "\n"; - compiler.write_listing( filename_lst ); + compiler->write_listing( filename_lst ); } else if ( Clib::FileExists( filename_lst.c_str() ) ) @@ -281,7 +294,7 @@ bool compile_file( const char* path ) INFO_PRINT << "Writing: " << filename_dbg << ".txt" << "\n"; } - compiler.write_dbg( filename_dbg, compilercfg.GenerateDebugTextInfo ); + compiler->write_dbg( filename_dbg, compilercfg.GenerateDebugTextInfo ); } else if ( Clib::FileExists( filename_dbg.c_str() ) ) { @@ -294,7 +307,7 @@ bool compile_file( const char* path ) { if ( !quiet ) INFO_PRINT << "Writing: " << filename_dep << "\n"; - compiler.write_included_filenames( filename_dep ); + compiler->write_included_filenames( filename_dep ); } else if ( Clib::FileExists( filename_dep.c_str() ) ) { @@ -386,6 +399,10 @@ int readargs( int argc, char** argv ) break; #endif + case 'g': + compilercfg.UseCompiler2020 = setting_value( arg ); + break; + case 'q': quiet = true; break;