Aseba::Compiler Class Reference
[AESL Compiler]

Aseba Event Scripting Language compiler. More...

#include <compiler.h>

List of all members.

Classes

struct  SubroutineDescriptor
 Description of a subroutine. More...
struct  Token
 A token is a parsed element of inputs. More...

Public Types

typedef std::map< std::string,
unsigned > 
FunctionsMap
 Lookup table for functions (name => id in target description).
typedef std::map< std::string,
unsigned > 
FunctionsMap
 Lookup table for functions (name => id in target description).
typedef std::set< unsigned > ImplementedEvents
 Lookup table to keep track of implemented events.
typedef std::set< unsigned > ImplementedEvents
 Lookup table to keep track of implemented events.
typedef std::map< std::string,
unsigned > 
SubroutineReverseTable
 Reverse Lookup table for subroutines name => id.
typedef std::map< std::string,
unsigned > 
SubroutineReverseTable
 Reverse Lookup table for subroutines name => id.
typedef std::vector
< SubroutineDescriptor
SubroutineTable
 Lookup table for subroutines id => (name, address, line).
typedef std::vector
< SubroutineDescriptor
SubroutineTable
 Lookup table for subroutines id => (name, address, line).
typedef std::map< std::string,
std::pair< unsigned, unsigned > > 
VariablesMap
 Lookup table for variables name => (pos, size)).
typedef std::map< std::string,
std::pair< unsigned, unsigned > > 
VariablesMap
 Lookup table for variables name => (pos, size)).

Public Member Functions

bool compile (std::istream &source, BytecodeVector &bytecode, unsigned &allocatedVariablesCount, Error &errorDescription, std::ostream *dump=0)
bool compile (std::istream &source, BytecodeVector &bytecode, unsigned &allocatedVariablesCount, Error &errorDescription, std::ostream *dump=0)
 Compiler ()
 Compiler ()
 Constructor. You must setup a description using setTargetDescription() before any call to compile().
const TargetDescriptiongetTargetDescription () const
const TargetDescriptiongetTargetDescription () const
const VariablesMapgetVariablesMap () const
const VariablesMapgetVariablesMap () const
void setCommonDefinitions (const CommonDefinitions *definitions)
void setCommonDefinitions (const CommonDefinitions *definitions)
 Set the common definitions, such as events or some constants.
void setTargetDescription (const TargetDescription *description)
void setTargetDescription (const TargetDescription *description)
 Set the description of the target as returned by the microcontroller. You must call this function before any call to compile().

Protected Member Functions

void buildMaps ()
void buildMaps ()
 Build variables and functions maps.
void disassemble (BytecodeVector &bytecode, const PreLinkBytecode &preLinkBytecode, std::ostream &dump) const
void disassemble (BytecodeVector &bytecode, const PreLinkBytecode &preLinkBytecode, std::ostream &dump) const
 Disassemble a microcontroller bytecode and dump it.
void dumpTokens (std::ostream &dest) const
void dumpTokens (std::ostream &dest) const
 Debug print of tokens.
std::string eventName (unsigned eventId) const
std::string eventName (unsigned eventId) const
 Return the name of an event given its identifier.
void expect (const Token::Type &type) const
void expect (const Token::Type &type) const
 Check if next token is of type, produce an exception otherwise.
int expectAbsoluteInt16Literal (bool negative) const
int expectAbsoluteInt16Literal (bool negative) const
 Check if next token is the absolute part of a 16 bits signed integer literal. If so, return it, if not, throw an exception.
unsigned expectAnyEventId () const
unsigned expectAnyEventId () const
 Check if next token is a known local or global event identifier.
int expectConstant () const
int expectConstant () const
 Check if next toxen is a valid 16 bits signed integer constant.
unsigned expectGlobalEventId () const
unsigned expectGlobalEventId () const
 Check if next token is a known global event identifier.
int expectInt16LiteralOrConstant ()
int expectInt16LiteralOrConstant ()
 Check and return either a 16 bits signed integer or the value of a valid constant.
