CHLLCode Class Reference

#include <codegen/chllcode.h>

Inheritance diagram for CHLLCode:

HLLCode List of all members.

Detailed Description

Outputs C code.

Definition at line 84 of file chllcode.h.

Public Member Functions

virtual void AddAssignmentStatement (int indLevel, Assign *asgn)
 Prints an assignment expression.
virtual void AddBreak (int indLevel)
 Adds: break;.
virtual void AddCallStatement (int indLevel, Proc *proc, const char *name, StatementList &args, StatementList *results)
 Adds a call to proc.
virtual void AddCaseCondElse (int indLevel)
 Adds: default:.
virtual void AddCaseCondEnd (int indLevel)
 Adds: }.
virtual void AddCaseCondHeader (int indLevel, Exp *cond)
 Adds: switch(cond) {.
virtual void AddCaseCondOption (int indLevel, Exp *opt)
 Adds: case opt :.
virtual void AddCaseCondOptionEnd (int indLevel)
 Adds: break;.
virtual void AddContinue (int indLevel)
 Adds: continue;.
virtual void AddEndlessLoopEnd (int indLevel)
 Adds: }.
virtual void AddEndlessLoopHeader (int indLevel)
 Adds: for(;;) {.
virtual void AddGlobal (const char *name, Type *type, Exp *init=NULL)
 Add the declaration for a global.
virtual void AddGoto (int indLevel, int ord)
 Adds: goto L ord.
virtual void AddIfCondEnd (int indLevel)
 Adds: }.
virtual void AddIfCondHeader (int indLevel, Exp *cond)
 Adds: if(cond) {.
virtual void AddIfElseCondEnd (int indLevel)
 Adds: }.
virtual void AddIfElseCondHeader (int indLevel, Exp *cond)
 Adds: if(cond) {.
virtual void AddIfElseCondOption (int indLevel)
 Adds: } else {.
virtual void AddIndCallStatement (int indLevel, Exp *exp, StatementList &args, StatementList *results)
 Adds an indirect call to exp.
virtual void AddLabel (int indLevel, int ord)
 Adds: L ord :.
virtual void AddLineComment (char *cmt)
 Adds one line of comment to the code.
virtual void AddLocal (const char *name, Type *type, bool last=false)
 Declare a local variable.
virtual void AddPosttestedLoopEnd (int indLevel, Exp *cond)
 Adds: } while (cond);.
virtual void AddPosttestedLoopHeader (int indLevel)
 Adds: do {.
virtual void AddPretestedLoopEnd (int indLevel)
 Adds: }.
virtual void AddPretestedLoopHeader (int indLevel, Exp *cond)
 Adds: while( cond) {.
virtual void AddProcEnd ()
 Adds: }.
virtual void AddProcStart (UserProc *proc)
 Print the start of a function, and also as a comment its address.
virtual void AddPrototype (UserProc *proc)
 Add a prototype (for forward declaration).
virtual void AddReturnStatement (int indLevel, StatementList *rets)
 Adds a return statement and returns the first expression in rets.
 CHLLCode (UserProc *p)
 Empty constructor, calls HLLCode(p).
 CHLLCode ()
 Empty constructor, calls HLLCode().
virtual void print (std::ostream &os)
 Dump all generated code to os.
virtual void RemoveLabel (int ord)
 Search for the label L ord and remove it from the generated code.
virtual void RemoveUnusedLabels (int maxOrd)
 Removes labels from the code which are not in usedLabels.
virtual void reset ()
 Remove all generated code.
virtual ~CHLLCode ()
 Empty destructor.

Private Member Functions

void AddProcDec (UserProc *proc, bool open)
 Print the declaration of a function.
void appendExp (std::ostringstream &str, Exp *exp, PREC curPrec, bool uns=false)
void appendLine (const std::string &s)
void appendLine (const std::ostringstream &ostr)
void appendType (std::ostringstream &str, Type *typ)
 Print the type represented by typ to str.
