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
25 # Generates ICode for the whole program
26 fun generate_icode_files
do
29 with_each_live_local_classes
!action
(c
) do
30 c
.generate_icode_file
(tc
.compdir
.as(not null))
35 # A class to dump ICode to a file
41 # We don't want to output line numbers and locations
47 for i
in [0..indent_level
[ do
55 redef class MMLocalClass
56 # Generates ICode for all properties of this class in a file
57 fun generate_icode_file
(dir
: String) do
58 var file
= new OFStream.open
("{dir}/{self}.icode")
59 if primitive_info
== null then
60 # Initialization methods
61 if init_var_iroutine
!= null then
62 var icd
= new FileICodeDumper(file
)
64 file
.write
("Init var iroutine::\n")
65 init_var_iroutine
.dump
(icd
)
68 if checknew_iroutine
!= null then
69 var icd
= new FileICodeDumper(file
)
71 file
.write
("Check new instance iroutine::\n")
72 checknew_iroutine
.dump
(icd
)
77 for pg
in global_properties
do
78 if not pg
.is_init_for
(self) then continue
81 var icd
= new FileICodeDumper(file
)
83 file
.write
("New instance:: {p.full_name}\n")
84 new_instance_iroutine
[p
].dump
(icd
)
90 for pg
in global_properties
do
92 if p
.local_class
== self and p
isa MMMethod then
93 p
.generate_icode
(file
)
101 # Generates ICode for this method with a little header
102 fun generate_icode
(file
: OFStream) do
103 var icd
= new FileICodeDumper(file
)
105 file
.write
("Method:: {full_name}\n")