• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rieske / trans / 28379938466

29 Jun 2026 02:35PM UTC coverage: 90.44% (-0.2%) from 90.635%
28379938466

push

github

web-flow
Merge pull request #41 from rieske/feature/file-scope-globals

Add file-scope global variables

300 of 358 new or added lines in 19 files covered. (83.8%)

8 existing lines in 2 files now uncovered.

5052 of 5586 relevant lines covered (90.44%)

242657.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

39.82
/src/codegen/ATandTInstructionSet.cpp
1
#include "ATandTInstructionSet.h"
2

3
#include "Register.h"
4
#include "MemoryOperand.h"
5

6
#include <stdexcept>
7

8
namespace {
9

10
using codegen::Register;
11

12
std::string memoryOffsetMnemonic(const Register& memoryBase, int memoryOffset) {
56✔
13
    return (memoryOffset ? "-" + std::to_string(memoryOffset) : "") + "(%" + memoryBase.getName() + ")";
112✔
14
}
15

16
std::string memoryReference(const codegen::MemoryOperand& operand) {
56✔
17
    if (operand.isGlobal()) {
56✔
NEW
18
        throw std::runtime_error { "not implemented ATandTInstructionSet: global variable operand" };
×
19
    }
20
    return memoryOffsetMnemonic(operand.baseRegister(), operand.offset());
56✔
21
}
22

23
std::string registerAccess(const Register& reg) {
216✔
24
    return "%" + reg.getName();
216✔
25
}
26

27
std::string constantReference(int constant) {
16✔
28
   return "$" + std::to_string(constant);
16✔
29
}
30

31
}
32