template<int length>
void expectOneOf (const Token::Type types[length]) const
template<int length>
void expectOneOf (const Token::Type types[length]) const
 Check if next token is of one of the following types, produce an exception otherwise.
unsigned expectPositiveConstant () const
unsigned expectPositiveConstant () const
 Check if next toxen is a valid positive part of a 16 bits signed integer constant.
unsigned expectPositiveInt16Literal () const
unsigned expectPositiveInt16Literal () const
 Check if next token is the positive part of a 16 bits signed integer literal. If so, return it, if not, throw an exception.
unsigned expectPositiveInt16LiteralOrConstant () const
unsigned expectPositiveInt16LiteralOrConstant () const
 Check and return either the positive part of a 16 bits signed integer or the value of a valid constant.
unsigned expectUInt12Literal () const
unsigned expectUInt12Literal () const
 Check if next token is an unsigned 12 bits integer literal. If so, return it, if not, throw an exception.
unsigned expectUInt16Literal () const
unsigned expectUInt16Literal () const
 Check if next token is an unsigned 16 bits integer literal. If so, return it, if not, throw an exception.
void internalCompilerError () const
void internalCompilerError () const
 There is a bug in the compiler, ask for a bug report.
template<int length>
bool isOneOf (const Token::Type types[length]) const
template<int length>
bool isOneOf (const Token::Type types[length]) const
 Return true if next token is of the following types.
bool link (const PreLinkBytecode &preLinkBytecode, BytecodeVector &bytecode)
bool link (const PreLinkBytecode &preLinkBytecode, BytecodeVector &bytecode)
 Create the final bytecode for a microcontroller.
NodeparseAddExpression ()
NodeparseAddExpression ()
 Parse "add_expression" grammar element.
NodeparseAnd ()
NodeparseAnd ()
 Parse "and" grammar element.
NodeparseAssignment ()
NodeparseAssignment ()
 Parse "assignment" grammar element.
NodeparseBinaryAndExpression ()
NodeparseBinaryAndExpression ()
 Parse "binary and" grammar element.
NodeparseBinaryOrExpression ()
NodeparseBinaryOrExpression ()
 Parse "binary or" grammar element.
NodeparseBinaryXorExpression ()
NodeparseBinaryXorExpression ()
 Parse "binary xor" grammar element.
NodeparseBlockStatement ()
NodeparseBlockStatement ()
 Parse "block statement" grammar element.
NodeparseCallSub ()
NodeparseCallSub ()
 Parse "subcall" grammar element, call of subroutine.
NodeparseCondition ()
NodeparseCondition ()
 Parse "condition" grammar element.
NodeparseEmit ()
NodeparseEmit ()
 Parse "event" grammar element.
NodeparseFor ()
NodeparseFor ()
 Parse "for" grammar element.
NodeparseFunctionCall ()
NodeparseFunctionCall ()
 Parse "function_call" grammar element.
NodeparseIfWhen (bool edgeSensitive)
NodeparseIfWhen (bool edgeSensitive)
 Parse "if" grammar element.
NodeparseMultExpression ()
NodeparseMultExpression ()
 Parse "mult_expression" grammar element.
NodeparseNot ()
NodeparseNot ()
 Parse "not" grammar element.
NodeparseOnEvent ()
NodeparseOnEvent ()
 Parse "onevent" grammar element.
NodeparseOr ()
NodeparseOr ()
 Parse "or" grammar element.
NodeparseProgram ()
NodeparseProgram ()
 Parse "program" grammar element.
void parseReadVarArrayAccess (unsigned *addr, unsigned *size)
void parseReadVarArrayAccess (unsigned *addr, unsigned *size)
 Parse access to variable, arrray, or array subscript.
NodeparseShiftExpression ()
NodeparseShiftExpression ()
 Parse "shift_expression" grammar element.
NodeparseStatement ()
NodeparseStatement ()
 Parse "statement" grammar element.
NodeparseSubDecl ()
NodeparseSubDecl ()
 Parse "sub" grammar element, declaration of subroutine.
