blob: 49dad8afd635a65eccb983ba8c2d49a412e8865a [file] [log] [blame]
Josh Gaobfb6bae2016-07-15 17:25:21 -07001/*
2 * Copyright 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "Arch.h"
18
19#include <err.h>
20
21#include <string>
22
23std::string to_string(const Arch& arch) {
24 switch (arch) {
25 case Arch::arm:
26 return "arm";
27
28 case Arch::arm64:
29 return "arm64";
30
31 case Arch::mips:
32 return "mips";
33
34 case Arch::mips64:
35 return "mips64";
36
37 case Arch::x86:
38 return "x86";
39
40 case Arch::x86_64:
41 return "x86_64";
42 }
43
44 errx(1, "unknown arch '%zu'", size_t(arch));
45}
46
47Arch arch_from_string(const std::string& name) {
48 if (name == "arm") {
49 return Arch::arm;
50 } else if (name == "arm64") {
51 return Arch::arm64;
52 } else if (name == "mips") {
53 return Arch::mips;
54 } else if (name == "mips64") {
55 return Arch::mips64;
56 } else if (name == "x86") {
57 return Arch::x86;
58 } else if (name == "x86_64") {
59 return Arch::x86_64;
60 }
61
62 errx(1, "unknown architecture '%s'", name.c_str());
63}