{
/* then depending on the expression value */
if (floatFromVal (condAst->opval.val))
- ifxNode = newNode (GOTO,
- newAst_VALUE (symbolVal (trueLabel)),
- NULL);
+ ifxNode = newNode (GOTO,
+ newAst_VALUE (symbolVal (trueLabel)),
+ NULL);
else
- ifxNode = newNode (GOTO,
- newAst_VALUE (symbolVal (falseLabel)),
- NULL);
+ ifxNode = newNode (GOTO,
+ newAst_VALUE (symbolVal (falseLabel)),
+ NULL);
}
else
{
case SWITCH:
dest->values.switchVals.swVals =
- copyValue (src->values.switchVals.swVals);
+ copyValue (src->values.switchVals.swVals);
dest->values.switchVals.swDefault =
- src->values.switchVals.swDefault;
+ src->values.switchVals.swDefault;
dest->values.switchVals.swNum =
- src->values.switchVals.swNum;
+ src->values.switchVals.swNum;
break;
case INLINEASM:
break;
case ARRAYINIT:
- dest->values.constlist = copyLiteralList(src->values.constlist);
- break;
+ dest->values.constlist = copyLiteralList(src->values.constlist);
+ break;
case FOR:
AST_FOR (dest, trueLabel) = copySymbol (AST_FOR (src, trueLabel));
return TRUE;
return (hasSEFcalls (tree->left) |
- hasSEFcalls (tree->right));
+ hasSEFcalls (tree->right));
}
/*-----------------------------------------------------------------*/
{
case EX_OP:
if (t1->opval.op != t2->opval.op)
- return 0;
+ return 0;
return (isAstEqual (t1->left, t2->left) &&
- isAstEqual (t1->right, t2->right));
+ isAstEqual (t1->right, t2->right));
break;
case EX_VALUE:
if (t1->opval.val->sym)
- {
- if (!t2->opval.val->sym)
- return 0;
- else
- return isSymbolEqual (t1->opval.val->sym,
- t2->opval.val->sym);
- }
+ {
+ if (!t2->opval.val->sym)
+ return 0;
+ else
+ return isSymbolEqual (t1->opval.val->sym,
+ t2->opval.val->sym);
+ }
else
- {
- if (t2->opval.val->sym)
- return 0;
- else
- return (floatFromVal (t1->opval.val) ==
- floatFromVal (t2->opval.val));
- }
+ {
+ if (t2->opval.val->sym)
+ return 0;
+ else
+ return (floatFromVal (t1->opval.val) ==
+ floatFromVal (t2->opval.val));
+ }
break;
/* only compare these two types */
symbol *csym;
if (tree->trueLabel)
- {
- if ((csym = findSym (LabelTab, tree->trueLabel,
- tree->trueLabel->name)))
- tree->trueLabel = csym;
- else
- werrorfl (tree->filename, tree->lineno, E_LABEL_UNDEF,
- tree->trueLabel->name);
- }
+ {
+ if ((csym = findSym (LabelTab, tree->trueLabel,
+ tree->trueLabel->name)))
+ tree->trueLabel = csym;
+ else
+ werrorfl (tree->filename, tree->lineno, E_LABEL_UNDEF,
+ tree->trueLabel->name);
+ }
if (tree->falseLabel)
- {
- if ((csym = findSym (LabelTab,
- tree->falseLabel,
- tree->falseLabel->name)))
- tree->falseLabel = csym;
- else
- werrorfl (tree->filename, tree->lineno, E_LABEL_UNDEF,
- tree->falseLabel->name);
- }
+ {
+ if ((csym = findSym (LabelTab,
+ tree->falseLabel,
+ tree->falseLabel->name)))
+ tree->falseLabel = csym;
+ else
+ werrorfl (tree->filename, tree->lineno, E_LABEL_UNDEF,
+ tree->falseLabel->name);
+ }
}
{
symbol *csym = findSym (LabelTab, tree->opval.val->sym,
- tree->opval.val->sym->name);
+ tree->opval.val->sym->name);
if (!csym)
- werrorfl (tree->filename, tree->lineno, E_LABEL_UNDEF,
- tree->opval.val->sym->name);
+ werrorfl (tree->filename, tree->lineno, E_LABEL_UNDEF,
+ tree->opval.val->sym->name);
else
- tree->opval.val->sym = csym;
+ tree->opval.val->sym = csym;
goto resolveChildren;
}
/* if found in the symbol table & they r not the same */
if (csym && tree->opval.val->sym != csym)
- {
- tree->opval.val->sym = csym;
- tree->opval.val->type = csym->type;
- tree->opval.val->etype = csym->etype;
- }
+ {
+ tree->opval.val->sym = csym;
+ tree->opval.val->type = csym->type;
+ tree->opval.val->etype = csym->etype;
+ }
/* if not found in the symbol table */
/* mark it as undefined assume it is */
/* an integer in data space */
if (!csym && !tree->opval.val->sym->implicit)
- {
-
- /* if this is a function name then */
- /* mark it as returning an int */
- if (tree->funcName)
- {
- tree->opval.val->sym->type = newLink (DECLARATOR);
- DCL_TYPE (tree->opval.val->sym->type) = FUNCTION;
- tree->opval.val->sym->type->next =
- tree->opval.val->sym->etype = newIntLink ();
- tree->opval.val->etype = tree->opval.val->etype;
- tree->opval.val->type = tree->opval.val->sym->type;
- werrorfl (tree->filename, tree->lineno, W_IMPLICIT_FUNC,
- tree->opval.val->sym->name);
- //tree->opval.val->sym->undefined = 1;
- allocVariables (tree->opval.val->sym);
- }
- else
- {
- tree->opval.val->sym->undefined = 1;
- tree->opval.val->type =
- tree->opval.val->etype = newIntLink ();
- tree->opval.val->sym->type =
- tree->opval.val->sym->etype = newIntLink ();
- }
- }
+ {
+
+ /* if this is a function name then */
+ /* mark it as returning an int */
+ if (tree->funcName)
+ {
+ tree->opval.val->sym->type = newLink (DECLARATOR);
+ DCL_TYPE (tree->opval.val->sym->type) = FUNCTION;
+ tree->opval.val->sym->type->next =
+ tree->opval.val->sym->etype = newIntLink ();
+ tree->opval.val->etype = tree->opval.val->etype;
+ tree->opval.val->type = tree->opval.val->sym->type;
+ werrorfl (tree->filename, tree->lineno, W_IMPLICIT_FUNC,
+ tree->opval.val->sym->name);
+ //tree->opval.val->sym->undefined = 1;
+ allocVariables (tree->opval.val->sym);
+ }
+ else
+ {
+ tree->opval.val->sym->undefined = 1;
+ tree->opval.val->type =
+ tree->opval.val->etype = newIntLink ();
+ tree->opval.val->sym->type =
+ tree->opval.val->sym->etype = newIntLink ();
+ }
+ }
}
resolveChildren:
/*-----------------------------------------------------------------*/
symbol *
funcOfType (char *name, sym_link * type, sym_link * argType,
- int nArgs, int rent)
+ int nArgs, int rent)
{
symbol *sym;
/* create the symbol */
args = FUNC_ARGS(sym->type) = newValue ();
while (nArgs--)
- {
- args->type = copyLinkChain (argType);
- args->etype = getSpec (args->type);
- SPEC_EXTR(args->etype)=1;
- if (!nArgs)
- break;
- args = args->next = newValue ();
- }
+ {
+ args->type = copyLinkChain (argType);
+ args->etype = getSpec (args->type);
+ SPEC_EXTR(args->etype)=1;
+ if (!nArgs)
+ break;
+ args = args->next = newValue ();
+ }
}
/* save it */
/* if arguments required */
if (nArgs) {
- value *args;
- args = FUNC_ARGS(sym->type) = newValue ();
-
- for ( i = 0 ; i < nArgs ; i++ ) {
- args->type = typeFromStr(atypes[i]);
- args->etype = getSpec (args->type);
- SPEC_EXTR(args->etype)=1;
- if ((i + 1) == nArgs) break;
- args = args->next = newValue ();
- }
+ value *args;
+ args = FUNC_ARGS(sym->type) = newValue ();
+
+ for ( i = 0 ; i < nArgs ; i++ ) {
+ args->type = typeFromStr(atypes[i]);
+ args->etype = getSpec (args->type);
+ SPEC_EXTR(args->etype)=1;
+ if ((i + 1) == nArgs) break;
+ args = args->next = newValue ();
+ }
}
/* save it */
/*-----------------------------------------------------------------*/
static int
processParms (ast *func,
- value *defParm,
- ast **actParm,
- int *parmNumber, /* unused, although updated */
- bool rightmost)
+ value *defParm,
+ ast **actParm,
+ int *parmNumber, /* unused, although updated */
+ bool rightmost)
{
RESULT_TYPE resultType;
sym_link *functype;
{
(*actParm)->decorated = 1;
return (processParms (func, defParm,
- &(*actParm)->left, parmNumber, FALSE) ||
- processParms (func, defParm ? defParm->next : NULL,
- &(*actParm)->right, parmNumber, rightmost));
+ &(*actParm)->left, parmNumber, FALSE) ||
+ processParms (func, defParm ? defParm->next : NULL,
+ &(*actParm)->right, parmNumber, rightmost));
}
else if (defParm) /* not vararg */
{
* supply enough.
*/
if (rightmost && defParm->next)
- {
- werror (E_TOO_FEW_PARMS);
- return 1;
- }
+ {
+ werror (E_TOO_FEW_PARMS);
+ return 1;
+ }
}
/* decorate parameter */
sym_link *ftype;
if (IS_CAST_OP (*actParm)
- || (IS_AST_LIT_VALUE (*actParm) && (*actParm)->values.literalFromCast))
- {
- /* Parameter was explicitly typecast; don't touch it. */
- return 0;
- }
+ || (IS_AST_LIT_VALUE (*actParm) && (*actParm)->values.literalFromCast))
+ {
+ /* Parameter was explicitly typecast; don't touch it. */
+ return 0;
+ }
ftype = (*actParm)->ftype;
/* If it's a char, upcast to int. */
if (IS_INTEGRAL (ftype)
- && (getSize (ftype) < (unsigned) INTSIZE))
- {
- newType = newAst_LINK(INTTYPE);
- }
+ && (getSize (ftype) < (unsigned) INTSIZE))
+ {
+ newType = newAst_LINK(INTTYPE);
+ }
if (IS_PTR(ftype) && !IS_GENPTR(ftype))
- {
- newType = newAst_LINK (copyLinkChain(ftype));
- DCL_TYPE (newType->opval.lnk) = port->unqualified_pointer;
- }
+ {
+ newType = newAst_LINK (copyLinkChain(ftype));
+ DCL_TYPE (newType->opval.lnk) = port->unqualified_pointer;
+ }
if (IS_AGGREGATE (ftype))
- {
- newType = newAst_LINK (copyLinkChain (ftype));
- DCL_TYPE (newType->opval.lnk) = port->unqualified_pointer;
- }
+ {
+ newType = newAst_LINK (copyLinkChain (ftype));
+ DCL_TYPE (newType->opval.lnk) = port->unqualified_pointer;
+ }
if (newType)
{
{
/* if we have come to end */
if (!iloop)
- break;
+ break;
sflds->implicit = 1;
lAst = newNode (PTR_OP, newNode ('&', sym, NULL), newAst_VALUE (symbolVal (sflds)));
lAst = decorateType (resolveSymbols (lAst), RESULT_CHECK);
if (iloop) {
werrorfl (sym->opval.val->sym->fileDef, sym->opval.val->sym->lineDef,
- W_EXCESS_INITIALIZERS, "struct",
- sym->opval.val->sym->name);
+ W_EXCESS_INITIALIZERS, "struct",
+ sym->opval.val->sym->name);
}
return rast;
/* by a string */
if (IS_CHAR (type->next))
if ((rast = createIvalCharPtr (sym,
- type,
- decorateType (resolveSymbols (list2expr (ilist)), RESULT_CHECK))))
+ type,
+ decorateType (resolveSymbols (list2expr (ilist)), RESULT_CHECK))))
return decorateType (resolveSymbols (rast), RESULT_CHECK);
/* not the special case */
if (ilist->type != INIT_DEEP)
{
- werror (E_INIT_STRUCT, "");
- return NULL;
+ werror (E_INIT_STRUCT, "");
+ return NULL;
}
iloop = ilist->init.deep;
if (port->arrayInitializerSuppported && convertIListToConstList(ilist, &literalL))
{
- ast *aSym;
-
- aSym = decorateType (resolveSymbols(sym), RESULT_CHECK);
-
- rast = newNode(ARRAYINIT, aSym, NULL);
- rast->values.constlist = literalL;
-
- // Make sure size is set to length of initializer list.
- while (iloop)
- {
- size++;
- iloop = iloop->next;
- }
-
- if (lcnt && size > lcnt)
- {
- // Array size was specified, and we have more initializers than needed.
- char *name=sym->opval.val->sym->name;
- int lineno=sym->opval.val->sym->lineDef;
- char *filename=sym->opval.val->sym->fileDef;
-
- werrorfl (filename, lineno, W_EXCESS_INITIALIZERS, "array", name);
- }
+ ast *aSym;
+
+ aSym = decorateType (resolveSymbols(sym), RESULT_CHECK);
+
+ rast = newNode(ARRAYINIT, aSym, NULL);
+ rast->values.constlist = literalL;
+
+ // Make sure size is set to length of initializer list.
+ while (iloop)
+ {
+ size++;
+ iloop = iloop->next;
+ }
+
+ if (lcnt && size > lcnt)
+ {
+ // Array size was specified, and we have more initializers than needed.
+ char *name=sym->opval.val->sym->name;
+ int lineno=sym->opval.val->sym->lineDef;
+ char *filename=sym->opval.val->sym->fileDef;
+
+ werrorfl (filename, lineno, W_EXCESS_INITIALIZERS, "array", name);
+ }
}
else
{
- for (;;)
- {
- ast *aSym;
-
- aSym = newNode ('[', sym, newAst_VALUE (valueFromLit ((float) (size++))));
- aSym = decorateType (resolveSymbols (aSym), RESULT_CHECK);
- rast = createIval (aSym, type->next, iloop, rast);
- iloop = (iloop ? iloop->next : NULL);
- if (!iloop)
- {
- break;
- }
-
- /* no of elements given and we */
- /* have generated for all of them */
- if (!--lcnt)
- {
- // there has to be a better way
- char *name=sym->opval.val->sym->name;
- int lineno=sym->opval.val->sym->lineDef;
- char *filename=sym->opval.val->sym->fileDef;
- werrorfl (filename, lineno, W_EXCESS_INITIALIZERS, "array", name);
-
- break;
- }
- }
+ for (;;)
+ {
+ ast *aSym;
+
+ aSym = newNode ('[', sym, newAst_VALUE (valueFromLit ((float) (size++))));
+ aSym = decorateType (resolveSymbols (aSym), RESULT_CHECK);
+ rast = createIval (aSym, type->next, iloop, rast);
+ iloop = (iloop ? iloop->next : NULL);
+ if (!iloop)
+ {
+ break;
+ }
+
+ /* no of elements given and we */
+ /* have generated for all of them */
+ if (!--lcnt)
+ {
+ // is this a better way? at least it won't crash
+ char *name = (IS_AST_SYM_VALUE(sym)) ? AST_SYMBOL(sym)->name : "";
+ int lineno = iloop->lineno;
+ char *filename = iloop->filename;
+ werrorfl (filename, lineno, W_EXCESS_INITIALIZERS, "array", name);
+
+ break;
+ }
+ }
}
/* if we have not been given a size */
if (!DCL_ELEM (type))
{
- DCL_ELEM (type) = size;
+ /* but this still updates the typedef instead of the instance ! see bug 770487 */
+ DCL_ELEM (type) = size;
}
return decorateType (resolveSymbols (rast), RESULT_CHECK);
/* if this is a pointer & right is a literal array then */
/* just assignment will do */
if (IS_PTR (type) && ((IS_LITERAL (iexpr->etype) ||
- SPEC_SCLS (iexpr->etype) == S_CODE)
- && IS_ARRAY (iexpr->ftype)))
+ SPEC_SCLS (iexpr->etype) == S_CODE)
+ && IS_ARRAY (iexpr->ftype)))
return newNode ('=', sym, iexpr);
/* left side is an array so we have to assign each */
if (size>symsize)
{
- if (size>(symsize+1))
- werrorfl (iexpr->filename, iexpr->lineno, W_EXCESS_INITIALIZERS,
- "string", sym->opval.val->sym->name);
- size = symsize;
- }
+ if (size>(symsize+1))
+ werrorfl (iexpr->filename, iexpr->lineno, W_EXCESS_INITIALIZERS,
+ "string", sym->opval.val->sym->name);
+ size = symsize;
+ }
for (i=0;i<size;i++)
- {
- rast = newNode (NULLOP,
- rast,
- newNode ('=',
- newNode ('[', sym,
- newAst_VALUE (valueFromLit ((float) i))),
- newAst_VALUE (valueFromLit (*s))));
- s++;
- }
+ {
+ rast = newNode (NULLOP,
+ rast,
+ newNode ('=',
+ newNode ('[', sym,
+ newAst_VALUE (valueFromLit ((float) i))),
+ newAst_VALUE (valueFromLit (*s))));
+ s++;
+ }
// now WE don't need iexpr's symbol anymore
freeStringSymbol(AST_SYMBOL(iexpr));
/* resolve the symbols in the ival */
if (sym->ival)
- resolveIvalSym (sym->ival, sym->type);
+ resolveIvalSym (sym->ival, sym->type);
/* if this is a static variable & has an */
/* initial value the code needs to be lifted */
/* here to the main portion since they can be */
/* initialised only once at the start */
if (IS_STATIC (sym->etype) && sym->ival &&
- SPEC_SCLS (sym->etype) != S_CODE)
- {
- symbol *newSym;
-
- /* insert the symbol into the symbol table */
- /* with level = 0 & name = rname */
- newSym = copySymbol (sym);
- addSym (SymbolTab, newSym, newSym->rname, 0, 0, 1);
-
- /* now lift the code to main */
- if (IS_AGGREGATE (sym->type)) {
- work = initAggregates (sym, sym->ival, NULL);
- } else {
- if (getNelements(sym->type, sym->ival)>1) {
- werrorfl (sym->fileDef, sym->lineDef,
- W_EXCESS_INITIALIZERS, "scalar",
- sym->name);
- }
- work = newNode ('=', newAst_VALUE (symbolVal (newSym)),
- list2expr (sym->ival));
- }
-
- setAstLineno (work, sym->lineDef);
-
- sym->ival = NULL;
- if (staticAutos)
- staticAutos = newNode (NULLOP, staticAutos, work);
- else
- staticAutos = work;
-
- continue;
- }
+ SPEC_SCLS (sym->etype) != S_CODE)
+ {
+ symbol *newSym;
+
+ /* insert the symbol into the symbol table */
+ /* with level = 0 & name = rname */
+ newSym = copySymbol (sym);
+ addSym (SymbolTab, newSym, newSym->rname, 0, 0, 1);
+
+ /* now lift the code to main */
+ if (IS_AGGREGATE (sym->type)) {
+ work = initAggregates (sym, sym->ival, NULL);
+ } else {
+ if (getNelements(sym->type, sym->ival)>1) {
+ werrorfl (sym->fileDef, sym->lineDef,
+ W_EXCESS_INITIALIZERS, "scalar",
+ sym->name);
+ }
+ work = newNode ('=', newAst_VALUE (symbolVal (newSym)),
+ list2expr (sym->ival));
+ }
+
+ setAstLineno (work, sym->lineDef);
+
+ sym->ival = NULL;
+ if (staticAutos)
+ staticAutos = newNode (NULLOP, staticAutos, work);
+ else
+ staticAutos = work;
+
+ continue;
+ }
/* if there is an initial value */
if (sym->ival && SPEC_SCLS (sym->etype) != S_CODE)
- {
- initList *ilist=sym->ival;
-
- while (ilist->type == INIT_DEEP) {
- ilist = ilist->init.deep;
- }
-
- /* update lineno for error msg */
- lineno=sym->lineDef;
- setAstLineno (ilist->init.node, lineno);
-
- if (IS_AGGREGATE (sym->type)) {
- work = initAggregates (sym, sym->ival, NULL);
- } else {
- if (getNelements(sym->type, sym->ival)>1) {
- werrorfl (sym->fileDef, sym->lineDef,
- W_EXCESS_INITIALIZERS, "scalar",
- sym->name);
- }
- work = newNode ('=', newAst_VALUE (symbolVal (sym)),
- list2expr (sym->ival));
- }
-
- // just to be sure
- setAstLineno (work, sym->lineDef);
-
- sym->ival = NULL;
- if (init)
- init = newNode (NULLOP, init, work);
- else
- init = work;
- }
+ {
+ initList *ilist=sym->ival;
+
+ while (ilist->type == INIT_DEEP) {
+ ilist = ilist->init.deep;
+ }
+
+ /* update lineno for error msg */
+ lineno=sym->lineDef;
+ setAstLineno (ilist->init.node, lineno);
+
+ if (IS_AGGREGATE (sym->type)) {
+ work = initAggregates (sym, sym->ival, NULL);
+ } else {
+ if (getNelements(sym->type, sym->ival)>1) {
+ werrorfl (sym->fileDef, sym->lineDef,
+ W_EXCESS_INITIALIZERS, "scalar",
+ sym->name);
+ }
+ work = newNode ('=', newAst_VALUE (symbolVal (sym)),
+ list2expr (sym->ival));
+ }
+
+ // just to be sure
+ setAstLineno (work, sym->lineDef);
+
+ sym->ival = NULL;
+ if (init)
+ init = newNode (NULLOP, init, work);
+ else
+ init = work;
+ }
}
inInitMode = 0;
return init;
sym=sp->item;
size = getSize (sym->type);
if (sym->isstrlit && size == getSize (val->type) &&
- !memcmp(SPEC_CVAL(sym->etype).v_char, SPEC_CVAL(val->etype).v_char, size)) {
+ !memcmp(SPEC_CVAL(sym->etype).v_char, SPEC_CVAL(val->etype).v_char, size)) {
// yes, this is old news. Don't publish it again.
sym->isstrlit++; // but raise the usage count
return symbolVal(sym);
}
SNPRINTF (name, sizeof(name), "_str_%d", charLbl++);
- sym = newSymbol (name, 0); /* make it @ level 0 */
+ sym = newSymbol (name, 0); /* make it @ level 0 */
strncpyz (sym->rname, name, SDCC_NAME_MAX);
/* copy the type from the value passed */
if (action == ALLOCATE)
{
- *stack += allocVariables (tree->values.sym);
- autoInit = gatherAutoInit (tree->values.sym);
-
- /* if there are auto inits then do them */
- if (autoInit)
- tree->left = newNode (NULLOP, autoInit, tree->left);
+ *stack += allocVariables (tree->values.sym);
+ autoInit = gatherAutoInit (tree->values.sym);
+
+ /* if there are auto inits then do them */
+ if (autoInit)
+ tree->left = newNode (NULLOP, autoInit, tree->left);
}
- else /* action is deallocate */
- deallocLocal (tree->values.sym);
+ else /* action is deallocate */
+ deallocLocal (tree->values.sym);
}
processBlockVars (tree->left, stack, action);
{
case EX_VALUE:
if (IS_AST_LIT_VALUE(cexpr)) {
- // this is a literal
- return TRUE;
+ // this is a literal
+ return TRUE;
}
if (IS_AST_SYM_VALUE(cexpr) && IS_FUNC(AST_SYMBOL(cexpr)->type)) {
- // a function's address will never change
- return TRUE;
+ // a function's address will never change
+ return TRUE;
}
if (IS_AST_SYM_VALUE(cexpr) && IS_ARRAY(AST_SYMBOL(cexpr)->type)) {
- // an array's address will never change
- return TRUE;
+ // an array's address will never change
+ return TRUE;
}
if (IS_AST_SYM_VALUE(cexpr) &&
- IN_CODESPACE(SPEC_OCLS(AST_SYMBOL(cexpr)->etype))) {
- // a symbol in code space will never change
- // This is only for the 'char *s="hallo"' case and will have to leave
+ IN_CODESPACE(SPEC_OCLS(AST_SYMBOL(cexpr)->etype))) {
+ // a symbol in code space will never change
+ // This is only for the 'char *s="hallo"' case and will have to leave
//printf(" code space symbol");
- return TRUE;
+ return TRUE;
}
return FALSE;
case EX_LINK:
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
- "unexpected link in expression tree\n");
+ "unexpected link in expression tree\n");
return FALSE;
case EX_OP:
if (cexpr->opval.op==ARRAYINIT) {
- // this is a list of literals
- return TRUE;
+ // this is a list of literals
+ return TRUE;
}
if (cexpr->opval.op=='=') {
- return constExprTree(cexpr->right);
+ return constExprTree(cexpr->right);
}
if (cexpr->opval.op==CAST) {
- // cast ignored, maybe we should throw a warning here?
- return constExprTree(cexpr->right);
+ // cast ignored, maybe we should throw a warning here?
+ return constExprTree(cexpr->right);
}
if (cexpr->opval.op=='&') {
- return TRUE;
+ return TRUE;
}
if (cexpr->opval.op==CALL || cexpr->opval.op==PCALL) {
- return FALSE;
+ return FALSE;
}
if (constExprTree(cexpr->left) && constExprTree(cexpr->right)) {
- return TRUE;
+ return TRUE;
}
return FALSE;
case EX_OPERAND:
/* then check if this is a literal array
in code segment */
if (SPEC_SCLS (cexpr->etype) == S_CODE &&
- SPEC_CVAL (cexpr->etype).v_char &&
- IS_ARRAY (cexpr->ftype))
- {
- value *val = valFromType (cexpr->ftype);
- SPEC_SCLS (val->etype) = S_LITERAL;
- val->sym = cexpr->opval.val->sym;
- val->sym->type = copyLinkChain (cexpr->ftype);
- val->sym->etype = getSpec (val->sym->type);
- strncpyz (val->name, cexpr->opval.val->sym->rname, SDCC_NAME_MAX);
- return val;
- }
+ SPEC_CVAL (cexpr->etype).v_char &&
+ IS_ARRAY (cexpr->ftype))
+ {
+ value *val = valFromType (cexpr->ftype);
+ SPEC_SCLS (val->etype) = S_LITERAL;
+ val->sym = cexpr->opval.val->sym;
+ val->sym->type = copyLinkChain (cexpr->ftype);
+ val->sym->etype = getSpec (val->sym->type);
+ strncpyz (val->name, cexpr->opval.val->sym->rname, SDCC_NAME_MAX);
+ return val;
+ }
/* if we are casting a literal value then */
if (IS_AST_OP (cexpr) &&
- cexpr->opval.op == CAST &&
- IS_LITERAL (cexpr->right->ftype))
+ cexpr->opval.op == CAST &&
+ IS_LITERAL (cexpr->right->ftype))
{
- return valCastLiteral (cexpr->ftype,
- floatFromVal (cexpr->right->opval.val));
+ return valCastLiteral (cexpr->ftype,
+ floatFromVal (cexpr->right->opval.val));
}
if (IS_AST_VALUE (cexpr))
{
- return cexpr->opval.val;
+ return cexpr->opval.val;
}
if (check)
- werror (E_CONST_EXPECTED, "found expression");
+ werror (E_CONST_EXPECTED, "found expression");
return NULL;
}
/*-----------------------------------------------------------------*/
bool
isLoopCountable (ast * initExpr, ast * condExpr, ast * loopExpr,
- symbol ** sym, ast ** init, ast ** end)
+ symbol ** sym, ast ** init, ast ** end)
{
/* the loop is considered countable if the following
/* first check the initExpr */
if (IS_AST_OP (initExpr) &&
- initExpr->opval.op == '=' && /* is assignment */
+ initExpr->opval.op == '=' && /* is assignment */
IS_AST_SYM_VALUE (initExpr->left))
- { /* left is a symbol */
+ { /* left is a symbol */
*sym = AST_SYMBOL (initExpr->left);
*init = initExpr->right;
{
switch (condExpr->opval.op)
- {
- case '<':
- if (IS_AST_SYM_VALUE (condExpr->left) &&
- isSymbolEqual (*sym, AST_SYMBOL (condExpr->left)) &&
- IS_AST_LIT_VALUE (condExpr->right))
- {
- *end = condExpr->right;
- break;
- }
- return FALSE;
-
- case '!':
- if (IS_AST_OP (condExpr->left) &&
- condExpr->left->opval.op == '>' &&
- IS_AST_LIT_VALUE (condExpr->left->right) &&
- IS_AST_SYM_VALUE (condExpr->left->left) &&
- isSymbolEqual (*sym, AST_SYMBOL (condExpr->left->left)))
- {
-
- *end = newNode ('+', condExpr->left->right,
- newAst_VALUE (constVal ("1")));
- break;
- }
- return FALSE;
-
- default:
- return FALSE;
- }
+ {
+ case '<':
+ if (IS_AST_SYM_VALUE (condExpr->left) &&
+ isSymbolEqual (*sym, AST_SYMBOL (condExpr->left)) &&
+ IS_AST_LIT_VALUE (condExpr->right))
+ {
+ *end = condExpr->right;
+ break;
+ }
+ return FALSE;
+
+ case '!':
+ if (IS_AST_OP (condExpr->left) &&
+ condExpr->left->opval.op == '>' &&
+ IS_AST_LIT_VALUE (condExpr->left->right) &&
+ IS_AST_SYM_VALUE (condExpr->left->left) &&
+ isSymbolEqual (*sym, AST_SYMBOL (condExpr->left->left)))
+ {
+
+ *end = newNode ('+', condExpr->left->right,
+ newAst_VALUE (constVal ("1")));
+ break;
+ }
+ return FALSE;
+
+ default:
+ return FALSE;
+ }
}
{
if (loopExpr->left)
- {
- /* pre */
- if (IS_AST_SYM_VALUE (loopExpr->left) &&
- isSymbolEqual (*sym, AST_SYMBOL (loopExpr->left)))
- return TRUE;
+ {
+ /* pre */
+ if (IS_AST_SYM_VALUE (loopExpr->left) &&
+ isSymbolEqual (*sym, AST_SYMBOL (loopExpr->left)))
+ return TRUE;
- }
+ }
else
- {
- /* post */
- if (IS_AST_SYM_VALUE (loopExpr->right) &&
- isSymbolEqual (*sym, AST_SYMBOL (loopExpr->right)))
- return TRUE;
- }
+ {
+ /* post */
+ if (IS_AST_SYM_VALUE (loopExpr->right) &&
+ isSymbolEqual (*sym, AST_SYMBOL (loopExpr->right)))
+ return TRUE;
+ }
}
else
{
/* check for += */
if (loopExpr->opval.op == ADD_ASSIGN)
- {
-
- if (IS_AST_SYM_VALUE (loopExpr->left) &&
- isSymbolEqual (*sym, AST_SYMBOL (loopExpr->left)) &&
- IS_AST_LIT_VALUE (loopExpr->right) &&
- (int) AST_LIT_VALUE (loopExpr->right) != 1)
- return TRUE;
- }
+ {
+
+ if (IS_AST_SYM_VALUE (loopExpr->left) &&
+ isSymbolEqual (*sym, AST_SYMBOL (loopExpr->left)) &&
+ IS_AST_LIT_VALUE (loopExpr->right) &&
+ (int) AST_LIT_VALUE (loopExpr->right) != 1)
+ return TRUE;
+ }
}
return FALSE;
if (IS_AST_VALUE (tree))
{
if (IS_AST_SYM_VALUE (tree))
- return isSymbolEqual (AST_SYMBOL (tree), sym);
+ return isSymbolEqual (AST_SYMBOL (tree), sym);
else
- return FALSE;
+ return FALSE;
}
return astHasSymbol (tree->left, sym) ||
// if the loopvar is used as an index
/* array op is commutative -- must check both left & right */
if (astHasSymbol(pbody->right, sym) || astHasSymbol(pbody->left, sym)) {
- return FALSE;
+ return FALSE;
}
return isConformingBody (pbody->right, sym, body)
&& isConformingBody (pbody->left, sym, body);
/* sure we are not sym is not modified */
if (pbody->left &&
- IS_AST_SYM_VALUE (pbody->left) &&
- isSymbolEqual (AST_SYMBOL (pbody->left), sym))
- return FALSE;
+ IS_AST_SYM_VALUE (pbody->left) &&
+ isSymbolEqual (AST_SYMBOL (pbody->left), sym))
+ return FALSE;
if (pbody->right &&
- IS_AST_SYM_VALUE (pbody->right) &&
- isSymbolEqual (AST_SYMBOL (pbody->right), sym))
- return FALSE;
+ IS_AST_SYM_VALUE (pbody->right) &&
+ isSymbolEqual (AST_SYMBOL (pbody->right), sym))
+ return FALSE;
return TRUE;
/*------------------------------------------------------------------*/
- case '*': /* can be unary : if right is null then unary operation */
+ case '*': /* can be unary : if right is null then unary operation */
case '+':
case '-':
case '&':
/* address of */
/*----------------------------*/
if (!pbody->right)
- {
- if (IS_AST_SYM_VALUE (pbody->left) &&
- isSymbolEqual (AST_SYMBOL (pbody->left), sym))
- return FALSE;
- else
- return isConformingBody (pbody->left, sym, body);
- }
+ {
+ if (IS_AST_SYM_VALUE (pbody->left) &&
+ isSymbolEqual (AST_SYMBOL (pbody->left), sym))
+ return FALSE;
+ else
+ return isConformingBody (pbody->left, sym, body);
+ }
else
- {
- if (astHasSymbol (pbody->left, sym) ||
- astHasSymbol (pbody->right, sym))
- return FALSE;
- }
+ {
+ if (astHasSymbol (pbody->left, sym) ||
+ astHasSymbol (pbody->right, sym))
+ return FALSE;
+ }
/*------------------------------------------------------------------*/
case RIGHT_OP:
if (IS_AST_SYM_VALUE (pbody->left) &&
- isSymbolEqual (AST_SYMBOL (pbody->left), sym))
- return FALSE;
+ isSymbolEqual (AST_SYMBOL (pbody->left), sym))
+ return FALSE;
if (IS_AST_SYM_VALUE (pbody->right) &&
- isSymbolEqual (AST_SYMBOL (pbody->right), sym))
- return FALSE;
+ isSymbolEqual (AST_SYMBOL (pbody->right), sym))
+ return FALSE;
return isConformingBody (pbody->left, sym, body) &&
- isConformingBody (pbody->right, sym, body);
+ isConformingBody (pbody->right, sym, body);
case '~':
case '!':
case GETHBIT:
case SWAP:
if (IS_AST_SYM_VALUE (pbody->left) &&
- isSymbolEqual (AST_SYMBOL (pbody->left), sym))
- return FALSE;
+ isSymbolEqual (AST_SYMBOL (pbody->left), sym))
+ return FALSE;
return isConformingBody (pbody->left, sym, body);
/*------------------------------------------------------------------*/
case NE_OP:
case '?':
case ':':
- case SIZEOF: /* evaluate wihout code generation */
+ case SIZEOF: /* evaluate wihout code generation */
if (IS_AST_SYM_VALUE (pbody->left) &&
- isSymbolEqual (AST_SYMBOL (pbody->left), sym))
- return FALSE;
+ isSymbolEqual (AST_SYMBOL (pbody->left), sym))
+ return FALSE;
if (IS_AST_SYM_VALUE (pbody->right) &&
- isSymbolEqual (AST_SYMBOL (pbody->right), sym))
- return FALSE;
+ isSymbolEqual (AST_SYMBOL (pbody->right), sym))
+ return FALSE;
return isConformingBody (pbody->left, sym, body) &&
- isConformingBody (pbody->right, sym, body);
+ isConformingBody (pbody->right, sym, body);
/*------------------------------------------------------------------*/
case '=':
/* if left has a pointer & right has loop
control variable then we cannot */
if (astHasPointer (pbody->left) &&
- astHasSymbol (pbody->right, sym))
- return FALSE;
+ astHasSymbol (pbody->right, sym))
+ return FALSE;
if (astHasVolatile (pbody->left))
- return FALSE;
+ return FALSE;
if (IS_AST_SYM_VALUE (pbody->left)) {
- // if the loopvar has an assignment
- if (isSymbolEqual (AST_SYMBOL (pbody->left), sym))
- return FALSE;
- // if the loopvar is used in another (maybe conditional) block
- if (astHasSymbol (pbody->right, sym) &&
- (pbody->level >= body->level)) {
- return FALSE;
- }
+ // if the loopvar has an assignment
+ if (isSymbolEqual (AST_SYMBOL (pbody->left), sym))
+ return FALSE;
+ // if the loopvar is used in another (maybe conditional) block
+ if (astHasSymbol (pbody->right, sym) &&
+ (pbody->level >= body->level)) {
+ return FALSE;
+ }
}
if (astHasVolatile (pbody->left))
- return FALSE;
+ return FALSE;
if (astHasDeref(pbody->right)) return FALSE;
return isConformingBody (pbody->left, sym, body) &&
- isConformingBody (pbody->right, sym, body);
+ isConformingBody (pbody->right, sym, body);
case MUL_ASSIGN:
case DIV_ASSIGN:
/*----------------------------*/
case ',':
return isConformingBody (pbody->left, sym, body) &&
- isConformingBody (pbody->right, sym, body);
+ isConformingBody (pbody->right, sym, body);
/*------------------------------------------------------------------*/
/*----------------------------*/
/* function call */
/*----------------------------*/
case CALL:
- /* if local & not passed as paramater then ok */
- if (sym->level && !astHasSymbol(pbody->right,sym))
- return TRUE;
+ /* if local & not passed as paramater then ok */
+ if (sym->level && !astHasSymbol(pbody->right,sym))
+ return TRUE;
return FALSE;
/*------------------------------------------------------------------*/
case GOTO:
if (isLabelInAst (AST_SYMBOL (pbody->left), body))
- return TRUE;
+ return TRUE;
else
- return FALSE;
+ return FALSE;
case SWITCH:
if (astHasSymbol (pbody->left, sym))
- return FALSE;
+ return FALSE;
default:
break;
/*-----------------------------------------------------------------*/
bool
isLoopReversible (ast * loop, symbol ** loopCntrl,
- ast ** init, ast ** end)
+ ast ** init, ast ** end)
{
/* if option says don't do it then don't */
if (optimize.noLoopReverse)
[<sym>++] | [<sym> += 1] | [<sym> = <sym> + 1] )
forBody */
if (!isLoopCountable (AST_FOR (loop, initExpr),
- AST_FOR (loop, condExpr),
- AST_FOR (loop, loopExpr),
- loopCntrl, init, end))
+ AST_FOR (loop, condExpr),
+ AST_FOR (loop, loopExpr),
+ loopCntrl, init, end))
return 0;
/* now do some serious checking on the body of the loop
{
if (isSymbolEqual (AST_SYMBOL (body), sym))
- {
+ {
- body->type = EX_OP;
- body->opval.op = '-';
- body->left = newAst_VALUE (symbolVal (sym));
- body->right = newAst_VALUE (constVal ("1"));
+ body->type = EX_OP;
+ body->opval.op = '-';
+ body->left = newAst_VALUE (symbolVal (sym));
+ body->right = newAst_VALUE (constVal ("1"));
- }
+ }
return;
/* put it together piece by piece */
rloop = newNode (NULLOP,
- createIf (newAst_VALUE (symbolVal (sym)),
- newNode (GOTO,
- newAst_VALUE (symbolVal (AST_FOR (loop, continueLabel))),
- NULL), NULL),
- newNode ('=',
- newAst_VALUE (symbolVal (sym)),
- end));
+ createIf (newAst_VALUE (symbolVal (sym)),
+ newNode (GOTO,
+ newAst_VALUE (symbolVal (AST_FOR (loop, continueLabel))),
+ NULL), NULL),
+ newNode ('=',
+ newAst_VALUE (symbolVal (sym)),
+ end));
replLoopSym (loop->left, sym);
setAstLineno (rloop, init->lineno);
rloop = newNode (NULLOP,
- newNode ('=',
- newAst_VALUE (symbolVal (sym)),
- newNode ('-', end, init)),
- createLabel (AST_FOR (loop, continueLabel),
- newNode (NULLOP,
- loop->left,
- newNode (NULLOP,
- newNode (SUB_ASSIGN,
- newAst_VALUE (symbolVal (sym)),
- newAst_VALUE (constVal ("1"))),
- rloop))));
+ newNode ('=',
+ newAst_VALUE (symbolVal (sym)),
+ newNode ('-', end, init)),
+ createLabel (AST_FOR (loop, continueLabel),
+ newNode (NULLOP,
+ loop->left,
+ newNode (NULLOP,
+ newNode (SUB_ASSIGN,
+ newAst_VALUE (symbolVal (sym)),
+ newAst_VALUE (constVal ("1"))),
+ rloop))));
rloop->lineno=init->lineno;
return decorateType (rloop, RESULT_CHECK);
IS_AST_OP(tree->right) &&
tree->right->right &&
(tree->right->opval.op == ops[0] || tree->right->opval.op == ops[1]))
- {
- if (IS_LITERAL (RTYPE (tree->right)) !=
- IS_LITERAL (LTYPE (tree->right)))
- {
- tree->right->decorated = 0;
- tree->decorated = 0;
- *parent = tree;
- return tree->right;
- }
- ret = searchLitOp (tree->right, parent, ops);
- if (ret)
- return ret;
+ {
+ if (IS_LITERAL (RTYPE (tree->right)) !=
+ IS_LITERAL (LTYPE (tree->right)))
+ {
+ tree->right->decorated = 0;
+ tree->decorated = 0;
+ *parent = tree;
+ return tree->right;
+ }
+ ret = searchLitOp (tree->right, parent, ops);
+ if (ret)
+ return ret;
}
if (tree->left &&
IS_AST_OP(tree->left) &&
tree->left->right &&
- (tree->left->opval.op == ops[0] || tree->left->opval.op == ops[1]))
- {
- if (IS_LITERAL (RTYPE (tree->left)) !=
- IS_LITERAL (LTYPE (tree->left)))
- {
- tree->left->decorated = 0;
- tree->decorated = 0;
- *parent = tree;
- return tree->left;
- }
- ret = searchLitOp (tree->left, parent, ops);
- if (ret)
- return ret;
- }
+ (tree->left->opval.op == ops[0] || tree->left->opval.op == ops[1]))
+ {
+ if (IS_LITERAL (RTYPE (tree->left)) !=
+ IS_LITERAL (LTYPE (tree->left)))
+ {
+ tree->left->decorated = 0;
+ tree->decorated = 0;
+ *parent = tree;
+ return tree->left;
+ }
+ ret = searchLitOp (tree->left, parent, ops);
+ if (ret)
+ return ret;
+ }
}
return NULL;
}
switch (resultType)
{
case RESULT_TYPE_NONE:
- /* char: promote to int */
- if (!upcast ||
- getSize (tree->etype) >= INTSIZE)
- return tree;
- newLink = newIntLink();
- upCasted = TRUE;
- break;
+ /* char: promote to int */
+ if (!upcast ||
+ getSize (tree->etype) >= INTSIZE)
+ return tree;
+ newLink = newIntLink();
+ upCasted = TRUE;
+ break;
case RESULT_TYPE_CHAR:
- if (IS_CHAR (tree->etype) ||
- IS_FLOAT(tree->etype))
- return tree;
- newLink = newCharLink();
- break;
+ if (IS_CHAR (tree->etype) ||
+ IS_FLOAT(tree->etype))
+ return tree;
+ newLink = newCharLink();
+ break;
case RESULT_TYPE_INT:
#if 0
- if (getSize (tree->etype) > INTSIZE)
+ if (getSize (tree->etype) > INTSIZE)
{
/* warn ("Loosing significant digits"); */
- return;
- }
+ return;
+ }
#endif
- /* char: promote to int */
- if (!upcast ||
- getSize (tree->etype) >= INTSIZE)
- return tree;
- newLink = newIntLink();
- upCasted = TRUE;
- break;
+ /* char: promote to int */
+ if (!upcast ||
+ getSize (tree->etype) >= INTSIZE)
+ return tree;
+ newLink = newIntLink();
+ upCasted = TRUE;
+ break;
case RESULT_TYPE_OTHER:
- if (!upcast)
- return tree;
+ if (!upcast)
+ return tree;
/* return type is long, float: promote char to int */
- if (getSize (tree->etype) >= INTSIZE)
- return tree;
- newLink = newIntLink();
- upCasted = TRUE;
- break;
+ if (getSize (tree->etype) >= INTSIZE)
+ return tree;
+ newLink = newIntLink();
+ upCasted = TRUE;
+ break;
default:
- return tree;
+ return tree;
}
tree->decorated = 0;
tree = newNode (CAST, newAst_LINK (newLink), tree);
case '+':
case '-':
case LABEL:
- return resultType;
+ return resultType;
case '&':
- if (!tree->right)
- /* can be unary */
- return RESULT_TYPE_NONE;
- else
- return resultType;
+ if (!tree->right)
+ /* can be unary */
+ return RESULT_TYPE_NONE;
+ else
+ return resultType;
case IFX:
- return RESULT_TYPE_IFX;
+ return RESULT_TYPE_IFX;
default:
- return RESULT_TYPE_NONE;
+ return RESULT_TYPE_NONE;
}
}
{
case '=':
case CAST:
- if (IS_PTR (LTYPE (tree)))
- return RESULT_TYPE_NONE;
- else
- return getResultTypeFromType (LETYPE (tree));
+ if (IS_PTR (LTYPE (tree)))
+ return RESULT_TYPE_NONE;
+ else
+ return getResultTypeFromType (LETYPE (tree));
case RETURN:
- if (IS_PTR (currFunc->type->next))
- return RESULT_TYPE_NONE;
- else
- return getResultTypeFromType (currFunc->type->next);
+ if (IS_PTR (currFunc->type->next))
+ return RESULT_TYPE_NONE;
+ else
+ return getResultTypeFromType (currFunc->type->next);
case '[':
- if (!IS_ARRAY (LTYPE (tree)))
- return resultType;
- if (DCL_ELEM (LTYPE (tree)) > 0 && DCL_ELEM (LTYPE (tree)) <= 256)
- return RESULT_TYPE_CHAR;
- return resultType;
+ if (!IS_ARRAY (LTYPE (tree)))
+ return resultType;
+ if (DCL_ELEM (LTYPE (tree)) > 0 && DCL_ELEM (LTYPE (tree)) <= 256)
+ return RESULT_TYPE_CHAR;
+ return resultType;
default:
- return resultType;
+ return resultType;
}
}
{
if (IS_LITERAL (tree->opval.val->etype))
- {
+ {
- /* if this is a character array then declare it */
- if (IS_ARRAY (tree->opval.val->type))
- tree->opval.val = stringToSymbol (tree->opval.val);
+ /* if this is a character array then declare it */
+ if (IS_ARRAY (tree->opval.val->type))
+ tree->opval.val = stringToSymbol (tree->opval.val);
- /* otherwise just copy the type information */
- COPYTYPE (TTYPE (tree), TETYPE (tree), tree->opval.val->type);
- return tree;
- }
+ /* otherwise just copy the type information */
+ COPYTYPE (TTYPE (tree), TETYPE (tree), tree->opval.val->type);
+ return tree;
+ }
if (tree->opval.val->sym)
- {
- /* if the undefined flag is set then give error message */
- if (tree->opval.val->sym->undefined)
- {
- werror (E_ID_UNDEF, tree->opval.val->sym->name);
- /* assume int */
- TTYPE (tree) = TETYPE (tree) =
- tree->opval.val->type = tree->opval.val->sym->type =
- tree->opval.val->etype = tree->opval.val->sym->etype =
- copyLinkChain (INTTYPE);
- }
- else
- {
-
- /* if impilicit i.e. struct/union member then no type */
- if (tree->opval.val->sym->implicit)
- TTYPE (tree) = TETYPE (tree) = NULL;
-
- else
- {
-
- /* else copy the type */
- COPYTYPE (TTYPE (tree), TETYPE (tree), tree->opval.val->type);
-
- /* and mark it as referenced */
- tree->opval.val->sym->isref = 1;
- }
- }
- }
+ {
+ /* if the undefined flag is set then give error message */
+ if (tree->opval.val->sym->undefined)
+ {
+ werror (E_ID_UNDEF, tree->opval.val->sym->name);
+ /* assume int */
+ TTYPE (tree) = TETYPE (tree) =
+ tree->opval.val->type = tree->opval.val->sym->type =
+ tree->opval.val->etype = tree->opval.val->sym->etype =
+ copyLinkChain (INTTYPE);
+ }
+ else
+ {
+
+ /* if impilicit i.e. struct/union member then no type */
+ if (tree->opval.val->sym->implicit)
+ TTYPE (tree) = TETYPE (tree) = NULL;
+
+ else
+ {
+
+ /* else copy the type */
+ COPYTYPE (TTYPE (tree), TETYPE (tree), tree->opval.val->type);
+
+ /* and mark it as referenced */
+ tree->opval.val->sym->isref = 1;
+ }
+ }
+ }
return tree;
}
if (tree->opval.op == NULLOP || tree->opval.op == BLOCK)
{
if (tree->left && tree->left->type == EX_OPERAND
- && (tree->left->opval.op == INC_OP
- || tree->left->opval.op == DEC_OP)
- && tree->left->left)
- {
- tree->left->right = tree->left->left;
- tree->left->left = NULL;
- }
+ && (tree->left->opval.op == INC_OP
+ || tree->left->opval.op == DEC_OP)
+ && tree->left->left)
+ {
+ tree->left->right = tree->left->left;
+ tree->left->left = NULL;
+ }
if (tree->right && tree->right->type == EX_OPERAND
- && (tree->right->opval.op == INC_OP
- || tree->right->opval.op == DEC_OP)
- && tree->right->left)
- {
- tree->right->right = tree->right->left;
- tree->right->left = NULL;
- }
+ && (tree->right->opval.op == INC_OP
+ || tree->right->opval.op == DEC_OP)
+ && tree->right->left)
+ {
+ tree->right->right = tree->right->left;
+ tree->right->left = NULL;
+ }
}
#endif
{
/* determine which is the array & which the index */
if ((IS_ARRAY (RTYPE (tree)) || IS_PTR (RTYPE (tree))) &&
- IS_INTEGRAL (LTYPE (tree)))
- {
- ast *tempTree = tree->left;
- tree->left = tree->right;
- tree->right = tempTree;
- }
+ IS_INTEGRAL (LTYPE (tree)))
+ {
+ ast *tempTree = tree->left;
+ tree->left = tree->right;
+ tree->right = tempTree;
+ }
}
/* After decorating the left branch there's type information available
switch (tree->opval.op)
{
case '?':
- /* delay right side for '?' operator since conditional macro
- expansions might rely on this */
- dtr = tree->right;
- break;
- case CALL:
- /* decorate right side for CALL (parameter list) in processParms();
- there is resultType available */
- dtr = tree->right;
- break;
- default:
- dtr = decorateType (tree->right, resultTypeProp);
- break;
+ /* delay right side for '?' operator since conditional macro
+ expansions might rely on this */
+ dtr = tree->right;
+ break;
+ case CALL:
+ /* decorate right side for CALL (parameter list) in processParms();
+ there is resultType available */
+ dtr = tree->right;
+ break;
+ default:
+ dtr = decorateType (tree->right, resultTypeProp);
+ break;
}
/* this is to take care of situations
switch (tree->opval.op)
{
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* array node */
- /*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* array node */
+ /*----------------------------*/
case '[':
/* first check if this is a array or a pointer */
if ((!IS_ARRAY (LTYPE (tree))) && (!IS_PTR (LTYPE (tree))))
- {
- werror (E_NEED_ARRAY_PTR, "[]");
- goto errorTreeReturn;
- }
+ {
+ werror (E_NEED_ARRAY_PTR, "[]");
+ goto errorTreeReturn;
+ }
/* check if the type of the idx */
if (!IS_INTEGRAL (RTYPE (tree)))
- {
- werror (E_IDX_NOT_INT);
- goto errorTreeReturn;
- }
+ {
+ werror (E_IDX_NOT_INT);
+ goto errorTreeReturn;
+ }
/* if the left is an rvalue then error */
if (LRVAL (tree))
- {
- werror (E_LVALUE_REQUIRED, "array access");
- goto errorTreeReturn;
- }
+ {
+ werror (E_LVALUE_REQUIRED, "array access");
+ goto errorTreeReturn;
+ }
if (IS_LITERAL (RTYPE (tree)))
- {
- int arrayIndex = (int) floatFromVal (valFromType (RETYPE (tree)));
- int arraySize = DCL_ELEM (LTYPE (tree));
- if (arraySize && arrayIndex >= arraySize)
- {
- werror (W_IDX_OUT_OF_BOUNDS, arrayIndex, arraySize);
- }
- }
+ {
+ int arrayIndex = (int) floatFromVal (valFromType (RETYPE (tree)));
+ int arraySize = DCL_ELEM (LTYPE (tree));
+ if (arraySize && arrayIndex >= arraySize)
+ {
+ werror (W_IDX_OUT_OF_BOUNDS, arrayIndex, arraySize);
+ }
+ }
RRVAL (tree) = 1;
COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree)->next);
case '.':
/* if this is not a structure */
if (!IS_STRUCT (LTYPE (tree)))
- {
- werror (E_STRUCT_UNION, ".");
- goto errorTreeReturn;
- }
+ {
+ werror (E_STRUCT_UNION, ".");
+ goto errorTreeReturn;
+ }
TTYPE (tree) = structElemType (LTYPE (tree),
- (tree->right->type == EX_VALUE ?
- tree->right->opval.val : NULL));
+ (tree->right->type == EX_VALUE ?
+ tree->right->opval.val : NULL));
TETYPE (tree) = getSpec (TTYPE (tree));
return tree;
case PTR_OP:
/* if not pointer to a structure */
if (!IS_PTR (LTYPE (tree)) && !IS_ARRAY (LTYPE(tree)))
- {
- werror (E_PTR_REQD);
- goto errorTreeReturn;
- }
+ {
+ werror (E_PTR_REQD);
+ goto errorTreeReturn;
+ }
if (!IS_STRUCT (LTYPE (tree)->next))
- {
- werror (E_STRUCT_UNION, "->");
- goto errorTreeReturn;
- }
+ {
+ werror (E_STRUCT_UNION, "->");
+ goto errorTreeReturn;
+ }
TTYPE (tree) = structElemType (LTYPE (tree)->next,
- (tree->right->type == EX_VALUE ?
- tree->right->opval.val : NULL));
+ (tree->right->type == EX_VALUE ?
+ tree->right->opval.val : NULL));
TETYPE (tree) = getSpec (TTYPE (tree));
/* adjust the storage class */
switch (DCL_TYPE(tree->left->ftype)) {
case POINTER:
- SPEC_SCLS(TETYPE(tree)) = S_DATA;
- break;
+ SPEC_SCLS(TETYPE(tree)) = S_DATA;
+ break;
case FPOINTER:
- SPEC_SCLS(TETYPE(tree)) = S_XDATA;
- break;
+ SPEC_SCLS(TETYPE(tree)) = S_XDATA;
+ break;
case CPOINTER:
- SPEC_SCLS(TETYPE(tree)) = S_CODE;
- break;
+ SPEC_SCLS(TETYPE(tree)) = S_CODE;
+ break;
case GPOINTER:
- SPEC_SCLS (TETYPE (tree)) = 0;
- break;
+ SPEC_SCLS (TETYPE (tree)) = 0;
+ break;
case PPOINTER:
- SPEC_SCLS(TETYPE(tree)) = S_XSTACK;
- break;
+ SPEC_SCLS(TETYPE(tree)) = S_XSTACK;
+ break;
case IPOINTER:
- SPEC_SCLS(TETYPE(tree)) = S_IDATA;
- break;
+ SPEC_SCLS(TETYPE(tree)) = S_IDATA;
+ break;
case EEPPOINTER:
- SPEC_SCLS(TETYPE(tree)) = S_EEPROM;
- break;
+ SPEC_SCLS(TETYPE(tree)) = S_EEPROM;
+ break;
case UPOINTER:
- SPEC_SCLS (TETYPE (tree)) = 0;
- break;
+ SPEC_SCLS (TETYPE (tree)) = 0;
+ break;
case ARRAY:
case FUNCTION:
- break;
+ break;
}
/* This breaks with extern declarations, bitfields, and perhaps other */
*/
symbol *sym;
symbol *element = getStructElement (SPEC_STRUCT (LETYPE(tree)),
- AST_SYMBOL(tree->right));
+ AST_SYMBOL(tree->right));
sym = newSymbol(genSymName (0), 0);
sym->type = TTYPE (tree);
case INC_OP:
case DEC_OP:
{
- sym_link *ltc = (tree->right ? RTYPE (tree) : LTYPE (tree));
- COPYTYPE (TTYPE (tree), TETYPE (tree), ltc);
+ sym_link *ltc = (tree->right ? RTYPE (tree) : LTYPE (tree));
+ COPYTYPE (TTYPE (tree), TETYPE (tree), ltc);
if (!tree->initMode && IS_CONSTANT(TTYPE(tree)))
- werror (E_CODE_WRITE, tree->opval.op==INC_OP ? "++" : "--");
+ werror (E_CODE_WRITE, tree->opval.op==INC_OP ? "++" : "--");
- if (tree->right)
- RLVAL (tree) = 1;
- else
- LLVAL (tree) = 1;
- return tree;
+ if (tree->right)
+ RLVAL (tree) = 1;
+ else
+ LLVAL (tree) = 1;
+ return tree;
}
/*------------------------------------------------------------------*/
/*----------------------------*/
/* bitwise and */
/*----------------------------*/
- case '&': /* can be unary */
+ case '&': /* can be unary */
/* if right is NULL then unary operation */
- if (tree->right) /* not an unary operation */
- {
-
- if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
- {
- werror (E_BITWISE_OP);
- werror (W_CONTINUE, "left & right types are ");
- printTypeChain (LTYPE (tree), stderr);
- fprintf (stderr, ",");
- printTypeChain (RTYPE (tree), stderr);
- fprintf (stderr, "\n");
- goto errorTreeReturn;
- }
-
- /* if they are both literal */
- if (IS_LITERAL (RTYPE (tree)) && IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->opval.val = valBitwise (valFromType (LETYPE (tree)),
- valFromType (RETYPE (tree)), '&');
-
- tree->right = tree->left = NULL;
- TETYPE (tree) = tree->opval.val->etype;
- TTYPE (tree) = tree->opval.val->type;
- return tree;
- }
-
- /* see if this is a GETHBIT operation if yes
- then return that */
- {
- ast *otree = optimizeGetHbit (tree);
-
- if (otree != tree)
- return decorateType (otree, RESULT_CHECK);
- }
-
- TTYPE (tree) = computeType (LTYPE (tree),
- RTYPE (tree),
- resultType,
- tree->opval.op);
- TETYPE (tree) = getSpec (TTYPE (tree));
+ if (tree->right) /* not an unary operation */
+ {
+
+ if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
+ {
+ werror (E_BITWISE_OP);
+ werror (W_CONTINUE, "left & right types are ");
+ printTypeChain (LTYPE (tree), stderr);
+ fprintf (stderr, ",");
+ printTypeChain (RTYPE (tree), stderr);
+ fprintf (stderr, "\n");
+ goto errorTreeReturn;
+ }
+
+ /* if they are both literal */
+ if (IS_LITERAL (RTYPE (tree)) && IS_LITERAL (LTYPE (tree)))
+ {
+ tree->type = EX_VALUE;
+ tree->opval.val = valBitwise (valFromType (LETYPE (tree)),
+ valFromType (RETYPE (tree)), '&');
+
+ tree->right = tree->left = NULL;
+ TETYPE (tree) = tree->opval.val->etype;
+ TTYPE (tree) = tree->opval.val->type;
+ return tree;
+ }
+
+ /* see if this is a GETHBIT operation if yes
+ then return that */
+ {
+ ast *otree = optimizeGetHbit (tree);
+
+ if (otree != tree)
+ return decorateType (otree, RESULT_CHECK);
+ }
+
+ TTYPE (tree) = computeType (LTYPE (tree),
+ RTYPE (tree),
+ resultType,
+ tree->opval.op);
+ TETYPE (tree) = getSpec (TTYPE (tree));
/* if left is a literal exchange left & right */
if (IS_LITERAL (LTYPE (tree)))
- {
- ast *tTree = tree->left;
- tree->left = tree->right;
- tree->right = tTree;
- }
-
- /* if right is a literal and */
- /* we can find a 2nd literal in a and-tree then */
- /* rearrange the tree */
- if (IS_LITERAL (RTYPE (tree)))
- {
- ast *parent;
- ast *litTree = searchLitOp (tree, &parent, "&");
- if (litTree)
- {
- DEBUG_CF("&")
- ast *tTree = litTree->left;
- litTree->left = tree->right;
- tree->right = tTree;
- /* both operands in tTree are literal now */
- decorateType (parent, resultType);
- }
- }
-
- LRVAL (tree) = RRVAL (tree) = 1;
-
- return tree;
- }
+ {
+ ast *tTree = tree->left;
+ tree->left = tree->right;
+ tree->right = tTree;
+ }
+
+ /* if right is a literal and */
+ /* we can find a 2nd literal in a and-tree then */
+ /* rearrange the tree */
+ if (IS_LITERAL (RTYPE (tree)))
+ {
+ ast *parent;
+ ast *litTree = searchLitOp (tree, &parent, "&");
+ if (litTree)
+ {
+ DEBUG_CF("&")
+ ast *tTree = litTree->left;
+ litTree->left = tree->right;
+ tree->right = tTree;
+ /* both operands in tTree are literal now */
+ decorateType (parent, resultType);
+ }
+ }
+
+ LRVAL (tree) = RRVAL (tree) = 1;
+
+ return tree;
+ }
/*------------------------------------------------------------------*/
/*----------------------------*/
p = newLink (DECLARATOR);
/* if bit field then error */
if (IS_BITVAR (tree->left->etype))
- {
- werror (E_ILLEGAL_ADDR, "address of bit variable");
- goto errorTreeReturn;
- }
+ {
+ werror (E_ILLEGAL_ADDR, "address of bit variable");
+ goto errorTreeReturn;
+ }
if (LETYPE(tree) && SPEC_SCLS (tree->left->etype) == S_REGISTER)
- {
- werror (E_ILLEGAL_ADDR, "address of register variable");
- goto errorTreeReturn;
- }
+ {
+ werror (E_ILLEGAL_ADDR, "address of register variable");
+ goto errorTreeReturn;
+ }
if (IS_FUNC (LTYPE (tree)))
- {
- // this ought to be ignored
- return (tree->left);
- }
+ {
+ // this ought to be ignored
+ return (tree->left);
+ }
if (IS_LITERAL(LTYPE(tree)))
- {
- werror (E_ILLEGAL_ADDR, "address of literal");
- goto errorTreeReturn;
- }
+ {
+ werror (E_ILLEGAL_ADDR, "address of literal");
+ goto errorTreeReturn;
+ }
if (LRVAL (tree))
- {
- werror (E_LVALUE_REQUIRED, "address of");
- goto errorTreeReturn;
- }
+ {
+ werror (E_LVALUE_REQUIRED, "address of");
+ goto errorTreeReturn;
+ }
if (!LETYPE (tree))
DCL_TYPE (p) = POINTER;
else if (SPEC_SCLS (tree->left->etype) == S_CODE)
- DCL_TYPE (p) = CPOINTER;
+ DCL_TYPE (p) = CPOINTER;
else if (SPEC_SCLS (tree->left->etype) == S_XDATA)
- DCL_TYPE (p) = FPOINTER;
+ DCL_TYPE (p) = FPOINTER;
else if (SPEC_SCLS (tree->left->etype) == S_XSTACK)
- DCL_TYPE (p) = PPOINTER;
+ DCL_TYPE (p) = PPOINTER;
else if (SPEC_SCLS (tree->left->etype) == S_IDATA)
- DCL_TYPE (p) = IPOINTER;
+ DCL_TYPE (p) = IPOINTER;
else if (SPEC_SCLS (tree->left->etype) == S_EEPROM)
- DCL_TYPE (p) = EEPPOINTER;
+ DCL_TYPE (p) = EEPPOINTER;
else if (SPEC_OCLS(tree->left->etype))
- DCL_TYPE (p) = PTR_TYPE(SPEC_OCLS(tree->left->etype));
+ DCL_TYPE (p) = PTR_TYPE(SPEC_OCLS(tree->left->etype));
else
- DCL_TYPE (p) = POINTER;
+ DCL_TYPE (p) = POINTER;
if (IS_AST_SYM_VALUE (tree->left))
- {
- AST_SYMBOL (tree->left)->addrtaken = 1;
- AST_SYMBOL (tree->left)->allocreq = 1;
- }
+ {
+ AST_SYMBOL (tree->left)->addrtaken = 1;
+ AST_SYMBOL (tree->left)->allocreq = 1;
+ }
p->next = LTYPE (tree);
TTYPE (tree) = p;
&& IS_AST_VALUE (tree->left->left) && !IS_AST_SYM_VALUE (tree->left->left))
{
symbol *element = getStructElement (SPEC_STRUCT (LETYPE(tree->left)),
- AST_SYMBOL(tree->left->right));
- AST_VALUE(tree) = valPlus(AST_VALUE(tree->left->left),
+ AST_SYMBOL(tree->left->right));
+ AST_VALUE(tree) = valPlus(AST_VALUE(tree->left->left),
valueFromLit(element->offset));
- tree->left = NULL;
- tree->right = NULL;
- tree->type = EX_VALUE;
- tree->values.literalFromCast = 1;
+ tree->left = NULL;
+ tree->right = NULL;
+ tree->type = EX_VALUE;
+ tree->values.literalFromCast = 1;
}
#endif
case '|':
/* if the rewrite succeeds then don't go any furthur */
{
- ast *wtree = optimizeRRCRLC (tree);
- if (wtree != tree)
- return decorateType (wtree, RESULT_CHECK);
-
- wtree = optimizeSWAP (tree);
- if (wtree != tree)
- return decorateType (wtree, RESULT_CHECK);
+ ast *wtree = optimizeRRCRLC (tree);
+ if (wtree != tree)
+ return decorateType (wtree, RESULT_CHECK);
+
+ wtree = optimizeSWAP (tree);
+ if (wtree != tree)
+ return decorateType (wtree, RESULT_CHECK);
}
/* if left is a literal exchange left & right */
if (IS_LITERAL (LTYPE (tree)))
- {
- ast *tTree = tree->left;
- tree->left = tree->right;
- tree->right = tTree;
- }
+ {
+ ast *tTree = tree->left;
+ tree->left = tree->right;
+ tree->right = tTree;
+ }
/* if right is a literal and */
/* we can find a 2nd literal in a or-tree then */
/* rearrange the tree */
if (IS_LITERAL (RTYPE (tree)))
- {
- ast *parent;
- ast *litTree = searchLitOp (tree, &parent, "|");
- if (litTree)
- {
- DEBUG_CF("|")
- ast *tTree = litTree->left;
- litTree->left = tree->right;
- tree->right = tTree;
- /* both operands in tTree are literal now */
- decorateType (parent, resultType);
- }
+ {
+ ast *parent;
+ ast *litTree = searchLitOp (tree, &parent, "|");
+ if (litTree)
+ {
+ DEBUG_CF("|")
+ ast *tTree = litTree->left;
+ litTree->left = tree->right;
+ tree->right = tTree;
+ /* both operands in tTree are literal now */
+ decorateType (parent, resultType);
+ }
}
/* fall through */
/*----------------------------*/
case '^':
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
- {
- werror (E_BITWISE_OP);
- werror (W_CONTINUE, "left & right types are ");
- printTypeChain (LTYPE (tree), stderr);
- fprintf (stderr, ",");
- printTypeChain (RTYPE (tree), stderr);
- fprintf (stderr, "\n");
- goto errorTreeReturn;
- }
+ {
+ werror (E_BITWISE_OP);
+ werror (W_CONTINUE, "left & right types are ");
+ printTypeChain (LTYPE (tree), stderr);
+ fprintf (stderr, ",");
+ printTypeChain (RTYPE (tree), stderr);
+ fprintf (stderr, "\n");
+ goto errorTreeReturn;
+ }
/* if they are both literal then */
/* rewrite the tree */
if (IS_LITERAL (RTYPE (tree)) && IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->opval.val = valBitwise (valFromType (LETYPE (tree)),
- valFromType (RETYPE (tree)),
- tree->opval.op);
- tree->right = tree->left = NULL;
- TETYPE (tree) = tree->opval.val->etype;
- TTYPE (tree) = tree->opval.val->type;
- return tree;
- }
+ {
+ tree->type = EX_VALUE;
+ tree->opval.val = valBitwise (valFromType (LETYPE (tree)),
+ valFromType (RETYPE (tree)),
+ tree->opval.op);
+ tree->right = tree->left = NULL;
+ TETYPE (tree) = tree->opval.val->etype;
+ TTYPE (tree) = tree->opval.val->type;
+ return tree;
+ }
/* if left is a literal exchange left & right */
if (IS_LITERAL (LTYPE (tree)))
- {
- ast *tTree = tree->left;
- tree->left = tree->right;
- tree->right = tTree;
- }
+ {
+ ast *tTree = tree->left;
+ tree->left = tree->right;
+ tree->right = tTree;
+ }
/* if right is a literal and */
/* we can find a 2nd literal in a xor-tree then */
/* rearrange the tree */
if (IS_LITERAL (RTYPE (tree)) &&
tree->opval.op == '^') /* the same source is used by 'bitwise or' */
- {
- ast *parent;
- ast *litTree = searchLitOp (tree, &parent, "^");
- if (litTree)
- {
- DEBUG_CF("^")
- ast *tTree = litTree->left;
- litTree->left = tree->right;
- tree->right = tTree;
- /* both operands in litTree are literal now */
- decorateType (parent, resultType);
- }
+ {
+ ast *parent;
+ ast *litTree = searchLitOp (tree, &parent, "^");
+ if (litTree)
+ {
+ DEBUG_CF("^")
+ ast *tTree = litTree->left;
+ litTree->left = tree->right;
+ tree->right = tTree;
+ /* both operands in litTree are literal now */
+ decorateType (parent, resultType);
+ }
}
LRVAL (tree) = RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) =
- computeType (LTYPE (tree),
- RTYPE (tree),
- resultType,
- tree->opval.op));
+ computeType (LTYPE (tree),
+ RTYPE (tree),
+ resultType,
+ tree->opval.op));
return tree;
/*----------------------------*/
case '/':
if (!IS_ARITHMETIC (LTYPE (tree)) || !IS_ARITHMETIC (RTYPE (tree)))
- {
- werror (E_INVALID_OP, "divide");
- goto errorTreeReturn;
- }
+ {
+ werror (E_INVALID_OP, "divide");
+ goto errorTreeReturn;
+ }
/* if they are both literal then */
/* rewrite the tree */
if (IS_LITERAL (RTYPE (tree)) && IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->opval.val = valDiv (valFromType (LETYPE (tree)),
- valFromType (RETYPE (tree)));
- tree->right = tree->left = NULL;
- TETYPE (tree) = getSpec (TTYPE (tree) =
- tree->opval.val->type);
- return tree;
- }
+ {
+ tree->type = EX_VALUE;
+ tree->opval.val = valDiv (valFromType (LETYPE (tree)),
+ valFromType (RETYPE (tree)));
+ tree->right = tree->left = NULL;
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ tree->opval.val->type);
+ return tree;
+ }
LRVAL (tree) = RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) =
- computeType (LTYPE (tree),
- RTYPE (tree),
- resultType,
- tree->opval.op));
+ computeType (LTYPE (tree),
+ RTYPE (tree),
+ resultType,
+ tree->opval.op));
/* if right is a literal and */
/* left is also a division by a literal then */
if (IS_LITERAL (RTYPE (tree))
/* avoid infinite loop */
&& (TYPE_UDWORD) floatFromVal (tree->right->opval.val) != 1)
- {
- ast *parent;
- ast *litTree = searchLitOp (tree, &parent, "/");
- if (litTree)
- {
- if (IS_LITERAL (RTYPE (litTree)))
- {
- /* foo_div */
- DEBUG_CF("div r")
- litTree->right = newNode ('*',
- litTree->right,
- copyAst (tree->right));
- litTree->right->lineno = tree->lineno;
-
- tree->right->opval.val = constVal ("1");
- decorateType (parent, resultType);
- }
- else
- {
- /* litTree->left is literal: no gcse possible.
- We can't call decorateType(parent, RESULT_CHECK), because
- this would cause an infinit loop. */
- parent->decorated = 1;
- decorateType (litTree, resultType);
- }
- }
- }
+ {
+ ast *parent;
+ ast *litTree = searchLitOp (tree, &parent, "/");
+ if (litTree)
+ {
+ if (IS_LITERAL (RTYPE (litTree)))
+ {
+ /* foo_div */
+ DEBUG_CF("div r")
+ litTree->right = newNode ('*',
+ litTree->right,
+ copyAst (tree->right));
+ litTree->right->lineno = tree->lineno;
+
+ tree->right->opval.val = constVal ("1");
+ decorateType (parent, resultType);
+ }
+ else
+ {
+ /* litTree->left is literal: no gcse possible.
+ We can't call decorateType(parent, RESULT_CHECK), because
+ this would cause an infinit loop. */
+ parent->decorated = 1;
+ decorateType (litTree, resultType);
+ }
+ }
+ }
return tree;
/*----------------------------*/
case '%':
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
- {
- werror (E_BITWISE_OP);
- werror (W_CONTINUE, "left & right types are ");
- printTypeChain (LTYPE (tree), stderr);
- fprintf (stderr, ",");
- printTypeChain (RTYPE (tree), stderr);
- fprintf (stderr, "\n");
- goto errorTreeReturn;
- }
+ {
+ werror (E_BITWISE_OP);
+ werror (W_CONTINUE, "left & right types are ");
+ printTypeChain (LTYPE (tree), stderr);
+ fprintf (stderr, ",");
+ printTypeChain (RTYPE (tree), stderr);
+ fprintf (stderr, "\n");
+ goto errorTreeReturn;
+ }
/* if they are both literal then */
/* rewrite the tree */
if (IS_LITERAL (RTYPE (tree)) && IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->opval.val = valMod (valFromType (LETYPE (tree)),
- valFromType (RETYPE (tree)));
- tree->right = tree->left = NULL;
- TETYPE (tree) = getSpec (TTYPE (tree) =
- tree->opval.val->type);
- return tree;
- }
+ {
+ tree->type = EX_VALUE;
+ tree->opval.val = valMod (valFromType (LETYPE (tree)),
+ valFromType (RETYPE (tree)));
+ tree->right = tree->left = NULL;
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ tree->opval.val->type);
+ return tree;
+ }
LRVAL (tree) = RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) =
- computeType (LTYPE (tree),
- RTYPE (tree),
- resultType,
- tree->opval.op));
+ computeType (LTYPE (tree),
+ RTYPE (tree),
+ resultType,
+ tree->opval.op));
return tree;
/*------------------------------------------------------------------*/
/*----------------------------*/
/* address dereference */
/*----------------------------*/
- case '*': /* can be unary : if right is null then unary operation */
+ case '*': /* can be unary : if right is null then unary operation */
if (!tree->right)
- {
- if (!IS_PTR (LTYPE (tree)) && !IS_ARRAY (LTYPE (tree)))
- {
- werror (E_PTR_REQD);
- goto errorTreeReturn;
- }
-
- if (LRVAL (tree))
- {
- werror (E_LVALUE_REQUIRED, "pointer deref");
- goto errorTreeReturn;
- }
- if (IS_ADDRESS_OF_OP(tree->left))
+ {
+ if (!IS_PTR (LTYPE (tree)) && !IS_ARRAY (LTYPE (tree)))
+ {
+ werror (E_PTR_REQD);
+ goto errorTreeReturn;
+ }
+
+ if (LRVAL (tree))
+ {
+ werror (E_LVALUE_REQUIRED, "pointer deref");
+ goto errorTreeReturn;
+ }
+ if (IS_ADDRESS_OF_OP(tree->left))
{
/* replace *&obj with obj */
return tree->left->left;
}
TTYPE (tree) = copyLinkChain (LTYPE (tree)->next);
- TETYPE (tree) = getSpec (TTYPE (tree));
- /* adjust the storage class */
- switch (DCL_TYPE(tree->left->ftype)) {
- case POINTER:
- SPEC_SCLS(TETYPE(tree)) = S_DATA;
- break;
- case FPOINTER:
- SPEC_SCLS(TETYPE(tree)) = S_XDATA;
- break;
- case CPOINTER:
- SPEC_SCLS(TETYPE(tree)) = S_CODE;
- break;
- case GPOINTER:
- SPEC_SCLS (TETYPE (tree)) = 0;
- break;
- case PPOINTER:
- SPEC_SCLS(TETYPE(tree)) = S_XSTACK;
- break;
- case IPOINTER:
- SPEC_SCLS(TETYPE(tree)) = S_IDATA;
- break;
- case EEPPOINTER:
- SPEC_SCLS(TETYPE(tree)) = S_EEPROM;
- break;
- case UPOINTER:
- SPEC_SCLS (TETYPE (tree)) = 0;
+ TETYPE (tree) = getSpec (TTYPE (tree));
+ /* adjust the storage class */
+ switch (DCL_TYPE(tree->left->ftype)) {
+ case POINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_DATA;
+ break;
+ case FPOINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_XDATA;
+ break;
+ case CPOINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_CODE;
+ break;
+ case GPOINTER:
+ SPEC_SCLS (TETYPE (tree)) = 0;
+ break;
+ case PPOINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_XSTACK;
break;
- case ARRAY:
- case FUNCTION:
- break;
- }
- return tree;
- }
+ case IPOINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_IDATA;
+ break;
+ case EEPPOINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_EEPROM;
+ break;
+ case UPOINTER:
+ SPEC_SCLS (TETYPE (tree)) = 0;
+ break;
+ case ARRAY:
+ case FUNCTION:
+ break;
+ }
+ return tree;
+ }
/*------------------------------------------------------------------*/
/*----------------------------*/
/* multiplication */
/*----------------------------*/
if (!IS_ARITHMETIC (LTYPE (tree)) || !IS_ARITHMETIC (RTYPE (tree)))
- {
- werror (E_INVALID_OP, "multiplication");
- goto errorTreeReturn;
- }
+ {
+ werror (E_INVALID_OP, "multiplication");
+ goto errorTreeReturn;
+ }
/* if they are both literal then */
/* rewrite the tree */
if (IS_LITERAL (RTYPE (tree)) && IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->opval.val = valMult (valFromType (LETYPE (tree)),
- valFromType (RETYPE (tree)));
- tree->right = tree->left = NULL;
- TETYPE (tree) = getSpec (TTYPE (tree) =
- tree->opval.val->type);
- return tree;
- }
+ {
+ tree->type = EX_VALUE;
+ tree->opval.val = valMult (valFromType (LETYPE (tree)),
+ valFromType (RETYPE (tree)));
+ tree->right = tree->left = NULL;
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ tree->opval.val->type);
+ return tree;
+ }
/* if left is a literal exchange left & right */
if (IS_LITERAL (LTYPE (tree)))
- {
- ast *tTree = tree->left;
- tree->left = tree->right;
- tree->right = tTree;
- }
+ {
+ ast *tTree = tree->left;
+ tree->left = tree->right;
+ tree->right = tTree;
+ }
/* if right is a literal and */
/* we can find a 2nd literal in a mul-tree then */
/* rearrange the tree */
if (IS_LITERAL (RTYPE (tree)))
- {
- ast *parent;
- ast *litTree = searchLitOp (tree, &parent, "*");
- if (litTree)
- {
- DEBUG_CF("mul")
- ast *tTree = litTree->left;
- litTree->left = tree->right;
- tree->right = tTree;
- /* both operands in litTree are literal now */
- decorateType (parent, resultType);
- }
+ {
+ ast *parent;
+ ast *litTree = searchLitOp (tree, &parent, "*");
+ if (litTree)
+ {
+ DEBUG_CF("mul")
+ ast *tTree = litTree->left;
+ litTree->left = tree->right;
+ tree->right = tTree;
+ /* both operands in litTree are literal now */
+ decorateType (parent, resultType);
+ }
}
LRVAL (tree) = RRVAL (tree) = 1;
tree->left = addCast (tree->left, resultType, FALSE);
tree->right = addCast (tree->right, resultType, FALSE);
TETYPE (tree) = getSpec (TTYPE (tree) =
- computeType (LTYPE (tree),
- RTYPE (tree),
- resultType,
- tree->opval.op));
+ computeType (LTYPE (tree),
+ RTYPE (tree),
+ resultType,
+ tree->opval.op));
return tree;
case '+':
/* if unary plus */
if (!tree->right)
- {
- if (!IS_ARITHMETIC (LTYPE (tree)))
- {
- werror (E_UNARY_OP, '+');
- goto errorTreeReturn;
- }
-
- /* if left is a literal then do it */
- if (IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->opval.val = valFromType (LETYPE (tree));
- tree->left = NULL;
- TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
- return tree;
- }
- LRVAL (tree) = 1;
- COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree));
- return tree;
- }
+ {
+ if (!IS_ARITHMETIC (LTYPE (tree)))
+ {
+ werror (E_UNARY_OP, '+');
+ goto errorTreeReturn;
+ }
+
+ /* if left is a literal then do it */
+ if (IS_LITERAL (LTYPE (tree)))
+ {
+ tree->type = EX_VALUE;
+ tree->opval.val = valFromType (LETYPE (tree));
+ tree->left = NULL;
+ TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
+ return tree;
+ }
+ LRVAL (tree) = 1;
+ COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree));
+ return tree;
+ }
/*------------------------------------------------------------------*/
/*----------------------------*/
/* this is not a unary operation */
/* if both pointers then problem */
if ((IS_PTR (LTYPE (tree)) || IS_ARRAY (LTYPE (tree))) &&
- (IS_PTR (RTYPE (tree)) || IS_ARRAY (RTYPE (tree))))
- {
- werror (E_PTR_PLUS_PTR);
- goto errorTreeReturn;
- }
+ (IS_PTR (RTYPE (tree)) || IS_ARRAY (RTYPE (tree))))
+ {
+ werror (E_PTR_PLUS_PTR);
+ goto errorTreeReturn;
+ }
if (!IS_ARITHMETIC (LTYPE (tree)) &&
- !IS_PTR (LTYPE (tree)) && !IS_ARRAY (LTYPE (tree)))
- {
- werror (E_PLUS_INVALID, "+");
- goto errorTreeReturn;
- }
+ !IS_PTR (LTYPE (tree)) && !IS_ARRAY (LTYPE (tree)))
+ {
+ werror (E_PLUS_INVALID, "+");
+ goto errorTreeReturn;
+ }
if (!IS_ARITHMETIC (RTYPE (tree)) &&
- !IS_PTR (RTYPE (tree)) && !IS_ARRAY (RTYPE (tree)))
- {
- werror (E_PLUS_INVALID, "+");
- goto errorTreeReturn;
- }
+ !IS_PTR (RTYPE (tree)) && !IS_ARRAY (RTYPE (tree)))
+ {
+ werror (E_PLUS_INVALID, "+");
+ goto errorTreeReturn;
+ }
/* if they are both literal then */
/* rewrite the tree */
if (IS_LITERAL (RTYPE (tree)) && IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->left = addCast (tree->left, resultType, TRUE);
+ {
+ tree->type = EX_VALUE;
+ tree->left = addCast (tree->left, resultType, TRUE);
tree->right = addCast (tree->right, resultType, TRUE);
- tree->opval.val = valPlus (valFromType (LETYPE (tree)),
- valFromType (RETYPE (tree)));
- tree->right = tree->left = NULL;
- TETYPE (tree) = getSpec (TTYPE (tree) =
- tree->opval.val->type);
- return tree;
- }
+ tree->opval.val = valPlus (valFromType (LETYPE (tree)),
+ valFromType (RETYPE (tree)));
+ tree->right = tree->left = NULL;
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ tree->opval.val->type);
+ return tree;
+ }
/* if the right is a pointer or left is a literal
xchange left & right */
if (IS_ARRAY (RTYPE (tree)) ||
- IS_PTR (RTYPE (tree)) ||
- IS_LITERAL (LTYPE (tree)))
- {
- ast *tTree = tree->left;
- tree->left = tree->right;
- tree->right = tTree;
- }
+ IS_PTR (RTYPE (tree)) ||
+ IS_LITERAL (LTYPE (tree)))
+ {
+ ast *tTree = tree->left;
+ tree->left = tree->right;
+ tree->right = tTree;
+ }
/* if right is a literal and */
/* left is also an addition/subtraction with a literal then */
/* rearrange the tree */
if (IS_LITERAL (RTYPE (tree)))
- {
- ast *litTree, *parent;
- litTree = searchLitOp (tree, &parent, "+-");
- if (litTree)
- {
- if (litTree->opval.op == '+')
- {
- /* foo_aa */
- DEBUG_CF("+ 1 AA")
- ast *tTree = litTree->left;
- litTree->left = tree->right;
- tree->right = tree->left;
- tree->left = tTree;
- }
- else if (litTree->opval.op == '-')
- {
- if (IS_LITERAL (RTYPE (litTree)))
- {
- DEBUG_CF("+ 2 ASR")
- /* foo_asr */
- ast *tTree = litTree->left;
- litTree->left = tree->right;
- tree->right = tTree;
- }
- else
- {
- DEBUG_CF("+ 3 ASL")
- /* foo_asl */
- ast *tTree = litTree->right;
- litTree->right = tree->right;
- tree->right = tTree;
- litTree->opval.op = '+';
- tree->opval.op = '-';
- }
- }
- decorateType (parent, resultType);
- }
- }
+ {
+ ast *litTree, *parent;
+ litTree = searchLitOp (tree, &parent, "+-");
+ if (litTree)
+ {
+ if (litTree->opval.op == '+')
+ {
+ /* foo_aa */
+ DEBUG_CF("+ 1 AA")
+ ast *tTree = litTree->left;
+ litTree->left = tree->right;
+ tree->right = tree->left;
+ tree->left = tTree;
+ }
+ else if (litTree->opval.op == '-')
+ {
+ if (IS_LITERAL (RTYPE (litTree)))
+ {
+ DEBUG_CF("+ 2 ASR")
+ /* foo_asr */
+ ast *tTree = litTree->left;
+ litTree->left = tree->right;
+ tree->right = tTree;
+ }
+ else
+ {
+ DEBUG_CF("+ 3 ASL")
+ /* foo_asl */
+ ast *tTree = litTree->right;
+ litTree->right = tree->right;
+ tree->right = tTree;
+ litTree->opval.op = '+';
+ tree->opval.op = '-';
+ }
+ }
+ decorateType (parent, resultType);
+ }
+ }
LRVAL (tree) = RRVAL (tree) = 1;
/* if the left is a pointer */
if (IS_PTR (LTYPE (tree)) || IS_AGGREGATE (LTYPE (tree)) )
- TETYPE (tree) = getSpec (TTYPE (tree) =
- LTYPE (tree));
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ LTYPE (tree));
else
- {
- tree->left = addCast (tree->left, resultType, TRUE);
+ {
+ tree->left = addCast (tree->left, resultType, TRUE);
tree->right = addCast (tree->right, resultType, TRUE);
TETYPE (tree) = getSpec (TTYPE (tree) =
- computeType (LTYPE (tree),
- RTYPE (tree),
- resultType,
- tree->opval.op));
- }
-
+ computeType (LTYPE (tree),
+ RTYPE (tree),
+ resultType,
+ tree->opval.op));
+ }
+
return tree;
/*------------------------------------------------------------------*/
/*----------------------------*/
/* unary '-' */
/*----------------------------*/
- case '-': /* can be unary */
+ case '-': /* can be unary */
/* if right is null then unary */
if (!tree->right)
- {
-
- if (!IS_ARITHMETIC (LTYPE (tree)))
- {
- werror (E_UNARY_OP, tree->opval.op);
- goto errorTreeReturn;
- }
-
- /* if left is a literal then do it */
- if (IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->opval.val = valUnaryPM (valFromType (LETYPE (tree)));
- tree->left = NULL;
- TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
- SPEC_USIGN(TETYPE(tree)) = 0;
- return tree;
- }
- LRVAL (tree) = 1;
- TETYPE(tree) = getSpec (TTYPE (tree) = LTYPE (tree));
- return tree;
- }
+ {
+
+ if (!IS_ARITHMETIC (LTYPE (tree)))
+ {
+ werror (E_UNARY_OP, tree->opval.op);
+ goto errorTreeReturn;
+ }
+
+ /* if left is a literal then do it */
+ if (IS_LITERAL (LTYPE (tree)))
+ {
+ tree->type = EX_VALUE;
+ tree->opval.val = valUnaryPM (valFromType (LETYPE (tree)));
+ tree->left = NULL;
+ TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
+ SPEC_USIGN(TETYPE(tree)) = 0;
+ return tree;
+ }
+ LRVAL (tree) = 1;
+ TETYPE(tree) = getSpec (TTYPE (tree) = LTYPE (tree));
+ return tree;
+ }
/*------------------------------------------------------------------*/
/*----------------------------*/
/*----------------------------*/
if (!(IS_PTR (LTYPE (tree)) ||
- IS_ARRAY (LTYPE (tree)) ||
- IS_ARITHMETIC (LTYPE (tree))))
- {
- werror (E_PLUS_INVALID, "-");
- goto errorTreeReturn;
- }
+ IS_ARRAY (LTYPE (tree)) ||
+ IS_ARITHMETIC (LTYPE (tree))))
+ {
+ werror (E_PLUS_INVALID, "-");
+ goto errorTreeReturn;
+ }
if (!(IS_PTR (RTYPE (tree)) ||
- IS_ARRAY (RTYPE (tree)) ||
- IS_ARITHMETIC (RTYPE (tree))))
- {
- werror (E_PLUS_INVALID, "-");
- goto errorTreeReturn;
- }
+ IS_ARRAY (RTYPE (tree)) ||
+ IS_ARITHMETIC (RTYPE (tree))))
+ {
+ werror (E_PLUS_INVALID, "-");
+ goto errorTreeReturn;
+ }
if ((IS_PTR (LTYPE (tree)) || IS_ARRAY (LTYPE (tree))) &&
- !(IS_PTR (RTYPE (tree)) || IS_ARRAY (RTYPE (tree)) ||
- IS_INTEGRAL (RTYPE (tree))))
- {
- werror (E_PLUS_INVALID, "-");
- goto errorTreeReturn;
- }
+ !(IS_PTR (RTYPE (tree)) || IS_ARRAY (RTYPE (tree)) ||
+ IS_INTEGRAL (RTYPE (tree))))
+ {
+ werror (E_PLUS_INVALID, "-");
+ goto errorTreeReturn;
+ }
/* if they are both literal then */
/* rewrite the tree */
if (IS_LITERAL (RTYPE (tree)) && IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->left = addCast (tree->left, resultType, TRUE);
- tree->right = addCast (tree->right, resultType, TRUE);
- tree->opval.val = valMinus (valFromType (LETYPE (tree)),
- valFromType (RETYPE (tree)));
- tree->right = tree->left = NULL;
- TETYPE (tree) = getSpec (TTYPE (tree) =
- tree->opval.val->type);
- return tree;
- }
+ {
+ tree->type = EX_VALUE;
+ tree->left = addCast (tree->left, resultType, TRUE);
+ tree->right = addCast (tree->right, resultType, TRUE);
+ tree->opval.val = valMinus (valFromType (LETYPE (tree)),
+ valFromType (RETYPE (tree)));
+ tree->right = tree->left = NULL;
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ tree->opval.val->type);
+ return tree;
+ }
/* if the left & right are equal then zero */
if (isAstEqual (tree->left, tree->right))
- {
- tree->type = EX_VALUE;
- tree->left = tree->right = NULL;
- tree->opval.val = constVal ("0");
- TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
- return tree;
- }
+ {
+ tree->type = EX_VALUE;
+ tree->left = tree->right = NULL;
+ tree->opval.val = constVal ("0");
+ TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
+ return tree;
+ }
/* if both of them are pointers or arrays then */
/* the result is going to be an integer */
if ((IS_ARRAY (LTYPE (tree)) || IS_PTR (LTYPE (tree))) &&
- (IS_ARRAY (RTYPE (tree)) || IS_PTR (RTYPE (tree))))
- TETYPE (tree) = TTYPE (tree) = newIntLink ();
+ (IS_ARRAY (RTYPE (tree)) || IS_PTR (RTYPE (tree))))
+ TETYPE (tree) = TTYPE (tree) = newIntLink ();
else
- /* if only the left is a pointer */
- /* then result is a pointer */
+ /* if only the left is a pointer */
+ /* then result is a pointer */
if (IS_PTR (LTYPE (tree)) || IS_ARRAY (LTYPE (tree)))
- TETYPE (tree) = getSpec (TTYPE (tree) =
- LTYPE (tree));
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ LTYPE (tree));
else
- {
- tree->left = addCast (tree->left, resultType, TRUE);
- tree->right = addCast (tree->right, resultType, TRUE);
+ {
+ tree->left = addCast (tree->left, resultType, TRUE);
+ tree->right = addCast (tree->right, resultType, TRUE);
- TETYPE (tree) = getSpec (TTYPE (tree) =
- computeType (LTYPE (tree),
- RTYPE (tree),
- resultType,
- tree->opval.op));
- }
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ computeType (LTYPE (tree),
+ RTYPE (tree),
+ resultType,
+ tree->opval.op));
+ }
LRVAL (tree) = RRVAL (tree) = 1;
if (IS_LITERAL (RTYPE (tree))
/* avoid infinite loop */
&& (TYPE_UDWORD) floatFromVal (tree->right->opval.val) != 0)
- {
- ast *litTree, *litParent;
- litTree = searchLitOp (tree, &litParent, "+-");
- if (litTree)
- {
- if (litTree->opval.op == '+')
- {
- /* foo_sa */
- DEBUG_CF("- 1 SA")
- ast *tTree = litTree->left;
- litTree->left = litTree->right;
- litTree->right = tree->right;
- tree->right = tTree;
- tree->opval.op = '+';
- litTree->opval.op = '-';
- }
- else if (litTree->opval.op == '-')
- {
- if (IS_LITERAL (RTYPE (litTree)))
- {
- /* foo_ssr */
- DEBUG_CF("- 2 SSR")
- ast *tTree = litTree->left;
- litTree->left = tree->right;
- tree->right = litParent->left;
- litParent->left = tTree;
- litTree->opval.op = '+';
-
- tree->decorated = 0;
- decorateType (tree, resultType);
- }
- else
- {
- /* foo_ssl */
- DEBUG_CF("- 3 SSL")
- ast *tTree = litTree->right;
- litTree->right = tree->right;
- tree->right = tTree;
- }
- }
- decorateType (litParent, resultType);
- }
- }
+ {
+ ast *litTree, *litParent;
+ litTree = searchLitOp (tree, &litParent, "+-");
+ if (litTree)
+ {
+ if (litTree->opval.op == '+')
+ {
+ /* foo_sa */
+ DEBUG_CF("- 1 SA")
+ ast *tTree = litTree->left;
+ litTree->left = litTree->right;
+ litTree->right = tree->right;
+ tree->right = tTree;
+ tree->opval.op = '+';
+ litTree->opval.op = '-';
+ }
+ else if (litTree->opval.op == '-')
+ {
+ if (IS_LITERAL (RTYPE (litTree)))
+ {
+ /* foo_ssr */
+ DEBUG_CF("- 2 SSR")
+ ast *tTree = litTree->left;
+ litTree->left = tree->right;
+ tree->right = litParent->left;
+ litParent->left = tTree;
+ litTree->opval.op = '+';
+
+ tree->decorated = 0;
+ decorateType (tree, resultType);
+ }
+ else
+ {
+ /* foo_ssl */
+ DEBUG_CF("- 3 SSL")
+ ast *tTree = litTree->right;
+ litTree->right = tree->right;
+ tree->right = tTree;
+ }
+ }
+ decorateType (litParent, resultType);
+ }
+ }
return tree;
/*------------------------------------------------------------------*/
case '~':
/* can be only integral type */
if (!IS_INTEGRAL (LTYPE (tree)))
- {
- werror (E_UNARY_OP, tree->opval.op);
- goto errorTreeReturn;
- }
+ {
+ werror (E_UNARY_OP, tree->opval.op);
+ goto errorTreeReturn;
+ }
/* if left is a literal then do it */
if (IS_LITERAL (LTYPE (tree)))
case '!':
/* can be pointer */
if (!IS_ARITHMETIC (LTYPE (tree)) &&
- !IS_PTR (LTYPE (tree)) &&
- !IS_ARRAY (LTYPE (tree)))
- {
- werror (E_UNARY_OP, tree->opval.op);
- goto errorTreeReturn;
- }
+ !IS_PTR (LTYPE (tree)) &&
+ !IS_ARRAY (LTYPE (tree)))
+ {
+ werror (E_UNARY_OP, tree->opval.op);
+ goto errorTreeReturn;
+ }
/* if left is a literal then do it */
if (IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->opval.val = valNot (valFromType (LETYPE (tree)));
- tree->left = NULL;
- TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
- return tree;
- }
+ {
+ tree->type = EX_VALUE;
+ tree->opval.val = valNot (valFromType (LETYPE (tree)));
+ tree->left = NULL;
+ TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
+ return tree;
+ }
LRVAL (tree) = 1;
TTYPE (tree) = TETYPE (tree) = newCharLink ();
return tree;
case LEFT_OP:
case RIGHT_OP:
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (tree->left->etype))
- {
- werror (E_SHIFT_OP_INVALID);
- werror (W_CONTINUE, "left & right types are ");
- printTypeChain (LTYPE (tree), stderr);
- fprintf (stderr, ",");
- printTypeChain (RTYPE (tree), stderr);
- fprintf (stderr, "\n");
- goto errorTreeReturn;
- }
+ {
+ werror (E_SHIFT_OP_INVALID);
+ werror (W_CONTINUE, "left & right types are ");
+ printTypeChain (LTYPE (tree), stderr);
+ fprintf (stderr, ",");
+ printTypeChain (RTYPE (tree), stderr);
+ fprintf (stderr, "\n");
+ goto errorTreeReturn;
+ }
/* make smaller type only if it's a LEFT_OP */
if (tree->opval.op == LEFT_OP)
/* if they are both literal then */
/* rewrite the tree */
if (IS_LITERAL (RTYPE (tree)) && IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->opval.val = valShift (valFromType (LETYPE (tree)),
- valFromType (RETYPE (tree)),
- (tree->opval.op == LEFT_OP ? 1 : 0));
- tree->right = tree->left = NULL;
- TETYPE (tree) = getSpec (TTYPE (tree) =
- tree->opval.val->type);
- return tree;
- }
+ {
+ tree->type = EX_VALUE;
+ tree->opval.val = valShift (valFromType (LETYPE (tree)),
+ valFromType (RETYPE (tree)),
+ (tree->opval.op == LEFT_OP ? 1 : 0));
+ tree->right = tree->left = NULL;
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ tree->opval.val->type);
+ return tree;
+ }
LRVAL (tree) = RRVAL (tree) = 1;
if (tree->opval.op == LEFT_OP)
- {
- TETYPE (tree) = getSpec (TTYPE (tree) =
- computeType (LTYPE (tree),
- NULL,
- resultType,
- tree->opval.op));
- }
+ {
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ computeType (LTYPE (tree),
+ NULL,
+ resultType,
+ tree->opval.op));
+ }
else /* RIGHT_OP */
- {
- /* no promotion necessary */
- TTYPE (tree) = TETYPE (tree) = copyLinkChain (LTYPE (tree));
- if (IS_LITERAL (TTYPE (tree)))
- SPEC_SCLS (TTYPE (tree)) &= ~S_LITERAL;
- }
+ {
+ /* no promotion necessary */
+ TTYPE (tree) = TETYPE (tree) = copyLinkChain (LTYPE (tree));
+ if (IS_LITERAL (TTYPE (tree)))
+ SPEC_SCLS (TTYPE (tree)) &= ~S_LITERAL;
+ }
/* if only the right side is a literal & we are
shifting more than size of the left operand then zero */
if (IS_LITERAL (RTYPE (tree)) &&
- ((TYPE_UDWORD) floatFromVal (valFromType (RETYPE (tree)))) >=
- (getSize (TETYPE (tree)) * 8))
- {
- if (tree->opval.op==LEFT_OP ||
- (tree->opval.op==RIGHT_OP && SPEC_USIGN(LETYPE(tree))))
- {
- lineno=tree->lineno;
- werror (W_SHIFT_CHANGED,
- (tree->opval.op == LEFT_OP ? "left" : "right"));
- tree->type = EX_VALUE;
- tree->left = tree->right = NULL;
- tree->opval.val = constVal ("0");
- TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
- return tree;
- }
- }
+ ((TYPE_UDWORD) floatFromVal (valFromType (RETYPE (tree)))) >=
+ (getSize (TETYPE (tree)) * 8))
+ {
+ if (tree->opval.op==LEFT_OP ||
+ (tree->opval.op==RIGHT_OP && SPEC_USIGN(LETYPE(tree))))
+ {
+ lineno=tree->lineno;
+ werror (W_SHIFT_CHANGED,
+ (tree->opval.op == LEFT_OP ? "left" : "right"));
+ tree->type = EX_VALUE;
+ tree->left = tree->right = NULL;
+ tree->opval.val = constVal ("0");
+ TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
+ return tree;
+ }
+ }
return tree;
/*----------------------------*/
/* casting */
/*----------------------------*/
- case CAST: /* change the type */
+ case CAST: /* change the type */
/* cannot cast to an aggregate type */
if (IS_AGGREGATE (LTYPE (tree)))
- {
- werror (E_CAST_ILLEGAL);
- goto errorTreeReturn;
- }
+ {
+ werror (E_CAST_ILLEGAL);
+ goto errorTreeReturn;
+ }
/* make sure the type is complete and sane */
checkTypeSanity(LETYPE(tree), "(cast)");
/* If code memory is read only, then pointers to code memory */
/* implicitly point to constants -- make this explicit */
{
- sym_link *t = LTYPE(tree);
- while (t && t->next)
- {
- if (IS_CODEPTR(t) && port->mem.code_ro)
- {
- if (IS_SPEC(t->next))
- SPEC_CONST (t->next) = 1;
- else
- DCL_PTR_CONST (t->next) = 1;
- }
- t = t->next;
+ sym_link *t = LTYPE(tree);
+ while (t && t->next)
+ {
+ if (IS_CODEPTR(t) && port->mem.code_ro)
+ {
+ if (IS_SPEC(t->next))
+ SPEC_CONST (t->next) = 1;
+ else
+ DCL_PTR_CONST (t->next) = 1;
+ }
+ t = t->next;
}
}
#if 0
/* if the right is a literal replace the tree */
if (IS_LITERAL (RETYPE (tree))) {
- if (!IS_PTR (LTYPE (tree))) {
- tree->type = EX_VALUE;
- tree->opval.val =
- valCastLiteral (LTYPE (tree),
- floatFromVal (valFromType (RETYPE (tree))));
- tree->left = NULL;
- tree->right = NULL;
- TTYPE (tree) = tree->opval.val->type;
- tree->values.literalFromCast = 1;
- } else if (IS_GENPTR(LTYPE(tree)) && !IS_PTR(RTYPE(tree)) &&
- ((int)floatFromVal(valFromType(RETYPE(tree)))) !=0 ) /* special case of NULL */ {
- sym_link *rest = LTYPE(tree)->next;
- werror(W_LITERAL_GENERIC);
- TTYPE(tree) = newLink(DECLARATOR);
- DCL_TYPE(TTYPE(tree)) = FPOINTER;
- TTYPE(tree)->next = rest;
- tree->left->opval.lnk = TTYPE(tree);
- LRVAL (tree) = 1;
- } else {
- TTYPE (tree) = LTYPE (tree);
- LRVAL (tree) = 1;
- }
+ if (!IS_PTR (LTYPE (tree))) {
+ tree->type = EX_VALUE;
+ tree->opval.val =
+ valCastLiteral (LTYPE (tree),
+ floatFromVal (valFromType (RETYPE (tree))));
+ tree->left = NULL;
+ tree->right = NULL;
+ TTYPE (tree) = tree->opval.val->type;
+ tree->values.literalFromCast = 1;
+ } else if (IS_GENPTR(LTYPE(tree)) && !IS_PTR(RTYPE(tree)) &&
+ ((int)floatFromVal(valFromType(RETYPE(tree)))) !=0 ) /* special case of NULL */ {
+ sym_link *rest = LTYPE(tree)->next;
+ werror(W_LITERAL_GENERIC);
+ TTYPE(tree) = newLink(DECLARATOR);
+ DCL_TYPE(TTYPE(tree)) = FPOINTER;
+ TTYPE(tree)->next = rest;
+ tree->left->opval.lnk = TTYPE(tree);
+ LRVAL (tree) = 1;
+ } else {
+ TTYPE (tree) = LTYPE (tree);
+ LRVAL (tree) = 1;
+ }
} else {
- TTYPE (tree) = LTYPE (tree);
- LRVAL (tree) = 1;
+ TTYPE (tree) = LTYPE (tree);
+ LRVAL (tree) = 1;
}
#else
#if 0 // this is already checked, now this could be explicit
/* if pointer to struct then check names */
if (IS_PTR(LTYPE(tree)) && IS_STRUCT(LTYPE(tree)->next) &&
- IS_PTR(RTYPE(tree)) && IS_STRUCT(RTYPE(tree)->next) &&
- strcmp(SPEC_STRUCT(LETYPE(tree))->tag,SPEC_STRUCT(RETYPE(tree))->tag))
- {
- werror(W_CAST_STRUCT_PTR,SPEC_STRUCT(RETYPE(tree))->tag,
- SPEC_STRUCT(LETYPE(tree))->tag);
- }
+ IS_PTR(RTYPE(tree)) && IS_STRUCT(RTYPE(tree)->next) &&
+ strcmp(SPEC_STRUCT(LETYPE(tree))->tag,SPEC_STRUCT(RETYPE(tree))->tag))
+ {
+ werror(W_CAST_STRUCT_PTR,SPEC_STRUCT(RETYPE(tree))->tag,
+ SPEC_STRUCT(LETYPE(tree))->tag);
+ }
#endif
if (IS_ADDRESS_OF_OP(tree->right)
&& IS_AST_SYM_VALUE (tree->right->left)
&& SPEC_ABSA (AST_SYMBOL (tree->right->left)->etype)) {
tree->type = EX_VALUE;
- tree->opval.val =
- valCastLiteral (LTYPE (tree),
- SPEC_ADDR (AST_SYMBOL (tree->right->left)->etype));
- TTYPE (tree) = tree->opval.val->type;
+ tree->opval.val =
+ valCastLiteral (LTYPE (tree),
+ SPEC_ADDR (AST_SYMBOL (tree->right->left)->etype));
+ TTYPE (tree) = tree->opval.val->type;
TETYPE (tree) = getSpec (TTYPE (tree));
- tree->left = NULL;
- tree->right = NULL;
- tree->values.literalFromCast = 1;
+ tree->left = NULL;
+ tree->right = NULL;
+ tree->values.literalFromCast = 1;
return tree;
}
symbol *element = getStructElement (
SPEC_STRUCT (LETYPE(tree->right->left)),
- AST_SYMBOL(tree->right->left->right)
+ AST_SYMBOL(tree->right->left->right)
);
if (element) {
tree->type = EX_VALUE;
- tree->opval.val = valCastLiteral (
- LTYPE (tree),
- element->offset
+ tree->opval.val = valCastLiteral (
+ LTYPE (tree),
+ element->offset
+ floatFromVal (valFromType (RTYPE (tree->right->left->left)))
);
- TTYPE (tree) = tree->opval.val->type;
+ TTYPE (tree) = tree->opval.val->type;
TETYPE (tree) = getSpec (TTYPE (tree));
- tree->left = NULL;
- tree->right = NULL;
+ tree->left = NULL;
+ tree->right = NULL;
return tree;
}
}
/* if the right is a literal replace the tree */
if (IS_LITERAL (RETYPE (tree))) {
#if 0
- if (IS_PTR (LTYPE (tree)) && !IS_GENPTR (LTYPE (tree)) ) {
+ if (IS_PTR (LTYPE (tree)) && !IS_GENPTR (LTYPE (tree)) ) {
/* rewrite (type *)litaddr
as &temp
and define type at litaddr temp
newTree->left->lineno = tree->lineno;
LTYPE (newTree) = sym->type;
LETYPE (newTree) = sym->etype;
- LLVAL (newTree) = 1;
+ LLVAL (newTree) = 1;
LRVAL (newTree) = 0;
TLVAL (newTree) = 1;
return newTree;
}
- #endif
+ #endif
if (!IS_PTR (LTYPE (tree))) {
- tree->type = EX_VALUE;
- tree->opval.val =
- valCastLiteral (LTYPE (tree),
- floatFromVal (valFromType (RTYPE (tree))));
- TTYPE (tree) = tree->opval.val->type;
- tree->left = NULL;
- tree->right = NULL;
- tree->values.literalFromCast = 1;
- TETYPE (tree) = getSpec (TTYPE (tree));
+ tree->type = EX_VALUE;
+ tree->opval.val =
+ valCastLiteral (LTYPE (tree),
+ floatFromVal (valFromType (RTYPE (tree))));
+ TTYPE (tree) = tree->opval.val->type;
+ tree->left = NULL;
+ tree->right = NULL;
+ tree->values.literalFromCast = 1;
+ TETYPE (tree) = getSpec (TTYPE (tree));
return tree;
}
}
case OR_OP:
/* each must be arithmetic type or be a pointer */
if (!IS_PTR (LTYPE (tree)) &&
- !IS_ARRAY (LTYPE (tree)) &&
- !IS_INTEGRAL (LTYPE (tree)))
- {
- werror (E_COMPARE_OP);
- goto errorTreeReturn;
- }
+ !IS_ARRAY (LTYPE (tree)) &&
+ !IS_INTEGRAL (LTYPE (tree)))
+ {
+ werror (E_COMPARE_OP);
+ goto errorTreeReturn;
+ }
if (!IS_PTR (RTYPE (tree)) &&
- !IS_ARRAY (RTYPE (tree)) &&
- !IS_INTEGRAL (RTYPE (tree)))
- {
- werror (E_COMPARE_OP);
- goto errorTreeReturn;
- }
+ !IS_ARRAY (RTYPE (tree)) &&
+ !IS_INTEGRAL (RTYPE (tree)))
+ {
+ werror (E_COMPARE_OP);
+ goto errorTreeReturn;
+ }
/* if they are both literal then */
/* rewrite the tree */
if (IS_LITERAL (RTYPE (tree)) &&
- IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->opval.val = valLogicAndOr (valFromType (LTYPE (tree)),
- valFromType (RTYPE (tree)),
- tree->opval.op);
- tree->right = tree->left = NULL;
- TETYPE (tree) = getSpec (TTYPE (tree) =
- tree->opval.val->type);
- return tree;
- }
+ IS_LITERAL (LTYPE (tree)))
+ {
+ tree->type = EX_VALUE;
+ tree->opval.val = valLogicAndOr (valFromType (LTYPE (tree)),
+ valFromType (RTYPE (tree)),
+ tree->opval.op);
+ tree->right = tree->left = NULL;
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ tree->opval.val->type);
+ return tree;
+ }
LRVAL (tree) = RRVAL (tree) = 1;
TTYPE (tree) = TETYPE (tree) = newCharLink ();
return tree;
case EQ_OP:
case NE_OP:
{
- ast *lt = optimizeCompare (tree);
+ ast *lt = optimizeCompare (tree);
- if (tree != lt)
- return lt;
+ if (tree != lt)
+ return lt;
}
/* if they are pointers they must be castable */
if (IS_PTR (LTYPE (tree)) && IS_PTR (RTYPE (tree)))
- {
- if (tree->opval.op==EQ_OP &&
- !IS_GENPTR(LTYPE(tree)) && IS_GENPTR(RTYPE(tree))) {
- // we cannot cast a gptr to a !gptr: switch the leaves
- struct ast *s=tree->left;
- tree->left=tree->right;
- tree->right=s;
- }
- if (compareType (LTYPE (tree), RTYPE (tree)) == 0)
- {
- werror (E_COMPARE_OP);
- fprintf (stderr, "comparing type ");
- printTypeChain (LTYPE (tree), stderr);
- fprintf (stderr, "to type ");
- printTypeChain (RTYPE (tree), stderr);
- fprintf (stderr, "\n");
- goto errorTreeReturn;
- }
- }
+ {
+ if (tree->opval.op==EQ_OP &&
+ !IS_GENPTR(LTYPE(tree)) && IS_GENPTR(RTYPE(tree))) {
+ // we cannot cast a gptr to a !gptr: switch the leaves
+ struct ast *s=tree->left;
+ tree->left=tree->right;
+ tree->right=s;
+ }
+ if (compareType (LTYPE (tree), RTYPE (tree)) == 0)
+ {
+ werror (E_COMPARE_OP);
+ fprintf (stderr, "comparing type ");
+ printTypeChain (LTYPE (tree), stderr);
+ fprintf (stderr, "to type ");
+ printTypeChain (RTYPE (tree), stderr);
+ fprintf (stderr, "\n");
+ goto errorTreeReturn;
+ }
+ }
/* else they should be promotable to one another */
else
- {
- if (!((IS_PTR (LTYPE (tree)) && IS_LITERAL (RTYPE (tree))) ||
- (IS_PTR (RTYPE (tree)) && IS_LITERAL (LTYPE (tree)))))
-
- if (compareType (LTYPE (tree), RTYPE (tree)) == 0)
- {
- werror (E_COMPARE_OP);
- fprintf (stderr, "comparing type ");
- printTypeChain (LTYPE (tree), stderr);
- fprintf (stderr, "to type ");
- printTypeChain (RTYPE (tree), stderr);
- fprintf (stderr, "\n");
- goto errorTreeReturn;
- }
- }
+ {
+ if (!((IS_PTR (LTYPE (tree)) && IS_LITERAL (RTYPE (tree))) ||
+ (IS_PTR (RTYPE (tree)) && IS_LITERAL (LTYPE (tree)))))
+
+ if (compareType (LTYPE (tree), RTYPE (tree)) == 0)
+ {
+ werror (E_COMPARE_OP);
+ fprintf (stderr, "comparing type ");
+ printTypeChain (LTYPE (tree), stderr);
+ fprintf (stderr, "to type ");
+ printTypeChain (RTYPE (tree), stderr);
+ fprintf (stderr, "\n");
+ goto errorTreeReturn;
+ }
+ }
/* if unsigned value < 0 then always false */
/* if (unsigned value) > 0 then '(unsigned value) ? 1 : 0' */
if (SPEC_USIGN(LETYPE(tree)) &&
!IS_CHAR(LETYPE(tree)) && /* promotion to signed int */
IS_LITERAL(RTYPE(tree)) &&
- ((int) floatFromVal (valFromType (RETYPE (tree)))) == 0)
- {
- if (tree->opval.op == '<')
- {
- return tree->right;
- }
- if (tree->opval.op == '>')
- {
- if (resultType == RESULT_TYPE_IFX)
- {
- /* the parent is an ifx: */
- /* if (unsigned value) */
- return tree->left;
- }
-
- /* (unsigned value) ? 1 : 0 */
- tree->opval.op = '?';
- tree->right = newNode (':',
- newAst_VALUE (constVal ("1")),
- tree->right); /* val 0 */
- tree->right->lineno = tree->lineno;
- tree->right->left->lineno = tree->lineno;
- decorateType (tree->right, RESULT_CHECK);
- }
+ ((int) floatFromVal (valFromType (RETYPE (tree)))) == 0)
+ {
+ if (tree->opval.op == '<')
+ {
+ return tree->right;
+ }
+ if (tree->opval.op == '>')
+ {
+ if (resultType == RESULT_TYPE_IFX)
+ {
+ /* the parent is an ifx: */
+ /* if (unsigned value) */
+ return tree->left;
+ }
+
+ /* (unsigned value) ? 1 : 0 */
+ tree->opval.op = '?';
+ tree->right = newNode (':',
+ newAst_VALUE (constVal ("1")),
+ tree->right); /* val 0 */
+ tree->right->lineno = tree->lineno;
+ tree->right->left->lineno = tree->lineno;
+ decorateType (tree->right, RESULT_CHECK);
+ }
}
/* if they are both literal then */
/* rewrite the tree */
if (IS_LITERAL (RTYPE (tree)) &&
- IS_LITERAL (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->opval.val = valCompare (valFromType (LETYPE (tree)),
- valFromType (RETYPE (tree)),
- tree->opval.op);
- tree->right = tree->left = NULL;
- TETYPE (tree) = getSpec (TTYPE (tree) =
- tree->opval.val->type);
- return tree;
- }
+ IS_LITERAL (LTYPE (tree)))
+ {
+ tree->type = EX_VALUE;
+ tree->opval.val = valCompare (valFromType (LETYPE (tree)),
+ valFromType (RETYPE (tree)),
+ tree->opval.op);
+ tree->right = tree->left = NULL;
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ tree->opval.val->type);
+ return tree;
+ }
LRVAL (tree) = RRVAL (tree) = 1;
TTYPE (tree) = TETYPE (tree) = newCharLink ();
return tree;
/*----------------------------*/
/* sizeof */
/*----------------------------*/
- case SIZEOF: /* evaluate wihout code generation */
+ case SIZEOF: /* evaluate wihout code generation */
/* change the type to a integer */
{
- int size = getSize (tree->right->ftype);
- SNPRINTF(buffer, sizeof(buffer), "%d", size);
- if (!size && !IS_VOID(tree->right->ftype))
- werrorfl (tree->filename, tree->lineno, E_SIZEOF_INCOMPLETE_TYPE);
+ int size = getSize (tree->right->ftype);
+ SNPRINTF(buffer, sizeof(buffer), "%d", size);
+ if (!size && !IS_VOID(tree->right->ftype))
+ werrorfl (tree->filename, tree->lineno, E_SIZEOF_INCOMPLETE_TYPE);
}
tree->type = EX_VALUE;
tree->opval.val = constVal (buffer);
tree->right = tree->left = NULL;
TETYPE (tree) = getSpec (TTYPE (tree) =
- tree->opval.val->type);
+ tree->opval.val->type);
return tree;
/*------------------------------------------------------------------*/
/* typeof */
/*----------------------------*/
case TYPEOF:
- /* return typeof enum value */
- tree->type = EX_VALUE;
- {
- int typeofv = 0;
- if (IS_SPEC(tree->right->ftype)) {
- switch (SPEC_NOUN(tree->right->ftype)) {
- case V_INT:
- if (SPEC_LONG(tree->right->ftype)) typeofv = TYPEOF_LONG;
- else typeofv = TYPEOF_INT;
- break;
- case V_FLOAT:
- typeofv = TYPEOF_FLOAT;
- break;
- case V_CHAR:
- typeofv = TYPEOF_CHAR;
- break;
- case V_VOID:
- typeofv = TYPEOF_VOID;
- break;
- case V_STRUCT:
- typeofv = TYPEOF_STRUCT;
- break;
- case V_BITFIELD:
- typeofv = TYPEOF_BITFIELD;
- break;
- case V_BIT:
- typeofv = TYPEOF_BIT;
- break;
- case V_SBIT:
- typeofv = TYPEOF_SBIT;
- break;
- default:
- break;
- }
- } else {
- switch (DCL_TYPE(tree->right->ftype)) {
- case POINTER:
- typeofv = TYPEOF_POINTER;
- break;
- case FPOINTER:
- typeofv = TYPEOF_FPOINTER;
- break;
- case CPOINTER:
- typeofv = TYPEOF_CPOINTER;
- break;
- case GPOINTER:
- typeofv = TYPEOF_GPOINTER;
- break;
- case PPOINTER:
- typeofv = TYPEOF_PPOINTER;
- break;
- case IPOINTER:
- typeofv = TYPEOF_IPOINTER;
- break;
- case ARRAY:
- typeofv = TYPEOF_ARRAY;
- break;
- case FUNCTION:
- typeofv = TYPEOF_FUNCTION;
- break;
- default:
- break;
- }
- }
- SNPRINTF (buffer, sizeof(buffer), "%d", typeofv);
- tree->opval.val = constVal (buffer);
- tree->right = tree->left = NULL;
- TETYPE (tree) = getSpec (TTYPE (tree) =
- tree->opval.val->type);
- }
- return tree;
+ /* return typeof enum value */
+ tree->type = EX_VALUE;
+ {
+ int typeofv = 0;
+ if (IS_SPEC(tree->right->ftype)) {
+ switch (SPEC_NOUN(tree->right->ftype)) {
+ case V_INT:
+ if (SPEC_LONG(tree->right->ftype)) typeofv = TYPEOF_LONG;
+ else typeofv = TYPEOF_INT;
+ break;
+ case V_FLOAT:
+ typeofv = TYPEOF_FLOAT;
+ break;
+ case V_CHAR:
+ typeofv = TYPEOF_CHAR;
+ break;
+ case V_VOID:
+ typeofv = TYPEOF_VOID;
+ break;
+ case V_STRUCT:
+ typeofv = TYPEOF_STRUCT;
+ break;
+ case V_BITFIELD:
+ typeofv = TYPEOF_BITFIELD;
+ break;
+ case V_BIT:
+ typeofv = TYPEOF_BIT;
+ break;
+ case V_SBIT:
+ typeofv = TYPEOF_SBIT;
+ break;
+ default:
+ break;
+ }
+ } else {
+ switch (DCL_TYPE(tree->right->ftype)) {
+ case POINTER:
+ typeofv = TYPEOF_POINTER;
+ break;
+ case FPOINTER:
+ typeofv = TYPEOF_FPOINTER;
+ break;
+ case CPOINTER:
+ typeofv = TYPEOF_CPOINTER;
+ break;
+ case GPOINTER:
+ typeofv = TYPEOF_GPOINTER;
+ break;
+ case PPOINTER:
+ typeofv = TYPEOF_PPOINTER;
+ break;
+ case IPOINTER:
+ typeofv = TYPEOF_IPOINTER;
+ break;
+ case ARRAY:
+ typeofv = TYPEOF_ARRAY;
+ break;
+ case FUNCTION:
+ typeofv = TYPEOF_FUNCTION;
+ break;
+ default:
+ break;
+ }
+ }
+ SNPRINTF (buffer, sizeof(buffer), "%d", typeofv);
+ tree->opval.val = constVal (buffer);
+ tree->right = tree->left = NULL;
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ tree->opval.val->type);
+ }
+ return tree;
/*------------------------------------------------------------------*/
/*----------------------------*/
/* conditional operator '?' */
/* the type is value of the colon operator (on the right) */
assert (IS_COLON_OP (tree->right));
/* if already known then replace the tree : optimizer will do it
- but faster to do it here */
+ but faster to do it here */
if (IS_LITERAL (LTYPE (tree)))
- {
- if (((int) floatFromVal (valFromType (LETYPE (tree)))) != 0)
+ {
+ if (((int) floatFromVal (valFromType (LETYPE (tree)))) != 0)
return decorateType (tree->right->left, resultTypeProp);
- else
- return decorateType (tree->right->right, resultTypeProp);
- }
+ else
+ return decorateType (tree->right->right, resultTypeProp);
+ }
else
- {
- tree->right = decorateType (tree->right, resultTypeProp);
- TTYPE (tree) = RTYPE (tree);
- TETYPE (tree) = getSpec (TTYPE (tree));
- }
+ {
+ tree->right = decorateType (tree->right, resultTypeProp);
+ TTYPE (tree) = RTYPE (tree);
+ TETYPE (tree) = getSpec (TTYPE (tree));
+ }
return tree;
case ':':
/* if they don't match we have a problem */
if (compareType (LTYPE (tree), RTYPE (tree)) == 0)
- {
- werror (E_TYPE_MISMATCH, "conditional operator", " ");
- goto errorTreeReturn;
- }
+ {
+ werror (E_TYPE_MISMATCH, "conditional operator", " ");
+ goto errorTreeReturn;
+ }
TTYPE (tree) = computeType (LTYPE (tree), RTYPE (tree),
resultType, tree->opval.op);
case DIV_ASSIGN:
/* for these it must be both must be integral */
if (!IS_ARITHMETIC (LTYPE (tree)) ||
- !IS_ARITHMETIC (RTYPE (tree)))
- {
- werror (E_OPS_INTEGRAL);
- goto errorTreeReturn;
- }
+ !IS_ARITHMETIC (RTYPE (tree)))
+ {
+ werror (E_OPS_INTEGRAL);
+ goto errorTreeReturn;
+ }
RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree));
if (!tree->initMode && IS_CONSTANT (LTYPE (tree)))
- werror (E_CODE_WRITE, tree->opval.op==MUL_ASSIGN ? "*=" : "/=");
+ werror (E_CODE_WRITE, tree->opval.op==MUL_ASSIGN ? "*=" : "/=");
if (LRVAL (tree))
- {
- werror (E_LVALUE_REQUIRED, tree->opval.op==MUL_ASSIGN ? "*=" : "/=");
- goto errorTreeReturn;
- }
+ {
+ werror (E_LVALUE_REQUIRED, tree->opval.op==MUL_ASSIGN ? "*=" : "/=");
+ goto errorTreeReturn;
+ }
LLVAL (tree) = 1;
return tree;
case LEFT_ASSIGN:
/* for these it must be both must be integral */
if (!IS_INTEGRAL (LTYPE (tree)) ||
- !IS_INTEGRAL (RTYPE (tree)))
- {
- werror (E_OPS_INTEGRAL);
- goto errorTreeReturn;
- }
+ !IS_INTEGRAL (RTYPE (tree)))
+ {
+ werror (E_OPS_INTEGRAL);
+ goto errorTreeReturn;
+ }
RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree));
if (!tree->initMode && IS_CONSTANT (LETYPE (tree)))
- werror (E_CODE_WRITE, "&= or |= or ^= or >>= or <<=");
+ werror (E_CODE_WRITE, "&= or |= or ^= or >>= or <<=");
if (LRVAL (tree))
- {
- werror (E_LVALUE_REQUIRED, "&= or |= or ^= or >>= or <<=");
- goto errorTreeReturn;
- }
+ {
+ werror (E_LVALUE_REQUIRED, "&= or |= or ^= or >>= or <<=");
+ goto errorTreeReturn;
+ }
LLVAL (tree) = 1;
return tree;
/*----------------------------*/
case SUB_ASSIGN:
if (!(IS_PTR (LTYPE (tree)) ||
- IS_ARITHMETIC (LTYPE (tree))))
- {
- werror (E_PLUS_INVALID, "-=");
- goto errorTreeReturn;
- }
+ IS_ARITHMETIC (LTYPE (tree))))
+ {
+ werror (E_PLUS_INVALID, "-=");
+ goto errorTreeReturn;
+ }
if (!(IS_PTR (RTYPE (tree)) ||
- IS_ARITHMETIC (RTYPE (tree))))
- {
- werror (E_PLUS_INVALID, "-=");
- goto errorTreeReturn;
- }
+ IS_ARITHMETIC (RTYPE (tree))))
+ {
+ werror (E_PLUS_INVALID, "-=");
+ goto errorTreeReturn;
+ }
RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) =
- computeType (LTYPE (tree),
- RTYPE (tree),
- RESULT_TYPE_NOPROM,
- tree->opval.op));
+ computeType (LTYPE (tree),
+ RTYPE (tree),
+ RESULT_TYPE_NOPROM,
+ tree->opval.op));
if (!tree->initMode && IS_CONSTANT (LETYPE (tree)))
- werror (E_CODE_WRITE, "-=");
+ werror (E_CODE_WRITE, "-=");
if (LRVAL (tree))
- {
- werror (E_LVALUE_REQUIRED, "-=");
- goto errorTreeReturn;
- }
+ {
+ werror (E_LVALUE_REQUIRED, "-=");
+ goto errorTreeReturn;
+ }
LLVAL (tree) = 1;
return tree;
/* this is not a unary operation */
/* if both pointers then problem */
if (IS_PTR (LTYPE (tree)) && IS_PTR (RTYPE (tree)))
- {
- werror (E_PTR_PLUS_PTR);
- goto errorTreeReturn;
- }
+ {
+ werror (E_PTR_PLUS_PTR);
+ goto errorTreeReturn;
+ }
if (!IS_ARITHMETIC (LTYPE (tree)) && !IS_PTR (LTYPE (tree)))
- {
- werror (E_PLUS_INVALID, "+=");
- goto errorTreeReturn;
- }
+ {
+ werror (E_PLUS_INVALID, "+=");
+ goto errorTreeReturn;
+ }
if (!IS_ARITHMETIC (RTYPE (tree)) && !IS_PTR (RTYPE (tree)))
- {
- werror (E_PLUS_INVALID, "+=");
- goto errorTreeReturn;
- }
+ {
+ werror (E_PLUS_INVALID, "+=");
+ goto errorTreeReturn;
+ }
RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) =
- computeType (LTYPE (tree),
- RTYPE (tree),
- RESULT_TYPE_NOPROM,
- tree->opval.op));
+ computeType (LTYPE (tree),
+ RTYPE (tree),
+ RESULT_TYPE_NOPROM,
+ tree->opval.op));
if (!tree->initMode && IS_CONSTANT (LETYPE (tree)))
- werror (E_CODE_WRITE, "+=");
+ werror (E_CODE_WRITE, "+=");
if (LRVAL (tree))
- {
- werror (E_LVALUE_REQUIRED, "+=");
- goto errorTreeReturn;
- }
+ {
+ werror (E_LVALUE_REQUIRED, "+=");
+ goto errorTreeReturn;
+ }
tree->right = decorateType (newNode ('+', copyAst (tree->left), tree->right), RESULT_CHECK);
tree->opval.op = '=';
case '=':
/* cannot be an aggregate */
if (IS_AGGREGATE (LTYPE (tree)))
- {
- werror (E_AGGR_ASSIGN);
- goto errorTreeReturn;
- }
+ {
+ werror (E_AGGR_ASSIGN);
+ goto errorTreeReturn;
+ }
/* they should either match or be castable */
if (compareType (LTYPE (tree), RTYPE (tree)) == 0)
- {
- werror (E_TYPE_MISMATCH, "assignment", " ");
- printFromToType(RTYPE(tree),LTYPE(tree));
- }
+ {
+ werror (E_TYPE_MISMATCH, "assignment", " ");
+ printFromToType(RTYPE(tree),LTYPE(tree));
+ }
/* if the left side of the tree is of type void
then report error */
if (IS_VOID (LTYPE (tree)))
- {
- werror (E_CAST_ZERO);
- printFromToType(RTYPE(tree), LTYPE(tree));
- }
+ {
+ werror (E_CAST_ZERO);
+ printFromToType(RTYPE(tree), LTYPE(tree));
+ }
TETYPE (tree) = getSpec (TTYPE (tree) =
- LTYPE (tree));
+ LTYPE (tree));
RRVAL (tree) = 1;
LLVAL (tree) = 1;
if (!tree->initMode ) {
if (IS_CONSTANT(LTYPE(tree)))
- werror (E_CODE_WRITE, "=");
+ werror (E_CODE_WRITE, "=");
}
if (LRVAL (tree))
- {
- werror (E_LVALUE_REQUIRED, "=");
- goto errorTreeReturn;
- }
+ {
+ werror (E_LVALUE_REQUIRED, "=");
+ goto errorTreeReturn;
+ }
return tree;
/* undo any explicit pointer derefernce; PCALL will handle it instead */
if (IS_FUNC (LTYPE (tree)) && tree->left->type == EX_OP)
{
- if (tree->left->opval.op == '*' && !tree->left->right)
- tree->left = tree->left->left;
- }
+ if (tree->left->opval.op == '*' && !tree->left->right)
+ tree->left = tree->left->left;
+ }
/* require a function or pointer to function */
if (!IS_FUNC (LTYPE (tree))
&& !(IS_CODEPTR (LTYPE (tree)) && IS_FUNC (LTYPE (tree)->next)))
- {
- werrorfl (tree->filename, tree->lineno, E_FUNCTION_EXPECTED);
- goto errorTreeReturn;
- }
+ {
+ werrorfl (tree->filename, tree->lineno, E_FUNCTION_EXPECTED);
+ goto errorTreeReturn;
+ }
/* if there are parms, make sure that
parms are decorate / process / reverse only once */
/*----------------------------*/
case RETURN:
if (!tree->right)
- goto voidcheck;
+ goto voidcheck;
if (compareType (currFunc->type->next, RTYPE (tree)) == 0)
- {
- werrorfl (tree->filename, tree->lineno, W_RETURN_MISMATCH);
- printFromToType (RTYPE(tree), currFunc->type->next);
- goto errorTreeReturn;
- }
+ {
+ werrorfl (tree->filename, tree->lineno, W_RETURN_MISMATCH);
+ printFromToType (RTYPE(tree), currFunc->type->next);
+ goto errorTreeReturn;
+ }
if (IS_VOID (currFunc->type->next)
- && tree->right &&
- !IS_VOID (RTYPE (tree)))
- {
- werrorfl (tree->filename, tree->lineno, E_FUNC_VOID);
- goto errorTreeReturn;
- }
+ && tree->right &&
+ !IS_VOID (RTYPE (tree)))
+ {
+ werrorfl (tree->filename, tree->lineno, E_FUNC_VOID);
+ goto errorTreeReturn;
+ }
/* if there is going to be a casting required then add it */
if (compareType (currFunc->type->next, RTYPE (tree)) < 0)
- {
- tree->right =
- decorateType (newNode (CAST,
- newAst_LINK (copyLinkChain (currFunc->type->next)),
- tree->right),
- RESULT_CHECK);
- }
+ {
+ tree->right =
+ decorateType (newNode (CAST,
+ newAst_LINK (copyLinkChain (currFunc->type->next)),
+ tree->right),
+ RESULT_CHECK);
+ }
RRVAL (tree) = 1;
return tree;
voidcheck:
if (!IS_VOID (currFunc->type->next) && tree->right == NULL)
- {
- werror (W_VOID_FUNC, currFunc->name);
- goto errorTreeReturn;
- }
+ {
+ werror (W_VOID_FUNC, currFunc->name);
+ goto errorTreeReturn;
+ }
TTYPE (tree) = TETYPE (tree) = NULL;
return tree;
case SWITCH:
/* the switch value must be an integer */
if (!IS_INTEGRAL (LTYPE (tree)))
- {
- werrorfl (tree->filename, tree->lineno, E_SWITCH_NON_INTEGER);
- goto errorTreeReturn;
- }
+ {
+ werrorfl (tree->filename, tree->lineno, E_SWITCH_NON_INTEGER);
+ goto errorTreeReturn;
+ }
LRVAL (tree) = 1;
TTYPE (tree) = TETYPE (tree) = NULL;
return tree;
/*----------------------------*/
case IFX:
tree->left = backPatchLabels (tree->left,
- tree->trueLabel,
- tree->falseLabel);
+ tree->trueLabel,
+ tree->falseLabel);
TTYPE (tree) = TETYPE (tree) = NULL;
return tree;
reverse it otherwise do what we normally
do */
{
- symbol *sym;
- ast *init, *end;
-
- if (isLoopReversible (tree, &sym, &init, &end))
- return reverseLoop (tree, sym, init, end);
- else
- return decorateType (createFor (AST_FOR (tree, trueLabel),
- AST_FOR (tree, continueLabel),
- AST_FOR (tree, falseLabel),
- AST_FOR (tree, condLabel),
- AST_FOR (tree, initExpr),
- AST_FOR (tree, condExpr),
- AST_FOR (tree, loopExpr),
- tree->left), RESULT_CHECK);
+ symbol *sym;
+ ast *init, *end;
+
+ if (isLoopReversible (tree, &sym, &init, &end))
+ return reverseLoop (tree, sym, init, end);
+ else
+ return decorateType (createFor (AST_FOR (tree, trueLabel),
+ AST_FOR (tree, continueLabel),
+ AST_FOR (tree, falseLabel),
+ AST_FOR (tree, condLabel),
+ AST_FOR (tree, initExpr),
+ AST_FOR (tree, condExpr),
+ AST_FOR (tree, loopExpr),
+ tree->left), RESULT_CHECK);
}
case PARAM:
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
- "node PARAM shouldn't be processed here");
- /* but in processParams() */
+ "node PARAM shouldn't be processed here");
+ /* but in processParams() */
return tree;
default:
TTYPE (tree) = TETYPE (tree) = NULL;
/* if left is already a IFX then just change the if true label in that */
if (!IS_IFX (tree->left))
- tree->left = newIfxNode (tree->left, localLabel, falseLabel);
+ tree->left = newIfxNode (tree->left, localLabel, falseLabel);
tree->right = backPatchLabels (tree->right, trueLabel, falseLabel);
/* right is a IFX then just join */
if (IS_IFX (tree->right))
- return newNode (NULLOP, tree->left, createLabel (localLabel, tree->right));
+ return newNode (NULLOP, tree->left, createLabel (localLabel, tree->right));
tree->right = createLabel (localLabel, tree->right);
tree->right = newIfxNode (tree->right, trueLabel, falseLabel);
/* if left is already a IFX then just change the if true label in that */
if (!IS_IFX (tree->left))
- tree->left = newIfxNode (tree->left, trueLabel, localLabel);
+ tree->left = newIfxNode (tree->left, trueLabel, localLabel);
tree->right = backPatchLabels (tree->right, trueLabel, falseLabel);
/* right is a IFX then just join */
if (IS_IFX (tree->right))
- return newNode (NULLOP, tree->left, createLabel (localLabel, tree->right));
+ return newNode (NULLOP, tree->left, createLabel (localLabel, tree->right));
tree->right = createLabel (localLabel, tree->right);
tree->right = newIfxNode (tree->right, trueLabel, falseLabel);
/* if the left is already a IFX */
if (!IS_IFX (tree->left))
- tree->left = newNode (IFX, tree->left, NULL);
+ tree->left = newNode (IFX, tree->left, NULL);
if (wasnot)
- {
- tree->left->trueLabel = trueLabel;
- tree->left->falseLabel = falseLabel;
- }
+ {
+ tree->left->trueLabel = trueLabel;
+ tree->left->falseLabel = falseLabel;
+ }
else
- {
- tree->left->trueLabel = falseLabel;
- tree->left->falseLabel = trueLabel;
- }
+ {
+ tree->left->trueLabel = falseLabel;
+ tree->left->falseLabel = trueLabel;
+ }
return tree->left;
}
value *pval = NULL;
int cVal = (int) floatFromVal (caseVal->opval.val);
while (val && (int) floatFromVal (val) < cVal)
- {
- pval = val;
- val = val->next;
- }
+ {
+ pval = val;
+ val = val->next;
+ }
/* if we reached the end then */
if (!val)
- {
- pval->next = caseVal->opval.val;
- }
+ {
+ pval->next = caseVal->opval.val;
+ }
else if ((int) floatFromVal (val) == cVal)
- {
- werrorfl (caseVal->filename, caseVal->lineno, E_DUPLICATE_LABEL,
- "case");
- return NULL;
- }
+ {
+ werrorfl (caseVal->filename, caseVal->lineno, E_DUPLICATE_LABEL,
+ "case");
+ return NULL;
+ }
else
- {
- /* we found a value greater than */
- /* the current value we must add this */
- /* before the value */
- caseVal->opval.val->next = val;
-
- /* if this was the first in chain */
- if (swStat->values.switchVals.swVals == val)
- swStat->values.switchVals.swVals =
- caseVal->opval.val;
- else
- pval->next = caseVal->opval.val;
- }
+ {
+ /* we found a value greater than */
+ /* the current value we must add this */
+ /* before the value */
+ caseVal->opval.val->next = val;
+
+ /* if this was the first in chain */
+ if (swStat->values.switchVals.swVals == val)
+ swStat->values.switchVals.swVals =
+ caseVal->opval.val;
+ else
+ pval->next = caseVal->opval.val;
+ }
}
/* create the case label */
SNPRINTF(caseLbl, sizeof(caseLbl),
- "_case_%d_%d",
- swStat->values.switchVals.swNum,
- (int) floatFromVal (caseVal->opval.val));
+ "_case_%d_%d",
+ swStat->values.switchVals.swNum,
+ (int) floatFromVal (caseVal->opval.val));
rexpr = createLabel (newSymbol (caseLbl, 0), stmnt);
rexpr->lineno = 0;
if (swStat->values.switchVals.swDefault)
{
werrorfl (defaultVal->filename, defaultVal->lineno, E_DUPLICATE_LABEL,
- "default");
+ "default");
return NULL;
}
/* create the label */
SNPRINTF (defLbl, sizeof(defLbl),
- "_default_%d", swStat->values.switchVals.swNum);
+ "_default_%d", swStat->values.switchVals.swNum);
return createLabel (newSymbol (defLbl, 0), stmnt);
}
if (elseBody)
{
ifBody = newNode (NULLOP, ifBody,
- newNode (GOTO,
- newAst_VALUE (symbolVal (ifEnd)),
- NULL));
+ newNode (GOTO,
+ newAst_VALUE (symbolVal (ifEnd)),
+ NULL));
/* put the elseLabel on the else body */
elseBody = createLabel (ifFalse, elseBody);
/* out the end at the end of the body */
elseBody = newNode (NULLOP,
- elseBody,
- createLabel (ifEnd, NULL));
+ elseBody,
+ createLabel (ifEnd, NULL));
}
else
{
ifBody = newNode (NULLOP, ifBody,
- createLabel (ifFalse, NULL));
+ createLabel (ifFalse, NULL));
}
condAst = backPatchLabels (condAst, ifTrue, ifFalse);
if (IS_IFX (condAst))
ifTree = newIfxNode (condAst, ifTrue, ifFalse);
return newNode (NULLOP, ifTree,
- newNode (NULLOP, ifBody, elseBody));
+ newNode (NULLOP, ifBody, elseBody));
}
/*-----------------------------------------------------------------*/
ast *
createDo (symbol * trueLabel, symbol * continueLabel,
- symbol * falseLabel, ast * condAst, ast * doBody)
+ symbol * falseLabel, ast * condAst, ast * doBody)
{
ast *doTree;
{
condAst = backPatchLabels (condAst, continueLabel, NULL);
doTree = (IS_IFX (condAst) ? createLabel (continueLabel, condAst)
- : newNode (IFX, createLabel (continueLabel, condAst), NULL));
+ : newNode (IFX, createLabel (continueLabel, condAst), NULL));
doTree->trueLabel = continueLabel;
doTree->falseLabel = NULL;
return doTree;
doBody = createLabel (trueLabel, doBody);
/* attach the continue label to end of body */
doBody = newNode (NULLOP, doBody,
- createLabel (continueLabel, NULL));
+ createLabel (continueLabel, NULL));
/* now put the break label at the end */
if (IS_IFX (condAst))
/*-----------------------------------------------------------------*/
ast *
createFor (symbol * trueLabel, symbol * continueLabel,
- symbol * falseLabel, symbol * condLabel,
- ast * initExpr, ast * condExpr, ast * loopExpr,
- ast * forBody)
+ symbol * falseLabel, symbol * condLabel,
+ ast * initExpr, ast * condExpr, ast * loopExpr,
+ ast * forBody)
{
ast *forTree;
/* the same way as a while */
if (!loopExpr)
return newNode (NULLOP, initExpr,
- createWhile (trueLabel, continueLabel,
- falseLabel, condExpr, forBody));
+ createWhile (trueLabel, continueLabel,
+ falseLabel, condExpr, forBody));
/* vanilla for statement */
condExpr = backPatchLabels (condExpr, trueLabel, falseLabel);
/* attach continue to forLoop expression & attach */
/* goto the forcond @ and of loopExpression */
loopExpr = createLabel (continueLabel,
- newNode (NULLOP,
- loopExpr,
- newNode (GOTO,
- newAst_VALUE (symbolVal (condLabel)),
- NULL)));
+ newNode (NULLOP,
+ loopExpr,
+ newNode (GOTO,
+ newAst_VALUE (symbolVal (condLabel)),
+ NULL)));
/* now start putting them together */
forTree = newNode (NULLOP, initExpr, condExpr);
forTree = newNode (NULLOP, forTree, forBody);
forTree = newNode (NULLOP, forTree, loopExpr);
/* finally add the break label */
forTree = newNode (NULLOP, forTree,
- createLabel (falseLabel, NULL));
+ createLabel (falseLabel, NULL));
return forTree;
}
/*-----------------------------------------------------------------*/
ast *
createWhile (symbol * trueLabel, symbol * continueLabel,
- symbol * falseLabel, ast * condExpr, ast * whileBody)
+ symbol * falseLabel, ast * condExpr, ast * whileBody)
{
ast *whileTree;
/* put a jump to continue at the end of the body */
/* and put break label at the end of the body */
whileBody = newNode (NULLOP,
- whileBody,
- newNode (GOTO,
- newAst_VALUE (symbolVal (continueLabel)),
- createLabel (falseLabel, NULL)));
+ whileBody,
+ newNode (GOTO,
+ newAst_VALUE (symbolVal (continueLabel)),
+ createLabel (falseLabel, NULL)));
/* put it all together */
if (IS_IFX (condExpr))
{
if (!SPEC_USIGN (TETYPE (root->left->left)))
- return root;
+ return root;
if (!IS_AST_LIT_VALUE (root->left->right) ||
- !IS_AST_LIT_VALUE (root->right->right))
- goto tryNext0;
+ !IS_AST_LIT_VALUE (root->right->right))
+ goto tryNext0;
/* make sure it is the same expression */
if (!isAstEqual (root->left->left,
- root->right->left))
- goto tryNext0;
+ root->right->left))
+ goto tryNext0;
if (AST_LIT_VALUE (root->left->right) != 1)
- goto tryNext0;
+ goto tryNext0;
if (AST_LIT_VALUE (root->right->right) !=
- (getSize (TTYPE (root->left->left)) * 8 - 1))
- goto tryNext0;
+ (getSize (TTYPE (root->left->left)) * 8 - 1))
+ goto tryNext0;
/* make sure the port supports RLC */
if (port->hasExtBitOp
{
if (!SPEC_USIGN (TETYPE (root->left->left)))
- return root;
+ return root;
if (!IS_AST_LIT_VALUE (root->left->right) ||
- !IS_AST_LIT_VALUE (root->right->right))
- goto tryNext1;
+ !IS_AST_LIT_VALUE (root->right->right))
+ goto tryNext1;
/* make sure it is the same symbol */
if (!isAstEqual (root->left->left,
- root->right->left))
- goto tryNext1;
+ root->right->left))
+ goto tryNext1;
if (AST_LIT_VALUE (root->right->right) != 1)
- goto tryNext1;
+ goto tryNext1;
if (AST_LIT_VALUE (root->left->right) !=
- (getSize (TTYPE (root->left->left)) * 8 - 1))
- goto tryNext1;
+ (getSize (TTYPE (root->left->left)) * 8 - 1))
+ goto tryNext1;
/* make sure the port supports RLC */
if (port->hasExtBitOp
{
if (!SPEC_USIGN (TETYPE (root->left->left)))
- return root;
+ return root;
if (!IS_AST_LIT_VALUE (root->left->right) ||
- !IS_AST_LIT_VALUE (root->right->right))
- goto tryNext2;
+ !IS_AST_LIT_VALUE (root->right->right))
+ goto tryNext2;
/* make sure it is the same symbol */
if (!isAstEqual (root->left->left,
- root->right->left))
- goto tryNext2;
+ root->right->left))
+ goto tryNext2;
if (AST_LIT_VALUE (root->left->right) != 1)
- goto tryNext2;
+ goto tryNext2;
if (AST_LIT_VALUE (root->right->right) !=
- (getSize (TTYPE (root->left->left)) * 8 - 1))
- goto tryNext2;
+ (getSize (TTYPE (root->left->left)) * 8 - 1))
+ goto tryNext2;
/* make sure the port supports RRC */
if (port->hasExtBitOp
{
if (!SPEC_USIGN (TETYPE (root->left->left)))
- return root;
+ return root;
if (!IS_AST_LIT_VALUE (root->left->right) ||
- !IS_AST_LIT_VALUE (root->right->right))
- return root;
+ !IS_AST_LIT_VALUE (root->right->right))
+ return root;
/* make sure it is the same symbol */
if (!isAstEqual (root->left->left,
- root->right->left))
- return root;
+ root->right->left))
+ return root;
if (AST_LIT_VALUE (root->right->right) != 1)
- return root;
+ return root;
if (AST_LIT_VALUE (root->left->right) !=
- (getSize (TTYPE (root->left->left)) * 8 - 1))
- return root;
+ (getSize (TTYPE (root->left->left)) * 8 - 1))
+ return root;
/* make sure the port supports RRC */
if (port->hasExtBitOp
{
if (!SPEC_USIGN (TETYPE (root->left->left)))
- return root;
+ return root;
if (!IS_AST_LIT_VALUE (root->left->right) ||
- !IS_AST_LIT_VALUE (root->right->right))
- return root;
+ !IS_AST_LIT_VALUE (root->right->right))
+ return root;
/* make sure it is the same expression */
if (!isAstEqual (root->left->left,
- root->right->left))
- return root;
+ root->right->left))
+ return root;
if (AST_LIT_VALUE (root->left->right) !=
- (getSize (TTYPE (root->left->left)) * 4))
- return root;
+ (getSize (TTYPE (root->left->left)) * 4))
+ return root;
if (AST_LIT_VALUE (root->right->right) !=
- (getSize (TTYPE (root->left->left)) * 4))
- return root;
+ (getSize (TTYPE (root->left->left)) * 4))
+ return root;
/* make sure the port supports SWAP */
if (port->hasExtBitOp
if (isAstEqual (root->left, root->right))
{
switch (root->opval.op)
- {
- case '>':
- case '<':
- case NE_OP:
- optExpr = newAst_VALUE (constVal ("0"));
- break;
- case GE_OP:
- case LE_OP:
- case EQ_OP:
- optExpr = newAst_VALUE (constVal ("1"));
- break;
- }
+ {
+ case '>':
+ case '<':
+ case NE_OP:
+ optExpr = newAst_VALUE (constVal ("0"));
+ break;
+ case GE_OP:
+ case LE_OP:
+ case EQ_OP:
+ optExpr = newAst_VALUE (constVal ("1"));
+ break;
+ }
return decorateType (optExpr, RESULT_CHECK);
}
vleft = (root->left->type == EX_VALUE ?
- root->left->opval.val : NULL);
+ root->left->opval.val : NULL);
vright = (root->right->type == EX_VALUE ?
- root->right->opval.val : NULL);
+ root->right->opval.val : NULL);
/* if left is a BITVAR in BITSPACE */
/* and right is a LITERAL then opt- */
/* if right side > 1 then comparison may never succeed */
if ((litValue = (int) floatFromVal (vright)) > 1)
- {
- werror (W_BAD_COMPARE);
- goto noOptimize;
- }
+ {
+ werror (W_BAD_COMPARE);
+ goto noOptimize;
+ }
if (litValue)
- {
- switch (root->opval.op)
- {
- case '>': /* bit value greater than 1 cannot be */
- werror (W_BAD_COMPARE);
- goto noOptimize;
- break;
-
- case '<': /* bit value < 1 means 0 */
- case NE_OP:
- optExpr = newNode ('!', newAst_VALUE (vleft), NULL);
- break;
-
- case LE_OP: /* bit value <= 1 means no check */
- optExpr = newAst_VALUE (vright);
- break;
-
- case GE_OP: /* bit value >= 1 means only check for = */
- case EQ_OP:
- optExpr = newAst_VALUE (vleft);
- break;
- }
- }
+ {
+ switch (root->opval.op)
+ {
+ case '>': /* bit value greater than 1 cannot be */
+ werror (W_BAD_COMPARE);
+ goto noOptimize;
+ break;
+
+ case '<': /* bit value < 1 means 0 */
+ case NE_OP:
+ optExpr = newNode ('!', newAst_VALUE (vleft), NULL);
+ break;
+
+ case LE_OP: /* bit value <= 1 means no check */
+ optExpr = newAst_VALUE (vright);
+ break;
+
+ case GE_OP: /* bit value >= 1 means only check for = */
+ case EQ_OP:
+ optExpr = newAst_VALUE (vleft);
+ break;
+ }
+ }
else
- { /* literal is zero */
- switch (root->opval.op)
- {
- case '<': /* bit value < 0 cannot be */
- werror (W_BAD_COMPARE);
- goto noOptimize;
- break;
-
- case '>': /* bit value > 0 means 1 */
- case NE_OP:
- optExpr = newAst_VALUE (vleft);
- break;
-
- case LE_OP: /* bit value <= 0 means no check */
- case GE_OP: /* bit value >= 0 means no check */
- werror (W_BAD_COMPARE);
- goto noOptimize;
- break;
-
- case EQ_OP: /* bit == 0 means ! of bit */
- optExpr = newNode ('!', newAst_VALUE (vleft), NULL);
- break;
- }
- }
+ { /* literal is zero */
+ switch (root->opval.op)
+ {
+ case '<': /* bit value < 0 cannot be */
+ werror (W_BAD_COMPARE);
+ goto noOptimize;
+ break;
+
+ case '>': /* bit value > 0 means 1 */
+ case NE_OP:
+ optExpr = newAst_VALUE (vleft);
+ break;
+
+ case LE_OP: /* bit value <= 0 means no check */
+ case GE_OP: /* bit value >= 0 means no check */
+ werror (W_BAD_COMPARE);
+ goto noOptimize;
+ break;
+
+ case EQ_OP: /* bit == 0 means ! of bit */
+ optExpr = newNode ('!', newAst_VALUE (vleft), NULL);
+ break;
+ }
+ }
return decorateType (resolveSymbols (optExpr), RESULT_CHECK);
- } /* end-of-if of BITVAR */
+ } /* end-of-if of BITVAR */
noOptimize:
return root;
while (args)
{
if (IS_REGPARM (args->etype))
- addSymToBlock (args->sym, body);
+ addSymToBlock (args->sym, body);
args = args->next;
}
}
actually means we are now compiling the compiler
support routine */
if (name->cdef)
- {
- addSet (&publics, name);
- }
+ {
+ addSet (&publics, name);
+ }
}
else
{
xstackPtr = -port->stack.direction * port->stack.call_overhead;
- fetype = getSpec (name->type); /* get the specifier for the function */
+ fetype = getSpec (name->type); /* get the specifier for the function */
/* if this is a reentrant function then */
if (IFFUNC_ISREENT (name->type))
reentrant++;
- allocParms (FUNC_ARGS(name->type)); /* allocate the parameters */
+ allocParms (FUNC_ARGS(name->type)); /* allocate the parameters */
/* do processing for parameters that are passed in registers */
processRegParms (FUNC_ARGS(name->type), body);
/* name needs to be mangled */
SNPRINTF (name->rname, sizeof(name->rname), "%s%s", port->fun_prefix, name->name);
- body = resolveSymbols (body); /* resolve the symbols */
- body = decorateType (body, RESULT_TYPE_NONE); /* propagateType & do semantic checks */
-
+ body = resolveSymbols (body); /* resolve the symbols */
+ body = decorateType (body, RESULT_TYPE_NONE); /* propagateType & do semantic checks */
+
- ex = newAst_VALUE (symbolVal (name)); /* create name */
+ ex = newAst_VALUE (symbolVal (name)); /* create name */
ex = newNode (FUNCTION, ex, body);
ex->values.args = FUNC_ARGS(name->type);
ex->decorated=1;
void ast_print (ast * tree, FILE *outfile, int indent)
{
- if (!tree) return ;
-
- /* can print only decorated trees */
- if (!tree->decorated) return;
-
- /* if any child is an error | this one is an error do nothing */
- if (tree->isError ||
- (tree->left && tree->left->isError) ||
- (tree->right && tree->right->isError)) {
- fprintf(outfile,"ERROR_NODE(%p)\n",tree);
- }
-
-
- /* print the line */
- /* if not block & function */
- if (tree->type == EX_OP &&
- (tree->opval.op != FUNCTION &&
- tree->opval.op != BLOCK &&
- tree->opval.op != NULLOP)) {
- }
-
- if (tree->opval.op == FUNCTION) {
- int arg=0;
- value *args=FUNC_ARGS(tree->left->opval.val->type);
- fprintf(outfile,"FUNCTION (%s=%p) type (",
- tree->left->opval.val->name, tree);
- printTypeChain (tree->left->opval.val->type->next,outfile);
- fprintf(outfile,") args (");
- do {
- if (arg) {
- fprintf (outfile, ", ");
- }
- printTypeChain (args ? args->type : NULL, outfile);
- arg++;
- args= args ? args->next : NULL;
- } while (args);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent);
- ast_print(tree->right,outfile,indent);
- return ;
- }
- if (tree->opval.op == BLOCK) {
- symbol *decls = tree->values.sym;
- INDENT(indent,outfile);
- fprintf(outfile,"{\n");
- while (decls) {
- INDENT(indent+2,outfile);
- fprintf(outfile,"DECLARE SYMBOL (%s=%p) type (",
- decls->name, decls);
- printTypeChain(decls->type,outfile);
- fprintf(outfile,")\n");
-
- decls = decls->next;
- }
- ast_print(tree->right,outfile,indent+2);
- INDENT(indent,outfile);
- fprintf(outfile,"}\n");
- return;
- }
- if (tree->opval.op == NULLOP) {
- ast_print(tree->left,outfile,indent);
- ast_print(tree->right,outfile,indent);
- return ;
- }
- INDENT(indent,outfile);
-
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* leaf has been reached */
- /*----------------------------*/
- /* if this is of type value */
- /* just get the type */
- if (tree->type == EX_VALUE) {
-
- if (IS_LITERAL (tree->opval.val->etype)) {
- fprintf(outfile,"CONSTANT (%p) value = ", tree);
- if (SPEC_USIGN (tree->opval.val->etype))
- fprintf(outfile,"%u", (TYPE_UDWORD) floatFromVal(tree->opval.val));
- else
- fprintf(outfile,"%d", (TYPE_DWORD) floatFromVal(tree->opval.val));
- fprintf(outfile,", 0x%x, %f", (TYPE_UDWORD) floatFromVal(tree->opval.val),
- floatFromVal(tree->opval.val));
- } else if (tree->opval.val->sym) {
- /* if the undefined flag is set then give error message */
- if (tree->opval.val->sym->undefined) {
- fprintf(outfile,"UNDEFINED SYMBOL ");
- } else {
- fprintf(outfile,"SYMBOL ");
- }
- fprintf(outfile,"(%s=%p)",
- tree->opval.val->sym->name,tree);
- }
- if (tree->ftype) {
- fprintf(outfile," type (");
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- } else {
- fprintf(outfile,"\n");
- }
- return ;
- }
-
- /* if type link for the case of cast */
- if (tree->type == EX_LINK) {
- fprintf(outfile,"TYPENODE (%p) type = (",tree);
- printTypeChain(tree->opval.lnk,outfile);
- fprintf(outfile,")\n");
- return ;
- }
-
-
- /* depending on type of operator do */
-
- switch (tree->opval.op) {
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* array node */
- /*----------------------------*/
- case '[':
- fprintf(outfile,"ARRAY_OP (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
-
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* struct/union */
- /*----------------------------*/
- case '.':
- fprintf(outfile,"STRUCT_ACCESS (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
-
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* struct/union pointer */
- /*----------------------------*/
- case PTR_OP:
- fprintf(outfile,"PTR_ACCESS (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
-
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* ++/-- operation */
- /*----------------------------*/
- case INC_OP:
- if (tree->left)
- fprintf(outfile,"post-");
- else
- fprintf(outfile,"pre-");
- fprintf(outfile,"INC_OP (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2); /* postincrement case */
- ast_print(tree->right,outfile,indent+2); /* preincrement case */
- return ;
-
- case DEC_OP:
- if (tree->left)
- fprintf(outfile,"post-");
- else
- fprintf(outfile,"pre-");
- fprintf(outfile,"DEC_OP (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2); /* postdecrement case */
- ast_print(tree->right,outfile,indent+2); /* predecrement case */
- return ;
-
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* bitwise and */
- /*----------------------------*/
- case '&':
- if (tree->right) {
- fprintf(outfile,"& (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- } else {
- fprintf(outfile,"ADDRESS_OF (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- }
- return ;
- /*----------------------------*/
- /* bitwise or */
- /*----------------------------*/
- case '|':
- fprintf(outfile,"OR (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* bitwise xor */
- /*----------------------------*/
- case '^':
- fprintf(outfile,"XOR (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
-
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* division */
- /*----------------------------*/
- case '/':
- fprintf(outfile,"DIV (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* modulus */
- /*----------------------------*/
- case '%':
- fprintf(outfile,"MOD (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
-
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* address dereference */
- /*----------------------------*/
- case '*': /* can be unary : if right is null then unary operation */
- if (!tree->right) {
- fprintf(outfile,"DEREF (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- return ;
- }
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* multiplication */
- /*----------------------------*/
- fprintf(outfile,"MULT (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
-
-
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* unary '+' operator */
- /*----------------------------*/
- case '+':
- /* if unary plus */
- if (!tree->right) {
- fprintf(outfile,"UPLUS (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- } else {
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* addition */
- /*----------------------------*/
- fprintf(outfile,"ADD (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- }
- return;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* unary '-' */
- /*----------------------------*/
- case '-': /* can be unary */
- if (!tree->right) {
- fprintf(outfile,"UMINUS (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- } else {
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* subtraction */
- /*----------------------------*/
- fprintf(outfile,"SUB (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- }
- return;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* compliment */
- /*----------------------------*/
- case '~':
- fprintf(outfile,"COMPL (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- return ;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* not */
- /*----------------------------*/
- case '!':
- fprintf(outfile,"NOT (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- return ;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* shift */
- /*----------------------------*/
- case RRC:
- fprintf(outfile,"RRC (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- return ;
-
- case RLC:
- fprintf(outfile,"RLC (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- return ;
- case SWAP:
- fprintf(outfile,"SWAP (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- return ;
- case GETHBIT:
- fprintf(outfile,"GETHBIT (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- return ;
- case LEFT_OP:
- fprintf(outfile,"LEFT_SHIFT (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
- case RIGHT_OP:
- fprintf(outfile,"RIGHT_SHIFT (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* casting */
- /*----------------------------*/
- case CAST: /* change the type */
- fprintf(outfile,"CAST (%p) from type (",tree);
- printTypeChain(tree->right->ftype,outfile);
- fprintf(outfile,") to type (");
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->right,outfile,indent+2);
- return ;
-
- case AND_OP:
- fprintf(outfile,"ANDAND (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
- case OR_OP:
- fprintf(outfile,"OROR (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
-
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* comparison operators */
- /*----------------------------*/
- case '>':
- fprintf(outfile,"GT(>) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
- case '<':
- fprintf(outfile,"LT(<) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
- case LE_OP:
- fprintf(outfile,"LE(<=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
- case GE_OP:
- fprintf(outfile,"GE(>=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
- case EQ_OP:
- fprintf(outfile,"EQ(==) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
- case NE_OP:
- fprintf(outfile,"NE(!=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* sizeof */
- /*----------------------------*/
- case SIZEOF: /* evaluate wihout code generation */
- fprintf(outfile,"SIZEOF %d\n",(getSize (tree->right->ftype)));
- return ;
-
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* conditional operator '?' */
- /*----------------------------*/
- case '?':
- fprintf(outfile,"QUEST(?) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
-
- case ':':
- fprintf(outfile,"COLON(:) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return ;
-
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* assignment operators */
- /*----------------------------*/
- case MUL_ASSIGN:
- fprintf(outfile,"MULASS(*=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
- case DIV_ASSIGN:
- fprintf(outfile,"DIVASS(/=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
- case AND_ASSIGN:
- fprintf(outfile,"ANDASS(&=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
- case OR_ASSIGN:
- fprintf(outfile,"ORASS(|=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
- case XOR_ASSIGN:
- fprintf(outfile,"XORASS(^=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
- case RIGHT_ASSIGN:
- fprintf(outfile,"RSHFTASS(>>=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
- case LEFT_ASSIGN:
- fprintf(outfile,"LSHFTASS(<<=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* -= operator */
- /*----------------------------*/
- case SUB_ASSIGN:
- fprintf(outfile,"SUBASS(-=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* += operator */
- /*----------------------------*/
- case ADD_ASSIGN:
- fprintf(outfile,"ADDASS(+=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* straight assignemnt */
- /*----------------------------*/
- case '=':
- fprintf(outfile,"ASSIGN(=) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* comma operator */
- /*----------------------------*/
- case ',':
- fprintf(outfile,"COMMA(,) (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* function call */
- /*----------------------------*/
- case CALL:
- case PCALL:
- fprintf(outfile,"CALL (%p) type (",tree);
- printTypeChain(tree->ftype,outfile);
- fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent+2);
- return;
- case PARAM:
- fprintf(outfile,"PARMS\n");
- ast_print(tree->left,outfile,indent+2);
- if (tree->right /*&& !IS_AST_PARAM(tree->right)*/) {
- ast_print(tree->right,outfile,indent+2);
- }
- return ;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* return statement */
- /*----------------------------*/
- case RETURN:
- fprintf(outfile,"RETURN (%p) type (",tree);
- if (tree->right) {
- printTypeChain(tree->right->ftype,outfile);
- }
- fprintf(outfile,")\n");
- ast_print(tree->right,outfile,indent+2);
- return ;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* label statement */
- /*----------------------------*/
- case LABEL :
- fprintf(outfile,"LABEL (%p)\n",tree);
- ast_print(tree->left,outfile,indent+2);
- ast_print(tree->right,outfile,indent);
- return;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* switch statement */
- /*----------------------------*/
- case SWITCH:
- {
- value *val;
- fprintf(outfile,"SWITCH (%p) ",tree);
- ast_print(tree->left,outfile,0);
- for (val = tree->values.switchVals.swVals; val ; val = val->next) {
- INDENT(indent+2,outfile);
- fprintf(outfile,"CASE 0x%x GOTO _case_%d_%d\n",
- (int) floatFromVal(val),
- tree->values.switchVals.swNum,
- (int) floatFromVal(val));
- }
- ast_print(tree->right,outfile,indent);
- }
- return ;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* ifx Statement */
- /*----------------------------*/
- case IFX:
- fprintf(outfile,"IF (%p) \n",tree);
- ast_print(tree->left,outfile,indent+2);
- if (tree->trueLabel) {
- INDENT(indent+2,outfile);
- fprintf(outfile,"NE(!=) 0 goto %s\n",tree->trueLabel->name);
- }
- if (tree->falseLabel) {
- INDENT(indent+2,outfile);
- fprintf(outfile,"EQ(==) 0 goto %s\n",tree->falseLabel->name);
- }
- ast_print(tree->right,outfile,indent+2);
- return ;
- /*----------------------------*/
- /* goto Statement */
- /*----------------------------*/
- case GOTO:
- fprintf(outfile,"GOTO (%p) \n",tree);
- ast_print(tree->left,outfile,indent+2);
- fprintf(outfile,"\n");
- return ;
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* for Statement */
- /*----------------------------*/
- case FOR:
- fprintf(outfile,"FOR (%p) \n",tree);
- if (AST_FOR( tree, initExpr)) {
- INDENT(indent+2,outfile);
- fprintf(outfile,"INIT EXPR ");
- ast_print(AST_FOR(tree, initExpr),outfile,indent+2);
- }
- if (AST_FOR( tree, condExpr)) {
- INDENT(indent+2,outfile);
- fprintf(outfile,"COND EXPR ");
- ast_print(AST_FOR(tree, condExpr),outfile,indent+2);
- }
- if (AST_FOR( tree, loopExpr)) {
- INDENT(indent+2,outfile);
- fprintf(outfile,"LOOP EXPR ");
- ast_print(AST_FOR(tree, loopExpr),outfile,indent+2);
- }
- fprintf(outfile,"FOR LOOP BODY \n");
- ast_print(tree->left,outfile,indent+2);
- return ;
- case CRITICAL:
- fprintf(outfile,"CRITICAL (%p) \n",tree);
- ast_print(tree->left,outfile,indent+2);
- default:
- return ;
- }
+ if (!tree) return ;
+
+ /* can print only decorated trees */
+ if (!tree->decorated) return;
+
+ /* if any child is an error | this one is an error do nothing */
+ if (tree->isError ||
+ (tree->left && tree->left->isError) ||
+ (tree->right && tree->right->isError)) {
+ fprintf(outfile,"ERROR_NODE(%p)\n",tree);
+ }
+
+
+ /* print the line */
+ /* if not block & function */
+ if (tree->type == EX_OP &&
+ (tree->opval.op != FUNCTION &&
+ tree->opval.op != BLOCK &&
+ tree->opval.op != NULLOP)) {
+ }
+
+ if (tree->opval.op == FUNCTION) {
+ int arg=0;
+ value *args=FUNC_ARGS(tree->left->opval.val->type);
+ fprintf(outfile,"FUNCTION (%s=%p) type (",
+ tree->left->opval.val->name, tree);
+ printTypeChain (tree->left->opval.val->type->next,outfile);
+ fprintf(outfile,") args (");
+ do {
+ if (arg) {
+ fprintf (outfile, ", ");
+ }
+ printTypeChain (args ? args->type : NULL, outfile);
+ arg++;
+ args= args ? args->next : NULL;
+ } while (args);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent);
+ ast_print(tree->right,outfile,indent);
+ return ;
+ }
+ if (tree->opval.op == BLOCK) {
+ symbol *decls = tree->values.sym;
+ INDENT(indent,outfile);
+ fprintf(outfile,"{\n");
+ while (decls) {
+ INDENT(indent+2,outfile);
+ fprintf(outfile,"DECLARE SYMBOL (%s=%p) type (",
+ decls->name, decls);
+ printTypeChain(decls->type,outfile);
+ fprintf(outfile,")\n");
+
+ decls = decls->next;
+ }
+ ast_print(tree->right,outfile,indent+2);
+ INDENT(indent,outfile);
+ fprintf(outfile,"}\n");
+ return;
+ }
+ if (tree->opval.op == NULLOP) {
+ ast_print(tree->left,outfile,indent);
+ ast_print(tree->right,outfile,indent);
+ return ;
+ }
+ INDENT(indent,outfile);
+
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* leaf has been reached */
+ /*----------------------------*/
+ /* if this is of type value */
+ /* just get the type */
+ if (tree->type == EX_VALUE) {
+
+ if (IS_LITERAL (tree->opval.val->etype)) {
+ fprintf(outfile,"CONSTANT (%p) value = ", tree);
+ if (SPEC_USIGN (tree->opval.val->etype))
+ fprintf(outfile,"%u", (TYPE_UDWORD) floatFromVal(tree->opval.val));
+ else
+ fprintf(outfile,"%d", (TYPE_DWORD) floatFromVal(tree->opval.val));
+ fprintf(outfile,", 0x%x, %f", (TYPE_UDWORD) floatFromVal(tree->opval.val),
+ floatFromVal(tree->opval.val));
+ } else if (tree->opval.val->sym) {
+ /* if the undefined flag is set then give error message */
+ if (tree->opval.val->sym->undefined) {
+ fprintf(outfile,"UNDEFINED SYMBOL ");
+ } else {
+ fprintf(outfile,"SYMBOL ");
+ }
+ fprintf(outfile,"(%s=%p)",
+ tree->opval.val->sym->name,tree);
+ }
+ if (tree->ftype) {
+ fprintf(outfile," type (");
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ } else {
+ fprintf(outfile,"\n");
+ }
+ return ;
+ }
+
+ /* if type link for the case of cast */
+ if (tree->type == EX_LINK) {
+ fprintf(outfile,"TYPENODE (%p) type = (",tree);
+ printTypeChain(tree->opval.lnk,outfile);
+ fprintf(outfile,")\n");
+ return ;
+ }
+
+
+ /* depending on type of operator do */
+
+ switch (tree->opval.op) {
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* array node */
+ /*----------------------------*/
+ case '[':
+ fprintf(outfile,"ARRAY_OP (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* struct/union */
+ /*----------------------------*/
+ case '.':
+ fprintf(outfile,"STRUCT_ACCESS (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* struct/union pointer */
+ /*----------------------------*/
+ case PTR_OP:
+ fprintf(outfile,"PTR_ACCESS (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* ++/-- operation */
+ /*----------------------------*/
+ case INC_OP:
+ if (tree->left)
+ fprintf(outfile,"post-");
+ else
+ fprintf(outfile,"pre-");
+ fprintf(outfile,"INC_OP (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2); /* postincrement case */
+ ast_print(tree->right,outfile,indent+2); /* preincrement case */
+ return ;
+
+ case DEC_OP:
+ if (tree->left)
+ fprintf(outfile,"post-");
+ else
+ fprintf(outfile,"pre-");
+ fprintf(outfile,"DEC_OP (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2); /* postdecrement case */
+ ast_print(tree->right,outfile,indent+2); /* predecrement case */
+ return ;
+
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* bitwise and */
+ /*----------------------------*/
+ case '&':
+ if (tree->right) {
+ fprintf(outfile,"& (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ } else {
+ fprintf(outfile,"ADDRESS_OF (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ }
+ return ;
+ /*----------------------------*/
+ /* bitwise or */
+ /*----------------------------*/
+ case '|':
+ fprintf(outfile,"OR (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* bitwise xor */
+ /*----------------------------*/
+ case '^':
+ fprintf(outfile,"XOR (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* division */
+ /*----------------------------*/
+ case '/':
+ fprintf(outfile,"DIV (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* modulus */
+ /*----------------------------*/
+ case '%':
+ fprintf(outfile,"MOD (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* address dereference */
+ /*----------------------------*/
+ case '*': /* can be unary : if right is null then unary operation */
+ if (!tree->right) {
+ fprintf(outfile,"DEREF (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ return ;
+ }
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* multiplication */
+ /*----------------------------*/
+ fprintf(outfile,"MULT (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+
+
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* unary '+' operator */
+ /*----------------------------*/
+ case '+':
+ /* if unary plus */
+ if (!tree->right) {
+ fprintf(outfile,"UPLUS (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ } else {
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* addition */
+ /*----------------------------*/
+ fprintf(outfile,"ADD (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ }
+ return;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* unary '-' */
+ /*----------------------------*/
+ case '-': /* can be unary */
+ if (!tree->right) {
+ fprintf(outfile,"UMINUS (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ } else {
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* subtraction */
+ /*----------------------------*/
+ fprintf(outfile,"SUB (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ }
+ return;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* compliment */
+ /*----------------------------*/
+ case '~':
+ fprintf(outfile,"COMPL (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ return ;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* not */
+ /*----------------------------*/
+ case '!':
+ fprintf(outfile,"NOT (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ return ;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* shift */
+ /*----------------------------*/
+ case RRC:
+ fprintf(outfile,"RRC (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ return ;
+
+ case RLC:
+ fprintf(outfile,"RLC (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ return ;
+ case SWAP:
+ fprintf(outfile,"SWAP (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ return ;
+ case GETHBIT:
+ fprintf(outfile,"GETHBIT (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ return ;
+ case LEFT_OP:
+ fprintf(outfile,"LEFT_SHIFT (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+ case RIGHT_OP:
+ fprintf(outfile,"RIGHT_SHIFT (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* casting */
+ /*----------------------------*/
+ case CAST: /* change the type */
+ fprintf(outfile,"CAST (%p) from type (",tree);
+ printTypeChain(tree->right->ftype,outfile);
+ fprintf(outfile,") to type (");
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+
+ case AND_OP:
+ fprintf(outfile,"ANDAND (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+ case OR_OP:
+ fprintf(outfile,"OROR (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* comparison operators */
+ /*----------------------------*/
+ case '>':
+ fprintf(outfile,"GT(>) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+ case '<':
+ fprintf(outfile,"LT(<) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+ case LE_OP:
+ fprintf(outfile,"LE(<=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+ case GE_OP:
+ fprintf(outfile,"GE(>=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+ case EQ_OP:
+ fprintf(outfile,"EQ(==) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+ case NE_OP:
+ fprintf(outfile,"NE(!=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* sizeof */
+ /*----------------------------*/
+ case SIZEOF: /* evaluate wihout code generation */
+ fprintf(outfile,"SIZEOF %d\n",(getSize (tree->right->ftype)));
+ return ;
+
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* conditional operator '?' */
+ /*----------------------------*/
+ case '?':
+ fprintf(outfile,"QUEST(?) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+
+ case ':':
+ fprintf(outfile,"COLON(:) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* assignment operators */
+ /*----------------------------*/
+ case MUL_ASSIGN:
+ fprintf(outfile,"MULASS(*=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+ case DIV_ASSIGN:
+ fprintf(outfile,"DIVASS(/=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+ case AND_ASSIGN:
+ fprintf(outfile,"ANDASS(&=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+ case OR_ASSIGN:
+ fprintf(outfile,"ORASS(|=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+ case XOR_ASSIGN:
+ fprintf(outfile,"XORASS(^=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+ case RIGHT_ASSIGN:
+ fprintf(outfile,"RSHFTASS(>>=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+ case LEFT_ASSIGN:
+ fprintf(outfile,"LSHFTASS(<<=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* -= operator */
+ /*----------------------------*/
+ case SUB_ASSIGN:
+ fprintf(outfile,"SUBASS(-=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* += operator */
+ /*----------------------------*/
+ case ADD_ASSIGN:
+ fprintf(outfile,"ADDASS(+=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* straight assignemnt */
+ /*----------------------------*/
+ case '=':
+ fprintf(outfile,"ASSIGN(=) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* comma operator */
+ /*----------------------------*/
+ case ',':
+ fprintf(outfile,"COMMA(,) (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* function call */
+ /*----------------------------*/
+ case CALL:
+ case PCALL:
+ fprintf(outfile,"CALL (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent+2);
+ return;
+ case PARAM:
+ fprintf(outfile,"PARMS\n");
+ ast_print(tree->left,outfile,indent+2);
+ if (tree->right /*&& !IS_AST_PARAM(tree->right)*/) {
+ ast_print(tree->right,outfile,indent+2);
+ }
+ return ;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* return statement */
+ /*----------------------------*/
+ case RETURN:
+ fprintf(outfile,"RETURN (%p) type (",tree);
+ if (tree->right) {
+ printTypeChain(tree->right->ftype,outfile);
+ }
+ fprintf(outfile,")\n");
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* label statement */
+ /*----------------------------*/
+ case LABEL :
+ fprintf(outfile,"LABEL (%p)\n",tree);
+ ast_print(tree->left,outfile,indent+2);
+ ast_print(tree->right,outfile,indent);
+ return;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* switch statement */
+ /*----------------------------*/
+ case SWITCH:
+ {
+ value *val;
+ fprintf(outfile,"SWITCH (%p) ",tree);
+ ast_print(tree->left,outfile,0);
+ for (val = tree->values.switchVals.swVals; val ; val = val->next) {
+ INDENT(indent+2,outfile);
+ fprintf(outfile,"CASE 0x%x GOTO _case_%d_%d\n",
+ (int) floatFromVal(val),
+ tree->values.switchVals.swNum,
+ (int) floatFromVal(val));
+ }
+ ast_print(tree->right,outfile,indent);
+ }
+ return ;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* ifx Statement */
+ /*----------------------------*/
+ case IFX:
+ fprintf(outfile,"IF (%p) \n",tree);
+ ast_print(tree->left,outfile,indent+2);
+ if (tree->trueLabel) {
+ INDENT(indent+2,outfile);
+ fprintf(outfile,"NE(!=) 0 goto %s\n",tree->trueLabel->name);
+ }
+ if (tree->falseLabel) {
+ INDENT(indent+2,outfile);
+ fprintf(outfile,"EQ(==) 0 goto %s\n",tree->falseLabel->name);
+ }
+ ast_print(tree->right,outfile,indent+2);
+ return ;
+ /*----------------------------*/
+ /* goto Statement */
+ /*----------------------------*/
+ case GOTO:
+ fprintf(outfile,"GOTO (%p) \n",tree);
+ ast_print(tree->left,outfile,indent+2);
+ fprintf(outfile,"\n");
+ return ;
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* for Statement */
+ /*----------------------------*/
+ case FOR:
+ fprintf(outfile,"FOR (%p) \n",tree);
+ if (AST_FOR( tree, initExpr)) {
+ INDENT(indent+2,outfile);
+ fprintf(outfile,"INIT EXPR ");
+ ast_print(AST_FOR(tree, initExpr),outfile,indent+2);
+ }
+ if (AST_FOR( tree, condExpr)) {
+ INDENT(indent+2,outfile);
+ fprintf(outfile,"COND EXPR ");
+ ast_print(AST_FOR(tree, condExpr),outfile,indent+2);
+ }
+ if (AST_FOR( tree, loopExpr)) {
+ INDENT(indent+2,outfile);
+ fprintf(outfile,"LOOP EXPR ");
+ ast_print(AST_FOR(tree, loopExpr),outfile,indent+2);
+ }
+ fprintf(outfile,"FOR LOOP BODY \n");
+ ast_print(tree->left,outfile,indent+2);
+ return ;
+ case CRITICAL:
+ fprintf(outfile,"CRITICAL (%p) \n",tree);
+ ast_print(tree->left,outfile,indent+2);
+ default:
+ return ;
+ }
}
void PA(ast *t)
{
- ast_print(t,stdout,0);
+ ast_print(t,stdout,0);
}
symbol *interrupts[INTNO_MAX+1];
void printIval (symbol *, sym_link *, initList *, FILE *);
-set *publics = NULL; /* public variables */
-set *externs = NULL; /* Varibles that are declared as extern */
+set *publics = NULL; /* public variables */
+set *externs = NULL; /* Varibles that are declared as extern */
/* TODO: this should be configurable (DS803C90 uses more than 6) */
unsigned maxInterrupts = 6;
int allocInfo = 1;
symbol *mainf;
set *pipeSet = NULL; /* set of pipes */
-set *tmpfileSet = NULL; /* set of tmp file created by the compiler */
-set *tmpfileNameSet = NULL; /* All are unlinked at close. */
+set *tmpfileSet = NULL; /* set of tmp file created by the compiler */
+set *tmpfileNameSet = NULL; /* All are unlinked at close. */
/*-----------------------------------------------------------------*/
/* closePipes - closes all pipes created by the compiler */
char *
aopLiteralLong (value * val, int offset, int size)
{
- union {
- float f;
- unsigned char c[4];
- }
- fl;
-
- if (!val) {
- // assuming we have been warned before
- val=constVal("0");
- }
-
- /* if it is a float then it gets tricky */
- /* otherwise it is fairly simple */
- if (!IS_FLOAT (val->type)) {
- unsigned long v = (unsigned long) floatFromVal (val);
-
- v >>= (offset * 8);
- switch (size) {
- case 1:
- tsprintf (buffer, sizeof(buffer),
- "!immedbyte", (unsigned int) v & 0xff);
- break;
- case 2:
- tsprintf (buffer, sizeof(buffer),
- "!immedword", (unsigned int) v & 0xffff);
- break;
- default:
- /* Hmm. Too big for now. */
- assert (0);
- }
- return Safe_strdup (buffer);
- }
-
- /* PENDING: For now size must be 1 */
- assert (size == 1);
-
- /* it is type float */
- fl.f = (float) floatFromVal (val);
+ union {
+ float f;
+ unsigned char c[4];
+ }
+ fl;
+
+ if (!val) {
+ // assuming we have been warned before
+ val=constVal("0");
+ }
+
+ /* if it is a float then it gets tricky */
+ /* otherwise it is fairly simple */
+ if (!IS_FLOAT (val->type)) {
+ unsigned long v = (unsigned long) floatFromVal (val);
+
+ v >>= (offset * 8);
+ switch (size) {
+ case 1:
+ tsprintf (buffer, sizeof(buffer),
+ "!immedbyte", (unsigned int) v & 0xff);
+ break;
+ case 2:
+ tsprintf (buffer, sizeof(buffer),
+ "!immedword", (unsigned int) v & 0xffff);
+ break;
+ default:
+ /* Hmm. Too big for now. */
+ assert (0);
+ }
+ return Safe_strdup (buffer);
+ }
+
+ /* PENDING: For now size must be 1 */
+ assert (size == 1);
+
+ /* it is type float */
+ fl.f = (float) floatFromVal (val);
#ifdef WORDS_BIGENDIAN
- tsprintf (buffer, sizeof(buffer),
- "!immedbyte", fl.c[3 - offset]);
+ tsprintf (buffer, sizeof(buffer),
+ "!immedbyte", fl.c[3 - offset]);
#else
- tsprintf (buffer, sizeof(buffer),
- "!immedbyte", fl.c[offset]);
+ tsprintf (buffer, sizeof(buffer),
+ "!immedbyte", fl.c[offset]);
#endif
- return Safe_strdup (buffer);
+ return Safe_strdup (buffer);
}
/*-----------------------------------------------------------------*/
char *
aopLiteral (value * val, int offset)
{
- return aopLiteralLong (val, offset, 1);
+ return aopLiteralLong (val, offset, 1);
}
/*-----------------------------------------------------------------*/
{
/* PENDING: special case here - should remove */
if (!strcmp (map->sname, CODE_NAME))
- tfprintf (map->oFile, "\t!areacode\n", map->sname);
+ tfprintf (map->oFile, "\t!areacode\n", map->sname);
else if (!strcmp (map->sname, DATA_NAME))
- tfprintf (map->oFile, "\t!areadata\n", map->sname);
+ tfprintf (map->oFile, "\t!areadata\n", map->sname);
else if (!strcmp (map->sname, HOME_NAME))
- tfprintf (map->oFile, "\t!areahome\n", map->sname);
+ tfprintf (map->oFile, "\t!areahome\n", map->sname);
else
- tfprintf (map->oFile, "\t!area\n", map->sname);
+ tfprintf (map->oFile, "\t!area\n", map->sname);
}
for (sym = setFirstItem (map->syms); sym;
/* if extern then add it into the extern list */
if (IS_EXTERN (sym->etype))
- {
+ {
addSetHead (&externs, sym);
- continue;
- }
+ continue;
+ }
/* if allocation required check is needed
then check if the symbol really requires
allocation only for local variables */
if (arFlag && !IS_AGGREGATE (sym->type) &&
- !(sym->_isparm && !IS_REGPARM (sym->etype)) &&
- !sym->allocreq && sym->level)
- continue;
+ !(sym->_isparm && !IS_REGPARM (sym->etype)) &&
+ !sym->allocreq && sym->level)
+ continue;
/* for bitvar locals and parameters */
if (!arFlag && !sym->allocreq && sym->level
- && !SPEC_ABSA (sym->etype)) {
- continue;
+ && !SPEC_ABSA (sym->etype)) {
+ continue;
}
/* if global variable & not static or extern
and addPublics allowed then add it to the public set */
if ((sym->level == 0 ||
- (sym->_isparm && !IS_REGPARM (sym->etype))) &&
- addPublics &&
- !IS_STATIC (sym->etype) &&
+ (sym->_isparm && !IS_REGPARM (sym->etype))) &&
+ addPublics &&
+ !IS_STATIC (sym->etype) &&
(IS_FUNC(sym->type) ? (sym->used || IFFUNC_HASBODY(sym->type)) : 1))
- {
- addSetHead (&publics, sym);
- }
+ {
+ addSetHead (&publics, sym);
+ }
/* if extern then do nothing or is a function
then do nothing */
if (IS_FUNC (sym->type) && !(sym->isitmp))
- continue;
+ continue;
/* print extra debug info if required */
if (options.debug)
- {
- if (!sym->level) /* global */
- {
- if (IS_STATIC (sym->etype))
- fprintf (map->oFile, "F%s$", moduleName); /* scope is file */
- else
- fprintf (map->oFile, "G$"); /* scope is global */
- }
- else
- {
- /* symbol is local */
- fprintf (map->oFile, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
- }
- fprintf (map->oFile, "%s$%d$%d", sym->name, sym->level, sym->block);
- }
+ {
+ if (!sym->level) /* global */
+ {
+ if (IS_STATIC (sym->etype))
+ fprintf (map->oFile, "F%s$", moduleName); /* scope is file */
+ else
+ fprintf (map->oFile, "G$"); /* scope is global */
+ }
+ else
+ {
+ /* symbol is local */
+ fprintf (map->oFile, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
+ }
+ fprintf (map->oFile, "%s$%d$%d", sym->name, sym->level, sym->block);
+ }
/* if it has an initial value then do it only if
it is a global variable */
if (sym->ival && sym->level == 0) {
- if (SPEC_OCLS(sym->etype)==xidata) {
- /* create a new "XINIT (CODE)" symbol, that will be emitted later
- in the static seg */
- newSym=copySymbol (sym);
- SPEC_OCLS(newSym->etype)=xinit;
- SNPRINTF (newSym->name, sizeof(newSym->name), "__xinit_%s", sym->name);
- SNPRINTF (newSym->rname, sizeof(newSym->rname), "__xinit_%s", sym->rname);
- if (IS_SPEC (newSym->type))
+ if (SPEC_OCLS(sym->etype)==xidata) {
+ /* create a new "XINIT (CODE)" symbol, that will be emitted later
+ in the static seg */
+ newSym=copySymbol (sym);
+ SPEC_OCLS(newSym->etype)=xinit;
+ SNPRINTF (newSym->name, sizeof(newSym->name), "__xinit_%s", sym->name);
+ SNPRINTF (newSym->rname, sizeof(newSym->rname), "__xinit_%s", sym->rname);
+ if (IS_SPEC (newSym->type))
SPEC_CONST (newSym->type) = 1;
else
DCL_PTR_CONST (newSym->type) = 1;
- SPEC_STAT(newSym->etype)=1;
- resolveIvalSym(newSym->ival, newSym->type);
-
- // add it to the "XINIT (CODE)" segment
- addSet(&xinit->syms, newSym);
- sym->ival=NULL;
- } else {
- if (IS_AGGREGATE (sym->type)) {
- ival = initAggregates (sym, sym->ival, NULL);
- } else {
- if (getNelements(sym->type, sym->ival)>1) {
- werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "scalar",
- sym->name);
- }
- ival = newNode ('=', newAst_VALUE (symbolVal (sym)),
- decorateType (resolveSymbols (list2expr (sym->ival)), RESULT_CHECK));
- }
- codeOutFile = statsg->oFile;
-
- if (ival) {
- // set ival's lineno to where the symbol was defined
- setAstLineno (ival, lineno=sym->lineDef);
- // check if this is not a constant expression
- if (!constExprTree(ival)) {
- werror (E_CONST_EXPECTED, "found expression");
- // but try to do it anyway
- }
- allocInfo = 0;
+ SPEC_STAT(newSym->etype)=1;
+ resolveIvalSym(newSym->ival, newSym->type);
+
+ // add it to the "XINIT (CODE)" segment
+ addSet(&xinit->syms, newSym);
+
+ if (!SPEC_ABSA (sym->etype))
+ {
+ FILE *tmpFile = tempfile ();
+ addSetHead (&tmpfileSet, tmpFile);
+ // before allocation we must parse the sym->ival tree
+ // but without actually generating initialization code
+ noAlloc++;
+ resolveIvalSym (sym->ival, sym->type);
+ printIval (sym, sym->type, sym->ival, tmpFile);
+ noAlloc--;
+ }
+
+ sym->ival=NULL;
+ } else {
+ if (IS_AGGREGATE (sym->type)) {
+ ival = initAggregates (sym, sym->ival, NULL);
+ } else {
+ if (getNelements(sym->type, sym->ival)>1) {
+ werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "scalar",
+ sym->name);
+ }
+ ival = newNode ('=', newAst_VALUE (symbolVal (sym)),
+ decorateType (resolveSymbols (list2expr (sym->ival)), RESULT_CHECK));
+ }
+ codeOutFile = statsg->oFile;
+
+ if (ival) {
+ // set ival's lineno to where the symbol was defined
+ setAstLineno (ival, lineno=sym->lineDef);
+ // check if this is not a constant expression
+ if (!constExprTree(ival)) {
+ werror (E_CONST_EXPECTED, "found expression");
+ // but try to do it anyway
+ }
+ allocInfo = 0;
if (!astErrors(ival))
- eBBlockFromiCode (iCodeFromAst (ival));
- allocInfo = 1;
- }
- }
- sym->ival = NULL;
+ eBBlockFromiCode (iCodeFromAst (ival));
+ allocInfo = 1;
+ }
+ }
+ sym->ival = NULL;
}
- /* if is has an absolute address then generate
+ /* if it has an absolute address then generate
an equate for this no need to allocate space */
if (SPEC_ABSA (sym->etype))
- {
- char *equ="=";
- if (options.debug) {
- fprintf (map->oFile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
- }
- if (TARGET_IS_XA51) {
- if (map==sfr) {
- equ="sfr";
- } else if (map==bit || map==sfrbit) {
- equ="bit";
- }
- }
- fprintf (map->oFile, "%s\t%s\t0x%04x\n",
- sym->rname, equ,
- SPEC_ADDR (sym->etype));
- }
+ {
+ char *equ="=";
+ if (options.debug) {
+ fprintf (map->oFile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
+ }
+ if (TARGET_IS_XA51) {
+ if (map==sfr) {
+ equ="sfr";
+ } else if (map==bit || map==sfrbit) {
+ equ="bit";
+ }
+ }
+ fprintf (map->oFile, "%s\t%s\t0x%04x\n",
+ sym->rname, equ,
+ SPEC_ADDR (sym->etype));
+ }
else {
- int size = getSize (sym->type);
- if (size==0) {
- werrorfl (sym->fileDef, sym->lineDef, E_UNKNOWN_SIZE, sym->name);
- }
- /* allocate space */
- if (options.debug) {
- fprintf (map->oFile, "==.\n");
- }
- if (IS_STATIC (sym->etype))
- tfprintf (map->oFile, "!slabeldef\n", sym->rname);
- else
- tfprintf (map->oFile, "!labeldef\n", sym->rname);
- tfprintf (map->oFile, "\t!ds\n",
- (unsigned int) size & 0xffff);
+ int size = getAllocSize (sym->type);
+ if (size==0) {
+ werrorfl (sym->fileDef, sym->lineDef, E_UNKNOWN_SIZE, sym->name);
+ }
+ /* allocate space */
+ if (options.debug) {
+ fprintf (map->oFile, "==.\n");
+ }
+ if (IS_STATIC (sym->etype))
+ tfprintf (map->oFile, "!slabeldef\n", sym->rname);
+ else
+ tfprintf (map->oFile, "!labeldef\n", sym->rname);
+ tfprintf (map->oFile, "\t!ds\n",
+ (unsigned int) size & 0xffff);
}
}
}
value *
initPointer (initList * ilist, sym_link *toType)
{
- value *val;
- ast *expr = list2expr (ilist);
-
- if (!expr)
- goto wrong;
-
- /* try it the oldway first */
- if ((val = constExprValue (expr, FALSE)))
- return val;
-
- /* ( ptr + constant ) */
- if (IS_AST_OP (expr) &&
- (expr->opval.op == '+' || expr->opval.op == '-') &&
- IS_AST_SYM_VALUE (expr->left) &&
- (IS_ARRAY(expr->left->ftype) || IS_PTR(expr->left->ftype)) &&
- compareType(toType, expr->left->ftype) &&
- IS_AST_LIT_VALUE (expr->right)) {
- return valForCastAggr (expr->left, expr->left->ftype,
- expr->right,
- expr->opval.op);
- }
-
- /* (char *)&a */
- if (IS_AST_OP(expr) && expr->opval.op==CAST &&
- IS_AST_OP(expr->right) && expr->right->opval.op=='&') {
- if (compareType(toType, expr->left->ftype)!=1) {
- werror (W_INIT_WRONG);
- printFromToType(expr->left->ftype, toType);
- }
- // skip the cast ???
- expr=expr->right;
- }
-
- /* no then we have to do these cludgy checks */
- /* pointers can be initialized with address of
- a variable or address of an array element */
- if (IS_AST_OP (expr) && expr->opval.op == '&') {
- /* address of symbol */
- if (IS_AST_SYM_VALUE (expr->left)) {
- val = copyValue (AST_VALUE (expr->left));
- val->type = newLink (DECLARATOR);
- if (SPEC_SCLS (expr->left->etype) == S_CODE) {
- DCL_TYPE (val->type) = CPOINTER;
- DCL_PTR_CONST (val->type) = port->mem.code_ro;
- }
- else if (SPEC_SCLS (expr->left->etype) == S_XDATA)
- DCL_TYPE (val->type) = FPOINTER;
- else if (SPEC_SCLS (expr->left->etype) == S_XSTACK)
- DCL_TYPE (val->type) = PPOINTER;
- else if (SPEC_SCLS (expr->left->etype) == S_IDATA)
- DCL_TYPE (val->type) = IPOINTER;
- else if (SPEC_SCLS (expr->left->etype) == S_EEPROM)
- DCL_TYPE (val->type) = EEPPOINTER;
- else
- DCL_TYPE (val->type) = POINTER;
- val->type->next = expr->left->ftype;
- val->etype = getSpec (val->type);
- return val;
- }
-
- /* if address of indexed array */
- if (IS_AST_OP (expr->left) && expr->left->opval.op == '[')
- return valForArray (expr->left);
-
- /* if address of structure element then
- case 1. a.b ; */
- if (IS_AST_OP (expr->left) &&
- expr->left->opval.op == '.') {
- return valForStructElem (expr->left->left,
- expr->left->right);
- }
-
- /* case 2. (&a)->b ;
- (&some_struct)->element */
- if (IS_AST_OP (expr->left) &&
- expr->left->opval.op == PTR_OP &&
- IS_ADDRESS_OF_OP (expr->left->left)) {
- return valForStructElem (expr->left->left->left,
- expr->left->right);
- }
- }
- /* case 3. (((char *) &a) +/- constant) */
- if (IS_AST_OP (expr) &&
- (expr->opval.op == '+' || expr->opval.op == '-') &&
- IS_AST_OP (expr->left) && expr->left->opval.op == CAST &&
- IS_AST_OP (expr->left->right) &&
- expr->left->right->opval.op == '&' &&
- IS_AST_LIT_VALUE (expr->right)) {
-
- return valForCastAggr (expr->left->right->left,
- expr->left->left->opval.lnk,
- expr->right, expr->opval.op);
-
- }
- /* case 4. (char *)(array type) */
- if (IS_CAST_OP(expr) && IS_AST_SYM_VALUE (expr->right) &&
- IS_ARRAY(expr->right->ftype)) {
-
- val = copyValue (AST_VALUE (expr->right));
- val->type = newLink (DECLARATOR);
- if (SPEC_SCLS (expr->right->etype) == S_CODE) {
- DCL_TYPE (val->type) = CPOINTER;
- DCL_PTR_CONST (val->type) = port->mem.code_ro;
- }
- else if (SPEC_SCLS (expr->right->etype) == S_XDATA)
- DCL_TYPE (val->type) = FPOINTER;
- else if (SPEC_SCLS (expr->right->etype) == S_XSTACK)
- DCL_TYPE (val->type) = PPOINTER;
- else if (SPEC_SCLS (expr->right->etype) == S_IDATA)
- DCL_TYPE (val->type) = IPOINTER;
- else if (SPEC_SCLS (expr->right->etype) == S_EEPROM)
- DCL_TYPE (val->type) = EEPPOINTER;
- else
- DCL_TYPE (val->type) = POINTER;
- val->type->next = expr->right->ftype->next;
- val->etype = getSpec (val->type);
- return val;
- }
+ value *val;
+ ast *expr;
+
+ if (!ilist) {
+ return valCastLiteral(toType, 0.0);
+ }
+
+ expr = list2expr (ilist);
+
+ if (!expr)
+ goto wrong;
+
+ /* try it the old way first */
+ if ((val = constExprValue (expr, FALSE)))
+ return val;
+
+ /* ( ptr + constant ) */
+ if (IS_AST_OP (expr) &&
+ (expr->opval.op == '+' || expr->opval.op == '-') &&
+ IS_AST_SYM_VALUE (expr->left) &&
+ (IS_ARRAY(expr->left->ftype) || IS_PTR(expr->left->ftype)) &&
+ compareType(toType, expr->left->ftype) &&
+ IS_AST_LIT_VALUE (expr->right)) {
+ return valForCastAggr (expr->left, expr->left->ftype,
+ expr->right,
+ expr->opval.op);
+ }
+
+ /* (char *)&a */
+ if (IS_AST_OP(expr) && expr->opval.op==CAST &&
+ IS_AST_OP(expr->right) && expr->right->opval.op=='&') {
+ if (compareType(toType, expr->left->ftype)!=1) {
+ werror (W_INIT_WRONG);
+ printFromToType(expr->left->ftype, toType);
+ }
+ // skip the cast ???
+ expr=expr->right;
+ }
+
+ /* no then we have to do these cludgy checks */
+ /* pointers can be initialized with address of
+ a variable or address of an array element */
+ if (IS_AST_OP (expr) && expr->opval.op == '&') {
+ /* address of symbol */
+ if (IS_AST_SYM_VALUE (expr->left)) {
+ val = copyValue (AST_VALUE (expr->left));
+ val->type = newLink (DECLARATOR);
+ if (SPEC_SCLS (expr->left->etype) == S_CODE) {
+ DCL_TYPE (val->type) = CPOINTER;
+ DCL_PTR_CONST (val->type) = port->mem.code_ro;
+ }
+ else if (SPEC_SCLS (expr->left->etype) == S_XDATA)
+ DCL_TYPE (val->type) = FPOINTER;
+ else if (SPEC_SCLS (expr->left->etype) == S_XSTACK)
+ DCL_TYPE (val->type) = PPOINTER;
+ else if (SPEC_SCLS (expr->left->etype) == S_IDATA)
+ DCL_TYPE (val->type) = IPOINTER;
+ else if (SPEC_SCLS (expr->left->etype) == S_EEPROM)
+ DCL_TYPE (val->type) = EEPPOINTER;
+ else
+ DCL_TYPE (val->type) = POINTER;
+ val->type->next = expr->left->ftype;
+ val->etype = getSpec (val->type);
+ return val;
+ }
+
+ /* if address of indexed array */
+ if (IS_AST_OP (expr->left) && expr->left->opval.op == '[')
+ return valForArray (expr->left);
+
+ /* if address of structure element then
+ case 1. a.b ; */
+ if (IS_AST_OP (expr->left) &&
+ expr->left->opval.op == '.') {
+ return valForStructElem (expr->left->left,
+ expr->left->right);
+ }
+
+ /* case 2. (&a)->b ;
+ (&some_struct)->element */
+ if (IS_AST_OP (expr->left) &&
+ expr->left->opval.op == PTR_OP &&
+ IS_ADDRESS_OF_OP (expr->left->left)) {
+ return valForStructElem (expr->left->left->left,
+ expr->left->right);
+ }
+ }
+ /* case 3. (((char *) &a) +/- constant) */
+ if (IS_AST_OP (expr) &&
+ (expr->opval.op == '+' || expr->opval.op == '-') &&
+ IS_AST_OP (expr->left) && expr->left->opval.op == CAST &&
+ IS_AST_OP (expr->left->right) &&
+ expr->left->right->opval.op == '&' &&
+ IS_AST_LIT_VALUE (expr->right)) {
+
+ return valForCastAggr (expr->left->right->left,
+ expr->left->left->opval.lnk,
+ expr->right, expr->opval.op);
+
+ }
+ /* case 4. (char *)(array type) */
+ if (IS_CAST_OP(expr) && IS_AST_SYM_VALUE (expr->right) &&
+ IS_ARRAY(expr->right->ftype)) {
+
+ val = copyValue (AST_VALUE (expr->right));
+ val->type = newLink (DECLARATOR);
+ if (SPEC_SCLS (expr->right->etype) == S_CODE) {
+ DCL_TYPE (val->type) = CPOINTER;
+ DCL_PTR_CONST (val->type) = port->mem.code_ro;
+ }
+ else if (SPEC_SCLS (expr->right->etype) == S_XDATA)
+ DCL_TYPE (val->type) = FPOINTER;
+ else if (SPEC_SCLS (expr->right->etype) == S_XSTACK)
+ DCL_TYPE (val->type) = PPOINTER;
+ else if (SPEC_SCLS (expr->right->etype) == S_IDATA)
+ DCL_TYPE (val->type) = IPOINTER;
+ else if (SPEC_SCLS (expr->right->etype) == S_EEPROM)
+ DCL_TYPE (val->type) = EEPPOINTER;
+ else
+ DCL_TYPE (val->type) = POINTER;
+ val->type->next = expr->right->ftype->next;
+ val->etype = getSpec (val->type);
+ return val;
+ }
wrong:
- if (expr)
- werrorfl (expr->filename, expr->lineno, E_INCOMPAT_PTYPES);
- else
- werror (E_INCOMPAT_PTYPES);
- return NULL;
+ if (expr)
+ werrorfl (expr->filename, expr->lineno, E_INCOMPAT_PTYPES);
+ else
+ werror (E_INCOMPAT_PTYPES);
+ return NULL;
}
{
i = 60;
while (i && pplen < plen)
- {
- if (*s < ' ' || *s == '\"' || *s=='\\')
- {
- *p = '\0';
- if (p != buf)
- tfprintf (ofile, "\t!ascii\n", buf);
- tfprintf (ofile, "\t!db !constbyte\n", (unsigned char)*s);
- p = buf;
- }
- else
- {
- *p = *s;
- p++;
- }
- s++;
- pplen++;
- i--;
- }
+ {
+ if (*s < ' ' || *s == '\"' || *s=='\\')
+ {
+ *p = '\0';
+ if (p != buf)
+ tfprintf (ofile, "\t!ascii\n", buf);
+ tfprintf (ofile, "\t!db !constbyte\n", (unsigned char)*s);
+ p = buf;
+ }
+ else
+ {
+ *p = *s;
+ p++;
+ }
+ s++;
+ pplen++;
+ i--;
+ }
if (p != buf)
- {
- *p = '\0';
- tfprintf (ofile, "\t!ascii\n", buf);
- p = buf;
- }
+ {
+ *p = '\0';
+ tfprintf (ofile, "\t!ascii\n", buf);
+ p = buf;
+ }
if (len > 60)
- len -= 60;
+ len -= 60;
else
- len = 0;
+ len = 0;
}
while (pplen < plen)
{
case POINTER:
return GPTYPE_NEAR;
case GPOINTER:
- werror (E_CANNOT_USE_GENERIC_POINTER,
- iname ? iname : "<null>",
- oname ? oname : "<null>");
+ werror (E_CANNOT_USE_GENERIC_POINTER,
+ iname ? iname : "<null>",
+ oname ? oname : "<null>");
exit (1);
case FPOINTER:
return GPTYPE_FAR;
return GPTYPE_XSTACK;
default:
fprintf (stderr, "*** internal error: unknown pointer type %d in GPByte.\n",
- p_type);
+ p_type);
break;
}
return -1;
/*-----------------------------------------------------------------*/
void
printGPointerType (FILE * oFile, const char *iname, const char *oname,
- const unsigned int type)
+ const unsigned int type)
{
_printPointerType (oFile, iname);
fprintf (oFile, ",#0x%02x\n", pointerTypeToGPByte (type, iname, oname));
void
printIvalType (symbol *sym, sym_link * type, initList * ilist, FILE * oFile)
{
- value *val;
-
- /* if initList is deep */
- if (ilist->type == INIT_DEEP)
- ilist = ilist->init.deep;
-
- if (!(val = list2val (ilist))) {
- // assuming a warning has been thrown
- val=constVal("0");
- }
-
- if (val->type != type) {
- val = valCastLiteral(type, floatFromVal(val));
- }
-
- switch (getSize (type)) {
- case 1:
- if (!val)
- tfprintf (oFile, "\t!db !constbyte\n", 0);
- else
- tfprintf (oFile, "\t!dbs\n",
- aopLiteral (val, 0));
- break;
-
- case 2:
- if (port->use_dw_for_init)
- tfprintf (oFile, "\t!dws\n", aopLiteralLong (val, 0, 2));
- else if (port->little_endian)
- fprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
- else
- fprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 1), aopLiteral (val, 0));
- break;
- case 4:
- if (!val) {
- tfprintf (oFile, "\t!dw !constword\n", 0);
- tfprintf (oFile, "\t!dw !constword\n", 0);
- }
- else if (port->little_endian) {
- fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
- aopLiteral (val, 0), aopLiteral (val, 1),
- aopLiteral (val, 2), aopLiteral (val, 3));
- }
- else {
- fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
- aopLiteral (val, 3), aopLiteral (val, 2),
- aopLiteral (val, 1), aopLiteral (val, 0));
- }
- break;
- }
+ value *val;
+
+ /* if initList is deep */
+ if (ilist && (ilist->type == INIT_DEEP))
+ ilist = ilist->init.deep;
+
+ if (!(val = list2val (ilist))) {
+ // assuming a warning has been thrown
+ val=constVal("0");
+ }
+
+ if (val->type != type) {
+ val = valCastLiteral(type, floatFromVal(val));
+ }
+
+ switch (getSize (type)) {
+ case 1:
+ if (!val)
+ tfprintf (oFile, "\t!db !constbyte\n", 0);
+ else
+ tfprintf (oFile, "\t!dbs\n",
+ aopLiteral (val, 0));
+ break;
+
+ case 2:
+ if (port->use_dw_for_init)
+ tfprintf (oFile, "\t!dws\n", aopLiteralLong (val, 0, 2));
+ else if (port->little_endian)
+ fprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
+ else
+ fprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 1), aopLiteral (val, 0));
+ break;
+ case 4:
+ if (!val) {
+ tfprintf (oFile, "\t!dw !constword\n", 0);
+ tfprintf (oFile, "\t!dw !constword\n", 0);
+ }
+ else if (port->little_endian) {
+ fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+ aopLiteral (val, 0), aopLiteral (val, 1),
+ aopLiteral (val, 2), aopLiteral (val, 3));
+ }
+ else {
+ fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+ aopLiteral (val, 3), aopLiteral (val, 2),
+ aopLiteral (val, 1), aopLiteral (val, 0));
+ }
+ break;
+ }
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
void printIvalBitFields(symbol **sym, initList **ilist, FILE * oFile)
{
- value *val ;
- symbol *lsym = *sym;
- initList *lilist = *ilist ;
- unsigned long ival = 0;
- int size =0;
-
-
- do {
- unsigned long i;
- val = list2val(lilist);
- if (size) {
- if (SPEC_BLEN(lsym->etype) > 8) {
- size += ((SPEC_BLEN (lsym->etype) / 8) +
- (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
- }
- } else {
- size = ((SPEC_BLEN (lsym->etype) / 8) +
- (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
- }
- i = (unsigned long)floatFromVal(val);
- i <<= SPEC_BSTR (lsym->etype);
- ival |= i;
- if (! ( lsym->next &&
- (IS_BITFIELD(lsym->next->type)) &&
- (SPEC_BSTR(lsym->next->etype)))) break;
- lsym = lsym->next;
- lilist = lilist->next;
- } while (1);
- switch (size) {
- case 1:
- tfprintf (oFile, "\t!db !constbyte\n",ival);
- break;
-
- case 2:
- tfprintf (oFile, "\t!dw !constword\n",ival);
- break;
- case 4: /* EEP: why is this db and not dw? */
- tfprintf (oFile, "\t!db !constword,!constword\n",
- (ival >> 8) & 0xffff, (ival & 0xffff));
- break;
- }
- *sym = lsym;
- *ilist = lilist;
+ value *val ;
+ symbol *lsym = *sym;
+ initList *lilist = *ilist ;
+ unsigned long ival = 0;
+ int size =0;
+
+
+ do {
+ unsigned long i;
+ val = list2val(lilist);
+ if (size) {
+ if (SPEC_BLEN(lsym->etype) > 8) {
+ size += ((SPEC_BLEN (lsym->etype) / 8) +
+ (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
+ }
+ } else {
+ size = ((SPEC_BLEN (lsym->etype) / 8) +
+ (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
+ }
+ i = (unsigned long)floatFromVal(val);
+ i <<= SPEC_BSTR (lsym->etype);
+ ival |= i;
+ if (! ( lsym->next &&
+ (IS_BITFIELD(lsym->next->type)) &&
+ (SPEC_BSTR(lsym->next->etype)))) break;
+ lsym = lsym->next;
+ lilist = lilist->next;
+ } while (1);
+ switch (size) {
+ case 1:
+ tfprintf (oFile, "\t!db !constbyte\n",ival);
+ break;
+
+ case 2:
+ tfprintf (oFile, "\t!dw !constword\n",ival);
+ break;
+ case 4: /* EEP: why is this db and not dw? */
+ tfprintf (oFile, "\t!db !constword,!constword\n",
+ (ival >> 8) & 0xffff, (ival & 0xffff));
+ break;
+ }
+ *sym = lsym;
+ *ilist = lilist;
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
void
printIvalStruct (symbol * sym, sym_link * type,
- initList * ilist, FILE * oFile)
+ initList * ilist, FILE * oFile)
{
- symbol *sflds;
- initList *iloop;
-
- sflds = SPEC_STRUCT (type)->fields;
- if (ilist->type != INIT_DEEP) {
- werrorfl (sym->fileDef, sym->lineDef, E_INIT_STRUCT, sym->name);
- return;
- }
-
- iloop = ilist->init.deep;
-
- for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
- if (IS_BITFIELD(sflds->type)) {
- printIvalBitFields(&sflds,&iloop,oFile);
- } else {
- printIval (sym, sflds->type, iloop, oFile);
- }
- }
- if (iloop) {
- werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "struct", sym->name);
- }
- return;
+ symbol *sflds;
+ initList *iloop = NULL;
+
+ sflds = SPEC_STRUCT (type)->fields;
+
+ if (ilist) {
+ if (ilist->type != INIT_DEEP) {
+ werrorfl (sym->fileDef, sym->lineDef, E_INIT_STRUCT, sym->name);
+ return;
+ }
+
+ iloop = ilist->init.deep;
+ }
+
+ for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
+ if (IS_BITFIELD(sflds->type)) {
+ printIvalBitFields(&sflds,&iloop,oFile);
+ } else {
+ printIval (sym, sflds->type, iloop, oFile);
+ }
+ }
+ if (iloop) {
+ werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "struct", sym->name);
+ }
+ return;
}
/*-----------------------------------------------------------------*/
val = list2val (ilist);
/* if the value is a character string */
if (IS_ARRAY (val->type) && IS_CHAR (val->etype))
- {
- if (!DCL_ELEM (type))
- DCL_ELEM (type) = strlen (SPEC_CVAL (val->etype).v_char) + 1;
+ {
+ if (!DCL_ELEM (type))
+ DCL_ELEM (type) = strlen (SPEC_CVAL (val->etype).v_char) + 1;
- printChar (oFile, SPEC_CVAL (val->etype).v_char, DCL_ELEM (type));
+ printChar (oFile, SPEC_CVAL (val->etype).v_char, DCL_ELEM (type));
- return 1;
- }
+ return 1;
+ }
else
- return 0;
+ return 0;
}
else
printChar (oFile, s, strlen (s) + 1);
/*-----------------------------------------------------------------*/
void
printIvalArray (symbol * sym, sym_link * type, initList * ilist,
- FILE * oFile)
+ FILE * oFile)
{
initList *iloop;
int size = 0;
- /* take care of the special case */
- /* array of characters can be init */
- /* by a string */
- if (IS_CHAR (type->next)) {
- if (!IS_LITERAL(list2val(ilist)->etype)) {
- werrorfl (ilist->filename, ilist->lineno, E_CONST_EXPECTED);
- return;
+ if (ilist) {
+ /* take care of the special case */
+ /* array of characters can be init */
+ /* by a string */
+ if (IS_CHAR (type->next)) {
+ if (!IS_LITERAL(list2val(ilist)->etype)) {
+ werrorfl (ilist->filename, ilist->lineno, E_CONST_EXPECTED);
+ return;
+ }
+ if (printIvalChar (type,
+ (ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
+ oFile, SPEC_CVAL (sym->etype).v_char))
+ return;
}
- if (printIvalChar (type,
- (ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
- oFile, SPEC_CVAL (sym->etype).v_char))
- return;
- }
- /* not the special case */
- if (ilist->type != INIT_DEEP)
- {
+ /* not the special case */
+ if (ilist->type != INIT_DEEP) {
werrorfl (ilist->filename, ilist->lineno, E_INIT_STRUCT, sym->name);
return;
}
- for (iloop=ilist->init.deep; iloop; iloop=iloop->next)
- {
+ for (iloop=ilist->init.deep; iloop; iloop=iloop->next) {
printIval (sym, type->next, iloop, oFile);
- if (++size > DCL_ELEM(type)) {
- werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "array", sym->name);
- break;
+ if ((++size > DCL_ELEM(type)) && DCL_ELEM(type)) {
+ werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "array", sym->name);
+ break;
}
}
+ }
if (DCL_ELEM(type)) {
// pad with zeros if needed
if (size<DCL_ELEM(type)) {
size = (DCL_ELEM(type) - size) * getSize(type->next);
while (size--) {
- tfprintf (oFile, "\t!db !constbyte\n", 0);
+ tfprintf (oFile, "\t!db !constbyte\n", 0);
}
}
} else {
value *val;
int dLvl = 0;
- val = list2val (ilist);
+ if (ilist)
+ val = list2val (ilist);
+ else
+ val = valCastLiteral(type, 0.0);
if (!val) {
- // an error has been thrown allready
+ // an error has been thrown already
val=constVal("0");
}
if (IS_LITERAL(val->etype)) {
- if (compareType(type,val->etype)==0) {
+ if (compareType(type, val->etype) == 0) {
werrorfl (ilist->filename, ilist->lineno, E_INCOMPAT_TYPES);
printFromToType (val->type, type);
}
if (!val->sym)
{
if (port->use_dw_for_init)
- {
- tfprintf (oFile, "\t!dws\n", val->name);
- }
+ {
+ tfprintf (oFile, "\t!dws\n", val->name);
+ }
else
- {
- printPointerType (oFile, val->name);
- }
+ {
+ printPointerType (oFile, val->name);
+ }
}
else if (port->use_dw_for_init)
{
if (val->name && strlen (val->name))
{
- if (size == 1) /* This appears to be Z80 specific?? */
- {
- tfprintf (oFile,
- "\t!dbs\n", val->name);
- }
+ if (size == 1) /* This appears to be Z80 specific?? */
+ {
+ tfprintf (oFile,
+ "\t!dbs\n", val->name);
+ }
else if (size == FPTRSIZE)
- {
- if (port->use_dw_for_init)
- {
- tfprintf (oFile, "\t!dws\n", val->name);
- }
- else
- {
- printPointerType (oFile, val->name);
- }
- }
+ {
+ if (port->use_dw_for_init)
+ {
+ tfprintf (oFile, "\t!dws\n", val->name);
+ }
+ else
+ {
+ printPointerType (oFile, val->name);
+ }
+ }
else if (size == GPTRSIZE)
- {
- int type;
- if (IS_PTR (val->type)) {
- type = DCL_TYPE (val->type);
- } else {
- type = PTR_TYPE (SPEC_OCLS (val->etype));
- }
- if (val->sym && val->sym->isstrlit) {
- // this is a literal string
- type=CPOINTER;
- }
- printGPointerType (oFile, val->name, sym->name, type);
- }
+ {
+ int type;
+ if (IS_PTR (val->type)) {
+ type = DCL_TYPE (val->type);
+ } else {
+ type = PTR_TYPE (SPEC_OCLS (val->etype));
+ }
+ if (val->sym && val->sym->isstrlit) {
+ // this is a literal string
+ type=CPOINTER;
+ }
+ printGPointerType (oFile, val->name, sym->name, type);
+ }
else
- {
- fprintf (stderr, "*** internal error: unknown size in "
- "printIvalCharPtr.\n");
- }
+ {
+ fprintf (stderr, "*** internal error: unknown size in "
+ "printIvalCharPtr.\n");
+ }
}
else
{
// these are literals assigned to pointers
switch (size)
- {
- case 1:
- tfprintf (oFile, "\t!dbs\n", aopLiteral (val, 0));
- break;
- case 2:
- if (port->use_dw_for_init)
- tfprintf (oFile, "\t!dws\n", aopLiteralLong (val, 0, size));
- else if (port->little_endian)
- tfprintf (oFile, "\t.byte %s,%s\n",
- aopLiteral (val, 0), aopLiteral (val, 1));
- else
- tfprintf (oFile, "\t.byte %s,%s\n",
- aopLiteral (val, 1), aopLiteral (val, 0));
- break;
- case 3:
- if (IS_GENPTR(type) && floatFromVal(val)!=0) {
- // non-zero mcs51 generic pointer
- werrorfl (sym->fileDef, sym->lineDef, E_LITERAL_GENERIC);
- }
- if (port->little_endian) {
- fprintf (oFile, "\t.byte %s,%s,%s\n",
- aopLiteral (val, 0),
- aopLiteral (val, 1),
- aopLiteral (val, 2));
- } else {
- fprintf (oFile, "\t.byte %s,%s,%s\n",
- aopLiteral (val, 2),
- aopLiteral (val, 1),
- aopLiteral (val, 0));
- }
- break;
- case 4:
- if (IS_GENPTR(type) && floatFromVal(val)!=0) {
- // non-zero ds390 generic pointer
- werrorfl (sym->fileDef, sym->lineDef, E_LITERAL_GENERIC);
- }
- if (port->little_endian) {
- fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
- aopLiteral (val, 0),
- aopLiteral (val, 1),
- aopLiteral (val, 2),
- aopLiteral (val, 3));
- } else {
- fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
- aopLiteral (val, 3),
- aopLiteral (val, 2),
- aopLiteral (val, 1),
- aopLiteral (val, 0));
- }
- break;
- default:
- assert (0);
- }
+ {
+ case 1:
+ tfprintf (oFile, "\t!dbs\n", aopLiteral (val, 0));
+ break;
+ case 2:
+ if (port->use_dw_for_init)
+ tfprintf (oFile, "\t!dws\n", aopLiteralLong (val, 0, size));
+ else if (port->little_endian)
+ tfprintf (oFile, "\t.byte %s,%s\n",
+ aopLiteral (val, 0), aopLiteral (val, 1));
+ else
+ tfprintf (oFile, "\t.byte %s,%s\n",
+ aopLiteral (val, 1), aopLiteral (val, 0));
+ break;
+ case 3:
+ if (IS_GENPTR(type) && floatFromVal(val)!=0) {
+ // non-zero mcs51 generic pointer
+ werrorfl (sym->fileDef, sym->lineDef, E_LITERAL_GENERIC);
+ }
+ if (port->little_endian) {
+ fprintf (oFile, "\t.byte %s,%s,%s\n",
+ aopLiteral (val, 0),
+ aopLiteral (val, 1),
+ aopLiteral (val, 2));
+ } else {
+ fprintf (oFile, "\t.byte %s,%s,%s\n",
+ aopLiteral (val, 2),
+ aopLiteral (val, 1),
+ aopLiteral (val, 0));
+ }
+ break;
+ case 4:
+ if (IS_GENPTR(type) && floatFromVal(val)!=0) {
+ // non-zero ds390 generic pointer
+ werrorfl (sym->fileDef, sym->lineDef, E_LITERAL_GENERIC);
+ }
+ if (port->little_endian) {
+ fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+ aopLiteral (val, 0),
+ aopLiteral (val, 1),
+ aopLiteral (val, 2),
+ aopLiteral (val, 3));
+ } else {
+ fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+ aopLiteral (val, 3),
+ aopLiteral (val, 2),
+ aopLiteral (val, 1),
+ aopLiteral (val, 0));
+ }
+ break;
+ default:
+ assert (0);
+ }
}
if (val->sym && val->sym->isstrlit && !isinSet(statsg->syms, val->sym)) {
int size;
/* if deep then */
- if (ilist->type == INIT_DEEP)
+ if (ilist && (ilist->type == INIT_DEEP))
ilist = ilist->init.deep;
/* function pointer */
if (IS_LITERAL (val->etype))
{
switch (getSize (type))
- {
- case 1:
- tfprintf (oFile, "\t!db !constbyte\n", (unsigned int) floatFromVal (val) & 0xff);
- break;
- case 2:
- if (port->use_dw_for_init)
- tfprintf (oFile, "\t!dws\n", aopLiteralLong (val, 0, 2));
- else if (port->little_endian)
- tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
- else
- tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 1), aopLiteral (val, 0));
- break;
- case 3: // how about '390??
- fprintf (oFile, "; generic printIvalPtr\n");
- if (port->little_endian)
- {
- fprintf (oFile, "\t.byte %s,%s",
- aopLiteral (val, 0), aopLiteral (val, 1));
- }
- else
- {
- fprintf (oFile, "\t.byte %s,%s",
- aopLiteral (val, 1), aopLiteral (val, 0));
- }
- if (IS_GENPTR (val->type))
- fprintf (oFile, ",%s\n", aopLiteral (val, 2));
- else if (IS_PTR (val->type))
- fprintf (oFile, ",#%x\n", pointerTypeToGPByte (DCL_TYPE (val->type), NULL, NULL));
- else
- fprintf (oFile, ",%s\n", aopLiteral (val, 2));
- }
+ {
+ case 1:
+ tfprintf (oFile, "\t!db !constbyte\n", (unsigned int) floatFromVal (val) & 0xff);
+ break;
+ case 2:
+ if (port->use_dw_for_init)
+ tfprintf (oFile, "\t!dws\n", aopLiteralLong (val, 0, 2));
+ else if (port->little_endian)
+ tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
+ else
+ tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 1), aopLiteral (val, 0));
+ break;
+ case 3: // how about '390??
+ fprintf (oFile, "; generic printIvalPtr\n");
+ if (port->little_endian)
+ {
+ fprintf (oFile, "\t.byte %s,%s",
+ aopLiteral (val, 0), aopLiteral (val, 1));
+ }
+ else
+ {
+ fprintf (oFile, "\t.byte %s,%s",
+ aopLiteral (val, 1), aopLiteral (val, 0));
+ }
+ if (IS_GENPTR (val->type))
+ fprintf (oFile, ",%s\n", aopLiteral (val, 2));
+ else if (IS_PTR (val->type))
+ fprintf (oFile, ",#%x\n", pointerTypeToGPByte (DCL_TYPE (val->type), NULL, NULL));
+ else
+ fprintf (oFile, ",%s\n", aopLiteral (val, 2));
+ }
return;
}
size = getSize (type);
- if (size == 1) /* Z80 specific?? */
+ if (size == 1) /* Z80 specific?? */
{
tfprintf (oFile, "\t!dbs\n", val->name);
}
else if (size == FPTRSIZE)
{
if (port->use_dw_for_init) {
- tfprintf (oFile, "\t!dws\n", val->name);
+ tfprintf (oFile, "\t!dws\n", val->name);
} else {
- printPointerType (oFile, val->name);
+ printPointerType (oFile, val->name);
}
}
else if (size == GPTRSIZE)
{
printGPointerType (oFile, val->name, sym->name,
- (IS_PTR (val->type) ? DCL_TYPE (val->type) :
- PTR_TYPE (SPEC_OCLS (val->etype))));
+ (IS_PTR (val->type) ? DCL_TYPE (val->type) :
+ PTR_TYPE (SPEC_OCLS (val->etype))));
}
return;
}
{
sym_link *itype;
- if (!ilist)
- return;
-
/* if structure then */
if (IS_STRUCT (type))
{
return;
}
- // not an aggregate, ilist must be a node
- if (ilist->type!=INIT_NODE) {
- // or a 1-element list
- if (ilist->init.deep->next) {
- werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "scalar",
- sym->name);
- } else {
- ilist=ilist->init.deep;
- }
- }
-
- // and the type must match
- itype=ilist->init.node->ftype;
+ if (ilist)
+ {
+ // not an aggregate, ilist must be a node
+ if (ilist->type!=INIT_NODE) {
+ // or a 1-element list
+ if (ilist->init.deep->next) {
+ werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "scalar",
+ sym->name);
+ } else {
+ ilist=ilist->init.deep;
+ }
+ }
- if (compareType(type, itype)==0) {
- // special case for literal strings
- if (IS_ARRAY (itype) && IS_CHAR (getSpec(itype)) &&
- // which are really code pointers
- IS_PTR(type) && DCL_TYPE(type)==CPOINTER) {
- // no sweat
- } else {
- werrorfl (ilist->filename, ilist->lineno, E_TYPE_MISMATCH, "assignment", " ");
- printFromToType(itype, type);
+ // and the type must match
+ itype=ilist->init.node->ftype;
+
+ if (compareType(type, itype)==0) {
+ // special case for literal strings
+ if (IS_ARRAY (itype) && IS_CHAR (getSpec(itype)) &&
+ // which are really code pointers
+ IS_PTR(type) && DCL_TYPE(type)==CPOINTER) {
+ // no sweat
+ } else {
+ werrorfl (ilist->filename, ilist->lineno, E_TYPE_MISMATCH, "assignment", " ");
+ printFromToType(itype, type);
+ }
+ }
}
- }
/* if this is a pointer */
if (IS_PTR (type))
/* if it is "extern" then do nothing */
if (IS_EXTERN (sym->etype))
- continue;
+ continue;
/* if it is not static add it to the public
table */
/* print extra debug info if required */
if (options.debug) {
- if (!sym->level)
- { /* global */
- if (IS_STATIC (sym->etype))
- fprintf (out, "F%s$", moduleName); /* scope is file */
- else
- fprintf (out, "G$"); /* scope is global */
- }
- else
- /* symbol is local */
- fprintf (out, "L%s$",
- (sym->localof ? sym->localof->name : "-null-"));
- fprintf (out, "%s$%d$%d", sym->name, sym->level, sym->block);
+ if (!sym->level)
+ { /* global */
+ if (IS_STATIC (sym->etype))
+ fprintf (out, "F%s$", moduleName); /* scope is file */
+ else
+ fprintf (out, "G$"); /* scope is global */
+ }
+ else
+ /* symbol is local */
+ fprintf (out, "L%s$",
+ (sym->localof ? sym->localof->name : "-null-"));
+ fprintf (out, "%s$%d$%d", sym->name, sym->level, sym->block);
}
/* if it has an absolute address */
if (SPEC_ABSA (sym->etype))
- {
- if (options.debug)
- fprintf (out, " == 0x%04x\n", SPEC_ADDR (sym->etype));
-
- fprintf (out, "%s\t=\t0x%04x\n",
- sym->rname,
- SPEC_ADDR (sym->etype));
- }
+ {
+ if (options.debug)
+ fprintf (out, " == 0x%04x\n", SPEC_ADDR (sym->etype));
+
+ fprintf (out, "%s\t=\t0x%04x\n",
+ sym->rname,
+ SPEC_ADDR (sym->etype));
+ }
else
- {
- if (options.debug)
- fprintf (out, " == .\n");
-
- /* if it has an initial value */
- if (sym->ival)
- {
- fprintf (out, "%s:\n", sym->rname);
- noAlloc++;
- resolveIvalSym (sym->ival, sym->type);
- printIval (sym, sym->type, sym->ival, out);
- noAlloc--;
- /* if sym is a simple string and sym->ival is a string,
- WE don't need it anymore */
- if (IS_ARRAY(sym->type) && IS_CHAR(sym->type->next) &&
- IS_AST_SYM_VALUE(list2expr(sym->ival)) &&
- list2val(sym->ival)->sym->isstrlit) {
- freeStringSymbol(list2val(sym->ival)->sym);
- }
- }
- else {
- /* allocate space */
- int size = getSize (sym->type);
-
- if (size==0) {
- werrorfl (sym->fileDef, sym->lineDef, E_UNKNOWN_SIZE,sym->name);
- }
- fprintf (out, "%s:\n", sym->rname);
- /* special case for character strings */
- if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
- SPEC_CVAL (sym->etype).v_char)
- printChar (out,
- SPEC_CVAL (sym->etype).v_char,
- size);
- else
- tfprintf (out, "\t!ds\n", (unsigned int) size & 0xffff);
- }
- }
+ {
+ if (options.debug)
+ fprintf (out, " == .\n");
+
+ /* if it has an initial value */
+ if (sym->ival)
+ {
+ fprintf (out, "%s:\n", sym->rname);
+ noAlloc++;
+ resolveIvalSym (sym->ival, sym->type);
+ printIval (sym, sym->type, sym->ival, out);
+ noAlloc--;
+ /* if sym is a simple string and sym->ival is a string,
+ WE don't need it anymore */
+ if (IS_ARRAY(sym->type) && IS_CHAR(sym->type->next) &&
+ IS_AST_SYM_VALUE(list2expr(sym->ival)) &&
+ list2val(sym->ival)->sym->isstrlit) {
+ freeStringSymbol(list2val(sym->ival)->sym);
+ }
+ }
+ else {
+ /* allocate space */
+ int size = getSize (sym->type);
+
+ if (size==0) {
+ werrorfl (sym->fileDef, sym->lineDef, E_UNKNOWN_SIZE,sym->name);
+ }
+ fprintf (out, "%s:\n", sym->rname);
+ /* special case for character strings */
+ if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
+ SPEC_CVAL (sym->etype).v_char)
+ printChar (out,
+ SPEC_CVAL (sym->etype).v_char,
+ size);
+ else
+ tfprintf (out, "\t!ds\n", (unsigned int) size & 0xffff);
+ }
+ }
}
}
if (!(mainf = findSymWithLevel (SymbolTab, mainf)))
{
if (!options.cc_only && !noAssemble && !options.c1mode)
- werror (E_NO_MAIN);
+ werror (E_NO_MAIN);
return;
}
{
/* if ! compile only then main function should be present */
if (!options.cc_only && !noAssemble)
- werror (E_NO_MAIN);
+ werror (E_NO_MAIN);
return;
}
/* now for the other interrupts */
for (; i < maxInterrupts; i++)
- {
- if (interrupts[i])
- {
- fprintf (vFile, "\tljmp\t%s\n", interrupts[i]->rname);
- if ( i != maxInterrupts - 1 )
- fprintf (vFile, "\t.ds\t5\n");
- }
- else
- {
- fprintf (vFile, "\treti\n");
- if ( i != maxInterrupts - 1 )
- fprintf (vFile, "\t.ds\t7\n");
- }
- }
+ {
+ if (interrupts[i])
+ {
+ fprintf (vFile, "\tljmp\t%s\n", interrupts[i]->rname);
+ if ( i != maxInterrupts - 1 )
+ fprintf (vFile, "\t.ds\t5\n");
+ }
+ else
+ {
+ fprintf (vFile, "\treti\n");
+ if ( i != maxInterrupts - 1 )
+ fprintf (vFile, "\t.ds\t7\n");
+ }
+ }
}
}
symbol *sym;
if (elementsInSet (ovrset))
- {
- /* output the area informtion */
- fprintf (afile, "\t.area\t%s\n", port->mem.overlay_name); /* MOF */
- }
+ {
+ /* output the area informtion */
+ fprintf (afile, "\t.area\t%s\n", port->mem.overlay_name); /* MOF */
+ }
for (sym = setFirstItem (ovrset); sym;
- sym = setNextItem (ovrset))
- {
- /* if extern then it is in the publics table: do nothing */
- if (IS_EXTERN (sym->etype))
- continue;
-
- /* if allocation required check is needed
- then check if the symbol really requires
- allocation only for local variables */
- if (!IS_AGGREGATE (sym->type) &&
- !(sym->_isparm && !IS_REGPARM (sym->etype))
- && !sym->allocreq && sym->level)
- continue;
-
- /* if global variable & not static or extern
- and addPublics allowed then add it to the public set */
- if ((sym->_isparm && !IS_REGPARM (sym->etype))
- && !IS_STATIC (sym->etype))
+ sym = setNextItem (ovrset))
+ {
+ /* if extern then it is in the publics table: do nothing */
+ if (IS_EXTERN (sym->etype))
+ continue;
+
+ /* if allocation required check is needed
+ then check if the symbol really requires
+ allocation only for local variables */
+ if (!IS_AGGREGATE (sym->type) &&
+ !(sym->_isparm && !IS_REGPARM (sym->etype))
+ && !sym->allocreq && sym->level)
+ continue;
+
+ /* if global variable & not static or extern
+ and addPublics allowed then add it to the public set */
+ if ((sym->_isparm && !IS_REGPARM (sym->etype))
+ && !IS_STATIC (sym->etype))
{
addSetHead (&publics, sym);
}
- /* if extern then do nothing or is a function
- then do nothing */
- if (IS_FUNC (sym->type))
- continue;
-
- /* print extra debug info if required */
- if (options.debug)
- {
- if (!sym->level)
- { /* global */
- if (IS_STATIC (sym->etype))
- fprintf (afile, "F%s$", moduleName); /* scope is file */
- else
- fprintf (afile, "G$"); /* scope is global */
- }
- else
- /* symbol is local */
- fprintf (afile, "L%s$",
- (sym->localof ? sym->localof->name : "-null-"));
- fprintf (afile, "%s$%d$%d", sym->name, sym->level, sym->block);
- }
-
- /* if is has an absolute address then generate
- an equate for this no need to allocate space */
- if (SPEC_ABSA (sym->etype))
- {
-
- if (options.debug)
- fprintf (afile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
-
- fprintf (afile, "%s\t=\t0x%04x\n",
- sym->rname,
- SPEC_ADDR (sym->etype));
- }
- else {
- int size = getSize(sym->type);
-
- if (size==0) {
- werrorfl (sym->fileDef, sym->lineDef, E_UNKNOWN_SIZE);
- }
- if (options.debug)
- fprintf (afile, "==.\n");
-
- /* allocate space */
- tfprintf (afile, "!labeldef\n", sym->rname);
- tfprintf (afile, "\t!ds\n", (unsigned int) getSize (sym->type) & 0xffff);
- }
-
- }
+ /* if extern then do nothing or is a function
+ then do nothing */
+ if (IS_FUNC (sym->type))
+ continue;
+
+ /* print extra debug info if required */
+ if (options.debug)
+ {
+ if (!sym->level)
+ { /* global */
+ if (IS_STATIC (sym->etype))
+ fprintf (afile, "F%s$", moduleName); /* scope is file */
+ else
+ fprintf (afile, "G$"); /* scope is global */
+ }
+ else
+ /* symbol is local */
+ fprintf (afile, "L%s$",
+ (sym->localof ? sym->localof->name : "-null-"));
+ fprintf (afile, "%s$%d$%d", sym->name, sym->level, sym->block);
+ }
+
+ /* if is has an absolute address then generate
+ an equate for this no need to allocate space */
+ if (SPEC_ABSA (sym->etype))
+ {
+
+ if (options.debug)
+ fprintf (afile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
+
+ fprintf (afile, "%s\t=\t0x%04x\n",
+ sym->rname,
+ SPEC_ADDR (sym->etype));
+ }
+ else {
+ int size = getSize(sym->type);
+
+ if (size==0) {
+ werrorfl (sym->fileDef, sym->lineDef, E_UNKNOWN_SIZE);
+ }
+ if (options.debug)
+ fprintf (afile, "==.\n");
+
+ /* allocate space */
+ tfprintf (afile, "!labeldef\n", sym->rname);
+ tfprintf (afile, "\t!ds\n", (unsigned int) getSize (sym->type) & 0xffff);
+ }
+
+ }
}
}
}
if(mcs51_like)
- {
+ {
/* copy the sbit segment */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; special function bits \n");
copyFile (asmFile, sfrbit->oFile);
/*JCF: Create the areas for the register banks*/
- if(RegBankUsed[0]||RegBankUsed[1]||RegBankUsed[2]||RegBankUsed[3])
- {
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; overlayable register banks \n");
- fprintf (asmFile, "%s", iComments2);
- if(RegBankUsed[0])
- fprintf (asmFile, "\t.area REG_BANK_0\t(REL,OVR,DATA)\n\t.ds 8\n");
- if(RegBankUsed[1]||options.parms_in_bank1)
- fprintf (asmFile, "\t.area REG_BANK_1\t(REL,OVR,DATA)\n\t.ds 8\n");
- if(RegBankUsed[2])
- fprintf (asmFile, "\t.area REG_BANK_2\t(REL,OVR,DATA)\n\t.ds 8\n");
- if(RegBankUsed[3])
- fprintf (asmFile, "\t.area REG_BANK_3\t(REL,OVR,DATA)\n\t.ds 8\n");
- }
- }
+ if(RegBankUsed[0]||RegBankUsed[1]||RegBankUsed[2]||RegBankUsed[3])
+ {
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; overlayable register banks \n");
+ fprintf (asmFile, "%s", iComments2);
+ if(RegBankUsed[0])
+ fprintf (asmFile, "\t.area REG_BANK_0\t(REL,OVR,DATA)\n\t.ds 8\n");
+ if(RegBankUsed[1]||options.parms_in_bank1)
+ fprintf (asmFile, "\t.area REG_BANK_1\t(REL,OVR,DATA)\n\t.ds 8\n");
+ if(RegBankUsed[2])
+ fprintf (asmFile, "\t.area REG_BANK_2\t(REL,OVR,DATA)\n\t.ds 8\n");
+ if(RegBankUsed[3])
+ fprintf (asmFile, "\t.area REG_BANK_3\t(REL,OVR,DATA)\n\t.ds 8\n");
+ }
+ }
/* copy the data segment */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; Stack segment in internal ram \n");
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "\t.area\tSSEG\t(DATA)\n"
- "__start__stack:\n\t.ds\t1\n\n");
+ "__start__stack:\n\t.ds\t1\n\n");
}
/* create the idata segment */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; external stack \n");
fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "\t.area XSEG (XDATA)\n"); /* MOF */
+ fprintf (asmFile, "\t.area XSEG (XDATA)\n"); /* MOF */
fprintf (asmFile, "\t.ds 256\n");
}
if (port->extraAreas.genExtraAreaDeclaration)
{
port->extraAreas.genExtraAreaDeclaration(asmFile,
- mainf && IFFUNC_HASBODY(mainf->type));
+ mainf && IFFUNC_HASBODY(mainf->type));
}
/* copy the interrupt vector table */
* the post_static_name area will immediately follow the static_name
* area.
*/
- tfprintf (asmFile, "\t!area\n", port->mem.static_name); /* MOF */
+ tfprintf (asmFile, "\t!area\n", port->mem.static_name); /* MOF */
tfprintf (asmFile, "\t!area\n", port->mem.post_static_name);
tfprintf (asmFile, "\t!area\n", port->mem.static_name);
{
if (port->genInitStartup)
{
- port->genInitStartup(asmFile);
- }
+ port->genInitStartup(asmFile);
+ }
else
{
fprintf (asmFile, "__sdcc_gsinit_startup:\n");
going into P2 and the lower order going into
spx */
if (options.useXstack)
- {
- fprintf (asmFile, "\tmov\tP2,#0x%02x\n",
- (((unsigned int) options.xdata_loc) >> 8) & 0xff);
- fprintf (asmFile, "\tmov\t_spx,#0x%02x\n",
- (unsigned int) options.xdata_loc & 0xff);
- }
+ {
+ fprintf (asmFile, "\tmov\tP2,#0x%02x\n",
+ (((unsigned int) options.xdata_loc) >> 8) & 0xff);
+ fprintf (asmFile, "\tmov\t_spx,#0x%02x\n",
+ (unsigned int) options.xdata_loc & 0xff);
+ }
// This should probably be a port option, but I'm being lazy.
// on the 400, the firmware boot loader gives us a valid stack
// (see '400 data sheet pg. 85 (TINI400 ROM Initialization code)
if (!TARGET_IS_DS400)
- {
- /* initialise the stack pointer. JCF: aslink takes care of the location */
- fprintf (asmFile, "\tmov\tsp,#__start__stack - 1\n"); /* MOF */
- }
+ {
+ /* initialise the stack pointer. JCF: aslink takes care of the location */
+ fprintf (asmFile, "\tmov\tsp,#__start__stack - 1\n"); /* MOF */
+ }
fprintf (asmFile, "\tlcall\t__sdcc_external_startup\n");
fprintf (asmFile, "\tmov\ta,dpl\n");
// if the port can copy the XINIT segment to XISEG
if (port->genXINIT)
- {
- port->genXINIT(asmFile);
+ {
+ port->genXINIT(asmFile);
}
- }
+ }
}
copyFile (asmFile, statsg->oFile);
}
fprintf (asmFile,
- "%s"
- "; Home\n"
- "%s", iComments2, iComments2);
+ "%s"
+ "; Home\n"
+ "%s", iComments2, iComments2);
tfprintf (asmFile, "\t!areahome\n", HOME_NAME);
copyFile (asmFile, home->oFile);
}
-/** Creates a temporary file with unoque file name
+/** Creates a temporary file with unique file name
Scans, in order:
- TMP, TEMP, TMPDIR env. varibles
- if Un*x system: /usr/tmp and /tmp
if (!warning_emitted)
{
fprintf (stderr, "TMP not defined in environment, using %s for temporary files\n.", tmpdir);
- warning_emitted = 1;
- }
+ warning_emitted = 1;
+ }
}
}
#else
return "unknown";
};
-bucket *SymbolTab[256]; /* the symbol table */
-bucket *StructTab[256]; /* the structure table */
-bucket *TypedefTab[256]; /* the typedef table */
-bucket *LabelTab[256]; /* the Label table */
-bucket *enumTab[256]; /* enumerated table */
+bucket *SymbolTab[256]; /* the symbol table */
+bucket *StructTab[256]; /* the structure table */
+bucket *TypedefTab[256]; /* the typedef table */
+bucket *LabelTab[256]; /* the Label table */
+bucket *enumTab[256]; /* enumerated table */
/*------------------------------------------------------------------*/
/* initSymt () - initialises symbol table related stuff */
/*-----------------------------------------------------------------*/
void
addSym (bucket ** stab,
- void *sym,
- char *sname,
- int level,
- int block,
- int checkType)
+ void *sym,
+ char *sname,
+ int level,
+ int block,
+ int checkType)
{
- int i; /* index into the hash Table */
- bucket *bp; /* temp bucket * */
+ int i; /* index into the hash Table */
+ bucket *bp; /* temp bucket * */
if (checkType) {
symbol *csym = (symbol *)sym;
/* get a free entry */
bp = Safe_alloc ( sizeof (bucket));
- bp->sym = sym; /* update the symbol pointer */
- bp->level = level; /* update the nest level */
+ bp->sym = sym; /* update the symbol pointer */
+ bp->level = level; /* update the nest level */
bp->block = block;
- strncpyz (bp->name, sname, sizeof(bp->name)); /* copy the name into place */
+ strncpyz (bp->name, sname, sizeof(bp->name)); /* copy the name into place */
/* if this is the first entry */
if (stab[i] == NULL)
{
- bp->prev = bp->next = (void *) NULL; /* point to nothing */
+ bp->prev = bp->next = (void *) NULL; /* point to nothing */
stab[i] = bp;
}
/* not first entry then add @ head of list */
/* find the symbol */
while (bp)
{
- if (bp->sym == sym) /* found it then break out */
- break; /* of the loop */
+ if (bp->sym == sym) /* found it then break out */
+ break; /* of the loop */
bp = bp->next;
}
- if (!bp) /* did not find it */
+ if (!bp) /* did not find it */
return;
/* if this is the first one in the chain */
if (!bp->prev)
{
stab[i] = bp->next;
- if (stab[i]) /* if chain ! empty */
- stab[i]->prev = (void *) NULL;
+ if (stab[i]) /* if chain ! empty */
+ stab[i]->prev = (void *) NULL;
}
/* middle || end of chain */
else
{
- if (bp->next) /* if not end of chain */
- bp->next->prev = bp->prev;
+ if (bp->next) /* if not end of chain */
+ bp->next->prev = bp->prev;
bp->prev->next = bp->next;
}
while (bp)
{
if (bp->sym == sym || strcmp (bp->name, sname) == 0)
- break;
+ break;
bp = bp->next;
}
while (bp)
{
if (strcmp (bp->name, sym->name) == 0 && bp->level <= sym->level)
- {
- /* if this is parameter then nothing else need to be checked */
- if (((symbol *) (bp->sym))->_isparm)
- return (bp->sym);
- /* if levels match then block numbers should also match */
- if (bp->level && bp->level == sym->level && bp->block == sym->block)
- return (bp->sym);
- /* if levels don't match then we are okay */
- if (bp->level && bp->level != sym->level && bp->block <= sym->block)
- return (bp->sym);
- /* if this is a global variable then we are ok too */
- if (bp->level == 0)
- return (bp->sym);
- }
+ {
+ /* if this is parameter then nothing else need to be checked */
+ if (((symbol *) (bp->sym))->_isparm)
+ return (bp->sym);
+ /* if levels match then block numbers should also match */
+ if (bp->level && bp->level == sym->level && bp->block == sym->block)
+ return (bp->sym);
+ /* if levels don't match then we are okay */
+ if (bp->level && bp->level != sym->level && bp->block <= sym->block)
+ return (bp->sym);
+ /* if this is a global variable then we are ok too */
+ if (bp->level == 0)
+ return (bp->sym);
+ }
bp = bp->next;
}
while (bp)
{
if (strcmp (bp->name, sym->name) == 0 &&
- bp->block <= block)
- break;
+ bp->block <= block)
+ break;
bp = bp->next;
}
sym = Safe_alloc ( sizeof (symbol));
- strncpyz (sym->name, name, sizeof(sym->name)); /* copy the name */
- sym->level = scope; /* set the level */
+ strncpyz (sym->name, name, sizeof(sym->name)); /* copy the name */
+ sym->level = scope; /* set the level */
sym->block = currBlockno;
- sym->lineDef = mylineno; /* set the line number */
+ sym->lineDef = mylineno; /* set the line number */
sym->fileDef = currFname;
return sym;
}
s = Safe_alloc ( sizeof (structdef));
- strncpyz (s->tag, tag, sizeof(s->tag)); /* copy the tag */
+ strncpyz (s->tag, tag, sizeof(s->tag)); /* copy the tag */
return s;
}
if (IS_SPEC (type))
{
switch (SPEC_SCLS (type))
- {
- case S_XDATA:
- DCL_TYPE (ptr) = FPOINTER;
- break;
- case S_IDATA:
- DCL_TYPE (ptr) = IPOINTER;
- break;
- case S_PDATA:
- DCL_TYPE (ptr) = PPOINTER;
- break;
- case S_DATA:
- DCL_TYPE (ptr) = POINTER;
- break;
- case S_CODE:
- DCL_TYPE (ptr) = CPOINTER;
- break;
- case S_EEPROM:
- DCL_TYPE (ptr) = EEPPOINTER;
- break;
- default:
- DCL_TYPE (ptr) = port->unqualified_pointer;
- break;
- }
+ {
+ case S_XDATA:
+ DCL_TYPE (ptr) = FPOINTER;
+ break;
+ case S_IDATA:
+ DCL_TYPE (ptr) = IPOINTER;
+ break;
+ case S_PDATA:
+ DCL_TYPE (ptr) = PPOINTER;
+ break;
+ case S_DATA:
+ DCL_TYPE (ptr) = POINTER;
+ break;
+ case S_CODE:
+ DCL_TYPE (ptr) = CPOINTER;
+ break;
+ case S_EEPROM:
+ DCL_TYPE (ptr) = EEPPOINTER;
+ break;
+ default:
+ DCL_TYPE (ptr) = port->unqualified_pointer;
+ break;
+ }
/* the storage class of type ends here */
SPEC_SCLS (type) = 0;
}
while (ptr)
{
if (!IS_SPEC (ptr) && DCL_TYPE (ptr) == UPOINTER)
- DCL_TYPE (ptr) = port->unqualified_pointer;
+ DCL_TYPE (ptr) = port->unqualified_pointer;
ptr = ptr->next;
}
while (type)
{
if (!IS_SPEC (type) && DCL_TYPE (type) == UPOINTER)
- DCL_TYPE (type) = port->unqualified_pointer;
+ DCL_TYPE (type) = port->unqualified_pointer;
type = type->next;
}
}
{
tail = head = p;
while (tail->next)
- tail = tail->next;
+ tail = tail->next;
}
else
{
else
{
if (IS_SPEC (sym->etype) && IS_SPEC (head) && head == tail)
- {
- sym->etype = mergeSpec (sym->etype, head, sym->name);
- }
+ {
+ sym->etype = mergeSpec (sym->etype, head, sym->name);
+ }
else
- {
- if (IS_SPEC (sym->etype) && !IS_SPEC (head) && head == tail)
- {
- t = sym->type;
- while (t->next != sym->etype)
- t = t->next;
- t->next = head;
- tail->next = sym->etype;
- }
- else
- {
- sym->etype->next = head;
- sym->etype = tail;
- }
- }
+ {
+ if (IS_SPEC (sym->etype) && !IS_SPEC (head) && head == tail)
+ {
+ t = sym->type;
+ while (t->next != sym->etype)
+ t = t->next;
+ t->next = head;
+ tail->next = sym->etype;
+ }
+ else
+ {
+ sym->etype->next = head;
+ sym->etype = tail;
+ }
+ }
}
/* if the type is an unknown pointer and has
DCL_TSPEC (p))
{
if (!IS_SPEC (sym->etype))
- {
- sym->etype = sym->etype->next = newLink (SPECIFIER);
- }
+ {
+ sym->etype = sym->etype->next = newLink (SPECIFIER);
+ }
SPEC_SCLS (sym->etype) = SPEC_SCLS (DCL_TSPEC (p));
DCL_TSPEC (p) = NULL;
}
} else {
/* we shouldn't redeclare the type */
if (getenv("DEBUG_SANITY")) {
- fprintf (stderr, "mergeSpec: ");
+ fprintf (stderr, "mergeSpec: ");
}
werror(E_TWO_OR_MORE_DATA_TYPES, name);
}
SPEC_SCLS (dest) = SPEC_SCLS (src);
} else {
if (getenv("DEBUG_SANITY")) {
- fprintf (stderr, "mergeSpec: ");
+ fprintf (stderr, "mergeSpec: ");
}
werror(E_TWO_OR_MORE_STORAGE_CLASSES, name);
}
if (!p)
return 0;
if (IS_SPEC (p))
- { /* if this is the specifier then */
+ { /* if this is the specifier then */
switch (SPEC_NOUN (p))
- { /* depending on the specifier type */
- case V_INT:
- return (IS_LONG (p) ? LONGSIZE : INTSIZE);
- case V_FLOAT:
- return FLOATSIZE;
- case V_CHAR:
- return CHARSIZE;
- case V_VOID:
- return 0;
- case V_STRUCT:
- return SPEC_STRUCT (p)->size;
- case V_LABEL:
- return 0;
- case V_SBIT:
- case V_BIT:
- return BITSIZE;
- case V_BITFIELD:
- return ((SPEC_BLEN (p) / 8) + (SPEC_BLEN (p) % 8 ? 1 : 0));
- default:
- return 0;
- }
+ { /* depending on the specifier type */
+ case V_INT:
+ return (IS_LONG (p) ? LONGSIZE : INTSIZE);
+ case V_FLOAT:
+ return FLOATSIZE;
+ case V_CHAR:
+ return CHARSIZE;
+ case V_VOID:
+ return 0;
+ case V_STRUCT:
+ return SPEC_STRUCT (p)->size;
+ case V_LABEL:
+ return 0;
+ case V_SBIT:
+ case V_BIT:
+ return BITSIZE;
+ case V_BITFIELD:
+ return ((SPEC_BLEN (p) / 8) + (SPEC_BLEN (p) % 8 ? 1 : 0));
+ default:
+ return 0;
+ }
}
- /* this is a specifier */
+ /* this is a declarator */
switch (DCL_TYPE (p))
{
case ARRAY:
if (DCL_ELEM(p)) {
- return DCL_ELEM (p) * getSize (p->next);
+ return DCL_ELEM (p) * getSize (p->next);
} else {
- // werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
- // "can not tell the size of an array[]");
- return 0;
+ // werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ // "can not tell the size of an array[]");
+ return 0;
}
case IPOINTER:
case PPOINTER:
}
}
+/*---------------------------------------------------------------------*/
+/* getAllocSize - returns size of a type chain in bytes for allocation */
+/*---------------------------------------------------------------------*/
+unsigned int
+getAllocSize (sym_link *p)
+{
+ if (IS_STRUCT (p) && SPEC_STRUCT (p)->type == STRUCT)
+ {
+ /* if this is a struct specifier then */
+ /* calculate the size as it could end */
+ /* with an array of unspecified length */
+ symbol *sflds = SPEC_STRUCT (p)->fields;
+
+ while (sflds && sflds->next)
+ sflds = sflds->next;
+
+ if (sflds && !IS_BITFIELD (sflds->type))
+ return sflds->offset + getAllocSize (sflds->type);
+ else
+ return SPEC_STRUCT (p)->size;
+ }
+ else
+ return getSize (p);
+}
+
/*------------------------------------------------------------------*/
/* bitsForType - returns # of bits required to store this type */
/*------------------------------------------------------------------*/
return 0;
if (IS_SPEC (p))
- { /* if this is the specifier then */
+ { /* if this is the specifier then */
switch (SPEC_NOUN (p))
- { /* depending on the specifier type */
- case V_INT:
- return (IS_LONG (p) ? LONGSIZE * 8 : INTSIZE * 8);
- case V_FLOAT:
- return FLOATSIZE * 8;
- case V_CHAR:
- return CHARSIZE * 8;
- case V_VOID:
- return 0;
- case V_STRUCT:
- return SPEC_STRUCT (p)->size * 8;
- case V_LABEL:
- return 0;
- case V_SBIT:
- case V_BIT:
- return 1;
- case V_BITFIELD:
- return SPEC_BLEN (p);
- default:
- return 0;
- }
+ { /* depending on the specifier type */
+ case V_INT:
+ return (IS_LONG (p) ? LONGSIZE * 8 : INTSIZE * 8);
+ case V_FLOAT:
+ return FLOATSIZE * 8;
+ case V_CHAR:
+ return CHARSIZE * 8;
+ case V_VOID:
+ return 0;
+ case V_STRUCT:
+ return SPEC_STRUCT (p)->size * 8;
+ case V_LABEL:
+ return 0;
+ case V_SBIT:
+ case V_BIT:
+ return 1;
+ case V_BITFIELD:
+ return SPEC_BLEN (p);
+ default:
+ return 0;
+ }
}
/* this is a specifier */
then check if the type match, if the types match then
delete the current entry and add the new entry */
if ((csym = findSymWithLevel (SymbolTab, sym)) &&
- csym->level == sym->level) {
-
- /* If the previous definition was for an array with incomplete */
- /* type, and the new definition has completed the type, update */
- /* the original type to match */
- if (IS_DECL(csym->type) && DCL_TYPE(csym->type)==ARRAY
- && IS_DECL(sym->type) && DCL_TYPE(sym->type)==ARRAY)
- {
- if (!DCL_ELEM(csym->type) && DCL_ELEM(sym->type))
- DCL_ELEM(csym->type) = DCL_ELEM(sym->type);
- }
-
- #if 0
- /* If only one of the definitions used the "at" keyword, copy */
- /* the address to the other. */
- if (IS_SPEC(csym->etype) && SPEC_ABSA(csym->etype)
- && IS_SPEC(sym->etype) && !SPEC_ABSA(sym->etype))
- {
- SPEC_ABSA (sym->etype) = 1;
- SPEC_ADDR (sym->etype) = SPEC_ADDR (csym->etype);
- }
- if (IS_SPEC(csym->etype) && !SPEC_ABSA(csym->etype)
- && IS_SPEC(sym->etype) && SPEC_ABSA(sym->etype))
- {
- SPEC_ABSA (csym->etype) = 1;
- SPEC_ADDR (csym->etype) = SPEC_ADDR (sym->etype);
- }
- #endif
+ csym->level == sym->level) {
+
+ /* If the previous definition was for an array with incomplete */
+ /* type, and the new definition has completed the type, update */
+ /* the original type to match */
+ if (IS_DECL(csym->type) && DCL_TYPE(csym->type)==ARRAY
+ && IS_DECL(sym->type) && DCL_TYPE(sym->type)==ARRAY)
+ {
+ if (!DCL_ELEM(csym->type) && DCL_ELEM(sym->type))
+ DCL_ELEM(csym->type) = DCL_ELEM(sym->type);
+ }
+
+ #if 0
+ /* If only one of the definitions used the "at" keyword, copy */
+ /* the address to the other. */
+ if (IS_SPEC(csym->etype) && SPEC_ABSA(csym->etype)
+ && IS_SPEC(sym->etype) && !SPEC_ABSA(sym->etype))
+ {
+ SPEC_ABSA (sym->etype) = 1;
+ SPEC_ADDR (sym->etype) = SPEC_ADDR (csym->etype);
+ }
+ if (IS_SPEC(csym->etype) && !SPEC_ABSA(csym->etype)
+ && IS_SPEC(sym->etype) && SPEC_ABSA(sym->etype))
+ {
+ SPEC_ABSA (csym->etype) = 1;
+ SPEC_ADDR (csym->etype) = SPEC_ADDR (sym->etype);
+ }
+ #endif
error = 0;
if (csym->ival && sym->ival)
error = 1;
- if (compareTypeExact (csym->type, sym->type, sym->level) != 1)
+ if (compareTypeExact (csym->type, sym->type, sym->level) != 1)
error = 1;
if (error) {
/* one definition extern ? */
- if (IS_EXTERN (csym->etype) || IS_EXTERN (sym->etype))
- werror (E_EXTERN_MISMATCH, sym->name);
+ if (IS_EXTERN (csym->etype) || IS_EXTERN (sym->etype))
+ werror (E_EXTERN_MISMATCH, sym->name);
else
- werror (E_DUPLICATE, sym->name);
- werrorfl (csym->fileDef, csym->lineDef, E_PREVIOUS_DEF);
- #if 0
- fprintf (stderr, "from type '");
- printTypeChain (csym->type, stderr);
- if (IS_SPEC (csym->etype) && SPEC_ABSA (csym->etype))
- fprintf(stderr, " at 0x%x", SPEC_ADDR (csym->etype));
- fprintf (stderr, "'\nto type '");
- printTypeChain (sym->type, stderr);
- if (IS_SPEC (sym->etype) && SPEC_ABSA (sym->etype))
- fprintf(stderr, " at 0x%x", SPEC_ADDR (sym->etype));
- fprintf (stderr, "'\n");
- #endif
- continue;
- }
-
- if (csym->ival && !sym->ival)
- sym->ival = csym->ival;
-
- /* delete current entry */
- deleteSym (SymbolTab, csym, csym->name);
- deleteFromSeg(csym);
+ werror (E_DUPLICATE, sym->name);
+ werrorfl (csym->fileDef, csym->lineDef, E_PREVIOUS_DEF);
+ #if 0
+ fprintf (stderr, "from type '");
+ printTypeChain (csym->type, stderr);
+ if (IS_SPEC (csym->etype) && SPEC_ABSA (csym->etype))
+ fprintf(stderr, " at 0x%x", SPEC_ADDR (csym->etype));
+ fprintf (stderr, "'\nto type '");
+ printTypeChain (sym->type, stderr);
+ if (IS_SPEC (sym->etype) && SPEC_ABSA (sym->etype))
+ fprintf(stderr, " at 0x%x", SPEC_ADDR (sym->etype));
+ fprintf (stderr, "'\n");
+ #endif
+ continue;
+ }
+
+ if (csym->ival && !sym->ival)
+ sym->ival = csym->ival;
+
+ /* delete current entry */
+ deleteSym (SymbolTab, csym, csym->name);
+ deleteFromSeg(csym);
}
/* add new entry */
while (lnk)
{
if (IS_FUNC (lnk))
- return 1;
+ return 1;
lnk = lnk->next;
}
return 0;
/* look for the id */
while (fields)
{
- if (strcmp (fields->rname, id->name) == 0)
- {
- type = copyLinkChain (fields->type);
- etype = getSpec (type);
- SPEC_SCLS (etype) = (SPEC_SCLS (petype) == S_REGISTER ?
- SPEC_SCLS (etype) : SPEC_SCLS (petype));
+ if (strcmp (fields->rname, id->name) == 0)
+ {
+ type = copyLinkChain (fields->type);
+ etype = getSpec (type);
+ SPEC_SCLS (etype) = (SPEC_SCLS (petype) == S_REGISTER ?
+ SPEC_SCLS (etype) : SPEC_SCLS (petype));
if (IS_SPEC (type))
SPEC_CONST (type) |= SPEC_CONST (stype);
else
DCL_PTR_CONST (type) |= SPEC_CONST (stype);
- return type;
- }
- fields = fields->next;
+ return type;
+ }
+ fields = fields->next;
}
}
loop = sdef->fields;
while (loop) {
- /* create the internal name for this variable */
- SNPRINTF (loop->rname, sizeof(loop->rname), "_%s", loop->name);
- if (su == UNION) {
- sum = 0;
- bitOffset = 0;
- }
- SPEC_VOLATILE (loop->etype) |= (su == UNION ? 1 : 0);
-
- /* if this is a bit field */
- if (loop->bitVar) {
-
- /* change it to a unsigned bit */
- SPEC_NOUN (loop->etype) = V_BITFIELD;
- SPEC_USIGN (loop->etype) = 1;
- SPEC_BLEN (loop->etype) = loop->bitVar;
-
- if (loop->bitVar == BITVAR_PAD) {
- /* A zero length bitfield forces padding */
- SPEC_BSTR (loop->etype) = bitOffset;
- SPEC_BLEN (loop->etype) = 0;
- bitOffset = 8;
- loop->offset = sum;
- }
- else {
- if (bitOffset == 8) {
- bitOffset = 0;
- sum++;
- }
- /* check if this fit into the remaining */
- /* bits of this byte else align it to the */
- /* next byte boundary */
- if (loop->bitVar <= (8 - bitOffset)) {
- /* fits into current byte */
- loop->offset = sum;
- SPEC_BSTR (loop->etype) = bitOffset;
- bitOffset += loop->bitVar;
- }
- else if (!bitOffset) {
- /* does not fit, but is already byte aligned */
- loop->offset = sum;
- SPEC_BSTR (loop->etype) = bitOffset;
- bitOffset += loop->bitVar;
- }
- else {
- /* does not fit; need to realign first */
- sum++;
- loop->offset = (su == UNION ? sum = 0 : sum);
- bitOffset = 0;
- SPEC_BSTR (loop->etype) = bitOffset;
- bitOffset += loop->bitVar;
- }
- while (bitOffset>8) {
- bitOffset -= 8;
- sum++;
- }
- }
- }
- else {
- /* This is a non-bit field. Make sure we are */
- /* byte aligned first */
- if (bitOffset) {
- sum++;
- loop->offset = (su == UNION ? sum = 0 : sum);
- bitOffset = 0;
- }
- loop->offset = sum;
- checkDecl (loop, 1);
- sum += getSize (loop->type);
- }
-
- loop = loop->next;
-
- /* if union then size = sizeof larget field */
- if (su == UNION) {
- /* For UNION, round up after each field */
- sum += ((bitOffset+7)/8);
- usum = max (usum, sum);
- }
+ /* create the internal name for this variable */
+ SNPRINTF (loop->rname, sizeof(loop->rname), "_%s", loop->name);
+ if (su == UNION) {
+ sum = 0;
+ bitOffset = 0;
+ }
+ SPEC_VOLATILE (loop->etype) |= (su == UNION ? 1 : 0);
+
+ /* if this is a bit field */
+ if (loop->bitVar) {
+
+ /* change it to a unsigned bit */
+ SPEC_NOUN (loop->etype) = V_BITFIELD;
+ SPEC_USIGN (loop->etype) = 1;
+ SPEC_BLEN (loop->etype) = loop->bitVar;
+
+ if (loop->bitVar == BITVAR_PAD) {
+ /* A zero length bitfield forces padding */
+ SPEC_BSTR (loop->etype) = bitOffset;
+ SPEC_BLEN (loop->etype) = 0;
+ bitOffset = 8;
+ loop->offset = sum;
+ }
+ else {
+ if (bitOffset == 8) {
+ bitOffset = 0;
+ sum++;
+ }
+ /* check if this fit into the remaining */
+ /* bits of this byte else align it to the */
+ /* next byte boundary */
+ if (loop->bitVar <= (8 - bitOffset)) {
+ /* fits into current byte */
+ loop->offset = sum;
+ SPEC_BSTR (loop->etype) = bitOffset;
+ bitOffset += loop->bitVar;
+ }
+ else if (!bitOffset) {
+ /* does not fit, but is already byte aligned */
+ loop->offset = sum;
+ SPEC_BSTR (loop->etype) = bitOffset;
+ bitOffset += loop->bitVar;
+ }
+ else {
+ /* does not fit; need to realign first */
+ sum++;
+ loop->offset = (su == UNION ? sum = 0 : sum);
+ bitOffset = 0;
+ SPEC_BSTR (loop->etype) = bitOffset;
+ bitOffset += loop->bitVar;
+ }
+ while (bitOffset>8) {
+ bitOffset -= 8;
+ sum++;
+ }
+ }
+ }
+ else {
+ /* This is a non-bit field. Make sure we are */
+ /* byte aligned first */
+ if (bitOffset) {
+ sum++;
+ loop->offset = (su == UNION ? sum = 0 : sum);
+ bitOffset = 0;
+ }
+ loop->offset = sum;
+ checkDecl (loop, 1);
+ sum += getSize (loop->type);
+ }
+
+ loop = loop->next;
+
+ /* if union then size = sizeof larget field */
+ if (su == UNION) {
+ /* For UNION, round up after each field */
+ sum += ((bitOffset+7)/8);
+ usum = max (usum, sum);
+ }
}
/* For STRUCT, round up after all fields processed */
if (su != UNION)
- sum += ((bitOffset+7)/8);
+ sum += ((bitOffset+7)/8);
return (su == UNION ? usum : sum);
}
{
nextfield = field->next;
if (!*field->name && IS_STRUCT (field->type))
- {
- /* Found an anonymous struct/union. Replace it */
- /* with the fields it contains and adjust all */
- /* the offsets */
-
- base = field->offset;
- subfield = copySymbolChain (SPEC_STRUCT (field->type)->fields);
- if (!subfield)
- continue; /* just in case it's empty */
-
- *tofield = subfield;
- for (;;)
- {
- /* check for field name conflicts resulting from promotion */
- dupfield = sdef->fields;
- while (dupfield && dupfield != subfield)
- {
- if (*subfield->name && !strcmp (dupfield->name, subfield->name))
- {
- werrorfl (subfield->fileDef, subfield->lineDef,
- E_DUPLICATE_MEMBER,
- su==STRUCT ? "struct" : "union",
- subfield->name);
- werrorfl (dupfield->fileDef, dupfield->lineDef,
- E_PREVIOUS_DEF);
- }
- dupfield = dupfield->next;
- }
-
- subfield->offset += base;
- if (subfield->next)
- subfield = subfield->next;
- else
- break;
- }
- subfield->next = nextfield;
- tofield = &subfield->next;
- }
+ {
+ /* Found an anonymous struct/union. Replace it */
+ /* with the fields it contains and adjust all */
+ /* the offsets */
+
+ base = field->offset;
+ subfield = copySymbolChain (SPEC_STRUCT (field->type)->fields);
+ if (!subfield)
+ continue; /* just in case it's empty */
+
+ *tofield = subfield;
+ for (;;)
+ {
+ /* check for field name conflicts resulting from promotion */
+ dupfield = sdef->fields;
+ while (dupfield && dupfield != subfield)
+ {
+ if (*subfield->name && !strcmp (dupfield->name, subfield->name))
+ {
+ werrorfl (subfield->fileDef, subfield->lineDef,
+ E_DUPLICATE_MEMBER,
+ su==STRUCT ? "struct" : "union",
+ subfield->name);
+ werrorfl (dupfield->fileDef, dupfield->lineDef,
+ E_PREVIOUS_DEF);
+ }
+ dupfield = dupfield->next;
+ }
+
+ subfield->offset += base;
+ if (subfield->next)
+ subfield = subfield->next;
+ else
+ break;
+ }
+ subfield->next = nextfield;
+ tofield = &subfield->next;
+ }
else
- tofield = &field->next;
+ tofield = &field->next;
field = nextfield;
}
}
/* if this is an automatic symbol */
if (sym->level && (options.stackAuto || reentrant)) {
if ((SPEC_SCLS (sym->etype) == S_AUTO ||
- SPEC_SCLS (sym->etype) == S_FIXED ||
- SPEC_SCLS (sym->etype) == S_REGISTER ||
- SPEC_SCLS (sym->etype) == S_STACK ||
- SPEC_SCLS (sym->etype) == S_XSTACK)) {
+ SPEC_SCLS (sym->etype) == S_FIXED ||
+ SPEC_SCLS (sym->etype) == S_REGISTER ||
+ SPEC_SCLS (sym->etype) == S_STACK ||
+ SPEC_SCLS (sym->etype) == S_XSTACK)) {
SPEC_SCLS (sym->etype) = S_AUTO;
} else {
/* storage class may only be specified for statics */
if (!IS_STATIC(sym->etype)) {
- werror (E_AUTO_ASSUMED, sym->name);
+ werror (E_AUTO_ASSUMED, sym->name);
}
}
}
/* variables declared in CODE space must have */
/* initializers if not an extern */
if (SPEC_SCLS (sym->etype) == S_CODE &&
- sym->ival == NULL &&
- //!sym->level &&
- port->mem.code_ro &&
- !IS_EXTERN (sym->etype) &&
- !funcInChain (sym->type))
+ sym->ival == NULL &&
+ //!sym->level &&
+ port->mem.code_ro &&
+ !IS_EXTERN (sym->etype) &&
+ !funcInChain (sym->type))
werror (E_CODE_NO_INIT, sym->name);
}
!IS_STATIC(sym->etype))
{
if (options.stackAuto || (currFunc && IFFUNC_ISREENT (currFunc->type)))
- {
- SPEC_SCLS (sym->etype) = (options.useXstack ?
- S_XSTACK : S_STACK);
- }
+ {
+ SPEC_SCLS (sym->etype) = (options.useXstack ?
+ S_XSTACK : S_STACK);
+ }
else
- {
- /* hack-o-matic! I see no reason why the useXstack option should ever
- * control this allcoation, but the code was originally that way, and
- * changing it for non-390 ports breaks the compiler badly.
- */
- bool useXdata = (TARGET_IS_DS390 || TARGET_IS_DS400) ?
- 1 : options.useXstack;
- SPEC_SCLS (sym->etype) = (useXdata ?
- S_XDATA : S_FIXED);
- }
+ {
+ /* hack-o-matic! I see no reason why the useXstack option should ever
+ * control this allcoation, but the code was originally that way, and
+ * changing it for non-390 ports breaks the compiler badly.
+ */
+ bool useXdata = (TARGET_IS_DS390 || TARGET_IS_DS400) ?
+ 1 : options.useXstack;
+ SPEC_SCLS (sym->etype) = (useXdata ?
+ S_XDATA : S_FIXED);
+ }
}
}
for (p = sym->type; p; p = p->next)
{
if (!IS_SPEC (p) && DCL_TYPE (p) == UPOINTER)
- DCL_TYPE (p) = port->unqualified_pointer;
+ DCL_TYPE (p) = port->unqualified_pointer;
if (IS_PTR (p) && IS_FUNC (p->next))
- DCL_TYPE (p) = CPOINTER;
+ DCL_TYPE (p) = CPOINTER;
}
}
checkDecl (symbol * sym, int isProto)
{
- checkSClass (sym, isProto); /* check the storage class */
- changePointer (sym); /* change pointers if required */
+ checkSClass (sym, isProto); /* check the storage class */
+ changePointer (sym); /* change pointers if required */
/* if this is an array without any dimension
then update the dimension from the initial value */
head = loop = (curr ? newLink (p->class) : (void *) NULL);
while (curr)
{
- memcpy (loop, curr, sizeof (sym_link)); /* copy it */
+ memcpy (loop, curr, sizeof (sym_link)); /* copy it */
loop->next = (curr->next ? newLink (curr->next->class) : (void *) NULL);
loop = loop->next;
curr = curr->next;
for (i = 0; i < 256; i++)
{
for (chain = table[i]; chain; chain = chain->next)
- {
- if (chain->block >= block)
- {
- deleteSym (table, chain->sym, chain->name);
- }
- }
+ {
+ if (chain->block >= block)
+ {
+ deleteSym (table, chain->sym, chain->name);
+ }
+ }
}
}
for (i = 0; i < 256; i++)
{
for (chain = table[i]; chain; chain = chain->next)
- {
- if (chain->level >= level)
- {
- deleteSym (table, chain->sym, chain->name);
- }
- }
+ {
+ if (chain->level >= level)
+ {
+ deleteSym (table, chain->sym, chain->name);
+ }
+ }
}
}
if (SPEC_USIGN (etype1))
{
if ( IS_LITERAL (etype2)
- && floatFromVal (valFromType (etype2)) >= 0)
- SPEC_USIGN (reType) = 1;
+ && floatFromVal (valFromType (etype2)) >= 0)
+ SPEC_USIGN (reType) = 1;
else
- {
- /* promote to int */
- SPEC_USIGN (reType) = 0;
- SPEC_NOUN (reType) = V_INT;
- }
+ {
+ /* promote to int */
+ SPEC_USIGN (reType) = 0;
+ SPEC_NOUN (reType) = V_INT;
+ }
}
else /* etype1 signed */
{
if ( IS_LITERAL (etype2)
- && floatFromVal (valFromType (etype2)) <= 127)
- SPEC_USIGN (reType) = 0;
+ && floatFromVal (valFromType (etype2)) <= 127)
+ SPEC_USIGN (reType) = 0;
else
- {
- /* promote to int */
- SPEC_USIGN (reType) = 0;
- SPEC_NOUN (reType) = V_INT;
- }
+ {
+ /* promote to int */
+ SPEC_USIGN (reType) = 0;
+ SPEC_NOUN (reType) = V_INT;
+ }
}
if (SPEC_USIGN (etype2))
{
if ( IS_LITERAL (etype1)
- && floatFromVal (valFromType (etype1)) >= 0)
- SPEC_USIGN (reType) = 1;
+ && floatFromVal (valFromType (etype1)) >= 0)
+ SPEC_USIGN (reType) = 1;
else
- {
- /* promote to int */
- SPEC_USIGN (reType) = 0;
- SPEC_NOUN (reType) = V_INT;
- }
+ {
+ /* promote to int */
+ SPEC_USIGN (reType) = 0;
+ SPEC_NOUN (reType) = V_INT;
+ }
}
else /* etype2 signed */
{
if ( IS_LITERAL (etype1)
- && floatFromVal (valFromType (etype1)) <= 127)
- SPEC_USIGN (reType) = 0;
+ && floatFromVal (valFromType (etype1)) <= 127)
+ SPEC_USIGN (reType) = 0;
else
- {
- /* promote to int */
- SPEC_USIGN (reType) = 0;
- SPEC_NOUN (reType) = V_INT;
- }
+ {
+ /* promote to int */
+ SPEC_USIGN (reType) = 0;
+ SPEC_NOUN (reType) = V_INT;
+ }
}
return reType;
}
if (IS_BITVAR (etype1) && IS_BITVAR (etype2))
{
rType = SPEC_BLEN (etype1) >= SPEC_BLEN (etype2) ?
- copyLinkChain (type1) : copyLinkChain (type1);
+ copyLinkChain (type1) : copyLinkChain (type1);
}
/* if only one of them is a bit variable
then the other one prevails */
switch (resultType)
{
case RESULT_TYPE_CHAR:
- if (IS_BITVAR (reType))
- {
- SPEC_NOUN (reType) = V_CHAR;
- SPEC_SCLS (reType) = 0;
- SPEC_USIGN (reType) = 0;
- return rType;
- }
- break;
+ if (IS_BITVAR (reType))
+ {
+ SPEC_NOUN (reType) = V_CHAR;
+ SPEC_SCLS (reType) = 0;
+ SPEC_USIGN (reType) = 0;
+ return rType;
+ }
+ break;
case RESULT_TYPE_INT:
case RESULT_TYPE_NONE:
case RESULT_TYPE_OTHER:
- if (IS_BIT (reType))
- {
- SPEC_NOUN (reType) = V_CHAR;
- SPEC_SCLS (reType) = 0;
- SPEC_USIGN (reType) = 0;
- return rType;
- }
- else if (IS_BITFIELD (reType))
- {
- /* could be smarter, but it depends on the op */
- /* this is for the worst case: a multiplication of 4 * 4 bit */
- SPEC_NOUN (reType) = SPEC_BLEN (reType) <= 4 ? V_CHAR : V_INT;
- SPEC_SCLS (reType) = 0;
- SPEC_USIGN (reType) = 0;
- return rType;
- }
- else if (IS_CHAR (reType))
- {
- if (op == '|' || op == '^')
- return computeTypeOr (etype1, etype2, reType);
- else if ( op == '&'
- && SPEC_USIGN (etype1) != SPEC_USIGN (etype2))
- {
- SPEC_USIGN (reType) = 1;
- return rType;
- }
- else if (op == '*')
- {
- SPEC_NOUN (reType) = V_INT;
- SPEC_USIGN (reType) = 0;
- return rType;
- }
- /* TODO: should be in SDCCast.c */
- else if ( op == '/'
- && ( !SPEC_USIGN (etype1)
- || !SPEC_USIGN (etype2)))
- {
- SPEC_NOUN (reType) = V_INT;
- SPEC_USIGN (reType) = 0;
- return rType;
- }
- }
- break;
+ if (IS_BIT (reType))
+ {
+ SPEC_NOUN (reType) = V_CHAR;
+ SPEC_SCLS (reType) = 0;
+ SPEC_USIGN (reType) = 0;
+ return rType;
+ }
+ else if (IS_BITFIELD (reType))
+ {
+ /* could be smarter, but it depends on the op */
+ /* this is for the worst case: a multiplication of 4 * 4 bit */
+ SPEC_NOUN (reType) = SPEC_BLEN (reType) <= 4 ? V_CHAR : V_INT;
+ SPEC_SCLS (reType) = 0;
+ SPEC_USIGN (reType) = 0;
+ return rType;
+ }
+ else if (IS_CHAR (reType))
+ {
+ if (op == '|' || op == '^')
+ return computeTypeOr (etype1, etype2, reType);
+ else if ( op == '&'
+ && SPEC_USIGN (etype1) != SPEC_USIGN (etype2))
+ {
+ SPEC_USIGN (reType) = 1;
+ return rType;
+ }
+ else if (op == '*')
+ {
+ SPEC_NOUN (reType) = V_INT;
+ SPEC_USIGN (reType) = 0;
+ return rType;
+ }
+ /* TODO: should be in SDCCast.c */
+ else if ( op == '/'
+ && ( !SPEC_USIGN (etype1)
+ || !SPEC_USIGN (etype2)))
+ {
+ SPEC_NOUN (reType) = V_INT;
+ SPEC_USIGN (reType) = 0;
+ return rType;
+ }
+ }
+ break;
default:
- break;
+ break;
}
/* SDCC's sign promotion:
This seems to be contradictionary to the first two rules, but it makes
real sense (all types are char's):
- A signed char can be negative; this must be preserved in the result
- -1 * 100 = -100;
+ A signed char can be negative; this must be preserved in the result
+ -1 * 100 = -100;
- Only if both operands are unsigned it's safe to make the result
- unsigned; this helps to avoid overflow:
- 2 * 100 = 200;
+ Only if both operands are unsigned it's safe to make the result
+ unsigned; this helps to avoid overflow:
+ 2 * 100 = 200;
- ToDo: document '|', '^' and '&'
Homework: - why is (200 * 200 < 0) true?
- - why is { char l = 200, r = 200; (r * l > 0) } true?
+ - why is { char l = 200, r = 200; (r * l > 0) } true?
*/
if (!IS_FLOAT (reType)
&& ( (SPEC_USIGN (etype1)
/* if this operand is promoted to a larger type,
- then it will be promoted to a signed type */
- && !(getSize (etype1) < getSize (reType))
+ then it will be promoted to a signed type */
+ && !(getSize (etype1) < getSize (reType))
/* char require special handling */
- && !IS_CHAR (etype1))
- || /* same for 2nd operand */
- (SPEC_USIGN (etype2)
- && !(getSize (etype2) < getSize (reType))
- && !IS_CHAR (etype2))
- || /* if both are 'unsigned char' and not promoted
- let the result be unsigned too */
- ( SPEC_USIGN (etype1)
- && SPEC_USIGN (etype2)
- && IS_CHAR (etype1)
- && IS_CHAR (etype2)
- && IS_CHAR (reType))))
+ && !IS_CHAR (etype1))
+ || /* same for 2nd operand */
+ (SPEC_USIGN (etype2)
+ && !(getSize (etype2) < getSize (reType))
+ && !IS_CHAR (etype2))
+ || /* if both are 'unsigned char' and not promoted
+ let the result be unsigned too */
+ ( SPEC_USIGN (etype1)
+ && SPEC_USIGN (etype2)
+ && IS_CHAR (etype1)
+ && IS_CHAR (etype2)
+ && IS_CHAR (reType))))
SPEC_USIGN (reType) = 1;
else
SPEC_USIGN (reType) = 0;
if (IS_DECL (dest))
{
if (IS_DECL (src))
- {
- if (DCL_TYPE (src) == DCL_TYPE (dest)) {
- if (IS_FUNC(src)) {
- //checkFunction(src,dest);
- }
- return compareType (dest->next, src->next);
- }
- if (IS_PTR (dest) && IS_GENPTR (src) && IS_VOID(src->next)) {
- return 1;
- }
- if (IS_PTR (src) && IS_GENPTR (dest))
- return -1;
- if (IS_PTR (dest) && IS_ARRAY (src)) {
- value *val=aggregateToPointer (valFromType(src));
- int res=compareType (dest, val->type);
- Safe_free(val->type);
- Safe_free(val);
- return res;
- }
- if (IS_PTR (dest) && IS_FUNC (dest->next) && IS_FUNC (src))
- return compareType (dest->next, src);
- return 0;
- }
+ {
+ if (DCL_TYPE (src) == DCL_TYPE (dest)) {
+ if (IS_FUNC(src)) {
+ //checkFunction(src,dest);
+ }
+ return compareType (dest->next, src->next);
+ }
+ if (IS_PTR (dest) && IS_GENPTR (src) && IS_VOID(src->next)) {
+ return 1;
+ }
+ if (IS_PTR (src) && IS_GENPTR (dest))
+ return -1;
+ if (IS_PTR (dest) && IS_ARRAY (src)) {
+ value *val=aggregateToPointer (valFromType(src));
+ int res=compareType (dest, val->type);
+ Safe_free(val->type);
+ Safe_free(val);
+ return res;
+ }
+ if (IS_PTR (dest) && IS_FUNC (dest->next) && IS_FUNC (src))
+ return compareType (dest->next, src);
+ return 0;
+ }
else if (IS_PTR (dest) && IS_INTEGRAL (src))
- return -1;
+ return -1;
else
- return 0;
+ return 0;
}
/* if one is a specifier and the other is not */
if (SPEC_NOUN (dest) != SPEC_NOUN (src))
{
if (SPEC_USIGN (dest) == SPEC_USIGN (src) &&
- IS_INTEGRAL (dest) && IS_INTEGRAL (src) &&
- /* I would prefer
- bitsForType (dest) == bitsForType (src))
- instead of the next two lines, but the regression tests fail with
- them; I guess it's a problem with replaceCheaperOp */
- getSize (dest) == getSize (src) &&
- !(!IS_BIT (dest) && IS_BIT (src)))
- return 1;
+ IS_INTEGRAL (dest) && IS_INTEGRAL (src) &&
+ /* I would prefer
+ bitsForType (dest) == bitsForType (src))
+ instead of the next two lines, but the regression tests fail with
+ them; I guess it's a problem with replaceCheaperOp */
+ getSize (dest) == getSize (src) &&
+ !(!IS_BIT (dest) && IS_BIT (src)))
+ return 1;
else if (IS_ARITHMETIC (dest) && IS_ARITHMETIC (src))
- return -1;
+ return -1;
else
- return 0;
+ return 0;
}
else if (IS_STRUCT (dest))
{
if (SPEC_STRUCT (dest) != SPEC_STRUCT (src))
- return 0;
+ return 0;
else
- return 1;
+ return 1;
}
if (SPEC_LONG (dest) != SPEC_LONG (src))
return -1;
if (IS_DECL (dest))
{
if (IS_DECL (src))
- {
- if (DCL_TYPE (src) == DCL_TYPE (dest)) {
- if ((DCL_TYPE (src) == ARRAY) && (DCL_ELEM (src) != DCL_ELEM (dest)))
- return 0;
- if (DCL_PTR_CONST (src) != DCL_PTR_CONST (dest))
- return 0;
- if (DCL_PTR_VOLATILE (src) != DCL_PTR_VOLATILE (dest))
- return 0;
- if (IS_FUNC(src))
+ {
+ if (DCL_TYPE (src) == DCL_TYPE (dest)) {
+ if ((DCL_TYPE (src) == ARRAY) && (DCL_ELEM (src) != DCL_ELEM (dest)))
+ return 0;
+ if (DCL_PTR_CONST (src) != DCL_PTR_CONST (dest))
+ return 0;
+ if (DCL_PTR_VOLATILE (src) != DCL_PTR_VOLATILE (dest))
+ return 0;
+ if (IS_FUNC(src))
{
- value *exargs, *acargs, *checkValue;
+ value *exargs, *acargs, *checkValue;
/* verify function return type */
- if (!compareTypeExact (dest->next, src->next, -1))
- return 0;
- if (FUNC_ISISR (dest) != FUNC_ISISR (src))
- return 0;
- if (FUNC_REGBANK (dest) != FUNC_REGBANK (src))
- return 0;
- if (IFFUNC_ISNAKED (dest) != IFFUNC_ISNAKED (src))
- return 0;
- #if 0
+ if (!compareTypeExact (dest->next, src->next, -1))
+ return 0;
+ if (FUNC_ISISR (dest) != FUNC_ISISR (src))
+ return 0;
+ if (FUNC_REGBANK (dest) != FUNC_REGBANK (src))
+ return 0;
+ if (IFFUNC_ISNAKED (dest) != IFFUNC_ISNAKED (src))
+ return 0;
+ #if 0
if (IFFUNC_ISREENT (dest) != IFFUNC_ISREENT (src) && argCnt>1)
- return 0;
+ return 0;
#endif
- /* compare expected args with actual args */
- exargs = FUNC_ARGS(dest);
- acargs = FUNC_ARGS(src);
+ /* compare expected args with actual args */
+ exargs = FUNC_ARGS(dest);
+ acargs = FUNC_ARGS(src);
- /* for all the expected args do */
- for (; exargs && acargs; exargs = exargs->next, acargs = acargs->next)
- {
- //checkTypeSanity(acargs->etype, acargs->name);
+ /* for all the expected args do */
+ for (; exargs && acargs; exargs = exargs->next, acargs = acargs->next)
+ {
+ //checkTypeSanity(acargs->etype, acargs->name);
- if (IS_AGGREGATE (acargs->type))
- {
- checkValue = copyValue (acargs);
- aggregateToPointer (checkValue);
- }
- else
- checkValue = acargs;
+ if (IS_AGGREGATE (acargs->type))
+ {
+ checkValue = copyValue (acargs);
+ aggregateToPointer (checkValue);
+ }
+ else
+ checkValue = acargs;
#if 0
- if (!compareTypeExact (exargs->type, checkValue->type, -1))
+ if (!compareTypeExact (exargs->type, checkValue->type, -1))
return 0;
#endif
- }
+ }
- /* if one them ended we have a problem */
- if ((exargs && !acargs && !IS_VOID (exargs->type)) ||
- (!exargs && acargs && !IS_VOID (acargs->type)))
- return 0;
+ /* if one them ended we have a problem */
+ if ((exargs && !acargs && !IS_VOID (exargs->type)) ||
+ (!exargs && acargs && !IS_VOID (acargs->type)))
+ return 0;
return 1;
}
- return compareTypeExact (dest->next, src->next, level);
- }
+ return compareTypeExact (dest->next, src->next, level);
+ }
return 0;
- }
+ }
return 0;
}
{
/* signedness must match */
if (SPEC_USIGN (dest) != SPEC_USIGN (src))
- return 0;
+ return 0;
/* size must match */
if (SPEC_LONG (dest) != SPEC_LONG (src))
- return 0;
+ return 0;
if (SPEC_SHORT (dest) != SPEC_SHORT (src))
- return 0;
+ return 0;
}
if (IS_STRUCT (dest))
{
if (SPEC_STRUCT (dest) != SPEC_STRUCT (src))
- return 0;
+ return 0;
}
if (SPEC_CONST (dest) != SPEC_CONST (src))
if (!level & port->mem.code_ro && SPEC_CONST (dest))
{
if (srcScls == S_CODE && destScls == S_FIXED)
- destScls = S_CODE;
+ destScls = S_CODE;
if (destScls == S_CODE && srcScls == S_FIXED)
- srcScls = S_CODE;
+ srcScls = S_CODE;
}
/* compensate for allocGlobal() */
{
/* Compensate for hack-o-matic in checkSClass() */
if (options.stackAuto || (currFunc && IFFUNC_ISREENT (currFunc->type)))
- {
- if (destScls == S_FIXED)
- destScls = (options.useXstack ? S_XSTACK : S_STACK);
- if (srcScls == S_FIXED)
- srcScls = (options.useXstack ? S_XSTACK : S_STACK);
- }
+ {
+ if (destScls == S_FIXED)
+ destScls = (options.useXstack ? S_XSTACK : S_STACK);
+ if (srcScls == S_FIXED)
+ srcScls = (options.useXstack ? S_XSTACK : S_STACK);
+ }
else if (TARGET_IS_DS390 || TARGET_IS_DS400 || options.useXstack)
- {
- if (destScls == S_FIXED)
- destScls = S_XDATA;
- if (srcScls == S_FIXED)
- srcScls = S_XDATA;
- }
+ {
+ if (destScls == S_FIXED)
+ destScls = S_XDATA;
+ if (srcScls == S_FIXED)
+ srcScls = S_XDATA;
+ }
}
if (srcScls != destScls)
#if 0
printf ("level = %d\n", level);
printf ("SPEC_SCLS (src) = %d, SPEC_SCLS (dest) = %d\n",
- SPEC_SCLS (src), SPEC_SCLS (dest));
+ SPEC_SCLS (src), SPEC_SCLS (dest));
printf ("srcScls = %d, destScls = %d\n",srcScls, destScls);
#endif
return 0;
/* if this is a structure */
/* then we need to add a new link */
if (IS_STRUCT (val->type))
- {
- /* first lets add DECLARATOR type */
- sym_link *p = val->type;
+ {
+ /* first lets add DECLARATOR type */
+ sym_link *p = val->type;
- werror (W_STRUCT_AS_ARG, val->name);
- val->type = newLink (DECLARATOR);
- val->type->next = p;
- }
+ werror (W_STRUCT_AS_ARG, val->name);
+ val->type = newLink (DECLARATOR);
+ val->type->next = p;
+ }
/* change to a pointer depending on the */
/* storage class specified */
switch (SPEC_SCLS (val->etype))
- {
- case S_IDATA:
- DCL_TYPE (val->type) = IPOINTER;
- break;
- case S_PDATA:
- DCL_TYPE (val->type) = PPOINTER;
- break;
- case S_FIXED:
- if (SPEC_OCLS(val->etype)) {
- DCL_TYPE(val->type)=PTR_TYPE(SPEC_OCLS(val->etype));
- } else {
- // this happens for (external) function parameters
- DCL_TYPE (val->type) = port->unqualified_pointer;
- }
- break;
- case S_AUTO:
- case S_DATA:
- case S_REGISTER:
- DCL_TYPE (val->type) = POINTER;
- break;
- case S_CODE:
- DCL_TYPE (val->type) = CPOINTER;
- break;
- case S_XDATA:
- DCL_TYPE (val->type) = FPOINTER;
- break;
- case S_EEPROM:
- DCL_TYPE (val->type) = EEPPOINTER;
- break;
- default:
- DCL_TYPE (val->type) = port->unqualified_pointer;
- }
+ {
+ case S_IDATA:
+ DCL_TYPE (val->type) = IPOINTER;
+ break;
+ case S_PDATA:
+ DCL_TYPE (val->type) = PPOINTER;
+ break;
+ case S_FIXED:
+ if (SPEC_OCLS(val->etype)) {
+ DCL_TYPE(val->type)=PTR_TYPE(SPEC_OCLS(val->etype));
+ } else {
+ // this happens for (external) function parameters
+ DCL_TYPE (val->type) = port->unqualified_pointer;
+ }
+ break;
+ case S_AUTO:
+ case S_DATA:
+ case S_REGISTER:
+ DCL_TYPE (val->type) = POINTER;
+ break;
+ case S_CODE:
+ DCL_TYPE (val->type) = CPOINTER;
+ break;
+ case S_XDATA:
+ DCL_TYPE (val->type) = FPOINTER;
+ break;
+ case S_EEPROM:
+ DCL_TYPE (val->type) = EEPPOINTER;
+ break;
+ default:
+ DCL_TYPE (val->type) = port->unqualified_pointer;
+ }
/* is there is a symbol associated then */
/* change the type of the symbol as well */
if (val->sym)
- {
- val->sym->type = copyLinkChain (val->type);
- val->sym->etype = getSpec (val->sym->type);
- }
+ {
+ val->sym->type = copyLinkChain (val->type);
+ val->sym->etype = getSpec (val->sym->type);
+ }
}
return val;
}
if (IFFUNC_ARGS(sym->type) && FUNC_ISISR (sym->type))
{
if (!IS_VOID(FUNC_ARGS(sym->type)->type)) {
- werror (E_INT_ARGS, sym->name);
- FUNC_ARGS(sym->type)=NULL;
+ werror (E_INT_ARGS, sym->name);
+ FUNC_ARGS(sym->type)=NULL;
}
}
argCnt--;
if (!csym && !(csym = findSym (SymbolTab, sym, sym->name)))
- return 1; /* not defined nothing more to check */
+ return 1; /* not defined nothing more to check */
/* check if body already present */
if (csym && IFFUNC_HASBODY(csym->type))
exargs = exargs->next, acargs = acargs->next, argCnt++)
{
if (getenv("DEBUG_SANITY")) {
- fprintf (stderr, "checkFunction: %s ", exargs->name);
+ fprintf (stderr, "checkFunction: %s ", exargs->name);
}
/* make sure the type is complete and sane */
checkTypeSanity(exargs->etype, exargs->name);
* change here.
*/
if (IS_AGGREGATE (acargs->type))
- {
- checkValue = copyValue (acargs);
- aggregateToPointer (checkValue);
- }
+ {
+ checkValue = copyValue (acargs);
+ aggregateToPointer (checkValue);
+ }
else
- {
- checkValue = acargs;
- }
+ {
+ checkValue = acargs;
+ }
if (compareType (exargs->type, checkValue->type) <= 0)
- {
- werror (E_ARG_TYPE, argCnt);
- printFromToType(exargs->type, checkValue->type);
- return 0;
- }
+ {
+ werror (E_ARG_TYPE, argCnt);
+ printFromToType(exargs->type, checkValue->type);
+ return 0;
+ }
}
/* if one them ended we have a problem */
for (i = 0; i < 256; i++)
{
for (chain = table[i]; chain; chain = chain->next)
- {
- if (chain->block >= block)
- {
- if(debugFile)
- debugFile->writeType((structdef *)chain->sym, chain->block, 0, NULL);
- }
- }
+ {
+ if (chain->block >= block)
+ {
+ if(debugFile)
+ debugFile->writeType((structdef *)chain->sym, chain->block, 0, NULL);
+ }
+ }
}
}
/* change it to pointer to the same type */
while (val)
{
- int argreg = 0;
+ int argreg = 0;
/* mark it as a register parameter if
the function does not have VA_ARG
and as port dictates */
if (!IFFUNC_HASVARARGS(funcType) &&
- (argreg = (*port->reg_parm) (val->type)))
- {
- SPEC_REGPARM (val->etype) = 1;
- SPEC_ARGREG(val->etype) = argreg;
- } else if (IFFUNC_ISREENT(funcType)) {
- FUNC_HASSTACKPARM(funcType) = 1;
- }
+ (argreg = (*port->reg_parm) (val->type)))
+ {
+ SPEC_REGPARM (val->etype) = 1;
+ SPEC_ARGREG(val->etype) = argreg;
+ } else if (IFFUNC_ISREENT(funcType)) {
+ FUNC_HASSTACKPARM(funcType) = 1;
+ }
if (IS_AGGREGATE (val->type))
- {
- aggregateToPointer (val);
- }
+ {
+ aggregateToPointer (val);
+ }
val = val->next;
pNum++;
/* if a symbolname is not given */
/* synthesize a variable name */
if (!val->sym)
- {
- SNPRINTF (val->name, sizeof(val->name),
- "_%s_PARM_%d", func->name, pNum++);
- val->sym = newSymbol (val->name, 1);
- SPEC_OCLS (val->etype) = port->mem.default_local_map;
- val->sym->type = copyLinkChain (val->type);
- val->sym->etype = getSpec (val->sym->type);
- val->sym->_isparm = 1;
- strncpyz (val->sym->rname, val->name, sizeof(val->sym->rname));
- #if 0
- /* ?? static functions shouldn't imply static parameters - EEP */
- if (IS_SPEC(func->etype)) {
- SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
- SPEC_STAT (func->etype);
- }
- #endif
- addSymChain (val->sym);
-
- }
- else /* symbol name given create synth name */
- {
-
- SNPRINTF (val->name, sizeof(val->name), "_%s_PARM_%d", func->name, pNum++);
- strncpyz (val->sym->rname, val->name, sizeof(val->sym->rname));
- val->sym->_isparm = 1;
- SPEC_OCLS (val->etype) = SPEC_OCLS (val->sym->etype) =
- (options.model != MODEL_SMALL ? xdata : data);
-
- #if 0
- /* ?? static functions shouldn't imply static parameters - EEP */
- if (IS_SPEC(func->etype)) {
- SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
- SPEC_STAT (func->etype);
- }
- #endif
- }
+ {
+ SNPRINTF (val->name, sizeof(val->name),
+ "_%s_PARM_%d", func->name, pNum++);
+ val->sym = newSymbol (val->name, 1);
+ SPEC_OCLS (val->etype) = port->mem.default_local_map;
+ val->sym->type = copyLinkChain (val->type);
+ val->sym->etype = getSpec (val->sym->type);
+ val->sym->_isparm = 1;
+ strncpyz (val->sym->rname, val->name, sizeof(val->sym->rname));
+ #if 0
+ /* ?? static functions shouldn't imply static parameters - EEP */
+ if (IS_SPEC(func->etype)) {
+ SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
+ SPEC_STAT (func->etype);
+ }
+ #endif
+ addSymChain (val->sym);
+
+ }
+ else /* symbol name given create synth name */
+ {
+
+ SNPRINTF (val->name, sizeof(val->name), "_%s_PARM_%d", func->name, pNum++);
+ strncpyz (val->sym->rname, val->name, sizeof(val->sym->rname));
+ val->sym->_isparm = 1;
+ SPEC_OCLS (val->etype) = SPEC_OCLS (val->sym->etype) =
+ (options.model != MODEL_SMALL ? xdata : data);
+
+ #if 0
+ /* ?? static functions shouldn't imply static parameters - EEP */
+ if (IS_SPEC(func->etype)) {
+ SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
+ SPEC_STAT (func->etype);
+ }
+ #endif
+ }
if (!isinSet(operKeyReset, val->sym)) {
- addSet (&operKeyReset, val->sym);
- applyToSet (operKeyReset, resetParmKey);
+ addSet (&operKeyReset, val->sym);
+ applyToSet (operKeyReset, resetParmKey);
}
val = val->next;
}
void PT(sym_link *type)
{
- printTypeChain(type,0);
+ printTypeChain(type,0);
}
/*-----------------------------------------------------------------*/
/* printTypeChain - prints the type chain in human readable form */
while (type)
{
if (type==start) {
- switch (scls)
- {
- case S_DATA: fprintf (of, "data-"); break;
- case S_XDATA: fprintf (of, "xdata-"); break;
- case S_SFR: fprintf (of, "sfr-"); break;
- case S_SBIT: fprintf (of, "sbit-"); break;
- case S_CODE: fprintf (of, "code-"); break;
- case S_IDATA: fprintf (of, "idata-"); break;
- case S_PDATA: fprintf (of, "pdata-"); break;
- case S_LITERAL: fprintf (of, "literal-"); break;
- case S_STACK: fprintf (of, "stack-"); break;
- case S_XSTACK: fprintf (of, "xstack-"); break;
- case S_BIT: fprintf (of, "bit-"); break;
- case S_EEPROM: fprintf (of, "eeprom-"); break;
- default: break;
- }
+ switch (scls)
+ {
+ case S_DATA: fprintf (of, "data-"); break;
+ case S_XDATA: fprintf (of, "xdata-"); break;
+ case S_SFR: fprintf (of, "sfr-"); break;
+ case S_SBIT: fprintf (of, "sbit-"); break;
+ case S_CODE: fprintf (of, "code-"); break;
+ case S_IDATA: fprintf (of, "idata-"); break;
+ case S_PDATA: fprintf (of, "pdata-"); break;
+ case S_LITERAL: fprintf (of, "literal-"); break;
+ case S_STACK: fprintf (of, "stack-"); break;
+ case S_XSTACK: fprintf (of, "xstack-"); break;
+ case S_BIT: fprintf (of, "bit-"); break;
+ case S_EEPROM: fprintf (of, "eeprom-"); break;
+ default: break;
+ }
}
if (IS_DECL (type))
- {
- if (!IS_FUNC(type)) {
- if (DCL_PTR_VOLATILE (type)) {
- fprintf (of, "volatile-");
- }
- if (DCL_PTR_CONST (type)) {
- fprintf (of, "const-");
- }
- }
- switch (DCL_TYPE (type))
- {
- case FUNCTION:
- fprintf (of, "function %s %s",
- (IFFUNC_ISBUILTIN(type) ? "__builtin__" : " "),
- (IFFUNC_ISJAVANATIVE(type) ? "_JavaNative" : " "));
- fprintf (of, "( ");
- for (args = FUNC_ARGS(type);
- args;
- args=args->next) {
- printTypeChain(args->type, of);
- if (args->next)
- fprintf(of, ", ");
- }
- fprintf (of, ") ");
- break;
- case GPOINTER:
- fprintf (of, "generic* ");
- break;
- case CPOINTER:
- fprintf (of, "code* ");
- break;
- case FPOINTER:
- fprintf (of, "xdata* ");
- break;
- case EEPPOINTER:
- fprintf (of, "eeprom* ");
- break;
- case POINTER:
- fprintf (of, "near* ");
- break;
- case IPOINTER:
- fprintf (of, "idata* ");
- break;
- case PPOINTER:
- fprintf (of, "pdata* ");
- break;
- case UPOINTER:
- fprintf (of, "unknown* ");
- break;
- case ARRAY:
- if (DCL_ELEM(type)) {
- fprintf (of, "[%d] ", DCL_ELEM(type));
- } else {
- fprintf (of, "[] ");
- }
- break;
- }
- }
+ {
+ if (!IS_FUNC(type)) {
+ if (DCL_PTR_VOLATILE (type)) {
+ fprintf (of, "volatile-");
+ }
+ if (DCL_PTR_CONST (type)) {
+ fprintf (of, "const-");
+ }
+ }
+ switch (DCL_TYPE (type))
+ {
+ case FUNCTION:
+ fprintf (of, "function %s %s",
+ (IFFUNC_ISBUILTIN(type) ? "__builtin__" : " "),
+ (IFFUNC_ISJAVANATIVE(type) ? "_JavaNative" : " "));
+ fprintf (of, "( ");
+ for (args = FUNC_ARGS(type);
+ args;
+ args=args->next) {
+ printTypeChain(args->type, of);
+ if (args->next)
+ fprintf(of, ", ");
+ }
+ fprintf (of, ") ");
+ break;
+ case GPOINTER:
+ fprintf (of, "generic* ");
+ break;
+ case CPOINTER:
+ fprintf (of, "code* ");
+ break;
+ case FPOINTER:
+ fprintf (of, "xdata* ");
+ break;
+ case EEPPOINTER:
+ fprintf (of, "eeprom* ");
+ break;
+ case POINTER:
+ fprintf (of, "near* ");
+ break;
+ case IPOINTER:
+ fprintf (of, "idata* ");
+ break;
+ case PPOINTER:
+ fprintf (of, "pdata* ");
+ break;
+ case UPOINTER:
+ fprintf (of, "unknown* ");
+ break;
+ case ARRAY:
+ if (DCL_ELEM(type)) {
+ fprintf (of, "[%d] ", DCL_ELEM(type));
+ } else {
+ fprintf (of, "[] ");
+ }
+ break;
+ }
+ }
else
- {
- if (SPEC_VOLATILE (type))
- fprintf (of, "volatile-");
- if (SPEC_CONST (type))
- fprintf (of, "const-");
- if (SPEC_USIGN (type))
- fprintf (of, "unsigned-");
- switch (SPEC_NOUN (type))
- {
- case V_INT:
- if (IS_LONG (type))
- fprintf (of, "long-");
- fprintf (of, "int");
- break;
-
- case V_CHAR:
- fprintf (of, "char");
- break;
-
- case V_VOID:
- fprintf (of, "void");
- break;
-
- case V_FLOAT:
- fprintf (of, "float");
- break;
-
- case V_STRUCT:
- fprintf (of, "struct %s", SPEC_STRUCT (type)->tag);
- break;
-
- case V_SBIT:
- fprintf (of, "sbit");
- break;
-
- case V_BIT:
- fprintf (of, "bit");
- break;
-
- case V_BITFIELD:
- fprintf (of, "bitfield {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type));
- break;
-
- case V_DOUBLE:
- fprintf (of, "double");
- break;
-
- default:
- fprintf (of, "unknown type");
- break;
- }
- }
+ {
+ if (SPEC_VOLATILE (type))
+ fprintf (of, "volatile-");
+ if (SPEC_CONST (type))
+ fprintf (of, "const-");
+ if (SPEC_USIGN (type))
+ fprintf (of, "unsigned-");
+ switch (SPEC_NOUN (type))
+ {
+ case V_INT:
+ if (IS_LONG (type))
+ fprintf (of, "long-");
+ fprintf (of, "int");
+ break;
+
+ case V_CHAR:
+ fprintf (of, "char");
+ break;
+
+ case V_VOID:
+ fprintf (of, "void");
+ break;
+
+ case V_FLOAT:
+ fprintf (of, "float");
+ break;
+
+ case V_STRUCT:
+ fprintf (of, "struct %s", SPEC_STRUCT (type)->tag);
+ break;
+
+ case V_SBIT:
+ fprintf (of, "sbit");
+ break;
+
+ case V_BIT:
+ fprintf (of, "bit");
+ break;
+
+ case V_BITFIELD:
+ fprintf (of, "bitfield {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type));
+ break;
+
+ case V_DOUBLE:
+ fprintf (of, "double");
+ break;
+
+ default:
+ fprintf (of, "unknown type");
+ break;
+ }
+ }
/* search entry in list before "type" */
for (search = start; search && search->next != type;)
- search = search->next;
+ search = search->next;
type = search;
if (type)
- fputc (' ', of);
+ fputc (' ', of);
}
if (nlr)
fprintf (of, "\n");
while (type)
{
if (IS_DECL (type))
- {
- if (!IS_FUNC(type)) {
- if (DCL_PTR_VOLATILE (type)) {
- fprintf (of, "volatile-");
- }
- if (DCL_PTR_CONST (type)) {
- fprintf (of, "const-");
- }
- }
- switch (DCL_TYPE (type))
- {
- case FUNCTION:
- fprintf (of, "function %s %s",
- (IFFUNC_ISBUILTIN(type) ? "__builtin__" : " "),
- (IFFUNC_ISJAVANATIVE(type) ? "_JavaNative" : " "));
- fprintf (of, "( ");
- for (args = FUNC_ARGS(type);
- args;
- args=args->next) {
- printTypeChain(args->type, of);
- if (args->next)
- fprintf(of, ", ");
- }
- fprintf (of, ") ");
- break;
- case GPOINTER:
- fprintf (of, "generic* ");
- break;
- case CPOINTER:
- fprintf (of, "code* ");
- break;
- case FPOINTER:
- fprintf (of, "xdata* ");
- break;
- case EEPPOINTER:
- fprintf (of, "eeprom* ");
- break;
- case POINTER:
- fprintf (of, "near* ");
- break;
- case IPOINTER:
- fprintf (of, "idata* ");
- break;
- case PPOINTER:
- fprintf (of, "pdata* ");
- break;
- case UPOINTER:
- fprintf (of, "unknown* ");
- break;
- case ARRAY:
- if (DCL_ELEM(type)) {
- fprintf (of, "[%d] ", DCL_ELEM(type));
- } else {
- fprintf (of, "[] ");
- }
- break;
- }
+ {
+ if (!IS_FUNC(type)) {
+ if (DCL_PTR_VOLATILE (type)) {
+ fprintf (of, "volatile-");
+ }
+ if (DCL_PTR_CONST (type)) {
+ fprintf (of, "const-");
+ }
+ }
+ switch (DCL_TYPE (type))
+ {
+ case FUNCTION:
+ fprintf (of, "function %s %s",
+ (IFFUNC_ISBUILTIN(type) ? "__builtin__" : " "),
+ (IFFUNC_ISJAVANATIVE(type) ? "_JavaNative" : " "));
+ fprintf (of, "( ");
+ for (args = FUNC_ARGS(type);
+ args;
+ args=args->next) {
+ printTypeChain(args->type, of);
+ if (args->next)
+ fprintf(of, ", ");
+ }
+ fprintf (of, ") ");
+ break;
+ case GPOINTER:
+ fprintf (of, "generic* ");
+ break;
+ case CPOINTER:
+ fprintf (of, "code* ");
+ break;
+ case FPOINTER:
+ fprintf (of, "xdata* ");
+ break;
+ case EEPPOINTER:
+ fprintf (of, "eeprom* ");
+ break;
+ case POINTER:
+ fprintf (of, "near* ");
+ break;
+ case IPOINTER:
+ fprintf (of, "idata* ");
+ break;
+ case PPOINTER:
+ fprintf (of, "pdata* ");
+ break;
+ case UPOINTER:
+ fprintf (of, "unknown* ");
+ break;
+ case ARRAY:
+ if (DCL_ELEM(type)) {
+ fprintf (of, "[%d] ", DCL_ELEM(type));
+ } else {
+ fprintf (of, "[] ");
+ }
+ break;
+ }
if (DCL_TSPEC(type))
{
fprintf (of, "{");
printTypeChainRaw(DCL_TSPEC(type), of);
fprintf (of, "}");
}
- }
+ }
else if (IS_SPEC (type))
- {
- switch (SPEC_SCLS (type))
- {
- case S_DATA: fprintf (of, "data-"); break;
- case S_XDATA: fprintf (of, "xdata-"); break;
- case S_SFR: fprintf (of, "sfr-"); break;
- case S_SBIT: fprintf (of, "sbit-"); break;
- case S_CODE: fprintf (of, "code-"); break;
- case S_IDATA: fprintf (of, "idata-"); break;
- case S_PDATA: fprintf (of, "pdata-"); break;
- case S_LITERAL: fprintf (of, "literal-"); break;
- case S_STACK: fprintf (of, "stack-"); break;
- case S_XSTACK: fprintf (of, "xstack-"); break;
- case S_BIT: fprintf (of, "bit-"); break;
- case S_EEPROM: fprintf (of, "eeprom-"); break;
- default: break;
- }
- if (SPEC_VOLATILE (type))
- fprintf (of, "volatile-");
- if (SPEC_CONST (type))
- fprintf (of, "const-");
- if (SPEC_USIGN (type))
- fprintf (of, "unsigned-");
- switch (SPEC_NOUN (type))
- {
- case V_INT:
- if (IS_LONG (type))
- fprintf (of, "long-");
- fprintf (of, "int");
- break;
-
- case V_CHAR:
- fprintf (of, "char");
- break;
-
- case V_VOID:
- fprintf (of, "void");
- break;
-
- case V_FLOAT:
- fprintf (of, "float");
- break;
-
- case V_STRUCT:
- fprintf (of, "struct %s", SPEC_STRUCT (type)->tag);
- break;
-
- case V_SBIT:
- fprintf (of, "sbit");
- break;
-
- case V_BIT:
- fprintf (of, "bit");
- break;
-
- case V_BITFIELD:
- fprintf (of, "bitfield {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type));
- break;
-
- case V_DOUBLE:
- fprintf (of, "double");
- break;
-
- default:
- fprintf (of, "unknown type");
- break;
- }
- }
+ {
+ switch (SPEC_SCLS (type))
+ {
+ case S_DATA: fprintf (of, "data-"); break;
+ case S_XDATA: fprintf (of, "xdata-"); break;
+ case S_SFR: fprintf (of, "sfr-"); break;
+ case S_SBIT: fprintf (of, "sbit-"); break;
+ case S_CODE: fprintf (of, "code-"); break;
+ case S_IDATA: fprintf (of, "idata-"); break;
+ case S_PDATA: fprintf (of, "pdata-"); break;
+ case S_LITERAL: fprintf (of, "literal-"); break;
+ case S_STACK: fprintf (of, "stack-"); break;
+ case S_XSTACK: fprintf (of, "xstack-"); break;
+ case S_BIT: fprintf (of, "bit-"); break;
+ case S_EEPROM: fprintf (of, "eeprom-"); break;
+ default: break;
+ }
+ if (SPEC_VOLATILE (type))
+ fprintf (of, "volatile-");
+ if (SPEC_CONST (type))
+ fprintf (of, "const-");
+ if (SPEC_USIGN (type))
+ fprintf (of, "unsigned-");
+ switch (SPEC_NOUN (type))
+ {
+ case V_INT:
+ if (IS_LONG (type))
+ fprintf (of, "long-");
+ fprintf (of, "int");
+ break;
+
+ case V_CHAR:
+ fprintf (of, "char");
+ break;
+
+ case V_VOID:
+ fprintf (of, "void");
+ break;
+
+ case V_FLOAT:
+ fprintf (of, "float");
+ break;
+
+ case V_STRUCT:
+ fprintf (of, "struct %s", SPEC_STRUCT (type)->tag);
+ break;
+
+ case V_SBIT:
+ fprintf (of, "sbit");
+ break;
+
+ case V_BIT:
+ fprintf (of, "bit");
+ break;
+
+ case V_BITFIELD:
+ fprintf (of, "bitfield {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type));
+ break;
+
+ case V_DOUBLE:
+ fprintf (of, "double");
+ break;
+
+ default:
+ fprintf (of, "unknown type");
+ break;
+ }
+ }
else
fprintf (of, "NOT_SPEC_OR_DECL");
type = type->next;
if (type)
- fputc (' ', of);
+ fputc (' ', of);
}
if (nlr)
fprintf (of, "\n");
while (num)
{
if (num & 1)
- n1s++;
+ n1s++;
num >>= 1;
nshifts++;
}
/*-----------------------------------------------------------------*/
/* typeFromStr - create a typechain from an encoded string */
-/* basic types - 'c' - char */
-/* 's' - short */
-/* 'i' - int */
-/* 'l' - long */
-/* 'f' - float */
-/* 'v' - void */
-/* '*' - pointer - default (GPOINTER) */
+/* basic types - 'c' - char */
+/* 's' - short */
+/* 'i' - int */
+/* 'l' - long */
+/* 'f' - float */
+/* 'v' - void */
+/* '*' - pointer - default (GPOINTER) */
/* modifiers - 'u' - unsigned */
/* pointer modifiers - 'g' - generic */
/* 'x' - xdata */
/* 'p' - code */
/* 'd' - data */
/* 'F' - function */
-/* examples : "ig*" - generic int * */
+/* examples : "ig*" - generic int * */
/* "cx*" - char xdata * */
/* "ui" - unsigned int */
/*-----------------------------------------------------------------*/
int usign = 0;
do {
- sym_link *nr;
- switch (*s) {
- case 'u' :
- usign = 1;
- s++;
- continue ;
- break ;
- case 'c':
- r->class = SPECIFIER;
- SPEC_NOUN(r) = V_CHAR;
- break;
- case 's':
- case 'i':
- r->class = SPECIFIER;
- SPEC_NOUN(r) = V_INT;
- break;
- case 'l':
- r->class = SPECIFIER;
- SPEC_NOUN(r) = V_INT;
- SPEC_LONG(r) = 1;
- break;
- case 'f':
- r->class = SPECIFIER;
- SPEC_NOUN(r) = V_FLOAT;
- break;
- case 'v':
- r->class = SPECIFIER;
- SPEC_NOUN(r) = V_VOID;
- break;
- case '*':
- DCL_TYPE(r) = port->unqualified_pointer;
- break;
- case 'g':
- case 'x':
- case 'p':
- case 'd':
- case 'F':
- assert(*(s+1)=='*');
- nr = newLink(DECLARATOR);
- nr->next = r;
- r = nr;
- switch (*s) {
- case 'g':
- DCL_TYPE(r) = GPOINTER;
- break;
- case 'x':
- DCL_TYPE(r) = FPOINTER;
- break;
- case 'p':
- DCL_TYPE(r) = CPOINTER;
- break;
- case 'd':
- DCL_TYPE(r) = POINTER;
- break;
- case 'F':
- DCL_TYPE(r) = FUNCTION;
- nr = newLink(DECLARATOR);
- nr->next = r;
- r = nr;
- DCL_TYPE(r) = CPOINTER;
- break;
- }
- s++;
- break;
- default:
- werror(E_INTERNAL_ERROR, __FILE__, __LINE__,
- "typeFromStr: unknown type");
- break;
- }
- if (IS_SPEC(r) && usign) {
- SPEC_USIGN(r) = 1;
- usign = 0;
- }
- s++;
+ sym_link *nr;
+ switch (*s) {
+ case 'u' :
+ usign = 1;
+ s++;
+ continue ;
+ break ;
+ case 'c':
+ r->class = SPECIFIER;
+ SPEC_NOUN(r) = V_CHAR;
+ break;
+ case 's':
+ case 'i':
+ r->class = SPECIFIER;
+ SPEC_NOUN(r) = V_INT;
+ break;
+ case 'l':
+ r->class = SPECIFIER;
+ SPEC_NOUN(r) = V_INT;
+ SPEC_LONG(r) = 1;
+ break;
+ case 'f':
+ r->class = SPECIFIER;
+ SPEC_NOUN(r) = V_FLOAT;
+ break;
+ case 'v':
+ r->class = SPECIFIER;
+ SPEC_NOUN(r) = V_VOID;
+ break;
+ case '*':
+ DCL_TYPE(r) = port->unqualified_pointer;
+ break;
+ case 'g':
+ case 'x':
+ case 'p':
+ case 'd':
+ case 'F':
+ assert(*(s+1)=='*');
+ nr = newLink(DECLARATOR);
+ nr->next = r;
+ r = nr;
+ switch (*s) {
+ case 'g':
+ DCL_TYPE(r) = GPOINTER;
+ break;
+ case 'x':
+ DCL_TYPE(r) = FPOINTER;
+ break;
+ case 'p':
+ DCL_TYPE(r) = CPOINTER;
+ break;
+ case 'd':
+ DCL_TYPE(r) = POINTER;
+ break;
+ case 'F':
+ DCL_TYPE(r) = FUNCTION;
+ nr = newLink(DECLARATOR);
+ nr->next = r;
+ r = nr;
+ DCL_TYPE(r) = CPOINTER;
+ break;
+ }
+ s++;
+ break;
+ default:
+ werror(E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "typeFromStr: unknown type");
+ break;
+ }
+ if (IS_SPEC(r) && usign) {
+ SPEC_USIGN(r) = 1;
+ usign = 0;
+ }
+ s++;
} while (*s);
return r;
}
{
sym_link *l = NULL;
switch (bwd)
- {
- case 0:
- l = newCharLink ();
- break;
- case 1:
- l = newIntLink ();
- break;
- case 2:
- l = newLongLink ();
- break;
- default:
- assert (0);
- }
+ {
+ case 0:
+ l = newCharLink ();
+ break;
+ case 1:
+ l = newIntLink ();
+ break;
+ case 2:
+ l = newLongLink ();
+ break;
+ default:
+ assert (0);
+ }
__multypes[bwd][0] = l;
__multypes[bwd][1] = copyLinkChain (l);
SPEC_USIGN (__multypes[bwd][1]) = 1;
for (tofrom = 0; tofrom < 2; tofrom++)
{
for (bwd = 0; bwd < 3; bwd++)
- {
- for (su = 0; su < 2; su++)
- {
- if (tofrom)
- {
- SNPRINTF (buffer, sizeof(buffer), "__fs2%s%s", ssu[su], sbwd[bwd]);
- __conv[tofrom][bwd][su] = funcOfType (buffer, __multypes[bwd][su], floatType, 1, options.float_rent);
- }
- else
- {
- SNPRINTF (buffer, sizeof(buffer), "__%s%s2fs", ssu[su], sbwd[bwd]);
- __conv[tofrom][bwd][su] = funcOfType (buffer, floatType, __multypes[bwd][su], 1, options.float_rent);
- }
- }
- }
+ {
+ for (su = 0; su < 2; su++)
+ {
+ if (tofrom)
+ {
+ SNPRINTF (buffer, sizeof(buffer), "__fs2%s%s", ssu[su], sbwd[bwd]);
+ __conv[tofrom][bwd][su] = funcOfType (buffer, __multypes[bwd][su], floatType, 1, options.float_rent);
+ }
+ else
+ {
+ SNPRINTF (buffer, sizeof(buffer), "__%s%s2fs", ssu[su], sbwd[bwd]);
+ __conv[tofrom][bwd][su] = funcOfType (buffer, floatType, __multypes[bwd][su], 1, options.float_rent);
+ }
+ }
+ }
}
/*
for (muldivmod = 0; muldivmod < 3; muldivmod++)
{
for (bwd = 0; bwd < 3; bwd++)
- {
- for (su = 0; su < 2; su++)
- {
- SNPRINTF (buffer, sizeof(buffer),
- "_%s%s%s",
- smuldivmod[muldivmod],
- ssu[su],
- sbwd[bwd]);
+ {
+ for (su = 0; su < 2; su++)
+ {
+ SNPRINTF (buffer, sizeof(buffer),
+ "_%s%s%s",
+ smuldivmod[muldivmod],
+ ssu[su],
+ sbwd[bwd]);
__muldiv[muldivmod][bwd][su] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
- FUNC_NONBANKED (__muldiv[muldivmod][bwd][su]->type) = 1;
- }
- }
+ FUNC_NONBANKED (__muldiv[muldivmod][bwd][su]->type) = 1;
+ }
+ }
}
muluint() and mulsint() resp. mululong() and mulslong() return the same result.
for (bwd = 0; bwd < 3; bwd++)
{
for (su = 0; su < 2; su++)
- {
- for (muldivmod = 1; muldivmod < 3; muldivmod++)
- {
- /* div and mod */
- SNPRINTF (buffer, sizeof(buffer),
- "_%s%s%s",
- smuldivmod[muldivmod],
- ssu[su],
- sbwd[bwd]);
- __muldiv[muldivmod][bwd][su] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
- FUNC_NONBANKED (__muldiv[muldivmod][bwd][su]->type) = 1;
- }
- }
+ {
+ for (muldivmod = 1; muldivmod < 3; muldivmod++)
+ {
+ /* div and mod */
+ SNPRINTF (buffer, sizeof(buffer),
+ "_%s%s%s",
+ smuldivmod[muldivmod],
+ ssu[su],
+ sbwd[bwd]);
+ __muldiv[muldivmod][bwd][su] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
+ FUNC_NONBANKED (__muldiv[muldivmod][bwd][su]->type) = 1;
+ }
+ }
}
/* mul only */
muldivmod = 0;
/* muluchar and mulschar are still separate functions, because e.g. the z80
port is sign/zero-extending to int before calling mulint() */
SNPRINTF (buffer, sizeof(buffer),
- "_%s%s%s",
- smuldivmod[muldivmod],
- ssu[su],
- sbwd[bwd]);
+ "_%s%s%s",
+ smuldivmod[muldivmod],
+ ssu[su],
+ sbwd[bwd]);
__muldiv[muldivmod][bwd][su] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
FUNC_NONBANKED (__muldiv[muldivmod][bwd][su]->type) = 1;
}
{
/* mul, int/long */
SNPRINTF (buffer, sizeof(buffer),
- "_%s%s",
- smuldivmod[muldivmod],
- sbwd[bwd]);
+ "_%s%s",
+ smuldivmod[muldivmod],
+ sbwd[bwd]);
__muldiv[muldivmod][bwd][0] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
FUNC_NONBANKED (__muldiv[muldivmod][bwd][0]->type) = 1;
/* signed = unsigned */
for (rlrr = 0; rlrr < 2; rlrr++)
{
for (bwd = 0; bwd < 3; bwd++)
- {
- for (su = 0; su < 2; su++)
- {
- SNPRINTF (buffer, sizeof(buffer),
- "_%s%s%s",
- srlrr[rlrr],
- ssu[su],
- sbwd[bwd]);
+ {
+ for (su = 0; su < 2; su++)
+ {
+ SNPRINTF (buffer, sizeof(buffer),
+ "_%s%s%s",
+ srlrr[rlrr],
+ ssu[su],
+ sbwd[bwd]);
__rlrr[rlrr][bwd][su] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[0][0], 2, options.intlong_rent);
- FUNC_NONBANKED (__rlrr[rlrr][bwd][su]->type) = 1;
- }
- }
+ FUNC_NONBANKED (__rlrr[rlrr][bwd][su]->type) = 1;
+ }
+ }
}
}
if (!port->builtintable) return ;
for (i = 0 ; port->builtintable[i].name ; i++) {
- sym = funcOfTypeVarg(port->builtintable[i].name,port->builtintable[i].rtype,
- port->builtintable[i].nParms,port->builtintable[i].parm_types);
- FUNC_ISBUILTIN(sym->type) = 1;
- FUNC_ISREENT(sym->type) = 0; /* can never be reentrant */
+ sym = funcOfTypeVarg(port->builtintable[i].name,port->builtintable[i].rtype,
+ port->builtintable[i].nParms,port->builtintable[i].parm_types);
+ FUNC_ISBUILTIN(sym->type) = 1;
+ FUNC_ISREENT(sym->type) = 0; /* can never be reentrant */
}
}
-sym_link *validateLink(sym_link *l,
- const char *macro,
- const char *args,
- const char select,
- const char *file,
- unsigned line)
+sym_link *validateLink(sym_link *l,
+ const char *macro,
+ const char *args,
+ const char select,
+ const char *file,
+ unsigned line)
{
if (l && l->class==select)
{
- return l;
+ return l;
}
fprintf(stderr,
- "Internal error: validateLink failed in %s(%s) @ %s:%u:"
- " expected %s, got %s\n",
- macro, args, file, line,
- DECLSPEC2TXT(select), l ? DECLSPEC2TXT(l->class) : "null-link");
+ "Internal error: validateLink failed in %s(%s) @ %s:%u:"
+ " expected %s, got %s\n",
+ macro, args, file, line,
+ DECLSPEC2TXT(select), l ? DECLSPEC2TXT(l->class) : "null-link");
exit(-1);
return l; // never reached, makes compiler happy.
}