<commit_before>/*****************************************************************************
				Tejas Simulator
------------------------------------------------------------------------------------------------------------

   Copyright [2010] [Indian Institute of Technology, Delhi]
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
------------------------------------------------------------------------------------------------------------

	Contributors:  <NAME>
*****************************************************************************/

package emulatorinterface.translator.x86.registers;


import java.util.Hashtable;

import generic.Operand;


public class Registers 
{
	private static Hashtable<String, Long> machineSpecificRegistersHashTable = null;
	private static Hashtable<String, Long> integerRegistersHashTable = null;
	private static Hashtable<String, Long> floatRegistersHashTable = null;

	// --- Number of temporary registers must be maintained by the translator ---
//	public static int noOfIntTempRegs = 0;
//	public static int noOfFloatTempRegs = 0;

	//Allocate a new temporary register	
	public static Operand getTempIntReg(TempRegisterNum tempRegister)
	{
		return Operand.getIntegerRegister(encodeRegister("temp" + tempRegister.numTempIntRegister++));
	}

	//Allocate a new temporary float register	
	public static Operand getTempFloatReg(TempRegisterNum tempRegister)
	{
		return Operand.getFloatRegister(encodeRegister("tempFloat" + tempRegister.numTempFloatRegister++));
	}
	
	public static void createRegisterHashTable()
	{
		//Create required hash-tables
		machineSpecificRegistersHashTable = new Hashtable<String, Long>();
		integerRegistersHashTable = new Hashtable<String, Long>();
		floatRegistersHashTable = new Hashtable<String, Long>();
		
		
		//--------------------------Machine specific registers---------------------------------
		//Segment Registers
		machineSpecificRegistersHashTable.put("es", new Long(0));
		machineSpecificRegistersHashTable.put("cs", new Long(1));
		machineSpecificRegistersHashTable.put("ss", new Long(2));
		machineSpecificRegistersHashTable.put("ds", new Long(3));
		machineSpecificRegistersHashTable.put("fs", new Long(4));
		machineSpecificRegistersHashTable.put("gs", new Long(5));
		
		machineSpecificRegistersHashTable.put("eflags", new Long(5));
		machineSpecificRegistersHashTable.put("rip", new Long(6));
		
		//FIXME: Not sure if this goes here
		machineSpecificRegistersHashTable.put("FP_CWORD", new Long(7));
		
		//-------------------------Integer register-----------------------------------------------
		//Registers available to the programmer
		integerRegistersHashTable.put("rax", new Long(0));
		integerRegistersHashTable.put("rbx", new Long(1));
		integerRegistersHashTable.put("rcx", new Long(2));
		integerRegistersHashTable.put("rdx", new Long(3));
		integerRegistersHashTable.put("r8", new Long(4));
		integerRegistersHashTable.put("r9", new Long(5));
		integerRegistersHashTable.put("r10", new Long(6));
		integerRegistersHashTable.put("r11", new Long(7));
		integerRegistersHashTable.put("r12", new Long(8));
		integerRegistersHashTable.put("r13", new Long(9));
		integerRegistersHashTable.put("r14", new Long(10));
		integerRegistersHashTable.put("r15", new Long(11));
		
		//Index registers
		machineSpecificRegistersHashTable.put("rsi", new Long(12));
		machineSpecificRegistersHashTable.put("rdi", new Long(13));
		machineSpecificRegistersHashTable.put("rbp", new Long(14));
		machineSpecificRegistersHashTable.put("rsp", new Long(15));
		
		//Weird Register
		machineSpecificRegistersHashTable.put("riz", new Long(17));
		
		//Temporary registers
		integerRegistersHashTable.put("temp0", new Long(18));
		integerRegistersHashTable.put("temp1", new Long(19));
		integerRegistersHashTable.put("temp2", new Long(20));
		integerRegistersHashTable.put("temp3", new Long(21));
		integerRegistersHashTable.put("temp4", new Long(22));
		integerRegistersHashTable.put("temp5", new Long(23));
		integerRegistersHashTable.put("temp6", new Long(24));
		integerRegistersHashTable.put("temp7", new Long(25));
		
		
		//-------------------------Floating-point register-----------------------------------------
		//Stack registers
		floatRegistersHashTable.put("st", new Long(0));
		floatRegistersHashTable.put("st(0)", new Long(0));
		floatRegistersHashTable.put("st(1)", new Long(1));
		floatRegistersHashTable.put("st(2)", new Long(2));
		floatRegistersHashTable.put("st(3)", new Long(3));
		floatRegistersHashTable.put("st(4)", new Long(4));
		floatRegistersHashTable.put("st(5)", new Long(5));
		floatRegistersHashTable.put("st(6)", new Long(6));
		floatRegistersHashTable.put("st(7)", new Long(7));
		
		//TODO This register-set can be used to perform integer operations too.
		//So its exact type - integer or floating point is ambiguous
		floatRegistersHashTable.put("xmm0", new Long(9));
		floatRegistersHashTable.put("xmm1", new Long(10));
		floatRegistersHashTable.put("xmm2", new Long(11));
		floatRegistersHashTable.put("xmm3", new Long(12));
		floatRegistersHashTable.put("xmm4", new Long(13));
		floatRegistersHashTable.put("xmm5", new Long(14));
		floatRegistersHashTable.put("xmm6", new Long(15));
		floatRegistersHashTable.put("xmm7", new Long(16));
		
		//temporary floating-point registers
		floatRegistersHashTable.put("tempFloat0", new Long(17));
		floatRegistersHashTable.put("tempFloat1", new Long(18));
		floatRegistersHashTable.put("tempFloat2", new Long(19));
		floatRegistersHashTable.put("tempFloat3", new Long(20));
	}

	
	//assign an index to each coarse-register
	public static long encodeRegister(String regStr)
	{
		checkAndCreateRegisterHashTable();
		
		Long codeRegister = null;
		
		if((codeRegister = machineSpecificRegistersHashTable.get(regStr)) != null)
		{
			return codeRegister.longValue();
		}
		else if((codeRegister = integerRegistersHashTable.get(regStr)) != null)
		{
			return codeRegister.longValue();
		}
		else if((codeRegister = floatRegistersHashTable.get(regStr)) != null)
		{
			return codeRegister.longValue();
		}
		else
		{
			misc.Error.showErrorAndExit("\n\tNot a valid register : " + regStr + " !!");
			return -1;
		}
	}
	
<commit_msg>xmm8-15 added to floating registers list.<commit_after>/*****************************************************************************
				Tejas Simulator
------------------------------------------------------------------------------------------------------------

   Copyright [2010] [Indian Institute of Technology, Delhi]
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
------------------------------------------------------------------------------------------------------------

	Contributors:  <NAME>
*****************************************************************************/

package emulatorinterface.translator.x86.registers;


import java.util.Hashtable;

import generic.Operand;


public class Registers 
{
	private static Hashtable<String, Long> machineSpecificRegistersHashTable = null;
	private static Hashtable<String, Long> integerRegistersHashTable = null;
	private static Hashtable<String, Long> floatRegistersHashTable = null;

