• benjamin@webkit.org's avatar
    Add an utility class to simplify generating function calls · 05413aee
    benjamin@webkit.org authored
    https://bugs.webkit.org/show_bug.cgi?id=125972
    
    Reviewed by Geoffrey Garen.
    
    Source/JavaScriptCore: 
    
    Split branchTest32 in two functions: test32AndSetFlags and branchOnFlags.
    This is done to allow code where the flags are set, multiple operation that
    do not modify the flags occur, then the flags are used.
    
    This is used for function calls to test the return value while discarding the
    return register.
    
    * assembler/MacroAssemblerX86Common.h:
    (JSC::MacroAssemblerX86Common::test32AndSetFlags):
    (JSC::MacroAssemblerX86Common::branchOnFlags):
    (JSC::MacroAssemblerX86Common::branchTest32):
    
    Source/WebCore: 
    
    FunctionCall is a little helper class to make function calls from the JIT
    in 3 or 4 lines.
    
    FunctionCall takes a StackAllocator, a RegisterAllocator and a function pointer.
    When the call is generated, the helper saves the registers as necessary, aligns
    the stack, does the call, restores the stack, and restore the registers.
    
    * cssjit/FunctionCall.h: Added.
    (WebCore::FunctionCall::FunctionCall):
    (WebCore::FunctionCall::setFunctionAddress):
    (WebCore::FunctionCall::setFirstArgument):
    (WebCore::FunctionCall::call):
    
    (WebCore::FunctionCall::callAndBranchOnCondition): Most test functions used
    with FunctionCall return a boolean. When the boolean is the sole purpose of the function
    call, this provides an easy way to branch on the boolean without worrying about registers.
    
    The return register is tested first, then all the saved registers are restored from the stack
    (which can include the return register), finally the flags are used for a jump.
    
    (WebCore::FunctionCall::prepareAndCall):
    (WebCore::FunctionCall::cleanupPostCall):
    (WebCore::FunctionCall::saveAllocatedRegisters):
    (WebCore::FunctionCall::restoreAllocatedRegisters):
    * WebCore.xcodeproj/project.pbxproj:
    * cssjit/FunctionCall.h: Added.
    (WebCore::FunctionCall::FunctionCall):
    (WebCore::FunctionCall::setFunctionAddress):
    (WebCore::FunctionCall::setFirstArgument):
    (WebCore::FunctionCall::call):
    (WebCore::FunctionCall::callAndBranchOnCondition):
    (WebCore::FunctionCall::prepareAndCall):
    (WebCore::FunctionCall::cleanupPostCall):
    (WebCore::FunctionCall::saveAllocatedRegisters):
    (WebCore::FunctionCall::restoreAllocatedRegisters):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@160881 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    05413aee