node/lib/metasm/metasm/cpu/ia32/compile_c.rb
def c_init_state(func)
		@state = State.new(func)
		# ET_DYN trashes ebx too
		# XXX hope we're not a Shellcode to be embedded in an ELF..
		@state.abi_flushregs_call << 3 if @exeformat and @exeformat.shortname == 'elf'

		c_reserve_stack(func.initializer)
		off = @state.offset.values.max.to_i	# where to store register args
		off = 0 if off < 0

		al = typesize[:ptr]
		argoff = 2*al
		fa = func.type.args.dup
		if func.has_attribute('fastcall')
			2.times {
				if a = fa.shift
					off = c_reserve_stack_var(a, off)
					@state.offset[a] = off
				end
			}
		end
		fa.each { |a|
			if a.has_attribute_var('register') or a.type.has_attribute_var('register')
				off = c_reserve_stack_var(a, off)
				@state.offset[a] = off
				next
			end
			@state.offset[a] = -argoff
			argoff = (argoff + sizeof(a) + al - 1) / al * al
		}
		if not @state.offset.values.grep(::Integer).empty?
			@state.saved_ebp = Reg.new(5, @cpusz)
			@state.used << 5
		end
	end
# holds compiler state information for a function
# registers are saved as register number (see Ia32::Reg)
# TODO cache eflags ? or just z ? (may be defered to asm_optimize)
holds compiler state information for a function
registers are saved as register number
TODO cache eflags . or just z . (may be defered to asm_optimize)
holds compiler state information for a function registers are saved as register number TODO cache eflags . or just z . ( may be defered to asm_optimize )
def c_init_state(func)
		@state = State.new(func)
		@state.abi_flushregs_call << 3 if @exeformat and @exeformat.shortname == 'elf'
		c_reserve_stack(func.initializer)
		off = @state.offset.values.max.to_i	
		off = 0 if off < 0
		al = typesize[:ptr]
		argoff = 2*al
		fa = func.type.args.dup
		if func.has_attribute('fastcall')
			2.times {
				if a = fa.shift
					off = c_reserve_stack_var(a, off)
					@state.offset[a] = off
				end
			}
		end
		fa.each { |a|
			if a.has_attribute_var('register') or a.type.has_attribute_var('register')
				off = c_reserve_stack_var(a, off)
				@state.offset[a] = off
				next
			end
			@state.offset[a] = -argoff
			argoff = (argoff + sizeof(a) + al - 1) / al * al
		}
		if not @state.offset.values.grep(::Integer).empty?
			@state.saved_ebp = Reg.new(5, @cpusz)
			@state.used << 5
		end
	end
def c_init_state ( func ) @state = State . new ( func ) @state . abi_flushregs_call << 3 if @exeformat and @exeformat . shortname == 'elf' c_reserve_stack ( func . initializer ) off = @state . offset . values . max . to_i off = 0 if off < 0 al = typesize [ :ptr ] argoff = 2 * al fa = func . type . args . dup if func . has_attribute ( 'fastcall' ) 2 . times { if a = fa . shift off = c_reserve_stack_var ( a , off ) @state . offset [ a ] = off end } end fa . each { | a | if a . has_attribute_var ( 'register' ) or a . type . has_attribute_var ( 'register' ) off = c_reserve_stack_var ( a , off ) @state . offset [ a ] = off next end @state . offset [ a ] = - argoff argoff = ( argoff + sizeof ( a ) + al - 1 ) / al * al } if not @state . offset . values . grep ( :: Integer ) . empty? @state . saved_ebp = Reg . new ( 5 , @cpusz ) @state . used << 5 end end
holds compiler state information for a function
registers are saved as register number (see Ia32::Reg)
TODO cache eflags ?
holds compiler state information for a function registers are saved as register number ( see Ia32 :: Reg ) TODO cache eflags ?
# ET_DYN trashes ebx too # XXX hope we're not a Shellcode to be embedded in an ELF.. # where to store register args
func