SDK Tools Guides

Home

Compilation, Linking, and Assembly

Pipe-Tool is MoSync's code transformation engine. It combines the functions of a code linker and assembler, and performs code verification, optimization and dead code elimination to produce highly optimized outputs for each of the target platforms.

Invoking Pipe-Tool

Pipe-Tool is automatically invoked by the MoSync IDE during the normal build process (when you click the Run button, or build a package), so in the normal case you don't need to do anything to use Pipe-Tool, just run or build your project.

When it is invoked, Pipe-Tool makes several passes through your code. It is very fast: it takes only around one second to make six passes through a 25000 line application.

For specialist uses, Pipe-Tool can also be run on demand from the command line.

Code Compilation

As the first step of the build process, the MoSync Eclipse IDE invokes the GCC compiler to compile your application code. 

Code Verification and Optimization

A little later in the build process, Pipe-Tool takes the output from GCC and the resource pre-compiler (for information about resource compilation, see our Resource Compiler Reference) and performs code verification, code optimization, and dead code elimination. Code verification includes among other things:

  • Bounds checking
  • Division error detection
  • Stack abuse detection
  • Function tracing

Depending partly on the output required by the target platform, Pipe-Tool's code optimization features help create faster, smaller programs by:

  • Converting immediate values to constant register values
  • Eliminating jump-to-jump occurrences
  • Rewriting functions to perform constant value inlining
  • Analyzing and optimizing program flow
  • Analyzing and optimizing register life
  • Performing memory index reduction and adaptive index scaling

During the dead code elimination phase, Pipe-Tool looks through the application tree, marking any nodes that are unreachable. Unlike a traditional linker that marks only whole objects or functions for elimination, Pipe-Tool eliminates dead code down to the lowest level of granularity: right down to individual instructions and bytes.

Linking

After optimization, Pipe-Tool links the MoSync IL from GCC with the pre-compiled MoSync libraries, and the compiled resource binary to create the MoSync bytecode, Java bytecode, or C/C++ source code that will be packaged with the platform runtimes.

Assembly

When a program has been optimized and linked, Pipe-Tool sends the internal representation of the program to the compiler backend. The backend transforms the application into a representation that can be understood by the target architecture. Most commonly the program gets assembled into MoSync bytecode which in turn may be interpreted or recompiled by the MoSync runtimes. We also have experimental support for producing a Java bytecode representation of the application that can be executed on Java virtual machines.

Using Pipe-Tool from the Command Line

Compiling Resources

If your resources are declared via a LST file (see the Resource Compiler Reference) you can invoke the resource compiler from the Pipe-Tool command line, if you really need to:

pipe-tool -R options outfile infile1 [infile2 ...]

Building a Library

In -L mode, Pipe-Tool combines the specifed infiles (.s files) into a single library .lib file.

pipe-tool -L options outfile infile1 [infile2 ...]

Building an Application

In -B mode, Pipe-Tool combines the specifed infiles to create a single output file.

pipe-tool -B options outfile infile1 [infile2 ...]

Manual Page

The options are described in the Pipe-Tool manual page, which can displayed using:

pipe-tool -h 

Usage: pipe-tool <mode> [options] outfile infile1 [infile2 ...]

Mode Switches:
  -L                   create library
  -R                   compile resources
  -B                   build application

General options:
  -h | --help          show this usage info
  -error-paths         show file paths in errors
  -xerr                extra information in case of errors
  -master-dump         also dump the input into a single text file
  -s<dir>              search <dir> for input libraries

Build application (-B) options:
  -entry=sym           set code entry point (default 'crt0_startup')
  -datasize=size       set data size (default 1048576)
  -stacksize=size      set stack size (default 131072)
  -heapsize=size       set heap size (default 524288)
  -appcode=value       set application code (default 'TEST'(0x54455354))
  -p=vendor/model      link with device profile
  -dump-syms           dump symbol tables
  -dump-unref          dump unreferenced symbols
  -sld=file            output source/line translation
  -stabs=file          output debug information
  -elim                eliminate unreferenced code/data
  -no-verify           prevent code verification
  -java                build a Java class file
  -gcj=flags           for -java option: set flags for GCJ
  -cpp                 build C++ source code
  -cs                  build C# source code

Resource compiler (-R) options:
  -depend=file         output dependencies in makefile syntax

Librarian (-L) options:
  -quiet               don't display the component files

Library mode (-L) is used to combine .s files into a .lib library file.
In resource mode (-R), resource files are compiled to the output file.
In normal mode (-B), one or more input files are built and linked to create a
single output file.

MoSync SDK 3.3
Copyright © 2013 MoSync AB
www.mosync.com