summaryrefslogtreecommitdiffhomepage
path: root/asm/arm/main.cpp
blob: 20e67abfde60159149add74e6513ba0501e8c026 (plain)
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
#include <iostream>
#include <stdexcept>

#include <fmt/format.h>

#include <libreichwein/file.h>

#include "assembler.h"
#include "instruction.h"

void dump(const code_sequence& c)
{
 for (size_t i = 0; i < c.size(); ++i) {
  if ((i % 16) == 0) {
   if (i > 0)
    std::cout << std::endl;
  } else {
   std::cout << " ";
  }
  std::cout << fmt::format("{:02x}", c[i]);
 }
 std::cout << std::endl;
}

int main(int argc, char* argv[])
{
 try {
  if (argc == 2) {
   Assembler assembler;
   std::string source {Reichwein::File::getFile(argv[1])};
   code_sequence result {assembler.encode(source)};
   dump(result);
  }
  return 0;
 } catch (const std::exception& ex) {
  std::cerr << "Error: " << ex.what() << std::endl;
  return 1;
 }
 return 2;
}