cfg_kernel_cfg.cpp

00001 /*
00002  *  TOPPERS/FDMP Kernel
00003  *      Toyohashi Open Platform for Embedded Real-Time Systems/
00004  *      Function Distributed Multiprocessor Kernel
00005  *
00006  *  Copyright (C) 2005 by Takagi Nobuhisa
00007  * 
00008  *  上記著作権者は,以下の (1)〜(4) の条件か,Free Software Foundation 
00009  *  によって公表されている GNU General Public License の Version 2 に記
00010  *  述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
00011  *  を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
00012  *  利用と呼ぶ)することを無償で許諾する.
00013  *  (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
00014  *      権表示,この利用条件および下記の無保証規定が,そのままの形でソー
00015  *      スコード中に含まれていること.
00016  *  (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
00017  *      用できる形で再配布する場合には,再配布に伴うドキュメント(利用
00018  *      者マニュアルなど)に,上記の著作権表示,この利用条件および下記
00019  *      の無保証規定を掲載すること.
00020  *  (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
00021  *      用できない形で再配布する場合には,次のいずれかの条件を満たすこ
00022  *      と.
00023  *    (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
00024  *        作権表示,この利用条件および下記の無保証規定を掲載すること.
00025  *    (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
00026  *        報告すること.
00027  *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
00028  *      害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
00029  * 
00030  *  本ソフトウェアは,無保証で提供されているものである.上記著作権者お
00031  *  よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
00032  *  含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
00033  *  接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
00034  * 
00035  */
00036 
00037 /*
00038  *  toppers/itron/cfg_kernel_cfg.cpp
00039  */
00040 #include "toppers/itron/cfg_kernel_cfg.hpp"
00041 #include "toppers/itron/cfg_factory.hpp"
00042 #include "toppers/itron/cfg_contents.hpp"
00043 #include <ostream>
00044 #include <boost/format.hpp>
00045 
00046 namespace toppers
00047 {
00048   namespace itron
00049   {
00050 
00057     cfg_kernel_cfg::cfg_kernel_cfg( const std::string& file, const std::string& id_file, long prid )
00058       : kernel_cfg( file, id_file ), prid_( prid )
00059     {
00060     }
00061 
00062     void cfg_kernel_cfg::do_load( const boost::shared_ptr<cfg_contents>& contents )
00063     {
00064       typedef cfg_contents::group_container::const_iterator group_iterator;
00065       const cfg_contents::group_container& container = contents->groups();
00066 
00067       for ( group_iterator giter( contents->groups().begin() ), glast( contents->groups().end() ); giter != glast; ++giter )
00068       {
00069         typedef cfg_group::object_container::const_iterator object_iterator;
00070         const boost::shared_ptr<cfg_group> group( *giter );
00071         for ( object_iterator oiter( group->objects().begin() ), olast( group->objects().end() ); oiter != olast; ++oiter )
00072         {
00073           insert_inib( ( *oiter )->get_object_type(), ( *oiter )->get_inib() );
00074         }
00075       }
00076     }
00077 
00078     void cfg_kernel_cfg::do_body( std::ostream& ostr ) const
00079     {
00080       boost::shared_ptr<cmdline::option_array> options( cfg_factory::global()->options() );
00081       std::string lang;
00082       bool c_plus_plus = false;
00083       if ( options->find( "-x", lang ) && lang == "c++" )
00084       {
00085         c_plus_plus = true;
00086       }
00087 
00088       if ( c_plus_plus )
00089       {
00090         ostr << "extern \"C\" {\n"
00091                 "\n";
00092       }
00093 
00094       do_include_headers( ostr );
00095       do_define_macros( ostr );
00096       do_check_version( ostr );
00097       do_define_objects( ostr );
00098       do_initialize_object( ostr );
00099       do_initialize_other( ostr );
00100       do_check_magic_number( ostr );
00101 
00102       if ( c_plus_plus )
00103       {
00104         ostr << "}\t// extern \"C\"\n"
00105                 "\n";
00106       }
00107     }
00108 
00109     void cfg_kernel_cfg::do_depend() const
00110     {
00111     }
00112 
00113     void cfg_kernel_cfg::do_include_headers( std::ostream& ostr ) const
00114     {
00115       boost::shared_ptr<cmdline::option_array> options( cfg_factory::global()->options() );
00116       if ( options->find( "-il" ) )
00117       {
00118         ostr << "#include <kernel_cfg.h>\n";
00119       }
00120       else
00121       {
00122         ostr << "#include \"kernel_cfg.h\"\n";
00123       }
00124       ostr << boost::format( "#include \"%1%\"\n" ) % id_file();
00125       ostr << '\n';
00126     }
00127 
00128     void cfg_kernel_cfg::do_define_macros( std::ostream& ostr ) const
00129     {
00130       ostr << "#define CFG_INTHDR_ENTRY(inthdr) INTHDR_ENTRY(inthdr)\n";
00131       ostr << "#define CFG_EXCHDR_ENTRY(exchdr) EXCHDR_ENTRY(exchdr)\n";
00132       ostr << "#define CFG_INT_ENTRY(inthdr) INT_ENTRY(inthdr)\n";
00133       ostr << "#define CFG_EXC_ENTRY(exchdr) EXC_ENTRY(exchdr)\n";
00134       ostr << '\n';
00135 
00136       boost::shared_ptr<cmdline::option_array> options( cfg_factory::global()->options() );
00137       if ( !options->find( "-z" ) )
00138       {
00139         ostr << "#ifndef __EMPTY_LABEL\n";
00140         ostr << "#define __EMPTY_LABEL(x,y) x y[0]\n";
00141         ostr << "#endif\n";
00142         ostr << '\n';
00143       }
00144       if ( options->find( "-c" ) )
00145       {
00146         ostr << "#define __CFG_ASSERT(expr) __CFG_ASSERT2(expr, __LINE__)\n";
00147         ostr << "#define __CFG_ASSERT2(expr, line) extern void __cfg_assert##line(int __cfg_assertion_failed[(expr)?1:-1])\n";
00148         ostr << '\n';
00149       }
00150     }
00151 
00152     void cfg_kernel_cfg::do_define_objects( std::ostream& ostr ) const
00153     {
00154       typedef factory::kernel_cfg_generator_type generator_type;
00155       const boost::shared_ptr<std::vector<generator_type> > generators( cfg_factory::global()->create_kernel_cfg_generators() );
00156       std::vector<generator_type>::const_iterator iter;
00157       const std::vector<generator_type>::const_iterator last( generators->end() );
00158 
00159       for ( iter = generators->begin(); iter != last; ++iter )
00160       {
00161         ( *iter )( *this, ostr );
00162       }
00163     }
00164 
00165     void cfg_kernel_cfg::do_initialize_object( std::ostream& ostr ) const
00166     {
00167       ostr << "void\n";
00168       ostr << "_kernel_object_initialize(void)\n";
00169       ostr << "{\n";
00170 
00171       const boost::shared_ptr<std::vector<std::string> > obj_names( cfg_factory::global()->get_kernel_object_names() );
00172 
00173       typedef std::vector<std::string>::const_iterator const_iterator;
00174       for ( const_iterator iter( obj_names->begin() ), last( obj_names->end() ); iter != last; ++iter )
00175       {
00176         const inib_array* pinibs = get_inib_array( *iter );
00177         if ( pinibs != 0 && !pinibs->empty() )
00178         {
00179           // 割り込みおよびCPU例外も対象とするため、IDが0の場合も有効とみなす。
00180           if ( pinibs->front()->id() >= 0 )
00181           {
00182             ostr << "\t_kernel_" << *iter << "_initialize();\n";
00183           }
00184         }
00185       }
00186       ostr << "}\n";
00187       ostr << '\n';
00188     }
00189 
00190     void cfg_kernel_cfg::do_initialize_other( std::ostream& ostr ) const
00191     {
00192       cfg_factory::extra_initializer_type einit = cfg_factory::global()->get_extra_initializer();
00193       ( *einit )( *this, ostr );
00194     }
00195 
00196     void cfg_kernel_cfg::do_check_version( std::ostream& ostr ) const
00197     {
00198       if ( prid_ >= 0 )
00199       {
00200         ostr << boost::format( "#if TKERNEL_PRID != %#04xu\n" ) % prid_;
00201         ostr << "#error \"cannot use this configuration file\"\n";
00202         ostr << "#endif\n";
00203         ostr << '\n';
00204       }
00205     }
00206 
00207     void cfg_kernel_cfg::do_check_magic_number( std::ostream& ostr ) const
00208     {
00209       boost::shared_ptr<cmdline::option_array> options( cfg_factory::global()->options() );
00210       if ( options->find( "-c" ) )
00211       {
00212 #if 0 // 旧コンフィギュレータとの互換性のために出力していた_checker_magic_numberを廃止
00213         ostr << "\t/* Variables for kernel checker */\n";
00214         ostr << "const UW _checker_magic_number = 0x01234567;\n";
00215 #endif
00216       }
00217     }
00218 
00219   }
00220 }

Copyright © 2006 by TAKAGI Nobuhisa.
このページは Wed Apr 12 16:31:56 2006 に Doxygen によって生成されました。