/
ElimTrivApp.cag
66 lines (51 loc) · 2.36 KB
/
ElimTrivApp.cag
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
%%[0
%include lhs2TeX.fmt
%include afp.fmt
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Eliminate trivial applications of known functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Eliminate function applications for which the semantics is fixed.
This is done for Prelude functions:
- id
%%[(8 codegen) hs module {%{EH}Core.Trf.ElimTrivApp} import(Data.Maybe,qualified Data.Set as Set,qualified Data.Map as Map)
%%]
%%[(8 codegen) hs import({%{EH}Base.Common},{%{EH}Base.Builtin},{%{EH}Opts},{%{EH}Core},{%{EH}Ty})
%%]
%%[(8 codegen) hs import(UHC.Util.Utils)
%%]
%%[(8 codegen).WRAPPER ag import({Core/AbsSyn},{Core/CommonLev},{Core/CommonCtxtPred},{Core/Trf/CommonFv},{Core/Trf/CommonStructureInfo},{Core/CommonBindNm})
WRAPPER CodeAGItf
%%]
%%[(99 codegen)
PRAGMA strictcase
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Haskell itf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%[(8 codegen) hs export(cmodTrfElimTrivApp)
cmodTrfElimTrivApp :: EHCOpts -> CModule -> CModule
cmodTrfElimTrivApp opts cmod
= let t = wrap_CodeAGItf (sem_CodeAGItf (CodeAGItf_AGItf cmod)) (Inh_CodeAGItf {opts_Inh_CodeAGItf = opts})
in cTrf_Syn_CodeAGItf t
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Global info
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%[(8 codegen)
ATTR AllCodeNT CodeAGItf [ opts: EHCOpts | | ]
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Transformation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%[(8 codegen)
ATTR AllCodeNT [ | | cTrf: SELF ]
ATTR CodeAGItf [ | | cTrf: CModule ]
SEM CExpr
| App lhs . cTrf = if @lhs.isTopApp
then case (@func.mbFunVar,reverse @argL) of
(Just f,[a]) | f == (ehcOptBuiltin @lhs.opts ehbnId)
-> acoreUnBoundVal a
_ -> @cTrf
else @cTrf
%%]