Changeset 122650 in webkit
- Timestamp:
- Jul 13, 2012 5:44:47 PM (12 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 1 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r122646 r122650 1 2012-07-13 Mark Lam <mark.lam@apple.com> 2 3 OfflineASM Pretty printing and commenting enhancements. 4 https://bugs.webkit.org/show_bug.cgi?id=91281 5 6 Reviewed by Filip Pizlo. 7 8 Added some minor pretty printing in the OfflineASM. 9 Also added infrastruture for adding multiple types of comments and 10 annotations with the ability to enable/disable them in the generated 11 output as desired. 12 13 * GNUmakefile.list.am: add new file config.rb. 14 * llint/LLIntOfflineAsmConfig.h: 15 Added OFFLINE_ASM_BEGIN, OFFLINE_ASM_END, and OFFLINE_ASM_LOCAL_LABEL macros. 16 This will allow us to redefine these for other backends later. 17 * llint/LowLevelInterpreter32_64.asm: 18 Add a small example of instruction annotations for now. 19 * llint/LowLevelInterpreter64.asm: 20 Add a small example of instruction annotations for now. 21 * offlineasm/armv7.rb: Added handling of annotations. 22 * offlineasm/asm.rb: 23 Added machinery to dump the new comments and annotations. 24 Also added some indentations to make the output a little prettier. 25 * offlineasm/ast.rb: Added annotation field in class Instruction. 26 * offlineasm/backends.rb: 27 * offlineasm/config.rb: Added. 28 Currently only contains commenting options. This file is meant to be 29 a centralized place for build config values much like config.h for 30 JavaScriptCore. 31 * offlineasm/generate_offset_extractor.rb: 32 * offlineasm/instructions.rb: 33 * offlineasm/offsets.rb: 34 * offlineasm/opt.rb: 35 * offlineasm/parser.rb: Parse and record annotations. 36 * offlineasm/registers.rb: 37 * offlineasm/self_hash.rb: 38 * offlineasm/settings.rb: 39 * offlineasm/transform.rb: 40 * offlineasm/x86.rb: Added handling of annotations. 41 1 42 2012-07-13 Filip Pizlo <fpizlo@apple.com> 2 43 -
trunk/Source/JavaScriptCore/GNUmakefile.list.am
r122544 r122650 685 685 Source/JavaScriptCore/offlineasm/ast.rb \ 686 686 Source/JavaScriptCore/offlineasm/backends.rb \ 687 Source/JavaScriptCore/offlineasm/config.rb \ 687 688 Source/JavaScriptCore/offlineasm/generate_offset_extractor.rb \ 688 689 Source/JavaScriptCore/offlineasm/instructions.rb \ -
trunk/Source/JavaScriptCore/llint/LLIntOfflineAsmConfig.h
r119729 r122650 92 92 #endif 93 93 94 // These are for building an interpreter from generated assembly code: 95 #define OFFLINE_ASM_BEGIN asm ( 96 #define OFFLINE_ASM_END ); 97 94 98 #if CPU(ARM_THUMB2) 95 99 #define OFFLINE_ASM_GLOBAL_LABEL(label) \ … … 106 110 #endif 107 111 112 #define OFFLINE_ASM_LOCAL_LABEL(label) LOCAL_LABEL_STRING(label) ":\n" 113 108 114 #endif // LLIntOfflineAsmConfig_h -
trunk/Source/JavaScriptCore/llint/LowLevelInterpreter32_64.asm
r121925 r122650 302 302 _llint_op_enter: 303 303 traceExecution() 304 loadp CodeBlock[cfr], t2 305 loadi CodeBlock::m_numVars[t2], t2 304 loadp CodeBlock[cfr], t2 // t2<CodeBlock> = cfr.CodeBlock 305 loadi CodeBlock::m_numVars[t2], t2 // t2<size_t> = t2<CodeBlock>.m_numVars 306 306 btiz t2, .opEnterDone 307 307 move UndefinedTag, t0 -
trunk/Source/JavaScriptCore/llint/LowLevelInterpreter64.asm
r121925 r122650 183 183 _llint_op_enter: 184 184 traceExecution() 185 loadp CodeBlock[cfr], t2 186 loadi CodeBlock::m_numVars[t2], t2 185 loadp CodeBlock[cfr], t2 // t2<CodeBlock> = cfr.CodeBlock 186 loadi CodeBlock::m_numVars[t2], t2 // t2<size_t> = t2<CodeBlock>.m_numVars 187 187 btiz t2, .opEnterDone 188 188 move ValueUndefined, t0 -
trunk/Source/JavaScriptCore/offlineasm/armv7.rb
r114434 r122650 22 22 # THE POSSIBILITY OF SUCH DAMAGE. 23 23 24 require "config" 24 25 require "ast" 25 26 require "opt" … … 148 149 | node | 149 150 if node.is_a? Instruction 151 annotation = node.annotation 150 152 case node.opcode 151 153 when /^b(addi|subi|ori|addp)/ … … 162 164 end 163 165 164 newList << Instruction.new(node.codeOrigin, op, node.operands[0..-2] )166 newList << Instruction.new(node.codeOrigin, op, node.operands[0..-2], annotation) 165 167 newList << Instruction.new(node.codeOrigin, branch, [node.operands[-1]]) 166 168 when "bmulio" 167 169 tmp1 = Tmp.new(node.codeOrigin, :gpr) 168 170 tmp2 = Tmp.new(node.codeOrigin, :gpr) 169 newList << Instruction.new(node.codeOrigin, "smulli", [node.operands[0], node.operands[1], node.operands[1], tmp1] )171 newList << Instruction.new(node.codeOrigin, "smulli", [node.operands[0], node.operands[1], node.operands[1], tmp1], annotation) 170 172 newList << Instruction.new(node.codeOrigin, "rshifti", [node.operands[-2], Immediate.new(node.codeOrigin, 31), tmp2]) 171 173 newList << Instruction.new(node.codeOrigin, "bineq", [tmp1, tmp2, node.operands[-1]]) 172 174 when /^bmuli/ 173 175 condition = $~.post_match 174 newList << Instruction.new(node.codeOrigin, "muli", node.operands[0..-2] )176 newList << Instruction.new(node.codeOrigin, "muli", node.operands[0..-2], annotation) 175 177 newList << Instruction.new(node.codeOrigin, "bti" + condition, [node.operands[-2], node.operands[-1]]) 176 178 else … … 211 213 when "lshifti", "rshifti", "urshifti", "lshiftp", "rshiftp", "urshiftp" 212 214 if node.operands.size == 2 213 newList << Instruction.new(node.codeOrigin, node.opcode, [armV7SanitizeShift(node.operands[0], newList), node.operands[1]] )215 newList << Instruction.new(node.codeOrigin, node.opcode, [armV7SanitizeShift(node.operands[0], newList), node.operands[1]], node.annotation) 214 216 else 215 newList << Instruction.new(node.codeOrigin, node.opcode, [node.operands[0], armV7SanitizeShift(node.operands[1], newList), node.operands[2]] )217 newList << Instruction.new(node.codeOrigin, node.opcode, [node.operands[0], armV7SanitizeShift(node.operands[1], newList), node.operands[2]], node.annotation) 216 218 raise "Wrong number of operands for shift at #{node.codeOriginString}" unless node.operands.size == 3 217 219 end … … 322 324 case node.opcode 323 325 when "loadd" 324 newList << Instruction.new(node.codeOrigin, "loadd", [node.operands[0].armV7DoubleAddress(newList), node.operands[1]] )326 newList << Instruction.new(node.codeOrigin, "loadd", [node.operands[0].armV7DoubleAddress(newList), node.operands[1]], node.annotation) 325 327 when "stored" 326 newList << Instruction.new(node.codeOrigin, "stored", [node.operands[0], node.operands[1].armV7DoubleAddress(newList)] )328 newList << Instruction.new(node.codeOrigin, "stored", [node.operands[0], node.operands[1].armV7DoubleAddress(newList)], node.annotation) 327 329 else 328 330 newList << node … … 365 367 end 366 368 } 367 newList << Instruction.new(node.codeOrigin, node.opcode, newOperands )369 newList << Instruction.new(node.codeOrigin, node.opcode, newOperands, node.annotation) 368 370 else 369 371 newList << node … … 432 434 | node | 433 435 if node.is_a? Instruction 436 annotation = node.annotation 434 437 case node.opcode 435 438 when "move" … … 446 449 end 447 450 newList << Instruction.new(node.codeOrigin, newOpcode, 448 [Immediate.new(-node.operands[0].value)] + node.operands[1..-1]) 451 [Immediate.new(-node.operands[0].value)] + node.operands[1..-1], 452 annotation) 449 453 else 450 454 newList << node.armV7LowerMalformedImmediatesRecurse(newList) … … 453 457 if node.operands[0].is_a? Immediate 454 458 tmp = Tmp.new(codeOrigin, :gpr) 455 newList << Instruction.new(node.codeOrigin, "move", [node.operands[0], tmp] )459 newList << Instruction.new(node.codeOrigin, "move", [node.operands[0], tmp], annotation) 456 460 newList << Instruction.new(node.codeOrigin, "muli", [tmp] + node.operands[1..-1]) 457 461 else … … 515 519 if node.is_a? Instruction 516 520 postInstructions = [] 521 annotation = node.annotation 517 522 case node.opcode 518 523 when "addi", "addp", "addis", "andi", "andp", "lshifti", "lshiftp", "muli", "mulp", "negi", … … 521 526 newList << Instruction.new(node.codeOrigin, 522 527 node.opcode, 523 armV7AsRegisters(newList, postInstructions, node.operands, "i")) 528 armV7AsRegisters(newList, postInstructions, node.operands, "i"), 529 annotation) 524 530 when "bbeq", "bbneq", "bba", "bbaeq", "bbb", "bbbeq", "btbo", "btbz", "btbnz", "tbz", "tbnz", 525 531 "tbo", "cbeq", "cbneq", "cba", "cbaeq", "cbb", "cbbeq" 526 532 newList << Instruction.new(node.codeOrigin, 527 533 node.opcode, 528 armV7AsRegisters(newList, postInstructions, node.operands, "b")) 534 armV7AsRegisters(newList, postInstructions, node.operands, "b"), 535 annotation) 529 536 when "bbgt", "bbgteq", "bblt", "bblteq", "btbs", "tbs", "cbgt", "cbgteq", "cblt", "cblteq" 530 537 newList << Instruction.new(node.codeOrigin, 531 538 node.opcode, 532 armV7AsRegisters(newList, postInstructions, node.operands, "bs")) 539 armV7AsRegisters(newList, postInstructions, node.operands, "bs"), 540 annotation) 533 541 when "addd", "divd", "subd", "muld", "sqrtd", /^bd/ 534 542 newList << Instruction.new(node.codeOrigin, 535 543 node.opcode, 536 armV7AsRegisters(newList, postInstructions, node.operands, "d")) 544 armV7AsRegisters(newList, postInstructions, node.operands, "d"), 545 annotation) 537 546 when "jmp", "call" 538 547 newList << Instruction.new(node.codeOrigin, 539 548 node.opcode, 540 [armV7AsRegister(newList, postInstructions, node.operands[0], "p", false)]) 549 [armV7AsRegister(newList, postInstructions, node.operands[0], "p", false)], 550 annotation) 541 551 else 542 552 newList << node … … 566 576 | node | 567 577 if node.is_a? Instruction 578 annotation = node.annotation 568 579 case node.opcode 569 580 when "cieq", "cineq", "cia", "ciaeq", "cib", "cibeq", "cigt", "cigteq", "cilt", "cilteq", … … 574 585 if node.operands[0] == node.operands[1] 575 586 tmp = Tmp.new(node.codeOrigin, :gpr) 576 newList << Instruction.new(node.codeOrigin, "move", [node.operands[0], tmp] )587 newList << Instruction.new(node.codeOrigin, "move", [node.operands[0], tmp], annotation) 577 588 newList << Instruction.new(node.codeOrigin, node.opcode, [tmp, node.operands[1]]) 578 589 else … … 583 594 if node.operands[0] == node.operands[2] 584 595 tmp = Tmp.new(node.codeOrigin, :gpr) 585 newList << Instruction.new(node.codeOrigin, "move", [node.operands[0], tmp] )596 newList << Instruction.new(node.codeOrigin, "move", [node.operands[0], tmp], annotation) 586 597 newList << Instruction.new(node.codeOrigin, node.opcode, [tmp, node.operands[1], node.operands[2]]) 587 598 elsif node.operands[1] == node.operands[2] 588 599 tmp = Tmp.new(node.codeOrigin, :gpr) 589 newList << Instruction.new(node.codeOrigin, "move", [node.operands[1], tmp] )600 newList << Instruction.new(node.codeOrigin, "move", [node.operands[1], tmp], annotation) 590 601 newList << Instruction.new(node.codeOrigin, node.opcode, [node.operands[0], tmp, node.operands[2]]) 591 602 else … … 733 744 class Instruction 734 745 def lowerARMv7 735 $asm.comment codeOriginString 746 $asm.codeOrigin codeOriginString 747 $asm.annotation annotation 748 736 749 case opcode 737 750 when "addi", "addp", "addis" -
trunk/Source/JavaScriptCore/offlineasm/asm.rb
r119857 r122650 26 26 $: << File.dirname(__FILE__) 27 27 28 require "config" 28 29 require "backends" 29 30 require "digest/sha1" … … 40 41 @commentState = :none 41 42 @comment = nil 43 @internalComment = nil 44 @annotation = nil 45 @codeOrigin = nil 46 @numLocalLabels = 0 47 @numGlobalLabels = 0 42 48 end 43 49 44 50 def enterAsm 45 @outp.puts " asm ("51 @outp.puts "OFFLINE_ASM_BEGIN" 46 52 @state = :asm 47 53 end … … 49 55 def leaveAsm 50 56 putsLastComment 51 @outp.puts " );"57 @outp.puts "OFFLINE_ASM_END" 52 58 @state = :cpp 53 59 end … … 59 65 end 60 66 67 # Concatenates all the various components of the comment to dump. 61 68 def lastComment 62 if @comment 63 result = "// #{@comment}" 64 else 65 result = "" 66 end 69 result = "" 70 result = " #{@comment} ." if @comment 71 result += " #{@annotation} ." if @annotation and $enableTrailingInstrAnnotations 72 result += " #{@internalComment} ." if @internalComment 73 result += " #{@codeOrigin} ." if @codeOrigin and $enableCodeOriginComments 74 if result != "" 75 result = " //" + result 76 end 77 78 # Reset all the components that we've just sent to be dumped. 67 79 @commentState = :none 68 80 @comment = nil 81 @internalComment = nil 82 @annotation = nil 83 @codeOrigin = nil 69 84 result 70 85 end 71 86 87 # Dumps the current instruction annotation in interlaced mode if appropriate. 88 def putInterlacedAnnotation() 89 raise unless @state == :asm 90 if $enableInterlacedInstrAnnotations 91 @outp.puts(" // #{@annotation}") if @annotation 92 @annotation = nil 93 end 94 end 95 72 96 def putsLastComment 73 97 comment = lastComment … … 79 103 def puts(*line) 80 104 raise unless @state == :asm 81 @outp.puts("\"\\t" + line.join('') + "\\n\" #{lastComment}") 105 putInterlacedAnnotation 106 @outp.puts(" \"\\t" + line.join('') + "\\n\"#{lastComment}") 82 107 end 83 108 … … 89 114 def putsLabel(labelName) 90 115 raise unless @state == :asm 91 @outp.puts("OFFLINE_ASM_GLOBAL_LABEL(#{labelName}) #{lastComment}") 116 @numGlobalLabels += 1 117 @outp.puts("\n") 118 @internalComment = $enableLabelCountComments ? "Global Label #{@numGlobalLabels}" : nil 119 @outp.puts("OFFLINE_ASM_GLOBAL_LABEL(#{labelName})#{lastComment}") 92 120 end 93 121 94 122 def putsLocalLabel(labelName) 95 123 raise unless @state == :asm 96 @outp.puts("LOCAL_LABEL_STRING(#{labelName}) \":\\n\" #{lastComment}") 124 @numLocalLabels += 1 125 @outp.puts("\n") 126 @internalComment = $enableLabelCountComments ? "Local Label #{@numLocalLabels}" : nil 127 @outp.puts("OFFLINE_ASM_LOCAL_LABEL(#{labelName})#{lastComment}") 97 128 end 98 129 … … 105 136 end 106 137 107 def co mment(text)138 def codeOrigin(text) 108 139 case @commentState 109 140 when :none 110 @co mment= text141 @codeOrigin = text 111 142 @commentState = :one 112 143 when :one 113 @outp.puts "// #{@comment}" 114 @outp.puts "// #{text}" 115 @comment = nil 144 if $enableCodeOriginComments 145 @outp.puts " // #{@codeOrigin}" 146 @outp.puts " // #{text}" 147 end 148 @codeOrigin = nil 116 149 @commentState = :many 117 150 when :many 118 @outp.puts "// #{text}" 151 @outp.puts "// #{text}" if $enableCodeOriginComments 119 152 else 120 153 raise 121 154 end 155 end 156 157 def comment(text) 158 @comment = text 159 end 160 def annotation(text) 161 @annotation = text 122 162 end 123 163 end -
trunk/Source/JavaScriptCore/offlineasm/ast.rb
r110383 r122650 21 21 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 22 # THE POSSIBILITY OF SUCH DAMAGE. 23 24 require "config" 23 25 24 26 # … … 785 787 786 788 class Instruction < Node 787 attr_reader :opcode, :operands 788 789 def initialize(codeOrigin, opcode, operands )789 attr_reader :opcode, :operands, :annotation 790 791 def initialize(codeOrigin, opcode, operands, annotation=nil) 790 792 super(codeOrigin) 791 793 @opcode = opcode 792 794 @operands = operands 795 @annotation = annotation 793 796 end 794 797 … … 798 801 799 802 def mapChildren(&proc) 800 Instruction.new(codeOrigin, @opcode, @operands.map(&proc) )803 Instruction.new(codeOrigin, @opcode, @operands.map(&proc), @annotation) 801 804 end 802 805 -
trunk/Source/JavaScriptCore/offlineasm/backends.rb
r110383 r122650 22 22 # THE POSSIBILITY OF SUCH DAMAGE. 23 23 24 require "config" 24 25 require "armv7" 25 26 require "ast" -
trunk/Source/JavaScriptCore/offlineasm/generate_offset_extractor.rb
r108913 r122650 26 26 $: << File.dirname(__FILE__) 27 27 28 require "config" 28 29 require "backends" 29 30 require "digest/sha1" -
trunk/Source/JavaScriptCore/offlineasm/instructions.rb
r113930 r122650 21 21 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 22 # THE POSSIBILITY OF SUCH DAMAGE. 23 24 require "config" 23 25 24 26 # Interesting invariant, which we take advantage of: branching instructions -
trunk/Source/JavaScriptCore/offlineasm/offsets.rb
r120860 r122650 22 22 # THE POSSIBILITY OF SUCH DAMAGE. 23 23 24 require "config" 24 25 require "ast" 25 26 -
trunk/Source/JavaScriptCore/offlineasm/opt.rb
r108444 r122650 22 22 # THE POSSIBILITY OF SUCH DAMAGE. 23 23 24 require "config" 24 25 require "ast" 25 26 -
trunk/Source/JavaScriptCore/offlineasm/parser.rb
r110383 r122650 22 22 # THE POSSIBILITY OF SUCH DAMAGE. 23 23 24 require "config" 24 25 require "ast" 25 26 require "instructions" … … 82 83 result = [] 83 84 lineNumber = 1 85 annotation = nil 84 86 while not str.empty? 85 87 case str 86 88 when /\A\#([^\n]*)/ 87 89 # comment, ignore 90 when /\A\/\/([^\n]*)/ 91 # annotation 92 annotation = $1 88 93 when /\A\n/ 94 # We've found a '\n'. Emit the last comment recorded if appropriate: 95 if $enableInstrAnnotations and annotation 96 result << Token.new(CodeOrigin.new(fileName, lineNumber), "@" + annotation) 97 annotation = nil 98 end 89 99 result << Token.new(CodeOrigin.new(fileName, lineNumber), $&) 90 100 lineNumber += 1 … … 137 147 end 138 148 149 def isAnnotation(token) 150 token =~ /\A\@([^\n]*)/ 151 end 152 139 153 def isLabel(token) 140 154 token =~ /\A_([a-zA-Z0-9_]*)\Z/ … … 536 550 list << Instruction.new(codeOrigin, name, []) 537 551 break 552 elsif isAnnotation @tokens[@idx] 553 annotation = @tokens[@idx].string 554 list << Instruction.new(codeOrigin, name, [], annotation) 555 @idx += 2 # Consume the newline as well. 538 556 elsif @tokens[@idx] == "\n" 539 557 # Zero operand instruction. … … 544 562 operands = [] 545 563 endOfSequence = false 564 annotation = nil 546 565 loop { 547 566 operands << parseOperand("while inside of instruction #{name}") … … 553 572 # Has another operand. 554 573 @idx += 1 574 elsif isAnnotation @tokens[@idx] 575 annotation = @tokens[@idx].string 576 @idx += 2 # Consume the newline as well. 577 break 555 578 elsif @tokens[@idx] == "\n" 556 579 # The end of the instruction. … … 561 584 end 562 585 } 563 list << Instruction.new(codeOrigin, name, operands )586 list << Instruction.new(codeOrigin, name, operands, annotation) 564 587 if endOfSequence 565 588 break -
trunk/Source/JavaScriptCore/offlineasm/registers.rb
r110383 r122650 21 21 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 22 # THE POSSIBILITY OF SUCH DAMAGE. 23 24 require "config" 23 25 24 26 GPRS = -
trunk/Source/JavaScriptCore/offlineasm/self_hash.rb
r108913 r122650 22 22 # THE POSSIBILITY OF SUCH DAMAGE. 23 23 24 require "config" 24 25 require "digest/sha1" 25 26 require "pathname" -
trunk/Source/JavaScriptCore/offlineasm/settings.rb
r108909 r122650 22 22 # THE POSSIBILITY OF SUCH DAMAGE. 23 23 24 require "config" 24 25 require "ast" 25 26 require "backends" -
trunk/Source/JavaScriptCore/offlineasm/transform.rb
r110383 r122650 22 22 # THE POSSIBILITY OF SUCH DAMAGE. 23 23 24 require "config" 24 25 require "ast" 25 26 -
trunk/Source/JavaScriptCore/offlineasm/x86.rb
r121925 r122650 21 21 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 22 # THE POSSIBILITY OF SUCH DAMAGE. 23 24 require "config" 23 25 24 26 def isX64 … … 354 356 end 355 357 } 356 newNode = Instruction.new(node.codeOrigin, node.opcode, newOperands )358 newNode = Instruction.new(node.codeOrigin, node.opcode, newOperands, node.annotation) 357 359 end 358 360 else … … 623 625 624 626 def lowerX86Common 625 $asm.comment codeOriginString 627 $asm.codeOrigin codeOriginString 628 $asm.annotation annotation 629 626 630 case opcode 627 631 when "addi"
Note: See TracChangeset
for help on using the changeset viewer.