Source file src/cmd/compile/internal/gc/export.go

     1  // Copyright 2009 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  package gc
     6  
     7  import (
     8  	"fmt"
     9  	"go/constant"
    10  
    11  	"cmd/compile/internal/base"
    12  	"cmd/compile/internal/ir"
    13  	"cmd/compile/internal/typecheck"
    14  	"cmd/compile/internal/types"
    15  	"cmd/internal/bio"
    16  )
    17  
    18  func dumpasmhdr() {
    19  	b, err := bio.Create(base.Flag.AsmHdr)
    20  	if err != nil {
    21  		base.Fatalf("%v", err)
    22  	}
    23  	fmt.Fprintf(b, "// generated by compile -asmhdr from package %s\n\n", types.LocalPkg.Name)
    24  	for _, n := range typecheck.Target.Asms {
    25  		if n.Sym().IsBlank() {
    26  			continue
    27  		}
    28  		switch n.Op() {
    29  		case ir.OLITERAL:
    30  			t := n.Val().Kind()
    31  			if t == constant.Float || t == constant.Complex {
    32  				break
    33  			}
    34  			fmt.Fprintf(b, "#define const_%s %v\n", n.Sym().Name, n.Val().ExactString())
    35  
    36  		case ir.OTYPE:
    37  			t := n.Type()
    38  			if !t.IsStruct() || t.StructType().Map != nil || t.IsFuncArgStruct() {
    39  				break
    40  			}
    41  			fmt.Fprintf(b, "#define %s__size %d\n", n.Sym().Name, int(t.Size()))
    42  			for _, f := range t.Fields().Slice() {
    43  				if !f.Sym.IsBlank() {
    44  					fmt.Fprintf(b, "#define %s_%s %d\n", n.Sym().Name, f.Sym.Name, int(f.Offset))
    45  				}
    46  			}
    47  		}
    48  	}
    49  
    50  	b.Close()
    51  }
    52  

View as plain text