-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassembly_segment_test.cc
More file actions
58 lines (44 loc) · 1.86 KB
/
assembly_segment_test.cc
File metadata and controls
58 lines (44 loc) · 1.86 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "gtest/gtest.h"
#include "gmock/gmock-matchers.h"
#include "assembly_segment.h"
#include <memory>
#include <iostream>
#include <fstream>
namespace gnossen {
namespace assembly {
namespace {
static std::string artifact_path(const std::string& filename) {
std::string extra_artifacts_dir(getenv("TEST_UNDECLARED_OUTPUTS_DIR"));
return extra_artifacts_dir + "/" + filename;
}
TEST(AssemblySegmentTest, CanBuild) {
// Matches "a*b".
AssemblySubroutine subroutine;
subroutine.add_segment(std::move(std::make_unique<StackManagementSegment>(0)));
subroutine.add_segment(std::move(std::make_unique<NoOp>(1)));
subroutine.add_segment(std::move(
std::make_unique<ConsumingMatchNonConsumingNonMatch>(2, 'a', 2)));
subroutine.add_segment(std::move(
std::make_unique<ConsumingMatchElse>(3, 'b', 5)));
subroutine.add_segment(std::move(std::make_unique<SuccessSegment>(4)));
subroutine.add_segment(std::move(std::make_unique<FailureSegment>(5)));
subroutine.finalize();
std::cerr << subroutine.debug_string();
std::ofstream asm_file(artifact_path("regex1.S"), std::ofstream::out);
asm_file << subroutine.debug_string();
uint8_t* code = new uint8_t[subroutine.size()];
subroutine.write_code(code);
std::string binary_path = artifact_path("regex1.bin");
std::ofstream binfile(binary_path, std::ofstream::binary);
binfile.write((char*)code, subroutine.size());
delete [] code;
}
// TODO: Add test for `write_code`.
// I don't know that I actually want to write a test for just the
// assembly_segment file. Since it's so coupled to everything else, it doesn't
// feel particularly useful. This test exists as an aid for me to ensure that
// I'm writing something that functions before getting to the end stage. I'll
// probably delete this after I've written my end-to-end level test.
}
} // end namespace assembly
} // end namespace gnossen