Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 18 | "fmt" |
| 19 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 20 | "android/soong/common" |
| 21 | ) |
| 22 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 23 | type toolchainFactory func(arch common.Arch) Toolchain |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 24 | |
| 25 | var 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 | |
| 30 | func registerToolchainFactory(hod common.HostOrDevice, arch common.ArchType, |
| 31 | factory toolchainFactory) { |
| 32 | |
| 33 | toolchainFactories[hod][arch] = factory |
| 34 | } |
| 35 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 36 | type Toolchain interface { |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 37 | Name() string |
| 38 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 39 | GccRoot() string |
| 40 | GccTriple() string |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 41 | GccVersion() string |
Colin Cross | c4bde76 | 2015-11-23 16:11:30 -0800 | [diff] [blame^] | 42 | ToolchainCflags() string |
| 43 | ToolchainLdflags() string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 44 | Cflags() string |
| 45 | Cppflags() string |
| 46 | Ldflags() string |
| 47 | IncludeFlags() string |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 48 | InstructionSetFlags(string) (string, error) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 49 | |
| 50 | ClangTriple() string |
Colin Cross | c4bde76 | 2015-11-23 16:11:30 -0800 | [diff] [blame^] | 51 | ToolchainClangCflags() string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 52 | ClangCflags() string |
| 53 | ClangCppflags() string |
| 54 | ClangLdflags() string |
Dan Willemsen | 6d11dd8 | 2015-11-03 14:27:00 -0800 | [diff] [blame] | 55 | ClangInstructionSetFlags(string) (string, error) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 56 | |
| 57 | Is64Bit() bool |
| 58 | } |
| 59 | |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 60 | type toolchainBase struct { |
| 61 | } |
| 62 | |
| 63 | func (toolchainBase) InstructionSetFlags(s string) (string, error) { |
| 64 | if s != "" { |
| 65 | return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s) |
| 66 | } |
| 67 | return "", nil |
| 68 | } |
| 69 | |
Dan Willemsen | 6d11dd8 | 2015-11-03 14:27:00 -0800 | [diff] [blame] | 70 | func (toolchainBase) ClangInstructionSetFlags(s string) (string, error) { |
| 71 | if s != "" { |
| 72 | return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s) |
| 73 | } |
| 74 | return "", nil |
| 75 | } |
| 76 | |
Colin Cross | c4bde76 | 2015-11-23 16:11:30 -0800 | [diff] [blame^] | 77 | func (toolchainBase) ToolchainCflags() string { |
| 78 | return "" |
| 79 | } |
| 80 | |
| 81 | func (toolchainBase) ToolchainLdflags() string { |
| 82 | return "" |
| 83 | } |
| 84 | |
| 85 | func (toolchainBase) ToolchainClangCflags() string { |
| 86 | return "" |
| 87 | } |
| 88 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 89 | type toolchain64Bit struct { |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 90 | toolchainBase |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | func (toolchain64Bit) Is64Bit() bool { |
| 94 | return true |
| 95 | } |
| 96 | |
| 97 | type toolchain32Bit struct { |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 98 | toolchainBase |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | func (toolchain32Bit) Is64Bit() bool { |
| 102 | return false |
| 103 | } |