source: cfg_oil/trunk/cfg/cfg2.cpp@ 8

Last change on this file since 8 was 8, checked in by msugi, 13 years ago

ディレクトリ構造の作成,ソース一式とReleaseビルドのコミット.

File size: 4.7 KB
Line 
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–{ƒ\ƒtƒgƒEƒF
8 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
9 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
10 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
11 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
12 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
13 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
14 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
15ƒƒ“ƒgi—˜—p
16 * ŽÒƒ}ƒjƒ…
17ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
18 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
19 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
20 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
21 * ‚ƁD
22 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
23ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
24ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
25 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
26 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
27 * •ñ‚·‚邱‚ƁD
28 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
29 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
30 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
31 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
32 * –Ɛӂ·‚邱‚ƁD
33 *
34 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
35 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
36 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
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 ƒpƒX‚Qˆ—
54 * \retval true ¬Œ÷
55 * \retval false Ž¸”s
56 */
57bool 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 // ƒeƒ“ƒvƒŒ[ƒ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 // ƒeƒ“ƒvƒŒ[ƒgƒtƒ@ƒCƒ‹‚ªŽw’肳‚ê‚Ä‚¢‚È‚¢‚̂ŁA‹¤’Ê•”•ªikernel.tfj‚Ì‚Ý‚ðˆ—
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}
Note: See TracBrowser for help on using the repository browser.