@@ -18,8 +18,8 @@ import (
1818// func ReadRegister(name string) uintptr
1919//
2020// The register name must be a constant, for example "sp".
21- func (c * Compiler ) emitReadRegister (name string , args []ssa.Value ) (llvm.Value , error ) {
22- fnType := llvm .FunctionType (c .uintptrType , []llvm.Type {}, false )
21+ func (b * builder ) createReadRegister (name string , args []ssa.Value ) (llvm.Value , error ) {
22+ fnType := llvm .FunctionType (b .uintptrType , []llvm.Type {}, false )
2323 regname := constant .StringVal (args [0 ].(* ssa.Const ).Value )
2424 var asm string
2525 switch name {
@@ -31,7 +31,7 @@ func (c *Compiler) emitReadRegister(name string, args []ssa.Value) (llvm.Value,
3131 panic ("unknown architecture" )
3232 }
3333 target := llvm .InlineAsm (fnType , asm , "=r" , false , false , 0 )
34- return c . builder .CreateCall (target , nil , "" ), nil
34+ return b .CreateCall (target , nil , "" ), nil
3535}
3636
3737// This is a compiler builtin, which emits a piece of inline assembly with no
@@ -41,12 +41,12 @@ func (c *Compiler) emitReadRegister(name string, args []ssa.Value) (llvm.Value,
4141// func Asm(asm string)
4242//
4343// The provided assembly must be a constant.
44- func (c * Compiler ) emitAsm (args []ssa.Value ) (llvm.Value , error ) {
44+ func (b * builder ) createInlineAsm (args []ssa.Value ) (llvm.Value , error ) {
4545 // Magic function: insert inline assembly instead of calling it.
46- fnType := llvm .FunctionType (c .ctx .VoidType (), []llvm.Type {}, false )
46+ fnType := llvm .FunctionType (b .ctx .VoidType (), []llvm.Type {}, false )
4747 asm := constant .StringVal (args [0 ].(* ssa.Const ).Value )
4848 target := llvm .InlineAsm (fnType , asm , "" , true , false , 0 )
49- return c . builder .CreateCall (target , nil , "" ), nil
49+ return b .CreateCall (target , nil , "" ), nil
5050}
5151
5252// This is a compiler builtin, which allows assembly to be called in a flexible
@@ -63,7 +63,7 @@ func (c *Compiler) emitAsm(args []ssa.Value) (llvm.Value, error) {
6363// "value": 1
6464// "result": &dest,
6565// })
66- func (c * Compiler ) emitAsmFull ( frame * Frame , instr * ssa.CallCommon ) (llvm.Value , error ) {
66+ func (b * builder ) createInlineAsmFull ( instr * ssa.CallCommon ) (llvm.Value , error ) {
6767 asmString := constant .StringVal (instr .Args [0 ].(* ssa.Const ).Value )
6868 registers := map [string ]llvm.Value {}
6969 registerMap := instr .Args [1 ].(* ssa.MakeMap )
@@ -73,17 +73,17 @@ func (c *Compiler) emitAsmFull(frame *Frame, instr *ssa.CallCommon) (llvm.Value,
7373 // ignore
7474 case * ssa.MapUpdate :
7575 if r .Block () != registerMap .Block () {
76- return llvm.Value {}, c .makeError (instr .Pos (), "register value map must be created in the same basic block" )
76+ return llvm.Value {}, b .makeError (instr .Pos (), "register value map must be created in the same basic block" )
7777 }
7878 key := constant .StringVal (r .Key .(* ssa.Const ).Value )
7979 //println("value:", r.Value.(*ssa.MakeInterface).X.String())
80- registers [key ] = frame .getValue (r .Value .(* ssa.MakeInterface ).X )
80+ registers [key ] = b .getValue (r .Value .(* ssa.MakeInterface ).X )
8181 case * ssa.Call :
8282 if r .Common () == instr {
8383 break
8484 }
8585 default :
86- return llvm.Value {}, c .makeError (instr .Pos (), "don't know how to handle argument to inline assembly: " + r .String ())
86+ return llvm.Value {}, b .makeError (instr .Pos (), "don't know how to handle argument to inline assembly: " + r .String ())
8787 }
8888 }
8989 // TODO: handle dollar signs in asm string
@@ -98,7 +98,7 @@ func (c *Compiler) emitAsmFull(frame *Frame, instr *ssa.CallCommon) (llvm.Value,
9898 name := s [1 : len (s )- 1 ]
9999 if _ , ok := registers [name ]; ! ok {
100100 if err == nil {
101- err = c .makeError (instr .Pos (), "unknown register name: " + name )
101+ err = b .makeError (instr .Pos (), "unknown register name: " + name )
102102 }
103103 return s
104104 }
@@ -112,7 +112,7 @@ func (c *Compiler) emitAsmFull(frame *Frame, instr *ssa.CallCommon) (llvm.Value,
112112 case llvm .PointerTypeKind :
113113 constraints = append (constraints , "*m" )
114114 default :
115- err = c .makeError (instr .Pos (), "unknown type in inline assembly for value: " + name )
115+ err = b .makeError (instr .Pos (), "unknown type in inline assembly for value: " + name )
116116 return s
117117 }
118118 }
@@ -121,9 +121,9 @@ func (c *Compiler) emitAsmFull(frame *Frame, instr *ssa.CallCommon) (llvm.Value,
121121 if err != nil {
122122 return llvm.Value {}, err
123123 }
124- fnType := llvm .FunctionType (c .ctx .VoidType (), argTypes , false )
124+ fnType := llvm .FunctionType (b .ctx .VoidType (), argTypes , false )
125125 target := llvm .InlineAsm (fnType , asmString , strings .Join (constraints , "," ), true , false , 0 )
126- return c . builder .CreateCall (target , args , "" ), nil
126+ return b .CreateCall (target , args , "" ), nil
127127}
128128
129129// This is a compiler builtin which emits an inline SVCall instruction. It can
@@ -137,7 +137,7 @@ func (c *Compiler) emitAsmFull(frame *Frame, instr *ssa.CallCommon) (llvm.Value,
137137//
138138// The num parameter must be a constant. All other parameters may be any scalar
139139// value supported by LLVM inline assembly.
140- func (c * Compiler ) emitSVCall (frame * Frame , args []ssa.Value ) (llvm.Value , error ) {
140+ func (b * builder ) emitSVCall (args []ssa.Value ) (llvm.Value , error ) {
141141 num , _ := constant .Uint64Val (args [0 ].(* ssa.Const ).Value )
142142 llvmArgs := []llvm.Value {}
143143 argTypes := []llvm.Type {}
@@ -150,17 +150,17 @@ func (c *Compiler) emitSVCall(frame *Frame, args []ssa.Value) (llvm.Value, error
150150 } else {
151151 constraints += ",{r" + strconv .Itoa (i ) + "}"
152152 }
153- llvmValue := frame .getValue (arg )
153+ llvmValue := b .getValue (arg )
154154 llvmArgs = append (llvmArgs , llvmValue )
155155 argTypes = append (argTypes , llvmValue .Type ())
156156 }
157157 // Implement the ARM calling convention by marking r1-r3 as
158158 // clobbered. r0 is used as an output register so doesn't have to be
159159 // marked as clobbered.
160160 constraints += ",~{r1},~{r2},~{r3}"
161- fnType := llvm .FunctionType (c .uintptrType , argTypes , false )
161+ fnType := llvm .FunctionType (b .uintptrType , argTypes , false )
162162 target := llvm .InlineAsm (fnType , asm , constraints , true , false , 0 )
163- return c . builder .CreateCall (target , llvmArgs , "" ), nil
163+ return b .CreateCall (target , llvmArgs , "" ), nil
164164}
165165
166166// This is a compiler builtin which emits CSR instructions. It can be one of:
@@ -172,38 +172,38 @@ func (c *Compiler) emitSVCall(frame *Frame, args []ssa.Value) (llvm.Value, error
172172//
173173// The csr parameter (method receiver) must be a constant. Other parameter can
174174// be any value.
175- func (c * Compiler ) emitCSROperation (frame * Frame , call * ssa.CallCommon ) (llvm.Value , error ) {
175+ func (b * builder ) emitCSROperation (call * ssa.CallCommon ) (llvm.Value , error ) {
176176 csrConst , ok := call .Args [0 ].(* ssa.Const )
177177 if ! ok {
178- return llvm.Value {}, c .makeError (call .Pos (), "CSR must be constant" )
178+ return llvm.Value {}, b .makeError (call .Pos (), "CSR must be constant" )
179179 }
180180 csr := csrConst .Uint64 ()
181181 switch name := call .StaticCallee ().Name (); name {
182182 case "Get" :
183183 // Note that this instruction may have side effects, and thus must be
184184 // marked as such.
185- fnType := llvm .FunctionType (c .uintptrType , nil , false )
185+ fnType := llvm .FunctionType (b .uintptrType , nil , false )
186186 asm := fmt .Sprintf ("csrr $0, %d" , csr )
187187 target := llvm .InlineAsm (fnType , asm , "=r" , true , false , 0 )
188- return c . builder .CreateCall (target , nil , "" ), nil
188+ return b .CreateCall (target , nil , "" ), nil
189189 case "Set" :
190- fnType := llvm .FunctionType (c .ctx .VoidType (), []llvm.Type {c .uintptrType }, false )
190+ fnType := llvm .FunctionType (b .ctx .VoidType (), []llvm.Type {b .uintptrType }, false )
191191 asm := fmt .Sprintf ("csrw %d, $0" , csr )
192192 target := llvm .InlineAsm (fnType , asm , "r" , true , false , 0 )
193- return c . builder . CreateCall (target , []llvm.Value {frame .getValue (call .Args [1 ])}, "" ), nil
193+ return b . CreateCall (target , []llvm.Value {b .getValue (call .Args [1 ])}, "" ), nil
194194 case "SetBits" :
195195 // Note: it may be possible to optimize this to csrrsi in many cases.
196- fnType := llvm .FunctionType (c .uintptrType , []llvm.Type {c .uintptrType }, false )
196+ fnType := llvm .FunctionType (b .uintptrType , []llvm.Type {b .uintptrType }, false )
197197 asm := fmt .Sprintf ("csrrs $0, %d, $1" , csr )
198198 target := llvm .InlineAsm (fnType , asm , "=r,r" , true , false , 0 )
199- return c . builder . CreateCall (target , []llvm.Value {frame .getValue (call .Args [1 ])}, "" ), nil
199+ return b . CreateCall (target , []llvm.Value {b .getValue (call .Args [1 ])}, "" ), nil
200200 case "ClearBits" :
201201 // Note: it may be possible to optimize this to csrrci in many cases.
202- fnType := llvm .FunctionType (c .uintptrType , []llvm.Type {c .uintptrType }, false )
202+ fnType := llvm .FunctionType (b .uintptrType , []llvm.Type {b .uintptrType }, false )
203203 asm := fmt .Sprintf ("csrrc $0, %d, $1" , csr )
204204 target := llvm .InlineAsm (fnType , asm , "=r,r" , true , false , 0 )
205- return c . builder . CreateCall (target , []llvm.Value {frame .getValue (call .Args [1 ])}, "" ), nil
205+ return b . CreateCall (target , []llvm.Value {b .getValue (call .Args [1 ])}, "" ), nil
206206 default :
207- return llvm.Value {}, c .makeError (call .Pos (), "unknown CSR operation: " + name )
207+ return llvm.Value {}, b .makeError (call .Pos (), "unknown CSR operation: " + name )
208208 }
209209}
0 commit comments