public void setLanguage(LanguageTranslator translator, CompilerSpec newCompilerSpec,
			AddressSetView programMemory, TaskMonitor monitor) throws CancelledException {

		if (translator == null) {
			// Language instance unchanged
			boolean clearContext = Boolean.valueOf(
				language.getProperty(GhidraLanguagePropertyKeys.RESET_CONTEXT_ON_UPGRADE));
			if (clearContext) {
				RegisterValueStore store = registerValueMap.get(baseContextRegister);
				if (store != null) {
					store.clearAll();
				}
			}
			initializeDefaultValues(language, newCompilerSpec);
			return;
		}

		Language newLanguage = translator.getNewLanguage();

		// Sort the registers by size so that largest come first.
		// This prevents the remove call below from incorrectly clearing 
		// smaller registers that are part of a larger register.
		List<Register> registers = new ArrayList<Register>(language.getRegisters());
		Collections.sort(registers, (r1, r2) -> r2.getBitLength() - r1.getBitLength());

		// Map all register stores to new registers
		for (Register register : registers) {
			monitor.checkCancelled();
			if (!register.isBaseRegister()) {
				continue; // only consider non-context base registers
			}
			RegisterValueStore store = registerValueMap.get(register);
			if (store == null) {
				continue;
			}

			boolean clearContext = register.isProcessorContext() && Boolean.valueOf(
				newLanguage.getProperty(GhidraLanguagePropertyKeys.RESET_CONTEXT_ON_UPGRADE));

			// Update storage range map
			if (clearContext || !store.setLanguage(translator, monitor)) {
				// Clear and remove old register value store
				Msg.warn(this,
					"WARNING! Discarding all context for register " + register.getName());
				store.clearAll();
			}
			registerValueMap.remove(register);
		}

		init(newLanguage);

		initializeDefaultValues(newLanguage, newCompilerSpec);

		registerValueMap.clear();
		initializedCurrentValues();

		// May need to fill-in blank context areas with a new specified context value 
		Register ctxReg = newLanguage.getContextBaseRegister();
		if (ctxReg != Register.NO_CONTEXT && translator.isValueTranslationRequired(ctxReg)) {
			RegisterValue gapValue = new RegisterValue(ctxReg);
			gapValue = translator.getNewRegisterValue(gapValue);
			if (gapValue != null && gapValue.hasAnyValue()) {
				fillInContextGaps(ctxReg, gapValue, programMemory);
			}
		}
	}
Perform context upgrade due to a language change
@param translator language translator required by major upgrades (may be null)
@param newCompilerSpec new compiler specification
@param programMemory program memory
@param monitor task monitor
@throws CancelledException thrown if monitor cancelled
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/register/ProgramRegisterContextDB.java