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
Loading items

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
Loading items
Show changes
Commits on Source (3)
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
project('dynare-preprocessor', 'cpp', project('dynare-preprocessor', 'cpp',
version : '6-unstable', version : '6-unstable',
# NB: update C++ standard in .clang-format whenever the following is modified # 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') meson_version : '>=0.64.0')
add_global_arguments('-DPACKAGE_VERSION="' + meson.project_version() + '"', language : 'cpp') 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) ...@@ -502,9 +502,9 @@ main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (mod_file->use_dll) // if (mod_file->use_dll)
ModelTree::initializeMEXCompilationWorkers(max(jthread::hardware_concurrency(), 1U), // ModelTree::initializeMEXCompilationWorkers(max(jthread::hardware_concurrency(), 1U),
dynareroot, mexext); // dynareroot, mexext);
if (json == JsonOutputPointType::parsing) if (json == JsonOutputPointType::parsing)
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson); mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
...@@ -539,8 +539,8 @@ main(int argc, char **argv) ...@@ -539,8 +539,8 @@ main(int argc, char **argv)
/* Ensures that workers are not destroyed before they finish compiling. /* Ensures that workers are not destroyed before they finish compiling.
Also ensures that the preprocessor final message is printed after the end of Also ensures that the preprocessor final message is printed after the end of
compilation (and is not printed in case of compilation failure). */ compilation (and is not printed in case of compilation failure). */
if (mod_file->use_dll) // if (mod_file->use_dll)
ModelTree::waitForMEXCompilationWorkers(); // ModelTree::waitForMEXCompilationWorkers();
cout << "Preprocessing completed." << endl; cout << "Preprocessing completed." << endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
......
...@@ -45,7 +45,7 @@ condition_variable_any ModelTree::mex_compilation_cv; ...@@ -45,7 +45,7 @@ condition_variable_any ModelTree::mex_compilation_cv;
mutex ModelTree::mex_compilation_mut; mutex ModelTree::mex_compilation_mut;
vector<tuple<filesystem::path, set<filesystem::path>, string>> ModelTree::mex_compilation_queue; 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; 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 void
ModelTree::copyHelper(const ModelTree &m) ModelTree::copyHelper(const ModelTree &m)
...@@ -1646,9 +1646,12 @@ ModelTree::findCompilerOnMacos(const string &mexext) ...@@ -1646,9 +1646,12 @@ ModelTree::findCompilerOnMacos(const string &mexext)
} }
#endif #endif
filesystem::path 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 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()); 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" }; 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 ...@@ -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"))}; filesystem::path output_filename {output_dir / (output_basename + "." + (link ? mexext : "o"))};
#if 0
ostringstream cmd; ostringstream cmd;
#ifdef _WIN32 #ifdef _WIN32
...@@ -1771,9 +1778,12 @@ ModelTree::compileMEX(const filesystem::path &output_dir, const string &output_b ...@@ -1771,9 +1778,12 @@ ModelTree::compileMEX(const filesystem::path &output_dir, const string &output_b
lk.unlock(); lk.unlock();
mex_compilation_cv.notify_one(); mex_compilation_cv.notify_one();
#endif
return output_filename; return output_filename;
} }
void void
ModelTree::reorderAuxiliaryEquations() ModelTree::reorderAuxiliaryEquations()
{ {
...@@ -1897,6 +1907,8 @@ ModelTree::getRHSFromLHS(expr_t lhs) const ...@@ -1897,6 +1907,8 @@ ModelTree::getRHSFromLHS(expr_t lhs) const
throw ExprNode::MatchFailureException{"Cannot find an equation with the requested LHS"}; throw ExprNode::MatchFailureException{"Cannot find an equation with the requested LHS"};
} }
#if 0
void void
ModelTree::initializeMEXCompilationWorkers(int numworkers, const filesystem::path &dynareroot, ModelTree::initializeMEXCompilationWorkers(int numworkers, const filesystem::path &dynareroot,
const string &mexext) const string &mexext)
...@@ -1991,6 +2003,10 @@ ModelTree::initializeMEXCompilationWorkers(int numworkers, const filesystem::pat ...@@ -1991,6 +2003,10 @@ ModelTree::initializeMEXCompilationWorkers(int numworkers, const filesystem::pat
#endif #endif
} }
#endif
#if 0
void void
ModelTree::waitForMEXCompilationWorkers() ModelTree::waitForMEXCompilationWorkers()
{ {
...@@ -2009,6 +2025,8 @@ ModelTree::waitForMEXCompilationWorkers() ...@@ -2009,6 +2025,8 @@ ModelTree::waitForMEXCompilationWorkers()
} }
} }
#endif
void void
ModelTree::computingPassBlock(const eval_context_t &eval_context, bool no_tmp_terms) ModelTree::computingPassBlock(const eval_context_t &eval_context, bool no_tmp_terms)
{ {
......
...@@ -410,7 +410,7 @@ private: ...@@ -410,7 +410,7 @@ private:
vector<int> endo2eq; vector<int> endo2eq;
// Stores workers used for compiling MEX files in parallel // 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 /* The following variables implement the thread synchronization mechanism for
limiting the number of concurrent GCC processes and tracking dependencies 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') boost_dep = dependency('boost')
## Flex stuff ## Flex stuff
...@@ -69,7 +79,10 @@ else ...@@ -69,7 +79,10 @@ else
preprocessor_link_args = [] preprocessor_link_args = []
endif endif
executable('dynare-preprocessor', preprocessor_src, flex_src, flexlexer_h, bison_src, # executable('dynare-preprocessor', preprocessor_src, flex_src, flexlexer_h, bison_src,
include_directories : preprocessor_incdir, dependencies : boost_dep, # include_directories : preprocessor_incdir, dependencies : boost_dep,
link_args : preprocessor_link_args, # link_args : preprocessor_link_args,
install : true) # 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