Skip to content

Commit

Permalink
A. Simonetta's #967 fixes corrected.
Browse files Browse the repository at this point in the history
  • Loading branch information
codemanyak committed Apr 24, 2021
1 parent 8efd5fb commit 7c866e6
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions src/lu/fisch/structorizer/generators/ArmGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* Kay Gürtzig 2021-04-14 Issue #738: Highlighting map faults mended
* Kay Gürtzig 2021-04-15 Gnu mode now obtained from plugin option rather than Element field
* A. Simonetta 2021-04-23 Input and output and some parsing flaws fixed
* Kay Gürtzig 2021-04-24 Some corrections to the fixes of A. Simonetta
*
******************************************************************************************************
*
Expand All @@ -47,6 +48,7 @@
******************************************************************************************************///

import lu.fisch.structorizer.elements.*;
import lu.fisch.structorizer.parsers.CodeParser;
import lu.fisch.utils.StringList;

import java.util.*;
Expand Down Expand Up @@ -83,6 +85,10 @@ public class ArmGenerator extends Generator {
private static final Pattern stringInitialization = Pattern.compile(String.format("(%s|%s) *%s *\"[\\w]{2,}\"", registerPattern, variablePattern, assignmentOperators));
private static final Pattern charInitialization = Pattern.compile(String.format("(%s|%s) *%s *\"[\\w]\"", registerPattern, variablePattern, assignmentOperators));
private static final Pattern booleanAssignmentPattern = Pattern.compile(String.format("(%s|%s) *%s *(true|false)", registerPattern, variablePattern, assignmentOperators));
// START KGU#968 2021-04-24: Enh. #967 - correct keyword comparison; patterns will be set when code generation is started
private static Pattern inputPattern = null;
private static Pattern outputPattern = null;
// END KGU#968 2021-04-24

/**
* Enum type for getMode()
Expand Down Expand Up @@ -236,6 +242,12 @@ public String generateCode(Root _root, String _indent, boolean _public) {
if (optionGnu instanceof Boolean) {
gnuEnabled = (Boolean) optionGnu;
}
// START KGU#968 2021-04-24: Enh. #967 - prepare correct keyword comparison
String inputKeyword = CodeParser.getKeywordOrDefault("input", "input");
String outputKeyword = CodeParser.getKeywordOrDefault("output", "output");
inputPattern = Pattern.compile(getKeywordPattern(inputKeyword) + "([\\W].*|$)");
outputPattern = Pattern.compile(getKeywordPattern(outputKeyword) + "([\\W].*|$)");
// END KGU#968 2021-04-24
// END KGU#968 2021-04-15
// START KGU#705 2021-04-14: Enh. #738 (Direct code changes compromise codeMap)
//if (topLevel && gnuEnabled) {
Expand Down Expand Up @@ -729,7 +741,11 @@ private void generateInstructionLine(String line, boolean isDisabled) {
if (gnuEnabled) {
newline = variablesToRegisters(line);
String register = newline.split(" ")[1];
addCode(String.format("LDR %s, =0xFF200050\n%sLDR %s, [%s]", register, getIndent(), register, register), getIndent(), isDisabled);
// START KGU#968 2021-04-24: We must add two lines via two calls (for correct line counting)
//addCode(String.format("LDR %s, =0xFF200050\n%sLDR %s, [%s]", register, getIndent(), register, register), getIndent(), isDisabled);
addCode(String.format("LDR %s, =0xFF200050", register), getIndent(), isDisabled);
addCode(String.format("LDR %s, [%s]", register, register), getIndent(), isDisabled);
// END KGU#968 2021-04-24
} else {
appendComment("Error: INPUT operation available only in GNU\n" + line, getIndent());
}
Expand All @@ -739,7 +755,11 @@ private void generateInstructionLine(String line, boolean isDisabled) {
newline = variablesToRegisters(line);
String register = newline.split(" ")[1];
String availableRegister = getAvailableRegister();
addCode(String.format("LDR %s, =0xFF201000\n%sSTR %s, [%s]", availableRegister, getIndent(), register, availableRegister), getIndent(), isDisabled);
// START KGU#968 2021-04-24: We must add two lines via two calls (for correct line counting)
//addCode(String.format("LDR %s, =0xFF201000\n%sSTR %s, [%s]", availableRegister, getIndent(), register, availableRegister), getIndent(), isDisabled);
addCode(String.format("LDR %s, =0xFF201000", availableRegister), getIndent(), isDisabled);
addCode(String.format("STR %s, [%s]", register, availableRegister), getIndent(), isDisabled);
// END KGU#968 2021-04-24
} else {
appendComment("Error: OUTPUT operation available only in GNU\n" + line, getIndent());
}
Expand All @@ -757,6 +777,11 @@ private void generateInstructionLine(String line, boolean isDisabled) {
* @return string that represents what is the instruction
*/
private ARM_OPERATIONS getMode(String line1) {
// START KGU#968 2021-04-24: Enh. #967 - correct keyword comparison
boolean isInput = inputPattern != null && inputPattern.matcher(line1).matches();
boolean isOutput = outputPattern != null && outputPattern.matcher(line1).matches();

// END KGU#968 2021-04-24
String line = line1.replace(" ", "");
ARM_OPERATIONS mode = ARM_OPERATIONS.NOT_IMPLEMENTED;

Expand All @@ -782,10 +807,16 @@ private ARM_OPERATIONS getMode(String line1) {
mode = ARM_OPERATIONS.ARRAY_INITIALIZATION;
} else if (address.matcher(line).matches()) {
mode = ARM_OPERATIONS.ADDRESS;
} else if (line.toLowerCase().contains("input")) {
// START KGU#968 2021-04-24: Correct input/output detection
//} else if (line.toLowerCase().contains("input")) {
// mode = ARM_OPERATIONS.INPUT;
//} else if (line.toLowerCase().contains("output")) {
// mode = ARM_OPERATIONS.OUTPUT;
} else if (isInput) {
mode = ARM_OPERATIONS.INPUT;
} else if (line.toLowerCase().contains("output")) {
} else if (isOutput) {
mode = ARM_OPERATIONS.OUTPUT;
// END KGU#968 2021-04-24
} else if (isArmInstruction(line)) {
mode = ARM_OPERATIONS.INSTRUCTION;
}
Expand Down

0 comments on commit 7c866e6

Please sign in to comment.