1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
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 # Generates ICode as an output format
18 package icode_generator
20 private import compiling_base
22 private import analysis
23 private import primitive_info
26 # Generates ICode for the whole program
27 fun generate_icode_files
do
30 with_each_live_local_classes
!action
(c
) do
31 c
.generate_icode_file
(tc
.compdir
.as(not null))
36 # A class to dump ICode to a file
42 # We don't want to output line numbers and locations
48 for i
in [0..indent_level
[ do
56 redef class MMLocalClass
57 # Generates ICode for all properties of this class in a file
58 fun generate_icode_file
(dir
: String) do
59 var file
= new OFStream.open
("{dir}/{self}.icode")
60 if primitive_info
== null then
61 # Initialization methods
62 if init_var_iroutine
!= null then
63 var icd
= new FileICodeDumper(file
)
65 file
.write
("Init var iroutine::\n")
66 init_var_iroutine
.dump
(icd
)
69 if checknew_iroutine
!= null then
70 var icd
= new FileICodeDumper(file
)
72 file
.write
("Check new instance iroutine::\n")
73 checknew_iroutine
.dump
(icd
)
78 for pg
in global_properties
do
79 if not pg
.is_init_for
(self) then continue
82 if not new_instance_iroutine
.has_key
(p
) then continue
83 var icd
= new FileICodeDumper(file
)
85 file
.write
("New instance:: {p.full_name}\n")
86 new_instance_iroutine
[p
].dump
(icd
)
92 for pg
in global_properties
do
94 if p
.local_class
== self and p
isa MMMethod then
95 p
.generate_icode
(file
)
103 # Generates ICode for this method with a little header
104 fun generate_icode
(file
: OFStream) do
105 var icd
= new FileICodeDumper(file
)
107 file
.write
("Method:: {full_name}\n")