--- a/.cvsignore Fri Jul 20 22:07:15 2007 +0200
+++ b/.cvsignore Wed Jul 25 18:03:27 2007 +0200
@@ -3,3 +3,4 @@
iec2cc
*.txt
*.c
+*.h
--- a/main.cc Fri Jul 20 22:07:15 2007 +0200
+++ b/main.cc Wed Jul 25 18:03:27 2007 +0200
@@ -82,7 +82,7 @@
/* forward declarations... */
int stage1_2(const char *filename, const char *includedir, symbol_c **tree_root);
//int stage3(symbol_c *tree_root);
-int stage4(symbol_c *tree_root);
+int stage4(symbol_c *tree_root, const char *builddir);
static void printusage(const char *cmd) {
@@ -94,6 +94,12 @@
int main(int argc, char **argv) {
symbol_c *tree_root;
char * includedir = NULL;
+ char * builddir = NULL;
+
+ if (argc == 5) {
+ builddir = argv[4];
+ argc = 4;
+ }
if (argc == 4) {
if (strcmp(argv[2], "-I") != 0) {
@@ -104,6 +110,11 @@
argc = 2;
}
+ if (argc == 3) {
+ builddir = argv[2];
+ argc = 2;
+ }
+
if (argc != 2) {
printusage(argv[0]);
return EXIT_FAILURE;
@@ -121,7 +132,7 @@
*/
/* 3rd Pass */
- if (stage4(tree_root) < 0)
+ if (stage4(tree_root, builddir) < 0)
return EXIT_FAILURE;
/* 4th Pass */
--- a/stage4/generate_cc/generate_cc.cc Fri Jul 20 22:07:15 2007 +0200
+++ b/stage4/generate_cc/generate_cc.cc Wed Jul 25 18:03:27 2007 +0200
@@ -1388,15 +1388,17 @@
symbol_c *current_configuration;
const char *current_name;
+ const char *current_builddir;
unsigned long common_ticktime;
public:
- generate_cc_c(stage4out_c *s4o_ptr):
+ generate_cc_c(stage4out_c *s4o_ptr, const char *builddir):
s4o(*s4o_ptr),
- pous_s4o("POUS", "c"),
- located_variables_s4o("LOCATED_VARIABLES","h"),
+ pous_s4o(builddir, "POUS", "c"),
+ located_variables_s4o(builddir, "LOCATED_VARIABLES","h"),
generate_cc_pous(&pous_s4o) {
+ current_builddir = builddir;
current_configuration = NULL;
}
@@ -1472,7 +1474,7 @@
common_ticktime = calculate_common_ticktime.get_ticktime();
symbol->configuration_name->accept(*this);
- stage4out_c config_s4o(current_name, "c");
+ stage4out_c config_s4o(current_builddir, current_name, "c");
generate_cc_config_c generate_cc_config(&config_s4o);
symbol->accept(generate_cc_config);
@@ -1489,14 +1491,14 @@
void *visit(resource_declaration_c *symbol) {
symbol->resource_name->accept(*this);
- stage4out_c resources_s4o(current_name, "c");
+ stage4out_c resources_s4o(current_builddir, current_name, "c");
generate_cc_resources_c generate_cc_resources(&resources_s4o, current_configuration, symbol, common_ticktime);
symbol->accept(generate_cc_resources);
return NULL;
}
void *visit(single_resource_declaration_c *symbol) {
- stage4out_c resources_s4o("RESOURCE", "c");
+ stage4out_c resources_s4o(current_builddir, "RESOURCE", "c");
generate_cc_resources_c generate_cc_resources(&resources_s4o, current_configuration, symbol, common_ticktime);
symbol->accept(generate_cc_resources);
return NULL;
@@ -1516,7 +1518,7 @@
-visitor_c *new_code_generator(stage4out_c *s4o) {return new generate_cc_c(s4o);}
+visitor_c *new_code_generator(stage4out_c *s4o, const char *builddir) {return new generate_cc_c(s4o, builddir);}
void delete_code_generator(visitor_c *code_generator) {delete code_generator;}
--- a/stage4/generate_iec/generate_iec.cc Fri Jul 20 22:07:15 2007 +0200
+++ b/stage4/generate_iec/generate_iec.cc Wed Jul 25 18:03:27 2007 +0200
@@ -1843,7 +1843,7 @@
-visitor_c *new_code_generator(stage4out_c *s4o) {return new generate_iec_c(s4o);}
+visitor_c *new_code_generator(stage4out_c *s4o, const char *builddir) {return new generate_iec_c(s4o);}
void delete_code_generator(visitor_c *code_generator) {delete code_generator;}
--- a/stage4/stage4.cc Fri Jul 20 22:07:15 2007 +0200
+++ b/stage4/stage4.cc Wed Jul 25 18:03:27 2007 +0200
@@ -53,11 +53,17 @@
this->indent_spaces = "";
}
-stage4out_c::stage4out_c(const char *radix, const char *extension, std::string indent_level) {
+stage4out_c::stage4out_c(const char *dir, const char *radix, const char *extension, std::string indent_level) {
std::string filename(radix);
filename += ".";
filename += extension;
- std::fstream *file = new std::fstream(filename.c_str(), std::fstream::out);
+ std::string filepath("");
+ if (dir != NULL) {
+ filepath += dir;
+ filepath += "/";
+ }
+ filepath += filename;
+ std::fstream *file = new std::fstream(filepath.c_str(), std::fstream::out);
if(file->fail()){
std::cerr << "Cannot open " << filename << " for write access \n";
exit(EXIT_FAILURE);
@@ -157,13 +163,13 @@
/* forward declarations... */
/* These functions will be implemented in generate_XXX.cc */
-visitor_c *new_code_generator(stage4out_c *s4o);
+visitor_c *new_code_generator(stage4out_c *s4o, const char *builddir);
void delete_code_generator(visitor_c *code_generator);
-int stage4(symbol_c *tree_root) {
+int stage4(symbol_c *tree_root, const char *builddir) {
stage4out_c s4o;
- visitor_c *generate_code = new_code_generator(&s4o);
+ visitor_c *generate_code = new_code_generator(&s4o, builddir);
if (NULL == generate_code)
return -1;
--- a/stage4/stage4.hh Fri Jul 20 22:07:15 2007 +0200
+++ b/stage4/stage4.hh Wed Jul 25 18:03:27 2007 +0200
@@ -38,7 +38,7 @@
public:
stage4out_c(std::string indent_level = " ");
- stage4out_c(const char *radix, const char *extension, std::string indent_level = " ");
+ stage4out_c(const char *dir, const char *radix, const char *extension, std::string indent_level = " ");
~stage4out_c(void);
void indent_right(void);