removed -O add-C++ option and updated documentation

This commit is contained in:
Vern Paxson 2023-01-24 10:52:58 -08:00
parent a82f743bcc
commit 65a2900bb7
7 changed files with 16 additions and 143 deletions

View file

@ -127,7 +127,7 @@ class CPPCompile
{
public:
CPPCompile(std::vector<FuncInfo>& _funcs, ProfileFuncs& pfs, const std::string& gen_name,
bool add, bool _standalone, bool report_uncompilable);
bool _standalone, bool report_uncompilable);
~CPPCompile();
// Constructing a CPPCompile object does all of the compilation.
@ -345,10 +345,6 @@ private:
// Maps functions (not hooks or events) to upstream compiled names.
std::unordered_map<std::string, std::string> hashed_funcs;
// If non-zero, provides a tag used for auxiliary/additional
// compilation units.
int addl_tag = 0;
// If true, the generated code should run "standalone".
bool standalone = false;
@ -359,10 +355,6 @@ private:
// likely not important to make distinct).
p_hash_type total_hash = 0;
// Working directory in which we're compiling. Used to quasi-locate
// error messages when doing test-suite "add-C++" crunches.
std::string working_dir;
//
// End of methods related to script/C++ variables.

View file

@ -15,45 +15,18 @@ namespace zeek::detail
using namespace std;
CPPCompile::CPPCompile(vector<FuncInfo>& _funcs, ProfileFuncs& _pfs, const string& gen_name,
bool add, bool _standalone, bool report_uncompilable)
bool _standalone, bool report_uncompilable)
: funcs(_funcs), pfs(_pfs), standalone(_standalone)
{
auto target_name = gen_name.c_str();
auto mode = add ? "a" : "w";
write_file = fopen(target_name, mode);
write_file = fopen(target_name, "w");
if ( ! write_file )
{
reporter->Error("can't open C++ target file %s", target_name);
exit(1);
}
if ( add )
{
// We need a unique number to associate with the name
// space for the code we're adding. A convenient way to
// generate this safely is to use the present size of the
// file we're appending to. That guarantees that every
// incremental compilation will wind up with a different
// number.
struct stat st;
if ( fstat(fileno(write_file), &st) != 0 )
{
char buf[256];
util::zeek_strerror_r(errno, buf, sizeof(buf));
reporter->Error("fstat failed on %s: %s", target_name, buf);
exit(1);
}
// We use a value of "0" to mean "we're not appending,
// we're generating from scratch", so make sure we're
// distinct from that.
addl_tag = st.st_size + 1;
}
else
addl_tag = 0;
Compile(report_uncompilable);
}
@ -64,15 +37,6 @@ CPPCompile::~CPPCompile()
void CPPCompile::Compile(bool report_uncompilable)
{
// Get the working directory so we can use it in diagnostic messages
// as a way to identify this compilation. Only germane when doing
// incremental compilation (particularly of the test suite).
char buf[8192];
if ( ! getcwd(buf, sizeof buf) )
reporter->FatalError("getcwd failed: %s", strerror(errno));
working_dir = buf;
unordered_set<string> filenames_reported_as_skipped;
bool had_to_skip = false;
@ -228,13 +192,16 @@ void CPPCompile::Compile(bool report_uncompilable)
void CPPCompile::GenProlog()
{
if ( addl_tag <= 1 )
// This is either a compilation via gen-C++, or
// one using add-C++ and an empty CPP-gen.cc file.
Emit("#include \"zeek/script_opt/CPP/Runtime.h\"\n");
Emit("#include \"zeek/script_opt/CPP/Runtime.h\"\n");
// Get the working directory for annotating the output to help
// with debugging.
char working_dir[8192];
if ( ! getcwd(working_dir, sizeof working_dir) )
reporter->FatalError("getcwd failed: %s", strerror(errno));
Emit("namespace zeek::detail { //\n");
Emit("namespace CPP_%s { // %s\n", Fmt(total_hash), working_dir);
Emit("namespace CPP_%s { // %s\n", Fmt(total_hash), string(working_dir));
// The following might-or-might-not wind up being populated/used.
Emit("std::vector<int> field_mapping;");
@ -390,7 +357,7 @@ void CPPCompile::GenEpilog()
GenInitHook();
Emit("} // %s\n\n", scope_prefix(addl_tag));
Emit("} //\n\n");
Emit("} // zeek::detail");
}

View file

@ -108,40 +108,8 @@ On the other hand, it's possible (not yet established) that code created
using `gen-C++` can be made to compile significantly faster than
standalone code.
Another option, `-O add-C++`, instead _appends_ the generated code to existing C++ in `CPP-gen.cc`.
You can use this option repeatedly for different scripts and then
compile the collection _en masse_.
There are additional workflows relating to running the test suite, which
we document only briefly here as they're likely going to change or go away
, as it's not clear they're actually needed.
* `non-embedded-build`
Builds `zeek` without any embedded compiled-to-C++ scripts.
* `bare-embedded-build`
Builds `zeek` with the `-b` "bare-mode" scripts compiled in.
* `full-embedded-build`
Builds `zeek` with the default scripts compiled in.
<br>
* `eval-test-suite`
Runs the test suite using the `cpp` alternative over the given set of tests.
* `test-suite-build`
Incrementally compiles to `CPP-gen-addl.h` code for the given test suite elements.
<br>
* `single-test.sh`
Builds the given btest test as a single `add-C++` add-on and then runs it.
* `single-full-test.sh`
Builds the given btest test from scratch as a self-contained `zeek`, and runs it.
* `update-single-test.sh`
Given an already-compiled `zeek` for the given test, updates its `cpp` test suite alternative.
Some of these scripts could be made less messy if `btest` supported
a "dry run" option that reported the executions it would do for a given
test without actually undertaking them.
There are additional workflows relating to running the test suite: see
`src/script_opt/CPP/maint/README`.
<br>