- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
if (op.size() == 1)
{
if (op[0].id == LexemID::REGISTER)
{
if (isSIBbase(registerName2registerId.at( std::get<std::string>(op[0].lexemas))))
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[0].lexemas))
});
else
mnemonic.mnemonics.emplace_back(IndirectAddress{
.index = Register(std::get<std::string>(op[0].lexemas))
});
}
else if (op[0].id == LexemID::LABEL_USE)
mnemonic.mnemonics.emplace_back(IndirectAddress{
.disp = LabelUse(std::get<std::string>(op[0].lexemas))
});
else if (op[0].id == LexemID::NUMBER)
mnemonic.mnemonics.emplace_back(IndirectAddress{
.disp = Constant(std::get<int>(op[0].lexemas))
});
}
else if (op.size() == 3)
{
if (const auto operation = std::get<std::string>(op[1].lexemas)[0]; operation == '+')
{
if (op[0].id == LexemID::REGISTER && op[2].id == LexemID::REGISTER)
{
if (isSIBbase(registerName2registerId.at(std::get<std::string>(op[0].lexemas))))
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[0].lexemas)),
.index = Register(std::get<std::string>(op[2].lexemas))
});
else
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[2].lexemas)),
.index = Register(std::get<std::string>(op[0].lexemas))
});
}
else if (op[0].id == LexemID::REGISTER && op[2].id == LexemID::NUMBER)
{
if (isSIBbase(registerName2registerId.at(std::get<std::string>(op[0].lexemas))))
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[0].lexemas)),
.disp = Constant(std::get<int>(op[2].lexemas))
});
else
mnemonic.mnemonics.emplace_back(IndirectAddress{
.index = Register(std::get<std::string>(op[0].lexemas)),
.disp = Constant(std::get<int>(op[2].lexemas))
});
}
else if (op[0].id == LexemID::REGISTER && op[2].id == LexemID::LABEL_USE)
{
if (isSIBbase(registerName2registerId.at(std::get<std::string>(op[0].lexemas))))
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[0].lexemas)),
.disp = LabelUse(std::get<std::string>(op[2].lexemas))
});
else
mnemonic.mnemonics.emplace_back(IndirectAddress{
.index = Register(std::get<std::string>(op[0].lexemas)),
.disp = LabelUse(std::get<std::string>(op[2].lexemas))
});
}
}
else if (operation == '*')
{
if (op[0].id == LexemID::NUMBER && op[2].id == LexemID::REGISTER)
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[2].lexemas)),
.scale = static_cast<uint8_t>(std::get<int>(op[0].lexemas))
});
}
}
else if(op.size() == 5)
{
if (op[4].id == LexemID::REGISTER)
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[4].lexemas)),
.index = Register(std::get<std::string>(op[2].lexemas)),
.scale = static_cast<uint8_t>(std::get<int>(op[0].lexemas))
});
else if (op[4].id == LexemID::NUMBER)
mnemonic.mnemonics.emplace_back(IndirectAddress{
.index = Register(std::get<std::string>(op[2].lexemas)),
.scale = static_cast<uint8_t>(std::get<int>(op[0].lexemas)),
.disp = Constant(std::get<int>(op[4].lexemas))
});
else if (op[4].id == LexemID::LABEL_USE)
mnemonic.mnemonics.emplace_back(IndirectAddress{
.index = Register(std::get<std::string>(op[2].lexemas)),
.scale = static_cast<uint8_t>(std::get<int>(op[0].lexemas)),
.disp = LabelUse(std::get<std::string>(op[4].lexemas))
});
...
Персидский код.
Руками такую срань лучше не писать.
здесь уже синтаксический разбор проходит.
паттерн матчинга не существует в плюсах(да и не помог бы он здесь), а объединить выражения никак
> здесь уже синтаксический разбор проходит.
Ну так ты ж про перевод строчки спрашивал. Строчку в набор токенов переводиит лексер, выдавая токены. А чтоб токены перевести в некоторую иную хуету - нужен уже парсер.
Кстати, лексер и парсер можно совместить в одной хуйне.
> паттерн матчинга не существует в плюсах(да и не помог бы он здесь)
Эта хрень:
в паттерн-матчинг вполне переводится.
Да и вообще, можно сделать
Через бустоговно (boost::spirit, boost::hana) думаю можно.
Там была хотя бы какая-то попытка сгруппировать команды по "форме" их кодирования.
Звучит как очередная либа для питона.