Commit e2b2af9d authored by Julian Kranz's avatar Julian Kranz
Browse files

Liveness

parent ec546a65
......@@ -20,6 +20,8 @@ specifications/x86/c/clang-sweep
specifications/x86/c/gcc-sweep
specifications/x86/c/tester
specifications/x86/c/liveness-test
specifications/x86/c/liveness-example.bin
specifications/x86/c/liveness-sweep
gdrr/.cproject
gdrr/.project
......
......@@ -2,7 +2,8 @@
#./gdsl @MLton fixed-heap 6g -- "specifications/basis/bbtree.ml" "specifications/rreil/rreil.ml" "specifications/rreil/fmap.ml" "specifications/x86/x86.ml" "specifications/x86/x86-rreil-registermapping.ml" "specifications/x86/x86-pretty.ml" "specifications/rreil/rreil-pretty.ml" "specifications/x86/x86-rreil-translator.ml" "specifications/x86/x86-rreil-translator-a-l.ml" "specifications/x86/x86-rreil-translator-m-z.ml"
#./gdsl @MLton fixed-heap 6g -- "specifications/rreil/rreil.ml" "specifications/rreil/rreil-pretty.ml" "specifications/rreil/rreil-liveness-test.ml"
./gdsl @MLton fixed-heap 6g -- "specifications/rreil/rreil.ml" "specifications/rreil/rreil-pretty.ml" "specifications/rreil/rreil-liveness-test.ml" "specifications/rreil/rreil-liveness.ml" "specifications/basis/bbtree.ml" "specifications/rreil/fmap.ml" "specifications/x86/x86-rreil-registermapping.ml" "specifications/x86/x86.ml"
#./gdsl @MLton fixed-heap 6g -- "specifications/rreil/rreil.ml" "specifications/rreil/rreil-pretty.ml" "specifications/rreil/rreil-liveness-test.ml" "specifications/rreil/rreil-liveness.ml" "specifications/basis/bbtree.ml" "specifications/rreil/fmap.ml" "specifications/x86/x86-rreil-registermapping.ml" "specifications/x86/x86.ml"
./gdsl @MLton fixed-heap 6g -- "specifications/basis/bbtree.ml" "specifications/rreil/rreil.ml" "specifications/rreil/fmap.ml" "specifications/x86/x86.ml" "specifications/x86/x86-rreil-registermapping.ml" "specifications/x86/x86-pretty.ml" "specifications/rreil/rreil-pretty.ml" "specifications/x86/x86-rreil-translator.ml" "specifications/x86/x86-rreil-translator-a-l.ml" "specifications/x86/x86-rreil-translator-m-z.ml" "specifications/rreil/rreil-liveness.ml" "specifications/x86/x86-liveness.ml"
#[ $? -eq 0 ] && clang -fno-inline -O -c dis.c -o dis.o
[ $? -eq 0 ] && clang -fPIC -c dis.c -o dis.o
......
......@@ -16,6 +16,9 @@ clang-tester:
clang-sweep:
clang -pipe -O3 -Wall -static -I. -I../../.. -Wfatal-errors sweep.c ../../../dis.o -DRELAXEDFATAL -o clang-sweep
liveness-sweep:
clang -pipe -O3 -Wall -static -I. -I../../.. -Wfatal-errors liveness-sweep.c ../../../dis.o -DRELAXEDFATAL -o liveness-sweep
gcc-sweep:
gcc -pipe -O3 -Wall -static -I. -I../../.. -Wfatal-errors sweep.c ../../../dis.o -DRELAXEDFATAL -o gcc-sweep
......
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int a;
int b;
int c;
start:
a = 12;
b = 55;
c = 99;
a = b*c + 66;
b = a - c;
c = (a + b)*(c - b);
a = 3 + 77*c;
__asm__ ("jmp label\nlabel:\n");
end:;
FILE *f = fopen("liveness-example.bin", "w");
if(!f)
return 1;
for(void *i = &&start; i < &&end; i++)
fwrite(i, 1, 1, f);
fclose(f);
return 0;
}
/* vim:cindent:ts=2:sw=2:expandtab */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <dis.h>
#include <sys/resource.h>
int main (int argc, char** argv) {
const rlim_t kStackSize = 64L * 1024L * 1024L; // min stack size = 64 Mb
struct rlimit rl;
int result;
result = getrlimit(RLIMIT_STACK, &rl);
if (result == 0)
{
if (rl.rlim_cur < kStackSize)
{
rl.rlim_cur = kStackSize;
result = setrlimit(RLIMIT_STACK, &rl);
if (result != 0)
{
fprintf(stderr, "setrlimit returned result = %d\n", result);
}
}
}
size_t size = 16*1024*1024;
char fmt[size];
char fmt_state[size];
__obj insn;
if(argc != 4) {
printf("Usage: sweep file offset length\n");
return 1;
}
size_t offset;
sscanf(argv[2], "%zu", &offset);
size_t length;
sscanf(argv[3], "%zu", &length);
FILE *f = fopen(argv[1], "r");
if(!f) {
printf("Unable to open file.\n");
return 1;
}
fseek(f, offset, SEEK_SET);
size_t buffer_size = 16*length + 15;
unsigned char *buffer = (unsigned char*)malloc(buffer_size);
size_t buffer_length = fread(buffer, 1, buffer_size, f);
__obj state = __createState(buffer, buffer_length, 0, 0);
//uint64_t consumed = 0;
__obj stack = __runMonadicNoArg(__translateBlock__, &state);
//consumed += __decode(__decode__,buffer+consumed,buffer_length - consumed,&insn);
//printf("Consumed: %lu\n", consumed);
if (___isNil(stack))
__fatal("Translate failed");
else {
__obj greedy = __runMonadicOneArg(__liveness__, &state, stack);
__obj insns = __RECORD_SELECT(state, ___live);
//__obj r = __translate(__translate__,insn);
if(___isNil(greedy))
__fatal("Translate failed");
else {
__pretty(__lv_pretty__,greedy,fmt_state,size);
__pretty(__rreil_pretty__,stack,fmt,size);
puts(fmt_state);
puts(fmt);
}
}
return (1);
}
export = liveness
val liveness stack = do
live-registers <- registers-live-map;
lv-state <- lv-analyze live-registers stack;
return lv-state.greedy
end
......@@ -2209,5 +2209,6 @@ val translateBlock = do
# the type checker is seriously broken when it comes to infinite recursion,
# I cannot as of yet reproduce this bug
update @{ptrsz=0, reg/opcode='000', rm='000', mod='00', vexm='00001', vexv='0000', vexl='0', vexw='0'};
transBlock
stmts <- transBlock;
return (rreil-stmts-rev stmts)
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment