-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_call_asm.cpp
81 lines (80 loc) · 2.35 KB
/
gen_call_asm.cpp
1
2
3
4
5
6
7
8
9
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
#include <iostream>
#include <fstream>
#include "insn.h"
std::string input_path = "bytecode/bytecode.txt";
std::string output_path = "call_exec.s";
int main(int argc, char *argv[])
{
if (argc > 1)
input_path = argv[1];
std::ifstream infile(input_path);
if (!infile)
{
std::cerr << "No input file.\n";
return 1;
}
std::vector<unsigned char> bytecode;
std::string line;
while (std::getline(infile, line))
bytecode.push_back(std::stoi(line));
infile.close();
std::ofstream outfile(output_path);
outfile << " .global __Z8exec_asmv\n";
outfile << " .p2align 2\n";
outfile << "__Z8exec_asmv:\n";
outfile << " stp x29, x30, [sp, #-16]!\n";
outfile << " mov x29, sp\n";
for (auto insn : bytecode)
{
switch (insn)
{
case Insn::INT0:
outfile << " bl __Z12handler_int0v\n";
break;
case Insn::INT1:
outfile << " bl __Z12handler_int1v\n";
break;
case Insn::INT2:
outfile << " bl __Z12handler_int2v\n";
break;
case Insn::INT3:
outfile << " bl __Z12handler_int3v\n";
break;
case Insn::INT4:
outfile << " bl __Z12handler_int4v\n";
break;
case Insn::INT5:
outfile << " bl __Z12handler_int5v\n";
break;
case Insn::INT6:
outfile << " bl __Z12handler_int6v\n";
break;
case Insn::INT7:
outfile << " bl __Z12handler_int7v\n";
break;
case Insn::INT8:
outfile << " bl __Z12handler_int8v\n";
break;
case Insn::ADD:
outfile << " bl __Z11handler_addv\n";
break;
case Insn::SUB:
outfile << " bl __Z11handler_subv\n";
break;
case Insn::MUL:
outfile << " bl __Z11handler_mulv\n";
break;
case Insn::DIV:
outfile << " bl __Z11handler_divv\n";
break;
case Insn::RETURN:
outfile << " bl __Z11handler_retv\n";
outfile << " ldp x29, x30, [sp], #16\n";
outfile << " ret\n";
break;
case Insn::NOP:
outfile << " bl __Z11handler_nopv \n";
break;
}
}
}