> {
313 | static constexpr bool val = true;
314 | };
315 |
316 | template
317 | struct is_instruction> {
318 | static constexpr bool val = true;
319 | };
320 |
321 | template
322 | struct is_instruction> {
323 | static constexpr bool val = true;
324 | };
325 |
326 | template
327 | struct is_instruction> {
328 | static constexpr bool val = true;
329 | };
330 |
331 | template
332 | struct is_instruction> {
333 | static constexpr bool val = true;
334 | };
335 |
336 | template
337 | struct is_instruction> {
338 | static constexpr bool val = true;
339 | };
340 |
341 | template
342 | struct is_instruction> {
343 | static constexpr bool val = true;
344 | };
345 |
346 | template
347 | struct is_instruction> {
348 | static constexpr bool val = true;
349 | };
350 |
351 | template
352 | struct is_instruction> {
353 | static constexpr bool val = true;
354 | };
355 |
356 | template
357 | struct is_instruction> {
358 | static constexpr bool val = true;
359 | };
360 |
361 | template
362 | struct is_instruction> {
363 | static constexpr bool val = true;
364 | };
365 |
366 | template
367 | struct is_instruction> {
368 | static constexpr bool val = true;
369 | };
370 |
371 |
372 | template
373 | struct is_instruction> {
374 | static constexpr bool val = true;
375 | };
376 |
377 | template
378 | struct is_instruction> {
379 | static constexpr bool val = true;
380 | };
381 |
382 | template
383 | struct is_instruction> {
384 | static constexpr bool val = true;
385 | };
386 |
387 | template
388 | struct is_instruction> {
389 | static constexpr bool val = true;
390 | };
391 |
392 | template
393 | struct is_instruction> {
394 | static constexpr bool val = true;
395 | };
396 |
397 | template
398 | struct is_instruction> {
399 | static constexpr bool val = true;
400 | };
401 |
402 | template
403 | struct is_instruction> {
404 | static constexpr bool val = true;
405 | };
406 |
407 | template
408 | struct is_instruction> {
409 | static constexpr bool val = true;
410 | };
411 |
412 | template
413 | struct is_instruction> {
414 | static constexpr bool val = true;
415 | };
416 |
417 | template
418 | struct is_instruction> {
419 | static constexpr bool val = true;
420 | };
421 |
422 | /**
423 | * Concept declaring an Instruction, that is one of the types listed above.
424 | * @tparam T the type to check
425 | */
426 | template
427 | concept Instruction = is_instruction::val;
428 |
429 | #endif //TEMPLATE_CPU_INSTRUCTION_DEF_HPP
430 |
--------------------------------------------------------------------------------
/instruction_util.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * @file instruction_util.hpp
3 | * @author paul
4 | * @date 04.06.20
5 | * Definition of utility structs for the implementation of instructions.
6 | */
7 | #ifndef TEMPLATE_CPU_INSTRUCTION_UTIL_HPP
8 | #define TEMPLATE_CPU_INSTRUCTION_UTIL_HPP
9 |
10 | #include
11 |
12 | /**
13 | * Get the next program counter used for conditional jumps.
14 | * @tparam cond if the bool is false pc+1 is returned, else target is returned
15 | * @tparam PC the program counter for the if case
16 | * @tparam target the program counter for the else case
17 | */
18 | template
19 | struct GetTarget {
20 | static constexpr std::size_t val = PC+1;
21 | };
22 |
23 | /**
24 | * Specialization for GetTarget if cond==true
25 | */
26 | template
27 | struct GetTarget {
28 | static constexpr std::size_t val = target;
29 | };
30 |
31 | /**
32 | * Struct for implementing a division with exception if the result is undefined
33 | * @tparam T the type of the operands
34 | * @tparam a the numerator
35 | * @tparam b the denominator
36 | */
37 | template
38 | struct DivWithException {
39 | static_assert(b != 0, "Division by zero!");
40 | static constexpr auto val = a / b;
41 | };
42 |
43 |
44 | #endif //TEMPLATE_CPU_INSTRUCTION_UTIL_HPP
45 |
--------------------------------------------------------------------------------
/instructions.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * @file instructions.hpp
3 | * @author paul
4 | * @date 25.05.20
5 | * Implementation of all instructions.
6 | */
7 | #ifndef TEMPLATE_CPU_INSTRUCTIONS_HPP
8 | #define TEMPLATE_CPU_INSTRUCTIONS_HPP
9 |
10 | #include "config.hpp"
11 | #include "cpu_types.hpp"
12 | #include "instruction_def.hpp"
13 | #include "instruction_util.hpp"
14 |
15 | /**
16 | * Struct used for implementing the different instructions
17 | * @tparam instr the Instruction to execute
18 | * @tparam registers the registers at the start of the execution
19 | * @tparam memory the memory at the start of the execution
20 | * @tparam old_pc the program counter at the start of the execution
21 | */
22 | template
23 | struct InstrImpl {};
24 |
25 | template
26 | struct InstrImpl