Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stub for new compiler #184

Merged
merged 1 commit into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions pol-core/bscript/CMakeSources.cmake
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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