evoasm 0.0.2.pre7 → 0.1.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gdbinit +41 -0
- data/.gitignore +1 -2
- data/.gitmodules +3 -0
- data/.rubocop.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.md +660 -0
- data/Makefile +1 -1
- data/README.md +17 -9
- data/Rakefile +39 -107
- data/bin/gdb +1 -1
- data/bin/gdb_loop +4 -0
- data/docs/FindingInstructions.md +17 -0
- data/docs/JIT.md +14 -0
- data/docs/SymbolicRegression.md +102 -0
- data/docs/Visualization.md +29 -0
- data/docs/examples/bit_insts.rb +44 -0
- data/docs/examples/jit.rb +26 -0
- data/docs/examples/loss.gif +0 -0
- data/docs/examples/program.png +0 -0
- data/docs/examples/sym_reg.rb +64 -0
- data/docs/examples/vis.rb +38 -0
- data/evoasm.gemspec +21 -15
- data/ext/evoasm_ext/Rakefile +3 -0
- data/ext/evoasm_ext/compile.rake +35 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-alloc.c +226 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-alloc.h +84 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-arch.c +52 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-arch.h +101 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-bitmap.h +158 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-buf.c +204 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-buf.h +109 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-domain.c +124 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-domain.h +279 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-error.c +65 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-error.h +108 -0
- data/ext/evoasm_ext/{evoasm-log.c → libevoasm/src/evoasm-log.c} +36 -18
- data/ext/evoasm_ext/libevoasm/src/evoasm-log.h +93 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-param.c +22 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-param.h +33 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-pop-params.c +192 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-pop-params.h +60 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-pop.c +1323 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-pop.h +107 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-program-io.c +116 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-program-io.h +60 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-program.c +1827 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-program.h +167 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-rand.c +65 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-rand.h +76 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-signal.c +106 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-signal.h +58 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-util.h +112 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-x64.c +925 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm-x64.h +277 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm.c +28 -0
- data/ext/evoasm_ext/libevoasm/src/evoasm.h +35 -0
- data/ext/evoasm_ext/libevoasm/src/gen/evoasm-x64-enums.h +2077 -0
- data/ext/evoasm_ext/libevoasm/src/gen/evoasm-x64-insts.c +191203 -0
- data/ext/evoasm_ext/libevoasm/src/gen/evoasm-x64-insts.h +1713 -0
- data/ext/evoasm_ext/libevoasm/src/gen/evoasm-x64-misc.c +348 -0
- data/ext/evoasm_ext/libevoasm/src/gen/evoasm-x64-misc.h +93 -0
- data/ext/evoasm_ext/libevoasm/src/gen/evoasm-x64-params.c +51 -0
- data/ext/evoasm_ext/libevoasm/src/gen/evoasm-x64-params.h +509 -0
- data/lib/evoasm.rb +28 -11
- data/lib/evoasm/buffer.rb +105 -0
- data/lib/evoasm/capstone.rb +100 -0
- data/lib/evoasm/domain.rb +116 -0
- data/lib/evoasm/error.rb +37 -16
- data/lib/evoasm/exception_error.rb +19 -0
- data/lib/evoasm/ffi_ext.rb +53 -0
- data/lib/evoasm/libevoasm.rb +286 -0
- data/lib/evoasm/libevoasm/x64_enums.rb +1967 -0
- data/lib/evoasm/parameter.rb +20 -0
- data/lib/evoasm/population.rb +145 -0
- data/lib/evoasm/population/parameters.rb +227 -0
- data/lib/evoasm/population/plotter.rb +89 -0
- data/lib/evoasm/prng.rb +64 -0
- data/lib/evoasm/program.rb +195 -12
- data/lib/evoasm/program/io.rb +144 -0
- data/lib/evoasm/test.rb +8 -0
- data/lib/evoasm/version.rb +1 -1
- data/lib/evoasm/x64.rb +115 -0
- data/lib/evoasm/x64/cpu_state.rb +95 -0
- data/lib/evoasm/x64/instruction.rb +109 -0
- data/lib/evoasm/x64/operand.rb +156 -0
- data/lib/evoasm/x64/parameters.rb +211 -0
- data/test/helpers/population_helper.rb +128 -0
- data/test/helpers/test_helper.rb +1 -0
- data/test/helpers/x64_helper.rb +24 -0
- data/test/integration/bitwise_reverse_test.rb +41 -0
- data/test/integration/gcd_test.rb +52 -0
- data/test/integration/popcnt_test.rb +46 -0
- data/test/integration/sym_reg_test.rb +68 -0
- data/test/unit/evoasm/buffer_test.rb +48 -0
- data/test/unit/evoasm/capstone_test.rb +18 -0
- data/test/unit/evoasm/domain_test.rb +55 -0
- data/test/unit/evoasm/population/parameters_test.rb +106 -0
- data/test/unit/evoasm/population_test.rb +96 -0
- data/test/unit/evoasm/prng_test.rb +47 -0
- data/test/unit/evoasm/x64/cpu_state_test.rb +73 -0
- data/test/unit/evoasm/x64/encoding_test.rb +320 -0
- data/test/unit/evoasm/x64/instruction_access_test.rb +177 -0
- data/test/unit/evoasm/x64/instruction_encoding_test.rb +780 -0
- data/test/unit/evoasm/x64/instruction_test.rb +62 -0
- data/test/unit/evoasm/x64/parameters_test.rb +65 -0
- data/test/unit/evoasm/x64_test.rb +52 -0
- metadata +195 -89
- data/Gemfile.rake +0 -8
- data/Gemfile.rake.lock +0 -51
- data/LICENSE.txt +0 -373
- data/data/tables/README.md +0 -19
- data/data/tables/x64.csv +0 -1684
- data/data/templates/evoasm-x64.c.erb +0 -319
- data/data/templates/evoasm-x64.h.erb +0 -126
- data/examples/abs.yml +0 -20
- data/examples/popcnt.yml +0 -17
- data/examples/sym_reg.yml +0 -26
- data/exe/evoasm-search +0 -13
- data/ext/evoasm_ext/evoasm-alloc.c +0 -145
- data/ext/evoasm_ext/evoasm-alloc.h +0 -59
- data/ext/evoasm_ext/evoasm-arch.c +0 -44
- data/ext/evoasm_ext/evoasm-arch.h +0 -161
- data/ext/evoasm_ext/evoasm-bitmap.h +0 -114
- data/ext/evoasm_ext/evoasm-buf.c +0 -130
- data/ext/evoasm_ext/evoasm-buf.h +0 -47
- data/ext/evoasm_ext/evoasm-error.c +0 -31
- data/ext/evoasm_ext/evoasm-error.h +0 -75
- data/ext/evoasm_ext/evoasm-free-list.c.tmpl +0 -121
- data/ext/evoasm_ext/evoasm-free-list.h.tmpl +0 -86
- data/ext/evoasm_ext/evoasm-log.h +0 -69
- data/ext/evoasm_ext/evoasm-misc.c +0 -23
- data/ext/evoasm_ext/evoasm-misc.h +0 -282
- data/ext/evoasm_ext/evoasm-param.h +0 -37
- data/ext/evoasm_ext/evoasm-search.c +0 -2145
- data/ext/evoasm_ext/evoasm-search.h +0 -214
- data/ext/evoasm_ext/evoasm-util.h +0 -40
- data/ext/evoasm_ext/evoasm-x64.c +0 -275624
- data/ext/evoasm_ext/evoasm-x64.h +0 -5436
- data/ext/evoasm_ext/evoasm.c +0 -7
- data/ext/evoasm_ext/evoasm.h +0 -23
- data/ext/evoasm_ext/evoasm_ext.c +0 -1757
- data/ext/evoasm_ext/extconf.rb +0 -31
- data/lib/evoasm/cli.rb +0 -6
- data/lib/evoasm/cli/search.rb +0 -127
- data/lib/evoasm/core_ext.rb +0 -1
- data/lib/evoasm/core_ext/array.rb +0 -9
- data/lib/evoasm/core_ext/integer.rb +0 -10
- data/lib/evoasm/core_ext/kwstruct.rb +0 -13
- data/lib/evoasm/core_ext/range.rb +0 -5
- data/lib/evoasm/examples.rb +0 -27
- data/lib/evoasm/gen.rb +0 -8
- data/lib/evoasm/gen/enum.rb +0 -169
- data/lib/evoasm/gen/name_util.rb +0 -80
- data/lib/evoasm/gen/state.rb +0 -176
- data/lib/evoasm/gen/state_dsl.rb +0 -152
- data/lib/evoasm/gen/strio.rb +0 -27
- data/lib/evoasm/gen/translator.rb +0 -1102
- data/lib/evoasm/gen/version.rb +0 -5
- data/lib/evoasm/gen/x64.rb +0 -237
- data/lib/evoasm/gen/x64/funcs.rb +0 -495
- data/lib/evoasm/gen/x64/inst.rb +0 -781
- data/lib/evoasm/search.rb +0 -40
- data/lib/evoasm/tasks/gen_task.rb +0 -86
- data/lib/evoasm/tasks/template_task.rb +0 -52
- data/test/test_helper.rb +0 -1
- data/test/x64/test_helper.rb +0 -19
- data/test/x64/x64_test.rb +0 -87
@@ -0,0 +1,65 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2016 Julian Aron Prenner <jap@polyadic.com>
|
3
|
+
*
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU Affero General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#include "evoasm-error.h"
|
19
|
+
|
20
|
+
_Thread_local evoasm_error_t evoasm_last_error;
|
21
|
+
|
22
|
+
void
|
23
|
+
evoasm_error_setv(evoasm_error_t *error, unsigned error_type, unsigned error_code,
|
24
|
+
void *error_data, const char *file,
|
25
|
+
unsigned line, const char *format, va_list args) {
|
26
|
+
|
27
|
+
error->type = (uint16_t) error_type;
|
28
|
+
error->code = (uint16_t) error_code;
|
29
|
+
error->line = line;
|
30
|
+
strncpy(error->filename, file, EVOASM_ERROR_MAX_FILENAME_LEN);
|
31
|
+
vsnprintf(error->msg, EVOASM_ERROR_MAX_MSG_LEN, format, args);
|
32
|
+
|
33
|
+
if(error_data != NULL) {
|
34
|
+
memcpy(&error->data, error_data, sizeof(evoasm_error_data_t));
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
evoasm_error_t *
|
39
|
+
evoasm_get_last_error() {
|
40
|
+
return &evoasm_last_error;
|
41
|
+
}
|
42
|
+
|
43
|
+
void
|
44
|
+
evoasm_set_last_error(evoasm_error_t *error) {
|
45
|
+
evoasm_last_error = *error;
|
46
|
+
}
|
47
|
+
|
48
|
+
void
|
49
|
+
evoasm_error_set(evoasm_error_t *error, unsigned error_type, unsigned error_code,
|
50
|
+
void *error_data, const char *file,
|
51
|
+
unsigned line, const char *format, ...) {
|
52
|
+
va_list args;
|
53
|
+
va_start(args, format);
|
54
|
+
evoasm_error_setv(error, error_type, error_code,
|
55
|
+
error_data, file, line,
|
56
|
+
format, args);
|
57
|
+
va_end(args);
|
58
|
+
}
|
59
|
+
|
60
|
+
EVOASM_DEF_GETTER(error, type, evoasm_error_type_t)
|
61
|
+
EVOASM_DEF_GETTER(error, code, evoasm_error_code_t)
|
62
|
+
EVOASM_DEF_GETTER(error, line, unsigned)
|
63
|
+
EVOASM_DEF_GETTER(error, filename, char *)
|
64
|
+
EVOASM_DEF_GETTER(error, msg, char *)
|
65
|
+
|
@@ -0,0 +1,108 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2016 Julian Aron Prenner <jap@polyadic.com>
|
3
|
+
*
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU Affero General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#pragma once
|
19
|
+
|
20
|
+
#include <assert.h>
|
21
|
+
#include <stdio.h>
|
22
|
+
#include <stdlib.h>
|
23
|
+
#include <stdint.h>
|
24
|
+
#include <stdbool.h>
|
25
|
+
#include <string.h>
|
26
|
+
#include <stdarg.h>
|
27
|
+
|
28
|
+
#include "evoasm-util.h"
|
29
|
+
#include "evoasm-log.h"
|
30
|
+
|
31
|
+
#define EVOASM_ERROR_MAX_FILENAME_LEN 128
|
32
|
+
#define EVOASM_ERROR_MAX_MSG_LEN 128
|
33
|
+
|
34
|
+
#define EVOASM_ERROR_HEADER \
|
35
|
+
uint16_t type; \
|
36
|
+
uint16_t code; \
|
37
|
+
uint32_t line; \
|
38
|
+
char filename[EVOASM_ERROR_MAX_FILENAME_LEN]; \
|
39
|
+
char msg[EVOASM_ERROR_MAX_MSG_LEN];
|
40
|
+
|
41
|
+
typedef enum {
|
42
|
+
EVOASM_ERROR_CODE_NONE
|
43
|
+
} evoasm_error_code_t;
|
44
|
+
|
45
|
+
typedef enum {
|
46
|
+
EVOASM_ERROR_TYPE_BUF,
|
47
|
+
EVOASM_ERROR_TYPE_ALLOC,
|
48
|
+
EVOASM_ERROR_TYPE_ARCH,
|
49
|
+
EVOASM_ERROR_TYPE_PROGRAM,
|
50
|
+
EVOASM_ERROR_TYPE_POP_PARAMS,
|
51
|
+
EVOASM_ERROR_TYPE_POP,
|
52
|
+
EVOASM_ERROR_TYPE_NONE,
|
53
|
+
} evoasm_error_type_t;
|
54
|
+
|
55
|
+
typedef struct {
|
56
|
+
uint8_t data[64];
|
57
|
+
} evoasm_error_data_t;
|
58
|
+
|
59
|
+
typedef struct {
|
60
|
+
EVOASM_ERROR_HEADER
|
61
|
+
evoasm_error_data_t data;
|
62
|
+
} evoasm_error_t;
|
63
|
+
|
64
|
+
|
65
|
+
void
|
66
|
+
evoasm_error_setv(evoasm_error_t *error, unsigned error_type, unsigned error_code,
|
67
|
+
void *error_data, const char *file,
|
68
|
+
unsigned line, const char *format, va_list args);
|
69
|
+
|
70
|
+
void
|
71
|
+
evoasm_error_set(evoasm_error_t *error, unsigned error_type, unsigned error_code,
|
72
|
+
void *error_data, const char *file,
|
73
|
+
unsigned line, const char *format, ...) evoasm_printf(7, 8);
|
74
|
+
|
75
|
+
|
76
|
+
evoasm_error_t *
|
77
|
+
evoasm_get_last_error();
|
78
|
+
|
79
|
+
void
|
80
|
+
evoasm_set_last_error(evoasm_error_t *error);
|
81
|
+
|
82
|
+
extern _Thread_local evoasm_error_t evoasm_last_error;
|
83
|
+
|
84
|
+
#define EVOASM_TRY(label, func, ...) \
|
85
|
+
do { if(!func(__VA_ARGS__)) {goto label;} } while(0)
|
86
|
+
|
87
|
+
|
88
|
+
#define EVOASM_TRY_WARN(func, ...) \
|
89
|
+
do { \
|
90
|
+
if(!func(__VA_ARGS__)) { \
|
91
|
+
evoasm_log(EVOASM_LOG_LEVEL_WARN, EVOASM_LOG_TAG, #func "failed"); \
|
92
|
+
} \
|
93
|
+
} while(0)
|
94
|
+
|
95
|
+
#define evoasm_success_t evoasm_check_return bool
|
96
|
+
|
97
|
+
#define evoasm_error(type, code, ...) evoasm_error2(type, code, NULL, __VA_ARGS__)
|
98
|
+
|
99
|
+
#define evoasm_error2(type, code, data, ...) \
|
100
|
+
evoasm_error_set(&evoasm_last_error, (type), (code), (data),\
|
101
|
+
__FILE__, __LINE__, __VA_ARGS__)
|
102
|
+
|
103
|
+
#define evoasm_assert_not_reached() \
|
104
|
+
do { \
|
105
|
+
evoasm_log(EVOASM_LOG_LEVEL_FATAL, "error", "%s:%d should not be reached", __FILE__, __LINE__); \
|
106
|
+
abort(); \
|
107
|
+
} while(0)
|
108
|
+
|
@@ -1,12 +1,25 @@
|
|
1
|
-
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2016 Julian Aron Prenner <jap@polyadic.com>
|
3
|
+
*
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU Affero General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
2
17
|
|
3
18
|
#include <stdarg.h>
|
4
19
|
#include <stdio.h>
|
5
20
|
#include <string.h>
|
6
|
-
#include <stdint.h>
|
7
21
|
#include <stdlib.h>
|
8
22
|
#include <stdbool.h>
|
9
|
-
#include <alloca.h>
|
10
23
|
|
11
24
|
#ifdef _WIN32
|
12
25
|
#include <io.h>
|
@@ -18,10 +31,15 @@
|
|
18
31
|
#include "evoasm-log.h"
|
19
32
|
#include "evoasm-alloc.h"
|
20
33
|
|
21
|
-
|
22
|
-
FILE *
|
34
|
+
evoasm_log_level_t _evoasm_log_level = EVOASM_LOG_LEVEL_WARN;
|
35
|
+
FILE * _evoasm_log_file;
|
23
36
|
|
24
|
-
|
37
|
+
void
|
38
|
+
evoasm_set_log_level(evoasm_log_level_t log_level) {
|
39
|
+
_evoasm_log_level = log_level;
|
40
|
+
}
|
41
|
+
|
42
|
+
static const char *const log_levels[EVOASM_LOG_LEVEL_NONE] = {
|
25
43
|
"TRACE",
|
26
44
|
"DEBUG",
|
27
45
|
"INFO",
|
@@ -30,28 +48,28 @@ static const char *const log_levels[EVOASM_N_LOG_LEVELS] = {
|
|
30
48
|
"FATAL"
|
31
49
|
};
|
32
50
|
|
33
|
-
static const char *const log_colors[
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
51
|
+
static const char *const log_colors[EVOASM_LOG_LEVEL_NONE] = {
|
52
|
+
EVOASM_ANSI_CODE_BLACK,
|
53
|
+
EVOASM_ANSI_CODE_BLACK,
|
54
|
+
EVOASM_ANSI_CODE_GREEN,
|
55
|
+
EVOASM_ANSI_CODE_YELLOW,
|
56
|
+
EVOASM_ANSI_CODE_RED,
|
57
|
+
EVOASM_ANSI_CODE_RED,
|
40
58
|
};
|
41
59
|
|
42
60
|
|
43
61
|
void
|
44
|
-
evoasm_log(
|
62
|
+
evoasm_log(evoasm_log_level_t level, const char *tag, const char *format, ...)
|
45
63
|
{
|
46
|
-
if(level <
|
64
|
+
if(level < _evoasm_log_level) return;
|
47
65
|
|
48
66
|
va_list args;
|
49
67
|
|
50
68
|
static const char *prefix = "evoasm:";
|
51
69
|
static const char *sep1 = ":";
|
52
70
|
static const char *sep2 = ": ";
|
53
|
-
static const char *color_reset =
|
54
|
-
bool is_tty = isatty(fileno(
|
71
|
+
static const char *color_reset = EVOASM_ANSI_CODE_RESET;
|
72
|
+
bool is_tty = isatty(fileno(_evoasm_log_file)) != 0;
|
55
73
|
|
56
74
|
size_t prefix_len = strlen(prefix);
|
57
75
|
size_t color_len = is_tty ? strlen(log_colors[level]) : 0;
|
@@ -101,7 +119,7 @@ evoasm_log(evoasm_log_level level, const char *tag, const char *format, ...)
|
|
101
119
|
|
102
120
|
//fprintf(stderr, "printing '%s'\n", full_format);
|
103
121
|
va_start(args, format);
|
104
|
-
vfprintf(
|
122
|
+
vfprintf(_evoasm_log_file, full_format, args);
|
105
123
|
va_end(args);
|
106
124
|
}
|
107
125
|
|
@@ -0,0 +1,93 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2016 Julian Aron Prenner <jap@polyadic.com>
|
3
|
+
*
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU Affero General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#pragma once
|
19
|
+
|
20
|
+
#include <stdlib.h>
|
21
|
+
#include <stdio.h>
|
22
|
+
#include <stdint.h>
|
23
|
+
|
24
|
+
#include "evoasm-util.h"
|
25
|
+
|
26
|
+
typedef int evoasm_log_level_t;
|
27
|
+
#define EVOASM_LOG_LEVEL_TRACE 0
|
28
|
+
#define EVOASM_LOG_LEVEL_DEBUG 1
|
29
|
+
#define EVOASM_LOG_LEVEL_INFO 2
|
30
|
+
#define EVOASM_LOG_LEVEL_WARN 3
|
31
|
+
#define EVOASM_LOG_LEVEL_ERROR 4
|
32
|
+
#define EVOASM_LOG_LEVEL_FATAL 5
|
33
|
+
#define EVOASM_LOG_LEVEL_NONE 6
|
34
|
+
|
35
|
+
|
36
|
+
#define EVOASM_ANSI_CODE_BLACK "\x1b[30;1m"
|
37
|
+
#define EVOASM_ANSI_CODE_RED "\x1b[31;1m"
|
38
|
+
#define EVOASM_ANSI_CODE_GREEN "\x1b[32;1m"
|
39
|
+
#define EVOASM_ANSI_CODE_YELLOW "\x1b[33;1m"
|
40
|
+
#define EVOASM_ANSI_CODE_BLUE "\x1b[34;1m"
|
41
|
+
#define EVOASM_ANSI_CODE_MAGENTA "\x1b[35;1m"
|
42
|
+
#define EVOASM_ANSI_CODE_CYAN "\x1b[36;1m"
|
43
|
+
#define EVOASM_ANSI_CODE_WHITE "\x1b[37;1m"
|
44
|
+
#define EVOASM_ANSI_CODE_RESET "\x1b[0m"
|
45
|
+
|
46
|
+
#ifndef EVOASM_LOG_LEVEL
|
47
|
+
# define EVOASM_LOG_LEVEL EVOASM_LOG_LEVEL_INFO
|
48
|
+
#endif
|
49
|
+
|
50
|
+
extern evoasm_log_level_t _evoasm_log_level;
|
51
|
+
extern FILE * _evoasm_log_file;
|
52
|
+
|
53
|
+
#define EVOASM_DEF_LOG_TAG(tag) evoasm_used static const char *_evoasm_log_tag = tag;
|
54
|
+
#define EVOASM_LOG_TAG _evoasm_log_tag
|
55
|
+
|
56
|
+
void
|
57
|
+
evoasm_log(evoasm_log_level_t level, const char *tag, const char *format, ...) evoasm_printf(3, 4);
|
58
|
+
|
59
|
+
#if EVOASM_LOG_LEVEL <= EVOASM_LOG_LEVEL_TRACE
|
60
|
+
# define evoasm_log_trace(...) evoasm_log(EVOASM_LOG_LEVEL_TRACE, EVOASM_LOG_TAG, __VA_ARGS__)
|
61
|
+
#else
|
62
|
+
# define evoasm_log_trace(...)
|
63
|
+
#endif
|
64
|
+
|
65
|
+
#if EVOASM_LOG_LEVEL <= EVOASM_LOG_LEVEL_DEBUG
|
66
|
+
# define evoasm_log_debug(...) evoasm_log(EVOASM_LOG_LEVEL_DEBUG, EVOASM_LOG_TAG, __VA_ARGS__)
|
67
|
+
#else
|
68
|
+
# define evoasm_log_debug(...)
|
69
|
+
#endif
|
70
|
+
|
71
|
+
#if EVOASM_LOG_LEVEL <= EVOASM_LOG_LEVEL_INFO
|
72
|
+
# define evoasm_log_info(...) evoasm_log(EVOASM_LOG_LEVEL_INFO, EVOASM_LOG_TAG, __VA_ARGS__)
|
73
|
+
#else
|
74
|
+
# define evoasm_log_info(...)
|
75
|
+
#endif
|
76
|
+
|
77
|
+
#if EVOASM_LOG_LEVEL <= EVOASM_LOG_LEVEL_WARN
|
78
|
+
# define evoasm_log_warn(...) evoasm_log(EVOASM_LOG_LEVEL_WARN, EVOASM_LOG_TAG, __VA_ARGS__)
|
79
|
+
#else
|
80
|
+
# define evoasm_log_warn(...)
|
81
|
+
#endif
|
82
|
+
|
83
|
+
#if EVOASM_LOG_LEVEL <= EVOASM_LOG_LEVEL_ERROR
|
84
|
+
# define evoasm_log_error(...) evoasm_log(EVOASM_LOG_LEVEL_ERROR, EVOASM_LOG_TAG, __VA_ARGS__)
|
85
|
+
#else
|
86
|
+
# define evoasm_log_error(...)
|
87
|
+
#endif
|
88
|
+
|
89
|
+
#if EVOASM_LOG_LEVEL <= EVOASM_LOG_LEVEL_FATAL
|
90
|
+
# define evoasm_log_fatal(...) evoasm_log(EVOASM_LOG_LEVEL_FATAL, EVOASM_LOG_TAG, __VA_ARGS__)
|
91
|
+
#else
|
92
|
+
# define evoasm_log_fatal(...)
|
93
|
+
#endif
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2016 Julian Aron Prenner <jap@polyadic.com>
|
3
|
+
*
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU Affero General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#include "evoasm-param.h"
|
19
|
+
|
20
|
+
EVOASM_DEF_GETTER(param, domain, evoasm_domain_t *)
|
21
|
+
EVOASM_DEF_GETTER(param, id, evoasm_param_id_t)
|
22
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2016 Julian Aron Prenner <jap@polyadic.com>
|
3
|
+
*
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU Affero General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#pragma once
|
19
|
+
|
20
|
+
#include <stdint.h>
|
21
|
+
#include "evoasm-bitmap.h"
|
22
|
+
#include "evoasm-domain.h"
|
23
|
+
|
24
|
+
#define EVOASM_PARAM_VAL_FORMAT PRId64
|
25
|
+
#define EVOASM_PARAM_FORMAT PRIu32
|
26
|
+
|
27
|
+
typedef int64_t evoasm_param_val_t;
|
28
|
+
typedef uint8_t evoasm_param_id_t;
|
29
|
+
|
30
|
+
typedef struct {
|
31
|
+
evoasm_param_id_t id;
|
32
|
+
evoasm_domain_t *domain;
|
33
|
+
} evoasm_param_t;
|
@@ -0,0 +1,192 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2016 Julian Aron Prenner <jap@polyadic.com>
|
3
|
+
*
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU Affero General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#include "evoasm-pop-params.h"
|
19
|
+
#include "evoasm-util.h"
|
20
|
+
|
21
|
+
EVOASM_DEF_ALLOC_FREE_FUNCS(pop_params)
|
22
|
+
|
23
|
+
EVOASM_DEF_ZERO_INIT_FUNC(pop_params)
|
24
|
+
|
25
|
+
#define EVOASM_POP_PARAMS_DEF_GETTER_SETTER(field, value_type, field_type) \
|
26
|
+
EVOASM_DEF_GETTER(pop_params, field, value_type) \
|
27
|
+
EVOASM_DEF_SETTER(pop_params, field, value_type, field_type)
|
28
|
+
|
29
|
+
EVOASM_POP_PARAMS_DEF_GETTER_SETTER(program_size, size_t, uint16_t)
|
30
|
+
|
31
|
+
EVOASM_POP_PARAMS_DEF_GETTER_SETTER(kernel_size, size_t, uint16_t)
|
32
|
+
|
33
|
+
EVOASM_POP_PARAMS_DEF_GETTER_SETTER(deme_size, size_t, uint16_t)
|
34
|
+
|
35
|
+
EVOASM_POP_PARAMS_DEF_GETTER_SETTER(n_params, size_t, uint8_t)
|
36
|
+
|
37
|
+
EVOASM_POP_PARAMS_DEF_GETTER_SETTER(n_demes, size_t, uint16_t)
|
38
|
+
|
39
|
+
EVOASM_POP_PARAMS_DEF_GETTER_SETTER(mut_rate, float, float)
|
40
|
+
|
41
|
+
EVOASM_POP_PARAMS_DEF_GETTER_SETTER(recur_limit, size_t, uint32_t)
|
42
|
+
|
43
|
+
EVOASM_POP_PARAMS_DEF_GETTER_SETTER(n_insts, size_t, uint16_t)
|
44
|
+
|
45
|
+
EVOASM_POP_PARAMS_DEF_GETTER_SETTER(program_input, evoasm_program_io_t *, evoasm_program_io_t *)
|
46
|
+
|
47
|
+
EVOASM_POP_PARAMS_DEF_GETTER_SETTER(program_output, evoasm_program_io_t *, evoasm_program_io_t *)
|
48
|
+
|
49
|
+
static evoasm_domain_t **
|
50
|
+
evoasm_pop_params_find_domain(evoasm_pop_params_t *pop_params, evoasm_param_id_t param_id) {
|
51
|
+
for(size_t i = 0; i < pop_params->n_params; i++) {
|
52
|
+
if(pop_params->param_ids[i] == param_id) {
|
53
|
+
return &pop_params->domains[i];
|
54
|
+
}
|
55
|
+
}
|
56
|
+
return NULL;
|
57
|
+
}
|
58
|
+
|
59
|
+
bool
|
60
|
+
evoasm_pop_params_set_domain(evoasm_pop_params_t *pop_params, evoasm_param_id_t param_id, evoasm_domain_t *domain) {
|
61
|
+
evoasm_domain_t **domain_ptr = evoasm_pop_params_find_domain(pop_params, param_id);
|
62
|
+
if(domain_ptr) {
|
63
|
+
*domain_ptr = domain;
|
64
|
+
return true;
|
65
|
+
} else {
|
66
|
+
return false;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
evoasm_domain_t *
|
71
|
+
evoasm_pop_params_get_domain(evoasm_pop_params_t *pop_params, evoasm_param_id_t param_id) {
|
72
|
+
evoasm_domain_t **domain_ptr = evoasm_pop_params_find_domain(pop_params, param_id);
|
73
|
+
if(domain_ptr) {
|
74
|
+
return *domain_ptr;
|
75
|
+
} else {
|
76
|
+
return NULL;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
evoasm_param_id_t
|
81
|
+
evoasm_pop_params_get_param(evoasm_pop_params_t *pop_params, size_t idx) {
|
82
|
+
return pop_params->param_ids[idx];
|
83
|
+
}
|
84
|
+
|
85
|
+
void
|
86
|
+
evoasm_pop_params_set_param(evoasm_pop_params_t *pop_params, size_t idx, evoasm_param_id_t param) {
|
87
|
+
pop_params->param_ids[idx] = param;
|
88
|
+
}
|
89
|
+
|
90
|
+
uint64_t
|
91
|
+
evoasm_pop_params_get_seed(evoasm_pop_params_t *pop_params, size_t idx) {
|
92
|
+
return pop_params->seed.data[idx];
|
93
|
+
}
|
94
|
+
|
95
|
+
void
|
96
|
+
evoasm_pop_params_set_seed(evoasm_pop_params_t *pop_params, size_t idx, uint64_t seed) {
|
97
|
+
pop_params->seed.data[idx] = seed;
|
98
|
+
}
|
99
|
+
|
100
|
+
void
|
101
|
+
evoasm_pop_params_destroy(evoasm_pop_params_t *pop_params) {
|
102
|
+
}
|
103
|
+
|
104
|
+
void
|
105
|
+
evoasm_pop_params_set_inst(evoasm_pop_params_t *pop_params, size_t index, evoasm_inst_id_t inst_id) {
|
106
|
+
pop_params->inst_ids[index] = inst_id;
|
107
|
+
}
|
108
|
+
|
109
|
+
evoasm_inst_id_t
|
110
|
+
evoasm_pop_params_get_inst(evoasm_pop_params_t *pop_params, size_t idx) {
|
111
|
+
return pop_params->inst_ids[idx];
|
112
|
+
}
|
113
|
+
|
114
|
+
bool
|
115
|
+
evoasm_pop_params_validate(evoasm_pop_params_t *pop_params) {
|
116
|
+
if(pop_params->n_params == 0) {
|
117
|
+
evoasm_error(EVOASM_ERROR_TYPE_POP_PARAMS, EVOASM_POP_PARAMS_ERROR_CODE_INVALID,
|
118
|
+
"No parameters given");
|
119
|
+
goto fail;
|
120
|
+
}
|
121
|
+
|
122
|
+
if(pop_params->deme_size == 0) {
|
123
|
+
evoasm_error(EVOASM_ERROR_TYPE_POP_PARAMS, EVOASM_POP_PARAMS_ERROR_CODE_INVALID,
|
124
|
+
"Deme size cannot be zero");
|
125
|
+
goto fail;
|
126
|
+
}
|
127
|
+
|
128
|
+
if(pop_params->n_demes == 0) {
|
129
|
+
evoasm_error(EVOASM_ERROR_TYPE_POP_PARAMS, EVOASM_POP_PARAMS_ERROR_CODE_INVALID,
|
130
|
+
"Number of demes cannot be zero");
|
131
|
+
goto fail;
|
132
|
+
}
|
133
|
+
|
134
|
+
if(pop_params->mut_rate < 0.0 || pop_params->mut_rate > 1.0) {
|
135
|
+
evoasm_error(EVOASM_ERROR_TYPE_POP_PARAMS, EVOASM_POP_PARAMS_ERROR_CODE_INVALID,
|
136
|
+
"Mutatin rate must be in the range [0..1]");
|
137
|
+
goto fail;
|
138
|
+
}
|
139
|
+
|
140
|
+
if(pop_params->kernel_size > EVOASM_KERNEL_MAX_SIZE) {
|
141
|
+
evoasm_error(EVOASM_ERROR_TYPE_POP_PARAMS, EVOASM_POP_PARAMS_ERROR_CODE_INVALID,
|
142
|
+
"Program size cannot exceed %d", EVOASM_PROGRAM_MAX_SIZE);
|
143
|
+
goto fail;
|
144
|
+
}
|
145
|
+
|
146
|
+
if(pop_params->kernel_size == 0) {
|
147
|
+
evoasm_error(EVOASM_ERROR_TYPE_POP_PARAMS, EVOASM_POP_PARAMS_ERROR_CODE_INVALID,
|
148
|
+
"Kernel size cannot be zero");
|
149
|
+
goto fail;
|
150
|
+
}
|
151
|
+
|
152
|
+
if(pop_params->program_size > EVOASM_PROGRAM_MAX_SIZE) {
|
153
|
+
evoasm_error(EVOASM_ERROR_TYPE_POP_PARAMS, EVOASM_POP_PARAMS_ERROR_CODE_INVALID,
|
154
|
+
"Program size cannot exceed %d", EVOASM_PROGRAM_MAX_SIZE);
|
155
|
+
goto fail;
|
156
|
+
}
|
157
|
+
|
158
|
+
if(pop_params->program_size == 0) {
|
159
|
+
evoasm_error(EVOASM_ERROR_TYPE_POP_PARAMS, EVOASM_POP_PARAMS_ERROR_CODE_INVALID,
|
160
|
+
"Program size cannot be zero");
|
161
|
+
goto fail;
|
162
|
+
}
|
163
|
+
|
164
|
+
if(pop_params->n_insts == 0) {
|
165
|
+
evoasm_error(EVOASM_ERROR_TYPE_POP_PARAMS, EVOASM_POP_PARAMS_ERROR_CODE_INVALID,
|
166
|
+
"No instructions given");
|
167
|
+
goto fail;
|
168
|
+
}
|
169
|
+
|
170
|
+
if(pop_params->program_input == NULL || pop_params->program_input->len == 0) {
|
171
|
+
evoasm_error(EVOASM_ERROR_TYPE_POP_PARAMS, EVOASM_POP_PARAMS_ERROR_CODE_INVALID,
|
172
|
+
"No input values given");
|
173
|
+
goto fail;
|
174
|
+
}
|
175
|
+
|
176
|
+
if(pop_params->program_output == NULL || pop_params->program_output->len == 0) {
|
177
|
+
evoasm_error(EVOASM_ERROR_TYPE_POP_PARAMS, EVOASM_POP_PARAMS_ERROR_CODE_INVALID,
|
178
|
+
"No output values given");
|
179
|
+
goto fail;
|
180
|
+
}
|
181
|
+
|
182
|
+
// if(pop_params->n_demes == 0) {
|
183
|
+
// evoasm_error(EVOASM_ERROR_TYPE_ARG, EVOASM_ERROR_CODE_NONE,
|
184
|
+
// NULL, "Invalid number of demes");
|
185
|
+
// goto fail;
|
186
|
+
// }
|
187
|
+
|
188
|
+
return true;
|
189
|
+
|
190
|
+
fail:
|
191
|
+
return false;
|
192
|
+
}
|