Ignore:
Timestamp:
Jul 29, 2017, 8:01:12 PM (8 years ago)
Author:
[email protected]
Message:

LLInt offsets extractor should be able to handle C++ constexprs
https://bugs.webkit.org/show_bug.cgi?id=174964

Reviewed by Saam Barati.

This patch adds new syntax to the offline asm language. The new keyword,
constexpr, takes the subsequent identifier and maps it to a C++ constexpr
expression. Additionally, if the value is not an identifier you can wrap it in
parentheses. e.g. constexpr (myConstexprFunction() + OBJECT_OFFSET(Foo, bar)),
which will get converted into:
static_cast<int64_t>(myConstexprFunction() + OBJECT_OFFSET(Foo, bar));

This patch also changes the data format the LLIntOffsetsExtractor
binary produces. Previously, it would produce unsigned values,
after this patch every value is an int64_t. Using an int64_t is
useful because it means that we can represent any constant needed.
int32_t masks are sign extended then passed then converted to a
negative literal sting in the assembler so it will be the constant
expected.

  • llint/LLIntOffsetsExtractor.cpp:

(JSC::LLIntOffsetsExtractor::dummy):

  • llint/LowLevelInterpreter.asm:
  • llint/LowLevelInterpreter64.asm:
  • offlineasm/asm.rb:
  • offlineasm/ast.rb:
  • offlineasm/generate_offset_extractor.rb:
  • offlineasm/offsets.rb:
  • offlineasm/parser.rb:
  • offlineasm/transform.rb:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/offlineasm/parser.rb

    r200125 r220047  
    44# modification, are permitted provided that the following conditions
    55# are met:
    6 # 1. Redistributions of source code must retain the above copyright
     6# 1. Redistributions of source code must retain the above copyrighht
    77#    notice, this list of conditions and the following disclaimer.
    88# 2. Redistributions in binary form must reproduce the above copyright
     
    223223
    224224def isKeyword(token)
    225     token =~ /\A((true)|(false)|(if)|(then)|(else)|(elsif)|(end)|(and)|(or)|(not)|(global)|(macro)|(const)|(sizeof)|(error)|(include))\Z/ or
     225    token =~ /\A((true)|(false)|(if)|(then)|(else)|(elsif)|(end)|(and)|(or)|(not)|(global)|(macro)|(const)|(constexpr)|(sizeof)|(error)|(include))\Z/ or
    226226        token =~ REGISTER_PATTERN or
    227227        isInstruction(token)
     
    418418        [codeOrigin, names]
    419419    end
     420
     421    def parseTextInParens
     422        skipNewLine
     423        codeOrigin = @tokens[@idx].codeOrigin
     424        raise unless @tokens[@idx] == "("
     425        @idx += 1
     426        # need at least one item
     427        raise if @tokens[@idx] == ")"
     428        numEnclosedParens = 0
     429        text = []
     430        while @tokens[@idx] != ")" || numEnclosedParens > 0
     431            if @tokens[@idx] == "("
     432                numEnclosedParens += 1
     433            elsif @tokens[@idx] == ")"
     434                numEnclosedParens -= 1
     435            end
     436
     437            text << @tokens[@idx].string
     438            @idx += 1
     439        end
     440        @idx += 1
     441        return [codeOrigin, text]
     442    end
     443
    420444   
    421445    def parseExpressionAtom
     
    454478            codeOrigin, names = parseColonColon
    455479            Sizeof.forName(codeOrigin, names.join('::'))
     480        elsif @tokens[@idx] == "constexpr"
     481            @idx += 1
     482            skipNewLine
     483            if @tokens[@idx] == "("
     484                codeOrigin, text = parseTextInParens
     485                text = text.join
     486            else
     487                codeOrigin, text = parseColonColon
     488                text = text.join("::")
     489            end
     490            ConstExpr.forName(codeOrigin, text)
    456491        elsif isLabel @tokens[@idx]
    457492            result = LabelReference.new(@tokens[@idx].codeOrigin, Label.forName(@tokens[@idx].codeOrigin, @tokens[@idx].string))
     
    482517   
    483518    def couldBeExpression
    484         @tokens[@idx] == "-" or @tokens[@idx] == "~" or @tokens[@idx] == "sizeof" or isInteger(@tokens[@idx]) or isString(@tokens[@idx]) or isVariable(@tokens[@idx]) or @tokens[@idx] == "("
     519        @tokens[@idx] == "-" or @tokens[@idx] == "~" or @tokens[@idx] == "sizeof" or @tokens[@idx] == "constexpr" or isInteger(@tokens[@idx]) or isString(@tokens[@idx]) or isVariable(@tokens[@idx]) or @tokens[@idx] == "("
    485520    end
    486521   
Note: See TracChangeset for help on using the changeset viewer.