Instruction pairing extended to more than two instructions.

This commit is contained in:
Adrian Matoga 2021-03-14 23:32:32 +01:00 committed by Piotr Fusik
parent f33c112ac6
commit 9aae1ad4c4
2 changed files with 24 additions and 8 deletions

View File

@ -2664,19 +2664,24 @@ unittest {
void assemblyPair() { void assemblyPair() {
assert(!inOpcode); assert(!inOpcode);
string instruction = readInstruction(); string instruction = readInstruction();
if (!eol() && line[column] == ':') { string[] extraInstructions;
while (!eol() && line[column] == ':') {
pairing = true; pairing = true;
column++; column++;
string instruction2 = readInstruction(); extraInstructions ~= readInstruction();
}
if (!extraInstructions.empty) {
int savedColumn = column; int savedColumn = column;
if (willSkip) if (willSkip)
warning("Skipping only the first instruction"); warning("Skipping only the first instruction");
assemblyInstruction(instruction); assemblyInstruction(instruction);
checkNoExtraCharacters(); checkNoExtraCharacters();
column = savedColumn;
wereManyInstructions = false; wereManyInstructions = false;
assemblyInstruction(instruction2); foreach (instruction2; extraInstructions) {
wereManyInstructions = true; column = savedColumn;
assemblyInstruction(instruction2);
wereManyInstructions = true;
}
} else { } else {
pairing = false; pairing = false;
assemblyInstruction(instruction); assemblyInstruction(instruction);
@ -2847,6 +2852,16 @@ void assemblyFile(string filename) {
lineNo = oldLineNo; lineNo = oldLineNo;
} }
unittest {
sourceFiles[""] = " lda:sne:ldy:inx $1234".representation;
assemblyFile("");
pass2 = true;
objectBuffer.length = 0;
assemblyFile("");
writefln!"%(%02x%)"(objectBuffer);
assert(objectBuffer == [0xad, 0x34, 0x12, 0xd0, 0x03, 0xac, 0x34, 0x12, 0xe8]);
}
void assemblyPass() { void assemblyPass() {
origin = -1; origin = -1;
loadOrigin = -1; loadOrigin = -1;

View File

@ -160,7 +160,7 @@ to start a comment.
------------------------------------------------------------- -------------------------------------------------------------
[[new_pairing]] [[new_pairing]]
You may put two instructions in one line so they share their operand. You may put two or more instructions in one line so they share their operand.
For example: For example:
------------ ------------
eor:sta foo eor:sta foo
@ -173,9 +173,9 @@ is equivalent to
Note that Note that
------------ ------------
lda:tax #0 lda:tax:tay #0
------------ ------------
is allowed because `#0` is treated as a comment for `tax`. is allowed because `#0` is treated as a comment for `tax` and `tay`.
EXPRESSIONS EXPRESSIONS
----------- -----------
@ -716,6 +716,7 @@ Version 3.x.x (20xx-xx-xx)
~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
- source can optionally be read from standard input, and object can be - source can optionally be read from standard input, and object can be
written to standard output instead of files (by Adrian Matoga) written to standard output instead of files (by Adrian Matoga)
- <<new_pairing,any number of instructions in one line>> (by Adrian Matoga)
Version 3.2.0 (2021-06-22) Version 3.2.0 (2021-06-22)
~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~