Main Page | Class List | Directories | File List | Class Members | File Members

cc_code_gen.c File Reference

CKPM C compiler code generator. More...

#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "cpp_io.h"
#include "cc_scan.h"
#include "cc_symtab.h"
#include "cc_code_gen.h"

Functions

_codegenCodeGen_Create (int fd)
 create a code generator structure
void CodeGen_Destroy (struct _codegen *cg)
 destroy a code generator structure
void CodeGen_Dump (struct _codegen *cg, int fd)
 dump the code generator structure
void Increment_Level (struct _codegen *cg)
 increment the current level by one
void Decrement_Level (struct _codegen *cg)
 decrement the current level by one
int CG_Instr_Parms (int i)
 determine the length of the parameter of an instruction
void CG_Param (struct _codegen *cg, int p, int sz)
 emit a parameter of an instruction
void CG_Put (struct _codegen *cg, int i, int p, int sz)
 emit an instruction
void CG_Put_Cond_Operator (struct _codegen *cg, int i, int p, int sz)
 emit an instruction for conditionals
int CG_Put_Global_Data (struct _codegen *cg, char *dat, int len, int align)
 transfer data into the global data area
void CG_Link_Global_Data (struct _codegen *cg, char *name, int l)
 manage links to global data area
void CG_New_ExpImp (struct _codegen *cg, char *name, st_bind_t b, st_type_t t)
 create or update an entry in the symbol list
void CG_Link_ExpImp (struct _codegen *cg, char *name)
 handle the export and import list for symbols
void CG_Put_Branch (struct _codegen *cg, int i, int p)
 emit an branch instruction
void CG_Load (struct _codegen *cg, struct _item *x)
 load a variable onto the stack
int CG_Read_Short (struct _codegen *cg, int at)
 read two bytes from the code at a given address
int CG_Read_Long (struct _codegen *cg, int at)
 read four bytes from the code at a given address
void CG_Fix (struct _codegen *cg, int at, int with)
 do the branch destination fixup for relative addresses
void CG_Fix_Long (struct _codegen *cg, int at, int with)
 do the branch destination fixup for absolute addresses
int CG_Merged (struct _codegen *cg, int l0, int l1)
 merge two blocks
void CG_Fix_With (struct _codegen *cg, int l0, int l1)
void CG_Fix_Link (struct _codegen *cg, int l)
 do the branch destination fixup
void CG_Fix_Link_Long (struct _codegen *cg, int l)
 do the branch destination fixup
void CG_Put_Operator (struct _codegen *cg, int op, struct _item *x, struct _item *y)
 emit code for a logical operator
int CG_Negated_Operator (int op)
 determination of the negation of an operator
void CG_Call (struct _codegen *cg, struct _item *x, char *name)
 emit the code for a function call
void CG_Call_Predefined (struct _codegen *cg, struct _item *x, char *name)
 emit the code for a call of an predefined (builtin) function
int CG_Forward_Jump (struct _codegen *cg, int l)
 handle a forward jump to an (yet) unknown address
void CG_Backward_Jump (struct _codegen *cg, int l)
 handle a backward jump to an already known address
int CG_Function_Prolog (struct _codegen *cg, int par)
 emit code for the function prolog
void CG_Function_Epilog (struct _codegen *cg, int par, int loc, int f)
 emit code for the function epilog


Detailed Description

CKPM C compiler code generator.


Function Documentation

void CG_Backward_Jump struct _codegen cg,
int  l
 

handle a backward jump to an already known address

Parameters:
cg a pointer to the code generator
l the label to jump to

void CG_Call struct _codegen cg,
struct _item x,
char *  name
 

emit the code for a function call

Parameters:
cg a pointer to the code generator
x the function item
name the name of the external symbol in the export table

void CG_Call_Predefined struct _codegen cg,
struct _item x,
char *  name
 

emit the code for a call of an predefined (builtin) function

Parameters:
cg a pointer to the code generator
x the function item
name the name of the external symbol in the export table

void CG_Fix struct _codegen cg,
int  at,
int  with
 

do the branch destination fixup for relative addresses

Parameters:
cg a pointer to the code generator
at the address in the code of the parameter of a branch statement
with the new branch destination

void CG_Fix_Link struct _codegen cg,
int  l
 

do the branch destination fixup

Parameters:
cg a pointer to the code generator
l the address in the code of the parameter of a branch statement

void CG_Fix_Link_Long struct _codegen cg,
int  l
 

do the branch destination fixup

Parameters:
cg a pointer to the code generator
l the address in the code of the parameter of a branch statement

void CG_Fix_Long struct _codegen cg,
int  at,
int  with
 

do the branch destination fixup for absolute addresses

Parameters:
cg a pointer to the code generator
at the address in the code of the parameter of a branch statement
with the new branch destination

