-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbasic_explorer.cpp
More file actions
62 lines (49 loc) · 2.07 KB
/
basic_explorer.cpp
File metadata and controls
62 lines (49 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <random>
#include "amdisa/isa_explorer.h"
// Constants.
// Error constant string.
static const char* kStrErrorInvalidArgument = "Error: Requires XML specification path.";
static void print_instruction(const amdisa::explorer::Instruction& instruction)
{
std::cout << "Name: " << instruction.Name() << std::endl;
std::cout << "\tDescription: " << instruction.Description() << std::endl;
std::cout << "\tIsBranch ?: " << instruction.IsBranch() << std::endl;
std::cout << "\tIsConditionalBranch ?: " << instruction.IsConditionalBranch() << std::endl;
std::cout << "\tIsIndirectBranch ?: " << instruction.IsIndirectBranch() << std::endl;
std::cout << "\tFunctionalGroup: " << instruction.FuncGroup()->Name() << std::endl;
std::cout << "\t\t Description: " << instruction.FuncGroup()->Description() << std::endl << std::endl;
std::cout << "\tFunctionalSubgroup: " << instruction.FuncSubgroup()->Name() << std::endl;
}
int main(int argc, char** argv)
{
// Check for valid input argument.
if (argc != 2)
{
std::cerr << kStrErrorInvalidArgument << std::endl;
return -1;
}
amdisa::explorer::Spec explorer;
// Check API version.
std::cout << "IsaExplorer version: " << explorer.GetApiVersion() << std::endl;
const std::string kPathToSpec = argv[1];
std::string err_message;
bool is_init = explorer.Init(kPathToSpec, err_message);
// Check for successful spec initialization.
if (!is_init)
{
std::cerr << err_message << std::endl;
return -1;
}
// Lookup an instruction by name.
auto v_mov_b32 = explorer.GetInstructions().at("V_MOV_B32");
print_instruction(v_mov_b32);
// Choose a random instruction and print it.
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> dist(0, explorer.GetInstructions().size() - 1);
auto it = explorer.GetInstructions().begin();
std::advance(it, dist(gen));
print_instruction(it->second);
return 0;
}