mirror of
				https://github.com/simon987/Much-Assembly-Required.git
				synced 2025-10-31 08:16:52 +00:00 
			
		
		
		
	Merge pull request #189 from KevinRamharak/possible-implementation-aliases
add implementation for instruction aliases
This commit is contained in:
		
						commit
						a768cf0f4b
					
				| @ -4,6 +4,7 @@ import net.simon987.server.assembly.instruction.*; | |||||||
| import net.simon987.server.logging.LogManager; | import net.simon987.server.logging.LogManager; | ||||||
| 
 | 
 | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
|  | import java.util.Map; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Default instruction set for the CPU |  * Default instruction set for the CPU | ||||||
| @ -13,7 +14,12 @@ public class DefaultInstructionSet implements InstructionSet { | |||||||
|     /** |     /** | ||||||
|      * Map of instructions, stored in opcode : Instruction format |      * Map of instructions, stored in opcode : Instruction format | ||||||
|      */ |      */ | ||||||
|     private HashMap<Integer, Instruction> instructionMap = new HashMap<>(32); |     private Map<Integer, Instruction> instructionMap = new HashMap<>(32); | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Map of aliasses, stored in mnemonic : Instruction format | ||||||
|  |      */ | ||||||
|  |     private Map<String, Instruction> aliasesMap = new HashMap<>(16); | ||||||
| 
 | 
 | ||||||
|     private Instruction defaultInstruction; |     private Instruction defaultInstruction; | ||||||
| 
 | 
 | ||||||
| @ -32,7 +38,6 @@ public class DefaultInstructionSet implements InstructionSet { | |||||||
|         add(new AndInstruction()); |         add(new AndInstruction()); | ||||||
|         add(new OrInstruction()); |         add(new OrInstruction()); | ||||||
|         add(new ShlInstruction()); |         add(new ShlInstruction()); | ||||||
|         add(new SalInstruction()); //Alias is added |  | ||||||
|         add(new ShrInstruction()); |         add(new ShrInstruction()); | ||||||
|         add(new XorInstruction()); |         add(new XorInstruction()); | ||||||
|         add(new TestInstruction()); |         add(new TestInstruction()); | ||||||
| @ -46,6 +51,9 @@ public class DefaultInstructionSet implements InstructionSet { | |||||||
|         add(new SarInstruction()); |         add(new SarInstruction()); | ||||||
|         add(new IncInstruction()); |         add(new IncInstruction()); | ||||||
|         add(new DecInstruction()); |         add(new DecInstruction()); | ||||||
|  | 
 | ||||||
|  |         // aliases | ||||||
|  |         add(new SalInstruction()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -86,16 +94,22 @@ public class DefaultInstructionSet implements InstructionSet { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         Instruction aliasedInstruction = aliasesMap.get(mnemonic.toLowerCase()); | ||||||
|  |         if (aliasedInstruction != null) { | ||||||
|  |             return aliasedInstruction; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void add(Instruction instruction) { |     public void add(Instruction instruction) { | ||||||
|         if (instructionMap.containsKey(instruction.getOpCode())) { |         Instruction aliasedInstruction = instructionMap.get(instruction.getOpCode()); | ||||||
|             LogManager.LOGGER.fine(instruction.getMnemonic() + " instruction is an alias for " + |         if (aliasedInstruction != null) { | ||||||
|                     instructionMap.get(instruction.getOpCode()).getMnemonic()); |             aliasesMap.put(instruction.getMnemonic(), aliasedInstruction); | ||||||
|  |         } else { | ||||||
|  |             instructionMap.put(instruction.getOpCode(), instruction); | ||||||
|         } |         } | ||||||
|         instructionMap.put(instruction.getOpCode(), instruction); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user