tan  0.0.1
tan.h
1 #ifndef TAN_SRC_LIB_LIBTANC_H_
2 #define TAN_SRC_LIB_LIBTANC_H_
3 #include "base.h"
4 
5 /**
6  * \file libtanc.h
7  * \brief Defines tools for compiling tan source files.
8  * */
9 
10 namespace tanlang {
11 
12 class Parser;
13 class CompilerDriver;
14 
15 /**
16  * \enum TanCompileType
17  * \brief Output file type
18  */
19 enum TanCompileType {
20  OBJ = 0, /// Object file, use as default
21  EXE, /// Executable
22  SLIB, /// Static library
23  DLIB, /// Shared library
24 };
25 
26 /**
27  * \enum TanOptLevel
28  * \brief Optimization level
29  * \details The values must match llvm::CodeGenOpt::Level
30  */
31 enum TanOptLevel {
32  O0 = 0, /// Debug
33  O1 = 1, /// Less
34  O2 = 2, /// Default
35  O3 = 3, /// Aggressive
36 };
37 
38 /**
39  * \struct TanCompilation
40  * \brief Compilation configuration
41  */
43  TanCompileType type = OBJ; /// Type of compilation, \see TanCompileType
44  TanOptLevel opt_level = O0; /// Optimization level, \see TanOptLevel
45  unsigned verbose = 0; /// Verbose level, 0 non-verbose, 1 print LLVM IR, 2, print LLVM IR and abstract syntax tree
46  str out_file = "a.out"; /// Output filename, invalid if TanCompilation::type is set to OBJ
47  vector<str> link_files{}; /// Files to link against
48  vector<str> lib_dirs{}; /// Library search paths
49  vector<str> import_dirs{}; /// Search import paths
50 };
51 
52 /**
53  * \brief Initialize compiler
54  * \note This is required before calling compile_files
55  */
56 bool init_compiler(int argc, char **argv);
57 
58 /**
59  * \brief Get optimization level compiler flag from the enum value.
60  * \note This must match clang's option string.
61  */
62 inline str opt_level_to_string(TanOptLevel l) {
63  switch (l) {
64  case O0:
65  return "-O0";
66  case O1:
67  return "-O1";
68  case O2:
69  return "-O2";
70  case O3:
71  return "-O3";
72  default:
73  TAN_ASSERT(false);
74  }
75 }
76 
77 } // namespace tanlang
78 
79 #endif /* TAN_SRC_LIB_LIBTANC_H_ */
Compilation configuration.
Definition: tan.h:42
vector< str > import_dirs
Library search paths.
Definition: tan.h:49
unsigned verbose
Optimization level,.
Definition: tan.h:45
str out_file
Verbose level, 0 non-verbose, 1 print LLVM IR, 2, print LLVM IR and abstract syntax tree.
Definition: tan.h:46
vector< str > link_files
Output filename, invalid if TanCompilation::type is set to OBJ.
Definition: tan.h:47
TanOptLevel opt_level
Type of compilation,.
Definition: tan.h:44
vector< str > lib_dirs
Files to link against.
Definition: tan.h:48