@Override
	public boolean applyTo(Program program) {

		Function f = program.getListing().getFunctionContaining(addr);
		if (f == null) {
			errMsg = "Address not contained within function: " + addr;
			return false;
		}

		int firstUseOffset = (int) addr.subtract(f.getEntryPoint());
		try {
			Variable var = new LocalVariableImpl(name, firstUseOffset, dt, reg, program);
			if (f.addLocalVariable(var, source) == null) {
				errMsg = "Create register variable failed";
				return false;
			}
		}
		catch (DuplicateNameException e) {
			errMsg = "Variable named " + name + " already exists";
			return false;
		}
		catch (InvalidInputException e) {
			errMsg = "Variable named " + name + ": " + e.getMessage();
			return false;
		}
		return true;
	}
Constructs a new command to add a register variable to a function.
@param addr initial declaration point of variable.
@param reg register for the new variable.
@param name name of the new variable.
@param dataType data type to set on the new variable
@param source the source of this register variable
Ghidra/Features/Base/src/main/java/ghidra/app/cmd/function/AddRegisterVarCmd.java