Mercurial > hg > CbC > CbC_llvm
changeset 187:4680e0f68448
AST is generated in RetCS
SelectionDAG failed
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 05 Jun 2020 18:34:26 +0900 |
parents | f737e363b8f3 |
children | dd01b8f82867 |
files | clang/include/clang/Parse/Parser.h clang/lib/Parse/ParseCbC.cpp |
diffstat | 2 files changed, 28 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/clang/include/clang/Parse/Parser.h Wed Jun 03 10:45:39 2020 +0900 +++ b/clang/include/clang/Parse/Parser.h Fri Jun 05 18:34:26 2020 +0900 @@ -2350,6 +2350,7 @@ llvm::function_ref<void(ParsingFieldDeclarator &)> FieldsCallback); #ifndef noCbC void CreateRetCS(IdentifierInfo* csName); + void CreateRetCS1(IdentifierInfo *csName, const PrintingPolicy &Policy, QualType CurFuncResQT , TypeSourceInfo *CurFuncTI , Decl **BodyRes, StmtResult &FnBody); void Create__CbC_envStruct(SourceLocation Loc, AccessSpecifier AS); IdentifierInfo* CreateIdentifierInfo(const char* Name, SourceLocation Loc); IdentifierInfo* CreateAnonIdentifierInfo(const char* Name, SourceLocation Loc);
--- a/clang/lib/Parse/ParseCbC.cpp Wed Jun 03 10:45:39 2020 +0900 +++ b/clang/lib/Parse/ParseCbC.cpp Fri Jun 05 18:34:26 2020 +0900 @@ -1,4 +1,4 @@ -#ifndef noCbC +#ifndef noCbC #include "clang/Parse/Parser.h" #include "clang/Parse/RAIIObjectsForParser.h" @@ -161,8 +161,10 @@ PrettyStackTraceLoc CrashInfo(PP.getSourceManager(),Loc,"in compound statement ('{}')"); StmtVector CompoundStmts; + size_t cs = Actions.getCurFunction()->CompoundScopes.size(); // create code segment for return to C's function CreateRetCS(retcsII); + printf("cs = %zu, %zu\n", cs ,Actions.getCurFunction()->CompoundScopes.size()); // __code (*__CbC_return)(); innerRes = CreateDeclStmt(__CbC_retII, true, false, DeclSpec::TST___code); @@ -178,10 +180,11 @@ innerRes = CreateComplexStmtRet(__CbC_retII, false); if (innerRes.isUsable()) CompoundStmts.push_back(innerRes.get()); - size_t cs = Actions.getCurFunction()->CompoundScopes.size(); + cs = Actions.getCurFunction()->CompoundScopes.size(); Sema::CompoundScopeRAII CompoundScope(Actions); CompoundStmtRes = Actions.ActOnCompoundStmt(Loc,Loc,CompoundStmts,true); - assert( cs == Actions.getCurFunction()->CompoundScopes.size()); + // assert( cs == Actions.getCurFunction()->CompoundScopes.size()); + printf("cs = %zu, %zu\n", cs ,Actions.getCurFunction()->CompoundScopes.size()); // ConsumeToken(); ConsumeAnyToken(); // eat the '__return'. @@ -269,7 +272,8 @@ CompoundStmts.push_back(innerRes.get()); StmtResult CompoundStmtRes = Actions.ActOnCompoundStmt(Loc,Loc,CompoundStmts,true); - assert( cs == Actions.getCurFunction()->CompoundScopes.size()); + // assert( cs == Actions.getCurFunction()->CompoundScopes.size()); + printf("cs = %zu, %zu\n", cs ,Actions.getCurFunction()->CompoundScopes.size()); ConsumeAnyToken(); // eat the '__environment'. Result = Actions.ActOnStmtExpr(getCurScope() ,Loc, CompoundStmtRes.get(), Loc); @@ -529,7 +533,8 @@ if (innerStmtRes.isUsable()) innerStmts.push_back(innerStmtRes.get()); StmtRes = Actions.ActOnCompoundStmt(Loc, Loc,innerStmts, false); - assert( cs == Actions.getCurFunction()->CompoundScopes.size()); + // assert( cs == Actions.getCurFunction()->CompoundScopes.size()); + printf("cs = %zu, %zu\n", cs ,Actions.getCurFunction()->CompoundScopes.size()); StmtResult ThenStmt(StmtRes); InnerScope.Exit(); IfScope.Exit(); @@ -691,14 +696,25 @@ DeclContext *SavedContext = Actions.CurContext; TypeSourceInfo *CurFuncTI = Actions.Context.CreateTypeSourceInfo(CurFuncResQT); sema::FunctionScopeInfo *SavedFSI = Actions.FunctionScopes.pop_back_val(); + Decl *BodyRes = 0; + StmtResult FnBody; + CreateRetCS1(csName, Policy, CurFuncResQT, CurFuncTI,&BodyRes, FnBody); + Decl *TheDecl = Actions.ActOnFinishFunctionBody(BodyRes, FnBody.get()); + DeclGroupPtrTy returnDecl = DeclGroupPtrTy(); + returnDecl = Actions.ConvertDeclToDeclGroup(TheDecl); + (&Actions.getASTConsumer())->HandleTopLevelDecl(returnDecl.get()); + Actions.CurScope = SavedScope; + Actions.CurContext = SavedContext; + Actions.FunctionScopes.push_back(SavedFSI); +} +void Parser::CreateRetCS1(IdentifierInfo *csName, const PrintingPolicy &Policy, QualType CurFuncResQT , TypeSourceInfo *CurFuncTI , Decl ** BodyResP, StmtResult &FnBody){ Actions.CurContext = static_cast<DeclContext *>(Actions.Context.getTranslationUnitDecl()); Scope *TopScope = getCurScope(); while(TopScope->getParent() != NULL) TopScope = TopScope->getParent(); Actions.CurScope = TopScope; - DeclGroupPtrTy returnDecl = DeclGroupPtrTy(); SourceLocation Loc = Tok.getLocation(); ParsingDeclSpec PDS(*this); setTST(&PDS, DeclSpec::TST___code); @@ -740,7 +756,6 @@ Loc, Loc, D, TrailingReturnType, &FDS), std::move(FnAttrs), Loc); PrototypeScope.Exit(); - Decl *TheDecl; ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope); Sema::SkipBodyInfo SkipBody; const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(); @@ -751,7 +766,7 @@ D.complete(BodyRes); D.getMutableDeclSpec().abort(); Actions.ActOnDefaultCtorInitializers(BodyRes); - StmtResult FnBody; + *BodyResP = BodyRes; StmtVector FnStmts; StmtResult innerR; ExprResult retvalAssginmentExpr,LHS; @@ -838,14 +853,9 @@ if(innerR.isUsable()) FnStmts.push_back(innerR.get()); FnBody = Actions.ActOnCompoundStmt(Loc, Loc, FnStmts, false); - assert( cs == Actions.getCurFunction()->CompoundScopes.size()); + // assert( cs == Actions.getCurFunction()->CompoundScopes.size()); + printf("cs = %zu, %zu\n", cs ,Actions.getCurFunction()->CompoundScopes.size()); BodyScope.Exit(); - TheDecl = Actions.ActOnFinishFunctionBody(BodyRes, FnBody.get()); - returnDecl = Actions.ConvertDeclToDeclGroup(TheDecl); - (&Actions.getASTConsumer())->HandleTopLevelDecl(returnDecl.get()); - Actions.CurScope = SavedScope; - Actions.CurContext = SavedContext; - Actions.FunctionScopes.push_back(SavedFSI); } /// IIToExpr - Create ExprResult from IdentifierInfo. @@ -1045,7 +1055,8 @@ size_t cs = Actions.getCurFunction()->CompoundScopes.size(); Sema::CompoundScopeRAII CompoundScope(Actions); StmtResult R = Actions.ActOnCompoundStmt(gotoLoc, Tok.getLocation(), CompoundedStmts, false); - assert( cs == Actions.getCurFunction()->CompoundScopes.size()); + // assert( cs == Actions.getCurFunction()->CompoundScopes.size()); + printf("cs = %zu, %zu\n", cs ,Actions.getCurFunction()->CompoundScopes.size()); return R; }