initial implementation of class for temporary variables; this will grow in complexity as we add additional optimization stages

This commit is contained in:
Vern Paxson 2021-01-10 13:41:39 -08:00
parent 8d77194719
commit 6aa84087b0
3 changed files with 54 additions and 0 deletions

View file

@ -327,6 +327,7 @@ set(MAIN_SRCS
script_opt/ProfileFunc.cc script_opt/ProfileFunc.cc
script_opt/ScriptOpt.cc script_opt/ScriptOpt.cc
script_opt/Stmt.cc script_opt/Stmt.cc
script_opt/TempVar.cc
nb_dns.c nb_dns.c
digest.h digest.h

17
src/script_opt/TempVar.cc Normal file
View file

@ -0,0 +1,17 @@
// See the file "COPYING" in the main distribution directory for copyright.
#include "TempVar.h"
#include "Reporter.h"
namespace zeek::detail {
TempVar::TempVar(int num, const TypePtr& t, ExprPtr _rhs) : type(t)
{
char buf[8192];
snprintf(buf, sizeof buf, "#%d", num);
name = util::copy_string(buf);
id = nullptr;
}
} // zeek::detail

36
src/script_opt/TempVar.h Normal file
View file

@ -0,0 +1,36 @@
// See the file "COPYING" in the main distribution directory for copyright.
#pragma once
// Class for managing temporary variables created during statement reduction
// for compilation.
#include "ID.h"
#include "Expr.h"
namespace zeek::detail {
class TempVar {
public:
TempVar(int num, const TypePtr& t, ExprPtr rhs);
~TempVar() { delete name; }
const char* Name() const { return name; }
const zeek::Type* Type() const { return type.get(); }
const Expr* RHS() const { return rhs.get(); }
IDPtr Id() const { return id; }
void SetID(IDPtr _id) { id = std::move(_id); }
void Deactivate() { active = false; }
bool IsActive() const { return active; }
protected:
char* name;
IDPtr id;
const TypePtr& type;
ExprPtr rhs;
bool active = true;
};
} // zeek::detail