-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathps1_analysis_0.pro
43 lines (34 loc) · 999 Bytes
/
ps1_analysis_0.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
:- module(ps1_analysis_0, [
% routine-finding
routine_begin/2
, routine_begin/1
% heuristics
, routine_end/2
]).
:- use_module(library(clpfd)).
:- use_module('./ps1_cpu.pro').
:- use_module('./ps1_memory.pro').
/** routine_begin(Address, Comment)
"Address is the address of the first instruction of a routine."
This is used to begin grouping the statement list into basic blocks.
We assume that the program always calls a routine from the beginning (never into the middle).
*/
:- multifile routine_begin/2.
:- dynamic routine_begin/2.
routine_begin(A) :- routine_begin(A, _).
/*
This heuristic guesses the end of a routine.
We assume:
- Every routine has exactly one JR RA.
- Every routine ends with JR RA.
- Every routine does not exceed 100,000 instructions.
The end is exclusive.
*/
routine_end(B, E) :-
for(I in 1 .. 100000),
A #= B + 4 * I,
address_instruction(A, jr(r(31))),
!,
E #= A + 8.
% private
for(I in Range) :- I in Range, indomain(I).