Class Var

Class Documentation

class Var

Class representing a variable (global, local, etc.) in a program.

Public Functions

Var(types::Type *type = nullptr)

Constructs a variable of specified type.

std::string getName()
void setName(std::string name)
bool isGlobal()
void setGlobal()
void setThreadLocal()
void setREPL()
void setExternal()
void mapTo(Var *other)

Map this variable to another variable. This can be necessary to implement e.g. generator expressions, which need to be codegen’d in a separate (anonymous) function, meaning we cannot just reuse variables from the original function. This function can be called multiple times, and the mapped-to variables will be placed in a stack (e.g. if nested generators are being codegen’d).

Parameters
  • other: variable to delegate to

void unmap()

Un-maps the last-mapped-to variable.

Value *getPtr(BaseFunc *base)

Returns a pointer to this variable’s storage area.

Value *load(BaseFunc *base, llvm::BasicBlock *block, bool atomic = false)

Codegen’s a load of this variable.

Parameters
  • base: function containing the load

  • block: block to generate load in

  • atomic: whether this load is atomic

void store(BaseFunc *base, llvm::Value *val, llvm::BasicBlock *block, bool atomic = false)

Codegen’s a store of this variable.

Parameters
  • base: function containing the store

  • val: value to store

  • block: block to generate store in

  • atomic: whether this store is atomic

void setType(types::Type *type)

Sets the type of this variable.

types::Type *getType()

Returns the type of this variable.

Var *clone(Generic *ref)

Clones this variable. Note that global variables are not cloned.