node/lib/metasm/metasm/cpu/x86_64/compile_c.rb
# holds compiler state information for a function
# registers are saved as register number (see Reg)
holds compiler state information for a function
registers are saved as register number
holds compiler state information for a function registers are saved as register number
def c_prolog
		localspc = @state.offset.values.grep(::Integer).max
		return if @state.func.attributes.to_a.include? 'naked'
		@state.dirty -= @state.abi_trashregs
		if localspc
			localspc = (localspc + 7) / 8 * 8
			if @state.args_space > 0 and (localspc/8 + @state.dirty.length) & 1 == 1
				localspc += 8
			end
			ebp = @state.saved_rbp
			esp = Reg.new(4, ebp.sz)
			instr 'push', ebp
			instr 'mov', ebp, esp
			instr 'sub', esp, Expression[localspc] if localspc > 0
			rlist = @state.regargs.dup
			@state.func.type.args.each { |a|
				if rn = a.has_attribute_var('register')
					r = Reg.from_str(rn).val
				elsif r = rlist.shift
				else next
				end
				v = findvar(a)
				instr 'mov', v, Reg.new(r, v.sz)
			}
		elsif @state.args_space > 0 and @state.dirty.length & 1 == 0
			instr 'sub', Reg.new(4, @cpusz), Expression[8]
		end
		@state.dirty.each { |reg|
			instr 'push', Reg.new(reg, @cpusz)
		}
	end
def c_prolog localspc = @state . offset . values . grep ( :: Integer ) . max return if @state . func . attributes . to_a . include? 'naked' @state . dirty -= @state . abi_trashregs if localspc localspc = ( localspc + 7 ) / 8 * 8 if @state . args_space > 0 and ( localspc / 8 + @state . dirty . length ) & 1 == 1 localspc += 8 end ebp = @state . saved_rbp esp = Reg . new ( 4 , ebp . sz ) instr 'push' , ebp instr 'mov' , ebp , esp instr 'sub' , esp , Expression [ localspc ] if localspc > 0 rlist = @state . regargs . dup @state . func . type . args . each { | a | if rn = a . has_attribute_var ( 'register' ) r = Reg . from_str ( rn ) . val elsif r = rlist . shift else next end v = findvar ( a ) instr 'mov' , v , Reg . new ( r , v . sz ) } elsif @state . args_space > 0 and @state . dirty . length & 1 == 0 instr 'sub' , Reg . new ( 4 , @cpusz ) , Expression [ 8 ] end @state . dirty . each { | reg | instr 'push' , Reg . new ( reg , @cpusz ) } end
holds compiler state information for a function
registers are saved as register number (see Reg)
holds compiler state information for a function registers are saved as register number ( see Reg )
# ensure 16-o stack align on windows