void CG_Fix_With struct _codegen cg,
int  l0,
int  l1
 

Parameters:
cg a pointer to the code generator
l0 the link 0
l1 the link 1

int CG_Forward_Jump struct _codegen cg,
int  l
 

handle a forward jump to an (yet) unknown address

Parameters:
cg a pointer to the code generator
l the label to jump to

void CG_Function_Epilog struct _codegen cg,
int  par,
int  loc,
int  f
 

emit code for the function epilog

Parameters:
cg a pointer to the code generator
par the number of parameters of the function
loc the size of the local variables
f the form of the return value on the stack

int CG_Function_Prolog struct _codegen cg,
int  par
 

emit code for the function prolog

Parameters:
cg a pointer to the code generator
par the size of all parameters of the function
Returns:
the address to fix the length of the local variables

int CG_Instr_Parms int  i  ) 
 

determine the length of the parameter of an instruction

Parameters:
i the given instruction
Returns:
the length of the parameter

void CG_Link_ExpImp struct _codegen cg,
char *  name
 

handle the export and import list for symbols

Parameters:
cg a pointer to the code generator
name the name of the symbol

void CG_Link_Global_Data struct _codegen cg,
char *  name,
int  l
 

manage links to global data area

Parameters:
cg a pointer to the code generator
name the name of the symbol
l the link to be fixed in the code area

void CG_Load struct _codegen cg,
struct _item x
 

load a variable onto the stack

Parameters:
cg a pointer to the code generator
x the item to be loaded

int CG_Merged struct _codegen cg,
int  l0,
int  l1
 

merge two blocks

Parameters:
cg a pointer to the code generator
l0 the link 0
l1 the link 1
Returns:
the new link

int CG_Negated_Operator int  op  ) 
 

determination of the negation of an operator

Parameters:
op the operator
Returns:
the negated operator

void CG_New_ExpImp struct _codegen cg,
char *  name,
st_bind_t  b,
st_type_t  t
 

create or update an entry in the symbol list

Parameters:
cg a pointer to the code generator
name the name of the symbol
b the link binding information
t the link type information

void CG_Param struct _codegen cg,
int  p,
int  sz
 

emit a parameter of an instruction

Parameters:
cg a pointer to the code generator
p the parameter value
sz the size of the parameter value

void CG_Put struct _codegen cg,
int  i,
int  p,
int  sz
 

emit an instruction

Parameters:
cg a pointer to the code generator
i the instruction code
p the parameter value
sz the size of the parameter value (optional)

void CG_Put_Branch struct _codegen cg,
int  i,
int  p
 

emit an branch instruction

Parameters:
cg a pointer to the code generator
i the instruction code
p the parameter value

void CG_Put_Cond_Operator struct _codegen cg,
int  i,
int  p,
int  sz
 

emit an instruction for conditionals

Parameters:
cg a pointer to the code generator
i the instruction symbol from the scanner
p the parameter value
sz the size of the parameter value (optional)

int CG_Put_Global_Data struct _codegen cg,
char *  dat,
int  len,
int  align
 

transfer data into the global data area

Parameters:
cg a pointer to the code generator
dat a pointer to the data to be transferred
len the length of the data
align is the alignment of the data in the global data area (1,2,4,8,...)

void CG_Put_Operator struct _codegen cg,
int  op,
struct _item x,
struct _item y
 

emit code for a logical operator

Parameters:
cg a pointer to the code generator
op the operator
x the first item
y the second item

int CG_Read_Long struct _codegen cg,
int  at
 

read four bytes from the code at a given address

Parameters:
cg a pointer to the code generator
at the address in the code
Returns:
the four bytes as an integer value

int CG_Read_Short struct _codegen cg,
int  at
 

read two bytes from the code at a given address

Parameters:
cg a pointer to the code generator
at the address in the code
Returns:
the two bytes as an integer value

struct _codegen* CodeGen_Create int  fd  ) 
 

create a code generator structure

Parameters:
fd a filedescriptor index for error messages
Returns:
a pointer to the newly created code generator

void CodeGen_Destroy struct _codegen cg  ) 
 

destroy a code generator structure

Parameters:
cg a pointer to the code generator

void CodeGen_Dump struct _codegen cg,
int  fd
 

dump the code generator structure

Parameters:
cg a pointer to the code generator
fd a file descriptor index to an open file

void Decrement_Level struct _codegen cg  ) 
 

decrement the current level by one

Parameters:
cg a pointer to the code generator

void Increment_Level struct _codegen cg  ) 
 

increment the current level by one

Parameters:
cg a pointer to the code generator


Generated on Thu Jul 13 03:56:36 2006 for CKPMcc by  doxygen 1.4.4