/src/tools/compiler/asm/marshall/liberty_asm_writer.e
Specman e | 214 lines | 173 code | 27 blank | 14 comment | 5 complexity | ffcb8d63883521e21c9ff78a2be2fa00 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_WRITER 16 17inherit 18 LIBERTY_ASM_INSTRUCTION_VISITOR 19 20insert 21 LIBERTY_ASM_CODES 22 23create {LIBERTY_ASM_MARSHALLER} 24 write 25 26feature {} 27 write (a_stream: OUTPUT_STREAM; a_system: LIBERTY_ASM_SYSTEM) is 28 require 29 a_stream /= Void 30 a_system /= Void 31 do 32 positions.set_positions(a_system.types) 33 stream := a_stream 34 put_data(system_marker) 35 put_data(a_system.main.id) 36 put_data(a_system.main.type.id) 37 a_system.types.do_all(agent visit_type) 38 end 39 40 stream: OUTPUT_STREAM 41 42 put_string (string: ABSTRACT_STRING) is 43 require 44 string /= Void 45 do 46 put_data(string.count) 47 string.do_all(agent (c: CHARACTER) is 48 do 49 put_code(c.to_integer_8) 50 end 51 ) 52 end 53 54 put_native (native: LIBERTY_ASM_NATIVE_VALUE) is 55 do 56 if native = Void then 57 put_code(native_void) 58 elseif native.is_integer then 59 put_code(native_integer) 60 elseif native.is_pointer then 61 put_code(native_pointer) 62 else 63 check False end 64 end 65 end 66 67 put_code (code: INTEGER_8) is 68 do 69 stream.put_character(code.to_character) 70 end 71 72 put_data (int: INTEGER) is 73 do 74 stream.put_character(( int & 0xff).to_character) 75 stream.put_character(((int |>> 8) & 0xff).to_character) 76 stream.put_character(((int |>> 16) & 0xff).to_character) 77 stream.put_character(((int |>> 24) & 0xff).to_character) 78 end 79 80 visit_type (a_type: LIBERTY_ASM_TYPE) is 81 require 82 a_type /= Void 83 do 84 put_data(type_marker) 85 put_data(a_type.id) 86 put_data(a_type.attributes_count) 87 put_data(a_type.methods_count) 88 a_type.do_all_methods(agent visit_method) 89 end 90 91 visit_method (a_method: LIBERTY_ASM_METHOD) is 92 local 93 flags: INTEGER_8 94 do 95 put_data(method_marker) 96 put_data(a_method.id) 97 put_data(a_method.parameters.count) 98 if a_method.retry_code /= Void then 99 flags := flags | flag_retry 100 end 101 if a_method.precondition /= Void then 102 flags := flags | flag_precondition 103 end 104 if a_method.postcondition /= Void then 105 flags := flags | flag_postcondition 106 end 107 put_code(flags) 108 visit_code(a_method.code, a_method.code_size) 109 visit_code(a_method.retry_code, a_method.retry_size) 110 visit_code(a_method.precondition, a_method.precondition_size) 111 visit_code(a_method.postcondition, a_method.postcondition_size) 112 end 113 114 visit_code (a_instruction: LIBERTY_ASM_INSTRUCTION; size: INTEGER) is 115 require 116 size > 0 implies a_instruction /= Void 117 size >= 0 118 local 119 code: LIBERTY_ASM_INSTRUCTION 120 do 121 if size > 0 then 122 put_data(size) 123 from 124 code := a_instruction 125 until 126 code = Void 127 loop 128 code.accept(Current) 129 code := code.next 130 end 131 end 132 end 133 134feature {LIBERTY_ASM_INSTRUCTION} 135 visit_and (a_instruction: LIBERTY_ASM_AND) is 136 do 137 put_code(asm_and) 138 end 139 140 visit_invoke (a_instruction: LIBERTY_ASM_INVOKE) is 141 do 142 put_code(asm_invoke) 143 put_data(a_instruction.method.type.id) 144 put_data(a_instruction.method.id) 145 end 146 147 visit_jump (a_instruction: LIBERTY_ASM_JUMP) is 148 do 149 put_code(asm_jump) 150 put_data(a_instruction.target.position) 151 end 152 153 visit_new (a_instruction: LIBERTY_ASM_NEW) is 154 do 155 put_code(asm_new) 156 put_data(a_instruction.type.id) 157 end 158 159 visit_not (a_instruction: LIBERTY_ASM_NOT) is 160 do 161 put_code(asm_not) 162 end 163 164 visit_or (a_instruction: LIBERTY_ASM_OR) is 165 do 166 put_code(asm_or) 167 end 168 169 visit_return (a_instruction: LIBERTY_ASM_RETURN) is 170 do 171 put_code(asm_return) 172 end 173 174 visit_load_int (a_instruction: LIBERTY_ASM_LOAD_INT) is 175 do 176 put_code(asm_load_int) 177 put_data(a_instruction.value) 178 end 179 180 visit_add_int (a_instruction: LIBERTY_ASM_ADD_INT) is 181 do 182 put_code(asm_add_int) 183 end 184 185 visit_sub_int (a_instruction: LIBERTY_ASM_SUB_INT) is 186 do 187 put_code(asm_sub_int) 188 end 189 190 visit_mul_int (a_instruction: LIBERTY_ASM_MUL_INT) is 191 do 192 put_code(asm_mul_int) 193 end 194 195 visit_div_int (a_instruction: LIBERTY_ASM_DIV_INT) is 196 do 197 put_code(asm_div_int) 198 end 199 200 visit_rem_int (a_instruction: LIBERTY_ASM_REM_INT) is 201 do 202 put_code(asm_rem_int) 203 end 204 205 visit_call_native (a_instruction: LIBERTY_ASM_CALL_NATIVE) is 206 do 207 put_code(asm_call_native) 208 put_string(a_instruction.symbol) 209 put_native(a_instruction.return) 210 put_data(a_instruction.arguments.count) 211 a_instruction.arguments.do_all(agent put_native) 212 end 213 214end -- class LIBERTY_ASM_WRITER