	// --- Number of temporary registers must be maintained by the translator ---
//	public static int noOfIntTempRegs = 0;
//	public static int noOfFloatTempRegs = 0;

	//Allocate a new temporary register	
	public static Operand getTempIntReg(TempRegisterNum tempRegister)
	{
		return Operand.getIntegerRegister(encodeRegister("temp" + tempRegister.numTempIntRegister++));
	}

	//Allocate a new temporary float register	
	public static Operand getTempFloatReg(TempRegisterNum tempRegister)
	{
		return Operand.getFloatRegister(encodeRegister("tempFloat" + tempRegister.numTempFloatRegister++));
	}
	
	public static void createRegisterHashTable()
	{
		//Create required hash-tables
		machineSpecificRegistersHashTable = new Hashtable<String, Long>();
		integerRegistersHashTable = new Hashtable<String, Long>();
		floatRegistersHashTable = new Hashtable<String, Long>();
		
		
		//--------------------------Machine specific registers---------------------------------
		//Segment Registers
		machineSpecificRegistersHashTable.put("es", new Long(0));
		machineSpecificRegistersHashTable.put("cs", new Long(1));
		machineSpecificRegistersHashTable.put("ss", new Long(2));
		machineSpecificRegistersHashTable.put("ds", new Long(3));
		machineSpecificRegistersHashTable.put("fs", new Long(4));
		machineSpecificRegistersHashTable.put("gs", new Long(5));
		
		machineSpecificRegistersHashTable.put("eflags", new Long(5));
		machineSpecificRegistersHashTable.put("rip", new Long(6));
		
		//FIXME: Not sure if this goes here
		machineSpecificRegistersHashTable.put("FP_CWORD", new Long(7));
		
		//-------------------------Integer register-----------------------------------------------
		//Registers available to the programmer
		integerRegistersHashTable.put("rax", new Long(0));
		integerRegistersHashTable.put("rbx", new Long(1));
		integerRegistersHashTable.put("rcx", new Long(2));
		integerRegistersHashTable.put("rdx", new Long(3));
		integerRegistersHashTable.put("r8", new Long(4));
		integerRegistersHashTable.put("r9", new Long(5));
		integerRegistersHashTable.put("r10", new Long(6));
		integerRegistersHashTable.put("r11", new Long(7));
		integerRegistersHashTable.put("r12", new Long(8));
		integerRegistersHashTable.put("r13", new Long(9));
		integerRegistersHashTable.put("r14", new Long(10));
		integerRegistersHashTable.put("r15", new Long(11));
		
		//Index registers
		machineSpecificRegistersHashTable.put("rsi", new Long(12));
		machineSpecificRegistersHashTable.put("rdi", new Long(13));
		machineSpecificRegistersHashTable.put("rbp", new Long(14));
		machineSpecificRegistersHashTable.put("rsp", new Long(15));
		
		//Weird Register
		machineSpecificRegistersHashTable.put("riz", new Long(17));
		
		//Temporary registers
		integerRegistersHashTable.put("temp0", new Long(18));
		integerRegistersHashTable.put("temp1", new Long(19));
		integerRegistersHashTable.put("temp2", new Long(20));
		integerRegistersHashTable.put("temp3", new Long(21));
		integerRegistersHashTable.put("temp4", new Long(22));
		integerRegistersHashTable.put("temp5", new Long(23));
		integerRegistersHashTable.put("temp6", new Long(24));
		integerRegistersHashTable.put("temp7", new Long(25));
		
		
		//-------------------------Floating-point register-----------------------------------------
		//Stack registers
		floatRegistersHashTable.put("st",    new Long(0));
		floatRegistersHashTable.put("st(0)", new Long(0));
		floatRegistersHashTable.put("st(1)", new Long(1));
		floatRegistersHashTable.put("st(2)", new Long(2));
		floatRegistersHashTable.put("st(3)", new Long(3));
		floatRegistersHashTable.put("st(4)", new Long(4));
		floatRegistersHashTable.put("st(5)", new Long(5));
		floatRegistersHashTable.put("st(6)", new Long(6));
		floatRegistersHashTable.put("st(7)", new Long(7));
		
		//FIXME : This register-set can be used to perform integer operations too.
		//So its exact type - integer or floating point is ambiguous
		floatRegistersHashTable.put("xmm0",  new Long(9));
		floatRegistersHashTable.put("xmm1",  new Long(10));
		floatRegistersHashTable.put("xmm2",  new Long(11));
		floatRegistersHashTable.put("xmm3",  new Long(12));
		floatRegistersHashTable.put("xmm4",  new Long(13));
		floatRegistersHashTable.put("xmm5",  new Long(14));
		floatRegistersHashTable.put("xmm6",  new Long(15));
		floatRegistersHashTable.put("xmm7",  new Long(16));
		floatRegistersHashTable.put("xmm8",  new Long(17));
		floatRegistersHashTable.put("xmm9",  new Long(18));
		floatRegistersHashTable.put("xmm10", new Long(19));
		floatRegistersHashTable.put("xmm11", new Long(20));
		floatRegistersHashTable.put("xmm12", new Long(21));
		floatRegistersHashTable.put("xmm13", new Long(22));
		floatRegistersHashTable.put("xmm14", new Long(23));
		floatRegistersHashTable.put("xmm15", new Long(24));		
		
		//temporary floating-point registers
		floatRegistersHashTable.put("tempFloat0", new Long(25));
		floatRegistersHashTable.put("tempFloat1", new Long(26));
		floatRegistersHashTable.put("tempFloat2", new Long(27));
		floatRegistersHashTable.put("tempFloat3", new Long(28));
	}

	
	//assign an index to each coarse-register
	public static long encodeRegister(String regStr)
	{
		checkAndCreateRegisterHashTable();
		
		Long codeRegister = null;
		
		if((codeRegister = machineSpecificRegistersHashTable.get(regStr)) != null)
		{
			return codeRegister.longValue();
		}
		else if((codeRegister = integerRegistersHashTable.get(regStr)) != null)
		{
			return codeRegister.longValue();
		}
		else if((codeRegister = floatRegistersHashTable.get(regStr)) != null)
		{
			return codeRegister.longValue();
		}
		else
		{
			misc.Error.showErrorAndExit("\n\tNot a valid register : " + regStr + " !!");
			return -1;
		}
	}
	

{'fraction_non_alphanumeric': 0.197790294627383, 'fraction_numerical': 0.02202484113229347, 'mean_word_length': 3.956692913385827, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3404395', 'n_tokens_mistral': 4351, 'n_tokens_neox': 3856, 'n_words': 911}