-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpstcode.h
65 lines (51 loc) · 1.54 KB
/
pstcode.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
55
56
57
58
59
60
61
62
63
64
65
#ifndef PSTCODE_H_INCLUDED
#define PSTCODE_H_INCLUDED
#include <cstdio>
#include <string>
#include <list>
#include <vector>
#include "symbtable.h"
#include "pstack/apm.h"
// Temporaried used by Code::add_*()
#define ADDR_TEMP (STORAGE - 2)
class PstackCode
{
public:
PstackCode()
: code(), strings()
{}
PstackCode(const PstackCode &ps)
: code(ps.code), strings(ps.strings)
{}
// Add an instruction or (non-relocatable) operand
void add(int op);
// Generate code to duplicate the top element of the stack.
void add_dup();
// Generate code to begin a program.
void begin_prog();
// Generate code for standard functions.
void prolog(SymbolTable &fvsyms);
// Generate code to end a program.
void end_prog();
// Write the code to a file.
bool write(std::FILE *file, bool binary = true) const;
// Return a copy of the code vector.
std::vector<int> codevec() const;
// Return the current position.
int pos(void) const;
// Return a reference to the instruction/operand at the specified
// position.
int &at(int p);
// Or the value of that instruction/operand.
int at(int p) const;
// Add a string constant to be appended to the completed program.
void add_string(const std::string &value, int pos);
private:
// Sequence of instructions and operands. Supports integers only;
// need a vector of unions to handle doubles.
std::vector<int> code;
// Strings and the code addresses that will be backpatched to contain
// those strings' addresses.
std::list<std::pair<std::string, int> > strings;
};
#endif // PSTCODE_H_INCLUDED