summaryrefslogtreecommitdiffabout
path: root/lib
Unidiff
Diffstat (limited to 'lib') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/sitecing_enflesher.ll1
1 files changed, 0 insertions, 1 deletions
diff --git a/lib/sitecing_enflesher.ll b/lib/sitecing_enflesher.ll
index bb667be..f833af2 100644
--- a/lib/sitecing_enflesher.ll
+++ b/lib/sitecing_enflesher.ll
@@ -51,210 +51,209 @@ ID [A-Za-z_][A-Za-z0-9_]*
51 }else{ 51 }else{
52 outs << ","; 52 outs << ",";
53 } 53 }
54 if(i->bComponent) { 54 if(i->bComponent) {
55 outs << i->name << "(NULL)"; 55 outs << i->name << "(NULL)";
56 }else { 56 }else {
57 outs << i->name << "(" << i->initializer << ")"; 57 outs << i->name << "(" << i->initializer << ")";
58 } 58 }
59 } 59 }
60 }else if(i->name == "~") 60 }else if(i->name == "~")
61 outs << "~" << parser.class_name << "()"; 61 outs << "~" << parser.class_name << "()";
62 else 62 else
63 outs << i->name << i->args; 63 outs << i->name << i->args;
64 outs << "{\n" << i->body << "\n}\n"; 64 outs << "{\n" << i->body << "\n}\n";
65 } 65 }
66 anchor_time = true; 66 anchor_time = true;
67} 67}
68 \<\%class_name\%\> outs << parser.class_name; anchor_time = true; 68 \<\%class_name\%\> outs << parser.class_name; anchor_time = true;
69 \<\%baseclass_header\%\>outs << parser.base_header; anchor_time = true; 69 \<\%baseclass_header\%\>outs << parser.base_header; anchor_time = true;
70 \<\%decl\%\> outs << parser.decl; anchor_time = true; 70 \<\%decl\%\> outs << parser.decl; anchor_time = true;
71 \<\%baseclass_name\%\> outs << parser.base_class; anchor_time = true; 71 \<\%baseclass_name\%\> outs << parser.base_class; anchor_time = true;
72 \<\%member_variables:decl\%\>{ 72 \<\%member_variables:decl\%\>{
73 for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) { 73 for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) {
74 if(i->bComponent) { 74 if(i->bComponent) {
75 if(i->type.empty()) { 75 if(i->type.empty()) {
76 i->type = parser.factory.get_classname(i->initializer); 76 i->type = parser.factory.get_classname(i->initializer);
77 } 77 }
78 if(i->bTypeOnly) { 78 if(i->bTypeOnly) {
79 outs << "typedef " << i->type << " " << i->name << ";\n"; 79 outs << "typedef " << i->type << " " << i->name << ";\n";
80 }else{ 80 }else{
81 outs << "typedef " << i->type << " __type_" << i->name << ";\nsitecing::so_component __soc_" << i->name << ";\n__type_" << i->name << " *" << i->name << ";\n"; 81 outs << "typedef " << i->type << " __type_" << i->name << ";\nsitecing::so_component __soc_" << i->name << ";\n__type_" << i->name << " *" << i->name << ";\n";
82 } 82 }
83 }else{ 83 }else{
84 outs << i->type << " " << i->name << ";\n"; 84 outs << i->type << " " << i->name << ";\n";
85 } 85 }
86 } 86 }
87 anchor_time = true; 87 anchor_time = true;
88} 88}
89 \<\%member_functions:decl\%\>{ 89 \<\%member_functions:decl\%\>{
90 for(sitecing_parser::member_functions_t::const_iterator i=parser.member_functions.begin();i!=parser.member_functions.end();i++) { 90 for(sitecing_parser::member_functions_t::const_iterator i=parser.member_functions.begin();i!=parser.member_functions.end();i++) {
91 (i->name.empty()?outs:outs << "virtual ") 91 (i->name.empty()?outs:outs << "virtual ")
92 << i->type << " "; 92 << i->type << " ";
93 if(i->name.empty()) { 93 if(i->name.empty()) {
94 outs << parser.class_name << "()"; 94 outs << parser.class_name << "()";
95 }else if(i->name == "~") 95 }else if(i->name == "~")
96 outs << "~" << parser.class_name << "()"; 96 outs << "~" << parser.class_name << "()";
97 else 97 else
98 outs << i->name << i->args; 98 outs << i->name << i->args;
99 outs << ";\n"; 99 outs << ";\n";
100 } 100 }
101 anchor_time = true; 101 anchor_time = true;
102} 102}
103 \<\%imports:list\%\> { 103 \<\%imports:list\%\> {
104 for(sitecing_parser::member_variables_t::const_iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) { 104 for(sitecing_parser::member_variables_t::const_iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) {
105 if(i->bComponent) 105 if(i->bComponent)
106 outs << i->initializer << endl; 106 outs << i->initializer << endl;
107 } 107 }
108 anchor_time = true; 108 anchor_time = true;
109} 109}
110 \<\%imports:includes\%\>{ 110 \<\%imports:includes\%\>{
111 for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) { 111 for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) {
112 if(i->bComponent) 112 if(i->bComponent)
113 outs << "\n#include \"" << i->initializer << ".h\"\n"; 113 outs << "\n#include \"" << i->initializer << ".h\"\n";
114 } 114 }
115 anchor_time = true; 115 anchor_time = true;
116} 116}
117 \<\%imports:import\%\>{ 117 \<\%imports:import\%\>{
118 for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) { 118 for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) {
119 if(!i->bComponent) 119 if(!i->bComponent)
120 continue; 120 continue;
121 if(i->bTypeOnly) 121 if(i->bTypeOnly)
122 continue; 122 continue;
123 outs << "__soc_" << i->name << "=__SCIF->ss->fetch(\"" << i->initializer << "\",__SCIF); " << i->name << "=static_cast<__type_" << i->name << "*>(__soc_" << i->name << ".ac->__the_most_derived_this());\n"; 123 outs << "__soc_" << i->name << "=__SCIF->ss->fetch(\"" << i->initializer << "\",__SCIF); " << i->name << "=static_cast<__type_" << i->name << "*>(__soc_" << i->name << ".ac->__the_most_derived_this());\n";
124 } 124 }
125 anchor_time = true; 125 anchor_time = true;
126} 126}
127 127
128 \<\%base_component\%\> { 128 \<\%base_component\%\> {
129 // TODO: 129 // TODO:
130 anchor_time = true; 130 anchor_time = true;
131} 131}
132 132
133 \<\%ancestors:includes\%\>{ 133 \<\%ancestors:includes\%\>{
134 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { 134 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) {
135 outs << "#include \"" << i->path << ".h\"\n"; 135 outs << "#include \"" << i->path << ".h\"\n";
136 } 136 }
137 anchor_time = true; 137 anchor_time = true;
138} 138}
139 \<\%ancestors:component_list\%\>{ 139 \<\%ancestors:component_list\%\>{
140 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { 140 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) {
141 outs << i->path << "\n"; 141 outs << i->path << "\n";
142 } 142 }
143 anchor_time = true; 143 anchor_time = true;
144} 144}
145 \<\%ancestors:base_clause_part\%\>{ 145 \<\%ancestors:base_clause_part\%\>{
146 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { 146 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) {
147 outs << ", virtual public " << parser.factory.get_classname(i->path); 147 outs << ", virtual public " << parser.factory.get_classname(i->path);
148 } 148 }
149} 149}
150 \<\%ancestors:typedefs\%\> { 150 \<\%ancestors:typedefs\%\> {
151 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { 151 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) {
152 outs << "typedef class " << parser.factory.get_classname(i->path) << " " << i->name << ";\n"; 152 outs << "typedef class " << parser.factory.get_classname(i->path) << " " << i->name << ";\n";
153 } 153 }
154 anchor_time = true; 154 anchor_time = true;
155} 155}
156 \<\%ancestors:import\%\> { 156 \<\%ancestors:import\%\> {
157 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { 157 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) {
158 outs << i->name << "::__do_imports();\n"; 158 outs << i->name << "::__do_imports();\n";
159 } 159 }
160 anchor_time = true; 160 anchor_time = true;
161} 161}
162 162
163 \n { 163 \n {
164 if(anchor_time) 164 if(anchor_time)
165 anchor(); 165 anchor();
166 ECHO; 166 ECHO;
167} 167}
168 . ECHO; 168 . ECHO;
169 169
170%% 170%%
171 171
172void sitecing_enflesher::LexerOutput(const char *buf,int size) { 172void sitecing_enflesher::LexerOutput(const char *buf,int size) {
173 outs.write(buf,size); 173 outs.write(buf,size);
174} 174}
175 175
176void sitecing_enflesher::enflesh() { 176void sitecing_enflesher::enflesh() {
177 ifstream ifs(parser.skeleton.c_str()); 177 ifstream ifs(parser.skeleton.c_str());
178 if(!ifs.good()) 178 if(!ifs.good())
179 throw preprocessor_error(CODEPOINT,"failed to open skeleton file"); 179 throw preprocessor_error(CODEPOINT,"failed to open skeleton file");
180 switch_streams(&ifs,NULL); 180 switch_streams(&ifs,NULL);
181 yylex(); 181 yylex();
182 outs_close(); 182 outs_close();
183} 183}
184 184
185void sitecing_enflesher::anchor() { 185void sitecing_enflesher::anchor() {
186 if(!anchoraged) 186 if(!anchoraged)
187 return; 187 return;
188 outs << "\n#line " << lineno() << " \"" << parser.skeleton << "\"\n"; 188 outs << "\n#line " << lineno() << " \"" << parser.skeleton << "\"\n";
189 anchor_time = false; 189 anchor_time = false;
190} 190}
191 191
192void sitecing_enflesher::outs_close() { 192void sitecing_enflesher::outs_close() {
193 if(!outs_filename.empty()) { 193 if(!outs_filename.empty()) {
194 outs.flush(); 194 outs.flush();
195 outs.close(); 195 outs.close();
196 outs.clear(); 196 outs.clear();
197 /* 197 /*
198 * compare source and destination files. 198 * compare source and destination files.
199 * 199 *
200 * one can also keep a hash for the old one and compute one for the 200 * one can also keep a hash for the old one and compute one for the
201 * output while writing, but I'm not sure if it's any better. Surely a 201 * output while writing, but I'm not sure if it's any better. Surely a
202 * bit less accurate, unless we're going to compare it in case of 202 * bit less accurate, unless we're going to compare it in case of
203 * difference, anyway. 203 * difference, anyway.
204 */ 204 */
205 bool overwrite = false; 205 bool overwrite = false;
206 struct stat st_s, st_d; 206 struct stat st_s, st_d;
207 string fn_s = outs_filename+".new"; 207 string fn_s = outs_filename+".new";
208 string fn_d = outs_filename; 208 string fn_d = outs_filename;
209 if(stat(fn_d.c_str(),&st_d)) { 209 if(stat(fn_d.c_str(),&st_d)) {
210 overwrite = true; 210 overwrite = true;
211 }else{ 211 }else{
212 if(stat(fn_s.c_str(),&st_s)) 212 if(stat(fn_s.c_str(),&st_s))
213 throw preprocessor_error(CODEPOINT,"failed to stat() supposedly created file"); 213 throw preprocessor_error(CODEPOINT,"failed to stat() supposedly created file");
214 if(st_s.st_size!=st_d.st_size) { 214 if(st_s.st_size!=st_d.st_size) {
215 overwrite = true; 215 overwrite = true;
216 }else{ 216 }else{
217 ifstream i_s(fn_s.c_str(),ios::in); 217 ifstream i_s(fn_s.c_str(),ios::in);
218 if(!i_s) 218 if(!i_s)
219 throw preprocessor_error(CODEPOINT,"failed to open supposedly created file"); 219 throw preprocessor_error(CODEPOINT,"failed to open supposedly created file");
220 ifstream i_d(fn_d.c_str(),ios::in); 220 ifstream i_d(fn_d.c_str(),ios::in);
221 if(!i_d) 221 if(!i_d)
222 throw preprocessor_error(CODEPOINT,"failed to open the old preprocessed source"); 222 throw preprocessor_error(CODEPOINT,"failed to open the old preprocessed source");
223 off_t remaining = st_s.st_size; 223 off_t remaining = st_s.st_size;
224 char t1[2048]; 224 char t1[2048];
225 char t2[sizeof(t1)]; 225 char t2[sizeof(t1)];
226 while(remaining) { 226 while(remaining) {
227 int rb = remaining; 227 int rb = remaining;
228 if(rb>sizeof(t1)) 228 if(rb>sizeof(t1))
229 rb = sizeof(t1); 229 rb = sizeof(t1);
230 if(i_s.read(t1,rb).gcount()!=rb) 230 if(i_s.read(t1,rb).gcount()!=rb)
231 throw preprocessor_error(CODEPOINT,"error reading just created file"); 231 throw preprocessor_error(CODEPOINT,"error reading just created file");
232 if(i_d.read(t2,rb).gcount()!=rb) 232 if(i_d.read(t2,rb).gcount()!=rb)
233 throw preprocessor_error(CODEPOINT,"error reading the old preprocessed source"); 233 throw preprocessor_error(CODEPOINT,"error reading the old preprocessed source");
234 if(memcmp(t1,t2,rb)) { 234 if(memcmp(t1,t2,rb)) {
235 overwrite = true; 235 overwrite = true;
236 break; 236 break;
237 } 237 }
238 remaining -= rb; 238 remaining -= rb;
239 } 239 }
240 } 240 }
241 } 241 }
242 if(overwrite) { 242 if(overwrite) {
243 cerr << "renaming '" << fn_s << "'" << endl;
244 if(rename(fn_s.c_str(),fn_d.c_str())) 243 if(rename(fn_s.c_str(),fn_d.c_str()))
245 throw preprocessor_error(CODEPOINT,"failed to rename() generated output"); 244 throw preprocessor_error(CODEPOINT,"failed to rename() generated output");
246 } 245 }
247 } 246 }
248 outs_filename.erase(); 247 outs_filename.erase();
249} 248}
250 249
251void sitecing_enflesher::outs_open(const string& nfile) { 250void sitecing_enflesher::outs_open(const string& nfile) {
252 outs_close(); 251 outs_close();
253 outs_filename = nfile; 252 outs_filename = nfile;
254 outs.open((nfile+".new").c_str(),ios::trunc); 253 outs.open((nfile+".new").c_str(),ios::trunc);
255 if(!outs.good()) 254 if(!outs.good())
256 throw preprocessor_error(CODEPOINT,"failed to write preprocessor output"); 255 throw preprocessor_error(CODEPOINT,"failed to write preprocessor output");
257} 256}
258/* 257/*
259 * vim:set ft=lex: 258 * vim:set ft=lex:
260 */ 259 */