[RELEASE] u22-v04

This version is submitted for U22 final presentation. (squashed 158 commits)
This commit is contained in:
2020-10-09 00:00:00 +00:00
parent 84c3a02b9a
commit 80b3b82332
277 changed files with 12154 additions and 13836 deletions

141
tool/benum.sh Executable file
View File

@@ -0,0 +1,141 @@
#!/bin/bash
set -eu
if [[ -z ${1+x} || -z ${2+x} ]]; then
echo "usage: cat <file> | ./benum.sh <dst path without extension> <header path>"
exit 1
fi
DSTPATH="$1"
DSTDIR=$(dirname "$DSTPATH")
HEADERPATH="$2"
if [[ $DSTPATH =~ /$ ]]; then
echo "destination path must be a filename without extension" >&2
exit 1
fi
if [[ ! -d $DSTDIR ]]; then
echo "no such directory: $DSTDIR" >&2
exit 1
fi
preprocess=$(cat << EOS
s|^\s*||
s|\s*$||
/^\/\* *BENUM *BEGIN.*\*\/$/,/^\/\* *BENUM *END *\*\/$/ ! d
/^\/\* *BENUM *BEGIN.*\*\/$/ {
s|^\/\* *BENUM *BEGIN *([^ ]*) *\*\/$|^\1|
p
s|.||g
x
b
}
/^\/\* *BENUM *END *\*\/$/ {
x
s|\s||g
s|,|\\n|g
s|\\n\\n*|\\n|g
s|^\\n||
s|\\n$||
p; b
}
H
EOS
)
header=$(cat << EOS
#include <stdbool.h>
#include <stddef.h>
EOS
)
src=$(cat << EOS
#include "$HEADERPATH"
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
EOS
)
name=
NAME=
list=()
output_header() {
if [[ -z $name ]]; then return; fi
cat << EOS
#define ${NAME}_EACH(PROC) do { \\
$(for item in ${list[@]}; do
echo "PROC($item, ${item,,}); \\"
done)
} while (0)
#define ${NAME}_COUNT ${#list[@]}
const char* ${name}_stringify(${name}_t v);
bool ${name}_unstringify(${name}_t* v, const char* str, size_t len);
EOS
}
output_source() {
if [[ -z $name ]]; then return; fi
cat << EOS
const char* ${name}_stringify(${name}_t v) {
switch (v) {
$(for item in ${list[@]}; do
echo "case ${NAME}_$item: return \"$item\";"
done)
}
assert(false);
return NULL;
}
bool ${name}_unstringify(${name}_t* v, const char* str, size_t len) {
assert(v != NULL);
assert(str != NULL || len == 0);
$(for item in ${list[@]}; do
echo "if (len == ${#item} && strncmp(str, \"$item\", len) == 0) {"
echo " *v = ${NAME}_$item;"
echo " return true;"
echo "}"
done)
return false;
}
EOS
}
output() {
header+=$(output_header)
src+=$(output_source)
}
while read line; do
if [[ $line =~ ^\^(.*)$ ]]; then
output
name="${BASH_REMATCH[1]}"
name="${name,,}"
NAME="${name^^}"
list=()
else
if [[ ! $line =~ ^${NAME}_(.*)$ ]]; then
echo invalid naming rule: "$line" >&2
exit 1
fi
list+=(${BASH_REMATCH[1]})
fi
done < <(cat | sed -r -n "$preprocess")
output
echo "$header" > "$DSTPATH.h"
echo "$src" > "$DSTPATH.c"

View File

@@ -1,14 +1,19 @@
#!/bin/sh
#!/bin/bash
set -e
set -eu
name=`echo "$1" | sed -e 's/[^A-z0-9_]/_/g'`
if [[ -z ${1+x} || -z ${2+x} ]]; then
echo "usage: cat <file> | ./bin2c.sh <identifier name> <output name>"
exit 1
fi
name=$(sed -e 's/[^A-z0-9_]/_/g' <<< "$1")
hpath="$2.h"
cpath="$2.c"
data=`cat $in | xxd -i`
size=`echo $data | wc -w`
data=$(cat - | xxd -i)
size=$(wc -w <<< "$data")
echo "const char $name[$size] = {$data};" > $cpath
echo "extern const char $name[$size];" > $hpath

