node/lib/metasm/metasm/cpu/ia32/compile_c.rb
def make_volatile(e, type, rsz=@cpusz)
		if e.kind_of? ModRM or @state.bound.index(e)
			if type.integral? or type.pointer?
				oldval = @state.cache[e]
				if type.integral? and type.name == :__int64 and @cpusz != 64
					e2l = inuse findreg(32)
					unuse e
					e2h = inuse findreg(32)
					el, eh = get_composite_parts e
					instr 'mov', e2l, el
					instr 'mov', e2h, eh
					e2 = inuse Composite.new(e2l, e2h)
					unuse e2l, e2h
				else
					unuse e
					n = type.integral? ? type.name : :ptr
					if (sz = typesize[n]*8) < @cpusz or sz < rsz or e.sz < rsz
						e2 = inuse findreg(rsz)
						op = ((type.specifier == :unsigned) ? 'movzx' : 'movsx')
						op = 'mov' if e.sz == e2.sz
					else
						e2 = inuse findreg(sz)
						op = 'mov'
					end
					instr op, e2, e
				end
				@state.cache[e2] = oldval if oldval and e.kind_of? ModRM
				e2
			elsif type.float?
				raise 'bad float static' + e.inspect if not e.kind_of? ModRM
				unuse e
				instr 'fld', e
				FpReg.new nil
			else raise
			end
		elsif e.kind_of? Address
			make_volatile resolve_address(e), type, rsz
		elsif e.kind_of? Expression
			if type.integral? or type.pointer?
				if type.integral? and type.name == :__int64 and @cpusz != 64
					e2 = inuse Composite.new(inuse(findreg(32)), findreg(32))
					instr 'mov', e2.low, Expression[e, :&, 0xffff_ffff]
					instr 'mov', e2.high, Expression[e, :>>, 32]
				else
					e2 = inuse findreg
					instr 'mov', e2, e
				end
				e2
			elsif type.float?
				case e.reduce
				when 0; instr 'fldz'
				when 1; instr 'fld1'
				else
					esp = Reg.new(4, @cpusz)
					instr 'push.i32', Expression[e, :>>, 32]
					instr 'push.i32', Expression[e, :&, 0xffff_ffff]
					instr 'fild', ModRM.new(@cpusz, 64, nil, nil, esp, nil)
					instr 'add', esp, 8
				end
				FpReg.new nil
			end
		else
			e
		end
	end
# copies the arg e to a volatile location (register/composite) if it is not already
# unuses the old storage
# may return a register bigger than the type size (eg __int8 are stored in full reg size)
# use rsz only to force 32bits-return on a 16bits cpu
copies the arg e to a volatile location (register/composite) if it is not already
unuses the old storage
may return a register bigger than the type size
use rsz only to force 32bits-return on a 16bits cpu
copies the arg e to a volatile location ( register / composite ) if it is not already unuses the old storage may return a register bigger than the type size use rsz only to force 32bits - return on a 16bits cpu
def make_volatile(e, type, rsz=@cpusz)
		if e.kind_of? ModRM or @state.bound.index(e)
			if type.integral? or type.pointer?
				oldval = @state.cache[e]
				if type.integral? and type.name == :__int64 and @cpusz != 64
					e2l = inuse findreg(32)
					unuse e
					e2h = inuse findreg(32)
					el, eh = get_composite_parts e
					instr 'mov', e2l, el
					instr 'mov', e2h, eh
					e2 = inuse Composite.new(e2l, e2h)
					unuse e2l, e2h
				else
					unuse e
					n = type.integral? ? type.name : :ptr
					if (sz = typesize[n]*8) < @cpusz or sz < rsz or e.sz < rsz
						e2 = inuse findreg(rsz)
						op = ((type.specifier == :unsigned) ? 'movzx' : 'movsx')
						op = 'mov' if e.sz == e2.sz
					else
						e2 = inuse findreg(sz)
						op = 'mov'
					end
					instr op, e2, e
				end
				@state.cache[e2] = oldval if oldval and e.kind_of? ModRM
				e2
			elsif type.float?
				raise 'bad float static' + e.inspect if not e.kind_of? ModRM
				unuse e
				instr 'fld', e
				FpReg.new nil
			else raise
			end
		elsif e.kind_of? Address
			make_volatile resolve_address(e), type, rsz
		elsif e.kind_of? Expression
			if type.integral? or type.pointer?
				if type.integral? and type.name == :__int64 and @cpusz != 64
					e2 = inuse Composite.new(inuse(findreg(32)), findreg(32))
					instr 'mov', e2.low, Expression[e, :&, 0xffff_ffff]
					instr 'mov', e2.high, Expression[e, :>>, 32]
				else
					e2 = inuse findreg
					instr 'mov', e2, e
				end
				e2
			elsif type.float?
				case e.reduce
				when 0; instr 'fldz'
				when 1; instr 'fld1'
				else
					esp = Reg.new(4, @cpusz)
					instr 'push.i32', Expression[e, :>>, 32]
					instr 'push.i32', Expression[e, :&, 0xffff_ffff]
					instr 'fild', ModRM.new(@cpusz, 64, nil, nil, esp, nil)
					instr 'add', esp, 8
				end
				FpReg.new nil
			end
		else
			e
		end
	end
