Commit bf909203 authored by Gaurav Kukreja's avatar Gaurav Kukreja

Fixed a major bug in computeFlow functionality for cfg class.

Added a few example files to map_cfg
Changed .gitignore
Signed-off-by: Gaurav Kukreja's avatarGaurav Kukreja <gaurav@gauravk.in>
parent 244cbce2
...@@ -6,6 +6,6 @@ ...@@ -6,6 +6,6 @@
*.tmp *.tmp
*.objdump *.objdump
*.swp *.swp
*.project *.pyc
*.pydevproject *.gdbo
*.gdbx
...@@ -29,7 +29,7 @@ app: ...@@ -29,7 +29,7 @@ app:
$(MAKE) -C $$e/$(APPDIR) PHASE=final all; \ $(MAKE) -C $$e/$(APPDIR) PHASE=final all; \
done done
#run: run_ir2c # IR2C Targets
ir2c: ir2c:
set -e; for e in $(EXAMPLES); do \ set -e; for e in $(EXAMPLES); do \
...@@ -61,7 +61,19 @@ clean: ...@@ -61,7 +61,19 @@ clean:
$(MAKE) APPBASEDIR=$$e clean_ir2c; \ $(MAKE) APPBASEDIR=$$e clean_ir2c; \
done done
help:
@printf "\nHelp information for running project\n"
@printf "\n\ttarget: Operation Performed\n"
@printf "\nGeneral Targets\n"
@printf "\thelp: Display this message\n"
@printf "\tall: Compile all the benchmarks\n"
@printf "\nIR2C Targets\n"
@printf "\tir2c: For all benchmarks run_ir2c, compile_ir2c and test_ir2c\n"
@printf "\trun_ir2c: Needs variable APPBASEDIR. Runs ir2c code, and generates Intermediate Source Code\n"
@printf "\tcompile_ir2c: Needs variable APPBASEDIR. Compile ISC.\n"
@printf "\ttest: Calls test target declared in ir_c/Makefile in each benchmark\n"
@printf "\nmap_cfg Targets\n"
@printf "\thelp: Display this message\n"
@printf "\n\n"
Host Compiled Simulation for Timing and Power Estimation
********************************************************************************
The project is divided into following sub-projects.
1. ir_c : Intermediate Code to C code conversion.
2. cache_simulator : Cache Simulator code in C, which will be called from
instrumented benchmark code.
3. map_cfg : Python project to create a mapping between basic blocks in ISC
(Intermediate Source Code) and binary (objdump).
********************************************************************************
Project Organization
root (MYBASEDIR) : Global Root of the project.
- ir2c (IR2CDIR) : Directory containing the IR to C conversion code.
- map_cfg (MAPDIR) : Directory containing the code to match basic blocks.
- examples : Directory containing the code for benchmarks
********************************************************************************
To run the project,
1. Change to the "examples" directory.
2. The Makefile in examples/ offers following options.
a.
\ No newline at end of file
include ../../Makefile.macros include ../../Makefile.macros
TREEDUMP = -fdump-tree-all-blocks-details TREEDUMP = -fdump-tree-all-blocks-details
OPT = -O2 #is O3 in original MiBench download. Use O3 for final testing OPT = -g -O2 #is O3 in original MiBench download. Use O3 for final testing
DEBUG = -g DEBUG = -g
IRDUMP = 0 #defined - dump IR files, undefined - don't. IRDUMP = 0 #defined - dump IR files, undefined - don't.
#PRINT = 1 #if defined and PHASE defined, include soft-float lib. fprintf uses floating point #PRINT = 1 #if defined and PHASE defined, include soft-float lib. fprintf uses floating point
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
include ../../Makefile.macros include ../../Makefile.macros
TREEDUMP = -fdump-tree-all-blocks-details TREEDUMP = -fdump-tree-all-blocks-details
OPT = -O2 #is O3 in original MiBench download. Use O3 for final testing OPT = -g -O2 #is O3 in original MiBench download. Use O3 for final testing
DEBUG = -g DEBUG = -g
#IRDUMP = 1 #defined - dump IR files, undefined - don't. #IRDUMP = 1 #defined - dump IR files, undefined - don't.
#PRINT = 1 #if defined and PHASE defined, include soft-float lib. fprintf uses floating point #PRINT = 1 #if defined and PHASE defined, include soft-float lib. fprintf uses floating point
......
...@@ -89,7 +89,27 @@ class ControlFlowGraph: ...@@ -89,7 +89,27 @@ class ControlFlowGraph:
if succBlock not in self.dft_stack: if succBlock not in self.dft_stack:
self.dft(succBlock) self.dft(succBlock)
else: else:
# Awesome fix of an error identified during test
# if a closed loop occurs consisting of multiple blocks, we
# need to remove all edges of the loop, because removing just
# the last edge will lead to flow being mis-calculated.
# Remove edge from blockIndex to succBlock which has already
# visited.
# Add the blockIndex to a queue.
# Loop until queue is empty.
# Pop from queue in currBlock.
# if currBlock does not have any other successor,
# for each predecessor of currBlock, predBlock
# remove edge between predBlock and currBlock
# Add predBlock to queue
self.listBackEdges.append(self.findEdgeIndex(blockIndex, succBlock)) self.listBackEdges.append(self.findEdgeIndex(blockIndex, succBlock))
queueBlocksBackEdgesCheck = deque([blockIndex])
while len(queueBlocksBackEdgesCheck) != 0:
currBlock = queueBlocksBackEdgesCheck.popleft()
if len(self.successorBlocksWOBackEdges(currBlock)) == 0:
for predBlock in self.predecessorBlocksWOBackEdges(currBlock):
self.listBackEdges.append(self.findEdgeIndex(predBlock, currBlock))
queueBlocksBackEdgesCheck.append(predBlock)
self.dft_stack.pop() self.dft_stack.pop()
...@@ -101,8 +121,6 @@ class ControlFlowGraph: ...@@ -101,8 +121,6 @@ class ControlFlowGraph:
self.dft_stack = [] self.dft_stack = []
self.dft(0) self.dft(0)
self.listBackEdges = list(set(self.listBackEdges)) self.listBackEdges = list(set(self.listBackEdges))
for edgeIndex in self.listBackEdges:
print self.listEdges[edgeIndex].fromBlockIndex, self.listEdges[edgeIndex].toBlockIndex
return self.listBackEdges return self.listBackEdges
def computeFlow(self): def computeFlow(self):
......
...@@ -9,7 +9,7 @@ from cfg import * ...@@ -9,7 +9,7 @@ from cfg import *
re_sectionStart = re.compile('Disassembly of section .(.*):') re_sectionStart = re.compile('Disassembly of section .(.*):')
re_funcDef = re.compile('\s*([0-9a-f]*)\s*<(.*)>:') re_funcDef = re.compile('\s*([0-9a-f]*)\s*<(.*)>:')
re_instruction = re.compile('\s*([0-9a-f]*):\s*[0-9a-f]*\s*(.*)') re_instruction = re.compile('\s*([0-9a-f]*):\s*[0-9a-f]*\s*(.*)')
re_branchInst = re.compile('\s*(b(?:l|x|lx|xj)?(?:eq|ne|mi|pl|hi|ls|ge|lt|gt|le)?)\s*([0-9a-f]*)\s*<(.*)>') re_branchInst = re.compile('\s*(b(?!ic)(?:l|x|lx|xj)?(?:eq|ne|mi|pl|hi|ls|ge|lt|gt|le)?)\s*([0-9a-f]*)\s*<(.*)>')
re_unconditionalBranchInst = re.compile('\s*(b(?:l|x|lx|xj)?)\s*([0-9a-f]*)\s*<(.*)>') re_unconditionalBranchInst = re.compile('\s*(b(?:l|x|lx|xj)?)\s*([0-9a-f]*)\s*<(.*)>')
re_conditionalBranchInst = re.compile('\s*(b(?:l|x|lx|xj)?(?:eq|ne|mi|pl|hi|ls|ge|lt|gt|le))\s*([0-9a-f]*)\s*<(.*)>') re_conditionalBranchInst = re.compile('\s*(b(?:l|x|lx|xj)?(?:eq|ne|mi|pl|hi|ls|ge|lt|gt|le))\s*([0-9a-f]*)\s*<(.*)>')
re_returnInst = re.compile('\s*(bx)\s*(lr)') re_returnInst = re.compile('\s*(bx)\s*(lr)')
...@@ -43,7 +43,6 @@ def parse_binary(fileName, listFunctionNames = []): ...@@ -43,7 +43,6 @@ def parse_binary(fileName, listFunctionNames = []):
Returns a list of all the functions defined in the objdump, along with the Returns a list of all the functions defined in the objdump, along with the
control flow graph of each of the function. control flow graph of each of the function.
''' '''
# State Management Variables # State Management Variables
inTextSection = 0 # is 1, when inside Text Section inTextSection = 0 # is 1, when inside Text Section
inFuncBody = 0 # is 1, when inside Function Body inFuncBody = 0 # is 1, when inside Function Body
...@@ -163,8 +162,13 @@ def parse_binary(fileName, listFunctionNames = []): ...@@ -163,8 +162,13 @@ def parse_binary(fileName, listFunctionNames = []):
listCurrFuncBlockEndLineNum.sort() listCurrFuncBlockEndLineNum.sort()
# Ensure length of lists is equal # Ensure length of lists is equal
if len(listCurrFuncBlockStartLineNum) != len(listCurrFuncBlockEndLineNum): # if len(listCurrFuncBlockStartLineNum) != len(listCurrFuncBlockEndLineNum):
raise ParseError("Length of lists of block start and end line numbers do not match for function %s" % (currFuncName)) # raise ParseError("Length of lists of block start and end line numbers do not match for function %s" % (currFuncName))
# TODO: STUPID HACK !!!!
while len(listCurrFuncBlockStartLineNum) < len(listCurrFuncBlockEndLineNum):
del listCurrFuncBlockEndLineNum[-1]
while len(listCurrFuncBlockStartLineNum) > len(listCurrFuncBlockEndLineNum):
del listCurrFuncBlockStartLineNum[-1]
# Create List of Blocks # Create List of Blocks
listBlocks = [] listBlocks = []
...@@ -242,12 +246,13 @@ def parse_binary(fileName, listFunctionNames = []): ...@@ -242,12 +246,13 @@ def parse_binary(fileName, listFunctionNames = []):
listCurrFuncBlockEndLineNum = [] listCurrFuncBlockEndLineNum = []
listCurrFuncBlockStartAddress = [] listCurrFuncBlockStartAddress = []
listCurrFuncBlockEndAddress = [] listCurrFuncBlockEndAddress = []
lineNumForAddress = {} #lineNumForAddress = {}
branchInstAtLine = {} branchInstAtLine = {}
returnInstAtLine = {} returnInstAtLine = {}
functionCallAtLine = {} functionCallAtLine = {}
return listFunctions file.close()
return listFunctions, lineNumForAddress
def print_debug_binary(listFunctions): def print_debug_binary(listFunctions):
......
...@@ -10,13 +10,13 @@ from cfg import * ...@@ -10,13 +10,13 @@ from cfg import *
# group(1) is function Name # group(1) is function Name
# if group(2) == "){", single line definition # if group(2) == "){", single line definition
# elif group(2) == $, multi line definition # elif group(2) == $, multi line definition
re_funcDef = re.compile('(?:\w*\s+)*\**(\w+)\s*\([\w\s,*]*($|\)\s*\{)') re_funcDef = re.compile('(?:\w*\s+)*\**(\w+)\s*\([,\s\w&\[\]\*]*($|\)\s*\{)')
re_funcDefArgLine = re.compile('[\w\s,]*($|\)\s*\{)') re_funcDefArgLine = re.compile('[,\s\w&\[\]\*]*($|\)\s*\{)')
re_basicBlockLabel = re.compile('\s*(\w*bb_[0-9]*):') re_basicBlockLabel = re.compile('\s*(\w*bb_[0-9]*):')
re_basicBlockStart = re.compile('\s*//\s*#\s*PRED:./*') re_basicBlockStart = re.compile('\s*//\s*#\s*PRED:./*')
re_basicBlockEnd = re.compile('\s*//\s*#\s*SUCC:./*') re_basicBlockEnd = re.compile('\s*//\s*#\s*SUCC:./*')
re_gotoLine = re.compile('\s*goto\s*(\w*bb_[0-9]*);') re_gotoLine = re.compile('\s*goto\s*(\w*bb_[0-9]*);')
re_funcCallLine = re.compile('\s*(\w*)\s*\([\w\s,]*\);') re_funcCallLine = re.compile('\s*(\w*)\s*\([,\s\w&\[\]\*]*\);')
re_returnLine = re.compile('\s*return\s*.*;') re_returnLine = re.compile('\s*return\s*.*;')
re_funcDefEnd = re.compile('\s*\}') re_funcDefEnd = re.compile('\s*\}')
...@@ -223,9 +223,9 @@ def parse_isc(fileName): ...@@ -223,9 +223,9 @@ def parse_isc(fileName):
listCurrFuncBBEdges = [] listCurrFuncBBEdges = []
continue continue
file.close()
return listFunctions return listFunctions
def print_debug_isc(listFunctions): def print_debug_isc(listFunctions):
for func in listFunctions: for func in listFunctions:
print("\nFileName : %s" % (func.fileName)) print("\nFileName : %s" % (func.fileName))
......
/***********************************************************
Intermediate representation of
adpcm/app_dir/adpcm.c
Converted by ir2c v0.1
***********************************************************/
#include <limits.h>
#include <stdint.h>
#include "ir2c.h"
#include "adpcm.h"
#include <stdio.h> /*DBG*/
#ifndef __STDC__
#define signed
#endif
/* Intel ADPCM step variation table */
static int indexTable[16] = {
-1, -1, -1, -1, 2, 4, 6, 8,
-1, -1, -1, -1, 2, 4, 6, 8,
};
static int stepsizeTable[89] = {
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
};
void adpcm_coder(short indata[], char outdata[], int len, struct adpcm_state *state) {
int valpred_58;
int delta_56;
int step_55;
int step_54;
int valpred_53;
uintptr_t ivtmp_47;
int bufferstep;
int outputbuffer;
int index;
int vpdiff;
int valpred;
int step;
int diff;
int delta;
int sign;
signed char * outp;
adpcm_coderbb_2:
// # PRED: ENTRY [100.0%] (fallthru,exec)
valpred = state->valprev;
index = state->index;
step = stepsizeTable[index];
if (len > 0)
goto adpcm_coderbb_3;
else
goto adpcm_coderbb_24;
// # SUCC: 3 [91.0%] (true,exec) 24 [9.0%] (false,exec)
adpcm_coderbb_3:
// # PRED: 2 [91.0%] (true,exec)
outp = outdata;
ivtmp_47 = 0;
bufferstep = 1;
// # SUCC: 4 [100.0%] (fallthru,exec)
adpcm_coderbb_4:
// # PRED: 21 [91.0%] (dfs_back,true,exec) 3 [100.0%] (fallthru,exec)
diff = (int) *(short int *)((uintptr_t)indata + (uintptr_t)ivtmp_47) - valpred;
if (diff < 0)
goto adpcm_coderbb_5;
else
goto adpcm_coderbb_25;
// # SUCC: 5 [27.0%] (true,exec) 25 [73.0%] (false,exec)
adpcm_coderbb_25:
// # PRED: 4 [73.0%] (false,exec)
sign = 0;
goto adpcm_coderbb_6;
// # SUCC: 6 [100.0%] (fallthru)
adpcm_coderbb_5:
// # PRED: 4 [27.0%] (true,exec)
diff = -diff;
sign = 8;
// # SUCC: 6 [100.0%] (fallthru,exec)
adpcm_coderbb_6:
// # PRED: 25 [100.0%] (fallthru) 5 [100.0%] (fallthru,exec)
vpdiff = step >> 3;
if (diff >= step)
goto adpcm_coderbb_7;
else
goto adpcm_coderbb_26;
// # SUCC: 7 [50.0%] (true,exec) 26 [50.0%] (false,exec)
adpcm_coderbb_26:
// # PRED: 6 [50.0%] (false,exec)
delta = 0;
goto adpcm_coderbb_8;
// # SUCC: 8 [100.0%] (fallthru)
adpcm_coderbb_7:
// # PRED: 6 [50.0%] (true,exec)
diff = diff - step;
vpdiff = vpdiff + step;
delta = 4;
// # SUCC: 8 [100.0%] (fallthru,exec)
adpcm_coderbb_8:
// # PRED: 26 [100.0%] (fallthru) 7 [100.0%] (fallthru,exec)
step_54 = step >> 1;
if (diff >= step_54)
goto adpcm_coderbb_9;
else
goto adpcm_coderbb_10;
// # SUCC: 9 [50.0%] (true,exec) 10 [50.0%] (false,exec)
adpcm_coderbb_9:
// # PRED: 8 [50.0%] (true,exec)
delta = delta | 2;
diff = diff - step_54;
vpdiff = vpdiff + step_54;
// # SUCC: 10 [100.0%] (fallthru,exec)
adpcm_coderbb_10:
// # PRED: 8 [50.0%] (false,exec) 9 [100.0%] (fallthru,exec)
step_55 = step_54 >> 1;
if (diff >= step_55)
goto adpcm_coderbb_11;
else
goto adpcm_coderbb_12;
// # SUCC: 11 [50.0%] (true,exec) 12 [50.0%] (false,exec)
adpcm_coderbb_11:
// # PRED: 10 [50.0%] (true,exec)
delta = delta | 1;
vpdiff = vpdiff + step_55;
// # SUCC: 12 [100.0%] (fallthru,exec)
adpcm_coderbb_12:
// # PRED: 10 [50.0%] (false,exec) 11 [100.0%] (fallthru,exec)
if (sign != 0)
goto adpcm_coderbb_13;
else
goto adpcm_coderbb_14;
// # SUCC: 13 [50.0%] (true,exec) 14 [50.0%] (false,exec)
adpcm_coderbb_13:
// # PRED: 12 [50.0%] (true,exec)
valpred_53 = valpred - vpdiff;
goto adpcm_coderbb_15;
// # SUCC: 15 [100.0%] (fallthru,exec)
adpcm_coderbb_14:
// # PRED: 12 [50.0%] (false,exec)
valpred_53 = vpdiff + valpred;
// # SUCC: 15 [100.0%] (fallthru,exec)
adpcm_coderbb_15:
// # PRED: 13 [100.0%] (fallthru,exec) 14 [100.0%] (fallthru,exec)
valpred_58 = (valpred_53>-32768)?valpred_53:-32768;
valpred = (valpred_58<32767)?valpred_58:32767;
delta_56 = delta | sign;
index = indexTable[delta_56] + index;
if (index < 0)
goto adpcm_coderbb_27;
else
goto adpcm_coderbb_16;
// # SUCC: 27 [27.0%] (true,exec) 16 [73.0%] (false,exec)
adpcm_coderbb_27:
// # PRED: 15 [27.0%] (true,exec)
index = 0;
goto adpcm_coderbb_17;
// # SUCC: 17 [100.0%] (fallthru)
adpcm_coderbb_16:
// # PRED: 15 [73.0%] (false,exec)
if (index > 88)
goto adpcm_coderbb_28;
else
goto adpcm_coderbb_17;
// # SUCC: 28 [68.5%] (true,exec) 17 [31.5%] (false,exec)
adpcm_coderbb_28:
// # PRED: 16 [68.5%] (true,exec)
index = 88;
goto adpcm_coderbb_18;
// # SUCC: 18 [100.0%] (fallthru)
adpcm_coderbb_17:
// # PRED: 16 [31.5%] (false,exec) 27 [100.0%] (fallthru)
// # SUCC: 18 [100.0%] (fallthru,exec)
adpcm_coderbb_18:
// # PRED: 17 [100.0%] (fallthru,exec) 28 [100.0%] (fallthru)
step = stepsizeTable[index];
if (bufferstep != 0)
goto adpcm_coderbb_19;
else
goto adpcm_coderbb_20;
// # SUCC: 19 [50.0%] (true,exec) 20 [50.0%] (false,exec)
adpcm_coderbb_19:
// # PRED: 18 [50.0%] (true,exec)
outputbuffer = delta_56 << 4 & 255;
goto adpcm_coderbb_21;
// # SUCC: 21 [100.0%] (fallthru,exec)
adpcm_coderbb_20:
// # PRED: 18 [50.0%] (false,exec)
*outp = (signed char) delta_56 & 15 | (signed char) outputbuffer;
outp = (uintptr_t)outp + 1;
// # SUCC: 21 [100.0%] (fallthru,exec)
adpcm_coderbb_21:
// # PRED: 19 [100.0%] (fallthru,exec) 20 [100.0%] (fallthru,exec)
bufferstep = bufferstep ^ 1;
len = len + -1;
ivtmp_47 = ivtmp_47 + 2;
if (len != 0)
goto adpcm_coderbb_4;
else
goto adpcm_coderbb_22;
// # SUCC: 4 [91.0%] (dfs_back,true,exec) 22 [9.0%] (false,exec)
adpcm_coderbb_22:
// # PRED: 21 [9.0%] (false,exec)
if (bufferstep == 0)
goto adpcm_coderbb_23;
else
goto adpcm_coderbb_24;
// # SUCC: 23 [67.0%] (true,exec) 24 [33.0%] (false,exec)
adpcm_coderbb_23:
// # PRED: 22 [67.0%] (true,exec)
*outp = (signed char) (signed char) outputbuffer;
// # SUCC: 24 [100.0%] (fallthru,exec)
adpcm_coderbb_24:
// # PRED: 22 [33.0%] (false,exec) 23 [100.0%] (fallthru,exec) 2 [9.0%] (false,exec)
state->valprev = (short int) (short int) valpred;
state->index = (char) (char) index;
return;
// # SUCC: EXIT [100.0%]
}
void adpcm_decoder(char indata[], short int outdata[], int len, struct adpcm_state *state) {
int valpred_113;
int delta_112;
int valpred_111;
uintptr_t ivtmp_101;
short int prephitmp_86;
int bufferstep;
int inputbuffer;
int index;
int vpdiff;
int valpred;
int step;
int delta;
signed char * inp;
adpcm_decoderbb_2:
// # PRED: ENTRY [100.0%] (fallthru,exec)
valpred_111 = state->valprev;
index = state->index;
step = stepsizeTable[index];
if (len > 0)
goto adpcm_decoderbb_4;
else
goto adpcm_decoderbb_3;
// # SUCC: 4 [91.0%] (true,exec) 3 [9.0%] (false,exec)
adpcm_decoderbb_3:
// # PRED: 2 [9.0%] (false,exec)
prephitmp_86 = (short int) valpred_111;
goto adpcm_decoderbb_22;
// # SUCC: 22 [100.0%] (fallthru,exec)
adpcm_decoderbb_4:
// # PRED: 2 [91.0%] (true,exec)
inp = indata;
ivtmp_101 = 0;
bufferstep = 0;
// # SUCC: 5 [100.0%] (fallthru,exec)
adpcm_decoderbb_5:
// # PRED: 21 [100.0%] (fallthru,dfs_back,exec) 4 [100.0%] (fallthru,exec)
if (bufferstep != 0)
goto adpcm_decoderbb_6;
else
goto adpcm_decoderbb_7;
// # SUCC: 6 [50.0%] (true,exec) 7 [50.0%] (false,exec)
adpcm_decoderbb_6:
// # PRED: 5 [50.0%] (true,exec)
delta = inputbuffer & 15;
goto adpcm_decoderbb_8;
// # SUCC: 8 [100.0%] (fallthru,exec)
adpcm_decoderbb_7:
// # PRED: 5 [50.0%] (false,exec)
inputbuffer = (int) *inp;
inp = (uintptr_t)inp + 1;
delta = inputbuffer >> 4 & 15;
// # SUCC: 8 [100.0%] (fallthru,exec)
adpcm_decoderbb_8:
// # PRED: 6 [100.0%] (fallthru,exec) 7 [100.0%] (fallthru,exec)
index = indexTable[delta] + index;
if (index < 0)
goto adpcm_decoderbb_23;
else
goto adpcm_decoderbb_9;
// # SUCC: 23 [27.0%] (true,exec) 9 [73.0%] (false,exec)
adpcm_decoderbb_23:
// # PRED: 8 [27.0%] (true,exec)
index = 0;
goto adpcm_decoderbb_10;
// # SUCC: 10 [100.0%] (fallthru)
adpcm_decoderbb_9:
// # PRED: 8 [73.0%] (false,exec)
if (index > 88)
goto adpcm_decoderbb_24;
else
goto adpcm_decoderbb_10;
// # SUCC: 24 [68.5%] (true,exec) 10 [31.5%] (false,exec)
adpcm_decoderbb_24:
// # PRED: 9 [68.5%] (true,exec)
index = 88;
goto adpcm_decoderbb_11;
// # SUCC: 11 [100.0%] (fallthru)
adpcm_decoderbb_10:
// # PRED: 9 [31.5%] (false,exec) 23 [100.0%] (fallthru)
// # SUCC: 11 [100.0%] (fallthru,exec)
adpcm_decoderbb_11:
// # PRED: 10 [100.0%] (fallthru,exec) 24 [100.0%] (fallthru)
delta_112 = delta & 7;
vpdiff = step >> 3;
if (delta_112 & 4 != 0)
goto adpcm_decoderbb_12;
else
goto adpcm_decoderbb_13;
// # SUCC: 12 [50.0%] (true,exec) 13 [50.0%] (false,exec)
adpcm_decoderbb_12:
// # PRED: 11 [50.0%] (true,exec)
vpdiff = vpdiff + step;
// # SUCC: 13 [100.0%] (fallthru,exec)
adpcm_decoderbb_13:
// # PRED: 11 [50.0%] (false,exec) 12 [100.0%] (fallthru,exec)
if (delta_112 & 2 != 0)
goto adpcm_decoderbb_14;
else
goto adpcm_decoderbb_15;
// # SUCC: 14 [50.0%] (true,exec) 15 [50.0%] (false,exec)
adpcm_decoderbb_14:
// # PRED: 13 [50.0%] (true,exec)
vpdiff = vpdiff + (step >> 1);
// # SUCC: 15 [100.0%] (fallthru,exec)
adpcm_decoderbb_15:
// # PRED: 13 [50.0%] (false,exec) 14 [100.0%] (fallthru,exec)
if (delta_112 & 1 != 0)
goto adpcm_decoderbb_16;
else
goto adpcm_decoderbb_17;
// # SUCC: 16 [50.0%] (true,exec) 17 [50.0%] (false,exec)
adpcm_decoderbb_16:
// # PRED: 15 [50.0%] (true,exec)
vpdiff = vpdiff + (step >> 2);
// # SUCC: 17 [100.0%] (fallthru,exec)
adpcm_decoderbb_17:
// # PRED: 15 [50.0%] (false,exec) 16 [100.0%] (fallthru,exec)
if (delta & 8 != 0)
goto adpcm_decoderbb_18;
else
goto adpcm_decoderbb_19;
// # SUCC: 18 [50.0%] (true,exec) 19 [50.0%] (false,exec)
adpcm_decoderbb_18:
// # PRED: 17 [50.0%] (true,exec)
valpred = valpred_111 - vpdiff;
goto adpcm_decoderbb_20;
// # SUCC: 20 [100.0%] (fallthru,exec)
adpcm_decoderbb_19:
// # PRED: 17 [50.0%] (false,exec)
valpred = vpdiff + valpred_111;
// # SUCC: 20 [100.0%] (fallthru,exec)
adpcm_decoderbb_20:
// # PRED: 18 [100.0%] (fallthru,exec) 19 [100.0%] (fallthru,exec)
valpred_113 = (valpred>-32768)?valpred:-32768;
valpred_111 = (valpred_113<32767)?valpred_113:32767;
step = stepsizeTable[index];
prephitmp_86 = (short int) valpred_111;
*(short int *)((uintptr_t)outdata + (uintptr_t)ivtmp_101) = prephitmp_86;
len = len + -1;
ivtmp_101 = ivtmp_101 + 2;
if (len != 0)
goto adpcm_decoderbb_21;
else
goto adpcm_decoderbb_22;
// # SUCC: 21 [91.0%] (true,exec) 22 [9.0%] (false,exec)
adpcm_decoderbb_21:
// # PRED: 20 [91.0%] (true,exec)
bufferstep = bufferstep ^ 1;
goto adpcm_decoderbb_5;
// # SUCC: 5 [100.0%] (fallthru,dfs_back,exec)
adpcm_decoderbb_22:
// # PRED: 20 [9.0%] (false,exec) 3 [100.0%] (fallthru,exec)
state->valprev = prephitmp_86;
state->index = (char) (char) index;
return;
// # SUCC: EXIT [100.0%]
}
/***********************************************************
Intermediate representation of
adpcm/app_dir/my_ctop.c
Converted by ir2c v0.1
***********************************************************/
#include <limits.h>
#include <stdint.h>
#include "ir2c.h"
/*
** Timing - Test timing on adpcm coder and decoder.
**
** The program creates 10Kb garbage, and runs the compressor and
** the decompressor on it.
*/
#include <stdio.h>
#include "adpcm.h"
#include "in_small.h"
//#include "in_large.h"
#include "my_variables.h"
#define DATASIZE 10*1024 /* Data block size */
//ARR_SIZE is the number of short type elements in
//input data array. defined in in_data_small.h
//unsigned int ARR_SIZE = 13305601;
//unsigned int ARR_SIZE = 684433;
short int pcmdata[DATASIZE];
char adpcmdata[DATASIZE/2];
struct adpcm_state coder_1_state;
int main() {
long unsigned int end_62;
long unsigned int end_61;
long unsigned int end_60;
int i_59;
long unsigned int start_56;
uintptr_t ivtmp_50;
int D_2245;
uintptr_t ivtmp_44;
long unsigned int count;
long unsigned int end;
long unsigned int start;
long unsigned int j;
int i;
unsigned int ARR_SIZE_0;
mainbb_2:
// # PRED: ENTRY [100.0%] (fallthru,exec)
ARR_SIZE_0 = ARR_SIZE;
j = ARR_SIZE_0 / 10240;
if (j != 0)
goto mainbb_13;
else
goto mainbb_7;
// # SUCC: 13 [91.0%] (true,exec) 7 [9.0%] (false,exec)
mainbb_13:
// # PRED: 2 [91.0%] (true,exec)
end_61 = 0;
count = 0;
// # SUCC: 3 [100.0%] (fallthru)
mainbb_3:
// # PRED: 13 [100.0%] (fallthru) 14 [100.0%] (fallthru)
end_62 = end_61 + 10240;
if (end_61 < end_62)
goto mainbb_4;
else
goto mainbb_6;
// # SUCC: 4 [99.0%] (true,exec) 6 [1.0%] (false,exec)
mainbb_4:
// # PRED: 3 [99.0%] (true,exec)
i_59 = (int) end_61;
ivtmp_50 = (uintptr_t)&in_Data[i_59];
end_60 = end_61;
// # SUCC: 5 [100.0%] (fallthru,exec)
mainbb_5:
// # PRED: 5 [99.0%] (dfs_back,true,exec) 4 [100.0%] (fallthru,exec)
pcmdata[end_60 - end_61] = *(short int*)((uintptr_t)ivtmp_50);
i_59 = i_59 + 1;
end_60 = (long unsigned int) i_59;
ivtmp_50 = ivtmp_50 + 2;
if (end_60 < end_62)
goto mainbb_5;
else
goto mainbb_6;
// # SUCC: 5 [99.0%] (dfs_back,true,exec) 6 [1.0%] (false,exec)
mainbb_6:
// # PRED: 5 [1.0%] (false,exec) 3 [1.0%] (false,exec)
adpcm_coder (&pcmdata, &adpcmdata, 10240, &coder_1_state);
count = count + 1;
if (j > count)
goto mainbb_14;
else
goto mainbb_7;
// # SUCC: 14 [91.0%] (dfs_back,true,exec) 7 [9.0%] (false,exec)
mainbb_14:
// # PRED: 6 [91.0%] (dfs_back,true,exec)
end_61 = end_62;
goto mainbb_3;
// # SUCC: 3 [100.0%] (fallthru)
mainbb_7:
// # PRED: 6 [9.0%] (false,exec) 2 [9.0%] (false,exec)
if (ARR_SIZE_0 % 10240 != 0)
goto mainbb_8;
else
goto mainbb_12;
// # SUCC: 8 [61.0%] (true,exec) 12 [39.0%] (false,exec)
mainbb_8:
// # PRED: 7 [61.0%] (true,exec)
start = j * 10240;
end = ARR_SIZE;
if (start < end)
goto mainbb_9;
else
goto mainbb_11;
// # SUCC: 9 [99.0%] (true,exec) 11 [1.0%] (false,exec)
mainbb_9:
// # PRED: 8 [99.0%] (true,exec)
i = (int) start;
ivtmp_44 = (uintptr_t)&in_Data[i];
D_2245 = (int) end;
start_56 = start;
// # SUCC: 10 [100.0%] (fallthru,exec)
mainbb_10:
// # PRED: 10 [99.0%] (dfs_back,true,exec) 9 [100.0%] (fallthru,exec)
pcmdata[start_56 - start] = *(short int*)((uintptr_t)ivtmp_44);
i = i + 1;
start_56 = (long unsigned int) i;
ivtmp_44 = ivtmp_44 + 2;
if (i != D_2245)
goto mainbb_10;
else
goto mainbb_11;
// # SUCC: 10 [99.0%] (dfs_back,true,exec) 11 [1.0%] (false,exec)
mainbb_11:
// # PRED: 10 [1.0%] (false,exec) 8 [1.0%] (false,exec)
adpcm_coder (&pcmdata, &adpcmdata, (int) (end - start), &coder_1_state);
// # SUCC: 12 [100.0%] (fallthru,exec)
mainbb_12:
// # PRED: 7 [39.0%] (false,exec) 11 [100.0%] (fallthru,exec)
return 0;
// # SUCC: EXIT [100.0%]
}
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3,20 +3,68 @@ ...@@ -3,20 +3,68 @@
#----------------------------------------------------------------- #-----------------------------------------------------------------
from optparse import OptionParser from optparse import OptionParser
from subprocess import call
import logging
import re
from cfg_binary import parse_binary, print_debug_binary from cfg_binary import parse_binary, print_debug_binary
from cfg_isc import parse_isc, print_debug_isc from cfg_isc import parse_isc, print_debug_isc
import logging
from collections import deque from collections import deque
listISCFileNames = [] listISCFileNames = []
listObjdumpFileNames = [] listObjdumpFileNames = []
listBinaryFileNames = []
class GDBMapTarget:
def __init__(self, fileName, lineNum):
self.fileName = fileName
self.lineNum = lineNum
def gdbMappingDebug(gdbMapping):
for lineNum in gdbMapping:
print ("line %d maps to %s:%d" % (lineNum, gdbMapping[lineNum].fileName, gdbMapping[lineNum].lineNum))
def getGDBMapping(binFileName, objdumpLineNumForAddress):
gdbMapping = {}
re_gdbInfoLineOutput = re.compile('Line (\d*) of "(.*)" starts at address 0x([0-9a-f]*).*')
# File Name for GDB Command file
gdbXFileName = binFileName+".gdbx"
gdbXFile = open(gdbXFileName, 'w')
for address in objdumpLineNumForAddress:
line = "info line *0x%x\n" % (int(address, 16))
gdbXFile.write(line)
gdbXFile.write("quit\n")
gdbXFile.close()
def map_cfg(listISCFileNames, listObjdumpFileNames): gdbOutputFileName = binFileName+".gdbo"
gdbOutputFile = open(gdbOutputFileName, 'w')
call(args=["gdb", "--quiet", "--command="+gdbXFileName, binFileName],
stdout=gdbOutputFile)
gdbOutputFile.close()
gdbOutputFile = open(gdbOutputFileName, 'r')
for line in gdbOutputFile:
m = re_gdbInfoLineOutput.match(line)
if m is not None:
targetLineNum = int(m.group(1), 10)
targetFileName = m.group(2)
objdumpAddress = m.group(3)
objdumpLineNum = objdumpLineNumForAddress[objdumpAddress]
gdbMapping[objdumpLineNum] = GDBMapTarget(targetFileName, targetLineNum)
gdbOutputFile.close()
gdbMappingDebug(gdbMapping)
return gdbMapping
def map_cfg(listISCFileNames, listObjdumpFileNames, listBinaryFileNames):
listISCFunctions = [] listISCFunctions = []
listFunctionNames = [] listFunctionNames = []
listObjdumpFunctions = [] listObjdumpFunctions = []
...@@ -26,11 +74,14 @@ def map_cfg(listISCFileNames, listObjdumpFileNames): ...@@ -26,11 +74,14 @@ def map_cfg(listISCFileNames, listObjdumpFileNames):
listISCFunctions = listISCFunctions + parse_isc(ISCFileName) listISCFunctions = listISCFunctions + parse_isc(ISCFileName)
for function in listISCFunctions: for function in listISCFunctions:
listFunctionNames.append(function.functionName) listFunctionNames.append(function.functionName)
print "parsed "+ISCFileName
# Parse the objdump files # Parse the objdump files
for ObjdumpFileName in listObjdumpFileNames: for ObjdumpFileName in listObjdumpFileNames:
listObjdumpFunctions = listObjdumpFunctions + parse_binary(ObjdumpFileName, (tempListObjdumpFunctions, objdumpLineNumForAddress) = parse_binary(ObjdumpFileName,
listFunctionNames) listFunctionNames)
listObjdumpFunctions = listObjdumpFunctions + tempListObjdumpFunctions
# Check that we found all functions in ISC in Objdump # Check that we found all functions in ISC in Objdump
if len(listISCFunctions) != len(listObjdumpFunctions): if len(listISCFunctions) != len(listObjdumpFunctions):
...@@ -44,6 +95,9 @@ def map_cfg(listISCFileNames, listObjdumpFileNames): ...@@ -44,6 +95,9 @@ def map_cfg(listISCFileNames, listObjdumpFileNames):
logging.debug("Computing flow for function %s from file %s" % (function.functionName, function.fileName)) logging.debug("Computing flow for function %s from file %s" % (function.functionName, function.fileName))
function.cfg.computeFlow() function.cfg.computeFlow()
for binaryFileName in listBinaryFileNames:
getGDBMapping(binaryFileName, objdumpLineNumForAddress)
print_debug_isc (listISCFunctions) print_debug_isc (listISCFunctions)
print_debug_binary (listObjdumpFunctions) print_debug_binary (listObjdumpFunctions)
...@@ -51,15 +105,19 @@ def map_cfg(listISCFileNames, listObjdumpFileNames): ...@@ -51,15 +105,19 @@ def map_cfg(listISCFileNames, listObjdumpFileNames):
if __name__ == "__main__": if __name__ == "__main__":
# listISCFileNames = [] # listISCFileNames = []
# listObjdumpFileNames = [] # listObjdumpFileNames = []
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.WARNING)
optparser = OptionParser() optparser = OptionParser()
optparser.add_option("-i", "--isc", action="append", dest="listISCFileNames", optparser.add_option("-i", "--isc", action="append", dest="listISCFileNames",
type="string", help="ISC Filenamel. For multiple files, use -i <filename> multiple times.", type="string", help="ISC Filename. For multiple files, use -i <filename> multiple times.",
metavar="FILE") metavar="FILE")
optparser.add_option("-o", "--objdump", action="append", optparser.add_option("-o", "--objdump", action="append",
type="string", dest="listObjdumpFileNames", type="string", dest="listObjdumpFileNames",
help="Objdump Filename. For multiple files, use -o <filename> multiple times.", help="Objdump Filename. For multiple files, use -o <filename> multiple times.",
metavar="FILE") metavar="FILE")
optparser.add_option("-b", "--binary", action="append",
type="string", dest="listBinaryFileNames",
help="Binary Filename. For multiple files, use -b <filename> multiple times.",
metavar="FILE")
(options, args) = optparser.parse_args() (options, args) = optparser.parse_args()
...@@ -68,6 +126,7 @@ if __name__ == "__main__": ...@@ -68,6 +126,7 @@ if __name__ == "__main__":
listISCFileNames = options.listISCFileNames listISCFileNames = options.listISCFileNames
listObjdumpFileNames = options.listObjdumpFileNames listObjdumpFileNames = options.listObjdumpFileNames
listBinaryFileNames = options.listBinaryFileNames
map_cfg(listISCFileNames, listObjdumpFileNames) map_cfg(listISCFileNames, listObjdumpFileNames, listBinaryFileNames)
\ No newline at end of file
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