-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathchp2prs_pass.cc
112 lines (95 loc) · 2.81 KB
/
chp2prs_pass.cc
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
/*************************************************************************
*
* Copyright (c) 2021 Rajit Manohar
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
**************************************************************************
*/
#include <act/act.h>
#include "config_pkg.h"
#include "basicsdt.h"
#ifdef FOUND_expropt
#include "externoptsdt.h"
#endif
#include "chp2prs_pass.h"
void chp2prs_init (ActPass *dp)
{
/* nothing has to be done */
}
static BasicSDT *_pending = NULL;
static void kill_mapper_on_exit (void)
{
if (_pending) {
delete _pending;
}
_pending = NULL;
}
void *chp2prs_proc (ActPass *ap, Process *p, int mode)
{
ActDynamicPass *dp = dynamic_cast<ActDynamicPass *> (ap);
Assert (dp, "What?!");
/* -- create sdt version if a chp body exists without a prs body -- */
int chpopt, externopt, bundled;
const char *exprfile;
FILE *fp;
BasicSDT *sdt;
const char *mapper;
chpopt = dp->getIntParam ("chp_optimize");
externopt = dp->getIntParam ("externopt");
bundled = dp->getIntParam ("bundled_dpath");
if (dp->hasParam ("synthesis_engine")) {
mapper = (char *) dp->getPtrParam ("synthesis_engine");
}
else {
mapper = NULL;
}
exprfile = (const char *) dp->getPtrParam ("expr_file");
fp = (FILE *) dp->getPtrParam ("output_fp");
if (chpopt)
{
#ifdef FOUND_chp_opt
ActPass *opt_p = dp->getAct()->pass_find ("chpopt");
if (opt_p && p->getlang()->getchp()) {
opt_p->run (p);
printf("> Optimized CHP:\n");
chp_print(stdout, p->getlang()->getchp()->c);
printf("\n");
}
#else
fatal_error ("Optimize flag is not currently enabled in the build.");
#endif
}
if (externopt) {
#if defined(FOUND_expropt)
sdt = new ExternOptSDT (bundled, chpopt, fp, exprfile, mapper);
_pending = sdt;
#else
fatal_error ("External optimization package not installed.");
#endif
}
else {
if (bundled) {
fatal_error ("Bundled-data not supported is Basic mode");
}
sdt = new BasicSDT (bundled, chpopt, fp, exprfile);
_pending = sdt;
}
atexit (kill_mapper_on_exit);
sdt->run_sdt (p);
kill_mapper_on_exit ();
return NULL;
}