Sign in



Don't have an account?

Signing up is free and easy
Home -> Our Services -> Programming Tools BU -> C Compilers -> Development of 'C' compiler for 32-bit MCU

Development of 'C' compiler for 32-bit MCU

Requirements

A leading Japanese semi-conductor company required a C compiler for high performance 32-bit RISC microprocessor. The compiler was to be ANSI (ISO/IEC9899:1990) compatible optimizing C compiler with extensions.

The following were the requirements from the customer for the optimizing C compiler:

  • The compiler should be developed in a year's period.
  • The code size should be better than the standard compilers for benchmark programs.
  • The compiler should compile one or more input C source files and output an assembly file for each input file.
  • The compiler should conditionally output the following files:
    • Preprocessed file
    • Error listing file
    • Call tree file
    • Function prototype file
  • The assembly code generated by the compiler should meet the customer's assembler input specifications.
  • The undefined behavior, unspecified behavior and translation limits should be handled as per the customer's ANSI Implementation Dependent Specifications.
  • The compiler should support both 16 bit and 32 bit ISA modes.
  • The C compiler should follow the customer's EABI specification. The EABI specification includes the following:
    • Sizes and alignments of Basic types
    • Function calls
    • Stack frame
    • Argument register setup procedure
    • Passing the body of structure via arguments
    • Handling of variable arguments
    • Return values of functions
    • Software emulation of floating-point arithmetic
  • The debugging information should be based on IEEE695 specification.
  • The compiler should have command line options for group optimization
  • The compiler should have individual command line options for each optimization.

Challenges

  • Develop a compiler from scratch
  • Hand compilation of benchmark programs
  • Handle both 16 bit and 32 bit ISA
  • Better code size than standard compiler for benchmark programs
  • Identify optimizations that would reduce the code size
  • Support more than 100 command line options including individual command line option for each optimization

Solution

  • Environment
    OS
    Windows
    Language/Platform C
    Development model Waterfall development model
    Quality validation tools
    • Numega Dev Partner Studio to check for memory errors, memory leaks and test coverage
    • QAC for static analysis of code
    Test base
    • Standard test suites like Perennial, and Plum Hall
    • Acme generated test vectors
    • GCC test vectors
  • Description

    The Japanese customer identified two companies in India for development of the optimizing C compiler. One was Acme and the other was one of the leading software companies in India. The Japanese customer decided to give the compiler development to the company whose code size for benchmark programs was better. The benchmark programs needed to be hand compiled. As Acme's hand compilation code size was better, the compiler development was given to Acme.

    The Japanese customer required the C compiler urgently. The estimation was based on the lines of code and it was scheduled to be delivered in 13 calendar months.

    The project was decided to be developed in the waterfall model. Hence the project was divided into five phases.

    • 1st Phase:
      1. Functional Specification Document
      2. Software Architecture Document
      3. Hand compilation of one benchmark program
    • 2nd Phase:
      1. Acme's intermediate code specification document
      2. Module wise design document
      3. Hand compilation of remaining benchmark programs
    • 3rd Phase:

      Development of test specifications and test vectors

    • 4th Phase:
      1. User's Manual
      2. Alpha version of the C compiler
    • 5th Phase:

      Beta version of the C compiler

      The C compiler was planned to develop as a 4-pass optimizing compiler.

      • Pass I
        1. Preprocessing
        2. Lexical analysis
        3. Syntax analysis
        4. Semantic analysis
        5. Local optimization
        6. Intermediate code generation
      • Pass II
        1. Global optimization
        2. Loop optimization
      • Pass III
        1. Code generation
        2. Register allocation
      • Pass IV
        1. Postcode optimization
        2. Instruction scheduling

    The toughest challenge faced was to generate assembly code with the code size being better than standard compilers. The team identified the optimizations that would be required to attain this. The optimizations were identified by studying standard compiler text books and by evaluating standard compilers. Upon the release of the Beta version of the compiler, the code size was better than standard compilers. But there were some quality issues.

    As the compiler was developed from scratch and a short span of time, there were quality issues at the end 13 months. This was also because the best software practices were still evolving in Acme. The defect prone modules were identified and code was refined using the best software practices which by now had become part of Acme's development process. This helped in making the compiler stable.