def make_volatile ( e , type , rsz = @cpusz ) if e . kind_of? ModRM or @state . bound . index ( e ) if type . integral? or type . pointer? oldval = @state . cache [ e ] if type . integral? and type . name == :__int64 and @cpusz != 64 e2l = inuse findreg ( 32 ) unuse e e2h = inuse findreg ( 32 ) el , eh = get_composite_parts e instr 'mov' , e2l , el instr 'mov' , e2h , eh e2 = inuse Composite . new ( e2l , e2h ) unuse e2l , e2h else unuse e n = type . integral? ? type . name : :ptr if ( sz = typesize [ n ] * 8 ) < @cpusz or sz < rsz or e . sz < rsz e2 = inuse findreg ( rsz ) op = ( ( type . specifier == :unsigned ) ? 'movzx' : 'movsx' ) op = 'mov' if e . sz == e2 . sz else e2 = inuse findreg ( sz ) op = 'mov' end instr op , e2 , e end @state . cache [ e2 ] = oldval if oldval and e . kind_of? ModRM e2 elsif type . float? raise 'bad float static' + e . inspect if not e . kind_of? ModRM unuse e instr 'fld' , e FpReg . new nil else raise end elsif e . kind_of? Address make_volatile resolve_address ( e ) , type , rsz elsif e . kind_of? Expression if type . integral? or type . pointer? if type . integral? and type . name == :__int64 and @cpusz != 64 e2 = inuse Composite . new ( inuse ( findreg ( 32 ) ) , findreg ( 32 ) ) instr 'mov' , e2 . low , Expression [ e , :& , 0xffff_ffff ] instr 'mov' , e2 . high , Expression [ e , :>> , 32 ] else e2 = inuse findreg instr 'mov' , e2 , e end e2 elsif type . float? case e . reduce when 0 ; instr 'fldz' when 1 ; instr 'fld1' else esp = Reg . new ( 4 , @cpusz ) instr 'push.i32' , Expression [ e , :>> , 32 ] instr 'push.i32' , Expression [ e , :& , 0xffff_ffff ] instr 'fild' , ModRM . new ( @cpusz , 64 , nil , nil , esp , nil ) instr 'add' , esp , 8 end FpReg . new nil end else e end end
copies the arg e to a volatile location (register/composite) if it is not already
unuses the old storage
may return a register bigger than the type size (eg __int8 are stored in full reg size)
use rsz only to force 32bits-return on a 16bits cpu
copies the arg e to a volatile location ( register / composite ) if it is not already unuses the old storage may return a register bigger than the type size ( eg __int8 are stored in full reg size ) use rsz only to force 32bits - return on a 16bits cpu
e
type
rsz