...
Run Format

Source file src/runtime/wincallback.go

Documentation: runtime

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build ignore
     6  
     7  // Generate Windows callback assembly file.
     8  
     9  package main
    10  
    11  import (
    12  	"bytes"
    13  	"fmt"
    14  	"io/ioutil"
    15  	"os"
    16  )
    17  
    18  const maxCallback = 2000
    19  
    20  func genasm() {
    21  	var buf bytes.Buffer
    22  
    23  	buf.WriteString(`// generated by wincallback.go; run go generate
    24  
    25  // runtime·callbackasm is called by external code to
    26  // execute Go implemented callback function. It is not
    27  // called from the start, instead runtime·compilecallback
    28  // always returns address into runtime·callbackasm offset
    29  // appropriately so different callbacks start with different
    30  // CALL instruction in runtime·callbackasm. This determines
    31  // which Go callback function is executed later on.
    32  TEXT runtime·callbackasm(SB),7,$0
    33  `)
    34  	for i := 0; i < maxCallback; i++ {
    35  		buf.WriteString("\tCALL\truntime·callbackasm1(SB)\n")
    36  	}
    37  
    38  	err := ioutil.WriteFile("zcallback_windows.s", buf.Bytes(), 0666)
    39  	if err != nil {
    40  		fmt.Fprintf(os.Stderr, "wincallback: %s\n", err)
    41  		os.Exit(2)
    42  	}
    43  }
    44  
    45  func gengo() {
    46  	var buf bytes.Buffer
    47  
    48  	buf.WriteString(fmt.Sprintf(`// generated by wincallback.go; run go generate
    49  
    50  package runtime
    51  
    52  const cb_max = %d // maximum number of windows callbacks allowed
    53  `, maxCallback))
    54  	err := ioutil.WriteFile("zcallback_windows.go", buf.Bytes(), 0666)
    55  	if err != nil {
    56  		fmt.Fprintf(os.Stderr, "wincallback: %s\n", err)
    57  		os.Exit(2)
    58  	}
    59  }
    60  
    61  func main() {
    62  	genasm()
    63  	gengo()
    64  }
    65  

View as plain text