[404] | 1 | #include <string>
|
---|
| 2 | #include <vector>
|
---|
| 3 | #include <fstream>
|
---|
[274] | 4 |
|
---|
[404] | 5 | #include <windows.h>
|
---|
| 6 | #include <stdio.h>
|
---|
| 7 | #include <string.h>
|
---|
| 8 | #include <math.h>
|
---|
| 9 | #include <commctrl.h>
|
---|
| 10 | #include <time.h>
|
---|
| 11 | #include <limits.h>
|
---|
| 12 | #include <shlobj.h>
|
---|
| 13 |
|
---|
| 14 | //boost libraries
|
---|
| 15 | #include <boost/foreach.hpp>
|
---|
| 16 |
|
---|
| 17 | #include <jenga/include/common/String.h>
|
---|
| 18 |
|
---|
| 19 | #include "../common.h"
|
---|
[461] | 20 | #include "../BasicFixed.h"
|
---|
[404] | 21 |
|
---|
| 22 |
|
---|
| 23 | // ObjectModuleの内容をXmlで生成する場合はこの行を有効にする
|
---|
| 24 | //#define OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 28 | #include <boost/archive/xml_oarchive.hpp>
|
---|
| 29 | #include <boost/archive/xml_iarchive.hpp>
|
---|
| 30 | #else
|
---|
| 31 | #include <boost/archive/binary_oarchive.hpp>
|
---|
| 32 | #include <boost/archive/binary_iarchive.hpp>
|
---|
| 33 | #endif
|
---|
| 34 | #include <boost/serialization/string.hpp>
|
---|
| 35 | #include <boost/serialization/access.hpp>
|
---|
| 36 | #include <boost/serialization/level.hpp>
|
---|
| 37 | #include <boost/serialization/vector.hpp>
|
---|
| 38 | #include <boost/serialization/map.hpp>
|
---|
| 39 | #include <boost/serialization/version.hpp>
|
---|
| 40 | #include <boost/serialization/is_abstract.hpp>
|
---|
| 41 |
|
---|
| 42 | #include <BoostSerializationSupport.h>
|
---|
| 43 | #include <Hashmap.h>
|
---|
[274] | 44 | #include <Compiler.h>
|
---|
| 45 |
|
---|
[279] | 46 |
|
---|
[274] | 47 | void ObjectModule::StaticLink( ObjectModule &objectModule )
|
---|
| 48 | {
|
---|
[280] | 49 | long dataSectionBaseOffset = dataTable.GetSize();
|
---|
[308] | 50 | int sourceIndexBase = (int)sources.size();
|
---|
[280] | 51 |
|
---|
[274] | 52 | // メタ情報を結合
|
---|
[280] | 53 | meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase );
|
---|
[274] | 54 |
|
---|
[395] | 55 | // グローバル ネイティブコードを結合
|
---|
[280] | 56 | objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
---|
| 57 | objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
|
---|
[287] | 58 | globalNativeCode.PutEx( objectModule.globalNativeCode );
|
---|
[276] | 59 |
|
---|
[274] | 60 | // データテーブルを結合
|
---|
[355] | 61 | objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
---|
[274] | 62 | dataTable.Add( objectModule.dataTable );
|
---|
[280] | 63 |
|
---|
| 64 | // ソースコードを結合
|
---|
| 65 | BOOST_FOREACH( const BasicSource &source, objectModule.sources )
|
---|
| 66 | {
|
---|
| 67 | this->sources.push_back( source );
|
---|
| 68 | }
|
---|
[282] | 69 |
|
---|
| 70 | // TODO: basbufがいらなくなったら消す
|
---|
| 71 | extern char *basbuf;
|
---|
| 72 | basbuf = this->sources[0].GetBuffer();
|
---|
[274] | 73 | }
|
---|
[279] | 74 |
|
---|
| 75 | bool ObjectModule::Read( const std::string &filePath )
|
---|
| 76 | {
|
---|
[404] | 77 | // XMLとして読み込む
|
---|
| 78 | bool isSuccessful = false;
|
---|
| 79 |
|
---|
| 80 | try{
|
---|
| 81 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 82 | std::ifstream ifs( filePath.c_str() );
|
---|
| 83 | boost::archive::xml_iarchive ia(ifs);
|
---|
| 84 | #else
|
---|
| 85 | std::ifstream ifs( filePath.c_str(), ios::in | ios::binary );
|
---|
| 86 | boost::archive::binary_iarchive ia(ifs);
|
---|
| 87 | #endif
|
---|
| 88 |
|
---|
| 89 | // ファイルから読込
|
---|
| 90 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 91 |
|
---|
| 92 | isSuccessful = true;
|
---|
| 93 | }
|
---|
| 94 | catch( boost::archive::archive_exception e )
|
---|
[279] | 95 | {
|
---|
[404] | 96 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 97 | }
|
---|
[404] | 98 | catch(...){
|
---|
| 99 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | if( !isSuccessful )
|
---|
| 103 | {
|
---|
| 104 | return false;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | return true;
|
---|
[279] | 108 | }
|
---|
| 109 | bool ObjectModule::Write( const std::string &filePath ) const
|
---|
| 110 | {
|
---|
[404] | 111 | bool isSuccessful = false;
|
---|
| 112 |
|
---|
| 113 | try{
|
---|
| 114 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 115 | std::ofstream ofs( filePath.c_str() );
|
---|
| 116 | boost::archive::xml_oarchive oa(ofs);
|
---|
| 117 | #else
|
---|
| 118 | std::ofstream ofs( filePath.c_str(), ios::out | ios::binary );
|
---|
| 119 | boost::archive::binary_oarchive oa(ofs);
|
---|
| 120 | #endif
|
---|
| 121 |
|
---|
| 122 | // ファイルに書き出し
|
---|
| 123 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 124 |
|
---|
| 125 | isSuccessful = true;
|
---|
| 126 | }
|
---|
| 127 | catch( boost::archive::archive_exception e )
|
---|
[279] | 128 | {
|
---|
[404] | 129 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 130 | }
|
---|
[404] | 131 | catch(...){
|
---|
| 132 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | if( !isSuccessful )
|
---|
| 136 | {
|
---|
| 137 | return false;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | return true;
|
---|
[279] | 141 | }
|
---|
| 142 | bool ObjectModule::ReadString( const std::string &str )
|
---|
| 143 | {
|
---|
[404] | 144 | bool isSuccessful = false;
|
---|
| 145 |
|
---|
| 146 | // 入力アーカイブの作成
|
---|
| 147 |
|
---|
| 148 | try{
|
---|
| 149 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 150 | std::istringstream iss( str );
|
---|
| 151 | boost::archive::xml_iarchive ia(iss);
|
---|
| 152 | #else
|
---|
| 153 | std::istringstream iss( str, ios::in | ios::binary );
|
---|
| 154 | boost::archive::binary_iarchive ia(iss);
|
---|
| 155 | #endif
|
---|
| 156 |
|
---|
| 157 | // 文字列ストリームから読込
|
---|
| 158 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 159 |
|
---|
| 160 | isSuccessful = true;
|
---|
| 161 | }
|
---|
| 162 | catch( boost::archive::archive_exception e )
|
---|
[279] | 163 | {
|
---|
[404] | 164 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 165 | }
|
---|
[404] | 166 | catch(...){
|
---|
| 167 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | if( !isSuccessful )
|
---|
| 171 | {
|
---|
| 172 | return false;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | return true;
|
---|
[279] | 176 | }
|
---|
| 177 | bool ObjectModule::WriteString( std::string &str ) const
|
---|
| 178 | {
|
---|
[404] | 179 | // 出力アーカイブの作成
|
---|
| 180 |
|
---|
| 181 | bool isSuccessful = false;
|
---|
| 182 | try{
|
---|
| 183 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 184 | std::ostringstream oss;
|
---|
| 185 | boost::archive::xml_oarchive oa(oss);
|
---|
| 186 | #else
|
---|
| 187 | std::ostringstream oss( "", ios::out | ios::binary );
|
---|
| 188 | boost::archive::binary_oarchive oa(oss);
|
---|
| 189 | #endif
|
---|
| 190 |
|
---|
| 191 | // 文字列ストリームに書き出し
|
---|
| 192 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 193 |
|
---|
| 194 | str = oss.str();
|
---|
| 195 |
|
---|
| 196 | isSuccessful = true;
|
---|
| 197 | }
|
---|
| 198 | catch( boost::archive::archive_exception e )
|
---|
[279] | 199 | {
|
---|
[404] | 200 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 201 | }
|
---|
[404] | 202 | catch(...){
|
---|
| 203 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | return isSuccessful;
|
---|
[279] | 207 | }
|
---|