ni_nitdoc: added fast copy past utility to signatures.
[nit.git] / src / nitc.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2008 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Nit compiler main module
18 package nitc
19
20 import abstracttool
21 import analysis
22 import global
23 import program
24 import compiling
25 import syntax
26 import native_interface
27 import separate_options
28 import ffi
29
30 # The main class of the nitcompiler program
31 class NitCompiler
32 super AbstractCompiler
33 readable var _opt_output: OptionString = new OptionString("Output file", "-o", "--output")
34 readable var _opt_boost: OptionBool = new OptionBool("Optimize compilation", "-O", "--boost")
35 readable var _opt_no_cc: OptionBool = new OptionBool("Do not invoke C compiler", "--no-cc")
36 readable var _opt_cc_no_link: OptionBool = new OptionBool("Do not invoke C linker", "--cc-no-link")
37 readable var _opt_clibdir: OptionString = new OptionString("NIT C library directory", "--clibdir")
38 readable var _opt_bindir: OptionString = new OptionString("NIT tools directory", "--bindir")
39 readable var _opt_compdir: OptionString = new OptionString("Intermediate compilation directory", "--compdir")
40 readable var _opt_extension_prefix: OptionString = new OptionString("Append prefix to file extension", "-p", "--extension-prefix")
41 readable var _opt_output_format: OptionEnum = new OptionEnum(["none", "C", "icode"], "The type of code we want to be generated", 1, "--output-format")
42
43 init
44 do
45 super("nitc")
46 option_context.add_option(opt_output, opt_boost, opt_no_cc, opt_cc_no_link, opt_cc_libs, opt_cc_lib_paths, opt_cc_include_paths, opt_clibdir, opt_bindir, opt_compdir, opt_extension_prefix, opt_output_format)
47 end
48
49 redef fun process_options
50 do
51 super
52 output_file = opt_output.value
53 boost = opt_boost.value
54 no_cc = opt_no_cc.value
55 cc_link = not opt_cc_no_link.value
56 cc_lib_paths.add_all( opt_cc_lib_paths.value )
57 cc_libs.add_all( opt_cc_libs.value )
58 cc_include_paths.add_all( opt_cc_include_paths.value )
59 var ext = opt_extension_prefix.value
60 if ext != null then ext_prefix = ext else ext_prefix = ""
61 compdir = opt_compdir.value
62 if compdir == null then
63 var dir = "NIT_COMPDIR".environ
64 if not dir.is_empty then
65 compdir = dir
66 end
67 if compdir == null then
68 compdir = ".nit_compile"
69 end
70 end
71 compdir += ext_prefix
72 compdir = compdir.simplify_path
73
74 clibdir = opt_clibdir.value
75 if clibdir == null then
76 var dir = "NIT_DIR".environ
77 if dir.is_empty then
78 dir = "{sys.program_name.dirname}/../clib"
79 if dir.file_exists then clibdir = dir
80 else
81 dir = "{dir}/clib"
82 if dir.file_exists then clibdir = dir
83 end
84 if clibdir == null then
85 fatal_error(null, "Error: Cannot locate NIT C library directory. Uses --clibdir or envvar NIT_DIR.")
86 end
87 end
88 clibdir = clibdir.simplify_path
89
90 bindir = opt_bindir.value
91 if bindir == null then
92 var dir = "NIT_DIR".environ
93 if dir.is_empty then
94 dir = "{sys.program_name.dirname}/../bin"
95 if dir.file_exists then bindir = dir
96 else
97 dir = "{dir}/bin"
98 if dir.file_exists then bindir = dir
99 end
100 if bindir == null then
101 fatal_error(null, "Error: Cannot locate NIT tools directory. Uses --bindir or envvar NIT_DIR.")
102 end
103 end
104 bindir = bindir.simplify_path
105 end
106
107 redef fun perform_work(mods)
108 do
109 for mod in mods do
110 var p = new Program(mod, self)
111 p.output_format = opt_output_format.value_name
112 p.compute_main_method
113 p.generate_allocation_iroutines
114 if global then p.do_global_analysis
115 p.do_table_computation
116 p.compile_prog
117 end
118 end
119 end
120
121 redef class ToolContext
122 redef init do super # Avoid local property conflict
123 end
124
125
126 var c = new NitCompiler
127 c.exec_cmd_line