Skip to content

Commit

Permalink
Add separate 64 bit instruction table to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
TheThirdOne committed Jul 10, 2020
1 parent ca1fb58 commit 2faba4c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/rars/extras/Documentation.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package rars.extras;

import rars.Globals;
import rars.Settings;
import rars.assembler.Directives;
import rars.riscv.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;

/**
* Small class for automatically generating documentation.
Expand All @@ -23,6 +25,8 @@ public static void main(String[] args){
System.out.println(createSyscallMarkdown());
System.out.println(createInstructionMarkdown(BasicInstruction.class));
System.out.println(createInstructionMarkdown(ExtendedInstruction.class));
System.out.println(createInstructionMarkdown64Only(BasicInstruction.class));
System.out.println(createInstructionMarkdown64Only(ExtendedInstruction.class));
}

public static String createDirectiveMarkdown(){
Expand Down Expand Up @@ -61,8 +65,13 @@ public static String createSyscallMarkdown(){
}

public static String createInstructionMarkdown(Class<? extends Instruction> instructionClass){
Globals.getSettings().setBooleanSettingNonPersistent(Settings.Bool.RV64_ENABLED,false);
InstructionSet.rv64 = false;
Globals.instructionSet.populate();

ArrayList<Instruction> instructionList = Globals.instructionSet.getInstructionList();
instructionList.sort(Comparator.comparing(Instruction::getExampleFormat));

StringBuilder output = new StringBuilder("| Example Usage | Description |\n|---------------|-------------|");
for (Instruction instr : instructionList) {
if (instructionClass.isInstance(instr)) {
Expand All @@ -75,4 +84,33 @@ public static String createInstructionMarkdown(Class<? extends Instruction> inst
}
return output.toString();
}
public static String createInstructionMarkdown64Only(Class<? extends Instruction> instructionClass){

Globals.getSettings().setBooleanSettingNonPersistent(Settings.Bool.RV64_ENABLED,false);
InstructionSet.rv64 = false;
Globals.instructionSet.populate();

HashSet<String> set = new HashSet<>();
for (Instruction i : Globals.instructionSet.getInstructionList()){
set.add(i.getExampleFormat());
}

Globals.getSettings().setBooleanSettingNonPersistent(Settings.Bool.RV64_ENABLED,true);
InstructionSet.rv64 = true;
Globals.instructionSet.populate();

ArrayList<Instruction> instructionList64 = Globals.instructionSet.getInstructionList();
instructionList64.sort(Comparator.comparing(Instruction::getExampleFormat));
StringBuilder output = new StringBuilder("| Example Usage | Description |\n|---------------|-------------|");
for (Instruction instr : instructionList64) {
if (instructionClass.isInstance(instr) && !set.contains(instr.getExampleFormat())) {
output.append("\n|");
output.append(instr.getExampleFormat());
output.append('|');
output.append(instr.getDescription());
output.append('|');
}
}
return output.toString();
}
}

0 comments on commit 2faba4c

Please sign in to comment.