Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4252c3e

Browse files
committedSep 6, 2019
Linting and formatting
Sorry git history
1 parent 05b3b93 commit 4252c3e

30 files changed

+708
-529
lines changed
 

‎WARDuino.cpp

+150-114
Large diffs are not rendered by default.

‎WARDuino.h

+32-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#ifndef WAC_H
44
#define WAC_H
5+
56
#include <limits.h>
67
#include <stdbool.h>
78
#include <stdint.h>
@@ -49,9 +50,13 @@ typedef struct Type {
4950

5051
typedef union FuncPtr {
5152
void (*void_void)();
53+
5254
void (*void_i32)(uint32_t);
55+
5356
void (*void_i64)(uint64_t);
57+
5458
void (*void_f32)(float);
59+
5560
void (*void_f64)(double);
5661

5762
double (*f64_f64)(double);
@@ -60,11 +65,11 @@ typedef union FuncPtr {
6065
// A block or function
6166
typedef struct Block {
6267
uint8_t block_type; // 0x00: function, 0x01: init_exp
63-
// 0x02: block, 0x03: loop, 0x04: if
68+
// 0x02: block, 0x03: loop, 0x04: if
6469
uint32_t fidx; // function only (index)
6570
Type *type; // params/results type
6671
uint32_t local_count; // function only
67-
uint32_t *local_value_type; // types of locals (function only)
72+
uint8_t *local_value_type; // types of locals (function only)
6873
uint8_t *start_ptr;
6974
uint8_t *end_ptr;
7075
uint8_t *else_ptr; // if block only
@@ -128,7 +133,7 @@ typedef struct Options {
128133
class WARDuino; // predeclare for it work in the module decl
129134

130135
typedef struct Module {
131-
WARDuino* warduino;
136+
WARDuino *warduino;
132137
char *path; // file path of the wasm module
133138
Options options; // Config options
134139

@@ -142,8 +147,8 @@ typedef struct Module {
142147
uint32_t function_count; // number of function (including imports)
143148
Block *functions; // imported and locally defined functions
144149
std::map<uint8_t *, Block *>
145-
block_lookup; // map of module byte position to Blocks
146-
// same length as byte_count
150+
block_lookup; // map of module byte position to Blocks
151+
// same length as byte_count
147152
uint32_t start_function; // function to run on module load
148153
Table table;
149154
Memory memory;
@@ -160,17 +165,20 @@ typedef struct Module {
160165
} Module;
161166

162167
typedef void (*Primitive)(Module *);
168+
163169
typedef struct PrimitiveEntry {
164170
const char *name;
165171
Primitive f;
166172
Type t;
167173
} PrimitiveEntry;
168174

169175

170-
enum RunningState { WARDUINOrun, WARDUINOpause, WARDUINOstep };
176+
enum RunningState {
177+
WARDUINOrun, WARDUINOpause, WARDUINOstep
178+
};
171179

172180
class WARDuino {
173-
private:
181+
private:
174182
std::vector<Module *> modules = {};
175183
std::deque<uint8_t *> parsedInterrups = {};
176184

@@ -184,26 +192,35 @@ class WARDuino {
184192
std::vector<uint8_t> interruptBuffer;
185193
long interruptSize;
186194

187-
public:
195+
public:
188196

189197
// vector, we expect few breakpoints
190198
std::set<uint8_t *> breakpoints = {};
191199

192200
WARDuino();
193-
int run_module(Module* m);
201+
202+
int run_module(Module *m);
203+
194204
Module *load_module(uint8_t *bytes, uint32_t byte_count, Options options);
195-
void unload_module(Module* m);
205+
206+
void unload_module(Module *m);
207+
196208
bool invoke(Module *m, uint32_t fidx);
209+
197210
uint32_t get_export_fidx(Module *m, const char *name);
211+
198212
void handleInterrupt(size_t len, uint8_t *buff);
199213

200214
// breakpoints
201-
void addBreakpoint(uint8_t* loc);
202-
void delBreakpoint(uint8_t* loc);
203-
bool isBreakpoint(uint8_t* loc);
204-
215+
void addBreakpoint(uint8_t *loc);
216+
217+
void delBreakpoint(uint8_t *loc);
218+
219+
bool isBreakpoint(uint8_t *loc);
220+
205221
// Get interrupt or NULL if none
206-
uint8_t* getInterrupt();
222+
uint8_t *getInterrupt();
207223

208224
};
225+
209226
#endif

‎benchmarks/all_bench.sh

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ trap "rm -rf '$tmpdir'" EXIT
99

1010
echo -e "tip:\ntail -f $tmpdir/*"
1111

12-
echo "Not started yet" > $tmpdir/espruino
13-
echo "Not started yet" > $tmpdir/warduino
14-
echo "Not started yet" > $tmpdir/native
12+
echo "Not started yet" >$tmpdir/espruino
13+
echo "Not started yet" >$tmpdir/warduino
14+
echo "Not started yet" >$tmpdir/native
1515

16-
to_csv () {
16+
to_csv() {
1717
sed -i -n '0~2{N;s/\n/,/p}' $1
1818
}
1919

2020
sleep 5
2121
./espruino_bench.sh $tmpdir/espruino
22-
to_csv $tmpdir/espruino
22+
to_csv $tmpdir/espruino
2323

2424
sleep 5
2525
./warduino_bench.sh $tmpdir/warduino
@@ -36,18 +36,18 @@ cat $tmpdir/warduino
3636
echo "# Native"
3737
cat $tmpdir/native
3838

39-
sizes () {
39+
sizes() {
4040
find tasks -iname "*.$1" -exec du -b '{}' \+ | sed 's:\s*tasks/:,:;s:/.*::;s:\(.*\),\(.*\):\2,\1:' | sort
4141
}
4242

43-
echo "name,espruino,warduino,native,espruinoSize,warduinoSize" > $file.csv
43+
echo "name,espruino,warduino,native,espruinoSize,warduinoSize" >$file.csv
4444
sort $tmpdir/espruino
45-
join -j 1 -t',' - <(sort $tmpdir/warduino) |\
46-
join -j 1 -t',' - <(sort $tmpdir/native) |\
47-
join -j 1 -t',' - <(sizes js) |\
48-
join -j 1 -t',' - <(sizes wasm) >> $file.csv
49-
sed 's/,/ /g' $file.csv > $file
50-
51-
cat $file.csv | \
52-
sed 's/[0-9]\+\./ &/g;s/ *\([0-9 ]\{3\}\.\)/\1/g;s/\.\([0-9]\{4\}\)[0-9]*/.\1/g' |\
45+
join -j 1 -t',' - <(sort $tmpdir/warduino) |
46+
join -j 1 -t',' - <(sort $tmpdir/native) |
47+
join -j 1 -t',' - <(sizes js) |
48+
join -j 1 -t',' - <(sizes wasm) >>$file.csv
49+
sed 's/,/ /g' $file.csv >$file
50+
51+
cat $file.csv |
52+
sed 's/[0-9]\+\./ &/g;s/ *\([0-9 ]\{3\}\.\)/\1/g;s/\.\([0-9]\{4\}\)[0-9]*/.\1/g' |
5353
column -t -s','

‎benchmarks/arduino.ino.template

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Arduino.h"
22
#include "WARDuino.h"
3+
34
WARDuino wac;
45

56

@@ -17,7 +18,7 @@ void ICACHE_RAM_ATTR handleInput() {
1718
while (Serial.available()) {
1819
size_t buff_len = 0;
1920
while (Serial.available()) {
20-
buff[buff_len++] = (int8_t)Serial.read();
21+
buff[buff_len++] = (int8_t) Serial.read();
2122
}
2223
if (buff_len) {
2324
wac.handleInterrupt(buff_len, buff);
@@ -32,12 +33,12 @@ void setup() {
3233
}
3334

3435
void loop() {
35-
Module* m = wac.load_module(impl_wasm, impl_wasm_len, {});
36+
Module *m = wac.load_module(impl_wasm, impl_wasm_len, {});
3637
delay(1000);
3738
printf("START\n\n");
3839
for (int i = 0; i < 10; i++) {
3940
wac.run_module(m);
40-
printf("%d: %u\n", i,m->stack->value.uint32);
41+
printf("%d: %u\n", i, m->stack->value.uint32);
4142
}
4243
printf("DONE\n\n");
4344
}

‎benchmarks/benchmarks.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void set_path(char *path, string name) {
3636

3737
unsigned int read_file_to_buf(unsigned char *bytes, string path) {
3838
FILE *file = fopen(path, "r");
39-
if (file == NULL) {
39+
if (file == nullptr) {
4040
fprintf(stderr, "Cannot open file: %s", path);
4141
exit(1);
4242
}
@@ -45,7 +45,7 @@ unsigned int read_file_to_buf(unsigned char *bytes, string path) {
4545
ASSERT(num_bytes > 0, "Could not Ftell");
4646
if (num_bytes < MAX_BYTE_CODE_SIZE) {
4747
fseek(file, 0L, SEEK_SET);
48-
size_t result = fread(bytes, sizeof(char), num_bytes, file);
48+
size_t result = fread(bytes, sizeof(char), (size_t) num_bytes, file);
4949
if (result != (size_t) num_bytes) {
5050
fprintf(stderr, "reading error while loading file %s", path);
5151
exit(1);
@@ -62,7 +62,7 @@ void run_benchmarks(size_t num_benchmarks, string benchmarks[]) {
6262
char path[MAX_PATH];
6363
unsigned char bytes[MAX_BYTE_CODE_SIZE];
6464
unsigned int bytes_length;
65-
WARDuino *w = new WARDuino();
65+
auto *w = new WARDuino();
6666

6767
for (size_t i = 0; i < num_benchmarks; i++) {
6868
string name = benchmarks[i];
@@ -105,6 +105,6 @@ void run_benchmarks(size_t num_benchmarks, string benchmarks[]) {
105105

106106
int main(int argc, const char *argv[]) {
107107
string benchmarks[] = {"tak", "fib", "fac", "gcd", "catalan", "primes"};
108-
run_benchmarks((size_t)(sizeof(benchmarks) / sizeof(string *)), benchmarks);
108+
run_benchmarks((size_t) (sizeof(benchmarks) / sizeof(string *)), benchmarks);
109109
return 0;
110110
}

‎benchmarks/c.ino.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ void setup() {
22
Serial.begin(115200);
33
}
44

5-
void __attribute__((optimize("no-unroll-loops"))) loop() {
5+
void __attribute__((optimize("no-unroll-loops"))) loop() {
66
delay(1000);
77
printf("START\n\n");
88
for (int i = 0; i < 10; i++) {

‎benchmarks/espruino_bench.sh

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ set -e
66

77
file=${1:-/tmp/res}
88
cd "$(dirname "$0")"
9-
date > $file
9+
date >$file
1010

1111
./flash-espruino-esp32.sh
1212

1313
echo "Sleep 5 sec till espruino boots"
1414
sleep 5
1515

16-
17-
cat bench.list | while read l;
18-
do
19-
echo $l | tee -a $file
20-
python flash_and_check.py tasks/$l/espruino/impl.js | tee -a $file
16+
cat bench.list | while read l; do
17+
echo $l | tee -a $file
18+
python flash_and_check.py tasks/$l/espruino/impl.js | tee -a $file
2119
done

‎benchmarks/flash-espruino-esp32.sh

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
#!/bin/bash
2-
TMPDIR=`mktemp -d /tmp/buildfolder.XXXXXXXXXX`
2+
TMPDIR=$(mktemp -d /tmp/buildfolder.XXXXXXXXXX)
33
trap "rm -rf $dir" EXIT
44

5-
65
sed -n '/ex''it 0/,${/^ex''it /!p}' "$0" | base64 -d | tar -xzf- -C $TMPDIR
76

87
cd $TMPDIR
9-
~/.arduino15/packages/esp32/tools/esptool_py/2.6.1/esptool.py \
10-
--chip esp32 \
11-
--port /dev/ttyUSB0 \
12-
--baud 921600 \
13-
--after hard_reset write_flash \
14-
-z \
15-
--flash_mode dio \
16-
--flash_freq 40m \
17-
--flash_size detect \
18-
0x1000 bootloader.bin \
19-
0x8000 partitions_espruino.bin \
20-
0x10000 espruino_esp32.bin
21-
8+
~/.arduino15/packages/esp32/tools/esptool_py/2.6.1/esptool.py \
9+
--chip esp32 \
10+
--port /dev/ttyUSB0 \
11+
--baud 921600 \
12+
--after hard_reset write_flash \
13+
-z \
14+
--flash_mode dio \
15+
--flash_freq 40m \
16+
--flash_size detect \
17+
0x1000 bootloader.bin \
18+
0x8000 partitions_espruino.bin \
19+
0x10000 espruino_esp32.bin
2220

2321
exit 0
2422
H4sIAAAAAAAAA+z9CVxU5/U4jD8zbMMwwrCK+wUZNlmGARQR5A4wwMg2MsPiksDADDARmHFmUDQm

‎benchmarks/flash_and_check.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def await_output(s: serial.Serial, target: str):
1414
curpos: int = 0
1515
while True:
1616
x = s.read()
17-
print(x.decode('utf-8','replace'), end="", file=sys.stderr)
17+
print(x.decode('utf-8', 'replace'), end="", file=sys.stderr)
1818
x = x[0]
1919
if x == b'\r'[0]:
2020
continue

‎benchmarks/makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CXXSOURCES = \
3737
benchmarks.cpp
3838

3939
all: $(OUTPUTDIR)$(TARGET) $(addprefix tasks/,$(addsuffix /wast/impl.wasm, $(TASKS)))
40-
echo "made tasks: $(TASKS)"
40+
echo "made tasks: $(TASKS)"
4141

4242
tasks/%/wast/impl.wasm: tasks/%/wast/impl.c tasks/makefile
4343
make -C tasks $(@:tasks/%=%)

‎benchmarks/native_bench.sh

+8-10
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@ tmpfile="$(mktemp --tmpdir)"
66
trap "rm '$tmpfile'" EXIT
77
cd "$(dirname "$0")"
88
outloc=${1:--}
9-
date > $1
9+
date >$1
1010
make clean all
1111
make -C tasks all
1212

13-
cat bench.list | while read l;
14-
do
15-
echo $l | tee -a $1
16-
USE_TMPDIR=1 ../scripts/upload ${BOARD:-ESP32} ./tasks/$l/c/arduino.ino 2>&1 >"$tmpfile"
17-
if test "$?" == 0
18-
then
13+
cat bench.list | while read l; do
14+
echo $l | tee -a $1
15+
USE_TMPDIR=1 ../scripts/upload ${BOARD:-ESP32} ./tasks/$l/c/arduino.ino 2>&1 >"$tmpfile"
16+
if test "$?" == 0; then
1917
echo "flashed"
20-
python flash_and_check.py | tee -a $1
21-
else
18+
python flash_and_check.py | tee -a $1
19+
else
2220
cat $tmpfile
2321
echo "FAILED!"
2422
exit 1
25-
fi
23+
fi
2624
done

‎benchmarks/timer.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#include <iostream>
22
#include <chrono>
33

4-
class Timer
5-
{
4+
class Timer {
65
public:
76
Timer() : beg_(clock_::now()) {}
7+
88
void reset() { beg_ = clock_::now(); }
9-
double elapsed() const {
9+
10+
double elapsed() const {
1011
return std::chrono::duration_cast<second_>
11-
(clock_::now() - beg_).count(); }
12+
(clock_::now() - beg_).count();
13+
}
1214

1315
private:
1416
typedef std::chrono::high_resolution_clock clock_;

0 commit comments

Comments
 (0)
Please sign in to comment.