Skip to content

Commit

Permalink
Merge pull request #122 from fennecdjay/UnionTmpl
Browse files Browse the repository at this point in the history
Some cleanup
  • Loading branch information
fennecdjay committed Jun 6, 2019
2 parents d62e2d7 + eded9a0 commit 275301f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
32 changes: 32 additions & 0 deletions help/afl.sh
@@ -0,0 +1,32 @@
#!/bin/sh
: "${AFL_PREFIX:=afl-}"
: "${AFL_CC:=afl-gcc}"
: "${RESULT_DIR:=${AFL_PREFIX}result}"

clean_lib() {
echo "🛀 cleaning $1"
cd "$1" && make clean all && cd ..
}

compile() {
export CC="$AFL_CC"
clean_lib util
clean_lib ast
clean_lib "$PWD"
}

prepare() {
CRASH_DIR=${AFL_PREFIX}crash
if [ -d "$CRASH_DIR" ]
then echo "$CRASH_DIR already contains at risk data"
else mkdir "$CRASH_DIR"
fi
for file in "$RESULT_DIR"/*/crashes/id*
do
NEW_NAME="$(basename "$file" | sed 's/id:0*\([0-9]*\),.*/\1.gw/')"
cp "$file" "$NEW_NAME"
done
}

#compile
prepare
6 changes: 3 additions & 3 deletions help/struct_check.sh
@@ -1,7 +1,7 @@
#!/bin/sh
: "${PRG:=./gwion}"

pahole -s ${PRG} | while read name size gap
do [ $size -gt 64 ] && echo $name $size
[ $gap -gt 0 ] && echo "$name has a gap"
pahole -s ${PRG} | while read -r name size gap
do [ "$size" -gt 64 ] && echo "$name $size"
[ "$gap" -gt 0 ] && echo "$name has a gap"
done
2 changes: 1 addition & 1 deletion help/test.sh
Expand Up @@ -465,7 +465,7 @@ clean() {
[ -f test.log ] && rm test.log
[ $# -ne 0 ] && do_test "${@}" | consummer

if [ -f test.log ] && [ -z $NO_LOG ]
if [ -f test.log ] && [ -z "$NO_LOG" ]
then
cat test.log
exit 1
Expand Down
15 changes: 11 additions & 4 deletions src/emit/emit.c
Expand Up @@ -165,9 +165,10 @@ ANN static void emit_pre_ctor(const Emitter emit, const Type type) {
}

#define regxxx(name, instr) \
ANN static inline void reg##name(const Emitter emit, const m_uint sz) { \
ANN static inline Instr reg##name(const Emitter emit, const m_uint sz) { \
const Instr instr = emit_add_instr(emit, Reg##instr); \
instr->m_val = sz; \
return instr; \
}
regxxx(pop, Pop)
regxxx(pushi, PushImm)
Expand Down Expand Up @@ -210,9 +211,13 @@ ANN ArrayInfo* emit_array_extend_inner(const Emitter emit, const Type t, const E
ANN void emit_ext_ctor(const Emitter emit, const VM_Code code) {
const Instr cpy = emit_add_instr(emit, Reg2Reg);
cpy->m_val2 = -SZ_INT;
regpushi(emit, (m_uint)code);
const Instr set_code = regseti(emit, (m_uint)code);
set_code->m_val2 = SZ_INT;
const m_uint offset = emit_code_offset(emit);
regseti(emit, offset);
const Instr regset = regseti(emit, offset);
regset->m_val2 = SZ_INT *2;
const Instr push = emit_add_instr(emit, RegPush);
push->m_val = SZ_INT *2;
const Instr prelude = emit_add_instr(emit, !GET_FLAG(code, builtin) ? FuncUsr : FuncMember);
prelude->m_val2 = 2;
prelude->m_val = SZ_INT;
Expand Down Expand Up @@ -573,7 +578,7 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, const Var_Decl va
if(missing_depth) {
const Instr push = emit_add_instr(emit, Reg2Reg);
push->m_val = -(1 + missing_depth) * SZ_INT;
regpop(emit, (missing_depth + 1) * SZ_INT);
regpop(emit, (missing_depth) * SZ_INT);
}
}
return GW_OK;
Expand Down Expand Up @@ -881,6 +886,8 @@ ANN m_bool emit_exp_call1(const Emitter emit, const Func f) {
m_uint val2 = back->m_val2;
back->opcode = eReg2Reg;
back->m_val = SZ_INT;
const Instr push = emit_add_instr(emit, RegPush);
push->m_val = SZ_INT;
const Instr instr = emit_add_instr(emit, (f_instr)(m_uint)exec);
instr->m_val = val;
instr->m_val2 = val2;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/func.c
Expand Up @@ -211,9 +211,9 @@ static OP_EMIT(opem_fptr_cast) {
fptr_instr(emit, cast->exp->type->e->d.func, 1);
if(GET_FLAG(cast->exp->type->e->d.func, member)) {
const Instr instr = emit_add_instr(emit, RegPop);
instr->m_val = SZ_INT*2;
instr->m_val = SZ_INT;
const Instr dup = emit_add_instr(emit, Reg2Reg);
dup->m_val2 = SZ_INT;
dup->m_val = -SZ_INT;
}
return GW_OK;
}
Expand Down
1 change: 0 additions & 1 deletion src/vm/vm.c
Expand Up @@ -362,7 +362,6 @@ ANN void vm_run(const VM* vm) { // lgtm [cpp/use-of-goto]
DISPATCH();
regtoreg:
*(m_uint*)(reg + (m_int)instr->m_val) = *(m_uint*)(reg + (m_int)instr->m_val2);
reg += SZ_INT;
DISPATCH()
regtoregaddr:
*(m_uint**)reg = &*(m_uint*)(reg-SZ_INT);
Expand Down

0 comments on commit 275301f

Please sign in to comment.