void appendTypeIdent (std::ostringstream &str, Type *typ, const char *ident)
 Print the indented type to str.
void closeParen (std::ostringstream &str, PREC outer, PREC inner)
 Adds: ).
void indent (std::ostringstream &str, int indLevel)
 Output 4 * indLevel spaces to str.
void openParen (std::ostringstream &str, PREC outer, PREC inner)
 Adds: (.

Private Attributes

std::list< char * > lines
 The generated code.
std::map< std::string, Type * > locals
 All locals in a Proc.
std::set< int > usedLabels
 All used goto labels.


Constructor & Destructor Documentation

CHLLCode::CHLLCode  ) 
 

Empty constructor, calls HLLCode().

Definition at line 50 of file chllcode.cpp.

CHLLCode::CHLLCode UserProc p  ) 
 

Empty constructor, calls HLLCode(p).

Definition at line 55 of file chllcode.cpp.

CHLLCode::~CHLLCode  )  [virtual]
 

Empty destructor.

Definition at line 60 of file chllcode.cpp.


Member Function Documentation

void CHLLCode::AddAssignmentStatement int  indLevel,
Assign asgn
[virtual]
 

Prints an assignment expression.

Implements HLLCode.

Definition at line 1209 of file chllcode.cpp.

References Boomerang::get(), Prog::getFrontEndId(), Assignment::getLeft(), Exp::getOper(), Statement::getProc(), Proc::getProg(), Assign::getRight(), Exp::getSubExp1(), TypingStatement::getType(), indent(), isBareMemof(), HLLCode::m_proc, opFsize, opPC, opRegOf, PLAT_SPARC, result, and Exp::search().

void CHLLCode::AddBreak int  indLevel  )  [virtual]
 

Adds: break;.

Implements HLLCode.

Definition at line 1168 of file chllcode.cpp.

References appendLine(), and indent().

void CHLLCode::AddCallStatement int  indLevel,
Proc proc,
const char *  name,
StatementList args,
StatementList results
[virtual]
 

Adds a call to proc.

Parameters:
indLevel A string containing spaces to the indentation level.
proc The Proc the call is to.
name The name the Proc has.
args The arguments to the call.
results The variable that will receive the return value of the function.
Todo:
Remove the name parameter and use Proc::getName()

Add assingment for when the function returns a struct.

Implements HLLCode.

Definition at line 1336 of file chllcode.cpp.

References appendExp(), StatementList::begin(), indent(), PREC_ASSIGN, and StatementList::size().

void CHLLCode::AddCaseCondElse int  indLevel  )  [virtual]
 

Adds: default:.

Implements HLLCode.

Definition at line 1070 of file chllcode.cpp.

References appendLine(), and indent().

void CHLLCode::AddCaseCondEnd int  indLevel  )  [virtual]
 

Adds: }.

Implements HLLCode.

Definition at line 1079 of file chllcode.cpp.

References appendLine(), and indent().

void CHLLCode::AddCaseCondHeader int  indLevel,
Exp cond
[virtual]
 

Adds: switch(cond) {.

Implements HLLCode.

Definition at line 1039 of file chllcode.cpp.

References appendExp(), appendLine(), indent(), and PREC_NONE.

void CHLLCode::AddCaseCondOption int  indLevel,
Exp opt
[virtual]
 

Adds: case opt :.

Implements HLLCode.

Definition at line 1050 of file chllcode.cpp.

References appendExp(), appendLine(), indent(), and PREC_NONE.

void CHLLCode::AddCaseCondOptionEnd int  indLevel  )  [virtual]
 

Adds: break;.

Implements HLLCode.

Definition at line 1061 of file chllcode.cpp.

References appendLine(), and indent().

void CHLLCode::AddContinue int  indLevel  )  [virtual]
 

Adds: continue;.

Implements HLLCode.

Definition at line 1160 of file chllcode.cpp.

