From 774998412dac8ef776d52416babc5608995b38c9 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 15 Aug 2006 21:11:59 +0000 Subject: [PATCH] check in changes --- Robust/src/IR/Flat/BuildCode.java | 57 ++++++++++++++++++++++++---- Robust/src/IR/Flat/TempFlagPair.java | 4 ++ Robust/src/Runtime/runtime.c | 13 ++++++- Robust/src/Runtime/runtime.h | 3 ++ Robust/src/buildscripttask | 7 ++++ 5 files changed, 75 insertions(+), 9 deletions(-) create mode 100755 Robust/src/buildscripttask diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 380b2a81..09679d14 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -237,12 +237,12 @@ public class BuildCode { DNFFlagAtom dfa=(DNFFlagAtom)term.get(k); FlagDescriptor fd=dfa.getFlag(); boolean negated=dfa.getNegated(); - int flagid=((Integer)flags.get(fd)).intValue(); + int flagid=1<<((Integer)flags.get(fd)).intValue(); andmask|=flagid; if (!negated) checkmask|=flagid; } - output.print(andmask+", "+checkmask); + output.print("0x"+Integer.toHexString(andmask)+", 0x"+Integer.toHexString(checkmask)); } output.println("};"); @@ -464,8 +464,8 @@ public class BuildCode { FlagDescriptor fd=(FlagDescriptor)superflagit.next(); Integer number=(Integer)superflags.get(fd); flags.put(fd, number); - if (number.intValue()>max) - max=number.intValue(); + if ((number.intValue()+1)>max) + max=number.intValue()+1; } } @@ -473,7 +473,7 @@ public class BuildCode { while(flagit.hasNext()) { FlagDescriptor fd=(FlagDescriptor)flagit.next(); if (sp==null||!sp.getFlagTable().contains(fd.getSymbol())) - flags.put(fd, new Integer(++max)); + flags.put(fd, new Integer(max++)); } } } @@ -486,6 +486,8 @@ public class BuildCode { /* Output class structure */ classdefout.println("struct "+cn.getSafeSymbol()+" {"); classdefout.println(" int type;"); + if (cn.hasFlags()) + classdefout.println(" int flag;"); printClassStruct(cn, classdefout); classdefout.println("};\n"); @@ -1051,8 +1053,47 @@ public class BuildCode { output.print(")"); } - public void generateFlatFlagActionNode(FlatMethod fm, FlatFlagActionNode ffann, PrintWriter output) { - output.print("/* FlatFlagActionNode will go here */"); - + public void generateFlatFlagActionNode(FlatMethod fm, FlatFlagActionNode ffan, PrintWriter output) { + output.println("/* FlatFlagActionNode */"); + Hashtable flagandtable=new Hashtable(); + Hashtable flagortable=new Hashtable(); + + + Iterator flagsit=ffan.getTempFlagPairs(); + while(flagsit.hasNext()) { + TempFlagPair tfp=(TempFlagPair)flagsit.next(); + TempDescriptor temp=tfp.getTemp(); + Hashtable flagtable=(Hashtable)flagorder.get(temp.getType().getClassDesc()); + FlagDescriptor flag=tfp.getFlag(); + int flagid=1<<((Integer)flagtable.get(flag)).intValue(); + boolean flagstatus=ffan.getFlagChange(tfp); + if (flagstatus) { + int mask=0; + if (flagortable.containsKey(temp)) { + mask=((Integer)flagortable.get(temp)).intValue(); + } + mask|=flagid; + flagortable.put(temp,new Integer(mask)); + } else { + int mask=0xFFFFFFFF; + if (flagandtable.containsKey(temp)) { + mask=((Integer)flagandtable.get(temp)).intValue(); + } + mask&=(0xFFFFFFFF^flagid); + flagandtable.put(temp,new Integer(mask)); + } + } + Iterator orit=flagortable.keySet().iterator(); + while(orit.hasNext()) { + TempDescriptor temp=(TempDescriptor)orit.next(); + int ormask=((Integer)flagortable.get(temp)).intValue(); + output.println("flagor("+generateTemp(fm, temp)+", 0x"+Integer.toHexString(ormask)+");"); + } + Iterator andit=flagandtable.keySet().iterator(); + while(andit.hasNext()) { + TempDescriptor temp=(TempDescriptor)andit.next(); + int andmask=((Integer)flagandtable.get(temp)).intValue(); + output.println("flagand("+generateTemp(fm, temp)+", 0x"+Integer.toHexString(andmask)+");"); + } } } diff --git a/Robust/src/IR/Flat/TempFlagPair.java b/Robust/src/IR/Flat/TempFlagPair.java index c7f4e68e..81edcefc 100644 --- a/Robust/src/IR/Flat/TempFlagPair.java +++ b/Robust/src/IR/Flat/TempFlagPair.java @@ -17,6 +17,10 @@ public class TempFlagPair { return td; } + public FlagDescriptor getFlag() { + return fd; + } + public boolean equals(Object o) { if (!(o instanceof TempFlagPair)) return false; diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index c91890a9..a6e2f6a9 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -15,6 +15,8 @@ int main(int argc, char **argv) { int i; /* Allocate startup object */ struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(STARTUPTYPE); + /* Set flag */ + flagor(startupobject,1); /* Build array of strings */ struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc); @@ -23,11 +25,20 @@ int main(int argc, char **argv) { for(i=0;i___length___)+sizeof(int)))[i]=newstring; + ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i]=newstring; } + processtasks(); +} +void flagor(void * ptr, int ormask) { + ((int *)ptr)[1]|=ormask; +} +void flagand(void * ptr, int andmask) { + ((int *)ptr)[1]&=andmask; } + +void processtasks(); #endif int ___Object______hashcode____(struct ___Object___ * ___this___) { diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index eb020ef2..f9031810 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -10,4 +10,7 @@ struct ___String___ * NewString(char *str,int length); void failedboundschk(); void failednullptr(); +void flagor(void * ptr, int ormask); +void flagand(void * ptr, int andmask); + #endif diff --git a/Robust/src/buildscripttask b/Robust/src/buildscripttask new file mode 100755 index 00000000..fc37f883 --- /dev/null +++ b/Robust/src/buildscripttask @@ -0,0 +1,7 @@ +#!/bin/bash +ROBUSTROOT=~/research/Robust/src +MAINFILE=$1 +shift +mkdir tmpbuilddirectory +java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -task $@ +gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -DTASK -g tmpbuilddirectory/methods.c $ROBUSTROOT/Runtime/runtime.c -o $MAINFILE.bin \ No newline at end of file -- 2.34.1