Skip to content

Commit d4c18a8

Browse files
AlexeiAlexei
Alexei
authored and
Alexei
committed
lc3sim_cpp: Add types.h, 32bit version, and regress test.
1 parent dfb8926 commit d4c18a8

File tree

8 files changed

+44
-11
lines changed

8 files changed

+44
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ project(lc3
66
add_subdirectory(lcc-1.3)
77
add_subdirectory(lc3tools)
88
add_subdirectory(lc3sim-c)
9+
add_subdirectory(lc3sim_cpp)
910

1011
enable_testing()
1112
add_subdirectory(test)

lc3sim_cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(SOURCES
2929
${CMAKE_CURRENT_BINARY_DIR}/lc3os.c
3030
${CMAKE_CURRENT_BINARY_DIR}/lc3os32.c
3131
lc3sim.h
32+
types.h
3233
instr_config.h
3334
lc3sim.cpp
3435
)

lc3sim_cpp/lc3sim.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ static uint16_t Swap16(uint16_t val) {
2828
}
2929
#endif
3030

31-
#define LC3_SIGN_BIT_INDEX (sizeof(LC3_Sim::RegType) * 8 - 1)
32-
#define LC3_STATUS_BIT_INDEX (sizeof(LC3_Sim::RegType) * 8 - 1)
33-
3431
#define SING_BIT (1 << LC3_SIGN_BIT_INDEX)
3532
#define STATUS_BIT (1 << LC3_STATUS_BIT_INDEX)
3633

lc3sim_cpp/lc3sim.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// Copyright 2020 by Alexei Bezborodov <[email protected]>
22
#pragma once
33

4-
#include <stdint.h>
4+
#include <types.h>
55

66
namespace LC3_Sim
77
{
88

99
typedef char Char;
1010
typedef bool Bool;
11-
typedef uint16_t RegType;
12-
typedef uint32_t RegNumType;
13-
typedef uint32_t InstructionIndex;
14-
typedef RegType AddressType;
11+
typedef unsigned int RegNumType;
12+
typedef unsigned int InstructionIndex;
13+
typedef LC3_Sim::LC3_RegisterType RegType;
14+
typedef LC3_Sim::LC3MemAddressType AddressType;
1515

1616
class IInputOutput
1717
{

lc3sim_cpp/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class SimpleVM: public LC3_Sim::IVirtualMemory
5858
public:
5959
SimpleVM()
6060
{
61-
m_Memory.resize(65536);
61+
m_Memory.resize(LC3_MAX_MEMORY_ADDRESS);
6262
}
6363

6464
virtual LC3_Sim::IVirtualMemory::Result Read(LC3_Sim::RegType* a_Value, LC3_Sim::AddressType a_Address) const override
@@ -106,11 +106,11 @@ int main(int argc, const char* argv[])
106106
break;
107107

108108
case LC3_Sim::Processor::lrFileNotFound:
109-
printf("%s: Failed to load input\n", argv[0]);
109+
printf("%s: Failed to load input.\n", argv[0]);
110110
return 1;
111111

112112
case LC3_Sim::Processor::lrFileTooLarge:
113-
printf("%s: Failed to load input: Input exceeded memory space\n", argv[0]);
113+
printf("%s: Failed to load input: Input exceeded memory space.\n", argv[0]);
114114
return 1;
115115
}
116116

lc3sim_cpp/types.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2020 by Alexei Bezborodov <[email protected]>
2+
3+
#pragma once
4+
5+
#include <stdint.h>
6+
7+
namespace LC3_Sim
8+
{
9+
10+
#ifdef LC3_32BIT
11+
12+
typedef uint32_t LC3_RegisterType;
13+
typedef uint32_t LC3MemAddressType;
14+
15+
#define LC3_MAX_MEMORY_ADDRESS (2*UINT16_MAX) // may be up to UINT32_MAX
16+
17+
#else // LC3_16BIT
18+
19+
typedef uint16_t LC3_RegisterType;
20+
typedef uint16_t LC3MemAddressType;
21+
22+
#define LC3_MAX_MEMORY_ADDRESS UINT16_MAX
23+
24+
#endif
25+
26+
#define LC3_SIGN_BIT_INDEX (sizeof(LC3_Sim::LC3_RegisterType) * 8 - 1)
27+
#define LC3_STATUS_BIT_INDEX (sizeof(LC3_Sim::LC3_RegisterType) * 8 - 1)
28+
29+
} // namespace LC3_Sim

test/TestFunc.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ set(LC3SIM ${INSTALL_DIR}/lc3sim)
77
set(LC3SIM_C16 ${INSTALL_DIR}/lc3sim-c16)
88
set(LC3SIM_C32 ${INSTALL_DIR}/lc3sim-c32)
99

10+
set(LC3SIM_CPP16 ${INSTALL_DIR}/lc3sim_cpp16)
11+
set(LC3SIM_CPP32 ${INSTALL_DIR}/lc3sim_cpp32)
12+
1013
set(CORRECT_EXE ${CMAKE_CURRENT_SOURCE_DIR}/../correct_obj_file)
1114
set(CORRECT32_EXE ${CMAKE_CURRENT_SOURCE_DIR}/../correct_obj32_file)
1215

test/regress/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ foreach (index RANGE 0 ${obj_16bit_file_count})
148148
list(FIND exclude_src_files_for_lc3sim_c ${cur_src_file} find_src_file)
149149
if (${find_src_file} EQUAL -1)
150150
AndRegressTest(${LC3SIM_C16} ${cur_obj_file} ${cur_src_file} "sim16" ${DEFAULT_OUT} ${TYPE_OUT_STDOUT})
151+
AndRegressTest(${LC3SIM_CPP16} ${cur_obj_file} ${cur_src_file} "sim_cpp16" ${DEFAULT_OUT} ${TYPE_OUT_STDOUT})
151152
endif()
152153

153154
list(FIND exclude_src_files_for_lc3sim ${cur_src_file} find_src_file)
@@ -176,5 +177,6 @@ foreach (index RANGE 0 ${obj_32bit_file_count})
176177
list(FIND exclude_src_files_for_lc3sim_c32 ${cur_src_file} find_src_file)
177178
if (${find_src_file} EQUAL -1)
178179
AndRegressTest(${LC3SIM_C32} ${cur_obj_file} ${cur_src_file} "sim32" ${DEFAULT_OUT} ${TYPE_OUT_STDOUT})
180+
AndRegressTest(${LC3SIM_CPP32} ${cur_obj_file} ${cur_src_file} "sim_cpp32" ${DEFAULT_OUT} ${TYPE_OUT_STDOUT})
179181
endif()
180182
endforeach()

0 commit comments

Comments
 (0)