]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - offlineasm/asm.rb
JavaScriptCore-7600.1.4.13.1.tar.gz
[apple/javascriptcore.git] / offlineasm / asm.rb
index bf2426399145481150bc6073df36ba6fba81f6a0..88c7d7abb6d97a594634da5352f9d0d236f85561 100644 (file)
@@ -47,16 +47,18 @@ class Assembler
         @numGlobalLabels = 0
 
         @newlineSpacerState = :none
+        @lastlabel = ""
     end
-    
+
     def enterAsm
-        @outp.puts "OFFLINE_ASM_BEGIN"
+        @outp.puts "OFFLINE_ASM_BEGIN" if !$emitWinAsm
         @state = :asm
     end
     
     def leaveAsm
+        putsProcEndIfNeeded if $emitWinAsm
         putsLastComment
-        @outp.puts "OFFLINE_ASM_END"
+        @outp.puts "OFFLINE_ASM_END" if !$emitWinAsm
         @state = :cpp
     end
     
@@ -84,7 +86,7 @@ class Assembler
             result += "#{@codeOrigin}"
         end
         if result != ""
-            result = "// " + result
+            result = $commentPrefix + " " + result
         end
 
         # Reset all the components that we've just sent to be dumped.
@@ -137,7 +139,11 @@ class Assembler
     
     def puts(*line)
         raise unless @state == :asm
-        @outp.puts(formatDump("    \"\\t" + line.join('') + "\\n\"", lastComment))
+        if !$emitWinAsm
+            @outp.puts(formatDump("    \"\\t" + line.join('') + "\\n\"", lastComment))
+        else
+            @outp.puts(formatDump("    " + line.join(''), lastComment))
+        end
     end
     
     def print(line)
@@ -152,15 +158,45 @@ class Assembler
         end
     end
 
-    def putsLabel(labelName)
+    def putsProc(label, comment)
+        raise unless $emitWinAsm
+        @outp.puts(formatDump("#{label} PROC PUBLIC", comment))
+        @lastlabel = label
+    end
+
+    def putsProcEndIfNeeded
+        raise unless $emitWinAsm
+        if @lastlabel != ""
+            @outp.puts("#{@lastlabel} ENDP")
+        end
+        @lastlabel = ""
+    end
+
+    def putsLabel(labelName, isGlobal)
         raise unless @state == :asm
         @numGlobalLabels += 1
+        putsProcEndIfNeeded if $emitWinAsm and isGlobal
         putsNewlineSpacerIfAppropriate(:global)
         @internalComment = $enableLabelCountComments ? "Global Label #{@numGlobalLabels}" : nil
-        if /\Allint_op_/.match(labelName)
-            @outp.puts(formatDump("OFFLINE_ASM_OPCODE_LABEL(op_#{$~.post_match})", lastComment))
+        if isGlobal
+            if !$emitWinAsm
+                @outp.puts(formatDump("OFFLINE_ASM_GLOBAL_LABEL(#{labelName})", lastComment))
+            else
+                putsProc(labelName, lastComment)
+            end            
+        elsif /\Allint_op_/.match(labelName)
+            if !$emitWinAsm
+                @outp.puts(formatDump("OFFLINE_ASM_OPCODE_LABEL(op_#{$~.post_match})", lastComment))
+            else
+                label = "llint_" + "op_#{$~.post_match}"
+                @outp.puts(formatDump("  _#{label}:", lastComment))
+            end            
         else
-            @outp.puts(formatDump("OFFLINE_ASM_GLUE_LABEL(#{labelName})", lastComment))
+            if !$emitWinAsm
+                @outp.puts(formatDump("OFFLINE_ASM_GLUE_LABEL(#{labelName})", lastComment))
+            else
+                @outp.puts(formatDump("  _#{labelName}:", lastComment))
+            end
         end
         @newlineSpacerState = :none # After a global label, we can use another spacer.
     end
@@ -170,15 +206,35 @@ class Assembler
         @numLocalLabels += 1
         @outp.puts("\n")
         @internalComment = $enableLabelCountComments ? "Local Label #{@numLocalLabels}" : nil
-        @outp.puts(formatDump("  OFFLINE_ASM_LOCAL_LABEL(#{labelName})", lastComment))
+        if !$emitWinAsm
+            @outp.puts(formatDump("  OFFLINE_ASM_LOCAL_LABEL(#{labelName})", lastComment))
+        else
+            @outp.puts(formatDump("  #{labelName}:", lastComment))
+        end
     end
-    
+
+    def self.externLabelReference(labelName)
+        if !$emitWinAsm
+            "\" LOCAL_REFERENCE(#{labelName}) \""
+        else
+            "#{labelName}"
+        end
+    end
+
     def self.labelReference(labelName)
-        "\" LOCAL_REFERENCE(#{labelName}) \""
+        if !$emitWinAsm
+            "\" LOCAL_LABEL_STRING(#{labelName}) \""
+        else
+            "_#{labelName}"
+        end
     end
     
     def self.localLabelReference(labelName)
-        "\" LOCAL_LABEL_STRING(#{labelName}) \""
+        if !$emitWinAsm
+            "\" LOCAL_LABEL_STRING(#{labelName}) \""
+        else
+            "#{labelName}"
+        end
     end
     
     def self.cLabelReference(labelName)
@@ -200,13 +256,13 @@ class Assembler
             @commentState = :one
         when :one
             if $enableCodeOriginComments
-                @outp.puts "    // #{@codeOrigin}"
-                @outp.puts "    // #{text}"
+                @outp.puts "    " + $commentPrefix + " #{@codeOrigin}"
+                @outp.puts "    " + $commentPrefix + " #{text}"
             end
             @codeOrigin = nil
             @commentState = :many
         when :many
-            @outp.puts "// #{text}" if $enableCodeOriginComments
+            @outp.puts $commentPrefix + " #{text}" if $enableCodeOriginComments
         else
             raise
         end
@@ -220,6 +276,8 @@ class Assembler
     end
 end
 
+IncludeFile.processIncludeOptions()
+
 asmFile = ARGV.shift
 offsetsFile = ARGV.shift
 outputFlnm = ARGV.shift
@@ -233,8 +291,11 @@ rescue MissingMagicValuesException
     exit 0
 end
 
+$emitWinAsm = isMSVC ? outputFlnm.index(".asm") != nil : false
+$commentPrefix = $emitWinAsm ? ";" : "//"
+
 inputHash =
-    "// offlineasm input hash: " + parseHash(asmFile) +
+    $commentPrefix + " offlineasm input hash: " + parseHash(asmFile) +
     " " + Digest::SHA1.hexdigest(configurationList.map{|v| (v[0] + [v[1]]).join(' ')}.join(' ')) +
     " " + selfHash
 
@@ -253,11 +314,11 @@ File.open(outputFlnm, "w") {
     | outp |
     $output = outp
     $output.puts inputHash
-    
+
     $asm = Assembler.new($output)
     
     ast = parse(asmFile)
-    
+
     configurationList.each {
         | configuration |
         offsetsList = configuration[0]