Changeset 123147 in webkit for trunk/Source/JavaScriptCore/offlineasm/parser.rb
- Timestamp:
- Jul 19, 2012, 1:53:22 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/offlineasm/parser.rb
r122650 r123147 75 75 end 76 76 77 class Annotation 78 attr_reader :codeOrigin, :type, :string 79 def initialize(codeOrigin, type, string) 80 @codeOrigin = codeOrigin 81 @type = type 82 @string = string 83 end 84 end 85 77 86 # 78 87 # The lexer. Takes a string and returns an array of tokens. … … 84 93 lineNumber = 1 85 94 annotation = nil 95 whitespaceFound = false 86 96 while not str.empty? 87 97 case str 88 98 when /\A\#([^\n]*)/ 89 99 # comment, ignore 90 when /\A\/\/ ([^\n]*)/100 when /\A\/\/\ ?([^\n]*)/ 91 101 # annotation 92 102 annotation = $1 103 annotationType = whitespaceFound ? :local : :global 93 104 when /\A\n/ 94 105 # We've found a '\n'. Emit the last comment recorded if appropriate: 95 106 if $enableInstrAnnotations and annotation 96 result << Token.new(CodeOrigin.new(fileName, lineNumber), "@" + annotation) 107 result << Annotation.new(CodeOrigin.new(fileName, lineNumber), 108 annotationType, annotation) 97 109 annotation = nil 98 110 end … … 107 119 when /\A([ \t]+)/ 108 120 # whitespace, ignore 121 whitespaceFound = true 122 str = $~.post_match 123 next 109 124 when /\A0x([0-9a-fA-F]+)/ 110 125 result << Token.new(CodeOrigin.new(fileName, lineNumber), $&.hex.to_s) … … 120 135 raise "Lexer error at #{CodeOrigin.new(fileName, lineNumber).to_s}, unexpected sequence #{str[0..20].inspect}" 121 136 end 137 whitespaceFound = false 122 138 str = $~.post_match 123 139 end … … 147 163 end 148 164 149 def isAnnotation(token)150 token =~ /\A\@([^\n]*)/151 end152 153 165 def isLabel(token) 154 166 token =~ /\A_([a-zA-Z0-9_]*)\Z/ … … 176 188 @tokens = lex(data, fileName) 177 189 @idx = 0 190 @annotation = nil 178 191 end 179 192 … … 488 501 if (@idx == @tokens.length and not final) or (final and @tokens[@idx] =~ final) 489 502 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. 490 517 elsif @tokens[@idx] == "\n" 491 518 # ignore … … 548 575 if (not final and @idx == @tokens.size) or (final and @tokens[@idx] =~ final) 549 576 # 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 551 579 break 552 elsif isAnnotation @tokens[@idx]553 annotation = @tokens[@idx].string554 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 555 583 @idx += 2 # Consume the newline as well. 556 584 elsif @tokens[@idx] == "\n" 557 585 # Zero operand instruction. 558 list << Instruction.new(codeOrigin, name, []) 586 list << Instruction.new(codeOrigin, name, [], @annotation) 587 @annotation = nil 559 588 @idx += 1 560 589 else … … 562 591 operands = [] 563 592 endOfSequence = false 564 annotation = nil565 593 loop { 566 594 operands << parseOperand("while inside of instruction #{name}") … … 572 600 # Has another operand. 573 601 @idx += 1 574 elsif isAnnotation @tokens[@idx]575 annotation = @tokens[@idx].string602 elsif @tokens[@idx].is_a? Annotation 603 @annotation = @tokens[@idx].string 576 604 @idx += 2 # Consume the newline as well. 577 605 break … … 584 612 end 585 613 } 586 list << Instruction.new(codeOrigin, name, operands, annotation) 614 list << Instruction.new(codeOrigin, name, operands, @annotation) 615 @annotation = nil 587 616 if endOfSequence 588 617 break 589 618 end 590 619 end 620 621 # Check for potential macro invocation: 591 622 elsif isIdentifier @tokens[@idx] 592 623 codeOrigin = @tokens[@idx].codeOrigin … … 625 656 } 626 657 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 628 665 else 629 666 parseError "Expected \"(\" after #{name}"
Note:
See TracChangeset
for help on using the changeset viewer.