summaryrefslogtreecommitdiffabout
path: root/lib/sitecing_enflesher.ll
authorMichael Krelin <hacker@klever.net>2005-01-29 21:21:05 (UTC)
committer Michael Krelin <hacker@klever.net>2005-01-29 21:21:05 (UTC)
commitce1f37aae46ea95020d7b865f7a80e8abdfad0d8 (patch) (unidiff)
tree4964383ab8cd7e6d8ea821f1a615d1bbcf98dad8 /lib/sitecing_enflesher.ll
parent3c75c860fc1ad5b3f5185e23ec6f438dd2528958 (diff)
downloadsitecing-0.0.zip
sitecing-0.0.tar.gz
sitecing-0.0.tar.bz2
initial commit into repository0.0
Diffstat (limited to 'lib/sitecing_enflesher.ll') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/sitecing_enflesher.ll202
1 files changed, 202 insertions, 0 deletions
diff --git a/lib/sitecing_enflesher.ll b/lib/sitecing_enflesher.ll
new file mode 100644
index 0000000..5f631d7
--- a/dev/null
+++ b/lib/sitecing_enflesher.ll
@@ -0,0 +1,202 @@
1%{
2#include <iostream>
3#include <fstream>
4#include <cassert>
5#include <stdexcept>
6using namespace std;
7#include "sitecing/sitecing_exception.h"
8using namespace sitecing;
9#define sitecing_enflesher_flexlexer_once
10#include "sitecing/sitecing_enflesher.h"
11#include "sitecing/sitecing_parser.h"
12#undef yyFlexLexer
13#define yyFlexLexer sitecing_enflesherFlexLexer
14%}
15%option 8bit c++ verbose noyywrap yyclass="sitecing_enflesher" yylineno prefix="sitecing_enflesher" stack debug
16
17 ID[A-Za-z_][A-Za-z0-9_]*
18
19%%
20
21 ^\%\%\#[^\n]+\n{
22 string line = yytext;
23 line.erase(0,3);
24 line.erase(line.length()-1);
25 outs.flush();
26 outs.close();
27 outs.clear();
28 outs.open((parser.output_basename+line).c_str(),ios::trunc);
29 if(!outs.good())
30 throw preprocessor_error(CODEPOINT,"failed to write preprocessor output");
31 anchor();
32 anchoraged = true;
33}
34 ^\%\%[^\n]+\n{
35 string line = yytext;
36 line.erase(0,2);
37 line.erase(line.length()-1);
38 outs.flush();
39 outs.close();
40 outs.clear();
41 outs.open((parser.output_basename+line).c_str(),ios::trunc);
42 if(!outs.good())
43 throw preprocessor_error(CODEPOINT,"failed to write preprocessor output");
44 anchoraged = false;
45}
46
47 \<\%component_basename\%\>outs << parser.component_basename; anchor_time = true;
48 \<\%impl\%\> outs << parser.impl; anchor_time = true;
49 \<\%member_functions:impl\%\>{
50 for(sitecing_parser::member_functions_t::const_iterator i=parser.member_functions.begin();i!=parser.member_functions.end();i++) {
51 outs << i->type << " " << parser.class_name << "::";
52 if(i->name.empty()) {
53 outs << parser.class_name << "()";
54 bool first = true;
55 for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) {
56 if(i->initializer.empty())
57 continue;
58 if(first) {
59 outs << ":";
60 first=false;
61 }else{
62 outs << ",";
63 }
64 if(i->bComponent) {
65 outs << i->name << "(NULL)";
66 }else {
67 outs << i->name << "(" << i->initializer << ")";
68 }
69 }
70 }else if(i->name == "~")
71 outs << "~" << parser.class_name << "()";
72 else
73 outs << i->name << i->args;
74 outs << "{\n" << i->body << "\n}\n";
75 }
76 anchor_time = true;
77}
78 \<\%class_name\%\> outs << parser.class_name; anchor_time = true;
79 \<\%baseclass_header\%\>outs << parser.base_header; anchor_time = true;
80 \<\%decl\%\> outs << parser.decl; anchor_time = true;
81 \<\%baseclass_name\%\> outs << parser.base_class; anchor_time = true;
82 \<\%member_variables:decl\%\>{
83 for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) {
84 if(i->bComponent) {
85 if(i->type.empty()) {
86 i->type = parser.factory.get_classname(i->initializer);
87 }
88 if(i->bTypeOnly) {
89 outs << "typedef " << i->type << " " << i->name << ";\n";
90 }else{
91 outs << "typedef " << i->type << " __type_" << i->name << ";\nsitecing::so_component __soc_" << i->name << ";\n__type_" << i->name << " *" << i->name << ";\n";
92 }
93 }else{
94 outs << i->type << " " << i->name << ";\n";
95 }
96 }
97 anchor_time = true;
98}
99 \<\%member_functions:decl\%\>{
100 for(sitecing_parser::member_functions_t::const_iterator i=parser.member_functions.begin();i!=parser.member_functions.end();i++) {
101 (i->name.empty()?outs:outs << "virtual ")
102 << i->type << " ";
103 if(i->name.empty()) {
104 outs << parser.class_name << "()";
105 }else if(i->name == "~")
106 outs << "~" << parser.class_name << "()";
107 else
108 outs << i->name << i->args;
109 outs << ";\n";
110 }
111 anchor_time = true;
112}
113 \<\%imports:list\%\> {
114 for(sitecing_parser::member_variables_t::const_iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) {
115 if(i->bComponent)
116 outs << i->initializer << endl;
117 }
118 anchor_time = true;
119}
120 \<\%imports:includes\%\>{
121 for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) {
122 if(i->bComponent)
123 outs << "\n#include \"" << i->initializer << ".h\"\n";
124 }
125 anchor_time = true;
126}
127 \<\%imports:import\%\>{
128 for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) {
129 if(!i->bComponent)
130 continue;
131 if(i->bTypeOnly)
132 continue;
133 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";
134 }
135 anchor_time = true;
136}
137
138 \<\%base_component\%\> {
139 // TODO:
140 anchor_time = true;
141}
142
143 \<\%ancestors:includes\%\>{
144 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) {
145 outs << "#include \"" << i->path << ".h\"\n";
146 }
147 anchor_time = true;
148}
149 \<\%ancestors:component_list\%\>{
150 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) {
151 outs << i->path << "\n";
152 }
153 anchor_time = true;
154}
155 \<\%ancestors:base_clause_part\%\>{
156 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) {
157 outs << ", virtual public " << parser.factory.get_classname(i->path);
158 }
159}
160 \<\%ancestors:typedefs\%\> {
161 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) {
162 outs << "typedef class " << parser.factory.get_classname(i->path) << " " << i->name << ";\n";
163 }
164 anchor_time = true;
165}
166 \<\%ancestors:import\%\> {
167 for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) {
168 outs << i->name << "::__do_imports();\n";
169 }
170 anchor_time = true;
171}
172
173 \n {
174 if(anchor_time)
175 anchor();
176 ECHO;
177}
178 . ECHO;
179
180%%
181
182void sitecing_enflesher::LexerOutput(const char *buf,int size) {
183 outs.write(buf,size);
184}
185
186void sitecing_enflesher::enflesh() {
187 ifstream ifs(parser.skeleton.c_str());
188 if(!ifs.good())
189 throw preprocessor_error(CODEPOINT,"failed to open skeleton file");
190 switch_streams(&ifs,NULL);
191 yylex();
192}
193
194void sitecing_enflesher::anchor() {
195 if(!anchoraged)
196 return;
197 outs << "\n#line " << lineno() << " \"" << parser.skeleton << "\"\n";
198 anchor_time = false;
199}
200/*
201 * vim:set ft=lex:
202 */