Skip to content

Commit

Permalink
Add stub for new compiler, with -g and UseCompiler2020 options to sel…
Browse files Browse the repository at this point in the history
…ect. (#184)
  • Loading branch information
eric-swanson committed Aug 5, 2020
1 parent 13af52b commit 6e8c7ad
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pol-core/bscript/CMakeSources.cmake
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions 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
32 changes: 32 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions pol-core/bscript/compilercfg.cpp
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pol-core/bscript/compilercfg.h
Expand Up @@ -38,6 +38,7 @@ struct CompilerConfig
int NumberOfThreads;
bool ParanoiaWarnings;
bool ErrorOnFileCaseMissmatch;
bool UseCompiler2020;

void Read( const std::string& path );
void SetDefaults();
Expand Down
33 changes: 25 additions & 8 deletions pol-core/ecompile/ECompileMain.cpp
Expand Up @@ -6,8 +6,10 @@
#include <stdlib.h>
#include <string>
#include <time.h>
#include <boost/make_unique.hpp>

#include "../bscript/compiler.h"
#include "../bscript/compiler/Compiler.h"
#include "../bscript/compilercfg.h"
#include "../bscript/escriptv.h"
#include "../bscript/executor.h"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -224,12 +228,21 @@ bool compile_file( const char* path )
if ( !quiet )
INFO_PRINT << "Compiling: " << path << "\n";

Legacy::Compiler C;
std::unique_ptr<Facility::Compiler> compiler;

if ( compilercfg.UseCompiler2020 )
{
compiler = boost::make_unique<Compiler::Compiler>();
}
else
{
auto og_compiler = boost::make_unique<Legacy::Compiler>();
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 )
{
Expand All @@ -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" );
}
Expand All @@ -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() ) )
Expand All @@ -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() ) )
{
Expand All @@ -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() ) )
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6e8c7ad

Please sign in to comment.