@Override
	public boolean applyTo(Program program, TaskMonitor monitor) {
		ReferenceManager refMgr = program.getReferenceManager();
		Listing listing = program.getListing();

		monitor.initialize(toSet.getNumAddresses());
		monitor.setMessage("Adding memory references...");

		int cnt = 0;
		AddressIterator iter = toSet.getAddresses(true);
		CodeUnit prevCodeUnit = null;
		while (!monitor.isCancelled() && iter.hasNext()) {
			Address toAddr = iter.next();
			if (prevCodeUnit == null || !prevCodeUnit.contains(toAddr)) {
				CodeUnit cu = getSmallestCodeUnitAt(listing, toAddr);
				if (cu != null) {
					prevCodeUnit = cu;
					refMgr.addMemoryReference(fromAddr, toAddr, refType, source, opIndex);
				}
			}
			monitor.setProgress(++cnt);
		}
		return true;
	}
Add memory references.
@param fromAddr reference source
@param toSet set of addresses which make up reference destinations.
Only those addresses on code where a code unit exists will be considered.
@param refType reference type to be applied.
@param source the source of the reference
@param opIndex source operand index
Ghidra/Features/Base/src/main/java/ghidra/app/cmd/refs/AddMemRefsCmd.java