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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
%% -*- erlang-indent-level: 2 -*-
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Copyright (c) 2001 by Erik Johansson. All Rights Reserved
%% Time-stamp: <2008-04-20 14:57:08 richard>
%% ====================================================================
%% Module : hipe_data_pp
%% Purpose :
%% Notes :
%% History : * 2001-02-25 Erik Johansson ([email protected]): Created.
%% ====================================================================
%% Exports :
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-module(hipe_data_pp).
-export([pp/4]).
%%-----------------------------------------------------------------------------
-include("hipe_consttab.hrl").
-type hipe_code_type() :: 'icode' | 'rtl' | 'arm' | 'ppc' | 'sparc' | 'x86'.
%%-----------------------------------------------------------------------------
%%
%% Pretty print
-spec pp(io:device(), hipe_consttab(), hipe_code_type(), string()) -> 'ok'.
pp(Dev, Table, CodeType, Pre) ->
Ls = hipe_consttab:labels(Table),
lists:foreach(fun ({{_, ref}, _}) -> ok;
({L, E}) -> pp_element(Dev, L, E, CodeType, Pre)
end,
[{L, hipe_consttab:lookup(L, Table)} || L <- Ls]).
pp_element(Dev, Name, Element, CodeType, Prefix) ->
%% Alignment
case hipe_consttab:const_align(Element) of
4 -> ok; %% Wordalignment is assumed
Alignment ->
io:format(Dev, " .align~w\n", [Alignment])
end,
%% Local or exported?
Exported = hipe_consttab:const_exported(Element),
case CodeType of
rtl ->
case Exported of
true ->
io:format(Dev, "DL~w: ", [Name]);
false ->
io:format(Dev, ".DL~w: ", [Name])
end;
_ ->
io:format(Dev, "~w ", [Name])
end,
%% Type and data...
case hipe_consttab:const_type(Element) of
term ->
io:format(Dev, "~w\n", [hipe_consttab:const_data(Element)]);
sorted_block ->
Data = hipe_consttab:const_data(Element),
pp_block(Dev, {word, lists:sort(Data)}, CodeType, Prefix);
block ->
pp_block(Dev, hipe_consttab:const_data(Element), CodeType, Prefix)
end.
pp_block(Dev, {word, Data, SortOrder}, CodeType, Prefix) ->
case CodeType of
rtl ->
io:format(Dev, "\n",[]);
_ ->
ok
end,
pp_wordlist(Dev, Data, CodeType, Prefix),
case CodeType of
rtl ->
io:format(Dev, ";; Sorted by ~w\n",[SortOrder]);
_ ->
ok
end;
pp_block(Dev, {word, Data}, CodeType, Prefix) ->
case CodeType of
rtl ->
io:format(Dev, ".word\n",[]);
_ ->
ok
end,
pp_wordlist(Dev, Data, CodeType, Prefix);
pp_block(Dev, {byte, Data}, CodeType, _Prefix) ->
case CodeType of
rtl ->
io:format(Dev, ".byte\n ",[]);
_ ->
ok
end,
pp_bytelist(Dev, Data, CodeType),
case CodeType of
rtl ->
io:format(Dev, " ;; ~s\n ", [Data]);
_ -> ok
end.
pp_wordlist(Dev, [{label, L}|Rest], CodeType, Prefix) ->
case CodeType of
rtl ->
io:format(Dev, " &L~w\n", [L]);
_ ->
io:format(Dev, " <~w>\n", [L])
end,
pp_wordlist(Dev, Rest, CodeType, Prefix);
pp_wordlist(Dev, [D|Rest], CodeType, Prefix) ->
case CodeType of
rtl ->
io:format(Dev, " ~w\n", [D]);
_ ->
io:format(Dev, " ~w\n", [D])
end,
pp_wordlist(Dev, Rest, CodeType, Prefix);
pp_wordlist(_Dev, [], _CodeType, _Prefix) ->
ok.
pp_bytelist(Dev, [D], CodeType) ->
case CodeType of
rtl ->
io:format(Dev, "~w\n", [D]);
_ ->
io:format(Dev, "~w\n", [D])
end,
ok;
pp_bytelist(Dev, [D|Rest], CodeType) ->
case CodeType of
rtl ->
io:format(Dev, "~w,", [D]);
_ ->
io:format(Dev, "~w,", [D])
end,
pp_bytelist(Dev, Rest, CodeType);
pp_bytelist(Dev, [], _CodeType) ->
io:format(Dev, "\n", []).
|