Received: by 10.180.107.167 with SMTP id hd7mr3124569wib.0.1350352645785; Mon, 15 Oct 2012 18:57:25 -0700 (PDT) Path: q10ni65138205wif.0!nntp.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.130.MISMATCH!xlned.com!feeder1.xlned.com!border2.nntp.ams.giganews.com!nntp.giganews.com!news.panservice.it!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-l...@python.org Delivered-To: python-l...@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'xml,': 0.05; 'c++,': 0.07; 'parsing': 0.07; 'subject:code': 0.07; 'python': 0.09; 'mips': 0.09; 'trees': 0.09; 'cc:addr:python-list': 0.10; 'template': 0.11; '(like': 0.15; 'file,': 0.15; '(everything': 0.16; '(well,': 0.16; 'c++.': 0.16; 'constants': 0.16; 'example?': 0.16; 'fatal': 0.16; 'sense,': 0.16; 'compilation': 0.17; 'code.': 0.20; 'translate': 0.20; 'written': 0.20; 'parse': 0.22; 'help.': 0.22; 'defined': 0.22; 'cc:2**0': 0.23; 'changes,': 0.23; 'insert': 0.23; 'cc:no real name:2**0': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'wondering': 0.26; 'c++': 0.27; 'change,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'url:mailman': 0.29; 'probably': 0.29; 'maybe': 0.29; 'related': 0.30; 'classes': 0.30; 'received:209.85.215.46': 0.30; 'writes': 0.30; 'on,': 0.30; 'code': 0.31; 'url:python': 0.32; 'file': 0.32; 'not.': 0.32; 'structure': 0.32; 'running': 0.32; 'could': 0.32; 'url:listinfo': 0.32; 'like:': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'problem,': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'url:org': 0.36; 'depends': 0.36; 'generation': 0.36; "didn't": 0.36; 'xml': 0.37; 'option': 0.37; 'why': 0.37; 'quite': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'where': 0.40; 'header:Received:5': 0.40; 'end': 0.40; 'url:mail': 0.40; 'think': 0.40; 'your': 0.60; 'easy': 0.60; 'skip:u 10': 0.60; 'first': 0.61; 'harder': 0.65; 'want,': 0.65; 'subject': 0.66; 'basically,': 0.84; 'escaping': 0.84; 'ini': 0.84; 'working,': 0.84; 'successful.': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=Pyu4c0Fux3Nu7Ztcc5jCWigZT5aKoyTUi8KK3YAu9m0=; b=XG1WGp9fTVqnPP0veG9bTYwwj/VIcx5FxvaDBvfLQW6edtROa4NVUsVD0dK4FmariO uKX8B3IWwYoeJ/yLWH6pUdQHc+iA13I0hzLVim2TjM5DULk3lcWXz+vY73P4tvk4ANrL Jvtlj2x8hpjJRHtWHoOEPmtvtit3JN45AjSCZzPpDWF2gQC1BYZ8smhxVJDGevNl6P5r tJ6awqxKUpiI+2uEAiRh196JOYdc9lsfIbeDMpeEYcUKhJxwiWjmEaZNg/JtiQGZ4YE1 AIGSN4dvqoefWp0UY7fN/JMda6lVz0IbHXK9G46D+cDU8LwCVvETs5DOa84DQqrV4Jry jMpA== MIME-Version: 1.0 In-Reply-To: <596686195.3370358.1349863190132.JavaMail.r...@sequans.com> References: <20121009165226.13e5f3040b636e280f0ab...@gmail.com> <596686195.3370358.1349863190132.JavaMail.r...@sequans.com> Date: Wed, 10 Oct 2012 11:41:01 +0100 Subject: Re: Generating C++ code From: andrea crotti To: Jean-Michel Pichavant Cc: python-l...@python.org X-BeenThere: python-l...@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1349865663 news.xs4all.nl 6929 [2001:888:2000:d::a6]:57648 X-Complaints-To: ab...@xs4all.nl Bytes: 6034 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2012/10/10 Jean-Michel Pichavant : > Well, the C++ code will end up running on a MIPS on a SOC, unfortunately,= python is not an option here. > The xml to C++ makes a lot of sense, because only a small part of the cod= e is generated that way (everything related to log & fatal events). Everyth= ing else is written directly in C++. > > To answer Andrea's question, the files are regenerated for every compilat= ion (well, unless the xml didn't change, but the xml is highly subject to c= hanges, that's actually its purpose) > > Currently we already have a python script that translate this xml file to= C++, but it's done in a way that is difficult to maintain. Basically, when= parsing the xml file, it writes the generated C++ code. Something like: > if 'blabla' in xml: > h_file.write("#define blabla 55", append=3D"top") > c_file.write("someglobal =3D blabla", append=3D"bottom") > > This is working, but the python code is quite difficult to maintain, ther= e's a lot of escaping going on, it's almost impossible to see the structure= of the c files unless generating one and hopping it's successful. It's als= o quite difficult to insert code exactly where you want, because you do not= know the order in which the xml trees are defined then parsed. > > I was just wondering if a template engine would help. Maybe not. > > JM > -- > http://mail.python.org/mailman/listinfo/python-list I think it depends on what you're writing from the XML, are you generating just constants (like the #define) or also new classes for example? If it's just constants why don't you do a generation from XML -> ini or something similar and then parse it in the C++ properly, then it would be very easy to do? You could also parse the XML in the first place but probably that's harder given your requirements, but I don't think that an ini file would be a problem, or would it?