1 |
#include "compiler.h" |
2 |
|
3 |
/* #define COMPILER_DEBUG */ |
4 |
//#define BINTOKEN_DEBUG |
5 |
|
6 |
extern "C"{ |
7 |
#include <ascend/compiler/compiler.h> |
8 |
#include <ascend/compiler/bintoken.h> |
9 |
#include <ascend/utilities/error.h> |
10 |
} |
11 |
|
12 |
using namespace std; |
13 |
|
14 |
Compiler::Compiler(){ |
15 |
#ifdef COMPILE_DEBUG |
16 |
CONSOLE_DEBUG("Creating compiler"); |
17 |
#endif |
18 |
|
19 |
/* set some default for bintoken compilation */ |
20 |
use_bintoken = false; |
21 |
bintoken_options_sent = false; |
22 |
bt_targetstem = "/tmp/asc_bintoken"; |
23 |
bt_srcname = bt_targetstem + ".c"; |
24 |
bt_objname = bt_targetstem + ".o"; |
25 |
bt_libname = bt_targetstem + ".so"; |
26 |
bt_cmd = "make -f ascend/bintokens/Makefile ASCBT_TARGET=" + bt_libname + " ASCBT_SRC=" + bt_srcname; |
27 |
bt_rm = "/bin/rm"; |
28 |
} |
29 |
|
30 |
Compiler::~Compiler(){ |
31 |
#ifdef COMPILER_DEBUG |
32 |
CONSOLE_DEBUG("Destroying compiler...");; |
33 |
#endif |
34 |
} |
35 |
|
36 |
Compiler * |
37 |
Compiler::instance(){ |
38 |
static Compiler *_instance = NULL; |
39 |
if(_instance == NULL){ |
40 |
_instance = new Compiler(); |
41 |
} |
42 |
return _instance; |
43 |
} |
44 |
|
45 |
const bool |
46 |
Compiler::getUseRelationSharing() const{ |
47 |
if(g_use_copyanon){ |
48 |
return true; |
49 |
} |
50 |
return false; |
51 |
} |
52 |
|
53 |
void |
54 |
Compiler::setUseRelationSharing(const bool &use_relation_sharing){ |
55 |
g_use_copyanon = 0; |
56 |
if(use_relation_sharing){ |
57 |
g_use_copyanon = 1; |
58 |
} |
59 |
} |
60 |
|
61 |
void |
62 |
Compiler::setBinaryCompilation(const bool &use_bintoken){ |
63 |
this->use_bintoken = use_bintoken; |
64 |
#ifdef BINTOKEN_DEBUG |
65 |
ERROR_REPORTER_HERE(ASC_PROG_NOTE,"usebintoken = %d",int(use_bintoken)); |
66 |
#endif |
67 |
} |
68 |
|
69 |
void |
70 |
Compiler::sendBinaryCompilationOptions(){ |
71 |
if(use_bintoken && !bintoken_options_sent){ |
72 |
#ifdef BINTOKEN_DEBUG |
73 |
CONSOLE_DEBUG("SETUP BINTOKENS..."); |
74 |
#endif |
75 |
BinTokenSetOptions(bt_srcname.c_str(), bt_objname.c_str(), bt_libname.c_str() |
76 |
, bt_cmd.c_str(), bt_rm.c_str(), 1000/*maxrels*/, 1/*verbose*/, 0/*housekeep*/ |
77 |
); |
78 |
|
79 |
#ifdef BINTOKEN_DEBUG |
80 |
CONSOLE_DEBUG("srcname = %s, objname = %s, libname = %s, cmd = %s, rm = %s", |
81 |
bt_srcname.c_str(), bt_objname.c_str(), bt_libname.c_str(), bt_cmd.c_str(), bt_rm.c_str() |
82 |
); |
83 |
#endif |
84 |
|
85 |
bintoken_options_sent = true; |
86 |
}else{ |
87 |
/* ERROR_REPORTER_HERE(ASC_PROG_NOTE,"disabling bintoken compilation\n"); */ |
88 |
bintoken_options_sent = false; |
89 |
BinTokenSetOptions(NULL,NULL,NULL,NULL,NULL,0,1,1); |
90 |
} |
91 |
} |
92 |
|
93 |
Compiler *getCompiler(){ |
94 |
return Compiler::instance(); |
95 |
} |