blob: 8a8fc2d547a78657b352ba34b0718ffcb4bc9f46 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070018 "fmt"
19
Colin Cross3f40fa42015-01-30 17:27:36 -080020 "android/soong/common"
21)
22
Colin Crossc5c24ad2015-11-20 15:35:00 -080023type toolchainFactory func(arch common.Arch) Toolchain
Colin Cross3f40fa42015-01-30 17:27:36 -080024
25var toolchainFactories = map[common.HostOrDevice]map[common.ArchType]toolchainFactory{
26 common.Host: make(map[common.ArchType]toolchainFactory),
27 common.Device: make(map[common.ArchType]toolchainFactory),
28}
29
30func registerToolchainFactory(hod common.HostOrDevice, arch common.ArchType,
31 factory toolchainFactory) {
32
33 toolchainFactories[hod][arch] = factory
34}
35
Colin Cross97ba0732015-03-23 17:50:24 -070036type Toolchain interface {
Dan Albertbe961682015-03-18 23:38:50 -070037 Name() string
38
Colin Cross3f40fa42015-01-30 17:27:36 -080039 GccRoot() string
40 GccTriple() string
Dan Albertbe961682015-03-18 23:38:50 -070041 GccVersion() string
Colin Cross3f40fa42015-01-30 17:27:36 -080042 Cflags() string
43 Cppflags() string
44 Ldflags() string
45 IncludeFlags() string
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070046 InstructionSetFlags(string) (string, error)
Colin Cross3f40fa42015-01-30 17:27:36 -080047
48 ClangTriple() string
49 ClangCflags() string
50 ClangCppflags() string
51 ClangLdflags() string
Dan Willemsen6d11dd82015-11-03 14:27:00 -080052 ClangInstructionSetFlags(string) (string, error)
Colin Cross3f40fa42015-01-30 17:27:36 -080053
54 Is64Bit() bool
55}
56
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070057type toolchainBase struct {
58}
59
60func (toolchainBase) InstructionSetFlags(s string) (string, error) {
61 if s != "" {
62 return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s)
63 }
64 return "", nil
65}
66
Dan Willemsen6d11dd82015-11-03 14:27:00 -080067func (toolchainBase) ClangInstructionSetFlags(s string) (string, error) {
68 if s != "" {
69 return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s)
70 }
71 return "", nil
72}
73
Colin Cross3f40fa42015-01-30 17:27:36 -080074type toolchain64Bit struct {
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070075 toolchainBase
Colin Cross3f40fa42015-01-30 17:27:36 -080076}
77
78func (toolchain64Bit) Is64Bit() bool {
79 return true
80}
81
82type toolchain32Bit struct {
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070083 toolchainBase
Colin Cross3f40fa42015-01-30 17:27:36 -080084}
85
86func (toolchain32Bit) Is64Bit() bool {
87 return false
88}