NodeparseUnaryExpression ()
NodeparseUnaryExpression ()
 Parse "unary_expression" grammar element.
NodeparseVarDef ()
NodeparseVarDef ()
 Parse "var def" grammar element.
NodeparseWhile ()
NodeparseWhile ()
 Parse "while" grammar element.
void tokenize (std::istream &source)
void tokenize (std::istream &source)
bool verifyStackCalls (PreLinkBytecode &preLinkBytecode)
bool verifyStackCalls (PreLinkBytecode &preLinkBytecode)
 Verify that no call path can create a stack overflow.

Protected Attributes

const CommonDefinitionscommonDefinitions
 common definitions, such as events or some constants
unsigned freeVariableIndex
 index pointing to the first free variable
FunctionsMap functionsMap
 functions lookup
ImplementedEvents implementedEvents
 list of implemented events
SubroutineReverseTable subroutineReverseTable
 subroutine reverse lookup
SubroutineTable subroutineTable
 subroutine lookup
const TargetDescriptiontargetDescription
 description of the target VM
std::deque< Tokentokens
 parsed tokens
VariablesMap variablesMap
 variables lookup

Detailed Description

Aseba Event Scripting Language compiler.

Definition at line 202 of file compiler.h.


Member Typedef Documentation

typedef std::map<std::string, unsigned> Aseba::Compiler::FunctionsMap

Lookup table for functions (name => id in target description).

Definition at line 274 of file compiler.h.

typedef std::map<std::string, unsigned> Aseba::Compiler::FunctionsMap

Lookup table for functions (name => id in target description).

Definition at line 274 of file compiler.h.

typedef std::set<unsigned> Aseba::Compiler::ImplementedEvents

Lookup table to keep track of implemented events.

Definition at line 289 of file compiler.h.

typedef std::set<unsigned> Aseba::Compiler::ImplementedEvents

Lookup table to keep track of implemented events.

Definition at line 289 of file compiler.h.

typedef std::map<std::string, unsigned> Aseba::Compiler::SubroutineReverseTable

Reverse Lookup table for subroutines name => id.

Definition at line 287 of file compiler.h.

typedef std::map<std::string, unsigned> Aseba::Compiler::SubroutineReverseTable

Reverse Lookup table for subroutines name => id.

Definition at line 287 of file compiler.h.

Lookup table for subroutines id => (name, address, line).

Definition at line 285 of file compiler.h.

Lookup table for subroutines id => (name, address, line).

Definition at line 285 of file compiler.h.

typedef std::map<std::string, std::pair<unsigned, unsigned> > Aseba::Compiler::VariablesMap

Lookup table for variables name => (pos, size)).

Definition at line 272 of file compiler.h.

typedef std::map<std::string, std::pair<unsigned, unsigned> > Aseba::Compiler::VariablesMap

Lookup table for variables name => (pos, size)).

Definition at line 272 of file compiler.h.


Constructor & Destructor Documentation

Aseba::Compiler::Compiler (  ) 

Member Function Documentation

void Aseba::Compiler::buildMaps (  )  [protected]
bool Aseba::Compiler::compile ( std::istream &  source,
BytecodeVector bytecode,
unsigned &  allocatedVariablesCount,
Error errorDescription,
std::ostream *  dump = 0 
)
void Aseba::Compiler::disassemble ( BytecodeVector bytecode,
const PreLinkBytecode preLinkBytecode,
std::ostream &  dump 
) const [protected]
void Aseba::Compiler::dumpTokens ( std::ostream &  dest  )  const [protected]
void Aseba::Compiler::dumpTokens ( std::ostream &  dest  )  const [protected]

Debug print of tokens.

Definition at line 371 of file lexer.cpp.

std::string Aseba::Compiler::eventName ( unsigned  eventId  )  const [protected]
std::string Aseba::Compiler::eventName ( unsigned  eventId  )  const [protected]

Return the name of an event given its identifier.

Definition at line 225 of file parser.cpp.

