Commit 96ddffb0 authored by Bednárek David RNDr. Ph.D.'s avatar Bednárek David RNDr. Ph.D.
Browse files

-z flag to redirect output (except ckrt_printf)

linker warning suppresed
parent 9ae004a0
......@@ -33,6 +33,14 @@ function(SET_TARGET_OPTIONS TARGET OPT_GCC OPT_MSVC)
endif()
endfunction()
function(SET_TARGET_LINK_OPTIONS TARGET OPT_GCC OPT_MSVC)
if(MSVC)
target_link_options(${TARGET} PUBLIC ${OPT_MSVC})
else()
target_link_options(${TARGET} PUBLIC ${OPT_GCC})
endif()
endfunction()
function(COMMON_OPTIONS TARGET)
set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD 17)
if(NOT DEFINED LLVM_PACKAGE_VERSION)
......@@ -50,10 +58,9 @@ function(COMMON_OPTIONS TARGET)
SET_TARGET_OPTIONS(${TARGET} "" "/wd4267")
SET_TARGET_OPTIONS(${TARGET} "" "/wd4624")
if(MSVC)
else()
target_link_options(${TARGET} PUBLIC "-rdynamic") # for self-references to ckrt_printf etc
endif()
SET_TARGET_LINK_OPTIONS(${TARGET} "" "/IGNORE:4099") # missing pdb
SET_TARGET_LINK_OPTIONS(${TARGET} "-rdynamic" "") # for self-references to ckrt_printf etc
endfunction()
......
......@@ -54,12 +54,12 @@ namespace cecko {
void context::message(errors::err_s err, loc_t loc, std::string_view msg)
{
errors::err_def_s& e = err;
std::cout << "Error (line " << loc << "): " << e[0] << escape(msg) << e[1] << std::endl;
out() << "Error (line " << loc << "): " << e[0] << escape(msg) << e[1] << std::endl;
}
void context::message(errors::err_n err, loc_t loc)
{
errors::err_def_n & e = err;
std::cout << "Error (line " << loc << "): " << e[0] << std::endl;
out() << "Error (line " << loc << "): " << e[0] << std::endl;
}
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ context for the compiler
#include <string_view>
#include <functional>
#include <array>
#include <ostream>
namespace cecko {
......@@ -70,7 +71,9 @@ namespace cecko {
class context : public CKContext {
public:
context(CKTablesObs tables) : CKContext(tables), line_(1) {}
context(CKTablesObs tables, std::ostream* outp) : CKContext(tables), line_(1), outp_(outp) {}
std::ostream& out() { return *outp_; }
void message(errors::err_s err, loc_t loc, std::string_view msg);
void message(errors::err_n err, loc_t loc);
......@@ -81,6 +84,8 @@ namespace cecko {
loc_t incline() { return line_++; } // returns line value before increment
private:
loc_t line_;
std::ostream * outp_;
};
using context_obs = context*;
......
......@@ -109,28 +109,28 @@ tokens: tokens token
token: token_n{
if (@1)
{
std::cout << @1 << ": ";
ctx->out() << @1 << ": ";
}
std::cout << $1 << std::endl;
ctx->out() << $1 << std::endl;
}
| token_s{
if (@1)
{
std::cout << @1 << ": ";
ctx->out() << @1 << ": ";
}
std::cout << $1.first;
ctx->out() << $1.first;
if (!$1.second.empty())
{
std::cout << " " << $1.second;
ctx->out() << " " << $1.second;
}
std::cout << std::endl;
ctx->out() << std::endl;
}
| token_i{
if (@1)
{
std::cout << @1 << ": ";
ctx->out() << @1 << ": ";
}
std::cout << $1.first << " " << $1.second << std::endl;
ctx->out() << $1.first << " " << $1.second << std::endl;
}
;
......
......@@ -125,10 +125,8 @@ namespace cecko {
return oec;
}
int CKIREnvironment::run_main(CKIRFunctionObs fnc, int argc, char** argv)
int CKIREnvironment::run_main(CKIRFunctionObs fnc, int argc, char** argv, std::ostream & os)
{
//auto&& os = llvm::outs();
auto&& os = std::cout;
int mainrv = -1;
{
// Now we going to create JIT
......
......@@ -23,7 +23,7 @@
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/Support/raw_os_ostream.h"
#include <iostream>
#include <ostream>
#include <cstdio>
namespace cecko {
......@@ -154,7 +154,7 @@ namespace cecko {
std::error_code write_bitcode_module(const std::string& fname, CKIRModuleObs module) const;
int run_main(CKIRFunctionObs fnc, int argc, char** argv);
int run_main(CKIRFunctionObs fnc, int argc, char** argv, std::ostream& os);
CKIRContextRef context()
{
......
......@@ -61,8 +61,8 @@ namespace cecko {
bool main_state_parser::dump_tables() const
{
std::cout << "========== tables ==========" << std::endl;
the_tables.dump_tables(std::cout);
out() << "========== tables ==========" << std::endl;
the_tables.dump_tables(out());
return true;
}
......@@ -76,6 +76,20 @@ namespace cecko {
return false;
oname = get_val();
return true;
case 'z':
if (!!outp_owner_)
return false;
{
auto outname = get_val();
outp_owner_ = std::make_unique<std::ofstream>(outname);
if (!outp_owner_->good())
{
outp_owner_.reset();
return false;
}
outp_ = &*outp_owner_;
}
return true;
default:
return false;
}
......@@ -86,7 +100,7 @@ namespace cecko {
bool main_state_code::dump_code() const
{
std::cout << "========== IR module ==========" << std::endl;
out() << "========== IR module ==========" << std::endl;
{
std::stringstream oss;
the_tables.dump_ir_module(oss);
......@@ -96,7 +110,7 @@ namespace cecko {
auto rc = !!std::getline(oss, lbuf);
if (!rc)
break;
std::cout << "::: " << lbuf << std::endl;
out() << "::: " << lbuf << std::endl;
}
}
......@@ -120,13 +134,13 @@ namespace cecko {
auto mainf = the_tables.globtable()->find_function("main");
if (!mainf)
{
std::cout << "Cannot find main function." << std::endl;
out() << "Cannot find main function." << std::endl;
return false;
}
else
{
auto fnc = mainf->get_function_ir();
irenv.run_main(fnc, app_argc, app_argv);
irenv.run_main(fnc, app_argc, app_argv, out());
return true;
}
}
......
......@@ -5,6 +5,8 @@
#include "ckbisonflex.hpp"
#include <string>
#include <ostream>
#include <fstream>
#include <iostream>
#include <sstream>
......@@ -24,10 +26,12 @@ namespace cecko {
public:
std::string input_fname;
main_state_parser() : outp_(&std::cout) {}
template< class the_parser>
bool parse()
{
context ctx(&the_tables);
context ctx(&the_tables, &out());
FILE* iff = fopen(input_fname.c_str(), "r");
if (iff == nullptr)
......@@ -47,6 +51,11 @@ namespace cecko {
}
bool dump_tables() const;
std::ostream& out() const { return *outp_; }
protected:
std::ostream* outp_;
std::unique_ptr< std::ofstream> outp_owner_;
};
class main_state_code : public main_state_parser {
......
......@@ -22,7 +22,7 @@ int main(int argc, char **argv)
if (!rv2)
return 0;
std::cout << "========== cecko1 done ==========" << std::endl;
ms.out() << "========== cecko1 done ==========" << std::endl;
return 0;
}
......@@ -22,7 +22,7 @@ int main(int argc, char **argv)
if (!rv2)
return 0;
std::cout << "========== cecko2 done ==========" << std::endl;
ms.out() << "========== cecko2 done ==========" << std::endl;
return 0;
}
......@@ -26,7 +26,7 @@ int main(int argc, char **argv)
if (!rv3)
return 0;
std::cout << "========== cecko3 done ==========" << std::endl;
ms.out() << "========== cecko3 done ==========" << std::endl;
return 0;
}
......@@ -34,7 +34,7 @@ int main(int argc, char **argv)
if (!rv5)
return 0;
std::cout << "========== cecko4 done ==========" << std::endl;
ms.out() << "========== cecko4 done ==========" << std::endl;
return 0;
}
......@@ -34,7 +34,7 @@ int main(int argc, char **argv)
if (!rv5)
return 0;
std::cout << "========== cecko5 done ==========" << std::endl;
ms.out() << "========== cecko5 done ==========" << std::endl;
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment