@Override
	public boolean applyTo(Program p) {
		ReferenceManager refMgr = p.getReferenceManager();

		Function f = p.getFunctionManager().getFunctionContaining(fromAddr);
		if (f == null) {
			status = "Register reference may only be created within a function";
			return false;
		}
		int useOffset = (int) (fromAddr.getOffset() - f.getEntryPoint().getOffset());

		if (refType == null) {
			refType = RefTypeFactory.getDefaultRegisterRefType(
				p.getListing().getInstructionAt(fromAddr), reg, opIndex);
		}

		if (refType.isWrite()) {
			boolean found = false;
			for (Variable rv : f.getAllVariables()) {
				List<Register> registers = rv.getRegisters();
				if (registers == null) {
					continue;
				}
				for (Register r : registers) {
					// determine if reference reg contains variable storage register
					if (reg.contains(r) && rv.getFirstUseOffset() == useOffset) {
						found = true;
						break;
					}
				}
			}
			if (!found) {
				// Create a variable on write
				try {
					Variable var = new LocalVariableImpl(null, useOffset, null,
						new VariableStorage(p, reg), p);
					var = f.addLocalVariable(var, SourceType.DEFAULT);
				}
				catch (DuplicateNameException e) {
					throw new AssertException(); // Unexpected - we did not specify name
				}
				catch (InvalidInputException e) {
					throw new AssertException(); // Unexpected - we did not specify data-type
				}
			}
		}

		refMgr.addRegisterReference(fromAddr, opIndex, reg, refType, source);

		return true;
	}
Constructs a new command for adding a register reference.
@param fromAddr "from" address
@param opIndex operand index
@param reg register to add the reference to
@param refType reference type or null to use a default RefType
@param source the source of this reference
Ghidra/Features/Base/src/main/java/ghidra/app/cmd/refs/AddRegisterRefCmd.java