-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbf_compile_and_go.h
54 lines (45 loc) · 1.63 KB
/
bf_compile_and_go.h
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
// Copyright 2014 Brian Quinlan
// See "LICENSE" file for details.
//
// Implements a BrainfuckRunner that compiles the complete source into amd64
// machine code. For a description of the team "compile and go", see:
// http://en.wikipedia.org/wiki/Compile_and_go_system
#ifndef BF_COMPILE_AND_GO_H_
#define BF_COMPILE_AND_GO_H_
#include <map>
#include <string>
#include "bf_runner.h"
using std::string;
using std::map;
class BrainfuckCompileAndGo : public BrainfuckRunner {
public:
BrainfuckCompileAndGo();
virtual bool init(string::const_iterator start,
string::const_iterator end);
virtual void* run(BrainfuckReader reader,
void* reader_arg,
BrainfuckWriter writer,
void* writer_arg,
void* memory);
virtual ~BrainfuckCompileAndGo();
private:
int executable_size_;
void* executable_;
int exit_offset_;
void add_jne_to_exit(string* code);
void add_jl_to_exit(string* code);
void add_jmp_to_offset(int offset, string* code);
void add_jmp_to_exit(string* code);
void emit_offset_table(map<int8_t, uint8_t>* offset_to_change,
int8_t* offset,
string *code);
bool generate_sequence_code(string::const_iterator start,
string::const_iterator end,
string* code);
bool generate_loop_code(string::const_iterator start,
string::const_iterator end,
string* code);
void generate_read_code(string* code);
void generate_write_code(string* code);
};
#endif // BF_COMPILE_AND_GO_H_