Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Checks: '*,
-altera-id-dependent-backward-branch,
-altera-unroll-loops,
-android-*,
-boost-use-ranges,
-bugprone-casting-through-void,
-bugprone-easily-swappable-parameters,
Expand Down Expand Up @@ -40,6 +41,7 @@ Checks: '*,
-google-default-arguments,
-google-global-names-in-headers,
-google-readability-casting,
-google-upgrade-googletest-case,
-hicpp-avoid-c-arrays,
-hicpp-no-array-decay,
-hicpp-no-malloc,
Expand Down
31 changes: 26 additions & 5 deletions lint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
#!/bin/sh
clang-format-mp-19 -i --style=file --Werror src/*.cpp src/**/*.cpp src/**/*.h
clang-tidy-mp-19 --config-file=.clang-tidy src/**/*.cpp \
--fix \

CLANG_FORMAT="clang-format-mp-19 -i --style=file --Werror src/*.cpp src/**/*.cpp src/**/*.h"
$CLANG_FORMAT

## The check --enable-check-profile flag gives an overview of where clang-tidy spends its time
# --enable-check-profile

CLANG_START="clang-tidy-mp-19 --config-file=.clang-tidy"
CLANG_END="--fix \
-- -I/opt/local/include/ -fdiagnostics-absolute-paths \
-DGC_TYPE=GENERATIONAL -DUSE_TAGGING=false -DCACHE_INTEGER=false -DUNITTESTS
clang-format-mp-19 -i --style=file --Werror src/*.cpp src/**/*.cpp src/**/*.h
-DGC_TYPE=GENERATIONAL -DUSE_TAGGING=false -DCACHE_INTEGER=false -DUNITTESTS"


$CLANG_START src/*.cpp $CLANG_END &
$CLANG_START src/compiler/*.cpp $CLANG_END &
$CLANG_START src/interpreter/*.cpp $CLANG_END &
$CLANG_START src/memory/*.cpp $CLANG_END &
$CLANG_START src/misc/*.cpp $CLANG_END &
$CLANG_START src/primitives/*.cpp $CLANG_END &
$CLANG_START src/primitivesCore/*.cpp $CLANG_END &
$CLANG_START src/unitTests/*.cpp $CLANG_END &
$CLANG_START src/vm/*.cpp $CLANG_END &
$CLANG_START src/vmobjects/*.cpp $CLANG_END &

wait
$CLANG_FORMAT

12 changes: 3 additions & 9 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,15 @@
THE SOFTWARE.
*/

#include <fstream>
#include <cstdint>
#include <iostream>

#include "compiler/ClassGenerationContext.h"
#include "memory/Heap.h"
#include "misc/defs.h"
#include "vm/Print.h"
#include "vm/Universe.h"
#include "vmobjects/ObjectFormats.h"
#include "vmobjects/VMArray.h"
#include "vmobjects/VMMethod.h"
#include "vmobjects/VMObject.h"
#include "vmobjects/VMString.h"

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

Universe::Start(argc, argv);

Expand Down
82 changes: 54 additions & 28 deletions src/compiler/Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,26 @@ void Disassembler::DumpMethod(MethodGenerationContext* mgenc,
dumpMethod(bytecodes.data(), bytecodes.size(), indent, nullptr, true);
}

static void PrintFieldAccess(VMMethod* method, bool printObjects,
uint8_t const fieldIdx) {
if (method != nullptr && printObjects) {
auto* holder = dynamic_cast<VMClass*>((VMObject*)method->GetHolder());
if (holder != nullptr) {
VMSymbol* name = holder->GetInstanceFieldName(fieldIdx);
if (name != nullptr) {
DebugPrint("(index: %d) field: %s\n", fieldIdx,
name->GetStdString().c_str());
} else {
DebugPrint("(index: %d) field: !nullptr!: error!\n", fieldIdx);
}
} else {
DebugPrint("(index: %d) block holder is not a class!!\n", fieldIdx);
}
} else {
DebugPrint("(index: %d)\n", fieldIdx);
}
}

