// SPDX-License-Identifier: MIT
// Copyright (C) 2018-present iced project and contributors

package com.github.icedland.iced.x86.fmt.nasm;

import com.github.icedland.iced.x86.internal.IcedConstants;
import com.github.icedland.iced.x86.internal.fmt.FormatterString;

final class MemorySizes {
	public static final class Info {
		public final FormatterString keyword;
		public final FormatterString bcstTo;

		public Info(FormatterString keyword, FormatterString bcstTo) {
			this.keyword = keyword;
			this.bcstTo = bcstTo;
		}
	}

	public static final Info[] allMemorySizes = getMemorySizes();

	private static Info[] getMemorySizes() {
		// GENERATOR-BEGIN: ConstData
		// ⚠️This was generated by GENERATOR!🦹‍♂️
		FormatterString byte_ = new FormatterString("byte");
		FormatterString dword = new FormatterString("dword");
		FormatterString far = new FormatterString("far");
		FormatterString fpuenv14 = new FormatterString("fpuenv14");
		FormatterString fpuenv28 = new FormatterString("fpuenv28");
		FormatterString fpustate108 = new FormatterString("fpustate108");
		FormatterString fpustate94 = new FormatterString("fpustate94");
		FormatterString oword = new FormatterString("oword");
		FormatterString qword = new FormatterString("qword");
		FormatterString tword = new FormatterString("tword");
		FormatterString word = new FormatterString("word");
		FormatterString yword = new FormatterString("yword");
		FormatterString zword = new FormatterString("zword");
		FormatterString mem384 = new FormatterString("mem384");
		FormatterString empty = new FormatterString("");
		FormatterString b1to2 = new FormatterString("1to2");
		FormatterString b1to4 = new FormatterString("1to4");
		FormatterString b1to8 = new FormatterString("1to8");
		FormatterString b1to16 = new FormatterString("1to16");
		FormatterString b1to32 = new FormatterString("1to32");
		// GENERATOR-END: ConstData

		byte[] bcstToData = new byte[] {
			// GENERATOR-BEGIN: BcstTo
			// ⚠️This was generated by GENERATOR!🦹‍♂️
			(byte)0x01,
			(byte)0x01,
			(byte)0x01,
			(byte)0x02,
			(byte)0x01,
			(byte)0x03,
			(byte)0x03,
			(byte)0x02,
			(byte)0x02,
			(byte)0x01,
			(byte)0x01,
			(byte)0x01,
			(byte)0x03,
			(byte)0x02,
			(byte)0x01,
			(byte)0x02,
			(byte)0x01,
			(byte)0x01,
			(byte)0x02,
			(byte)0x02,
			(byte)0x04,
			(byte)0x04,
			(byte)0x03,
			(byte)0x03,
			(byte)0x02,
			(byte)0x02,
			(byte)0x02,
			(byte)0x04,
			(byte)0x03,
			(byte)0x02,
			(byte)0x03,
			(byte)0x02,
			(byte)0x02,
			(byte)0x03,
			(byte)0x03,
			(byte)0x05,
			(byte)0x05,
			(byte)0x04,
			(byte)0x04,
			(byte)0x03,
			(byte)0x03,
			(byte)0x03,
			(byte)0x05,
			(byte)0x04,
			(byte)0x03,
			(byte)0x04,
			(byte)0x04,
			(byte)0x03,
			(byte)0x03,
			(byte)0x04,
			// GENERATOR-END: BcstTo
		};
		byte[] data = new byte[] {
			// GENERATOR-BEGIN: MemorySizes
			// ⚠️This was generated by GENERATOR!🦹‍♂️
			(byte)0x00,
			(byte)0x01,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x09,
			(byte)0x09,
			(byte)0x08,
			(byte)0x0C,
			(byte)0x0D,
			(byte)0x01,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x09,
			(byte)0x08,
			(byte)0x0C,
			(byte)0x0D,
			(byte)0x03,
			(byte)0x03,
			(byte)0x03,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x09,
			(byte)0x00,
			(byte)0x00,
			(byte)0x09,
			(byte)0x08,
			(byte)0x00,
			(byte)0x00,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x09,
			(byte)0x0A,
			(byte)0x08,
			(byte)0x0B,
			(byte)0x04,
			(byte)0x05,
			(byte)0x07,
			(byte)0x06,
			(byte)0x00,
			(byte)0x00,
			(byte)0x00,
			(byte)0x00,
			(byte)0x0A,
			(byte)0x0D,
			(byte)0x00,
			(byte)0x0A,
			(byte)0x0E,
			(byte)0x0D,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x02,
			(byte)0x02,
			(byte)0x02,
			(byte)0x02,
			(byte)0x02,
			(byte)0x09,
			(byte)0x09,
			(byte)0x09,
			(byte)0x09,
			(byte)0x09,
			(byte)0x09,
			(byte)0x09,
			(byte)0x09,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x02,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x02,
			(byte)0x09,
			(byte)0x09,
			(byte)0x09,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x09,
			(byte)0x02,
			(byte)0x09,
			(byte)0x09,
			(byte)0x02,
			(byte)0x02,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x02,
			(byte)0x09,
			(byte)0x09,
			(byte)0x09,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x09,
			(byte)0x02,
			(byte)0x09,
			(byte)0x09,
			(byte)0x02,
			(byte)0x02,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x02,
			(byte)0x09,
			(byte)0x09,
			(byte)0x09,
			(byte)0x0B,
			(byte)0x02,
			(byte)0x09,
			(byte)0x02,
			(byte)0x02,
			(byte)0x09,
			(byte)0x09,
			(byte)0x02,
			// GENERATOR-END: MemorySizes
		};

		Info[] infos = new Info[IcedConstants.MEMORY_SIZE_ENUM_COUNT];
		for (int i = 0; i < infos.length; i++) {
			int d = data[i] & 0xFF;
			FormatterString keyword;
			switch (d) {
			// GENERATOR-BEGIN: MemoryKeywordsSwitch
			// ⚠️This was generated by GENERATOR!🦹‍♂️
			case 0x00:
				keyword = empty;
				break;
			case 0x01:
				keyword = byte_;
				break;
			case 0x02:
				keyword = dword;
				break;
			case 0x03:
				keyword = far;
				break;
			case 0x04:
				keyword = fpuenv14;
				break;
			case 0x05:
				keyword = fpuenv28;
				break;
			case 0x06:
				keyword = fpustate108;
				break;
			case 0x07:
				keyword = fpustate94;
				break;
			case 0x08:
				keyword = oword;
				break;
			case 0x09:
				keyword = qword;
				break;
			case 0x0A:
				keyword = tword;
				break;
			case 0x0B:
				keyword = word;
				break;
			case 0x0C:
				keyword = yword;
				break;
			case 0x0D:
				keyword = zword;
				break;
			case 0x0E:
				keyword = mem384;
				break;
			// GENERATOR-END: MemoryKeywordsSwitch
			default:
				throw new UnsupportedOperationException();
			}
			FormatterString bcstTo;
			if (i < IcedConstants.FIRST_BROADCAST_MEMORY_SIZE)
				bcstTo = empty;
			else {
				switch (bcstToData[i - IcedConstants.FIRST_BROADCAST_MEMORY_SIZE] & 0xFF) {
				// GENERATOR-BEGIN: BroadcastToKindSwitch
				// ⚠️This was generated by GENERATOR!🦹‍♂️
				case 0x00:
					bcstTo = empty;
					break;
				case 0x01:
					bcstTo = b1to2;
					break;
				case 0x02:
					bcstTo = b1to4;
					break;
				case 0x03:
					bcstTo = b1to8;
					break;
				case 0x04:
					bcstTo = b1to16;
					break;
				case 0x05:
					bcstTo = b1to32;
					break;
				// GENERATOR-END: BroadcastToKindSwitch
				default:
					throw new UnsupportedOperationException();
				}
			}

			infos[i] = new Info(keyword, bcstTo);
		}

		return infos;
	}
}
