Ignore:
Timestamp:
Jul 19, 2012, 1:53:22 PM (13 years ago)
Author:
[email protected]
Message:

Bug fixes and enhancements for OfflineASM annotation system.
https://bugs.webkit.org/show_bug.cgi?id=91690

Patch by Mark Lam <[email protected]> on 2012-07-19
Reviewed by Filip Pizlo.

  • offlineasm/armv7.rb: added default handling of Instruction lower().
  • offlineasm/asm.rb: added more support for annotations and more pretty printing.
  • offlineasm/ast.rb: added more support for annotations.
  • offlineasm/config.rb: added $preferredCommentStartColumn, simplified $enableInstrAnnotations.
  • offlineasm/parser.rb: added more support for annotations.
  • offlineasm/transform.rb: added more support for annotations.
  • offlineasm/x86.rb: added default handling of Instruction lower().
File:
1 edited

Legend:

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

    r122650 r123147  
    7575end
    7676
     77class Annotation
     78    attr_reader :codeOrigin, :type, :string
     79    def initialize(codeOrigin, type, string)
     80        @codeOrigin = codeOrigin
     81        @type = type
     82        @string = string
     83    end
     84end
     85
    7786#
    7887# The lexer. Takes a string and returns an array of tokens.
     
    8493    lineNumber = 1
    8594    annotation = nil
     95    whitespaceFound = false
    8696    while not str.empty?
    8797        case str
    8898        when /\A\#([^\n]*)/
    8999            # comment, ignore
    90         when /\A\/\/([^\n]*)/
     100        when /\A\/\/\ ?([^\n]*)/
    91101            # annotation
    92102            annotation = $1
     103            annotationType = whitespaceFound ? :local : :global
    93104        when /\A\n/
    94105            # We've found a '\n'.  Emit the last comment recorded if appropriate:
    95106            if $enableInstrAnnotations and annotation
    96                 result << Token.new(CodeOrigin.new(fileName, lineNumber), "@" + annotation)
     107                result << Annotation.new(CodeOrigin.new(fileName, lineNumber),
     108                                         annotationType, annotation)
    97109                annotation = nil
    98110            end
     
    107119        when /\A([ \t]+)/
    108120            # whitespace, ignore
     121            whitespaceFound = true
     122            str = $~.post_match
     123            next
    109124        when /\A0x([0-9a-fA-F]+)/
    110125            result << Token.new(CodeOrigin.new(fileName, lineNumber), $&.hex.to_s)
     
    120135            raise "Lexer error at #{CodeOrigin.new(fileName, lineNumber).to_s}, unexpected sequence #{str[0..20].inspect}"
    121136        end
     137        whitespaceFound = false
    122138        str = $~.post_match
    123139    end
     
    147163end
    148164
    149 def isAnnotation(token)
    150     token =~ /\A\@([^\n]*)/
    151 end
    152 
    153165def isLabel(token)
    154166    token =~ /\A_([a-zA-Z0-9_]*)\Z/
     
    176188        @tokens = lex(data, fileName)
    177189        @idx = 0
     190        @annotation = nil
    178191    end
    179192   
     
    488501            if (@idx == @tokens.length and not final) or (final and @tokens[@idx] =~ final)
    489502                break
     503            elsif @tokens[@idx].is_a? Annotation
     504                # This is the only place where we can encounter a global
     505                # annotation, and hence need to be able to distinguish between
     506                # them.
     507                # globalAnnotations are the ones that start from column 0. All
     508                # others are considered localAnnotations.  The only reason to
     509                # distinguish between them is so that we can format the output
     510                # nicely as one would expect.
     511
     512                codeOrigin = @tokens[@idx].codeOrigin
     513                annotationOpcode = (@tokens[@idx].type == :global) ? "globalAnnotation" : "localAnnotation"
     514                list << Instruction.new(codeOrigin, annotationOpcode, [], @tokens[@idx].string)
     515                @annotation = nil
     516                @idx += 2 # Consume the newline as well.
    490517            elsif @tokens[@idx] == "\n"
    491518                # ignore
     
    548575                if (not final and @idx == @tokens.size) or (final and @tokens[@idx] =~ final)
    549576                    # Zero operand instruction, and it's the last one.
    550                     list << Instruction.new(codeOrigin, name, [])
     577                    list << Instruction.new(codeOrigin, name, [], @annotation)
     578                    @annotation = nil
    551579                    break
    552                 elsif isAnnotation @tokens[@idx]
    553                     annotation = @tokens[@idx].string
    554                     list << Instruction.new(codeOrigin, name, [], annotation)
     580                elsif @tokens[@idx].is_a? Annotation
     581                    list << Instruction.new(codeOrigin, name, [], @tokens[@idx].string)
     582                    @annotation = nil
    555583                    @idx += 2 # Consume the newline as well.
    556584                elsif @tokens[@idx] == "\n"
    557585                    # Zero operand instruction.
    558                     list << Instruction.new(codeOrigin, name, [])
     586                    list << Instruction.new(codeOrigin, name, [], @annotation)
     587                    @annotation = nil
    559588                    @idx += 1
    560589                else
     
    562591                    operands = []
    563592                    endOfSequence = false
    564                     annotation = nil
    565593                    loop {
    566594                        operands << parseOperand("while inside of instruction #{name}")
     
    572600                            # Has another operand.
    573601                            @idx += 1
    574                         elsif isAnnotation @tokens[@idx]
    575                             annotation = @tokens[@idx].string
     602                        elsif @tokens[@idx].is_a? Annotation
     603                            @annotation = @tokens[@idx].string
    576604                            @idx += 2 # Consume the newline as well.
    577605                            break
     
    584612                        end
    585613                    }
    586                     list << Instruction.new(codeOrigin, name, operands, annotation)
     614                    list << Instruction.new(codeOrigin, name, operands, @annotation)
     615                    @annotation = nil
    587616                    if endOfSequence
    588617                        break
    589618                    end
    590619                end
     620
     621            # Check for potential macro invocation:
    591622            elsif isIdentifier @tokens[@idx]
    592623                codeOrigin = @tokens[@idx].codeOrigin
     
    625656                        }
    626657                    end
    627                     list << MacroCall.new(codeOrigin, name, operands)
     658                    # Check if there's a trailing annotation after the macro invoke:
     659                    if @tokens[@idx].is_a? Annotation
     660                        @annotation = @tokens[@idx].string
     661                        @idx += 2 # Consume the newline as well.
     662                    end
     663                    list << MacroCall.new(codeOrigin, name, operands, @annotation)
     664                    @annotation = nil
    628665                else
    629666                    parseError "Expected \"(\" after #{name}"
Note: See TracChangeset for help on using the changeset viewer.