| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <getopt.h> | 8 #include <getopt.h> |
| 9 #include <libgen.h> | 9 #include <libgen.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| 11 #include <stdlib.h> | 11 #include <stdlib.h> |
| 12 #include <string.h> | 12 #include <string.h> |
| 13 | 13 |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 #include <map> | 15 #include <map> |
| 16 #include <set> | 16 #include <set> |
| 17 #include <string> | 17 #include <string> |
| 18 #include <tuple> | 18 #include <tuple> |
| 19 #include <vector> | 19 #include <vector> |
| 20 | 20 |
| 21 |
| 21 template <typename T, size_t N> | 22 template <typename T, size_t N> |
| 22 char (&ArraySizeHelper(T (&array)[N]))[N]; | 23 char (&ArraySizeHelper(T (&array)[N]))[N]; |
| 23 #define arraysize(array) (sizeof(ArraySizeHelper(array))) | 24 #define arraysize(array) (sizeof(ArraySizeHelper(array))) |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 const char* short_program_name; | 27 const char* short_program_name; |
| 27 | 28 |
| 28 const struct option kProgramOptions[] = { | 29 const struct option kProgramOptions[] = { |
| 29 {"mode", required_argument, NULL, 'm'}, | 30 {"mode", required_argument, NULL, 'm'}, |
| 30 {"disable", required_argument, NULL, 'd'}, | 31 {"disable", required_argument, NULL, 'd'}, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 /* Flags for enabling/disabling based on architecture and validity. */ | 183 /* Flags for enabling/disabling based on architecture and validity. */ |
| 183 "ia32", | 184 "ia32", |
| 184 "amd64", | 185 "amd64", |
| 185 "nacl-ia32-forbidden", | 186 "nacl-ia32-forbidden", |
| 186 "nacl-amd64-forbidden", | 187 "nacl-amd64-forbidden", |
| 187 "nacl-forbidden" | 188 "nacl-forbidden" |
| 188 }; | 189 }; |
| 189 | 190 |
| 190 class Instruction { | 191 class Instruction { |
| 191 public: | 192 public: |
| 192 static bool check_flag_valid(const std::string &flag) { | 193 static void check_flag_valid(const std::string &flag) { |
| 193 if (all_instruction_flags.find(flag) == all_instruction_flags.end()) { | 194 if (all_instruction_flags.find(flag) == all_instruction_flags.end()) { |
| 194 fprintf(stderr, "%s: unknown flag: '%s'\n", | 195 fprintf(stderr, "%s: unknown flag: '%s'\n", |
| 195 short_program_name, flag.c_str()); | 196 short_program_name, flag.c_str()); |
| 196 exit(1); | 197 exit(1); |
| 197 } | 198 } |
| 198 } | 199 } |
| 199 | 200 |
| 200 void add_flag(const std::string &flag) { | 201 void add_flag(const std::string &flag) { |
| 201 check_flag_valid(flag); | 202 check_flag_valid(flag); |
| 202 flags.insert(flag); | 203 flags.insert(flag); |
| (...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 c_identifier(pair.first).c_str(), pair.second); | 1183 c_identifier(pair.first).c_str(), pair.second); |
| 1183 } | 1184 } |
| 1184 } | 1185 } |
| 1185 | 1186 |
| 1186 class MarkedInstruction : Instruction { | 1187 class MarkedInstruction : Instruction { |
| 1187 public: | 1188 public: |
| 1188 /* Additional marks are created in the process of parsing. */ | 1189 /* Additional marks are created in the process of parsing. */ |
| 1189 explicit MarkedInstruction(Instruction instruction_) : | 1190 explicit MarkedInstruction(Instruction instruction_) : |
| 1190 Instruction(instruction_), | 1191 Instruction(instruction_), |
| 1191 instruction_class(get_instruction_class(instruction_)), | 1192 instruction_class(get_instruction_class(instruction_)), |
| 1192 opcode_in_modrm(false), opcode_in_imm(false), rex { } { | 1193 rex { }, opcode_in_modrm(false), opcode_in_imm(false) { |
| 1193 if (has_flag("branch_hint")) { | 1194 if (has_flag("branch_hint")) { |
| 1194 optional_prefixes.insert("branch_hint"); | 1195 optional_prefixes.insert("branch_hint"); |
| 1195 } | 1196 } |
| 1196 if (has_flag("condrep")) { | 1197 if (has_flag("condrep")) { |
| 1197 optional_prefixes.insert("condrep"); | 1198 optional_prefixes.insert("condrep"); |
| 1198 } | 1199 } |
| 1199 if (has_flag("rep")) { | 1200 if (has_flag("rep")) { |
| 1200 optional_prefixes.insert("rep"); | 1201 optional_prefixes.insert("rep"); |
| 1201 } | 1202 } |
| 1202 for (auto opcode_it = opcodes.begin(); | 1203 for (auto opcode_it = opcodes.begin(); |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 } | 1542 } |
| 1542 } | 1543 } |
| 1543 | 1544 |
| 1544 void print_one_size_definition(void) { | 1545 void print_one_size_definition(void) { |
| 1545 /* 64bit commands are not supported in ia32 mode. */ | 1546 /* 64bit commands are not supported in ia32 mode. */ |
| 1546 if (ia32_mode && rex.w) { | 1547 if (ia32_mode && rex.w) { |
| 1547 return; | 1548 return; |
| 1548 } | 1549 } |
| 1549 bool modrm_memory = false; | 1550 bool modrm_memory = false; |
| 1550 bool modrm_register = false; | 1551 bool modrm_register = false; |
| 1551 char operand_source; | 1552 char operand_source = ' '; |
| 1552 for (auto operand_it = operands.begin(); | 1553 for (auto operand_it = operands.begin(); |
| 1553 operand_it != operands.end(); ++operand_it) { | 1554 operand_it != operands.end(); ++operand_it) { |
| 1554 auto &operand = *operand_it; | 1555 auto &operand = *operand_it; |
| 1555 static std::map<char, std::pair<bool, bool> > operand_map { | 1556 static std::map<char, std::pair<bool, bool> > operand_map { |
| 1556 { 'E', std::make_pair(true, true) }, | 1557 { 'E', std::make_pair(true, true) }, |
| 1557 { 'M', std::make_pair(true, false) }, | 1558 { 'M', std::make_pair(true, false) }, |
| 1558 { 'N', std::make_pair(false, true) }, | 1559 { 'N', std::make_pair(false, true) }, |
| 1559 { 'Q', std::make_pair(true, true) }, | 1560 { 'Q', std::make_pair(true, true) }, |
| 1560 { 'R', std::make_pair(false, true) }, | 1561 { 'R', std::make_pair(false, true) }, |
| 1561 { 'U', std::make_pair(false, true) }, | 1562 { 'U', std::make_pair(false, true) }, |
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2487 | 2488 |
| 2488 fprintf(out_file, "\n one_instruction ="); | 2489 fprintf(out_file, "\n one_instruction ="); |
| 2489 | 2490 |
| 2490 print_one_instruction_definition(); | 2491 print_one_instruction_definition(); |
| 2491 | 2492 |
| 2492 fprintf(out_file, ");\n" | 2493 fprintf(out_file, ");\n" |
| 2493 "}%%%%\n" | 2494 "}%%%%\n" |
| 2494 ""); | 2495 ""); |
| 2495 return 0; | 2496 return 0; |
| 2496 } | 2497 } |
| OLD | NEW |