From 19f03cf83449e062f49b1db3a5f3b742c2611428 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 4 Apr 2006 22:09:53 +0000 Subject: [PATCH] Start to support for virtual calls --- Robust/src/IR/Flat/BuildCode.java | 98 ++++++++++++++++++++++++++--- Robust/src/IR/MethodDescriptor.java | 15 +++++ Robust/src/IR/TypeDescriptor.java | 13 ++++ Robust/src/IR/Virtual.java | 65 +++++++++++++++++++ 4 files changed, 183 insertions(+), 8 deletions(-) create mode 100644 Robust/src/IR/Virtual.java diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 4302ab6b..aee78984 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -8,17 +8,21 @@ public class BuildCode { Hashtable temptovar; Hashtable paramstable; Hashtable tempstable; + Hashtable fieldorder; int tag=0; String localsprefix="___locals___"; String paramsprefix="___params___"; public static boolean GENERATEPRECISEGC=false; public static String PREFIX=""; + Virtual virtualcalls; public BuildCode(State st, Hashtable temptovar) { state=st; this.temptovar=temptovar; paramstable=new Hashtable(); tempstable=new Hashtable(); + fieldorder=new Hashtable(); + virtualcalls=new Virtual(state); } public void buildCode() { @@ -27,6 +31,8 @@ public class BuildCode { PrintWriter outstructs=null; PrintWriter outmethodheader=null; PrintWriter outmethod=null; + PrintWriter outvirtual=null; + try { OutputStream str=new FileOutputStream(PREFIX+"structdefs.h"); outstructs=new java.io.PrintWriter(str, true); @@ -36,10 +42,14 @@ public class BuildCode { outclassdefs=new java.io.PrintWriter(str, true); str=new FileOutputStream(PREFIX+"methods.c"); outmethod=new java.io.PrintWriter(str, true); + str=new FileOutputStream(PREFIX+"virtualtable.h"); + outvirtual=new java.io.PrintWriter(str, true); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } + + buildVirtualTables(outvirtual); outstructs.println("#include \"classdefs.h\""); outmethodheader.println("#include \"structdefs.h\""); @@ -61,6 +71,7 @@ public class BuildCode { /* Build the actual methods */ outmethod.println("#include \"methodheaders.h\""); + outmethod.println("#include \"virtualtable.h\""); outmethod.println("#include "); Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); while(classit.hasNext()) { @@ -76,6 +87,58 @@ public class BuildCode { outmethod.close(); } + private void buildVirtualTables(PrintWriter outvirtual) { + int numclasses=0; + int maxcount=0; + Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); + while(classit.hasNext()) { + ClassDescriptor cd=(ClassDescriptor)classit.next(); + if (virtualcalls.getMethodCount(cd)>maxcount) + maxcount=virtualcalls.getMethodCount(cd); + numclasses++; + } + MethodDescriptor[][] virtualtable=new MethodDescriptor[numclasses][maxcount]; + + /* Fill in virtual table */ + classit=state.getClassSymbolTable().getDescriptorsIterator(); + while(classit.hasNext()) { + ClassDescriptor cd=(ClassDescriptor)classit.next(); + fillinRow(cd, virtualtable, cd.getId()); + } + outvirtual.print("void * virtualtable[]={"); + boolean needcomma=false; + for(int i=0;i