MCPcopy Create free account
hub / github.com/despiteallobjections/amigo / structType

Method structType

cgotool/out.go:345–386  ·  view source on GitHub ↗

Construct a gcc struct matching the gc argument frame. Assumes that in gcc, char is 1 byte, short 2 bytes, int 4 bytes, long long 8 bytes. These assumptions are checked by the gccProlog. Also assumes that gc convention is to word-align the input and output parameters.

(n *Name)

Source from the content-addressed store, hash-verified

343// Also assumes that gc convention is to word-align the
344// input and output parameters.
345func (p *Package) structType(n *Name) (string, int64) {
346 var buf bytes.Buffer
347 fmt.Fprint(&buf, "struct {\n")
348 off := int64(0)
349 for i, t := range n.FuncType.Params {
350 if off%t.Align != 0 {
351 pad := t.Align - off%t.Align
352 fmt.Fprintf(&buf, "\t\tchar __pad%d[%d];\n", off, pad)
353 off += pad
354 }
355 c := t.Typedef
356 if c == "" {
357 c = t.C.String()
358 }
359 fmt.Fprintf(&buf, "\t\t%s p%d;\n", c, i)
360 off += t.Size
361 }
362 if off%p.PtrSize != 0 {
363 pad := p.PtrSize - off%p.PtrSize
364 fmt.Fprintf(&buf, "\t\tchar __pad%d[%d];\n", off, pad)
365 off += pad
366 }
367 if t := n.FuncType.Result; t != nil {
368 if off%t.Align != 0 {
369 pad := t.Align - off%t.Align
370 fmt.Fprintf(&buf, "\t\tchar __pad%d[%d];\n", off, pad)
371 off += pad
372 }
373 fmt.Fprintf(&buf, "\t\t%s r;\n", t.C)
374 off += t.Size
375 }
376 if off%p.PtrSize != 0 {
377 pad := p.PtrSize - off%p.PtrSize
378 fmt.Fprintf(&buf, "\t\tchar __pad%d[%d];\n", off, pad)
379 off += pad
380 }
381 if off == 0 {
382 fmt.Fprintf(&buf, "\t\tchar unused;\n") // avoid empty struct
383 }
384 fmt.Fprintf(&buf, "\t}")
385 return buf.String(), off
386}
387
388func (p *Package) writeDefsFunc(fgo2 io.Writer, n *Name, callsMalloc *bool) {
389 name := n.Go

Callers 1

writeOutputFuncMethod · 0.95

Calls 2

StringMethod · 0.95
StringMethod · 0.65

Tested by

no test coverage detected