References appendLine(), and indent().

void CHLLCode::AddEndlessLoopEnd int  indLevel  )  [virtual]
 

Adds: }.

Implements HLLCode.

Definition at line 1012 of file chllcode.cpp.

References appendLine(), and indent().

void CHLLCode::AddEndlessLoopHeader int  indLevel  )  [virtual]
 

Adds: for(;;) {.

Implements HLLCode.

Definition at line 1004 of file chllcode.cpp.

References appendLine(), and indent().

void CHLLCode::AddGlobal const char *  name,
Type type,
Exp init = NULL
[virtual]
 

Add the declaration for a global.

Parameters:
init The initial value of the global.

Implements HLLCode.

Definition at line 1602 of file chllcode.cpp.

References appendType(), and Type::isArray().

void CHLLCode::AddGoto int  indLevel,
int  ord
[virtual]
 

Adds: goto L ord.

Implements HLLCode.

Definition at line 1132 of file chllcode.cpp.

References appendLine(), indent(), and usedLabels.

void CHLLCode::AddIfCondEnd int  indLevel  )  [virtual]
 

Adds: }.

Implements HLLCode.

Definition at line 1098 of file chllcode.cpp.

References appendLine(), and indent().

void CHLLCode::AddIfCondHeader int  indLevel,
Exp cond
[virtual]
 

Adds: if(cond) {.

Implements HLLCode.

Definition at line 1088 of file chllcode.cpp.

References appendExp(), appendLine(), indent(), and PREC_NONE.

void CHLLCode::AddIfElseCondEnd int  indLevel  )  [virtual]
 

Adds: }.

Implements HLLCode.

Definition at line 1124 of file chllcode.cpp.

References appendLine(), and indent().

void CHLLCode::AddIfElseCondHeader int  indLevel,
Exp cond
[virtual]
 

Adds: if(cond) {.

Implements HLLCode.

Definition at line 1106 of file chllcode.cpp.

References appendExp(), appendLine(), indent(), and PREC_NONE.

void CHLLCode::AddIfElseCondOption int  indLevel  )  [virtual]
 

Adds: } else {.

Implements HLLCode.

Definition at line 1116 of file chllcode.cpp.

References appendLine(), and indent().

void CHLLCode::AddIndCallStatement int  indLevel,
Exp exp,
StatementList args,
StatementList results
[virtual]
 

Adds an indirect call to exp.

See also:
AddCallStatement
Parameters:
results UNUSED
Todo:
Add the use of results like AddCallStatement.

Implements HLLCode.

Definition at line 1401 of file chllcode.cpp.

References appendExp(), StatementList::begin(), StatementList::end(), indent(), PREC_COMMA, and PREC_NONE.

void CHLLCode::AddLabel int  indLevel,
int  ord
[virtual]
 

Adds: L ord :.

Implements HLLCode.

Definition at line 1176 of file chllcode.cpp.

References appendLine().

void CHLLCode::AddLineComment char *  cmt  )  [virtual]
 

Adds one line of comment to the code.

Implements HLLCode.

Definition at line 1645 of file chllcode.cpp.

References appendLine().

void CHLLCode::AddLocal const char *  name,
Type type,
bool  last = false
[virtual]
 

Declare a local variable.

Parameters:
last true if an empty line should be added.

Implements HLLCode.

Definition at line 1573 of file chllcode.cpp.

References appendExp(), appendLine(), appendTypeIdent(), Type::clone(), UserProc::expFromSymbol(), Exp::getOper(), Exp::getSubExp1(), indent(), locals, HLLCode::m_proc, opGlobal, opParam, opSubscript, PREC_NONE, and Exp::print().

void CHLLCode::AddPosttestedLoopEnd int  indLevel,
Exp cond
[virtual]
 

Adds: } while (cond);.

Implements HLLCode.

Definition at line 1028 of file chllcode.cpp.

References appendExp(), appendLine(), indent(), and PREC_NONE.

