Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • normann/preprocessor
  • Dynare/preprocessor
  • FerhatMihoubi/preprocessor
  • MichelJuillard/preprocessor
  • sebastien/preprocessor
  • lnsongxf/preprocessor
  • albop/preprocessor
  • DoraK/preprocessor
  • amg/preprocessor
  • wmutschl/preprocessor
  • JohannesPfeifer/preprocessor
11 results
Select Git revision
Show changes
Commits on Source (3)
......@@ -4,7 +4,7 @@
project('dynare-preprocessor', 'cpp',
version : '6-unstable',
# NB: update C++ standard in .clang-format whenever the following is modified
default_options : [ 'cpp_std=gnu++20', 'warning_level=2' ],
default_options : [ 'cpp_std=gnu++20', 'warning_level=0' ],
meson_version : '>=0.64.0')
add_global_arguments('-DPACKAGE_VERSION="' + meson.project_version() + '"', language : 'cpp')
......
# Cross-compile file for creating a WebAssembly version of the preprocessor
# Requires emscripten to be installed
# Creates a .wasm and .js wrapper under <builddir>/src/
# Can be run locally with node.js using:
# node --no-experimental-fetch dynare-preprocessor.js
[binaries]
cpp = 'em++'
[host_machine]
system = 'emscripten'
cpu_family = 'wasm32'
cpu = 'wasm32'
endian = 'little'
[properties]
# It’s necessary to use a different copy of Boost than the one under
# /usr/include, because otherwise GCC headers confuse Clang
#boost_root = '/path/to/boost'
# For accessing the local filesystem
; cpp_args = ['-fwasm-exceptions']
; cpp_link_args = ['--embed-file', 'example1.mod', '-o', 'dynare.html', '-fwasm-exceptions']
; cpp_args = ['-fexceptions']
cpp_args = ['-fexceptions']
cpp_link_args = ['-fexceptions']
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <string>
#include <regex>
#include <thread>
#include <algorithm>
#include <filesystem>
#include <cstdlib>
#include <unistd.h>
#include "ParsingDriver.hh"
#include "ExtendedPreprocessorTypes.hh"
#include "ConfigFile.hh"
#include "ModFile.hh"
std::string preprocess(const std::string &modfile_string) {
// dup2(STDOUT_FILENO, STDERR_FILENO);
// # we capture output completely
std::stringstream buffer;
std::streambuf * old = std::cout.rdbuf(buffer.rdbuf());
// std::streambuf * old = std::cerr.rdbuf(buffer.rdbuf());
const string basename = "model";
stringstream modfile;
modfile << modfile_string;
bool debug = false;
bool no_warn = true;
bool nostrict = true;
WarningConsolidation warnings(no_warn);
ParsingDriver p(warnings, nostrict);
unique_ptr<ModFile> mod_file = p.parse(modfile, debug);
JsonOutputPointType json{JsonOutputPointType::nojson};
JsonFileOutputType json_output_mode{JsonFileOutputType::file};
json = JsonOutputPointType::parsing;
json_output_mode = JsonFileOutputType::standardout;
bool onlyjson = false; // remark: why would writeJsonOutput ever decide to exit ?
mod_file->writeJsonOutput(basename, json, json_output_mode, false);
std::string output = buffer.str(); // text will now contain "Bla\n"
return output;
}
#include <pybind11/pybind11.h>
namespace py = pybind11;
PYBIND11_MODULE(dynare_preprocessor, m) {
m.doc() = "Dynare Preprocessor"; // optional module docstring
m.def("preprocess", &preprocess, "Another one");
}
......@@ -502,9 +502,9 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
if (mod_file->use_dll)
ModelTree::initializeMEXCompilationWorkers(max(jthread::hardware_concurrency(), 1U),
dynareroot, mexext);
// if (mod_file->use_dll)
// ModelTree::initializeMEXCompilationWorkers(max(jthread::hardware_concurrency(), 1U),
// dynareroot, mexext);
if (json == JsonOutputPointType::parsing)
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
......@@ -539,8 +539,8 @@ main(int argc, char **argv)
/* Ensures that workers are not destroyed before they finish compiling.
Also ensures that the preprocessor final message is printed after the end of
compilation (and is not printed in case of compilation failure). */
if (mod_file->use_dll)
ModelTree::waitForMEXCompilationWorkers();
// if (mod_file->use_dll)
// ModelTree::waitForMEXCompilationWorkers();
cout << "Preprocessing completed." << endl;
return EXIT_SUCCESS;
......
......@@ -45,7 +45,7 @@ condition_variable_any ModelTree::mex_compilation_cv;
mutex ModelTree::mex_compilation_mut;
vector<tuple<filesystem::path, set<filesystem::path>, string>> ModelTree::mex_compilation_queue;
set<filesystem::path> ModelTree::mex_compilation_ongoing, ModelTree::mex_compilation_done, ModelTree::mex_compilation_failed;
vector<jthread> ModelTree::mex_compilation_workers;
// vector<jthread> ModelTree::mex_compilation_workers;
void
ModelTree::copyHelper(const ModelTree &m)
......@@ -1646,9 +1646,12 @@ ModelTree::findCompilerOnMacos(const string &mexext)
}
#endif
filesystem::path
ModelTree::compileMEX(const filesystem::path &output_dir, const string &output_basename, const string &mexext, const vector<filesystem::path> &input_files, const filesystem::path &matlabroot, bool link) const
{
#if 0
assert(!mex_compilation_workers.empty());
const string gcc_opt_flags { "-O3 -g0 --param ira-max-conflict-table-size=1 -fno-forward-propagate -fno-gcse -fno-dce -fno-dse -fno-tree-fre -fno-tree-pre -fno-tree-cselim -fno-tree-dse -fno-tree-dce -fno-tree-pta -fno-gcse-after-reload" };
......@@ -1706,8 +1709,12 @@ ModelTree::compileMEX(const filesystem::path &output_dir, const string &output_b
}
}
#endif
filesystem::path output_filename {output_dir / (output_basename + "." + (link ? mexext : "o"))};
#if 0
ostringstream cmd;
#ifdef _WIN32
......@@ -1771,9 +1778,12 @@ ModelTree::compileMEX(const filesystem::path &output_dir, const string &output_b
lk.unlock();
mex_compilation_cv.notify_one();
#endif
return output_filename;
}
void
ModelTree::reorderAuxiliaryEquations()
{
......@@ -1897,6 +1907,8 @@ ModelTree::getRHSFromLHS(expr_t lhs) const
throw ExprNode::MatchFailureException{"Cannot find an equation with the requested LHS"};
}
#if 0
void
ModelTree::initializeMEXCompilationWorkers(int numworkers, const filesystem::path &dynareroot,
const string &mexext)
......@@ -1991,6 +2003,10 @@ ModelTree::initializeMEXCompilationWorkers(int numworkers, const filesystem::pat
#endif
}
#endif
#if 0
void
ModelTree::waitForMEXCompilationWorkers()
{
......@@ -2009,6 +2025,8 @@ ModelTree::waitForMEXCompilationWorkers()
}
}
#endif
void
ModelTree::computingPassBlock(const eval_context_t &eval_context, bool no_tmp_terms)
{
......
......@@ -410,7 +410,7 @@ private:
vector<int> endo2eq;
// Stores workers used for compiling MEX files in parallel
static vector<jthread> mex_compilation_workers;
// static vector<jthread> mex_compilation_workers;
/* The following variables implement the thread synchronization mechanism for
limiting the number of concurrent GCC processes and tracking dependencies
......
py3_inst = import('python').find_installation('python3')
pybind11_config = find_program('pybind11-config')
pybind11_config_ret = run_command(pybind11_config, ['--includes'])
pybind11 = declare_dependency(
include_directories: [pybind11_config_ret.stdout().split('-I')[-1].strip()],
)
python3 = dependency('python3')
boost_dep = dependency('boost')
## Flex stuff
......@@ -69,7 +79,10 @@ else
preprocessor_link_args = []
endif
executable('dynare-preprocessor', preprocessor_src, flex_src, flexlexer_h, bison_src,
include_directories : preprocessor_incdir, dependencies : boost_dep,
link_args : preprocessor_link_args,
install : true)
# executable('dynare-preprocessor', preprocessor_src, flex_src, flexlexer_h, bison_src,
# include_directories : preprocessor_incdir, dependencies : boost_dep,
# link_args : preprocessor_link_args,
# install : true)
py3_inst.extension_module('dynare_preprocessor', preprocessor_src, flex_src, flexlexer_h, bison_src, 'DynLib.cc', include_directories : preprocessor_incdir, dependencies : [boost_dep, python3, pybind11],
link_args : preprocessor_link_args, install: true)
\ No newline at end of file