Example #1
0
// 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, '-')])
	switch arch {
	case "x86-64":
		return x86TargetData, nil
	}
	for target := llvm.FirstTarget(); target.C != nil; target = target.NextTarget() {
		if arch == target.Name() {
			machine := target.CreateTargetMachine(
				triple, "", "",
				llvm.CodeGenLevelDefault,
				llvm.RelocDefault,
				llvm.CodeModelDefault,
			)
			target := machine.TargetData().String()
			machine.Dispose()
			return target, nil
		}
	}
	return "", fmt.Errorf("Invalid target triple: %s", triple)
}
Example #2
0
File: llgo.go Project: rvedam/llgo
func displayVersion() {
	fmt.Printf("llgo version %s (Go %s)\n", llgo.LLGOVersion, runtime.Version())
	fmt.Println()

	fmt.Println("  Available targets:")
	longestTargetName := 0
	targetDescriptions := make(map[string]string)
	targetNames := make([]string, 0)
	for target := llvm.FirstTarget(); target.C != nil; target = target.NextTarget() {
		targetName := target.Name()
		targetNames = append(targetNames, targetName)
		targetDescriptions[targetName] = target.Description()
		if len(targetName) > longestTargetName {
			longestTargetName = len(targetName)
		}
	}
	sort.Strings(targetNames)
	for _, targetName := range targetNames {
		var paddingLen int = longestTargetName - len(targetName)
		fmt.Printf("    %s %*s %s\n", targetName, paddingLen+1, "-",
			targetDescriptions[targetName])
	}
	fmt.Println()

	os.Exit(0)
}