aboutsummaryrefslogtreecommitdiffhomepage
path: root/compiler/calls.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-05-13 20:39:12 +0200
committerRon Evans <[email protected]>2019-05-14 11:18:38 +0200
commit371c468e8efcc6c415c4e955e69fc6072698f578 (patch)
tree3604981f91ec4949c45114cf6f9157f1aa40de6d /compiler/calls.go
parent0a4021968022fb6e55e06b01665df590760356e1 (diff)
downloadtinygo-371c468e8efcc6c415c4e955e69fc6072698f578.tar.gz
tinygo-371c468e8efcc6c415c4e955e69fc6072698f578.zip
compiler: add debug info for function arguments
This commit adds debug info to function arguments, so that in many cases you can see them when compiling with less optimizations enabled. Unfortunately, due to the way Go SSA works, it is hard to preserve them in many cases. Local variables are not yet saved. Also, change the language type to C, to make sure lldb shows function arguments. The previous language was Modula 3, apparently due to a off-by-one error somewhere.
Diffstat (limited to 'compiler/calls.go')
-rw-r--r--compiler/calls.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/compiler/calls.go b/compiler/calls.go
index b5296f91a..f0a497352 100644
--- a/compiler/calls.go
+++ b/compiler/calls.go
@@ -55,6 +55,25 @@ func (c *Compiler) expandFormalParamType(t llvm.Type) []llvm.Type {
}
}
+// Expand an argument type to a list of offsets from the start of the object.
+// Used together with expandFormalParam to get the offset of each value from the
+// start of the non-expanded value.
+func (c *Compiler) expandFormalParamOffsets(t llvm.Type) []uint64 {
+ switch t.TypeKind() {
+ case llvm.StructTypeKind:
+ fields := c.flattenAggregateTypeOffsets(t)
+ if len(fields) <= MaxFieldsPerParam {
+ return fields
+ } else {
+ // failed to lower
+ return []uint64{0}
+ }
+ default:
+ // TODO: split small arrays
+ return []uint64{0}
+ }
+}
+
// Equivalent of expandFormalParamType for parameter values.
func (c *Compiler) expandFormalParam(v llvm.Value) []llvm.Value {
switch v.Type().TypeKind() {
@@ -92,6 +111,27 @@ func (c *Compiler) flattenAggregateType(t llvm.Type) []llvm.Type {
}
}
+// Return the offsets from the start of the object if this object type were
+// flattened like in flattenAggregate. Used together with flattenAggregate to
+// know the start indices of each value in the non-flattened object.
+func (c *Compiler) flattenAggregateTypeOffsets(t llvm.Type) []uint64 {
+ switch t.TypeKind() {
+ case llvm.StructTypeKind:
+ fields := make([]uint64, 0, t.StructElementTypesCount())
+ for fieldIndex, field := range t.StructElementTypes() {
+ suboffsets := c.flattenAggregateTypeOffsets(field)
+ offset := c.targetData.ElementOffset(t, fieldIndex)
+ for i := range suboffsets {
+ suboffsets[i] += offset
+ }
+ fields = append(fields, suboffsets...)
+ }
+ return fields
+ default:
+ return []uint64{0}
+ }
+}
+
// Break down a struct into its elementary types for argument passing. The value
// equivalent of flattenAggregateType
func (c *Compiler) flattenAggregate(v llvm.Value) []llvm.Value {