pointerToConst converts the given LLVM IR constant to a pointer to c and returns the corresponding Go expression.
(c constant.Constant)
| 312 | // pointerToConst converts the given LLVM IR constant to a pointer to c and |
| 313 | // returns the corresponding Go expression. |
| 314 | func (d *decompiler) pointerToConst(c constant.Constant) ast.Expr { |
| 315 | switch c := c.(type) { |
| 316 | // Simple constants |
| 317 | case *constant.Int: |
| 318 | callee := fmt.Sprintf("newInt%d", c.Typ.Size) |
| 319 | d.newIntSizes[c.Typ.Size] = true |
| 320 | return &ast.CallExpr{ |
| 321 | Fun: ast.NewIdent(callee), |
| 322 | Args: []ast.Expr{d.value(c)}, |
| 323 | } |
| 324 | case *constant.Float: |
| 325 | panic("support for value *constant.Float not yet implemented") |
| 326 | case *constant.Null: |
| 327 | // nothing to do. |
| 328 | return d.value(c) |
| 329 | // Complex constants |
| 330 | case *constant.Vector, *constant.Array, *constant.Struct: |
| 331 | return &ast.UnaryExpr{ |
| 332 | Op: token.AND, |
| 333 | X: d.value(c), |
| 334 | } |
| 335 | case *constant.ZeroInitializer: |
| 336 | return &ast.CallExpr{ |
| 337 | Fun: ast.NewIdent("new"), |
| 338 | Args: []ast.Expr{d.goType(c.Typ)}, |
| 339 | } |
| 340 | // Global variable and function addresses |
| 341 | case *ir.Global: |
| 342 | // TODO: Check if `&g` should be returned instead of `g`. |
| 343 | return d.globalIdent(c.Name) |
| 344 | case *ir.Function: |
| 345 | // TODO: Check if `&f` should be returned instead of `f`. |
| 346 | return d.globalIdent(c.Name) |
| 347 | // Constant expressions |
| 348 | case constant.Expr: |
| 349 | panic("support for value constant.Expr not yet implemented") |
| 350 | default: |
| 351 | panic(fmt.Sprintf("support for value %T not yet implemented", c)) |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | // funcDecl converts the given LLVM IR function into a corresponding Go function |
| 356 | // declaration. |
no test coverage detected