getLocalVariable returns a debug info entry for a local variable, which may either be a parameter or a regular variable. It will create a new metadata entry if there isn't one for the variable yet.
(variable *types.Var)
| 742 | // either be a parameter or a regular variable. It will create a new metadata |
| 743 | // entry if there isn't one for the variable yet. |
| 744 | func (b *builder) getLocalVariable(variable *types.Var) llvm.Metadata { |
| 745 | if dilocal, ok := b.dilocals[variable]; ok { |
| 746 | // DILocalVariable was already created, return it directly. |
| 747 | return dilocal |
| 748 | } |
| 749 | |
| 750 | pos := b.program.Fset.Position(variable.Pos()) |
| 751 | |
| 752 | // Check whether this is a function parameter. |
| 753 | for i, param := range b.fn.Params { |
| 754 | if param.Object().(*types.Var) == variable { |
| 755 | // Yes it is, create it as a function parameter. |
| 756 | dilocal := b.dibuilder.CreateParameterVariable(b.difunc, llvm.DIParameterVariable{ |
| 757 | Name: param.Name(), |
| 758 | File: b.getDIFile(pos.Filename), |
| 759 | Line: pos.Line, |
| 760 | Type: b.getDIType(param.Type()), |
| 761 | AlwaysPreserve: true, |
| 762 | ArgNo: i + 1, |
| 763 | }) |
| 764 | b.dilocals[variable] = dilocal |
| 765 | return dilocal |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | // No, it's not a parameter. Create a regular (auto) variable. |
| 770 | dilocal := b.dibuilder.CreateAutoVariable(b.difunc, llvm.DIAutoVariable{ |
| 771 | Name: variable.Name(), |
| 772 | File: b.getDIFile(pos.Filename), |
| 773 | Line: pos.Line, |
| 774 | Type: b.getDIType(variable.Type()), |
| 775 | AlwaysPreserve: true, |
| 776 | }) |
| 777 | b.dilocals[variable] = dilocal |
| 778 | return dilocal |
| 779 | } |
| 780 | |
| 781 | // attachDebugInfo adds debug info to a function declaration. It returns the |
| 782 | // DISubprogram metadata node. |