aboutsummaryrefslogtreecommitdiff
path: root/asm/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'asm/main.cpp')
-rw-r--r--asm/main.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/asm/main.cpp b/asm/main.cpp
index c1b23b7..a168af1 100644
--- a/asm/main.cpp
+++ b/asm/main.cpp
@@ -15,6 +15,8 @@
#include <iostream>
#include <optional>
#include <string>
+#include <tuple>
+#include <vector>
#include <lib/inst.h>
@@ -53,4 +55,62 @@ int main(int argc, const char *argv[])
{
usage(argv[1], stdout);
return 0;
+ if (argc == 1 || argc > 3)
+ {
+ usage(argv[0], stderr);
+ return -1;
+ }
+ int ret = 0;
+ const char *file_name = argv[1];
+ auto file_source = read_file(file_name);
+
+ string source_str;
+ string_view original;
+ string_view src;
+ vector<token_t> tokens;
+ lerr_t lerr;
+
+ if (file_source.has_value())
+ source_str = file_source.value();
+ else
+ {
+ std::cerr << "ERROR: file `" << file_name << "` does not exist!"
+ << std::endl;
+ ret = -1;
+ goto end;
+ }
+ original = string_view{source_str};
+ src = string_view{source_str};
+ lerr = tokenise_buffer(src, tokens);
+
+ if (lerr != lerr_t::OK)
+ {
+ size_t col = 0, line = 1;
+ // TODO: Fix this UB (probably a change in API)
+ auto diff = src.begin() - original.begin();
+ for (auto i = 0; i < diff; ++i)
+ {
+ if (source_str[i] == '\n')
+ {
+ col = 0;
+ ++line;
+ }
+ else
+ ++col;
+ }
+ std::cerr << file_name << ":" << line << ":" << col << ":"
+ << lerr_as_cstr(lerr) << std::endl;
+ ret = 255 - lerr;
+ goto end;
+ }
+ else
+ {
+ for (auto token : tokens)
+ {
+ std::cout << "\t" << token << std::endl;
+ }
+ }
+
+end:
+ return ret;
}