the bulk of the compiler

This commit is contained in:
Vern Paxson 2021-04-19 16:32:04 -07:00
parent 158e82a2c1
commit 863be9436b
40 changed files with 7730 additions and 0 deletions

View file

@ -0,0 +1,76 @@
// See the file "COPYING" in the main distribution directory for copyright.
// Run-time support for initializing C++-compiled scripts.
#pragma once
#include "zeek/Val.h"
#include "zeek/script_opt/CPP/Func.h"
namespace zeek {
using FuncValPtr = IntrusivePtr<zeek::FuncVal>;
namespace detail {
// An initialization hook for a collection of compiled-to-C++ functions
// (the result of a single invocation of the compiler on a set of scripts).
typedef void (*CPP_init_func)();
// Tracks the initialization hooks for different compilation runs.
extern std::vector<CPP_init_func> CPP_init_funcs;
// Registers the given compiled function body as associated with the
// given priority and hash. "events" is a list of event handlers
// relevant for the function body, which should be registered if the
// function body is going to be used.
extern void register_body__CPP(CPPStmtPtr body, int priority, p_hash_type hash,
std::vector<std::string> events);
// Registers a lambda body as associated with the given hash. Includes
// the name of the lambda (so it can be made available as a quasi-global
// identifier), its type, and whether it needs captures.
extern void register_lambda__CPP(CPPStmtPtr body, p_hash_type hash,
const char* name, TypePtr t,
bool has_captures);
// Registers a callback for activating a set of scripts associated with
// the given hash.
extern void register_scripts__CPP(p_hash_type h, void (*callback)());
// Activates the event handler/hook with the given name (which is created
// if it doesn't exist) and type, using (at least) the bodies associated
// with the given hashes.
extern void activate_bodies__CPP(const char* fn, TypePtr t,
std::vector<p_hash_type> hashes);
// Looks for a global with the given name. If not present, creates it
// with the given type.
extern IDPtr lookup_global__CPP(const char* g, const TypePtr& t);
// Looks for a BiF with the given name. Returns nil if not present.
extern Func* lookup_bif__CPP(const char* bif);
// For the function body associated with the given hash, creates and
// returns an associated FuncVal. It's a fatal error for the hash
// not to exist, because this function should only be called by compiled
// code that has ensured its existence.
extern FuncValPtr lookup_func__CPP(std::string name, std::vector<p_hash_type> h,
const TypePtr& t);
// Returns the record corresponding to the given name, as long as the
// name is indeed a record type. Otherwise (or if the name is nil)
// creates a new empty record.
extern RecordTypePtr get_record_type__CPP(const char* record_type_name);
// Returns the "enum" type corresponding to the given name, as long as
// the name is indeed an enum type. Otherwise, creates a new enum
// type with the given name.
extern EnumTypePtr get_enum_type__CPP(const std::string& enum_type_name);
// Returns an enum value corresponding to the given low-level value 'i'
// in the context of the given enum type 't'.
extern EnumValPtr make_enum__CPP(TypePtr t, int i);
} // namespace zeek::detail
} // namespace zeek