Skip to content

Commit 2bc0f80

Browse files
authored
Add some debugging code, and parallelize ./lint.sh (#72)
This is mostly fixing some missing bits, but there are more bits missing. Most interesting is probably the change to `./lint.sh`, which now spans multiple clang-tidy processes in parallel, speeding things up drastically.
2 parents a5fbebf + 858f10f commit 2bc0f80

File tree

9 files changed

+95
-42
lines changed

9 files changed

+95
-42
lines changed

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Checks: '*,
33
-altera-id-dependent-backward-branch,
44
-altera-unroll-loops,
5+
-android-*,
56
-boost-use-ranges,
67
-bugprone-casting-through-void,
78
-bugprone-easily-swappable-parameters,
@@ -40,6 +41,7 @@ Checks: '*,
4041
-google-default-arguments,
4142
-google-global-names-in-headers,
4243
-google-readability-casting,
44+
-google-upgrade-googletest-case,
4345
-hicpp-avoid-c-arrays,
4446
-hicpp-no-array-decay,
4547
-hicpp-no-malloc,

lint.sh

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
#!/bin/sh
2-
clang-format-mp-19 -i --style=file --Werror src/*.cpp src/**/*.cpp src/**/*.h
3-
clang-tidy-mp-19 --config-file=.clang-tidy src/**/*.cpp \
4-
--fix \
2+
3+
CLANG_FORMAT="clang-format-mp-19 -i --style=file --Werror src/*.cpp src/**/*.cpp src/**/*.h"
4+
$CLANG_FORMAT
5+
6+
## The check --enable-check-profile flag gives an overview of where clang-tidy spends its time
7+
# --enable-check-profile
8+
9+
CLANG_START="clang-tidy-mp-19 --config-file=.clang-tidy"
10+
CLANG_END="--fix \
511
-- -I/opt/local/include/ -fdiagnostics-absolute-paths \
6-
-DGC_TYPE=GENERATIONAL -DUSE_TAGGING=false -DCACHE_INTEGER=false -DUNITTESTS
7-
clang-format-mp-19 -i --style=file --Werror src/*.cpp src/**/*.cpp src/**/*.h
12+
-DGC_TYPE=GENERATIONAL -DUSE_TAGGING=false -DCACHE_INTEGER=false -DUNITTESTS"
13+
14+
15+
$CLANG_START src/*.cpp $CLANG_END &
16+
$CLANG_START src/compiler/*.cpp $CLANG_END &
17+
$CLANG_START src/interpreter/*.cpp $CLANG_END &
18+
$CLANG_START src/memory/*.cpp $CLANG_END &
19+
$CLANG_START src/misc/*.cpp $CLANG_END &
20+
$CLANG_START src/primitives/*.cpp $CLANG_END &
21+
$CLANG_START src/primitivesCore/*.cpp $CLANG_END &
22+
$CLANG_START src/unitTests/*.cpp $CLANG_END &
23+
$CLANG_START src/vm/*.cpp $CLANG_END &
24+
$CLANG_START src/vmobjects/*.cpp $CLANG_END &
25+
26+
wait
27+
$CLANG_FORMAT
28+

src/Main.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,15 @@
2222
THE SOFTWARE.
2323
*/
2424

25-
#include <fstream>
25+
#include <cstdint>
2626
#include <iostream>
2727

28-
#include "compiler/ClassGenerationContext.h"
29-
#include "memory/Heap.h"
3028
#include "misc/defs.h"
29+
#include "vm/Print.h"
3130
#include "vm/Universe.h"
32-
#include "vmobjects/ObjectFormats.h"
33-
#include "vmobjects/VMArray.h"
34-
#include "vmobjects/VMMethod.h"
35-
#include "vmobjects/VMObject.h"
36-
#include "vmobjects/VMString.h"
3731

3832
int32_t main(int32_t argc, char** argv) {
39-
cout << "This is SOM++" << endl;
33+
cout << "This is SOM++" << '\n';
4034

4135
Universe::Start(argc, argv);
4236

src/compiler/Disassembler.cpp

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@ void Disassembler::DumpMethod(MethodGenerationContext* mgenc,
116116
dumpMethod(bytecodes.data(), bytecodes.size(), indent, nullptr, true);
117117
}
118118

119+
static void PrintFieldAccess(VMMethod* method, bool printObjects,
120+
uint8_t const fieldIdx) {
121+
if (method != nullptr && printObjects) {
122+
auto* holder = dynamic_cast<VMClass*>((VMObject*)method->GetHolder());
123+
if (holder != nullptr) {
124+
VMSymbol* name = holder->GetInstanceFieldName(fieldIdx);
125+
if (name != nullptr) {
126+
DebugPrint("(index: %d) field: %s\n", fieldIdx,
127+
name->GetStdString().c_str());
128+
} else {
129+
DebugPrint("(index: %d) field: !nullptr!: error!\n", fieldIdx);
130+
}
131+
} else {
132+
DebugPrint("(index: %d) block holder is not a class!!\n", fieldIdx);
133+
}
134+
} else {
135+
DebugPrint("(index: %d)\n", fieldIdx);
136+
}
137+
}
138+
119139
void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
120140
const char* indent, VMMethod* method,
121141
bool printObjects) {
@@ -152,7 +172,8 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
152172
switch (bytecode) {
153173
case BC_PUSH_0:
154174
case BC_PUSH_1:
155-
case BC_PUSH_NIL: {
175+
case BC_PUSH_NIL:
176+
case BC_RETURN_SELF: {
156177
// no more details to be printed
157178
break;
158179
}
@@ -260,26 +281,12 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
260281
case BC_POP_FIELD:
261282
case BC_PUSH_FIELD: {
262283
uint8_t const fieldIdx = bytecodes[bc_idx + 1];
263-
if (method != nullptr && printObjects) {
264-
auto* holder =
265-
dynamic_cast<VMClass*>((VMObject*)method->GetHolder());
266-
if (holder != nullptr) {
267-
VMSymbol* name = holder->GetInstanceFieldName(fieldIdx);
268-
if (name != nullptr) {
269-
DebugPrint("(index: %d) field: %s\n", fieldIdx,
270-
name->GetStdString().c_str());
271-
} else {
272-
DebugPrint("(index: %d) field: !nullptr!: error!\n",
273-
fieldIdx);
274-
}
275-
} else {
276-
DebugPrint(
277-
"(index: %d) block holder is not a class!!\n",
278-
fieldIdx);
279-
}
280-
} else {
281-
DebugPrint("(index: %d)\n", fieldIdx);
282-
}
284+
PrintFieldAccess(method, printObjects, fieldIdx);
285+
break;
286+
}
287+
case BC_POP_FIELD_1:
288+
case BC_PUSH_FIELD_1: {
289+
PrintFieldAccess(method, printObjects, 1);
283290
break;
284291
}
285292
case BC_SEND:
@@ -399,6 +406,16 @@ void Disassembler::printNth(uint8_t idx, VMFrame* frame, const char* op) {
399406
DebugPrint(">\n");
400407
}
401408

409+
void Disassembler::printConstantAccess(vm_oop_t constant, uint8_t index) {
410+
VMClass* c = CLASS_OF(constant);
411+
VMSymbol* cname = c->GetName();
412+
413+
DebugPrint("(index: %d) value: (%s) ", index,
414+
cname->GetStdString().c_str());
415+
dispatch(constant);
416+
DebugPrint("\n");
417+
}
418+
402419
/**
403420
* Dump bytecode from the frame running
404421
*/
@@ -528,13 +545,22 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method,
528545
}
529546
case BC_PUSH_CONSTANT: {
530547
vm_oop_t constant = method->GetConstant(bc_idx);
531-
VMClass* c = CLASS_OF(constant);
532-
VMSymbol* cname = c->GetName();
533-
534-
DebugPrint("(index: %d) value: (%s) ", BC_1,
535-
cname->GetStdString().c_str());
536-
dispatch(constant);
537-
DebugPrint("\n");
548+
printConstantAccess(constant, BC_1);
549+
break;
550+
}
551+
case BC_PUSH_CONSTANT_0: {
552+
vm_oop_t constant = method->GetIndexableField(0);
553+
printConstantAccess(constant, 0);
554+
break;
555+
}
556+
case BC_PUSH_CONSTANT_1: {
557+
vm_oop_t constant = method->GetIndexableField(1);
558+
printConstantAccess(constant, 1);
559+
break;
560+
}
561+
case BC_PUSH_CONSTANT_2: {
562+
vm_oop_t constant = method->GetIndexableField(2);
563+
printConstantAccess(constant, 2);
538564
break;
539565
}
540566
case BC_PUSH_GLOBAL: {

src/compiler/Disassembler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ class Disassembler {
5353
VMFrame* frame);
5454
static void printPopLocal(uint8_t idx, uint8_t ctx, VMFrame* frame);
5555
static void printNth(uint8_t idx, VMFrame* frame, const char* op);
56+
static void printConstantAccess(vm_oop_t constant, uint8_t index);
5657
};

src/memory/GenerationalCollector.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ void GenerationalCollector::MajorCollection() {
124124
}
125125

126126
void GenerationalCollector::Collect() {
127+
DebugLog("GenGC Collect\n");
127128
Timer::GCTimer.Resume();
128129
// reset collection trigger
129130
heap->resetGCTrigger();

src/memory/MarkSweepCollector.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <vector>
55

66
#include "../memory/Heap.h"
7+
#include "../misc/debug.h"
78
#include "../vm/Universe.h"
89
#include "../vmobjects/AbstractObject.h"
910
#include "../vmobjects/IntegerBox.h"
@@ -14,6 +15,8 @@
1415
#define GC_MARKED 3456
1516

1617
void MarkSweepCollector::Collect() {
18+
DebugLog("MarkSweep Collect\n");
19+
1720
auto* heap = GetHeap<MarkSweepHeap>();
1821
Timer::GCTimer.Resume();
1922
// reset collection trigger

src/misc/debug.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ std::string DebugGetClassName(gc_oop_t obj) {
1616
return CLASS_OF(obj)->GetName()->GetStdString();
1717
}
1818

19+
void DebugDumpMethodWithObjects(VMInvokable* method) {
20+
Disassembler::DumpMethod((VMMethod*)method, "", true);
21+
}
22+
1923
void DebugDumpMethod(VMInvokable* method) {
2024
Disassembler::DumpMethod((VMMethod*)method, "", false);
2125
}

src/misc/debug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ static inline void DebugTrace(const char* fmt, ...) {
100100
std::string DebugGetClassName(vm_oop_t /*obj*/);
101101
std::string DebugGetClassName(gc_oop_t /*obj*/);
102102
void DebugDumpMethod(VMInvokable* method);
103+
void DebugDumpMethodWithObjects(VMInvokable* method);
103104
void DebugDumpMethod(MethodGenerationContext* mgenc);

0 commit comments

Comments
 (0)