Skip to content

Commit e9a187e

Browse files
committed
Clang-format
1 parent e475844 commit e9a187e

File tree

5 files changed

+48
-35
lines changed

5 files changed

+48
-35
lines changed

src/Debug/debugger.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
194194
case interruptPAUSE:
195195
this->pauseRuntime(m);
196196
// Make a checkpoint so the debugger knows the current state and
197-
// knows how many instructions were executed since the last checkpoint.
197+
// knows how many instructions were executed since the last
198+
// checkpoint.
198199
if (snapshotPolicy == SnapshotPolicy::checkpointing) {
199200
checkpoint(m, true);
200201
}
@@ -218,7 +219,7 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
218219
uint8_t *data = interruptData + 1;
219220
uint32_t amount = read_B32(&data);
220221
printf("Continue for %d instruction(s)\n", amount);
221-
remaining_instructions = (int32_t) amount;
222+
remaining_instructions = (int32_t)amount;
222223
*program_state = WARDUINOrun;
223224
free(interruptData);
224225
break;
@@ -914,8 +915,7 @@ void Debugger::handleSnapshotPolicy(Module *m) {
914915
this->channel->write("SNAPSHOT ");
915916
snapshot(m);
916917
this->channel->write("\n");
917-
}
918-
else if (snapshotPolicy == SnapshotPolicy::checkpointing) {
918+
} else if (snapshotPolicy == SnapshotPolicy::checkpointing) {
919919
if (instructions_executed >= checkpointInterval || fidx_called) {
920920
checkpoint(m);
921921
}
@@ -925,11 +925,11 @@ void Debugger::handleSnapshotPolicy(Module *m) {
925925
if ((fidx_called = isPrimitiveBeingCalled(m, m->pc_ptr))) {
926926
const Type *type = m->functions[*fidx_called].type;
927927
for (int32_t i = 0; i < type->param_count; i++) {
928-
prim_args[type->param_count - i - 1] = m->stack[m->sp - i].value.uint32;
928+
prim_args[type->param_count - i - 1] =
929+
m->stack[m->sp - i].value.uint32;
929930
}
930931
}
931-
}
932-
else if (snapshotPolicy != SnapshotPolicy::none) {
932+
} else if (snapshotPolicy != SnapshotPolicy::none) {
933933
this->channel->write("WARNING: Invalid snapshot policy.");
934934
}
935935
}
@@ -939,7 +939,8 @@ void Debugger::checkpoint(Module *m, bool force) {
939939
return;
940940
}
941941

