Website Summary Files Commits Branches @commit @diff @stats
path: root / src / asm / bytecode.cpp
diff options
context:
space:
mode:
Commit6e19bb560d474736d45f5be011ff0830c7019991 (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-05 23:34:00 +0200
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-05 23:34:00 +0200
Files42d29cf1c4e6a535ba526f434debaac3a70df2c6 /src/asm/bytecode.cpp
IPL-6e19bb560d474736d45f5be011ff0830c7019991.tar
IPL-6e19bb560d474736d45f5be011ff0830c7019991.tar.gz
IPL-6e19bb560d474736d45f5be011ff0830c7019991.zip
Squashed 'spasm/' content from commit 08ee95d
git-subtree-dir: spasm git-subtree-split: 08ee95d89054ba0d33697d613799a0a013aedf89
1 files changed, 74 insertions, 0 deletions
-rw-r--r--src/asm/bytecode.cpp74
diff --git a/src/asm/bytecode.cpp b/src/asm/bytecode.cpp
new file mode 100644
index 0000000..27fed2b
--- /dev/null
+++ b/src/asm/bytecode.cpp
@@ -0,0 +1,74 @@
+#include <fstream>
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include "bytecode.hpp"
+
+namespace SpasmImpl
+{
+namespace ASM
+{
+Bytecode_Stream::~Bytecode_Stream() {}
+
+Bytecode_File::Bytecode_File(const std::string& filename)
+ : _bytecode(filename.c_str(), std::ios_base::out | std::ios_base::binary)
+{
+}
+
+void Bytecode_File::push_byte(Bytecode_Stream::byte byte)
+{
+ _bytecode.put(byte);
+}
+
+void Bytecode_File::push_opcode(Bytecode_Stream::Opcode_t opcode)
+{
+ push_byte(opcode);
+}
+
+void Bytecode_File::push_integer(int number)
+{
+ for (size_t i = 0; i < sizeof(int); ++i)
+ push_byte((number >> (i << 3)) & 0xff);
+}
+
+void Bytecode_Memory::push_byte(Bytecode_Stream::byte byte)
+{
+ _bytecode.push_back(byte);
+}
+
+void Bytecode_Memory::push_opcode(Bytecode_Stream::Opcode_t opcode)
+{
+ push_byte(opcode);
+}
+
+void Bytecode_Memory::push_integer(int number)
+{
+ for (size_t i = 0; i < sizeof(int); ++i)
+ push_byte((number >> (i << 3)) & 0xff);
+}
+
+void Bytecode_Memory::set_location(size_t index, size_t location)
+{
+ for (size_t i = 0; i < sizeof(size_t); ++i)
+ _bytecode.at(index + i) = ((location >> (i << 3)) & 0xff);
+}
+
+void Bytecode_Memory::push_location(size_t location)
+{
+ for (size_t i = 0; i < sizeof(size_t); ++i)
+ _bytecode.push_back((location >> (i << 3)) & 0xff);
+}
+
+const Bytecode_Memory::Bytecode& Bytecode_Memory::bytecode() const
+{
+ return _bytecode;
+}
+
+size_t Bytecode_Memory::size() const
+{
+ return _bytecode.size();
+}
+
+} // namespace ASM
+} // namespace SpasmImpl