void CHLLCode::AddPosttestedLoopHeader int  indLevel  )  [virtual]
 

Adds: do {.

Implements HLLCode.

Definition at line 1020 of file chllcode.cpp.

References appendLine(), and indent().

void CHLLCode::AddPretestedLoopEnd int  indLevel  )  [virtual]
 

Adds: }.

Implements HLLCode.

Definition at line 996 of file chllcode.cpp.

References appendLine(), and indent().

void CHLLCode::AddPretestedLoopHeader int  indLevel,
Exp cond
[virtual]
 

Adds: while( cond) {.

Implements HLLCode.

Definition at line 983 of file chllcode.cpp.

References appendExp(), appendLine(), indent(), and PREC_NONE.

void CHLLCode::AddProcDec UserProc proc,
bool  open
[private]
 

Print the declaration of a function.

Parameters:
open False if this is just a prototype and ";" should be printed instead of "{"

Definition at line 1483 of file chllcode.cpp.

References Signature::getNumReturns(), Proc::getProg(), Signature::getReturnExp(), Signature::getReturnType(), Proc::getSignature(), Signature::getStackRegister(), UserProc::getTheReturnStatement(), Signature::isForced(), Exp::isRegN(), and NULL.

Referenced by AddProcStart(), and AddPrototype().

void CHLLCode::AddProcEnd  )  [virtual]
 

Adds: }.

Implements HLLCode.

Definition at line 1564 of file chllcode.cpp.

References appendLine().

void CHLLCode::AddProcStart UserProc proc  )  [virtual]
 

Print the start of a function, and also as a comment its address.

Implements HLLCode.

Definition at line 1467 of file chllcode.cpp.

References AddProcDec(), appendLine(), and Proc::getNativeAddress().

void CHLLCode::AddPrototype UserProc proc  )  [virtual]
 

Add a prototype (for forward declaration).

Implements HLLCode.

Definition at line 1475 of file chllcode.cpp.

References AddProcDec().

void CHLLCode::AddReturnStatement int  indLevel,
StatementList rets
[virtual]
 

Adds a return statement and returns the first expression in rets.

Todo:
This should be returning a struct if more than one real return value.

Implements HLLCode.

Definition at line 1427 of file chllcode.cpp.

References appendExp(), StatementList::begin(), StatementList::end(), Boomerang::get(), Signature::getNumReturns(), Proc::getSignature(), indent(), HLLCode::m_proc, PREC_NONE, and StatementList::size().

void CHLLCode::appendExp std::ostringstream &  str,
Exp exp,
PREC  curPrec,
bool  uns = false
[private]
 

Definition at line 82 of file chllcode.cpp.

References Exp::getOper(), Exp::isTypedExp(), UserProc::lookupSym(), HLLCode::m_proc, NULL, and progress.

Referenced by AddCallStatement(), AddCaseCondHeader(), AddCaseCondOption(), AddIfCondHeader(), AddIfElseCondHeader(), AddIndCallStatement(), AddLocal(), AddPosttestedLoopEnd(), AddPretestedLoopHeader(), and AddReturnStatement().

void CHLLCode::appendLine const std::string &  s  )  [private]
 

Definition at line 1657 of file chllcode.cpp.

References lines.

void CHLLCode::appendLine const std::ostringstream &  ostr  )  [private]
 

Definition at line 1653 of file chllcode.cpp.

Referenced by AddBreak(), AddCaseCondElse(), AddCaseCondEnd(), AddCaseCondHeader(), AddCaseCondOption(), AddCaseCondOptionEnd(), AddContinue(), AddEndlessLoopEnd(), AddEndlessLoopHeader(), AddGoto(), AddIfCondEnd(), AddIfCondHeader(), AddIfElseCondEnd(), AddIfElseCondHeader(), AddIfElseCondOption(), AddLabel(), AddLineComment(), AddLocal(), AddPosttestedLoopEnd(), AddPosttestedLoopHeader(), AddPretestedLoopEnd(), AddPretestedLoopHeader(), AddProcEnd(), and AddProcStart().

