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