89
tool/crial.sh Executable file
View File

@@ -0,0 +1,89 @@
#!/bin/bash
set -eu
DEFAULT_SERIALIZER="${DEFAULT_SERIALIZER:-}"
DEFAULT_DESERIALIZER="${DEFAULT_DESERIALIZER:-}"
preproc=$(cat << EOS
s|^\s*(.*)\s*$|\1|
/^\/\*\s*CRIAL\s*$/, /^\*\/$/ ! d
/^\/\*\s*CRIAL\s*$/ d
/^\*\/$/ d
EOS
)
seq=
part_serializer="$DEFAULT_SERIALIZER"
part_deserializer="$DEFAULT_DESERIALIZER"
serializer=
deserializer=
last_name=
count=0
add_property() {
name=$(awk -F ' ' '{print $1}' <<< "$1")
code=$(awk -F ' ' '{print $1}' <<< "$2")
local s="$part_serializer"
local d="$part_deserializer"
s=${s//\$name/$name}
d=${d//\$name/$name}
s=${s//\$code/$code}
d=${d//\$code/$code}
serializer+="do { $s } while (0);"
deserializer+="do { $d } while (0);"
(( ++count ))
}
while IFS=$'\n' read line; do
if [[ ! $line ]]; then continue; fi
case $seq in
serializer)
if [[ $line == "END" ]]; then
seq=
else
part_serializer+="$line"
fi
;;
deserializer)
if [[ $line == "END" ]]; then
seq=
else
part_deserializer+="$line"
fi
;;
*)
if [[ $line =~ ^# ]]; then
:
elif [[ $line =~ ^SERIALIZER_BEGIN$ ]]; then
seq="serializer"
part_serializer=
elif [[ $line =~ ^DESERIALIZER_BEGIN$ ]]; then
seq="deserializer"
part_deserializer=
elif [[ $line =~ ^PROPERTY[[:blank:]](.*)=(.*)$ ]]; then
add_property "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}"
elif [[ $line =~ ^PROPERTY[[:blank:]](.*)$ ]]; then
add_property "${BASH_REMATCH[1]}" "${BASH_REMATCH[1]}"
else
echo crial syntax error
exit 1
fi
;;
esac
done < <(cat - | sed -r "$preproc")
echo "#define CRIAL_PROPERTY_COUNT_ $count"
echo "#define CRIAL_SERIALIZER_ do { $serializer } while (0)"
echo "#define CRIAL_DESERIALIZER_ do { $deserializer } while (0)"

View File

@@ -1,35 +1,31 @@
#!/bin/sh
#!/bin/bash
# This script works only with memory-trace file generated in Linux.
set -eu
file="memory-trace"
if [ ! -f $file ]; then
if [[ ! -f $file ]]; then
echo no memory trace file found
exit 1
fi
declare -A addrs
while read line; do
IFS=" " read -r type addr1 trash1 addr2 trash2 <<< $line
while IFS=$' \n' read -r type addr1 dummy1_ addr2 dummy2_; do
case "$type" in
"new")
addrs[$addr1]="allocated"
addrs[$addr1]=1
;;
"resize")
addrs[$addr1]="freed"
addrs[$addr2]="allocated"
unset addrs[$addr1]
;;
"delete")
addrs[$addr1]="freed"
unset addrs[$addr1]
;;
*)
;;
*) ;;
esac
done < $file
for addr in "${!addrs[@]}"; do
if [ "${addrs[$addr]}" == "allocated" ]; then
echo $addr
fi
echo $addr
done