void Aseba::Compiler::expect ( const Token::Type type  )  const [protected]
void Aseba::Compiler::expect ( const Token::Type type  )  const [protected]

Check if next token is of type, produce an exception otherwise.

Definition at line 54 of file parser.cpp.

int Aseba::Compiler::expectAbsoluteInt16Literal ( bool  negative  )  const [protected]
int Aseba::Compiler::expectAbsoluteInt16Literal ( bool  negative  )  const [protected]

Check if next token is the absolute part of a 16 bits signed integer literal. If so, return it, if not, throw an exception.

Definition at line 101 of file parser.cpp.

unsigned Aseba::Compiler::expectAnyEventId (  )  const [protected]
unsigned Aseba::Compiler::expectAnyEventId (  )  const [protected]

Check if next token is a known local or global event identifier.

Definition at line 206 of file parser.cpp.

int Aseba::Compiler::expectConstant (  )  const [protected]
int Aseba::Compiler::expectConstant (  )  const [protected]

Check if next toxen is a valid 16 bits signed integer constant.

Definition at line 140 of file parser.cpp.

unsigned Aseba::Compiler::expectGlobalEventId (  )  const [protected]
unsigned Aseba::Compiler::expectGlobalEventId (  )  const [protected]

Check if next token is a known global event identifier.

Definition at line 189 of file parser.cpp.

int Aseba::Compiler::expectInt16LiteralOrConstant (  )  [protected]
int Aseba::Compiler::expectInt16LiteralOrConstant (  )  [protected]

Check and return either a 16 bits signed integer or the value of a valid constant.

Definition at line 173 of file parser.cpp.

template<int length>
void Aseba::Compiler::expectOneOf ( const Token::Type  types[length]  )  const [inline, protected]
template<int length>
void Aseba::Compiler::expectOneOf ( const Token::Type  types[length]  )  const [inline, protected]

Check if next token is of one of the following types, produce an exception otherwise.

Definition at line 253 of file parser.cpp.

unsigned Aseba::Compiler::expectPositiveConstant (  )  const [protected]
unsigned Aseba::Compiler::expectPositiveConstant (  )  const [protected]

Check if next toxen is a valid positive part of a 16 bits signed integer constant.

Definition at line 116 of file parser.cpp.

unsigned Aseba::Compiler::expectPositiveInt16Literal (  )  const [protected]
unsigned Aseba::Compiler::expectPositiveInt16Literal (  )  const [protected]

Check if next token is the positive part of a 16 bits signed integer literal. If so, return it, if not, throw an exception.

Definition at line 89 of file parser.cpp.

unsigned Aseba::Compiler::expectPositiveInt16LiteralOrConstant (  )  const [protected]
unsigned Aseba::Compiler::expectPositiveInt16LiteralOrConstant (  )  const [protected]

Check and return either the positive part of a 16 bits signed integer or the value of a valid constant.

Definition at line 164 of file parser.cpp.

unsigned Aseba::Compiler::expectUInt12Literal (  )  const [protected]
unsigned Aseba::Compiler::expectUInt12Literal (  )  const [protected]

Check if next token is an unsigned 12 bits integer literal. If so, return it, if not, throw an exception.

Definition at line 65 of file parser.cpp.

unsigned Aseba::Compiler::expectUInt16Literal (  )  const [protected]
unsigned Aseba::Compiler::expectUInt16Literal (  )  const [protected]

Check if next token is an unsigned 16 bits integer literal. If so, return it, if not, throw an exception.

Definition at line 77 of file parser.cpp.

const TargetDescription* Aseba::Compiler::getTargetDescription (  )  const [inline]

Definition at line 294 of file compiler.h.

const TargetDescription* Aseba::Compiler::getTargetDescription (  )  const [inline]

Definition at line 294 of file compiler.h.

const VariablesMap* Aseba::Compiler::getVariablesMap (  )  const [inline]

Definition at line 295 of file compiler.h.

const VariablesMap* Aseba::Compiler::getVariablesMap (  )  const [inline]

