summaryrefslogtreecommitdiffstats
path: root/libacc/acc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libacc/acc.cpp')
-rw-r--r--libacc/acc.cpp51
1 files changed, 48 insertions, 3 deletions
diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index c52b992..73f7ef8 100644
--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -13,20 +13,20 @@
#include <ctype.h>
#include <errno.h>
+#include <limits.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+
#include <cutils/hashmap.h>
#if defined(__i386__)
#include <sys/mman.h>
#endif
-#if defined(__arm__)
-#include <unistd.h>
-#endif
#if defined(__arm__)
#define DEFAULT_ARM_CODEGEN
@@ -58,6 +58,15 @@
#define ENABLE_ARM_DISASSEMBLY
// #define PROVIDE_TRACE_CODEGEN
+// Uncomment to save input to a text file in DEBUG_DUMP_PATTERN
+// #define DEBUG_SAVE_INPUT_TO_FILE
+
+#ifdef ARM_USE_VFP
+#define DEBUG_DUMP_PATTERN "/sdcard/acc_dump/%d.c"
+#else
+#define DEBUG_DUMP_PATTERN "/tmp/acc_dump/%d.c"
+#endif
+
#define assert(b) assertImpl(b, __LINE__)
namespace acc {
@@ -5327,6 +5336,16 @@ class Compiler : public ErrorSink {
mLocals.add(pDecl);
}
+ bool checkUndeclaredStruct(Type* pBaseType) {
+ if (pBaseType->tag == TY_STRUCT && pBaseType->length < 0) {
+ String temp;
+ decodeToken(temp, pBaseType->structTag, false);
+ error("Undeclared struct %s", temp.getUnwrapped());
+ return true;
+ }
+ return false;
+ }
+
void localDeclarations(Type* pBaseType) {
intptr_t a;
@@ -5339,6 +5358,9 @@ class Compiler : public ErrorSink {
if (!pDecl->id) {
break;
}
+ if (checkUndeclaredStruct(pDecl)) {
+ break;
+ }
int variableAddress = 0;
addLocalSymbol(pDecl);
size_t alignment = pGen->alignmentOf(pDecl);
@@ -5436,6 +5458,11 @@ class Compiler : public ErrorSink {
continue;
}
+ if (checkUndeclaredStruct(pDecl)) {
+ skip(';');
+ continue;
+ }
+
if (! isDefined(pDecl->id)) {
addGlobalSymbol(pDecl);
}
@@ -5895,6 +5922,24 @@ void accScriptSource(ACCscript* script,
dest += len;
}
text[totalLength] = '\0';
+
+#ifdef DEBUG_SAVE_INPUT_TO_FILE
+ int counter;
+ char path[PATH_MAX];
+ for (counter = 0; counter < 4096; counter++) {
+ sprintf(path, DEBUG_DUMP_PATTERN, counter);
+ if(access(path, F_OK) != 0) {
+ break;
+ }
+ }
+ if (counter < 4096) {
+ FILE* fd = fopen(path, "w");
+ if (fd) {
+ fwrite(text, totalLength, 1, fd);
+ fclose(fd);
+ }
+ }
+#endif
}
extern "C"