parser now acounts for instruction address (#31)
Co-authored-by: darkress <30271678+DarkressX@users.noreply.github.com> Reviewed-on: darkress/pic16f84-sim#31
This commit was merged in pull request #31.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package de.darkress.pic16f84sim.parser;
|
||||
|
||||
import de.darkress.pic16f84sim.commands.Command;
|
||||
import de.darkress.pic16f84sim.decoder.CommandDecoder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
@@ -8,9 +11,9 @@ import java.util.Scanner;
|
||||
|
||||
public class Parser
|
||||
{
|
||||
public static List<Integer> parser(String filePath)
|
||||
public static Command[] parser(String filePath)
|
||||
{
|
||||
ArrayList<Integer> program = new ArrayList<>();
|
||||
ArrayList<String> instructions = new ArrayList<>();
|
||||
try {
|
||||
File file = new File(filePath);
|
||||
Scanner scanner = new Scanner(file);
|
||||
@@ -19,8 +22,10 @@ public class Parser
|
||||
if(!data.startsWith(" "))
|
||||
{
|
||||
String commandAndParametersString = "0x" + data.split(" ")[1];
|
||||
int commandAndParameters = Integer.decode(commandAndParametersString);
|
||||
program.add(commandAndParameters);
|
||||
String instructionAddress = "0x" + data.split(" ")[0];
|
||||
//int commandAndParameters = Integer.decode(commandAndParametersString);
|
||||
//program.add(commandAndParameters);
|
||||
instructions.add(instructionAddress + ", " + commandAndParametersString);
|
||||
}
|
||||
}
|
||||
scanner.close();
|
||||
@@ -28,6 +33,16 @@ public class Parser
|
||||
System.out.println("An error occurred.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Command[] program = new Command[1024];
|
||||
|
||||
for(int i = 0; i < instructions.size(); i++)
|
||||
{
|
||||
int instructionAddress = Integer.decode(instructions.get(i).split(", ")[0]);
|
||||
int instruction = Integer.decode(instructions.get(i).split(", ")[1]);
|
||||
program[instructionAddress] = CommandDecoder.decode(instruction);
|
||||
}
|
||||
|
||||
return program;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user