mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
ae65e281f3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
69 lines
2.2 KiB
Go
69 lines
2.2 KiB
Go
//===- analysis.go - Bindings for analysis --------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines bindings for the analysis component.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
package llvm
|
|
|
|
/*
|
|
#include "llvm-c/Analysis.h" // If you are getting an error here read bindings/go/README.txt
|
|
#include "llvm-c/Core.h"
|
|
#include <stdlib.h>
|
|
*/
|
|
import "C"
|
|
import "errors"
|
|
|
|
type VerifierFailureAction C.LLVMVerifierFailureAction
|
|
|
|
const (
|
|
// verifier will print to stderr and abort()
|
|
AbortProcessAction VerifierFailureAction = C.LLVMAbortProcessAction
|
|
// verifier will print to stderr and return 1
|
|
PrintMessageAction VerifierFailureAction = C.LLVMPrintMessageAction
|
|
// verifier will just return 1
|
|
ReturnStatusAction VerifierFailureAction = C.LLVMReturnStatusAction
|
|
)
|
|
|
|
// Verifies that a module is valid, taking the specified action if not.
|
|
// Optionally returns a human-readable description of any invalid constructs.
|
|
func VerifyModule(m Module, a VerifierFailureAction) error {
|
|
var cmsg *C.char
|
|
broken := C.LLVMVerifyModule(m.C, C.LLVMVerifierFailureAction(a), &cmsg)
|
|
|
|
// C++'s verifyModule means isModuleBroken, so it returns false if
|
|
// there are no errors
|
|
if broken != 0 {
|
|
err := errors.New(C.GoString(cmsg))
|
|
C.LLVMDisposeMessage(cmsg)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var verifyFunctionError = errors.New("Function is broken")
|
|
|
|
// Verifies that a single function is valid, taking the specified action.
|
|
// Useful for debugging.
|
|
func VerifyFunction(f Value, a VerifierFailureAction) error {
|
|
broken := C.LLVMVerifyFunction(f.C, C.LLVMVerifierFailureAction(a))
|
|
|
|
// C++'s verifyFunction means isFunctionBroken, so it returns false if
|
|
// there are no errors
|
|
if broken != 0 {
|
|
return verifyFunctionError
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Open up a ghostview window that displays the CFG of the current function.
|
|
// Useful for debugging.
|
|
func ViewFunctionCFG(f Value) { C.LLVMViewFunctionCFG(f.C) }
|
|
func ViewFunctionCFGOnly(f Value) { C.LLVMViewFunctionCFGOnly(f.C) }
|