PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tools/compiler/asm/marshall/liberty_asm_positions.e

http://github.com/tybor/Liberty
Specman e | 186 lines | 143 code | 29 blank | 14 comment | 1 complexity | 613ef1648a9f0c93eac36da8596ab431 MD5 | raw file
  1-- This file is part of Liberty Eiffel.
  2--
  3-- Liberty Eiffel is free software: you can redistribute it and/or modify
  4-- it under the terms of the GNU General Public License as published by
  5-- the Free Software Foundation, version 3 of the License.
  6--
  7-- Liberty Eiffel is distributed in the hope that it will be useful,
  8-- but WITHOUT ANY WARRANTY; without even the implied warranty of
  9-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 10-- GNU General Public License for more details.
 11--
 12-- You should have received a copy of the GNU General Public License
 13-- along with Liberty Eiffel.  If not, see <http://www.gnu.org/licenses/>.
 14--
 15class LIBERTY_ASM_POSITIONS
 16
 17inherit
 18   LIBERTY_ASM_INSTRUCTION_VISITOR
 19   LIBERTY_ASM_PROXY_VISITOR
 20
 21insert
 22   LIBERTY_ASM_CODES
 23
 24create {LIBERTY_ASM_CODES}
 25   make
 26
 27feature {}
 28   make is
 29      do
 30      end
 31
 32feature {LIBERTY_ASM_CODES}
 33   set_positions (a_types: COLLECTION[LIBERTY_ASM_TYPE]) is
 34      require
 35         a_types /= Void
 36      do
 37         a_types.do_all(agent visit_type)
 38      end
 39
 40   sizeof (a_instruction: LIBERTY_ASM_INSTRUCTION): INTEGER is
 41      do
 42         counter := 0
 43         a_instruction.accept(Current)
 44         Result := counter
 45      end
 46
 47feature {}
 48   visit_type (a_type: LIBERTY_ASM_TYPE) is
 49      require
 50         a_type /= Void
 51      do
 52         a_type.do_all_methods(agent visit_method)
 53      end
 54
 55   visit_method (a_method: LIBERTY_ASM_METHOD) is
 56      require
 57         a_method /= Void
 58      do
 59         visit_code(a_method.code,          agent a_method.set_code_size)
 60         visit_code(a_method.retry_code,    agent a_method.set_retry_size)
 61         visit_code(a_method.precondition,  agent a_method.set_precondition_size)
 62         visit_code(a_method.postcondition, agent a_method.set_postcondition_size)
 63      end
 64
 65   visit_code (a_code: LIBERTY_ASM_INSTRUCTION; size_setter: PROCEDURE[TUPLE[INTEGER]]) is
 66      local
 67         code: LIBERTY_ASM_INSTRUCTION
 68      do
 69         if a_code /= Void then
 70            counter := 0
 71            from
 72               code := a_code
 73            until
 74               code = Void
 75            loop
 76               code.accept(Current)
 77               code := code.next
 78            end
 79            check
 80               counter > 0
 81            end
 82            size_setter.call([counter])
 83         end
 84      end
 85
 86   counter: INTEGER
 87
 88   set_position (a_instruction: LIBERTY_ASM_INSTRUCTION; size: INTEGER) is
 89      require
 90         a_instruction /= Void
 91         size > 0
 92      do
 93         a_instruction.set_position(counter)
 94         counter := counter + size
 95      ensure
 96         a_instruction.position = old counter
 97         counter = old counter + size
 98      end
 99
100feature {LIBERTY_ASM_INSTRUCTION}
101   visit_and (a_instruction: LIBERTY_ASM_AND) is
102      do
103         set_position(a_instruction, 1)
104      end
105
106   visit_invoke (a_instruction: LIBERTY_ASM_INVOKE) is
107      do
108         set_position(a_instruction, 9)
109      end
110
111   visit_proxy_invoke (a_instruction: LIBERTY_ASM_INSTRUCTION_PROXY; method_id, type_id: INTEGER) is
112      do
113         set_position(a_instruction, 9)
114      end
115
116   visit_jump (a_instruction: LIBERTY_ASM_JUMP) is
117      do
118         set_position(a_instruction, 5)
119      end
120
121   visit_proxy_jump (a_instruction: LIBERTY_ASM_INSTRUCTION_PROXY; position: INTEGER) is
122      do
123         set_position(a_instruction, 5)
124      end
125
126   visit_new (a_instruction: LIBERTY_ASM_NEW) is
127      do
128         set_position(a_instruction, 5)
129      end
130
131   visit_proxy_new (a_instruction: LIBERTY_ASM_INSTRUCTION_PROXY; type_id: INTEGER) is
132      do
133         set_position(a_instruction, 5)
134      end
135
136   visit_not (a_instruction: LIBERTY_ASM_NOT) is
137      do
138         set_position(a_instruction, 1)
139      end
140
141   visit_or (a_instruction: LIBERTY_ASM_OR) is
142      do
143         set_position(a_instruction, 1)
144      end
145
146   visit_return (a_instruction: LIBERTY_ASM_RETURN) is
147      do
148         set_position(a_instruction, 1)
149      end
150
151   visit_load_int (a_instruction: LIBERTY_ASM_LOAD_INT) is
152      do
153         set_position(a_instruction, 5)
154      end
155
156   visit_add_int (a_instruction: LIBERTY_ASM_ADD_INT) is
157      do
158         set_position(a_instruction, 1)
159      end
160
161   visit_sub_int (a_instruction: LIBERTY_ASM_SUB_INT) is
162      do
163         set_position(a_instruction, 1)
164      end
165
166   visit_mul_int (a_instruction: LIBERTY_ASM_MUL_INT) is
167      do
168         set_position(a_instruction, 1)
169      end
170
171   visit_div_int (a_instruction: LIBERTY_ASM_DIV_INT) is
172      do
173         set_position(a_instruction, 1)
174      end
175
176   visit_rem_int (a_instruction: LIBERTY_ASM_REM_INT) is
177      do
178         set_position(a_instruction, 1)
179      end
180
181   visit_call_native (a_instruction: LIBERTY_ASM_CALL_NATIVE) is
182      do
183         set_position(a_instruction, 6 + a_instruction.arguments.count)
184      end
185
186end -- class LIBERTY_ASM_WRITER