Magpie 一个IDL 接口生成器的简单介绍

2936阅读 0评论2012-05-15 liu090
分类:Python/Ruby

Magpie 和其他idl工具相似,是一个接口生成器,用来产生service ,client 的 skeleton 代码
它是开源的,地址在
  

正如其介绍中所讲:

 "This is not a new technique, but is rather uncommon in interface compilers. "

它的确与众不同

主要特点是:
1. 由python 实现

2. 使用了antlr 做AST解析 (版本比较老1.1)

3. 使用templator 实现skeleton 代码

4. 可扩展 (可以自己写 generator, template 来实现自己的接口生成器)

目录:
   target 是主要入口,在其中设置使用那个generator, template等
  
   generator 是对AST进行操作以获取interface,function在AST中有用的信息

   output  放了对template 编译执行代码

   output/template 放了各个类型的template

   antlr  antlr 1.1

   idlparser  antlr的idl parser

   cparser   antlr 的c parser

   magpietypes  包含arch size 操作,build in type AST 生成,type info 整合操作等

   test\input 有供测试的 idl文件

   doc 中有使用和自己写一个skeleton 生成器的介绍


执行简单流程:
  输入命令:
    
  ./magpie.py --target=idl4/generic_l4v4 --output=client test/input/simple.idl4
  其中的参数输入可以通过--help 查询

Options:
  -h, --help            show this help message and exit
  --target=TARGET       Specify a target.
  -c, --camkes          specify source/generation = CAmkES
  --list-targets        List all targets.
  --output=OUTPUT       Specify an output format.
  --list-outputs        List all outputs for a given target.
  -I INCLUDE_DIRS       specify additional include directories
  --templates=TEMPLATES_DIR
                        The base directory for templates
  --output-filename=OUTPUT_FILENAME
                        The output filename (or '-' for standard output)

   1. 根据参数,选择target ,generator, 选择输出类型为client 还是service

   2. 根据buildin type 生成 basic AST

   3. 对 IDL文件中的头文件进行预处理

   4. 对预处理输出生成type AST,并且和basic ast 合并 (c parser)

   5. 对IDL 接口部分进行解析 (idl parser)

   6. 选择client或者serice template 的入口模板文件,开始编译(wsogmm.py=>_compile),并执行

   7. 输出结果到屏幕( 未指定输出文件,输出到屏幕)


对于这个接口生成器,感觉非常适合在一些轻量级的embeded 开发中,用于系统接口框架的生成

上一篇:python在嵌套域中执行exec in
下一篇:Magpie 简单分析(1)