コード例 #1
0
ファイル: debugPrint.c プロジェクト: lgxZJ/Tiger-Compiler
void printSeqStatement(FILE* file, IR_myStatement statement, int spaceNum)
{
    fprintf(file, "Seq(");
    printStatement(file, statement->u.seq.left, spaceNum + 2),

    indentAndPrintToFile(file, spaceNum, ", ");
    printStatement(file, statement->u.seq.right, spaceNum + 2);

    indentAndPrintToFile(file, spaceNum, ")\n");
}
コード例 #2
0
ファイル: CodeGenerator.cpp プロジェクト: drdrpyan/compiler
void CodeGenerator::printStatement(const Node *statementNode)
{
	Node *son = statementNode->son;
	Node *grandSon = son->son;
	while(son)
	{
		switch(son->kind)
		{
		case VAR_DEC_LIST:
			while(grandSon)
			{
				printVarDec(grandSon);
				grandSon = grandSon->bro;
			}
			break;

		case OUTPUT:
			printOutput(son);
			break;

		///아직 여러가지 남음
		case STMT:
			symbolTable.openNewScope();
			printStatement(son);
			symbolTable.closeLastScope();
			break;
		}
		son = son->bro;
		if(son)
			grandSon = son->son;
	}
}
コード例 #3
0
ファイル: debugPrint.c プロジェクト: lgxZJ/Tiger-Compiler
void printESeq(FILE* file, IR_myExp exp, int spaceNum)
{
    fprintf(file, "Eseq(");
	printStatement(file, exp->u.eseq.statement, spaceNum + 2);

	indentAndPrintToFile(file, spaceNum, ", ");
	printExpression(file, exp->u.eseq.exp, spaceNum + 2);

	indentAndPrintToFile(file, spaceNum, ")\n");
}
コード例 #4
0
ファイル: debugPrint.c プロジェクト: lgxZJ/Tiger-Compiler
void printFragments(FILE* file, Frame_myFragList fragments)
{
    while (fragments)
    {
        if (fragments->head->kind == Frame_StringFrag)
        {
            fprintf(file, "%s:\n", fragments->head->u.strFrag.str);
            indentSpace(file, 2);
            fprintf(file, "Label: %s\n\n",
                MySymbol_GetName(fragments->head->u.strFrag.label));
        }
        else
        {
            fprintf(file, "%s:\n", MySymbol_GetName(fragments->head->u.procFrag.funcName));
            printStatement(file, fragments->head->u.procFrag.body, 2);
            fprintf(file, "\n\n");
        }

        fragments = fragments->tail;
    }
}
コード例 #5
0
ファイル: parser.cpp プロジェクト: rafalpaszkiewicz/miniperl
NodePointer Parser::statement()
{
	NodePointer result;

	switch (currentSymbol_.symbolType_)
	{
		case IF:
			return ifStatement();

		case WHILE:
			return whileStatement();

		case IDENTIFIER:
		case GLOBAL:
		case ARGUMENT:
		case CALL:
		case CONSTANT:
			result = expression();
			accept(SEMICOLON);
			return result;

		case MY:
			return localVariable();

		case PRINT:
			return printStatement();

		case SUBROUTINE:
			return procedureDefinition();

		case RETURN:
			return returnStatement();

		case LEFT_BRACE:
			return blockStatement();

		default:
			throw ErrorMessage("Unexpected symbol " + symbolToString(currentSymbol_), getLineNumber());
	}
}
コード例 #6
0
ファイル: CodeGenerator.cpp プロジェクト: drdrpyan/compiler
void CodeGenerator::printSingleFuncDec(const Node *funcDecNode)
{
	Node *typeNode = funcDecNode->son;
	SYM_TYPE type = getType(typeNode);
	printType(typeNode);
	ofs << ' ';

	Node *funcNameNode = typeNode->bro;
	Node *paramNode = funcNameNode->bro;
	FuncEntry *funcEntry;
	unsigned long long key = SymbolTable::hash(funcNameNode->val.sVal);
	if(symbolTable.isInThisScope(key))
	{
		std::cerr << "function is duplicated : " << funcNameNode->val.sVal << std::endl;
		exit(-1);
	}
	else
	{
		funcEntry = new FuncEntry(key);
		funcEntry->addRetVal(type);
		symbolTable.addEntry(funcEntry);
		symbolTable.openNewScope();

		ofs << funcNameNode->val.sVal << '(';
		printParamList(paramNode, funcEntry);
		while(paramNode->kind == PARAM)
			paramNode = paramNode->bro;
		ofs << ')' << std::endl;

		ofs << '{' << std::endl;
		printStatement(paramNode);
		ofs << '}' << std::endl;

		symbolTable.closeLastScope();
	}
}
コード例 #7
0
ファイル: printer.cpp プロジェクト: DawidvC/clay
static void print(llvm::raw_ostream &out, const Object *x) {
    if (x == NULL) {
        out << "NULL";
        return;
    }

    switch (x->objKind) {

    case SOURCE : {
        const Source *y = (const Source *)x;
        out << "Source(" << y->fileName << ")";
        break;
    }
    case IDENTIFIER : {
        const Identifier *y = (const Identifier *)x;
        out << "Identifier(" << y->str << ")";
        break;
    }
    case DOTTED_NAME : {
        const DottedName *y = (const DottedName *)x;
        out << "DottedName(" << llvm::makeArrayRef(y->parts) << ")";
        break;
    }

    case EXPRESSION : {
        const Expr *y = (const Expr *)x;
        printExpr(out, y);
        break;
    }

    case EXPR_LIST : {
        const ExprList *y = (const ExprList *)x;
        out << "ExprList(" << y->exprs << ")";
        break;
    }

    case STATEMENT : {
        const Statement *y = (const Statement *)x;
        printStatement(out, y);
        break;
    }

    case CASE_BLOCK : {
        const CaseBlock *y = (const CaseBlock *)x;
        out << "CaseBlock(" << y->caseLabels << ", " << y->body << ")";
        break;
    }

    case CATCH : {
        const Catch *y = (const Catch *)x;
        out << "Catch(" << y->exceptionVar << ", "
            << y->exceptionType << ", " << y->body << ")";
        break;
    }

    case CODE : {
        const Code *y = (const Code *)x;
        out << "Code(" << y->patternVars << ", " << y->predicate;
        out << ", " << y->formalArgs << ", " << y->hasVarArg;
        out << ", " << y->returnSpecs << ", " << y->varReturnSpec;
        out << ", " << y->body << ")";
        break;
    }
    case FORMAL_ARG : {
        const FormalArg *y = (const FormalArg *)x;
        out << "FormalArg(" << y->name << ", " << y->type << ", "
            << y->tempness << ")";
        break;
    }
    case RETURN_SPEC : {
        const ReturnSpec *y = (const ReturnSpec *)x;
        out << "ReturnSpec(" << y->type << ", " << y->name << ")";
        break;
    }

    case RECORD_DECL : {
        const RecordDecl *y = (const RecordDecl *)x;
        out << "RecordDecl(" << y->name << ", " << y->params;
        out << ", " << y->varParam << ", " << y->body << ")";
        break;
    }
    case RECORD_BODY : {
        const RecordBody *y = (const RecordBody *)x;
        out << "RecordBody(" << y->isComputed << ", " << y->computed;
        out << ", " << y->fields << ")";
        break;
    }
    case RECORD_FIELD : {
        const RecordField *y = (const RecordField *)x;
        out << "RecordField(" << y->name << ", " << y->type << ")";
        break;
    }

    case VARIANT_DECL : {
        const VariantDecl *y = (const VariantDecl *)x;
        out << "VariantDecl(" << y->name << ", " << y->params;
        out << ", " << y->varParam << ")";
        break;
    }
    case INSTANCE_DECL : {
        const InstanceDecl *y = (const InstanceDecl *)x;
        out << "InstanceDecl(" << y->patternVars << ", " << y->predicate;
        out << ", " << y->target << ", " << y->members << ")";
        break;
    }

    case OVERLOAD : {
        const Overload *y = (const Overload *)x;
        out << "Overload(" << y->target << ", " << y->code << ", "
            << y->callByName << ", " << y->isInline << ")";
        break;
    }
    case PROCEDURE : {
        const Procedure *y = (const Procedure *)x;
        out << "Procedure(" << y->name << ")";
        break;
    }
    case INTRINSIC : {
        const IntrinsicSymbol *intrin = (const IntrinsicSymbol *)x;
        out << "IntrinsicSymbol(" << intrin->name << ", " << intrin->id << ")";
        break;
    }

    case ENUM_DECL : {
        const EnumDecl *y = (const EnumDecl *)x;
        out << "EnumDecl(" << y->name << ", " << y->members << ")";
        break;
    }
    case ENUM_MEMBER : {
        const EnumMember *y = (const EnumMember *)x;
        out << "EnumMember(" << y->name << ")";
        break;
    }

    case NEW_TYPE_DECL : {
        const NewTypeDecl *y = (const NewTypeDecl *)x;
        out << "NewTypeDecl(" << y->name << ")";
        break;
    }
    
    case GLOBAL_VARIABLE : {
        const GlobalVariable *y = (const GlobalVariable *)x;
        out << "GlobalVariable(" << y->name << ", " << y->params
            << ", " << y->varParam << ", " << y->expr << ")";
        break;
    }

    case EXTERNAL_PROCEDURE : {
        const ExternalProcedure *y = (const ExternalProcedure *)x;
        out << "ExternalProcedure(" << y->name << ", " << y->args;
        out << ", " << y->hasVarArgs << ", " << y->returnType;
        out << ", " << y->body << ")";
        break;
    }
    case EXTERNAL_ARG: {
        const ExternalArg *y = (const ExternalArg *)x;
        out << "ExternalArg(" << y->name << ", " << y->type << ")";
        break;
    }

    case EXTERNAL_VARIABLE : {
        const ExternalVariable *y = (const ExternalVariable *)x;
        out << "ExternalVariable(" << y->name << ", " << y->type << ")";
        break;
    }

    case GLOBAL_ALIAS : {
        const GlobalAlias *y = (const GlobalAlias *)x;
        out << "GlobalAlias(" << y->name << ", " << y->params
            << ", " << y->varParam << ", " << y->expr << ")";
        break;
    }

    case IMPORT : {
        const Import *y = (const Import *)x;
        switch (y->importKind) {
        case IMPORT_MODULE : {
            const ImportModule *z = (const ImportModule *)y;
            out << "Import(" << z->dottedName << ", " << z->alias << ")";
            break;
        }
        case IMPORT_STAR : {
            const ImportStar *z = (const ImportStar *)y;
            out << "ImportStar(" << z->dottedName << ")";
            break;
        }
        case IMPORT_MEMBERS : {
            const ImportMembers *z = (const ImportMembers *)y;
            out << "ImportMembers(" << z->visibility << ", " << z->dottedName << ", [";
            for (size_t i = 0; i < z->members.size(); ++i) {
                if (i != 0)
                    out << ", ";
                const ImportedMember &a = z->members[i];
                out << "(" << a.name << ", " << a.alias << ")";
            }
            out << "])";
            break;
        }
        default :
            assert(false);
        }
        break;
    }

    case EVAL_TOPLEVEL : {
        const EvalTopLevel *eval = (const EvalTopLevel *)x;
        out << "EvalTopLevel(" << eval->args << ")";
        break;
    }

    case STATIC_ASSERT_TOP_LEVEL : {
        const StaticAssertTopLevel *staticAssert = (const StaticAssertTopLevel*)x;
        out << "StaticAssertTopLevel(" << staticAssert->cond;
        for (size_t i = 0; i < staticAssert->message->size(); ++i) {
            out << ", " << staticAssert->message->exprs[i];
        }
        out << ")";
        break;
    }

    case MODULE_DECLARATION : {
        const ModuleDeclaration *y = (const ModuleDeclaration *)x;
        out << "ModuleDeclaration(" << y->name << ", " << y->attributes << ")";
        break;
    }
    case MODULE : {
        const Module *y = (const Module *)x;
        out << "Module(" << bigVec(y->imports) << ", "
            << bigVec(y->topLevelItems) << ")";
        break;
    }

    case PRIM_OP : {
        const PrimOp *y = (const PrimOp *)x;
        out << "PrimOp(" << primOpName(const_cast<PrimOp *>(y)) << ")";
        break;
    }

    case TYPE : {
        const Type *y = (const Type *)x;
        typePrint(out, const_cast<Type *>(y));
        break;
    }

    case PATTERN : {
        const Pattern *y = (const Pattern *)x;
        patternPrint(out, const_cast<Pattern *>(y));
        break;
    }
    case MULTI_PATTERN : {
        const MultiPattern *y = (const MultiPattern *)x;
        patternPrint(out, const_cast<MultiPattern *>(y));
        break;
    }

    case VALUE_HOLDER : {
        const ValueHolder *y = (const ValueHolder *)x;
        EValuePtr ev = new EValue(y->type, y->buf);
        out << "ValueHolder(";
        printTypeAndValue(out, ev);
        out << ")";
        break;
    }

    case MULTI_STATIC : {
        const MultiStatic *y = (const MultiStatic *)x;
        out << "MultiStatic(" << y->values << ")";
        break;
    }

    case PVALUE : {
        const PValue *y = (const PValue *)x;
        out << "PValue(" << y->data << ")";
        break;
    }

    case MULTI_PVALUE : {
        const MultiPValue *y = (const MultiPValue *)x;
        out << "MultiPValue(" << llvm::makeArrayRef(y->values) << ")";
        break;
    }

    case EVALUE : {
        const EValue *y = (const EValue *)x;
        out << "EValue(" << y->type << ")";
        break;
    }

    case MULTI_EVALUE : {
        const MultiEValue *y = (const MultiEValue *)x;
        out << "MultiEValue(" << y->values << ")";
        break;
    }

    case CVALUE : {
        const CValue *y = (const CValue *)x;
        out << "CValue(" << y->type << ")";
        break;
    }

    case MULTI_CVALUE : {
        const MultiCValue *y = (const MultiCValue *)x;
        out << "MultiCValue(" << y->values << ")";
        break;
    }
            
    case DOCUMENTATION : {
        const Documentation *d = (const Documentation *)x;
        out << "Documentation(" << d->text << ")";
        break;
    }

    default :
        out << "UnknownObj(" << x->objKind << ")";
        break;
    }
}
コード例 #8
0
ファイル: ast.c プロジェクト: BackupTheBerlios/elastic
void ASTPrint( int lev, ASTNode node )
{
	if (! node)
	{
		indent( lev ); ec_stderr_printf( "NULL" );
		return;
	}

	/* Simplify our lives ... */
	if (currentScope)
	{
		if (currentScope->type == PackageScope)
		{
			currentPackage  = currentScope->target;
			currentBytecode = EC_PACKAGECODE(currentScope->target);
		} else
		{
			currentBytecode = currentScope->target;
		}
		currentLiteral  = EC_COMPILEDLFRAME(currentBytecode);
	}

	switch ( node->type )
	{
	case nullType:
		indent( lev ); ec_stderr_printf( "<nullType>" );
		break;

	case symbolType:
		printSymbol( lev, node );
		break;

	case qualifiedSymbolType:
		printQualifiedSymbol( lev, node );
		break;

	case constExprType:
		printConstant( lev, node );
		break;

	case variableExprType:
		printVariable( lev, node );
		break;

	case arrayConstructionExprType:
		printArrayCons( lev, node );
		break;

	case hashConstructionExprType:
		printHashCons( lev, node );
		break;

	case unaryExprType:
		printUnary( lev, node );
		break;

	case binaryExprType:
		printBinary( lev, node );
		break;

	case conditionalExprType:
		printConditional( lev, node );
		break;

	case orExprType:
		printOr( lev, node );
		break;

	case andExprType:
		printAnd( lev, node );
		break;

	case assignExprType:
		printAssign( lev, node );
		break;

	case simAssignExprType:
		printSimAssign( lev, node );
		break;

	case arrayRefExprType:
		printArrayRef( lev, node );
		break;

	case declNodeType:
		printDecl( lev, node );
		break;

	case declAtomNodeType:
		printDeclAtom( lev, node );
		break;

	case statementType:
		printStatement( lev, node );
		break;

	case labeledStmtType:
		printLabeledStmt( lev, node );
		break;

	case exprStmtType:
		printExprStmt( lev, node );
		break;

	case ifStmtType:
		printIf( lev, node );
		break;

	case whileStmtType:
		printWhile( lev, node );
		break;

	case doStmtType:
		printDo( lev, node );
		break;

	case forStmtType:
		printFor( lev, node );
		break;

	case forInStmtType:
		printForIn( lev, node );
		break;

	case breakStmtType:
		printBreak( lev, node );
		break;

	case continueStmtType:
		printContinue( lev, node );
		break;

	case gotoStmtType:
		printGoto( lev, node );
		break;

	case tryStmtType:
		printTry( lev, node );
		break;

	case catchStmtType:
		printCatch( lev, node );
		break;

	case throwStmtType:
		printThrow( lev, node );
		break;

	case importStmtType:
		printImport( lev, node );
		break;

	case paramNodeType:
		printParam( lev, node );
		break;

	case paramListType:
		printParamList( lev, node );
		break;

	case callNodeType:
		printCall( lev, node );
		break;

	case methodCallNodeType:
		printMethodCall( lev, node );
		break;

	case stmtListType:
		printStmtList( lev, node );
		break;

	case funcNodeType:
		printFunction( lev, node );
		break;

	case returnNodeType:
		printReturn( lev, node );
		break;

	case classNodeType:
		printClass( lev, node );
		break;

	case methodNodeType:
		printMethod( lev, node );
		break;

	case packageNodeType:
		printPackage( lev, node );
		break;
	}
}