Debian Codegraph @

src/fcml_parser_utils.c

raw
1 /*
2 * FCML - Free Code Manipulation Library.
3 * Copyright (C) 2010-2020 Slawomir Wojtasiak
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "fcml_parser_utils.h"
21
22 #include <stdlib.h>
23 #include <errno.h>
24
25 void fcml_fn_pu_parse_integer(const fcml_char *str,
26 fcml_st_ast_val_integer *integer_value, int base) {
27 #ifdef FCML_MSCC
28 fcml_uint64_t value = _strtoui64( str, NULL, base );
29 #else
30 fcml_uint64_t value = strtoull(str, NULL, base);
31 #endif
32 integer_value->overflow = ( errno == ERANGE);
33 integer_value->value = value;
34 integer_value->is_signed = FCML_FALSE;
35 }
36
37 void fcml_fn_pu_parse_float(const fcml_char *str,
38 fcml_st_ast_val_float *float_value) {
39 // Floats are not supported yet.
40 #ifdef FCML_MSCC
41 float_value->value = (float)strtod( str, NULL );
42 #else
43 float_value->value = strtof(str, NULL);
44 #endif
45 float_value->overflow = ( errno == ERANGE) ? FCML_TRUE : FCML_FALSE;
46 }
47
48 void fcml_fn_pu_parse_register(fcml_en_register type, fcml_usize size,
49 fcml_uint8_t reg, fcml_bool x64_exp, fcml_st_register *reg_dest) {
50 reg_dest->type = type;
51 reg_dest->size = size;
52 reg_dest->reg = reg;
53 reg_dest->x64_exp = x64_exp;
54 }
55
56 fcml_char* fcml_fn_pu_reg_type_to_string(fcml_en_register type) {
57 fcml_char *desc;
58 switch (type) {
59 case FCML_REG_GPR:
60 desc = "GPR";
61 break;
62 case FCML_REG_SIMD:
63 desc = "SIMD";
64 break;
65 case FCML_REG_FPU:
66 desc = "FPU";
67 break;
68 case FCML_REG_SEG:
69 desc = "SEG";
70 break;
71 case FCML_REG_DR:
72 desc = "DR";
73 break;
74 case FCML_REG_CR:
75 desc = "CR";
76 break;
77 default:
78 desc = "Unknown";
79 break;
80 }
81 return desc;
82 }
83