Fletchgen
The Fletcher Design Generator
utils.cc
1 // Copyright 2018-2019 Delft University of Technology
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "fletchgen/utils.h"
16 
17 #include <fletcher/common.h>
18 #include <cerata/api.h>
19 #include <cstdlib>
20 
21 #include "fletchgen_config/config.h"
22 
23 namespace fletchgen {
24 
25 std::string GetProgramName(char *argv0) {
26  auto arg = std::string(argv0);
27  size_t pos = arg.rfind('\\');
28  if (pos != std::string::npos) {
29  return arg.substr(pos + 1);
30  } else {
31  return "fletchgen";
32  }
33 }
34 
35 cerata::Port::Dir mode2dir(fletcher::Mode mode) {
36  if (mode == fletcher::Mode::READ) {
37  return cerata::Port::Dir::IN;
38  } else {
39  return cerata::Port::Dir::OUT;
40  }
41 }
42 
43 void LogCerata(cerata::LogLevel level,
44  std::string const &message,
45  char const *source_function,
46  char const *source_file,
47  int line_number) {
48  switch (level) {
49  default: {
50  FLETCHER_LOG(DEBUG, message);
51  return;
52  }
53  case cerata::CERATA_LOG_INFO: {
54  FLETCHER_LOG(INFO, message);
55  return;
56  }
57  case cerata::CERATA_LOG_WARNING: {
58  FLETCHER_LOG(WARNING, message);
59  return;
60  }
61  case cerata::CERATA_LOG_ERROR: {
62  FLETCHER_LOG(ERROR, message);
63  std::abort();
64  }
65  case cerata::CERATA_LOG_FATAL: {
66  FLETCHER_LOG(FATAL, message);
67  std::abort();
68  }
69  }
70 }
71 
72 std::string version() {
73  return "fletchgen " + std::to_string(FLETCHGEN_VERSION_MAJOR)
74  + "." + std::to_string(FLETCHGEN_VERSION_MINOR)
75  + "." + std::to_string(FLETCHGEN_VERSION_PATCH);
76 }
77 
78 } // namespace fletchgen
Contains all classes and functions related to Fletchgen.
Definition: array.cc:29
void LogCerata(cerata::LogLevel level, std::string const &message, char const *source_function, char const *source_file, int line_number)
Callback function for the Cerata logger.
Definition: utils.cc:43
std::string GetProgramName(char *argv0)
Return the name of this program executable.
Definition: utils.cc:25
std::string version()
Return Fletchgen version string.
Definition: utils.cc:72
cerata::Port::Dir mode2dir(fletcher::Mode mode)
Return a Cerata port direction from a Fletcher access mode.
Definition: utils.cc:35