From 3d0f0e415e9c831b1f11fbc8a1017b5b5a3b8894 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 27 Sep 2006 16:37:26 +0000 Subject: [PATCH] Change main function --- Robust/src/IR/Flat/BuildCode.java | 22 ++++++++++++++++++++-- Robust/src/Runtime/runtime.c | 8 ++++---- Robust/src/Runtime/runtime.h | 2 +- Robust/src/Tests/Array.java | 2 +- Robust/src/Tests/Array2.java | 2 +- Robust/src/Tests/BoundsFail.java | 2 +- Robust/src/Tests/BoundsFail2.java | 2 +- Robust/src/Tests/BoundsFail3.java | 2 +- Robust/src/Tests/BoundsFail4.java | 2 +- Robust/src/Tests/DoTests | 1 + Robust/src/Tests/IncTest.java | 2 +- Robust/src/Tests/StringTest.java | 2 +- Robust/src/Tests/Test.java | 2 +- Robust/src/Tests/dotest | 15 ++++++++++----- Robust/src/Tests/virtualcalltest.java | 2 +- 15 files changed, 46 insertions(+), 22 deletions(-) diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 76bcf10e..d130c246 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -158,6 +158,10 @@ public class BuildCode { outmethod.println("#include \"methodheaders.h\""); outmethod.println("#include \"virtualtable.h\""); outmethod.println("#include "); + if (state.main!=null) { + outmethod.println("#include "); + } + if (state.CONSCHECK) { outmethod.println("#include \"checkers.h\""); } @@ -214,15 +218,29 @@ public class BuildCode { } else if (state.main!=null) { /* Generate main method */ outmethod.println("int main(int argc, const char *argv[]) {"); + outmethod.println("int i;"); + outmethod.println("struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);"); + outmethod.println("for(i=1;i___length___)+sizeof(int)))[i-1]=newstring;"); + outmethod.println("}"); + + ClassDescriptor cd=typeutil.getClass(state.main); Set mainset=cd.getMethodTable().getSet("main"); for(Iterator mainit=mainset.iterator();mainit.hasNext();) { MethodDescriptor md=(MethodDescriptor)mainit.next(); - if (md.numParameters()!=0) + if (md.numParameters()!=1) + continue; + if (md.getParameter(0).getType().getArrayCount()!=1) continue; + if (!md.getParameter(0).getType().getSymbol().equals("String")) + continue; + if (!md.getModifiers().isStatic()) throw new Error("Error: Non static main"); - outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"();"); + outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);"); break; } outmethod.println("}"); diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 8126ca13..abf51e71 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -35,7 +35,7 @@ int main(int argc, char **argv) { int i; /* Allocate startup object */ struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(STARTUPTYPE); - struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc); + struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1); failedtasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd, (int (*)(void *,void *)) &comparetpd); @@ -49,10 +49,10 @@ int main(int argc, char **argv) { startupobject->___parameters___=stringarray; - for(i=0;i___length___)+sizeof(int)))[i]=newstring; + ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring; } executetasks(); } @@ -277,7 +277,7 @@ struct ArrayObject * allocate_newarray(int type, int length) { return v; } -struct ___String___ * NewString(char *str,int length) { +struct ___String___ * NewString(const char *str,int length) { struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length); struct ___String___ * strobj=allocate_new(STRINGTYPE); int i; diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index d02c7286..c20578a8 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -5,7 +5,7 @@ extern jmp_buf error_handler; void * allocate_new(int type); struct ArrayObject * allocate_newarray(int type, int length); -struct ___String___ * NewString(char *str,int length); +struct ___String___ * NewString(const char *str,int length); void failedboundschk(); void failednullptr(); diff --git a/Robust/src/Tests/Array.java b/Robust/src/Tests/Array.java index 7a272d0d..28b32f3e 100644 --- a/Robust/src/Tests/Array.java +++ b/Robust/src/Tests/Array.java @@ -1,6 +1,6 @@ public class Array { int a; - public static void main() { + public static void main(String[] st) { int a[]=new int[10]; int i=2; a[i]=4; diff --git a/Robust/src/Tests/Array2.java b/Robust/src/Tests/Array2.java index 37b0a273..f7b69d47 100644 --- a/Robust/src/Tests/Array2.java +++ b/Robust/src/Tests/Array2.java @@ -1,6 +1,6 @@ public class Array2 { int a; - public static void main() { + public static void main(String str[]) { int a[][]=new int[10][20]; for(int i=0;i<10;i++) { for(int j=0;j<20;j++) { diff --git a/Robust/src/Tests/BoundsFail.java b/Robust/src/Tests/BoundsFail.java index b836789c..6aff4f2a 100644 --- a/Robust/src/Tests/BoundsFail.java +++ b/Robust/src/Tests/BoundsFail.java @@ -1,6 +1,6 @@ public class BoundsFail { int a; - public static void main() { + public static void main(String str[]) { int a[]=new int[10]; a[-1]=2; } diff --git a/Robust/src/Tests/BoundsFail2.java b/Robust/src/Tests/BoundsFail2.java index 98ac0ec0..abe327ca 100644 --- a/Robust/src/Tests/BoundsFail2.java +++ b/Robust/src/Tests/BoundsFail2.java @@ -1,6 +1,6 @@ public class BoundsFail2 { int a; - public static void main() { + public static void main(String str[]) { int a[]=new int[10]; a[10]=2; } diff --git a/Robust/src/Tests/BoundsFail3.java b/Robust/src/Tests/BoundsFail3.java index b439d461..c6949e2f 100644 --- a/Robust/src/Tests/BoundsFail3.java +++ b/Robust/src/Tests/BoundsFail3.java @@ -1,6 +1,6 @@ public class BoundsFail3 { int a; - public static void main() { + public static void main(String str[]) { int a[]=new int[10]; int b=a[-1]; } diff --git a/Robust/src/Tests/BoundsFail4.java b/Robust/src/Tests/BoundsFail4.java index 0af6e605..3eae8e26 100644 --- a/Robust/src/Tests/BoundsFail4.java +++ b/Robust/src/Tests/BoundsFail4.java @@ -1,6 +1,6 @@ public class BoundsFail4 { int a; - public static void main() { + public static void main(String str[]) { int a[]=new int[10]; int b=a[10]; } diff --git a/Robust/src/Tests/DoTests b/Robust/src/Tests/DoTests index b044ba58..e6de08ba 100755 --- a/Robust/src/Tests/DoTests +++ b/Robust/src/Tests/DoTests @@ -10,3 +10,4 @@ dotest StringTest StringTest.java dotest Test Test.java dotest virtualcalltest virtualcalltest.java dotest IncTest IncTest.java +dotest CommandLineTest CommandLineTest.java hello hi diff --git a/Robust/src/Tests/IncTest.java b/Robust/src/Tests/IncTest.java index bedb3d65..c48ac10a 100644 --- a/Robust/src/Tests/IncTest.java +++ b/Robust/src/Tests/IncTest.java @@ -1,6 +1,6 @@ public class IncTest { - public static void main() { + public static void main(String str[]) { int x[]=new int[20]; for(int i=0;i<10;) { x[i++]++; diff --git a/Robust/src/Tests/StringTest.java b/Robust/src/Tests/StringTest.java index 7114f4a6..62bd609d 100644 --- a/Robust/src/Tests/StringTest.java +++ b/Robust/src/Tests/StringTest.java @@ -1,5 +1,5 @@ class StringTest { - public static void main() { + public static void main(String str[]) { String a="hello world\n"; System.printString(a); } diff --git a/Robust/src/Tests/Test.java b/Robust/src/Tests/Test.java index 85b9c8d4..6f4f334f 100644 --- a/Robust/src/Tests/Test.java +++ b/Robust/src/Tests/Test.java @@ -3,7 +3,7 @@ public class Test { ; } int a; - public static void main() { + public static void main(String str[]) { Test t=new Test(); for(int i=3;i<10000;i++) { boolean flagx=true; diff --git a/Robust/src/Tests/dotest b/Robust/src/Tests/dotest index a57f1d93..c724ccf8 100755 --- a/Robust/src/Tests/dotest +++ b/Robust/src/Tests/dotest @@ -1,6 +1,11 @@ #!/bin/bash -echo Doing Test $1 -../buildscript $1 $2 &>/dev/null -$1.bin &> output/$1.output -diff output/$1.output output/$1.output.goal -rm $1.bin +ARG1=$1 +ARG2=$2 +shift +shift + +echo Doing Test $ARG1 +../buildscript $ARG1 $ARG2 &>/dev/null +$ARG1.bin $@ &> output/$ARG1.output +diff output/$ARG1.output output/$ARG1.output.goal +rm $ARG1.bin diff --git a/Robust/src/Tests/virtualcalltest.java b/Robust/src/Tests/virtualcalltest.java index 0996eef5..1b034ad2 100644 --- a/Robust/src/Tests/virtualcalltest.java +++ b/Robust/src/Tests/virtualcalltest.java @@ -30,7 +30,7 @@ class C extends A { } public class virtualcalltest { - public static void main() { + public static void main(String str[]) { A a=null; B b=new B(); -- 2.34.1