mirror of
https://github.com/lefticus/6502-cpp.git
synced 2025-07-24 13:24:23 +00:00
Start to cleanup layout and code
This commit is contained in:
@@ -1,25 +1,25 @@
|
|||||||
AccessModifierOffset: -2
|
AccessModifierOffset: -2
|
||||||
AlignAfterOpenBracket: DontAlign
|
AlignAfterOpenBracket: DontAlign
|
||||||
AlignConsecutiveAssignments: false
|
AlignConsecutiveAssignments: Consecutive
|
||||||
AlignConsecutiveDeclarations: false
|
AlignConsecutiveDeclarations: Consecutive
|
||||||
AlignEscapedNewlines: Left
|
AlignEscapedNewlines: Left
|
||||||
AlignOperands: true
|
AlignOperands: true
|
||||||
AlignTrailingComments: false
|
AlignTrailingComments: false
|
||||||
AllowAllParametersOfDeclarationOnNextLine: false
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
AllowShortBlocksOnASingleLine: true
|
AllowShortBlocksOnASingleLine: Always
|
||||||
AllowShortCaseLabelsOnASingleLine: false
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
AllowShortFunctionsOnASingleLine: All
|
AllowShortFunctionsOnASingleLine: All
|
||||||
AllowShortIfStatementsOnASingleLine: true
|
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||||
AllowShortLoopsOnASingleLine: true
|
AllowShortLoopsOnASingleLine: true
|
||||||
AlwaysBreakAfterDefinitionReturnType: None
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
AlwaysBreakAfterReturnType: None
|
AlwaysBreakAfterReturnType: None
|
||||||
AlwaysBreakBeforeMultilineStrings: true
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
AlwaysBreakTemplateDeclarations: false
|
AlwaysBreakTemplateDeclarations: MultiLine
|
||||||
BinPackArguments: false
|
BinPackArguments: false
|
||||||
BinPackParameters: false
|
BinPackParameters: false
|
||||||
BraceWrapping:
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
AfterClass: true
|
AfterClass: true
|
||||||
AfterControlStatement: false
|
|
||||||
AfterEnum: false
|
AfterEnum: false
|
||||||
AfterFunction: true
|
AfterFunction: true
|
||||||
AfterNamespace: false
|
AfterNamespace: false
|
||||||
@@ -79,7 +79,7 @@ ObjCSpaceAfterProperty: true
|
|||||||
ObjCSpaceBeforeProtocolList: false
|
ObjCSpaceBeforeProtocolList: false
|
||||||
PointerAlignment: Right
|
PointerAlignment: Right
|
||||||
ReflowComments: true
|
ReflowComments: true
|
||||||
SortIncludes: false
|
SortIncludes: CaseInsensitive
|
||||||
SortUsingDeclarations: false
|
SortUsingDeclarations: false
|
||||||
SpaceAfterCStyleCast: false
|
SpaceAfterCStyleCast: false
|
||||||
SpaceAfterTemplateKeyword: false
|
SpaceAfterTemplateKeyword: false
|
||||||
@@ -92,7 +92,7 @@ SpacesInCStyleCastParentheses: false
|
|||||||
SpacesInContainerLiterals: true
|
SpacesInContainerLiterals: true
|
||||||
SpacesInParentheses: false
|
SpacesInParentheses: false
|
||||||
SpacesInSquareBrackets: false
|
SpacesInSquareBrackets: false
|
||||||
Standard: Cpp11
|
Standard: c++20
|
||||||
TabWidth: 8
|
TabWidth: 8
|
||||||
UseTab: Never
|
UseTab: Never
|
||||||
|
|
||||||
|
373
src/6502-c++.cpp
373
src/6502-c++.cpp
@@ -1,12 +1,13 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <set>
|
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <map>
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <regex>
|
||||||
|
#include <set>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
struct ASMLine
|
struct ASMLine
|
||||||
{
|
{
|
||||||
@@ -101,43 +102,56 @@ struct mos6502 : ASMLine
|
|||||||
{
|
{
|
||||||
enum class OpCode {
|
enum class OpCode {
|
||||||
unknown,
|
unknown,
|
||||||
lda,
|
|
||||||
|
adc,
|
||||||
|
AND,
|
||||||
asl,
|
asl,
|
||||||
rol,
|
|
||||||
ldy,
|
bcc,
|
||||||
tay,
|
bcs,
|
||||||
tya,
|
beq,
|
||||||
tax,
|
bit,
|
||||||
txa,
|
bmi,
|
||||||
|
bne,
|
||||||
|
bpl,
|
||||||
|
|
||||||
cpy,
|
cpy,
|
||||||
|
cmp,
|
||||||
|
clc,
|
||||||
|
|
||||||
|
dec,
|
||||||
|
|
||||||
eor,
|
eor,
|
||||||
|
|
||||||
|
inc,
|
||||||
|
|
||||||
|
jmp,
|
||||||
|
jsr,
|
||||||
|
|
||||||
|
lda,
|
||||||
|
ldy,
|
||||||
|
lsr,
|
||||||
|
|
||||||
|
ORA,
|
||||||
|
|
||||||
|
pha,
|
||||||
|
php,
|
||||||
|
pla,
|
||||||
|
plp,
|
||||||
|
|
||||||
|
rol,
|
||||||
|
ror,
|
||||||
|
rts,
|
||||||
|
|
||||||
|
sbc,
|
||||||
|
sec,
|
||||||
sta,
|
sta,
|
||||||
sty,
|
sty,
|
||||||
pha,
|
|
||||||
pla,
|
tax,
|
||||||
php,
|
tay,
|
||||||
plp,
|
txa,
|
||||||
lsr,
|
tya,
|
||||||
ror,
|
|
||||||
AND,
|
|
||||||
inc,
|
|
||||||
dec,
|
|
||||||
ORA,
|
|
||||||
cmp,
|
|
||||||
bne,
|
|
||||||
beq,
|
|
||||||
bmi,
|
|
||||||
bpl,
|
|
||||||
jmp,
|
|
||||||
adc,
|
|
||||||
sbc,
|
|
||||||
rts,
|
|
||||||
clc,
|
|
||||||
sec,
|
|
||||||
bit,
|
|
||||||
jsr,
|
|
||||||
bcc,
|
|
||||||
bcs
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool get_is_branch(const OpCode o)
|
static bool get_is_branch(const OpCode o)
|
||||||
@@ -150,37 +164,38 @@ struct mos6502 : ASMLine
|
|||||||
case OpCode::bcc:
|
case OpCode::bcc:
|
||||||
case OpCode::bcs:
|
case OpCode::bcs:
|
||||||
return true;
|
return true;
|
||||||
case OpCode::lda:
|
case OpCode::adc:
|
||||||
case OpCode::ldy:
|
|
||||||
case OpCode::tay:
|
|
||||||
case OpCode::tya:
|
|
||||||
case OpCode::tax:
|
|
||||||
case OpCode::txa:
|
|
||||||
case OpCode::cpy:
|
|
||||||
case OpCode::eor:
|
|
||||||
case OpCode::sta:
|
|
||||||
case OpCode::sty:
|
|
||||||
case OpCode::pha:
|
|
||||||
case OpCode::pla:
|
|
||||||
case OpCode::php:
|
|
||||||
case OpCode::plp:
|
|
||||||
case OpCode::lsr:
|
|
||||||
case OpCode::ror:
|
|
||||||
case OpCode::AND:
|
case OpCode::AND:
|
||||||
case OpCode::inc:
|
case OpCode::asl:
|
||||||
case OpCode::dec:
|
case OpCode::bit:
|
||||||
case OpCode::ORA:
|
case OpCode::cpy:
|
||||||
case OpCode::cmp:
|
case OpCode::cmp:
|
||||||
|
case OpCode::clc:
|
||||||
|
case OpCode::dec:
|
||||||
|
case OpCode::eor:
|
||||||
|
case OpCode::inc:
|
||||||
case OpCode::jmp:
|
case OpCode::jmp:
|
||||||
case OpCode::jsr:
|
case OpCode::jsr:
|
||||||
case OpCode::adc:
|
case OpCode::lda:
|
||||||
case OpCode::sbc:
|
case OpCode::ldy:
|
||||||
case OpCode::rts:
|
case OpCode::lsr:
|
||||||
case OpCode::clc:
|
case OpCode::ORA:
|
||||||
case OpCode::sec:
|
case OpCode::pha:
|
||||||
case OpCode::bit:
|
case OpCode::php:
|
||||||
case OpCode::asl:
|
case OpCode::pla:
|
||||||
|
case OpCode::plp:
|
||||||
case OpCode::rol:
|
case OpCode::rol:
|
||||||
|
case OpCode::ror:
|
||||||
|
case OpCode::rts:
|
||||||
|
case OpCode::sbc:
|
||||||
|
case OpCode::sec:
|
||||||
|
case OpCode::sta:
|
||||||
|
case OpCode::sty:
|
||||||
|
case OpCode::tax:
|
||||||
|
case OpCode::tay:
|
||||||
|
case OpCode::txa:
|
||||||
|
case OpCode::tya:
|
||||||
|
|
||||||
case OpCode::unknown:
|
case OpCode::unknown:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -190,44 +205,44 @@ struct mos6502 : ASMLine
|
|||||||
static bool get_is_comparison(const OpCode o)
|
static bool get_is_comparison(const OpCode o)
|
||||||
{
|
{
|
||||||
switch (o) {
|
switch (o) {
|
||||||
|
case OpCode::bit:
|
||||||
case OpCode::cmp:
|
case OpCode::cmp:
|
||||||
case OpCode::cpy:
|
case OpCode::cpy:
|
||||||
case OpCode::bit:
|
|
||||||
return true;
|
return true;
|
||||||
case OpCode::lda:
|
case OpCode::adc:
|
||||||
case OpCode::ldy:
|
|
||||||
case OpCode::tay:
|
|
||||||
case OpCode::tya:
|
|
||||||
case OpCode::tax:
|
|
||||||
case OpCode::txa:
|
|
||||||
case OpCode::eor:
|
|
||||||
case OpCode::sta:
|
|
||||||
case OpCode::sty:
|
|
||||||
case OpCode::pha:
|
|
||||||
case OpCode::pla:
|
|
||||||
case OpCode::php:
|
|
||||||
case OpCode::plp:
|
|
||||||
case OpCode::lsr:
|
|
||||||
case OpCode::ror:
|
|
||||||
case OpCode::AND:
|
case OpCode::AND:
|
||||||
case OpCode::inc:
|
case OpCode::asl:
|
||||||
case OpCode::dec:
|
case OpCode::beq:
|
||||||
case OpCode::ORA:
|
|
||||||
case OpCode::jmp:
|
|
||||||
case OpCode::jsr:
|
|
||||||
case OpCode::bne:
|
case OpCode::bne:
|
||||||
case OpCode::bmi:
|
case OpCode::bmi:
|
||||||
case OpCode::beq:
|
|
||||||
case OpCode::bpl:
|
case OpCode::bpl:
|
||||||
case OpCode::bcs:
|
|
||||||
case OpCode::bcc:
|
case OpCode::bcc:
|
||||||
case OpCode::adc:
|
case OpCode::bcs:
|
||||||
case OpCode::sbc:
|
|
||||||
case OpCode::rts:
|
|
||||||
case OpCode::clc:
|
case OpCode::clc:
|
||||||
case OpCode::sec:
|
case OpCode::dec:
|
||||||
|
case OpCode::eor:
|
||||||
|
case OpCode::inc:
|
||||||
|
case OpCode::jmp:
|
||||||
|
case OpCode::jsr:
|
||||||
|
case OpCode::lda:
|
||||||
|
case OpCode::ldy:
|
||||||
|
case OpCode::lsr:
|
||||||
|
case OpCode::ORA:
|
||||||
|
case OpCode::pha:
|
||||||
|
case OpCode::php:
|
||||||
|
case OpCode::pla:
|
||||||
|
case OpCode::plp:
|
||||||
case OpCode::rol:
|
case OpCode::rol:
|
||||||
case OpCode::asl:
|
case OpCode::ror:
|
||||||
|
case OpCode::rts:
|
||||||
|
case OpCode::sbc:
|
||||||
|
case OpCode::sec:
|
||||||
|
case OpCode::sta:
|
||||||
|
case OpCode::sty:
|
||||||
|
case OpCode::tax:
|
||||||
|
case OpCode::tay:
|
||||||
|
case OpCode::txa:
|
||||||
|
case OpCode::tya:
|
||||||
case OpCode::unknown:
|
case OpCode::unknown:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -236,7 +251,7 @@ struct mos6502 : ASMLine
|
|||||||
|
|
||||||
|
|
||||||
explicit mos6502(const OpCode o)
|
explicit mos6502(const OpCode o)
|
||||||
: ASMLine(Type::Instruction, to_string(o)), opcode(o), is_branch(get_is_branch(o)), is_comparison(get_is_comparison(o))
|
: ASMLine(Type::Instruction, std::string{ to_string(o) }), opcode(o), is_branch(get_is_branch(o)), is_comparison(get_is_comparison(o))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,11 +261,11 @@ struct mos6502 : ASMLine
|
|||||||
}
|
}
|
||||||
|
|
||||||
mos6502(const OpCode o, Operand t_o)
|
mos6502(const OpCode o, Operand t_o)
|
||||||
: ASMLine(Type::Instruction, to_string(o)), opcode(o), op(std::move(t_o)), is_branch(get_is_branch(o)), is_comparison(get_is_comparison(o))
|
: ASMLine(Type::Instruction, std::string{ to_string(o) }), opcode(o), op(std::move(t_o)), is_branch(get_is_branch(o)), is_comparison(get_is_comparison(o))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string to_string(const OpCode o)
|
constexpr static std::string_view to_string(const OpCode o)
|
||||||
{
|
{
|
||||||
switch (o) {
|
switch (o) {
|
||||||
case OpCode::lda:
|
case OpCode::lda:
|
||||||
@@ -329,12 +344,12 @@ struct mos6502 : ASMLine
|
|||||||
return "bcs";
|
return "bcs";
|
||||||
case OpCode::unknown:
|
case OpCode::unknown:
|
||||||
return "";
|
return "";
|
||||||
};
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string to_string() const
|
[[nodiscard]] std::string to_string() const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ASMLine::Type::Label:
|
case ASMLine::Type::Label:
|
||||||
@@ -361,86 +376,95 @@ struct AVR : ASMLine
|
|||||||
{
|
{
|
||||||
enum class OpCode {
|
enum class OpCode {
|
||||||
unknown,
|
unknown,
|
||||||
ldi,
|
|
||||||
sts,
|
adc,
|
||||||
ret,
|
add,
|
||||||
mov,
|
|
||||||
lsl,
|
|
||||||
rol,
|
|
||||||
rcall,
|
|
||||||
ld,
|
|
||||||
subi,
|
|
||||||
sbci,
|
|
||||||
st,
|
|
||||||
lds,
|
|
||||||
lsr,
|
|
||||||
andi,
|
andi,
|
||||||
|
|
||||||
|
breq,
|
||||||
|
brlo,
|
||||||
|
brne,
|
||||||
|
brsh,
|
||||||
|
|
||||||
|
clr,
|
||||||
|
com,
|
||||||
|
cpc,
|
||||||
|
cpi,
|
||||||
|
cpse,
|
||||||
|
dec,
|
||||||
|
|
||||||
eor,
|
eor,
|
||||||
|
|
||||||
|
ld,
|
||||||
|
ldi,
|
||||||
|
lds,
|
||||||
|
lsl,
|
||||||
|
lsr,
|
||||||
|
|
||||||
|
mov,
|
||||||
|
|
||||||
|
pop,
|
||||||
|
push,
|
||||||
|
|
||||||
|
rcall,
|
||||||
|
ret,
|
||||||
|
rjmp,
|
||||||
|
rol,
|
||||||
|
|
||||||
|
sbci,
|
||||||
|
sbiw,
|
||||||
sbrc,
|
sbrc,
|
||||||
sbrs,
|
sbrs,
|
||||||
brne,
|
st,
|
||||||
rjmp,
|
sts,
|
||||||
dec,
|
subi,
|
||||||
sbiw,
|
|
||||||
push,
|
|
||||||
pop,
|
|
||||||
com,
|
|
||||||
swap,
|
swap,
|
||||||
clr,
|
|
||||||
cpse,
|
|
||||||
cpi,
|
|
||||||
brlo,
|
|
||||||
add,
|
|
||||||
adc,
|
|
||||||
cpc,
|
|
||||||
brsh,
|
|
||||||
breq
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static OpCode parse_opcode(Type t, const std::string &o)
|
[[nodiscard]] static constexpr OpCode parse_opcode(Type t, std::string_view o)
|
||||||
{
|
{
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case Type::Label:
|
case Type::Label:
|
||||||
case Type::Directive:
|
case Type::Directive:
|
||||||
return OpCode::unknown;
|
return OpCode::unknown;
|
||||||
case Type::Instruction: {
|
case Type::Instruction: {
|
||||||
if (o == "ldi") return OpCode::ldi;
|
if (o == "ldi") { return OpCode::ldi; }
|
||||||
if (o == "sts") return OpCode::sts;
|
if (o == "sts") { return OpCode::sts; }
|
||||||
if (o == "ret") return OpCode::ret;
|
if (o == "ret") { return OpCode::ret; }
|
||||||
if (o == "mov") return OpCode::mov;
|
if (o == "mov") { return OpCode::mov; }
|
||||||
if (o == "lsl") return OpCode::lsl;
|
if (o == "lsl") { return OpCode::lsl; }
|
||||||
if (o == "rol") return OpCode::rol;
|
if (o == "rol") { return OpCode::rol;}
|
||||||
if (o == "rcall") return OpCode::rcall;
|
if (o == "rcall") { return OpCode::rcall;}
|
||||||
if (o == "ld") return OpCode::ld;
|
if (o == "ld") { return OpCode::ld;}
|
||||||
if (o == "subi") return OpCode::subi;
|
if (o == "subi") { return OpCode::subi;}
|
||||||
if (o == "sbci") return OpCode::sbci;
|
if (o == "sbci") { return OpCode::sbci;}
|
||||||
if (o == "st") return OpCode::st;
|
if (o == "st") { return OpCode::st;}
|
||||||
if (o == "lds") return OpCode::lds;
|
if (o == "lds") { return OpCode::lds;}
|
||||||
if (o == "lsr") return OpCode::lsr;
|
if (o == "lsr") { return OpCode::lsr;}
|
||||||
if (o == "andi") return OpCode::andi;
|
if (o == "andi") { return OpCode::andi;}
|
||||||
if (o == "eor") return OpCode::eor;
|
if (o == "eor") { return OpCode::eor;}
|
||||||
if (o == "sbrc") return OpCode::sbrc;
|
if (o == "sbrc") { return OpCode::sbrc;}
|
||||||
if (o == "rjmp") return OpCode::rjmp;
|
if (o == "rjmp") { return OpCode::rjmp;}
|
||||||
if (o == "sbrs") return OpCode::sbrs;
|
if (o == "sbrs") { return OpCode::sbrs;}
|
||||||
if (o == "brne") return OpCode::brne;
|
if (o == "brne") { return OpCode::brne;}
|
||||||
if (o == "dec") return OpCode::dec;
|
if (o == "dec") { return OpCode::dec;}
|
||||||
if (o == "sbiw") return OpCode::sbiw;
|
if (o == "sbiw") { return OpCode::sbiw;}
|
||||||
if (o == "push") return OpCode::push;
|
if (o == "push") { return OpCode::push;}
|
||||||
if (o == "pop") return OpCode::pop;
|
if (o == "pop") { return OpCode::pop;}
|
||||||
if (o == "com") return OpCode::com;
|
if (o == "com") { return OpCode::com;}
|
||||||
if (o == "swap") return OpCode::swap;
|
if (o == "swap") { return OpCode::swap;}
|
||||||
if (o == "clr") return OpCode::clr;
|
if (o == "clr") { return OpCode::clr;}
|
||||||
if (o == "cpse") return OpCode::cpse;
|
if (o == "cpse") { return OpCode::cpse;}
|
||||||
if (o == "cpi") return OpCode::cpi;
|
if (o == "cpi") { return OpCode::cpi;}
|
||||||
if (o == "brlo") return OpCode::brlo;
|
if (o == "brlo") { return OpCode::brlo;}
|
||||||
if (o == "add") return OpCode::add;
|
if (o == "add") { return OpCode::add;}
|
||||||
if (o == "adc") return OpCode::adc;
|
if (o == "adc") { return OpCode::adc;}
|
||||||
if (o == "cpc") return OpCode::cpc;
|
if (o == "cpc") { return OpCode::cpc;}
|
||||||
if (o == "brsh") return OpCode::brsh;
|
if (o == "brsh") { return OpCode::brsh;}
|
||||||
if (o == "breq") return OpCode::breq;
|
if (o == "breq") { return OpCode::breq;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Unknown opcode: " + o);
|
throw std::runtime_error(fmt::format("Unknown opcode: {}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_register_number(const char reg_name)
|
static int get_register_number(const char reg_name)
|
||||||
@@ -536,7 +560,7 @@ struct AVR : ASMLine
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Operand parse_operand(std::string o)
|
static Operand parse_operand(std::string_view o)
|
||||||
{
|
{
|
||||||
if (o.empty()) {
|
if (o.empty()) {
|
||||||
return Operand();
|
return Operand();
|
||||||
@@ -545,12 +569,12 @@ struct AVR : ASMLine
|
|||||||
if (o[0] == 'r' && o.size() > 1) {
|
if (o[0] == 'r' && o.size() > 1) {
|
||||||
return Operand(Operand::Type::reg, atoi(&o[1]));
|
return Operand(Operand::Type::reg, atoi(&o[1]));
|
||||||
} else {
|
} else {
|
||||||
return Operand(Operand::Type::literal, std::move(o));
|
return Operand(Operand::Type::literal, std::string{ o });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AVR(const int t_line_num, std::string t_line_text, Type t, std::string t_opcode, std::string o1 = "", std::string o2 = "")
|
AVR(const int t_line_num, std::string_view t_line_text, Type t, std::string_view t_opcode, std::string_view o1 = "", std::string_view o2 = "")
|
||||||
: ASMLine(t, t_opcode), line_num(t_line_num), line_text(std::move(t_line_text)),
|
: ASMLine(t, std::string(t_opcode)), line_num(t_line_num), line_text(std::string(t_line_text)),
|
||||||
opcode(parse_opcode(t, t_opcode)), operand1(parse_operand(o1)), operand2(parse_operand(o2))
|
opcode(parse_opcode(t, t_opcode)), operand1(parse_operand(o1)), operand2(parse_operand(o2))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -920,7 +944,7 @@ void log(LogLevel ll, const AVR &i, const std::string &message)
|
|||||||
std::cerr << to_string(ll) << ": " << i.line_num << ": " << message << ": `" << i.line_text << "`\n";
|
std::cerr << to_string(ll) << ": " << i.line_num << ": " << message << ": `" << i.line_text << "`\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void log(LogLevel ll, const int line_no, const std::string &line, const std::string &message)
|
void log(LogLevel ll, const std::size_t line_no, const std::string &line, const std::string &message)
|
||||||
{
|
{
|
||||||
std::cerr << to_string(ll) << ": " << line_no << ": " << message << ": `" << line << "`\n";
|
std::cerr << to_string(ll) << ": " << line_no << ": " << message << ": `" << line << "`\n";
|
||||||
}
|
}
|
||||||
@@ -1209,7 +1233,7 @@ void run(std::istream &input)
|
|||||||
std::regex BinaryInstruction(R"(^\s+(\S+)\s+(\S+),\s*(\S+))");
|
std::regex BinaryInstruction(R"(^\s+(\S+)\s+(\S+),\s*(\S+))");
|
||||||
std::regex Instruction(R"(^\s+(\S+))");
|
std::regex Instruction(R"(^\s+(\S+))");
|
||||||
|
|
||||||
int lineno = 0;
|
std::size_t lineno = 0;
|
||||||
|
|
||||||
|
|
||||||
std::vector<AVR> instructions;
|
std::vector<AVR> instructions;
|
||||||
@@ -1220,18 +1244,19 @@ void run(std::istream &input)
|
|||||||
try {
|
try {
|
||||||
std::smatch match;
|
std::smatch match;
|
||||||
if (std::regex_match(line, match, Label)) {
|
if (std::regex_match(line, match, Label)) {
|
||||||
instructions.emplace_back(lineno, line, ASMLine::Type::Label, match[1]);
|
instructions.emplace_back(lineno, line, ASMLine::Type::Label, match[1].str());
|
||||||
} else if (std::regex_match(line, match, Comment)) {
|
} else if (std::regex_match(line, match, Comment)) {
|
||||||
// don't care about comments
|
// don't care about comments
|
||||||
} else if (std::regex_match(line, match, Directive)) {
|
} else if (std::regex_match(line, match, Directive)) {
|
||||||
instructions.emplace_back(lineno, line, ASMLine::Type::Directive, match[1]);
|
instructions.emplace_back(lineno, line, ASMLine::Type::Directive, match[1].str());
|
||||||
} else if (std::regex_match(line, match, BinaryInstruction)) {
|
} else if (std::regex_match(line, match, BinaryInstruction)) {
|
||||||
instructions.emplace_back(lineno, line, ASMLine::Type::Instruction, match[1], match[2], match[3]);
|
instructions.emplace_back(lineno, line, ASMLine::Type::Instruction, match[1].str(), match[2].str(), match[3].str());
|
||||||
} else if (std::regex_match(line, match, UnaryInstruction)) {
|
} else if (std::regex_match(line, match, UnaryInstruction)) {
|
||||||
instructions.emplace_back(lineno, line, ASMLine::Type::Instruction, match[1], match[2]);
|
instructions.emplace_back(lineno, line, ASMLine::Type::Instruction, match[1].str(), match[2].str());
|
||||||
} else if (std::regex_match(line, match, Instruction)) {
|
} else if (std::regex_match(line, match, Instruction)) {
|
||||||
instructions.emplace_back(lineno, line, ASMLine::Type::Instruction, match[1]);
|
instructions.emplace_back(lineno, line, ASMLine::Type::Instruction, match[1].str());
|
||||||
} else if (line == "") {
|
} else if (line.empty()) {
|
||||||
|
// skip empty lines
|
||||||
}
|
}
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
log(LogLevel::Error, lineno, line, e.what());
|
log(LogLevel::Error, lineno, line, e.what());
|
||||||
|
Reference in New Issue
Block a user