942-
this->channel->write(R"(CHECKPOINT {"instructions_executed": %d, )", instructions_executed);
942+
this->channel->write(R"(CHECKPOINT {"instructions_executed": %d, )",
943+
instructions_executed);
943944
if (fidx_called) {
944945
this->channel->write("\"fidx_called\": %d, \"args\": [", *fidx_called);
945946
const Block &func_block = m->functions[*fidx_called];
@@ -1461,7 +1462,8 @@ Debugger::~Debugger() {
14611462
delete this->supervisor;
14621463
}
14631464

1464-
std::optional<uint32_t> Debugger::isPrimitiveBeingCalled(Module *m, uint8_t *pc_ptr) {
1465+
std::optional<uint32_t> Debugger::isPrimitiveBeingCalled(Module *m,
1466+
uint8_t *pc_ptr) {
14651467
if (!pc_ptr) {
14661468
return {};
14671469
}
@@ -1477,8 +1479,7 @@ std::optional<uint32_t> Debugger::isPrimitiveBeingCalled(Module *m, uint8_t *pc_
14771479
}
14781480

14791481
bool Debugger::handleContinueFor(Module *m) {
1480-
if (remaining_instructions < 0)
1481-
return false;
1482+
if (remaining_instructions < 0) return false;
14821483

14831484
if (remaining_instructions == 0) {
14841485
remaining_instructions = -1;
@@ -1495,7 +1496,8 @@ bool Debugger::handleContinueFor(Module *m) {
14951496

14961497
void Debugger::notifyCompleteStep(Module *m) const {
14971498
// Upon completing a step in checkpointing mode, make a checkpoint.
1498-
if (m->warduino->debugger->getSnapshotPolicy() == SnapshotPolicy::checkpointing) {
1499+
if (m->warduino->debugger->getSnapshotPolicy() ==
1500+
SnapshotPolicy::checkpointing) {
14991501
m->warduino->debugger->checkpoint(m);
15001502
}
15011503
this->channel->write("STEP!\n");

src/Debug/debugger.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,15 @@ enum InterruptTypes {
9999
};
100100

101101
enum class SnapshotPolicy : int {
102-
none, // Don't automatically take snapshots.
103-
atEveryInstruction, // Take a snapshot after every instruction.
104-
checkpointing, // Take a snapshot every x instructions or at specific points were reversible primitives are used or sensor values are read.
102+
none, // Don't automatically take snapshots.
103+
atEveryInstruction, // Take a snapshot after every instruction.
104+
checkpointing, // Take a snapshot every x instructions or at specific
105+
// points were reversible primitives are used or sensor
106+
// values are read.
105107
};
106108

107109
class Debugger {
108-
private:
110+
private:
109111
std::deque<uint8_t *> debugMessages = {};
110112

111113
// Help variables
@@ -130,7 +132,8 @@ class Debugger {
130132
uint8_t *prev_pc_ptr;
131133
int32_t remaining_instructions;
132134

133-
std::unordered_map<uint32_t, std::unordered_map<uint32_t, uint32_t>> overrides;
135+
std::unordered_map<uint32_t, std::unordered_map<uint32_t, uint32_t>>
136+
overrides;
134137

135138
std::optional<uint32_t> fidx_called;
136139
uint32_t prim_args[8];
@@ -235,7 +238,8 @@ class Debugger {
235238

236239
void pauseRuntime(Module *m); // pause runtime for given module
237240

238-
void notifyCompleteStep(Module *m) const; // notify the debugger frontend that a step was taken
241+
void notifyCompleteStep(
242+
Module *m) const; // notify the debugger frontend that a step was taken
239243

240244
// Interrupts
241245

@@ -295,7 +299,5 @@ class Debugger {
295299
bool handlePushedEvent(char *bytes) const;
296300

297301
void checkpoint(Module *m, bool force = false);
298-
inline SnapshotPolicy getSnapshotPolicy() {
299-
return snapshotPolicy;
300-
}
302+
inline SnapshotPolicy getSnapshotPolicy() { return snapshotPolicy; }
301303
};

src/Primitives/emulated.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,9 @@ bool resolve_external_memory(char *symbol, Memory **val) {
575575
//------------------------------------------------------
576576
// Restore external state
577577
//------------------------------------------------------
578-
void restore_external_state(Module *m, std::vector<IOStateElement> external_state) {}
578+
void restore_external_state(Module *m,
579+
std::vector<IOStateElement> external_state) {}
579580

580-
std::vector<IOStateElement *> get_io_state(Module *m) {
581-
return {};
582-
}
581+
std::vector<IOStateElement *> get_io_state(Module *m) { return {}; }
583582

584583
#endif // ARDUINO

src/Primitives/zephyr.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ MotorEncoder encoders[] = {MotorEncoder(specs[51], specs[50]),
453453
MotorEncoder(specs[57], specs[58])};
454454
// MotorEncoder test_encoder = MotorEncoder(specs[57], specs[58]);
455455

456-
void drive_motor_to_target(pwm_dt_spec pwm1_spec, pwm_dt_spec pwm2_spec, MotorEncoder *encoder, int32_t speed) {
456+
void drive_motor_to_target(pwm_dt_spec pwm1_spec, pwm_dt_spec pwm2_spec,
457+
MotorEncoder *encoder, int32_t speed) {
457458
printf("drift = %d\n",
458459
abs(encoder->get_angle() - encoder->get_target_angle()));
459460

@@ -471,12 +472,17 @@ void drive_motor_to_target(pwm_dt_spec pwm1_spec, pwm_dt_spec pwm2_spec, MotorEn
471472
bool not_moving = k_uptime_get() - encoder->get_last_update() >= 150;
472473
if (not_moving) {
473474
speed += 100;
474-
printf("Not moving, increasing speed to %d, %llims since last movement\n", speed, k_uptime_get() - encoder->get_last_update());
475+
printf(
476+
"Not moving, increasing speed to %d, %llims since last "
477+
"movement\n",
478+
speed, k_uptime_get() - encoder->get_last_update());
475479
drive_motor(pwm1_spec, pwm2_spec, speed_sign * speed / 10000.0f);
476480

477481
// Wait for 10ms or movement.
478482
uint64_t start_time = k_uptime_get();
479-
while (k_uptime_get() - start_time < 10 && k_uptime_get() - encoder->get_last_update() >= 150) {}
483+
while (k_uptime_get() - start_time < 10 &&
484+
k_uptime_get() - encoder->get_last_update() >= 150) {
485+
}
480486
continue;
481487
}
482488
encoder->last_update = k_uptime_get();
@@ -497,7 +503,8 @@ void drive_motor_to_target(pwm_dt_spec pwm1_spec, pwm_dt_spec pwm2_spec, MotorEn
497503
}
498504
}
499505

500-
bool drive_motor_degrees_relative(int32_t motor_index, int32_t degrees, int32_t speed) {
506+
bool drive_motor_degrees_relative(int32_t motor_index, int32_t degrees,
507+
int32_t speed) {
501508
printf("drive_motor_degrees(%d, %d, %d)\n", motor_index, degrees, speed);
502509

503510
if (motor_index > 1) {
@@ -516,9 +523,9 @@ bool drive_motor_degrees_relative(int32_t motor_index, int32_t degrees, int32_t
516523

517524
def_prim(drive_motor_degrees, threeToNoneU32) {
518525
int32_t speed = (int32_t)arg0.uint32;
519-
//speed = 10000;
526+
// speed = 10000;
520527
int32_t degrees = (int32_t)arg1.uint32;
521-
//degrees = 360 * 20;
528+
// degrees = 360 * 20;
522529
int32_t motor_index = (int32_t)arg2.uint32;
523530
bool result = drive_motor_degrees_relative(motor_index, degrees, speed);
524531
pop_args(3);
@@ -935,15 +942,18 @@ bool resolve_external_memory(char *symbol, Memory **val) {
935942
void restore_external_state(Module *m,
936943
std::vector<IOStateElement> external_state) {
937944
uint8_t opcode = *m->pc_ptr;
938-
// TODO: Maybe primitives can also be called using the other call operators, maybe there should just be a function that checks if a certain function is being called?
939-
if (opcode == 0x10) { // call opcode
945+
// TODO: Maybe primitives can also be called using the other call operators,
946+
// maybe there should just be a function that checks if a certain function
947+
// is being called?
948+
if (opcode == 0x10) { // call opcode
940949
uint8_t *pc_copy = m->pc_ptr + 1;
941950
uint32_t fidx = read_LEB_32(&pc_copy);
942951
if (fidx < m->import_count) {
943952
for (auto &primitive : primitives) {
944953
if (!strcmp(primitive.name, m->functions[fidx].import_field)) {
945954
if (primitive.f_reverse) {
946-
printf("Reversing action for primitive %s\n", primitive.name);
955+
printf("Reversing action for primitive %s\n",
956+
primitive.name);
947957
primitive.f_reverse(m, external_state);
948958
}
949959
return;

src/WARDuino.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
#include "Debug/debugger.h"
1212
#include "Edward/proxy_supervisor.h"
13+
#include "IO/io.h"
1314
#include "Interpreter/interpreter.h"
1415
#include "WARDuino/internals.h"
15-
#include "IO/io.h"
1616

1717
// Constants
1818
#define WA_MAGIC 0x6d736100

0 commit comments

Comments
 (0)