void CHLLCode::appendType std::ostringstream &  str,
Type typ
[private]
 

Print the type represented by typ to str.

Definition at line 927 of file chllcode.cpp.

References Type::asArray(), Type::asPointer(), ArrayType::getBaseType(), PointerType::getPointsTo(), NULL, Type::resolvesToArray(), and Type::resolvesToPointer().

Referenced by AddGlobal(), and appendTypeIdent().

void CHLLCode::appendTypeIdent std::ostringstream &  str,
Type typ,
const char *  ident
[private]
 

Print the indented type to str.

Definition at line 946 of file chllcode.cpp.

References appendType(), Type::asArray(), Type::asPointer(), ArrayType::getBaseType(), PointerType::getPointsTo(), Type::isArray(), Type::isPointer(), and NULL.

Referenced by AddLocal().

void CHLLCode::closeParen std::ostringstream &  str,
PREC  outer,
PREC  inner
[inline, private]
 

Adds: ).

Definition at line 97 of file chllcode.h.

void CHLLCode::indent std::ostringstream &  str,
int  indLevel
[private]
 

Output 4 * indLevel spaces to str.

Definition at line 65 of file chllcode.cpp.

Referenced by AddAssignmentStatement(), AddBreak(), AddCallStatement(), AddCaseCondElse(), AddCaseCondEnd(), AddCaseCondHeader(), AddCaseCondOption(), AddCaseCondOptionEnd(), AddContinue(), AddEndlessLoopEnd(), AddEndlessLoopHeader(), AddGoto(), AddIfCondEnd(), AddIfCondHeader(), AddIfElseCondEnd(), AddIfElseCondHeader(), AddIfElseCondOption(), AddIndCallStatement(), AddLocal(), AddPosttestedLoopEnd(), AddPosttestedLoopHeader(), AddPretestedLoopEnd(), AddPretestedLoopHeader(), and AddReturnStatement().

void CHLLCode::openParen std::ostringstream &  str,
PREC  outer,
PREC  inner
[inline, private]
 

Adds: (.

Definition at line 94 of file chllcode.h.

void CHLLCode::print std::ostream &  os  )  [virtual]
 

Dump all generated code to os.

Implements HLLCode.

Definition at line 1637 of file chllcode.cpp.

References lines, HLLCode::m_proc, and NULL.

void CHLLCode::RemoveLabel int  ord  )  [virtual]
 

Search for the label L ord and remove it from the generated code.

Implements HLLCode.

Definition at line 1183 of file chllcode.cpp.

References lines.

void CHLLCode::RemoveUnusedLabels int  maxOrd  )  [virtual]
 

Removes labels from the code which are not in usedLabels.

Parameters:
maxOrd UNUSED

Implements HLLCode.

Definition at line 1144 of file chllcode.cpp.

References lines, and usedLabels.

void CHLLCode::reset  )  [virtual]
 

Remove all generated code.

Reimplemented from HLLCode.

Definition at line 978 of file chllcode.cpp.

References lines.


Member Data Documentation

std::list<char *> CHLLCode::lines [private]
 

The generated code.

Definition at line 87 of file chllcode.h.

Referenced by appendLine(), print(), RemoveLabel(), RemoveUnusedLabels(), and reset().

std::map<std::string, Type*> CHLLCode::locals [private]
 

All locals in a Proc.

Definition at line 104 of file chllcode.h.

Referenced by AddLocal().

std::set<int> CHLLCode::usedLabels [private]
 

All used goto labels.

Definition at line 107 of file chllcode.h.

Referenced by AddGoto(), and RemoveUnusedLabels().


The documentation for this class was generated from the following files:
Generated on Tue Sep 19 21:18:41 2006 for Boomerang by  doxygen 1.4.6