track more information about temporary variables

This commit is contained in:
Vern Paxson 2021-02-27 11:08:34 -08:00
parent 64ef7f0eb2
commit b581c6435e
2 changed files with 45 additions and 1 deletions

View file

@ -11,7 +11,31 @@ TempVar::TempVar(int num, const TypePtr& t, ExprPtr _rhs) : type(t)
char buf[8192]; char buf[8192];
snprintf(buf, sizeof buf, "#%d", num); snprintf(buf, sizeof buf, "#%d", num);
name = buf; name = buf;
id = nullptr; rhs = _rhs;
}
void TempVar::SetAlias(IDPtr _alias, const DefPoints* _dps)
{
if ( alias )
reporter->InternalError("Re-aliasing a temporary");
if ( ! _dps )
{
printf("trying to alias %s to %s\n", name.c_str(), _alias->Name());
reporter->InternalError("Empty dps for alias");
}
if ( alias == id )
reporter->InternalError("Creating alias loop");
alias = _alias;
dps = _dps;
}
void TempVar::SetDPs(const DefPoints* _dps)
{
ASSERT(_dps->length() == 1);
dps = _dps;
} }
} // zeek::detail } // zeek::detail

View file

@ -9,6 +9,7 @@
#include "zeek/ID.h" #include "zeek/ID.h"
#include "zeek/Expr.h" #include "zeek/Expr.h"
#include "zeek/script_opt/ReachingDefs.h"
namespace zeek::detail { namespace zeek::detail {
@ -25,12 +26,31 @@ public:
void Deactivate() { active = false; } void Deactivate() { active = false; }
bool IsActive() const { return active; } bool IsActive() const { return active; }
// Associated constant expression, if any.
const ConstExpr* Const() const { return const_expr; }
// The most use of "const" in any single line in the Zeek
// codebase :-P ... though only by one!
void SetConst(const ConstExpr* _const) { const_expr = _const; }
IDPtr Alias() const { return alias; }
const DefPoints* DPs() const { return dps; }
void SetAlias(IDPtr id, const DefPoints* dps);
void SetDPs(const DefPoints* _dps);
const RDPtr& MaxRDs() const { return max_rds; }
void SetMaxRDs(RDPtr rds) { max_rds = rds; }
protected: protected:
std::string name; std::string name;
IDPtr id; IDPtr id;
const TypePtr& type; const TypePtr& type;
ExprPtr rhs; ExprPtr rhs;
bool active = true; bool active = true;
const ConstExpr* const_expr = nullptr;
IDPtr alias;
const DefPoints* dps = nullptr;
RDPtr max_rds;
}; };
} // zeek::detail } // zeek::detail