Skip to content

Commit

Permalink
#76 inst2RawRI -> instr2RawRI
Browse files Browse the repository at this point in the history
  • Loading branch information
c71n93 committed Dec 20, 2023
1 parent ec41f2d commit f357d34
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
6 changes: 3 additions & 3 deletions include/ChaiVM/utils/instr2Raw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ chai::bytecode_t instr2Raw(interpreter::Operation op,

chai::bytecode_t instr2Raw(interpreter::Operation op);

chai::bytecode_t inst2RawRI(interpreter::Operation op,
interpreter::RegisterId r1,
interpreter::Immidiate imm);
chai::bytecode_t instr2RawRI(interpreter::Operation op,
interpreter::RegisterId r1,
interpreter::Immidiate imm);

} // namespace chai::utils
24 changes: 16 additions & 8 deletions include/frontend/assembler/assembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,16 @@ class Assembler final {
chai::bytecode_t processI(chai::interpreter::Operation op) {
lex_.nextLexem();
if (lex_.currentLexem()->type == AsmLex::INTEGER) {
auto val = static_cast<int64_t>(static_cast<AsmLex::Int *>(lex_.currentLexem().get())->value);
auto imm = chaiFile_.addConst(std::make_unique<chai::utils::fileformat::ConstI64>(val));
auto val = static_cast<int64_t>(
static_cast<AsmLex::Int *>(lex_.currentLexem().get())->value);
auto imm = chaiFile_.addConst(
std::make_unique<chai::utils::fileformat::ConstI64>(val));
return chai::utils::instr2Raw(op, imm);
} else if (lex_.currentLexem()->type == AsmLex::FLOAT) {
auto val = static_cast<AsmLex::Float *>(lex_.currentLexem().get())->value;
auto imm = chaiFile_.addConst(std::make_unique<chai::utils::fileformat::ConstI64>(val));
auto val =
static_cast<AsmLex::Float *>(lex_.currentLexem().get())->value;
auto imm = chaiFile_.addConst(
std::make_unique<chai::utils::fileformat::ConstI64>(val));
return chai::utils::instr2Raw(op, imm);
} else if (lex_.currentLexem()->type == AsmLex::STRING) {
std::string str =
Expand All @@ -124,12 +128,16 @@ class Assembler final {
expectComma();
lex_.nextLexem();
if (lex_.currentLexem()->type == AsmLex::INTEGER) {
auto val = static_cast<int64_t>(static_cast<AsmLex::Int *>(lex_.currentLexem().get())->value);
auto imm = chaiFile_.addConst(std::make_unique<chai::utils::fileformat::ConstI64>(val));
auto val = static_cast<int64_t>(
static_cast<AsmLex::Int *>(lex_.currentLexem().get())->value);
auto imm = chaiFile_.addConst(
std::make_unique<chai::utils::fileformat::ConstI64>(val));
return chai::utils::instr2RawRI(op, regId, imm);
} else if (lex_.currentLexem()->type == AsmLex::FLOAT) {
auto val = static_cast<AsmLex::Float *>(lex_.currentLexem().get())->value;
auto imm = chaiFile_.addConst(std::make_unique<chai::utils::fileformat::ConstI64>(val));
auto val =
static_cast<AsmLex::Float *>(lex_.currentLexem().get())->value;
auto imm = chaiFile_.addConst(
std::make_unique<chai::utils::fileformat::ConstI64>(val));
return chai::utils::instr2RawRI(op, regId, imm);
} else if (lex_.currentLexem()->type == AsmLex::STRING) {
std::string str =
Expand Down
2 changes: 1 addition & 1 deletion src/ChaiVM/utils/instr2Raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ chai::bytecode_t instr2Raw(Operation op, Immidiate imm) {

chai::bytecode_t instr2Raw(Operation op) { return (operation2opcode(op)); }

chai::bytecode_t inst2RawRI(Operation op, RegisterId r1, Immidiate imm) {
chai::bytecode_t instr2RawRI(Operation op, RegisterId r1, Immidiate imm) {
return (operation2opcode(op)) | (static_cast<chai::bytecode_t>(imm) << 16) |
(r1 << 8);
}
Expand Down
2 changes: 1 addition & 1 deletion test/ChaiVM/interpreter/executor-test-fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void ExecutorTest::loadRR(chai::interpreter::Operation op,
void ExecutorTest::loadRI(chai::interpreter::Operation op,
chai::interpreter::RegisterId reg1,
chai::interpreter::Immidiate imm) {
chaiFile_.addInstr(chai::utils::inst2RawRI(op, reg1, imm));
chaiFile_.addInstr(chai::utils::instr2RawRI(op, reg1, imm));
}

int ExecutorTest::loadI(chai::interpreter::Operation op,
Expand Down
1 change: 0 additions & 1 deletion test/ChaiVM/interpreter/executor_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "executor-test-fixture.hpp"

using chai::bytecode_t;
using chai::utils::inst2RawRI;
using chai::utils::instr2Raw;
using namespace chai::interpreter;
using namespace chai::utils::fileformat;
Expand Down
6 changes: 3 additions & 3 deletions test/ChaiVM/interpreter/simple-programs-executor-test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "executor-test-fixture.hpp"

using chai::bytecode_t;
using chai::utils::inst2RawRI;
using chai::utils::instr2Raw;
using chai::utils::instr2RawRI;
using namespace chai::interpreter;
using namespace chai::utils::fileformat;

Expand Down Expand Up @@ -82,8 +82,8 @@ TEST_F(ExecutorTest, Factorial) {
UINT16_MAX, "factorial", "(I)I",
std::vector<bytecode_t>{
instr2Raw(Ldra, 7, 0), // val2
inst2RawRI(If_icmpne, one,
static_cast<Immidiate>(3 * sizeof(bytecode_t))),
instr2RawRI(If_icmpne, one,
static_cast<Immidiate>(3 * sizeof(bytecode_t))),
instr2Raw(Ldia, one), instr2Raw(Ret), instr2Raw(Star, 2, 0),
instr2Raw(Subi, one), instr2Raw(Star, 7, 0),
instr2Raw(Call, func_ref), instr2Raw(Mul, 2, 0),
Expand Down

0 comments on commit f357d34

Please sign in to comment.