Commit 0e458c79 authored by Julian Kranz's avatar Julian Kranz

optimization configuration

parent 45513692
......@@ -44,7 +44,7 @@ enum flop {
FLOP_FMUL = 2
};
enum preservation {
enum optimization_configuration {
PRESERVATION_EVERYWHERE = 0,
PRESERVATION_BLOCK = 1,
PRESERVATION_CONTEXT = 2
......
......@@ -51,6 +51,7 @@ struct frontend {
obj_t (*pretty_arch_id)(state_t state, obj_t id);
obj_t (*pretty_arch_exception)(state_t state, obj_t id);
obj_t (*rreil_convert_sem_stmt_list)(state_t s, callbacks_t cbs, obj_t stmts);
obj_t (*optimization_config)(state_t state);
opt_result_t (*decode_translate_block_optimized)(state_t state, int_t config, int_t limit, int_t pres);
obj_t (*traverse_insn_list)(state_t state, obj_t insn_list, obj_t insns_init,
obj_t (*insn_cb)(state_t, obj_t, obj_t));
......
......@@ -121,6 +121,7 @@ static char gdsl_multiplex_frontend_get(struct frontend *frontend, void *dl) {
ADD_FUNCTION(translator, pretty_arch_id)
ADD_FUNCTION(translator, pretty_arch_exception)
ADD_FUNCTION(translator, rreil_convert_sem_stmt_list)
ADD_FUNCTION(translator, optimization_config)
ADD_FUNCTION(translator, decode_translate_block_optimized)
ADD_FUNCTION(translator, traverse_insn_list)
......
export decode-translate-block-optimized: (decoder-configuration, int, rreil-configuration) -> S opt-result <{} => {}>
export decode-translate-block-optimized: (decoder-configuration, int, optimization-configuration) -> S opt-result <{} => {}>
export traverse-insn-list: (insn_list, insn_list_obj, (insn_list_obj, insndata) -> insn_list_obj) -> insn_list_obj
export optimization-config : configuration[vec=optimization-configuration]
type optimization-configuration = |2|
val optimization-config =
conf '00' "block" "translate a basic block at a time" &*
conf '01' "liveness" "remove dead assignments" &*
conf '10' "inter-bb" "perform inter-basic block liveness analysis"
type insn_list_obj = INSN_LIST_OBJ
......@@ -45,12 +53,12 @@ type opt-result = {
rreil: sem_stmt_list
}
val decode-translate-block-optimized config limit rreil-config = do
val decode-translate-block-optimized config limit opt-config = do
update @{insns=INSNS_NIL};
rreil <- case rreil-config of
'00.': decode-translate-block-optimized-inner config limit SEM_PRESERVATION_EVERYWHERE
| '01.': decode-translate-block-optimized-inner config limit SEM_PRESERVATION_BLOCK
| '1..': decode-translate-block-optimized-inner config limit SEM_PRESERVATION_CONTEXT
rreil <- case opt-config of
'00': decode-translate-block-optimized-inner config limit SEM_PRESERVATION_EVERYWHERE
| '01': decode-translate-block-optimized-inner config limit SEM_PRESERVATION_BLOCK
| '10': decode-translate-block-optimized-inner config limit SEM_PRESERVATION_CONTEXT
end;
insns <- query $insns;
return {rreil=rreil, insns=insns}
......
......@@ -3,19 +3,11 @@ export decode-translate-single: (decoder-configuration) -> S sem_stmt_list <{ins
export decode-translate-super-block: (decoder-configuration, int) -> S translate-result <{insns: insn_list} => {insns: insn_list}>
export select_ins_count: S int <{ins_count: int} => {ins_count: int}>
export succ-pretty: (stmts_option, string) -> rope
export rreil-config : configuration[vec=rreil-configuration]
type rreil-configuration = |3|
val rreil-config =
conf '001' "block" "translate a basic block at a time" &*
conf '010' "liveness" "remove dead assignments" &*
conf '100' "inter-bb" "perform inter-basic block liveness analysis"
val decode-translate-block-headless config limit = do
insn <- decode config;
insns <- query $insns;
#Todo: Don't use state
update @{insns=INSNS_CONS {insn=insn, tl=insns}};
translate-block-single insn;
jmp <- query $foundJump;
......
......@@ -22,7 +22,7 @@
#define NANOS 1000000000LL
struct options {
enum preservation preservation;
enum optimization_configuration opt_config;
char elf;
char *file;
size_t offset;
......@@ -36,14 +36,14 @@ enum p_option {
static char args_parse(int argc, char **argv, struct options *options) {
options->elf = 0;
options->file = NULL;
options->preservation = PRESERVATION_EVERYWHERE;
options->opt_config = PRESERVATION_EVERYWHERE;
options->offset = 0;
options->length = 0;
struct option long_options[] = {{"elf", no_argument, NULL, OPTION_ELF},
{"file", required_argument, NULL, OPTION_FILE}, {"offset", required_argument, NULL, OPTION_FILE}, {"length",
required_argument, NULL, OPTION_LENGTH}, {"preserve", required_argument, NULL, OPTION_PRESERVATION}, {NULL, 0,
NULL, 0}};
struct option long_options[] = { { "elf", no_argument, NULL, OPTION_ELF }, { "file", required_argument, NULL,
OPTION_FILE }, { "offset", required_argument, NULL, OPTION_FILE }, { "length",
required_argument, NULL, OPTION_LENGTH }, { "preserve", required_argument, NULL, OPTION_PRESERVATION }, { NULL, 0,
NULL, 0 } };
while(1) {
int result = getopt_long(argc, argv, "", long_options, NULL);
......@@ -67,15 +67,15 @@ static char args_parse(int argc, char **argv, struct options *options) {
}
case OPTION_PRESERVATION: {
if(!strcmp("everywhere", optarg)) {
options->preservation = PRESERVATION_EVERYWHERE;
options->opt_config = PRESERVATION_EVERYWHERE;
break;
}
if(!strcmp("block", optarg)) {
options->preservation = PRESERVATION_BLOCK;
options->opt_config = PRESERVATION_BLOCK;
break;
}
if(!strcmp("context", optarg)) {
options->preservation = PRESERVATION_CONTEXT;
options->opt_config = PRESERVATION_CONTEXT;
break;
}
return 2;
......@@ -139,10 +139,10 @@ int main(int argc, char** argv) {
size_t last_offset = 0;
while(last_offset < options.length) {
obj_t rreil = gdsl_decode_translate_block_optimized(state, gdsl_config_default(state), gdsl_int_max(state),
options.preservation);
opt_result_t opt_result = gdsl_decode_translate_block_optimized(state, gdsl_config_default(state),
gdsl_int_max(state), options.opt_config);
string_t fmt = gdsl_merge_rope(state, gdsl_rreil_pretty(state, rreil));
string_t fmt = gdsl_merge_rope(state, gdsl_rreil_pretty(state, opt_result->rreil));
puts(fmt);
gdsl_reset_heap(state);
......
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