[8] | 1 | /*
|
---|
| 2 | * TOPPERS Software
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2007-2009 by TAKAGI Nobuhisa
|
---|
| 6 | *
|
---|
| 7 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
| 8 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
| 9 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
| 10 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
| 11 | * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
| 12 | * XR[hÉÜÜêÄ¢é±ÆD
|
---|
| 13 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
| 14 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
| 15 | gip
|
---|
| 16 | * Ò}j
|
---|
| 17 | AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL
|
---|
| 18 | * ̳ÛØKèðfÚ·é±ÆD
|
---|
| 19 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
| 20 | * pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
| 21 | * ÆD
|
---|
| 22 | * (a) Äzzɺ¤hL
|
---|
| 23 | gipÒ}j
|
---|
| 24 | AÈÇjÉCãLÌ
|
---|
| 25 | * ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD
|
---|
| 26 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
| 27 | * ñ·é±ÆD
|
---|
| 28 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
| 29 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
| 30 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
| 31 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
| 32 | * ÆÓ·é±ÆD
|
---|
| 33 | *
|
---|
| 34 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
| 35 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
| 36 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
| 37 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
| 38 | * ÌÓCðíÈ¢D
|
---|
| 39 | *
|
---|
| 40 | */
|
---|
| 41 | #include <fstream>
|
---|
| 42 | #include <sstream>
|
---|
| 43 | #include "toppers/diagnostics.hpp"
|
---|
| 44 | #include "toppers/s_record.hpp"
|
---|
| 45 | #include "toppers/macro_processor.hpp"
|
---|
| 46 | #include "cfg.hpp"
|
---|
| 47 | #include <boost/spirit.hpp>
|
---|
| 48 | #include <boost/filesystem/path.hpp>
|
---|
| 49 | #include <boost/filesystem/operations.hpp>
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | /*!
|
---|
| 53 | * \brief pXQ
|
---|
| 54 | * \retval true ¬÷
|
---|
| 55 | * \retval false ¸s
|
---|
| 56 | */
|
---|
| 57 | bool cfg2_main()
|
---|
| 58 | {
|
---|
| 59 | using namespace toppers;
|
---|
| 60 | using namespace toppers::oil;
|
---|
| 61 |
|
---|
| 62 | std::string kernel( get_global< std::string >( "kernel" ) );
|
---|
| 63 | oil::factory factory( kernel );
|
---|
| 64 |
|
---|
| 65 | // *.cfgÆcfg1_out.srecÌÇÝÝ
|
---|
| 66 | std::string input_file;
|
---|
| 67 | try
|
---|
| 68 | {
|
---|
| 69 | input_file = get_global< std::string >( "input-file" );
|
---|
| 70 | }
|
---|
| 71 | catch ( boost::bad_any_cast& )
|
---|
| 72 | {
|
---|
| 73 | fatal( _( "no input files" ) );
|
---|
| 74 | }
|
---|
| 75 | std::string cfg1_out_name( get_global< std::string >( "cfg1_out" ) );
|
---|
| 76 | std::auto_ptr< cfg1_out > cfg1_out( factory.create_cfg1_out( cfg1_out_name ) );
|
---|
| 77 |
|
---|
| 78 | codeset_t codeset = get_global< codeset_t >( "codeset" );
|
---|
| 79 | cfg1_out->load_cfg( input_file, codeset, factory.get_object_definition_info() );
|
---|
| 80 | cfg1_out->load_srec();
|
---|
| 81 | cfg1_out::cfg_obj_map cfg_obj_map( cfg1_out->merge() );
|
---|
| 82 |
|
---|
| 83 | // IDÔÌt¯
|
---|
| 84 | //assign_id(cfg_obj_map);
|
---|
| 85 | std::auto_ptr< macro_processor > mproc( factory.create_macro_processor( factory.get_hook_on_assign(), *cfg1_out, cfg_obj_map ) );
|
---|
| 86 |
|
---|
| 87 | // ev[g
|
---|
| 88 | boost::any template_file( global( "template-file" ) );
|
---|
| 89 | namespace fs = boost::filesystem;
|
---|
| 90 | fs::path cfg_dir( get_global< std::string >( "cfg-directory" ), fs::native );
|
---|
| 91 | std::vector< std::string > include_paths = get_global< std::vector< std::string > >( "include-path" );
|
---|
| 92 | include_paths.push_back( cfg_dir.empty() ? "." : cfg_dir.native_file_string() );
|
---|
| 93 | if ( !template_file.empty() )
|
---|
| 94 | {
|
---|
| 95 | toppers::text in_text;
|
---|
| 96 | toppers::text pp_text;
|
---|
| 97 | std::string file_name( boost::any_cast< std::string& >( template_file ) );
|
---|
| 98 |
|
---|
| 99 | in_text.set_line( file_name, 1 );
|
---|
| 100 | std::ifstream ifs( file_name.c_str() );
|
---|
| 101 | in_text.append( ifs );
|
---|
| 102 | macro_processor::preprocess( in_text, pp_text );
|
---|
| 103 | mproc->evaluate( pp_text );
|
---|
| 104 | }
|
---|
| 105 | else // ev[gt@Cªwè³êĢȢÌÅA¤Êªikernel.tfjÌÝð
|
---|
| 106 | {
|
---|
| 107 | fs::path kernel_cfg_template_file( cfg_dir/fs::path( "../../kernel/kernel.tf" ) );
|
---|
| 108 | if ( !fs::exists( kernel_cfg_template_file ) )
|
---|
| 109 | {
|
---|
| 110 | error( _( "cannot open file `%1%\'" ), kernel_cfg_template_file.native_file_string() );
|
---|
| 111 | }
|
---|
| 112 | else
|
---|
| 113 | {
|
---|
| 114 | toppers::text in_text;
|
---|
| 115 | toppers::text pp_text;
|
---|
| 116 |
|
---|
| 117 | in_text.set_line( kernel_cfg_template_file.native_file_string(), 1 );
|
---|
| 118 | std::ifstream ifs( kernel_cfg_template_file.native_file_string().c_str() );
|
---|
| 119 | in_text.append( ifs );
|
---|
| 120 | macro_processor::preprocess( in_text, pp_text );
|
---|
| 121 | mproc->evaluate( pp_text );
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 | if ( get_error_count() > 0 )
|
---|
| 125 | {
|
---|
| 126 | return false;
|
---|
| 127 | }
|
---|
| 128 | output_file::save();
|
---|
| 129 | return true;
|
---|
| 130 | }
|
---|