author | Mario de Sousa <msousa@fe.up.pt> |
Thu, 31 Mar 2011 10:45:34 +0100 | |
changeset 258 | d7d92b2f87e9 |
parent 210 | 8387cac2aba6 |
child 267 | 0a1204bcc9af |
permissions | -rwxr-xr-x |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
1 |
/* |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
2 |
* (c) 2003 Mario de Sousa |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
3 |
* |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
4 |
* Offered to the public under the terms of the GNU General Public License |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
6 |
* License, or (at your option) any later version. |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
7 |
* |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
8 |
* This program is distributed in the hope that it will be useful, but |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
11 |
* Public License for more details. |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
12 |
* |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
13 |
* This code is made available on the understanding that it will not be |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
14 |
* used in safety-critical situations without a full and competent review. |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
15 |
*/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
16 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
17 |
/* |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
18 |
* An IEC 61131-3 IL and ST compiler. |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
19 |
* |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
20 |
* Based on the |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
22 |
* |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
23 |
*/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
24 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
25 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
26 |
/* |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
27 |
* This file contains the code that stores the output generated |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
28 |
* by each specific version of the 4th stage. |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
29 |
*/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
30 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
31 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
32 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
33 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
34 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
35 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
36 |
// #include <stdio.h> /* required for NULL */ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
37 |
#include <string> |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
38 |
#include <iostream> |
27
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
39 |
#include <fstream> |
139
668a54686827
added missing includes on some platform (gentoo/gcc-4.3.1)
etisserant
parents:
55
diff
changeset
|
40 |
#include <stdlib.h> |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
41 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
42 |
#include "stage4.hh" |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
43 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
44 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
45 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
46 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
47 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
48 |
|
27
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
49 |
stage4out_c::stage4out_c(std::string indent_level): |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
50 |
m_file(NULL) { |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
51 |
out = &std::cout; |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
52 |
this->indent_level = indent_level; |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
53 |
this->indent_spaces = ""; |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
54 |
} |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
55 |
|
46
fc1b78ea6d84
Adding support for generating files into an user-defined folder
lbessard
parents:
41
diff
changeset
|
56 |
stage4out_c::stage4out_c(const char *dir, const char *radix, const char *extension, std::string indent_level) { |
27
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
57 |
std::string filename(radix); |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
58 |
filename += "."; |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
59 |
filename += extension; |
46
fc1b78ea6d84
Adding support for generating files into an user-defined folder
lbessard
parents:
41
diff
changeset
|
60 |
std::string filepath(""); |
fc1b78ea6d84
Adding support for generating files into an user-defined folder
lbessard
parents:
41
diff
changeset
|
61 |
if (dir != NULL) { |
fc1b78ea6d84
Adding support for generating files into an user-defined folder
lbessard
parents:
41
diff
changeset
|
62 |
filepath += dir; |
fc1b78ea6d84
Adding support for generating files into an user-defined folder
lbessard
parents:
41
diff
changeset
|
63 |
filepath += "/"; |
fc1b78ea6d84
Adding support for generating files into an user-defined folder
lbessard
parents:
41
diff
changeset
|
64 |
} |
fc1b78ea6d84
Adding support for generating files into an user-defined folder
lbessard
parents:
41
diff
changeset
|
65 |
filepath += filename; |
fc1b78ea6d84
Adding support for generating files into an user-defined folder
lbessard
parents:
41
diff
changeset
|
66 |
std::fstream *file = new std::fstream(filepath.c_str(), std::fstream::out); |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
28
diff
changeset
|
67 |
if(file->fail()){ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
28
diff
changeset
|
68 |
std::cerr << "Cannot open " << filename << " for write access \n"; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
28
diff
changeset
|
69 |
exit(EXIT_FAILURE); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
28
diff
changeset
|
70 |
}else{ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
28
diff
changeset
|
71 |
std::cout << filename << "\n"; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
28
diff
changeset
|
72 |
} |
27
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
73 |
out = file; |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
74 |
m_file = file; |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
75 |
this->indent_level = indent_level; |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
76 |
this->indent_spaces = ""; |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
77 |
} |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
78 |
|
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
79 |
stage4out_c::~stage4out_c(void) { |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
80 |
if(m_file) |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
81 |
{ |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
82 |
m_file->close(); |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
83 |
delete m_file; |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
84 |
} |
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
85 |
} |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
86 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
87 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
88 |
void stage4out_c::indent_right(void) { |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
89 |
indent_spaces+=indent_level; |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
90 |
} |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
91 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
92 |
void stage4out_c::indent_left(void) { |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
93 |
if (indent_spaces.length() >= indent_level.length()) |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
94 |
indent_spaces.erase(indent_spaces.length() - indent_level.length(), indent_level.length()); |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
95 |
else |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
96 |
indent_spaces.erase(); |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
97 |
} |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
98 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
99 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
100 |
void *stage4out_c::print(const char *str) { |
27
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
101 |
*out << str; |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
102 |
return NULL; |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
103 |
} |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
104 |
|
28
5b170c9ce134
Multi-file configuration and resource generation finished
lbessard
parents:
27
diff
changeset
|
105 |
void *stage4out_c::print_integer(int integer) { |
5b170c9ce134
Multi-file configuration and resource generation finished
lbessard
parents:
27
diff
changeset
|
106 |
*out << integer; |
5b170c9ce134
Multi-file configuration and resource generation finished
lbessard
parents:
27
diff
changeset
|
107 |
return NULL; |
5b170c9ce134
Multi-file configuration and resource generation finished
lbessard
parents:
27
diff
changeset
|
108 |
} |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
109 |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
202
diff
changeset
|
110 |
void *stage4out_c::print_long_integer(unsigned long l_integer) { |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
202
diff
changeset
|
111 |
*out << l_integer << "UL"; |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
202
diff
changeset
|
112 |
return NULL; |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
202
diff
changeset
|
113 |
} |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
202
diff
changeset
|
114 |
|
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
202
diff
changeset
|
115 |
void *stage4out_c::print_long_long_integer(unsigned long long ll_integer) { |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
202
diff
changeset
|
116 |
*out << ll_integer << "ULL"; |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
202
diff
changeset
|
117 |
return NULL; |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
202
diff
changeset
|
118 |
} |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
202
diff
changeset
|
119 |
|
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
120 |
void *stage4out_c::printupper(const char *str) { |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
121 |
for (int i = 0; str[i] != '\0'; i++) |
27
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
122 |
*out << (unsigned char)toupper(str[i]); |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
123 |
return NULL; |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
124 |
} |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
125 |
|
26
fd67f54e64e1
Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents:
0
diff
changeset
|
126 |
void *stage4out_c::printlocation(const char *str) { |
27
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
127 |
*out << "__"; |
26
fd67f54e64e1
Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents:
0
diff
changeset
|
128 |
for (int i = 0; str[i] != '\0'; i++) |
fd67f54e64e1
Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents:
0
diff
changeset
|
129 |
if(str[i] == '.') |
27
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
130 |
*out << '_'; |
26
fd67f54e64e1
Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents:
0
diff
changeset
|
131 |
else |
27
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
132 |
*out << (unsigned char)toupper(str[i]); |
26
fd67f54e64e1
Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents:
0
diff
changeset
|
133 |
return NULL; |
fd67f54e64e1
Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents:
0
diff
changeset
|
134 |
} |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
135 |
|
55
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
136 |
void *stage4out_c::printlocation_comasep(const char *str) { |
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
137 |
*out << (unsigned char)toupper(str[0]); |
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
138 |
*out << ','; |
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
139 |
*out << (unsigned char)toupper(str[1]); |
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
140 |
*out << ','; |
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
141 |
for (int i = 2; str[i] != '\0'; i++) |
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
142 |
if(str[i] == '.') |
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
143 |
*out << ','; |
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
144 |
else |
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
145 |
*out << (unsigned char)toupper(str[i]); |
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
146 |
return NULL; |
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
147 |
} |
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
148 |
|
8b7a21820737
Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents:
46
diff
changeset
|
149 |
|
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
150 |
void *stage4out_c::print(std::string str) { |
27
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
151 |
*out << str; |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
152 |
return NULL; |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
153 |
} |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
154 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
155 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
156 |
void *stage4out_c::printupper(std::string str) { |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
157 |
/* The string standard class does not have a converter member function to upper case. |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
158 |
* We have to do it ourselves, a character at a time... |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
159 |
*/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
160 |
#if 0 |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
161 |
/* The C++ way of doint things... */ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
162 |
for (string::const_iterator p = str.begin(); p != str.end(); ++p) |
27
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
163 |
*out << (unsigned char)toupper(*p); |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
164 |
#else |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
165 |
/* Or more simply... */ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
166 |
printupper(str.c_str()); |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
167 |
#endif |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
168 |
return NULL; |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
169 |
} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
139
diff
changeset
|
170 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
139
diff
changeset
|
171 |
|
26
fd67f54e64e1
Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents:
0
diff
changeset
|
172 |
void *stage4out_c::printlocation(std::string str) { |
27
667721cf52c5
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents:
26
diff
changeset
|
173 |
return printlocation(str.c_str()); |
26
fd67f54e64e1
Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents:
0
diff
changeset
|
174 |
} |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
175 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
176 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
177 |
/***********************************************************************/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
178 |
/***********************************************************************/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
179 |
/***********************************************************************/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
180 |
/***********************************************************************/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
181 |
/***********************************************************************/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
182 |
/***********************************************************************/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
183 |
/***********************************************************************/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
184 |
/***********************************************************************/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
185 |
/***********************************************************************/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
186 |
/***********************************************************************/ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
187 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
188 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
189 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
190 |
/* forward declarations... */ |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
191 |
/* These functions will be implemented in generate_XXX.cc */ |
46
fc1b78ea6d84
Adding support for generating files into an user-defined folder
lbessard
parents:
41
diff
changeset
|
192 |
visitor_c *new_code_generator(stage4out_c *s4o, const char *builddir); |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
193 |
void delete_code_generator(visitor_c *code_generator); |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
194 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
195 |
|
46
fc1b78ea6d84
Adding support for generating files into an user-defined folder
lbessard
parents:
41
diff
changeset
|
196 |
int stage4(symbol_c *tree_root, const char *builddir) { |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
197 |
stage4out_c s4o; |
46
fc1b78ea6d84
Adding support for generating files into an user-defined folder
lbessard
parents:
41
diff
changeset
|
198 |
visitor_c *generate_code = new_code_generator(&s4o, builddir); |
0
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
199 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
200 |
if (NULL == generate_code) |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
201 |
return -1; |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
202 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
203 |
tree_root->accept(*generate_code); |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
204 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
205 |
delete_code_generator(generate_code); |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
206 |
|
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
207 |
return 0; |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
208 |
} |
fb772792efd1
Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff
changeset
|
209 |