ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
Hex.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
18#ifndef ETISS_INCLUDE_GDB_HEX_H_
19#define ETISS_INCLUDE_GDB_HEX_H_
20
21#include "etiss/jit/types.h"
22
23#include <iostream>
24#include <string>
25
26namespace etiss
27{
28
29namespace plugin
30{
31
32namespace gdb
33{
34
35namespace hex
36{
37
43extern uint8_t fromHex(char c);
49extern char toHex(uint8_t l);
50
57extern uint8_t toByte(char h, char l);
63extern uint8_t toByte(std::string hex, size_t pos = 0);
64
70extern std::string fromByte(uint8_t byte);
76extern void fromByte(std::string &append, uint8_t byte);
77
84extern std::string fromBytes(uint8_t *buf, size_t length);
85
86template <typename INT>
93void fromInt(std::string &string, INT val, bool isLittleEndian)
94{
95 for (size_t i = 0; i < sizeof(INT); i++)
96 {
97 fromByte(string, (uint8_t)(val >> (isLittleEndian ? (i * 8) : ((sizeof(INT) - i - 1) * 8))));
98 }
99}
100
101template <typename INT>
106INT toInt(const std::string &string, bool isLittleEndian, size_t pos = 0)
107{
108 INT ret = 0;
109 for (unsigned i = 0; i < static_cast<unsigned>(sizeof(INT)); i++)
110 {
111 ret |= ((((INT)toByte(string, pos + i * 2)) & ((INT)0xFF))
112 << (isLittleEndian ? (i * 8) : ((sizeof(INT) - i - 1) * 8)));
113 }
114 return ret;
115}
116template <typename INT>
125INT tryInt(std::string &string, unsigned &pos, size_t maxlength = sizeof(INT) * 2)
126{
127 INT ret = 0;
128 unsigned opos = pos;
129 while (string.length() > pos && pos - opos < maxlength)
130 {
131 uint8_t hb = fromHex(string[pos]);
132 if (hb >= 16) // invalid character
133 return ret;
134 ret = (ret << 4) | hb;
135 pos++;
136 }
137 return ret;
138}
139} // namespace hex
140
141} // namespace gdb
142
143} // namespace plugin
144
145} // namespace etiss
146
147#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:57
std::string fromByte(uint8_t byte)
converts a byte to a hex string (without "0x" prefix);
Definition Hex.cpp:62
INT tryInt(std::string &string, unsigned &pos, size_t maxlength=sizeof(INT) *2)
parses a hex string and returns the result.
Definition Hex.h:125
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:106
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:76
uint8_t fromHex(char c)
convert a character to the hex value it represents(0-15)
Definition Hex.cpp:18
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:93
char toHex(uint8_t l)
converts the lower 4 bits to a representing char
Definition Hex.cpp:37
forwards: include/jit/*
Definition Benchmark.h:17
float __ovld __cnfn length(float p)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)