aboutsummaryrefslogtreecommitdiff
path: root/asm
diff options
context:
space:
mode:
Diffstat (limited to 'asm')
-rw-r--r--asm/base.cpp32
-rw-r--r--asm/base.hpp20
-rw-r--r--asm/main.cpp19
3 files changed, 53 insertions, 18 deletions
diff --git a/asm/base.cpp b/asm/base.cpp
new file mode 100644
index 0000000..d2812f1
--- /dev/null
+++ b/asm/base.cpp
@@ -0,0 +1,32 @@
+/* Copyright (C) 2024 Aryadev Chavali
+
+ * You may distribute and modify this code under the terms of the GPLv2
+ * license. You should have received a copy of the GPLv2 license with
+ * this file. If not, please write to: aryadev@aryadevchavali.com.
+
+ * Created: 2024-04-14
+ * Author: Aryadev Chavali
+ * Description:
+ */
+
+#include "./base.hpp"
+
+#include <cstdio>
+
+std::optional<std::string> read_file(const char *filename)
+{
+ FILE *fp = fopen(filename, "rb");
+ if (fp)
+ {
+ std::string contents;
+ fseek(fp, 0, SEEK_END);
+ contents.resize(ftell(fp));
+ rewind(fp);
+ fread(&contents[0], 1, contents.size(), fp);
+ fclose(fp);
+
+ return contents;
+ }
+ else
+ return std::nullopt;
+}
diff --git a/asm/base.hpp b/asm/base.hpp
new file mode 100644
index 0000000..b956028
--- /dev/null
+++ b/asm/base.hpp
@@ -0,0 +1,20 @@
+/* Copyright (C) 2024 Aryadev Chavali
+
+ * You may distribute and modify this code under the terms of the GPLv2
+ * license. You should have received a copy of the GPLv2 license with
+ * this file. If not, please write to: aryadev@aryadevchavali.com.
+
+ * Created: 2024-04-14
+ * Author: Aryadev Chavali
+ * Description: Base library
+ */
+
+#ifndef BASE_HPP
+#define BASE_HPP
+
+#include <optional>
+#include <string>
+
+std::optional<std::string> read_file(const char *);
+
+#endif
diff --git a/asm/main.cpp b/asm/main.cpp
index 51600cb..be26426 100644
--- a/asm/main.cpp
+++ b/asm/main.cpp
@@ -20,28 +20,11 @@
#include <lib/inst.h>
+#include "./base.hpp"
#include "./lexer.hpp"
using std::pair, std::string, std::string_view, std::vector;
-std::optional<string> read_file(const char *filename)
-{
- FILE *fp = fopen(filename, "rb");
- if (fp)
- {
- string contents;
- fseek(fp, 0, SEEK_END);
- contents.resize(ftell(fp));
- rewind(fp);
- fread(&contents[0], 1, contents.size(), fp);
- fclose(fp);
-
- return contents;
- }
- else
- return std::nullopt;
-}
-
void usage(const char *program_name, FILE *fp)
{
fprintf(fp,