00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef Bytecode_h
00025 #define Bytecode_h
00026
00027 #include "ycp/YCPValue.h"
00028 #include "ycp/YCode.h"
00029 #include "ycp/YStatement.h"
00030 #include "ycp/YBlock.h"
00031 #include "ycp/Type.h"
00032
00033 class Y2Namespace;
00034
00035 #include <iosfwd>
00036 #include <string>
00037 #include <map>
00038
00039 #include <fstream>
00040
00041 class bytecodeistream : public std::ifstream
00042 {
00043 int m_major, m_minor, m_release;
00044 public:
00045 bytecodeistream (string filename);
00046 bool isVersion (int major, int minor, int revision);
00047 bool isVersionAtMost (int major, int minor, int revision);
00048
00049 int major () const { return m_major; }
00050 int minor () const { return m_minor; }
00051 int release () const { return m_release; }
00052 };
00053
00054 class Bytecode {
00055 static int m_namespace_nesting_level;
00056 static int m_namespace_nesting_array_size;
00057 static int m_namespace_tare_level;
00058 typedef struct { const Y2Namespace *name_space; bool with_xrefs; } namespaceentry_t;
00059 static namespaceentry_t *m_namespace_nesting_array;
00060 static map<string, YBlockPtr>* m_bytecodeCache;
00061
00062 public:
00063
00064 static std::ostream & writeBool (std::ostream & streamref, bool value);
00065 static bool readBool (bytecodeistream & streamref);
00066
00067
00068 static std::ostream & writeString (std::ostream & streamref, const std::string & stringref);
00069 static bool readString (bytecodeistream & streamref, std::string & stringref);
00070
00071
00072 static std::ostream & writeUstring (std::ostream & streamref, const Ustring ustringref);
00073 static Ustring readUstring (bytecodeistream & streamref);
00074
00075
00076 static std::ostream & writeCharp (std::ostream & streamref, const char * charp);
00077 static char * readCharp (bytecodeistream & streamref);
00078
00079
00080 static std::ostream & writeBytep (std::ostream & streamref, const unsigned char * bytep, unsigned int len);
00081 static unsigned char * readBytep (bytecodeistream & streamref);
00082
00083
00084 static std::ostream & writeInt32 (std::ostream & str, const u_int32_t value);
00085 static u_int32_t readInt32 (bytecodeistream & str);
00086
00087
00088 static std::ostream & writeType (std::ostream & str, constTypePtr type);
00089 static TypePtr readType (bytecodeistream & str);
00090
00091
00092 static std::ostream & writeValue (std::ostream & str, const YCPValue value);
00093 static YCPValue readValue (bytecodeistream & str);
00094
00095
00096 static std::ostream & writeYCodelist (std::ostream & str, const ycodelist_t *codelist);
00097 static bool readYCodelist (bytecodeistream & str, ycodelist_t **anchor);
00098
00099
00100
00101
00102 static void namespaceInit ();
00103
00104 static int namespaceId (const Y2Namespace *name_space);
00105
00106 static const Y2Namespace *namespacePtr (int namespace_id);
00107
00108
00109 static int pushNamespace (const Y2Namespace *name_space, bool with_xrefs = false);
00110
00111
00112 static int popNamespace (const Y2Namespace *name_space);
00113
00114
00115 static void popUptoNamespace (const Y2Namespace *name_space);
00116
00117
00118
00119 static int tareStack ();
00120 static void untareStack (int tare_id);
00121
00122
00123
00124
00125
00126 static std::ostream &writeEntry (std::ostream & str, const SymbolEntryPtr entry);
00127 static SymbolEntryPtr readEntry (bytecodeistream & str);
00128
00129
00130
00131
00132
00133 static YCodePtr readCode (bytecodeistream & str);
00134
00135
00136
00137
00138
00139
00140 static YBlockPtr readModule (const string & mname);
00141
00142
00143 static YCodePtr readFile (const string & filename);
00144
00145
00146 static bool writeFile (const YCodePtr code, const string & filename);
00147 };
00148
00149 #endif // Bytecode_h