Definition at line 295 of file compiler.h.

void Aseba::Compiler::internalCompilerError (  )  const [protected]
void Aseba::Compiler::internalCompilerError (  )  const [protected]

There is a bug in the compiler, ask for a bug report.

Definition at line 48 of file parser.cpp.

template<int length>
bool Aseba::Compiler::isOneOf ( const Token::Type  types[length]  )  const [inline, protected]
template<int length>
bool Aseba::Compiler::isOneOf ( const Token::Type  types[length]  )  const [inline, protected]

Return true if next token is of the following types.

Definition at line 241 of file parser.cpp.

bool Aseba::Compiler::link ( const PreLinkBytecode preLinkBytecode,
BytecodeVector bytecode 
) [protected]
Node* Aseba::Compiler::parseAddExpression (  )  [protected]
Node * Aseba::Compiler::parseAddExpression (  )  [protected]

Parse "add_expression" grammar element.

Definition at line 934 of file parser.cpp.

Node* Aseba::Compiler::parseAnd (  )  [protected]
Node * Aseba::Compiler::parseAnd (  )  [protected]

Parse "and" grammar element.

Definition at line 789 of file parser.cpp.

Node* Aseba::Compiler::parseAssignment (  )  [protected]
Node * Aseba::Compiler::parseAssignment (  )  [protected]

Parse "assignment" grammar element.

Definition at line 391 of file parser.cpp.

Node* Aseba::Compiler::parseBinaryAndExpression (  )  [protected]
Node * Aseba::Compiler::parseBinaryAndExpression (  )  [protected]

Parse "binary and" grammar element.

Definition at line 899 of file parser.cpp.

Node* Aseba::Compiler::parseBinaryOrExpression (  )  [protected]
Node * Aseba::Compiler::parseBinaryOrExpression (  )  [protected]

Parse "binary or" grammar element.

Definition at line 867 of file parser.cpp.

Node* Aseba::Compiler::parseBinaryXorExpression (  )  [protected]
Node * Aseba::Compiler::parseBinaryXorExpression (  )  [protected]

Parse "binary xor" grammar element.

Definition at line 883 of file parser.cpp.

Node* Aseba::Compiler::parseBlockStatement (  )  [protected]
Node * Aseba::Compiler::parseBlockStatement (  )  [protected]

Parse "block statement" grammar element.

Definition at line 307 of file parser.cpp.

Node* Aseba::Compiler::parseCallSub (  )  [protected]
Node * Aseba::Compiler::parseCallSub (  )  [protected]

Parse "subcall" grammar element, call of subroutine.

Definition at line 694 of file parser.cpp.

Node* Aseba::Compiler::parseCondition (  )  [protected]
Node * Aseba::Compiler::parseCondition (  )  [protected]

Parse "condition" grammar element.

Definition at line 848 of file parser.cpp.

Node* Aseba::Compiler::parseEmit (  )  [protected]
Node * Aseba::Compiler::parseEmit (  )  [protected]

Parse "event" grammar element.

Definition at line 643 of file parser.cpp.

Node* Aseba::Compiler::parseFor (  )  [protected]
Node * Aseba::Compiler::parseFor (  )  [protected]

Parse "for" grammar element.

Definition at line 505 of file parser.cpp.

Node* Aseba::Compiler::parseFunctionCall (  )  [protected]
Node * Aseba::Compiler::parseFunctionCall (  )  [protected]

Parse "function_call" grammar element.

Definition at line 1075 of file parser.cpp.

Node* Aseba::Compiler::parseIfWhen ( bool  edgeSensitive  )  [protected]
Node * Aseba::Compiler::parseIfWhen ( bool  edgeSensitive  )  [protected]

Parse "if" grammar element.

Definition at line 442 of file parser.cpp.

Node* Aseba::Compiler::parseMultExpression (  )  [protected]
Node * Aseba::Compiler::parseMultExpression (  )  [protected]

Parse "mult_expression" grammar element.