33
namespace codegen {
34

35
ATandTInstructionSet::~ATandTInstructionSet() = default;
66✔
36

37
std::string ATandTInstructionSet::preamble(const std::map<std::string, std::string>& constants,
2✔
38
        const std::vector<GlobalVariable>& globalVariables) const {
39
    (void)constants;
40
    (void)globalVariables;
41
    return ".extern scanf\n"
42
            ".extern printf\n\n"
43
            ".data\n"
44
            "sfmt: .string \"%d\"\n"
45
            "fmt: .string \"%d\n\"\n\n"
46
            ".text\n"
47
            ".globl main\n\n";
4✔
48
}
49

50
std::string ATandTInstructionSet::call(std::string procedureName) const {
10✔
51
    return "call " + procedureName;
10✔
52
}
53

54
std::string ATandTInstructionSet::push(const Register& reg) const {
62✔
55
    return "pushq " + registerAccess(reg);
62✔
56
}
57

58
std::string ATandTInstructionSet::pop(const Register& reg) const {
10✔
59
    return "popq " + registerAccess(reg);
10✔
60
}
61

62
std::string ATandTInstructionSet::add(const Register& reg, int constant) const {
2✔
63
    return "addq " + constantReference(constant) + ", " + registerAccess(reg);
2✔
64
}
65

66
std::string ATandTInstructionSet::sub(const Register& reg, int constant) const {
14✔
67
    return "subq " + constantReference(constant) + ", " + registerAccess(reg);
14✔
68
}
69

NEW
70
std::string ATandTInstructionSet::lea(const MemoryOperand& source, const Register& target) const {
×
NEW
71
    throw std::runtime_error { "not implemented ATandTInstructionSet::lea" };
×
72
}
73

74
std::string ATandTInstructionSet::not_(const Register& reg) const {
×
75
    throw std::runtime_error { "not implemented ATandTInstructionSet::not_(const Register& reg)" };
×
76
}
77

78
std::string ATandTInstructionSet::mov(const Register& source, const MemoryOperand& destination) const {
22✔
79
    return "movq " + registerAccess(source) + ", " + memoryReference(destination);
22✔
80
}
81

82
std::string ATandTInstructionSet::mov(const Register& source, const Register& destination) const {
18✔
83
    if (&source == &destination) {
18✔
84
        return "";
×
85
    }
86
    return "movq " + registerAccess(source) + ", " + registerAccess(destination);
18✔
87
}
88

89
std::string ATandTInstructionSet::mov(const MemoryOperand& source, const Register& destination) const {
26✔
90
    return "movq " + memoryReference(source) + ", " + registerAccess(destination);
26✔
91
}
92

NEW
93
std::string ATandTInstructionSet::mov(std::string constant, const MemoryOperand& destination) const {
×
NEW
94
    throw std::runtime_error { "not implemented ATandTInstructionSet::mov(std::string constant, MemoryOperand)" };
×
95
}
96

97
std::string ATandTInstructionSet::mov(std::string constant, const Register& destination) const {
×
98
    throw std::runtime_error { "not implemented ATandTInstructionSet::mov(std::string constant, const Register& destination)" };
×
99
}
100

NEW
101
std::string ATandTInstructionSet::cmp(const Register& leftArgument, const MemoryOperand& rightArgument) const {
×
NEW
102
    throw std::runtime_error { "not implemented ATandTInstructionSet::cmp(Register, MemoryOperand)" };
×
103
}
104

105
std::string ATandTInstructionSet::cmp(const Register& leftArgument, const Register& rightArgument) const {
×
106
    throw std::runtime_error { "not implemented ATandTInstructionSet::cmp(const Register& leftArgument, const Register& rightArgument)" };
×
107
}
108

NEW
109
std::string ATandTInstructionSet::cmp(const MemoryOperand& leftArgument, const Register& rightArgument) const {
×
NEW
110
    throw std::runtime_error { "not implemented ATandTInstructionSet::cmp(MemoryOperand, Register)" };
×
111
}
112

113
std::string ATandTInstructionSet::cmp(const Register& argument, int constant) const {
×
114
    throw std::runtime_error { "not implemented ATandTInstructionSet::cmp(const Register& argument, int constant)" };
×
115
}
116

NEW
117
std::string ATandTInstructionSet::cmp(const MemoryOperand& leftArgument, int constant) const {
×
NEW
118
    throw std::runtime_error { "not implemented ATandTInstructionSet::cmp(MemoryOperand, int constant)" };
×
119
}
120

121
std::string ATandTInstructionSet::label(std::string name) const {
10✔
122
    return name + ":";
10✔
123
}
124

125
std::string ATandTInstructionSet::jmp(std::string label) const {
×
126
    throw std::runtime_error { "not implemented ATandTInstructionSet::jmp(std::string label)" };
×
127
}
128

129
std::string ATandTInstructionSet::je(std::string label) const {
×
130
    throw std::runtime_error { "not implemented ATandTInstructionSet::je(std::string label)" };
×
131
}
132

133
std::string ATandTInstructionSet::jne(std::string label) const {
×
134
    throw std::runtime_error { "not implemented ATandTInstructionSet::jne(std::string label)" };
×
135
}
136

137
std::string ATandTInstructionSet::jg(std::string label) const {
×
138
    throw std::runtime_error { "not implemented ATandTInstructionSet::jg(std::string label)" };
×
139
}
140

141
std::string ATandTInstructionSet::jl(std::string label) const {
×
142
    throw std::runtime_error { "not implemented ATandTInstructionSet::jl(std::string label)" };
×
143
}
144

145
std::string ATandTInstructionSet::jge(std::string label) const {
×
146
    throw std::runtime_error { "not implemented ATandTInstructionSet::jge(std::string label)" };
×
147
}
148

149
std::string ATandTInstructionSet::jle(std::string label) const {
×
150
    throw std::runtime_error { "not implemented ATandTInstructionSet::jle(std::string label)" };
×
151
}
152

153
std::string ATandTInstructionSet::syscall() const {
×
154
    throw std::runtime_error { "not implemented ATandTInstructionSet::syscall()" };
×
155
}
156

157
std::string ATandTInstructionSet::leave() const {
4✔
158
    return "leave";
8✔
159
}
160

161
std::string ATandTInstructionSet::ret() const {
4✔
162
    return "ret";
8✔
163
}
164

165
std::string ATandTInstructionSet::xor_(const Register& operand, const Register& result) const {
10✔
166
    return "xorq " + registerAccess(operand) + ", " + registerAccess(result);
10✔
167
}
168

NEW
169
std::string ATandTInstructionSet::xor_(const MemoryOperand& operand, const Register& result) const {
×
NEW
170
    throw std::runtime_error { "not implemented ATandTInstructionSet::xor_(MemoryOperand, Register)" };
×
171
}
172

173
std::string ATandTInstructionSet::or_(const Register& operand, const Register& result) const {
×
174
    throw std::runtime_error { "not implemented ATandTInstructionSet::or_(const Register& operand, const Register& result)" };
×
175
}
176

NEW
177
std::string ATandTInstructionSet::or_(const MemoryOperand& operand, const Register& result) const {
×
NEW
178
    throw std::runtime_error { "not implemented ATandTInstructionSet::or_(MemoryOperand, Register)" };
×
179
}
180

181
std::string ATandTInstructionSet::and_(const Register& operand, const Register& result) const {
×
182
    throw std::runtime_error { "not implemented ATandTInstructionSet::and_(const Register& operand, const Register& result)" };
×
183
}
184

NEW
185
std::string ATandTInstructionSet::and_(const MemoryOperand& operand, const Register& result) const {
×
NEW
186
    throw std::runtime_error { "not implemented ATandTInstructionSet::and_(MemoryOperand, Register)" };
×
187
}
188

189
std::string ATandTInstructionSet::shl(const Register& result) const {
×
190
    throw std::runtime_error {
191
        "not implemented ATandTInstructionSet::shl(const Register& operand, const Register& result)"
192
    };
×
193
}
194

195
//std::string ATandTInstructionSet::shl(std::string constant, const Register& result) const {
196
//}
197

198
std::string ATandTInstructionSet::shr(const Register& result) const {
×
199
    throw std::runtime_error {
200
        "not implemented ATandTInstructionSet::shr(const Register& operand, const Register& result)"
201
    };
×
202
}
203

204
//std::string ATandTInstructionSet::shr(std::string constant, const Register& result) const {
205
//}
206

207
std::string ATandTInstructionSet::add(const Register& operand, const Register& result) const {
4✔
208
    return "addq " + registerAccess(operand) + ", " + registerAccess(result); // result = result + operand
4✔
209
}
210

211
std::string ATandTInstructionSet::add(const MemoryOperand& operand, const Register& result) const {
4✔
212
    return "addq " + memoryReference(operand) + ", " + registerAccess(result);
4✔
213
}
214

215
std::string ATandTInstructionSet::sub(const Register& operand, const Register& result) const {
4✔
216
    return "subq " + registerAccess(operand) + ", " + registerAccess(result); // result = result - operand
4✔
217
}
218

219
std::string ATandTInstructionSet::sub(const MemoryOperand& operand, const Register& result) const {
4✔
220
    return "subq " + memoryReference(operand) + ", " + registerAccess(result);
4✔
221
}
222

223
std::string ATandTInstructionSet::imul(const Register& operand) const {
×
224
    throw std::runtime_error { "not implemented ATandTInstructionSet::imul(const Register& operand)" };
×
225
}
226

NEW
227
std::string ATandTInstructionSet::imul(const MemoryOperand& operand) const {
×
NEW
228
    throw std::runtime_error { "not implemented ATandTInstructionSet::imul(MemoryOperand)" };
×
229
}
230

231
std::string ATandTInstructionSet::idiv(const Register& operand) const {
×
232
    throw std::runtime_error { "not implemented ATandTInstructionSet::idiv(const Register& operand)" };
×
233
}
234

NEW
235
std::string ATandTInstructionSet::idiv(const MemoryOperand& operand) const {
×
NEW
236
    throw std::runtime_error { "not implemented ATandTInstructionSet::idiv(MemoryOperand)" };
×
237
}
238

239
std::string ATandTInstructionSet::inc(const Register& operand) const {
×
240
    throw std::runtime_error { "not implemented ATandTInstructionSet::inc(const Register& operand)" };
×
241
}
242

NEW
243
std::string ATandTInstructionSet::inc(const MemoryOperand& operand) const {
×
NEW
244
    throw std::runtime_error { "not implemented ATandTInstructionSet::inc(MemoryOperand)" };
×
245
}
246

247
std::string ATandTInstructionSet::dec(const Register& operand) const {
×
248
    throw std::runtime_error { "not implemented ATandTInstructionSet::dec(const Register& operand)" };
×
249
}
250

NEW
251
std::string ATandTInstructionSet::dec(const MemoryOperand& operand) const {
×
NEW
252
    throw std::runtime_error { "not implemented ATandTInstructionSet::dec(MemoryOperand)" };
×
253
}
254

255
std::string ATandTInstructionSet::neg(const Register& operand) const {
×
256
    throw std::runtime_error { "not implemented ATandTInstructionSet::neg(const Register& operand)" };
×
257
}
258

259
} // namespace codegen
260

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc