21.01.2013 Views

Lecture Notes in Computer Science 4917

Lecture Notes in Computer Science 4917

Lecture Notes in Computer Science 4917

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CLI as an Effective Deployment Format for Embedded Systems 135<br />

– CLI simplification: mostGIMPLE tree codes closely match what is representable<br />

<strong>in</strong> CIL, this pass expands the ones that do not follow this rule. The<br />

output of the pass is still GIMPLE but it does not conta<strong>in</strong> tree codes that<br />

the emission pass do not handle. The pass can be executed multiple times to<br />

avoid putt<strong>in</strong>g constra<strong>in</strong>ts on other passes. It is idempotent by construction.<br />

– Removal of temporary variables: InGIMPLE, expressions are broken down<br />

<strong>in</strong>to a 3-address form, us<strong>in</strong>g temporary variables to hold <strong>in</strong>termediate values.<br />

This pass merges GIMPLE expressions to elim<strong>in</strong>ate such temporary<br />

variables. Intermediate results are simply left on the evaluation stack. This<br />

results <strong>in</strong> cleaner code and a lower number of locals.<br />

– CLI emission: this pass receives a CIL-simplified GIMPLE form as <strong>in</strong>put<br />

and it produces a CLI assembly file as output.<br />

With these three passes and a m<strong>in</strong>imal target mach<strong>in</strong>e description we are able<br />

to support most of C99 1 [14]. More details of the implementation can be found<br />

<strong>in</strong> [5], and the code is freely available [4].<br />

2.3 CLI to Native Translation<br />

We have implemented a GCC front-end only for a subset of the CLI language,<br />

pragmatically dictated by the need to compile the code produced by our backend.<br />

However, noth<strong>in</strong>g <strong>in</strong> the design of the front-end forbids us to extend it to<br />

a more complete implementation <strong>in</strong> the future. The supported features <strong>in</strong>clude<br />

most base CIL <strong>in</strong>structions, direct and <strong>in</strong>direct calls to static methods, most CIL<br />

types, structures with explicit layout and size (very frequently used by our backend),<br />

constant <strong>in</strong>itializers, limited access to native platform libraries (pInvoke)<br />

support and other less frequently used features required by our back-end. On<br />

the other hand, unsupported features <strong>in</strong>clude object model related functionality,<br />

exceptions, garbage collection, reflection and support for generics.<br />

Our front-end is analogous to the GNU Compiler for Java (GCJ) [9] which<br />

compiles JVM bytecodes to native code (GCJ can also directly compile from<br />

Java to native code without us<strong>in</strong>g bytecodes). Both front-ends perform the work<br />

that is usually done by a JIT compiler <strong>in</strong> traditional virtual mach<strong>in</strong>es. But<br />

unlike JIT compilers, these front-ends are executed ahead of time. Hence, they<br />

can use much more time-consum<strong>in</strong>g optimizations to generate better code, and<br />

the startup overhead of the JIT compilation is elim<strong>in</strong>ated. In particular, our<br />

front-end compiles CIL us<strong>in</strong>g the full set of optimizations available <strong>in</strong> GCC.<br />

The front-end can compile one or more CLI assemblies <strong>in</strong>to an object file.<br />

The assembly is loaded and its metadata and code streams are parsed. Instead<br />

of writ<strong>in</strong>g our own metadata parser, we rely on Mono [3] shared library. Mono<br />

provides a comprehensive API to handle the CLI metadata and it has been easy<br />

to extend where it was lack<strong>in</strong>g some functionality. Hence, the front-end only has<br />

to parse the code stream of the methods to compile.<br />

1 In the <strong>in</strong>terest of time, we skipped a few features that were un<strong>in</strong>terest<strong>in</strong>g for our<br />

immediate purposes, for example complex numbers.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!