Definition at line 953 of file parser.cpp.

Node* Aseba::Compiler::parseNot (  )  [protected]
Node * Aseba::Compiler::parseNot (  )  [protected]

Parse "not" grammar element.

Definition at line 805 of file parser.cpp.

Node* Aseba::Compiler::parseOnEvent (  )  [protected]
Node * Aseba::Compiler::parseOnEvent (  )  [protected]

Parse "onevent" grammar element.

Definition at line 627 of file parser.cpp.

Node* Aseba::Compiler::parseOr (  )  [protected]
Node * Aseba::Compiler::parseOr (  )  [protected]

Parse "or" grammar element.

Definition at line 773 of file parser.cpp.

Node* Aseba::Compiler::parseProgram (  )  [protected]
Node * Aseba::Compiler::parseProgram (  )  [protected]

Parse "program" grammar element.

Definition at line 272 of file parser.cpp.

void Aseba::Compiler::parseReadVarArrayAccess ( unsigned *  addr,
unsigned *  size 
) [protected]
void Aseba::Compiler::parseReadVarArrayAccess ( unsigned *  addr,
unsigned *  size 
) [protected]

Parse access to variable, arrray, or array subscript.

Definition at line 712 of file parser.cpp.

Node* Aseba::Compiler::parseShiftExpression (  )  [protected]
Node * Aseba::Compiler::parseShiftExpression (  )  [protected]

Parse "shift_expression" grammar element.

Definition at line 915 of file parser.cpp.

Node* Aseba::Compiler::parseStatement (  )  [protected]
Node * Aseba::Compiler::parseStatement (  )  [protected]

Parse "statement" grammar element.

Definition at line 295 of file parser.cpp.

Node* Aseba::Compiler::parseSubDecl (  )  [protected]
Node * Aseba::Compiler::parseSubDecl (  )  [protected]

Parse "sub" grammar element, declaration of subroutine.

Definition at line 672 of file parser.cpp.

Node* Aseba::Compiler::parseUnaryExpression (  )  [protected]
Node * Aseba::Compiler::parseUnaryExpression (  )  [protected]

Parse "unary_expression" grammar element.

Definition at line 972 of file parser.cpp.

Node* Aseba::Compiler::parseVarDef (  )  [protected]
Node * Aseba::Compiler::parseVarDef (  )  [protected]

Parse "var def" grammar element.

Definition at line 323 of file parser.cpp.

Node* Aseba::Compiler::parseWhile (  )  [protected]
Node * Aseba::Compiler::parseWhile (  )  [protected]

Parse "while" grammar element.

Definition at line 602 of file parser.cpp.

void Aseba::Compiler::setCommonDefinitions ( const CommonDefinitions definitions  ) 
void Aseba::Compiler::setTargetDescription ( const TargetDescription description  ) 
void Aseba::Compiler::tokenize ( std::istream &  source  )  [protected]
void Aseba::Compiler::tokenize ( std::istream &  source  )  [protected]

Parse source and build tokens vector

Parameters:
source source code

Definition at line 133 of file lexer.cpp.

bool Aseba::Compiler::verifyStackCalls ( PreLinkBytecode preLinkBytecode  )  [protected]

Member Data Documentation

common definitions, such as events or some constants

Definition at line 368 of file compiler.h.

unsigned Aseba::Compiler::freeVariableIndex [protected]

index pointing to the first free variable

Definition at line 366 of file compiler.h.

functions lookup

Definition at line 363 of file compiler.h.

list of implemented events

Definition at line 362 of file compiler.h.

subroutine reverse lookup

Definition at line 365 of file compiler.h.

subroutine lookup

Definition at line 364 of file compiler.h.

description of the target VM

Definition at line 367 of file compiler.h.

std::deque< Token > Aseba::Compiler::tokens [protected]

parsed tokens

Definition at line 360 of file compiler.h.

variables lookup

Definition at line 361 of file compiler.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


asebaros
Author(s): $author
autogenerated on Mon Sep 5 08:42:13 2011