mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-03 19:32:35 +00:00
6436a4abd7
Switch gofrontend to using go.googlesource.com, and update to 81eb6a3f425b2158c67ee32c0cc973a72ce9d6be. There are various changes required to update to the go 1.5 runtime: typemap.go is changed to accommodate the change in representation for equal/hash algorithms, and the removal of the zero value/type. CMakeLists.txt is updated to add the build tree to the package search path, so internal packages, which are not installed, are found. various files changes due to removal of __go_new_nopointers; the same change as in D11863, but with NoUnwindAttribute added to the added runtime functions which are called with "callOnly". minor cleanups in ssa.go while investigating issues with unwinding/panic handling. Differential Revisision: http://reviews.llvm.org/D15188 llvm-svn: 263536
90 lines
2.4 KiB
Go
90 lines
2.4 KiB
Go
//===- targets.go - target data -------------------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file contains functions for retrieving target-specific data.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
package irgen
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"llvm.org/llvm/bindings/go/llvm"
|
|
)
|
|
|
|
// llvmDataLayout returns the data layout string
|
|
// representation for the specified LLVM triple.
|
|
func llvmDataLayout(triple string) (string, error) {
|
|
// Triples are several fields separated by '-' characters.
|
|
// The first field is the architecture. The architecture's
|
|
// canonical form may include a '-' character, which would
|
|
// have been translated to '_' for inclusion in a triple.
|
|
arch := parseArch(triple[:strings.IndexRune(triple, '-')])
|
|
for target := llvm.FirstTarget(); target.C != nil; target = target.NextTarget() {
|
|
if arch == target.Name() {
|
|
machine := target.CreateTargetMachine(
|
|
triple, "", "",
|
|
llvm.CodeGenLevelDefault,
|
|
llvm.RelocDefault,
|
|
llvm.CodeModelDefault,
|
|
)
|
|
targetData := machine.CreateTargetData()
|
|
targetDataLayout := targetData.String()
|
|
targetData.Dispose()
|
|
machine.Dispose()
|
|
return targetDataLayout, nil
|
|
}
|
|
}
|
|
return "", fmt.Errorf("Invalid target triple: %s", triple)
|
|
}
|
|
|
|
// Based on parseArch from LLVM's lib/Support/Triple.cpp.
|
|
// This is used to match the target machine type.
|
|
func parseArch(arch string) string {
|
|
switch arch {
|
|
case "i386", "i486", "i586", "i686", "i786", "i886", "i986":
|
|
return "x86"
|
|
case "amd64", "x86_64":
|
|
return "x86-64"
|
|
case "powerpc":
|
|
return "ppc"
|
|
case "powerpc64", "ppu":
|
|
return "ppc64"
|
|
case "mblaze":
|
|
return "mblaze"
|
|
case "arm", "xscale":
|
|
return "arm"
|
|
case "thumb":
|
|
return "thumb"
|
|
case "spu", "cellspu":
|
|
return "cellspu"
|
|
case "msp430":
|
|
return "msp430"
|
|
case "mips", "mipseb", "mipsallegrex":
|
|
return "mips"
|
|
case "mipsel", "mipsallegrexel":
|
|
return "mipsel"
|
|
case "mips64", "mips64eb":
|
|
return "mips64"
|
|
case "mipsel64":
|
|
return "mipsel64"
|
|
case "r600", "hexagon", "sparc", "sparcv9", "tce",
|
|
"xcore", "nvptx", "nvptx64", "le32", "amdil":
|
|
return arch
|
|
}
|
|
if strings.HasPrefix(arch, "armv") {
|
|
return "arm"
|
|
} else if strings.HasPrefix(arch, "thumbv") {
|
|
return "thumb"
|
|
}
|
|
return "unknown"
|
|
}
|