1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2008 Jean Privat <jean@pryen.org>
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # Nit compiler main module
21 private import compiling
23 # The main class of the nitcompiler program
25 special AbstractCompiler
26 readable attr _opt_output
: OptionString = new OptionString("Output file", "-o", "--output")
27 readable attr _opt_boost
: OptionBool = new OptionBool("Optimize compilation", "-O", "--boost")
28 readable attr _opt_no_cc
: OptionBool = new OptionBool("Do not invoke C compiler", "--no_cc")
29 readable attr _opt_attr_sim
: OptionBool = new OptionBool("Use attribute simulation", "--attr-sim")
30 readable attr _opt_global
: OptionBool = new OptionBool("Use global compilation", "--global")
31 readable attr _opt_clibdir
: OptionString = new OptionString("NIT C library directory", "--clibdir")
32 readable attr _opt_bindir
: OptionString = new OptionString("NIT tools directory", "--bindir")
33 readable attr _opt_extension_prefix
: OptionString = new OptionString("Append prefix to file extension", "-p", "--extension-prefix")
38 option_context
.add_option
(opt_output
, opt_boost
, opt_no_cc
, opt_attr_sim
, opt_global
, opt_clibdir
, opt_bindir
, opt_extension_prefix
)
41 redef meth process_options
45 tc
.output_file
= opt_output
.value
46 tc
.boost
= opt_boost
.value
47 tc
.no_cc
= opt_no_cc
.value
48 tc
.ext_prefix
= opt_extension_prefix
.value
49 if tc
.ext_prefix
== null then tc
.ext_prefix
= ""
50 tc
.attr_sim
= opt_attr_sim
.value
51 tc
.global
= opt_global
.value
52 tc
.base_dir
= ".nit_compile"
53 tc
.clibdir
= opt_clibdir
.value
54 if tc
.clibdir
== null then
55 var dir
= once
("NIT_DIR".to_symbol
).environ
57 var dir
= "{sys.program_name.dirname}/../lib"
58 if dir
.file_exists
then tc
.clibdir
= dir
61 if dir
.file_exists
then tc
.clibdir
= dir
63 if tc
.clibdir
== null then
64 error
("Error: Cannot locate NIT C library directory. Uses --clibdir or envvar NIT_DIR.")
68 tc
.bindir
= opt_bindir
.value
69 if tc
.bindir
== null then
70 var dir
= once
("NIT_DIR".to_symbol
).environ
72 var dir
= "{sys.program_name.dirname}/../bin"
73 if dir
.file_exists
then tc
.bindir
= dir
76 if dir
.file_exists
then tc
.bindir
= dir
78 if tc
.bindir
== null then
79 error
("Error: Cannot locate NIT tools directory. Uses --bindir or envvar NIT_DIR.")
85 redef meth perform_work
(mods
)
88 assert mod
isa MMSrcModule
89 mod
.compile_prog_to_c
(tc
)
95 var c
= new NitCompiler