void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
const char* indent, VMMethod* method,
bool printObjects) {
Expand Down Expand Up @@ -152,7 +172,8 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
switch (bytecode) {
case BC_PUSH_0:
case BC_PUSH_1:
case BC_PUSH_NIL: {
case BC_PUSH_NIL:
case BC_RETURN_SELF: {
// no more details to be printed
break;
}
Expand Down Expand Up @@ -260,26 +281,12 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
case BC_POP_FIELD:
case BC_PUSH_FIELD: {
uint8_t const fieldIdx = bytecodes[bc_idx + 1];
if (method != nullptr && printObjects) {
auto* holder =
dynamic_cast<VMClass*>((VMObject*)method->GetHolder());
if (holder != nullptr) {
VMSymbol* name = holder->GetInstanceFieldName(fieldIdx);
if (name != nullptr) {
DebugPrint("(index: %d) field: %s\n", fieldIdx,
name->GetStdString().c_str());
} else {
DebugPrint("(index: %d) field: !nullptr!: error!\n",
fieldIdx);
}
} else {
DebugPrint(
"(index: %d) block holder is not a class!!\n",
fieldIdx);
}
} else {
DebugPrint("(index: %d)\n", fieldIdx);
}
PrintFieldAccess(method, printObjects, fieldIdx);
break;
}
case BC_POP_FIELD_1:
case BC_PUSH_FIELD_1: {
PrintFieldAccess(method, printObjects, 1);
break;
}
case BC_SEND:
Expand Down Expand Up @@ -399,6 +406,16 @@ void Disassembler::printNth(uint8_t idx, VMFrame* frame, const char* op) {
DebugPrint(">\n");
}

void Disassembler::printConstantAccess(vm_oop_t constant, uint8_t index) {
VMClass* c = CLASS_OF(constant);
VMSymbol* cname = c->GetName();

DebugPrint("(index: %d) value: (%s) ", index,
cname->GetStdString().c_str());
dispatch(constant);
DebugPrint("\n");
}

/**
* Dump bytecode from the frame running
*/
Expand Down Expand Up @@ -528,13 +545,22 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method,
}
case BC_PUSH_CONSTANT: {
vm_oop_t constant = method->GetConstant(bc_idx);
VMClass* c = CLASS_OF(constant);
VMSymbol* cname = c->GetName();

DebugPrint("(index: %d) value: (%s) ", BC_1,
cname->GetStdString().c_str());
dispatch(constant);
DebugPrint("\n");
printConstantAccess(constant, BC_1);
break;
}
case BC_PUSH_CONSTANT_0: {
vm_oop_t constant = method->GetIndexableField(0);
printConstantAccess(constant, 0);
break;
}
case BC_PUSH_CONSTANT_1: {
vm_oop_t constant = method->GetIndexableField(1);
printConstantAccess(constant, 1);
break;
}
case BC_PUSH_CONSTANT_2: {
vm_oop_t constant = method->GetIndexableField(2);
printConstantAccess(constant, 2);
break;
}
case BC_PUSH_GLOBAL: {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/Disassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ class Disassembler {
VMFrame* frame);
static void printPopLocal(uint8_t idx, uint8_t ctx, VMFrame* frame);
static void printNth(uint8_t idx, VMFrame* frame, const char* op);
static void printConstantAccess(vm_oop_t constant, uint8_t index);
};
1 change: 1 addition & 0 deletions src/memory/GenerationalCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ void GenerationalCollector::MajorCollection() {
}

void GenerationalCollector::Collect() {
DebugLog("GenGC Collect\n");
Timer::GCTimer.Resume();
// reset collection trigger
heap->resetGCTrigger();
Expand Down
3 changes: 3 additions & 0 deletions src/memory/MarkSweepCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vector>

#include "../memory/Heap.h"
#include "../misc/debug.h"
#include "../vm/Universe.h"
#include "../vmobjects/AbstractObject.h"
#include "../vmobjects/IntegerBox.h"
Expand All @@ -14,6 +15,8 @@
#define GC_MARKED 3456

void MarkSweepCollector::Collect() {
DebugLog("MarkSweep Collect\n");

auto* heap = GetHeap<MarkSweepHeap>();
Timer::GCTimer.Resume();
// reset collection trigger
Expand Down
4 changes: 4 additions & 0 deletions src/misc/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ std::string DebugGetClassName(gc_oop_t obj) {
return CLASS_OF(obj)->GetName()->GetStdString();
}

void DebugDumpMethodWithObjects(VMInvokable* method) {
Disassembler::DumpMethod((VMMethod*)method, "", true);
}

void DebugDumpMethod(VMInvokable* method) {
Disassembler::DumpMethod((VMMethod*)method, "", false);
}
Expand Down
1 change: 1 addition & 0 deletions src/misc/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ static inline void DebugTrace(const char* fmt, ...) {
std::string DebugGetClassName(vm_oop_t /*obj*/);
std::string DebugGetClassName(gc_oop_t /*obj*/);
void DebugDumpMethod(VMInvokable* method);
void DebugDumpMethodWithObjects(VMInvokable* method);
void DebugDumpMethod(MethodGenerationContext* mgenc);