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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#ifndef COMPILER_GENERATOR_H_INCLUDED
#define COMPILER_GENERATOR_H_INCLUDED
#include <cassert>
#include <string>
#include <vector>
#include <components/interpreter/types.hpp>
namespace Compiler
{
class Literals;
namespace Generator
{
typedef std::vector<Interpreter::Type_Code> CodeContainer;
inline Interpreter::Type_Code segment0(unsigned int c, unsigned int arg0)
{
assert(c < 64);
return (c << 24) | (arg0 & 0xffffff);
}
inline Interpreter::Type_Code segment1(unsigned int c, unsigned int arg0, unsigned int arg1)
{
assert(c < 64);
return 0x40000000 | (c << 24) | ((arg0 & 0xfff) << 12) | (arg1 & 0xfff);
}
inline Interpreter::Type_Code segment2(unsigned int c, unsigned int arg0)
{
assert(c < 1024);
return 0x80000000 | (c << 20) | (arg0 & 0xfffff);
}
inline Interpreter::Type_Code segment3(unsigned int c, unsigned int arg0)
{
assert(c < 262144);
return 0xc0000000 | (c << 8) | (arg0 & 0xff);
}
inline Interpreter::Type_Code segment4(unsigned int c, unsigned int arg0, unsigned int arg1)
{
assert(c < 1024);
return 0xc4000000 | (c << 16) | ((arg0 & 0xff) << 8) | (arg1 & 0xff);
}
inline Interpreter::Type_Code segment5(unsigned int c)
{
assert(c < 67108864);
return 0xc8000000 | c;
}
void pushInt(CodeContainer& code, Literals& literals, int value);
void pushFloat(CodeContainer& code, Literals& literals, float value);
void pushString(CodeContainer& code, Literals& literals, const std::string& value);
void assignToLocal(
CodeContainer& code, char localType, int localIndex, const CodeContainer& value, char valueType);
void negate(CodeContainer& code, char valueType);
void add(CodeContainer& code, char valueType1, char valueType2);
void sub(CodeContainer& code, char valueType1, char valueType2);
void mul(CodeContainer& code, char valueType1, char valueType2);
void div(CodeContainer& code, char valueType1, char valueType2);
void convert(CodeContainer& code, char fromType, char toType);
void exit(CodeContainer& code);
void message(CodeContainer& code, Literals& literals, const std::string& message, int buttons);
void report(CodeContainer& code, Literals& literals, const std::string& message);
void fetchLocal(CodeContainer& code, char localType, int localIndex);
void jump(CodeContainer& code, int offset);
void jumpOnZero(CodeContainer& code, int offset);
void compare(CodeContainer& code, char op, char valueType1, char valueType2);
void assignToGlobal(CodeContainer& code, Literals& literals, char localType, const std::string& name,
const CodeContainer& value, char valueType);
void fetchGlobal(CodeContainer& code, Literals& literals, char localType, const std::string& name);
void assignToMember(CodeContainer& code, Literals& literals, char memberType, const std::string& name,
const std::string& id, const CodeContainer& value, char valueType, bool global);
///< \param global Member of a global script instead of a script of a reference.
void fetchMember(CodeContainer& code, Literals& literals, char memberType, const std::string& name,
const std::string& id, bool global);
///< \param global Member of a global script instead of a script of a reference.
}
}
#endif
|