Optimizing Compiler and Linker features

BoostC++ compiler has the same specification as the BoostC compiler plus the object oriented features of C++.

SourceBoost IDE Integration

The BoostC compiler integrates seamlessly into the MS Windows SourceBoost IDE (Integrated Development Environment).

Base Data types:

  • 8 bit char - signed and unsigned.
  • 16 bit int - signed and unsigned.
  • 32 bit long - signed and unsigned.

Special Data types:

  • Single bit - single bit data type for efficient flag storage.
  • Fixed address - fixed address data types allow easy access to target device registers.
  • Read only code memory based variables.

Code Producing Features:

  • ANSI 'C' compatible - Makes code highly portable.
  • Produces optimized code for both PIC16 (14bit core) and PIC18 (16bit core) targets.
  • Support for Data Structures and Unions - Data structures and arrays can be comprised of base data types or other data structures. Arrays of base data types or data structures can be created.
  • Support for pointers - pointers can be used in "all the usual ways".
  • Inline Assembly - Inline assembly allows hand crafted assembly code to be used when necessary.
  • Inline Functions - Inline functions allows a section of code to be written as a function, but when a reference is made to it the inline function code is inserted instead of a function call. This speeds up code execution.
  • Eliminates unreachable (or dead) code - reduces code memory usage.
  • Removal of Orphan (uncalled) functions - reduces code memory usage.
  • Minimal Code Page switching - code where necessary for targets with multiple code pages.
  • Automatic Banks Switching for Variables - allows carefree use of variables
  • Efficient RAM usage - local variables in different code sections can shared memory. The linker analyzes the program to prevent any clashes.
  • Function pointers.
  • Dynamic memory management.
  • Output file in Intel Hex format.

C++ Features:

  • Function overloading.
  • Function templates.
  • References.
  • Class inheritance.
  • Class constructors and destructors
  • Class ember functions.
  • Class virtual member functions.
  • New and Delete.

Debugging features:

  • Source Level and Instruction Level Debugger - linker Generates COF file output for source level debugging under SourceBoost Debugger.
  • Step into, Step over, Step out - functions operate at source level and instruction level.
  • Multiple Execution Views - see where the execution of the code is at source level and assembly level at the same time.
  • Monitoring variables - variables can be added to the watch windows to allow there values to be examined. There is no need to know where a variable is stored.

Librarian:

  • Allows generations of library files - this simplifies management and control of regularly used code.
  • Reduce compilation time - using library files reduces compilation time.

Code Analysis:

  • Call tree view - in SourceBoost IDE displays the function call tree.
  • Target Code Usage - From the complete program, down to Function level the code space usage can be view in SourceBoost IDE.
  • Target RAM Usage - From the complete program, down to Function level the RAM usage can be view in SourceBoost IDE.

Examples of C++ Features

Classes

A C++ class allows data and functions that operate on that data to be logically grouped together. This allows code to be written in a more re-usable module form.

class Motor
{
public:
    Motor();
    void SetSpeed( int speed );
    int GetActualSpeed();

private:
    int m_setSpeed;
};

Motor::Motor()
{
     m_setSpeed = 0;
}

void Motor::SetSpeed( int speed )
{
    m_setSpeed = speed;
    ... set speed
    ...
}

int Motor::GetActualSpeed()
{
    int actualSpeed;
    ... get speed/compute speed
    ...
    return actualSpeed;
}

class Motor m1;
class Motor m2;

void main()
{
    // wait for motor 1 up to speed
    m1.SetSpeed( 10 );
    while( m1.GetActualSpeed() != 10 );

    // wait for motor 2 up to speed
    m2.SetSpeed( 10 );
    while( m2.GetActualSpeed() != 10 );
   
    .....
    while( 1 );
}

References

References can be used as function arguments. This provides very effective way to change values of the variables passed into a function as references:

void foo( char& x )  //'x' is a reference
{
  x = 10;
}

void main( void )
{
  char a = 1;
  foo( a );  //before the call 'a' is 1 and after the call it becomes 10
  ...
}

Function overloading

Functions can have same names and differ only by number and type of their arguments:

void foo( void )  //'foo' number 1
{
...
}

void foo( char *ptr )  //'foo' number 2
{
...
}

void foo( char a, char b )  //'foo' number 3
{
...
}

void main( void )
{
  foo();  //'foo' number 1 gets called
  foo( "test" );  //'foo' number 2 gets called
  foo( 10, 20 );  //'foo' number 3 gets called
  ...
}

Function templates

Functions can be declared and defined using data type placeholders. This feature allows writing very general code (for example linked lists) that isn't tightened to a particular data type and what may be more important to create libraries in form of header files:

template <class T>
void foo( T *t )
{
...
}

void main( void )
{
  short s;
  foo<char>( "test" );  //'foo( char* )' gets called
  foo<short>( &s );  //'foo( short* )' gets called
  ...
}

 

new and delete operators

Class objects can be created at run time using the new operation. After such object is created its relevant constructor gets called. Such dynamically created class objects can be destroyed using the delete operation.

//Create object of type class A and than delete it
class A *a = new class A;
...
delete a;

For class objects constructor is called after this object is created. It can be either default or overloaded constructor:

class A *a = new class A; //create object of type class A
//and call default constructor

class A *a = new class A( 1 ); //create object of type class A and call
//overloaded constructor that has one argument

 

Virtual member functions

Virtual member functions are supported for class objects.

//Define class A
class A
{
  virtual void foo( void );
};

//Define class B that is inherited from A
class B : public A
{
  void foo( void );
};
...
  class B b; //declare object of type class B
  class A *a = &b; //declare pointer to an object of type class A and
  //initialize it with the address of object 'b'
  a->foo(); //B::foo method will be called here

 

See the BoostC++ Compiler Reference Manual for more examples.