source: trunk/IPs/systemC/processor/Morpheo/Behavioural/src/Vhdl_get_header.cpp

Last change on this file was 137, checked in by rosiere, 14 years ago

Various modif (add test, and vhdl)

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1#ifdef VHDL
2
3/*
4 * $Id: Vhdl_get_header.cpp 137 2010-02-16 12:35:48Z rosiere $
5 *
6 * [ Description ]
7 *
8 */
9
10#include "Behavioural/include/Vhdl.h"
11#include "Common/include/Environment.h"
12#include <time.h>
13#include <sstream>
14#include <fstream>
15
16namespace morpheo              {
17namespace behavioural          {
18 
19#undef  FUNCTION
20#define FUNCTION "Vhdl::get_header"
21  std::string Vhdl::get_header(uint32_t depth,
22                               std::string   filename)
23  {
24    log_begin(Behavioural,FUNCTION);
25
26    std::string text;
27
28    environment();
29
30    time_t current_time;
31    time (&current_time);
32
33    text += "-------------------------------------------------------------------------------\n";
34    text += "-- "+toString(_("File    : ")) + filename  +"\n";
35    text += "-- "+toString(_("Date    : ")) + ctime (&current_time );
36    text += "-- "+toString(_("Version : ")) + MORPHEO_HEADER +"\n";
37    text += "-- "+toString(_("Id      : ")) + _id +\n";
38    text += "-- "+toString(_("Comment : ")) + _("it's a autogenerated file, don't modify") +"\n";
39    text += "-------------------------------------------------------------------------------\n";
40   
41    log_end(Behavioural,FUNCTION);
42
43    return text;
44  };
45
46#undef  FUNCTION
47#define FUNCTION "vhdl_get_id"
48  std::string vhdl_get_id(std::string model_name)
49  {
50    log_begin(Behavioural,FUNCTION);
51
52    std::string id="";
53
54    directory();
55
56    std::string filename = MORPHEO_VHDL + "/" + model_name + VHDL_EXTENSION;
57    std::ifstream file;
58
59    file.open(filename.c_str(),std::ios::in);
60
61    // open file
62    if (!file)
63      {
64        log_printf(INFO,Behavioural,FUNCTION,_("Can't open file : \"%s\""),filename.c_str());
65      }
66    else
67      {
68        // get line with Id
69        do
70          {
71            std::getline(file,id,'\n'); // comment
72          } while ((id.find("Id      :") == std::string::npos) and
73                   (not file.eof()));
74
75        if (file.eof())
76          log_printf(INFO,Behavioural,FUNCTION,_("\"Id\" not find in file : \"%s\""),filename.c_str());
77        else
78          {
79            // get id
80            id = id.substr(id.find_first_of(':',0)+1,std::string::npos);
81
82            // Erase all ' '
83            size_t i=id.find_first_of(' ',0);
84            while (i!=std::string::npos)
85              {
86                id.erase(i,i+1);
87                i=id.find_first_of(' ',i);
88              }
89          }
90      }
91
92    log_end(Behavioural,FUNCTION);
93
94    return id;
95  };
96 
97}; // end namespace behavioural         
98}; // end namespace morpheo             
99
100#endif
Note: See TracBrowser for help on using the repository browser.