File: hipe_bb.erl

package info (click to toggle)
erlang 1%3A12.b.3-dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 77,780 kB
  • ctags: 157,528
  • sloc: erlang: 664,178; ansic: 241,119; makefile: 15,725; xml: 8,378; java: 7,780; sh: 6,789; lisp: 5,396; pascal: 3,637; perl: 2,310; asm: 1,438; cpp: 975; tcl: 245; python: 21; sed: 20; awk: 15
file content (63 lines) | stat: -rw-r--r-- 1,201 bytes parent folder | download
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Basic Block Module
%%
%% Exports:
%% ~~~~~~~~
%% mk_bb(Code) - construct a basic block.
%% code(BB) - returns the code.
%% code_update(BB, NewCode) - replace the code in a basic block.
%% last(BB) - returns the last instruction.
%% butlast(BB) - returns the code with the last instruction removed.
%%

-module(hipe_bb).

-export([mk_bb/1,
	 code/1,
	 code_update/2,
	 is_bb/1,
	 last/1,
	 butlast/1]).

-include("hipe_bb.hrl").

%%
%% Constructs a basic block.
%% Returns a basic block: {bb, Code}
%%   * Code is a list of instructions

-spec(mk_bb/1 :: ([_]) -> bb()).

mk_bb(Code) ->
    #bb{code=Code}.

-spec(is_bb/1 :: (_) -> bool()).

is_bb(#bb{}) -> true;
is_bb(_) -> false.

-spec(code_update/2 :: (bb(), [_]) -> bb()).

code_update(BB, Code) ->
    BB#bb{code = Code}.

-spec(code/1 :: (bb()) -> [_]).

code(#bb{code = Code}) -> 
    Code.

-spec(last/1 :: (bb()) -> _).

last(#bb{code = Code}) -> 
    lists:last(Code).

-spec(butlast/1 :: (bb()) -> [_]).

butlast(#bb{code = Code}) ->
    butlast_1(Code).

butlast_1([X|Xs]) -> butlast_1(Xs,X).

butlast_1([X|Xs],Y) -> [Y|butlast_1(Xs,X)];
butlast_1([],_) -> [].