summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--asm/assembler.cpp10
-rw-r--r--asm/assembler.h6
-rw-r--r--asm/chunk.h2
-rw-r--r--test-asm.cpp7
4 files changed, 20 insertions, 5 deletions
diff --git a/asm/assembler.cpp b/asm/assembler.cpp
index 7a9f6cf..d6ab230 100644
--- a/asm/assembler.cpp
+++ b/asm/assembler.cpp
@@ -49,3 +49,13 @@ std::shared_ptr<Op> makeOp(const std::string& mnemonic)
AsmArgs dummy; // empty list of arguments
return makeOp(mnemonic, dummy);
}
+
+std::shared_ptr<Label> makeLabel(const std::string& name)
+{
+ return std::make_shared<Label>(name);
+}
+
+std::shared_ptr<Data> makeData(const std::vector<uint8_t>& data)
+{
+ return std::make_shared<Data>(data);
+}
diff --git a/asm/assembler.h b/asm/assembler.h
index 42b5f8d..ddea4af 100644
--- a/asm/assembler.h
+++ b/asm/assembler.h
@@ -1,7 +1,6 @@
#pragma once
-//#include "chunk.h"
-//#include "segment.h"
+#include "chunk.h"
#include <any>
#include <functional>
@@ -23,6 +22,9 @@ std::shared_ptr<Op> makeOp(const std::string& mnemonic, AsmArgs& args);
// overload for empty list of arguments
std::shared_ptr<Op> makeOp(const std::string& mnemonic);
+std::shared_ptr<Label> makeLabel(const std::string& name);
+std::shared_ptr<Data> makeData(const std::vector<uint8_t>& data);
+
template<typename T>
std::string mangleNameOne(const std::string& s)
{
diff --git a/asm/chunk.h b/asm/chunk.h
index 723e711..cc45ea9 100644
--- a/asm/chunk.h
+++ b/asm/chunk.h
@@ -29,7 +29,7 @@ private:
class Data: public Chunk
{
public:
- Data(std::vector<uint8_t> data): m_data(data) {}
+ Data(const std::vector<uint8_t>& data): m_data(data) {}
virtual ~Data(){}
std::vector<uint8_t> getCode() override
diff --git a/test-asm.cpp b/test-asm.cpp
index 882f998..50e4112 100644
--- a/test-asm.cpp
+++ b/test-asm.cpp
@@ -82,11 +82,14 @@ TEST_F(AsmTest, Intel64_ret) {
TEST_F(AsmTest, Intel64_multiple) {
Segment segment;
+
segment.push_back(makeOp("nop"));
AsmArgs args{{Immediate8(5)}};
segment.push_back(makeOp("int", args));
segment.push_back(makeOp("ret"));
+ segment.push_back(makeLabel("data1"));
+ segment.push_back(makeData({1, 2, 3}));
- ASSERT_EQ(segment.size(), 3);
- ASSERT_EQ(segment.getCode(), std::vector<uint8_t>({0x90, 0xCD, 0x05, 0xC3}));
+ ASSERT_EQ(segment.size(), 5);
+ ASSERT_EQ(segment.getCode(), std::vector<uint8_t>({0x90, 0xCD, 0x05, 0xC3, 0x01, 0x02, 0x03}));
}