ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Hex.h
Go to the documentation of this file.
1
56#ifndef ETISS_INCLUDE_GDB_HEX_H_
57#define ETISS_INCLUDE_GDB_HEX_H_
58
59#include "etiss/jit/types.h"
60
61#include <iostream>
62#include <string>
63
64namespace etiss
65{
66
67namespace plugin
68{
69
70namespace gdb
71{
72
73namespace hex
74{
75
81extern uint8_t fromHex(char c);
87extern char toHex(uint8_t l);
88
95extern uint8_t toByte(char h, char l);
101extern uint8_t toByte(std::string hex, size_t pos = 0);
102
108extern std::string fromByte(uint8_t byte);
114extern void fromByte(std::string &append, uint8_t byte);
115
122extern std::string fromBytes(uint8_t *buf, size_t length);
123
124template <typename INT>
131void fromInt(std::string &string, INT val, bool isLittleEndian)
132{
133 for (size_t i = 0; i < sizeof(INT); i++)
134 {
135 fromByte(string, (uint8_t)(val >> (isLittleEndian ? (i * 8) : ((sizeof(INT) - i - 1) * 8))));
136 }
137}
138
139template <typename INT>
144INT toInt(const std::string &string, bool isLittleEndian, size_t pos = 0)
145{
146 INT ret = 0;
147 for (unsigned i = 0; i < static_cast<unsigned>(sizeof(INT)); i++)
148 {
149 ret |= ((((INT)toByte(string, pos + i * 2)) & ((INT)0xFF))
150 << (isLittleEndian ? (i * 8) : ((sizeof(INT) - i - 1) * 8)));
151 }
152 return ret;
153}
154template <typename INT>
163INT tryInt(std::string &string, unsigned &pos, size_t maxlength = sizeof(INT) * 2)
164{
165 INT ret = 0;
166 unsigned opos = pos;
167 while (string.length() > pos && pos - opos < maxlength)
168 {
169 uint8_t hb = fromHex(string[pos]);
170 if (hb >= 16) // invalid character
171 return ret;
172 ret = (ret << 4) | hb;
173 pos++;
174 }
175 return ret;
176}
177} // namespace hex
178
179} // namespace gdb
180
181} // namespace plugin
182
183} // namespace etiss
184
185#endif
__device__ __2f16 float c
static __inline__ uint8_t
Definition arm_mve.h:323
uint8_t toByte(char h, char l)
converts 2 hex characters to a byte
Definition Hex.cpp:95
std::string fromByte(uint8_t byte)
converts a byte to a hex string (without "0x" prefix);
Definition Hex.cpp:100
INT tryInt(std::string &string, unsigned &pos, size_t maxlength=sizeof(INT) *2)
parses a hex string and returns the result.
Definition Hex.h:163
INT toInt(const std::string &string, bool isLittleEndian, size_t pos=0)
convert a string of length (pos + sizeof(INT)) or larger to the represented value.
Definition Hex.h:144
std::string fromBytes(uint8_t *buf, size_t length)
converts a sequence of bytes to a representing hex string (without "0x" prefix)
Definition Hex.cpp:114
uint8_t fromHex(char c)
convert a character to the hex value it represents(0-15)
Definition Hex.cpp:56
void fromInt(std::string &string, INT val, bool isLittleEndian)
converts an integer type variable to a hexadecimal representation with the given endianness
Definition Hex.h:131
char toHex(uint8_t l)
converts the lower 4 bits to a representing char
Definition Hex.cpp:75
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition Benchmark.h:53
float __ovld __cnfn length(float p)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)