Merge change 3499
* changes: Make a host version of acc for testing.
This commit is contained in:
commit
5b533bea52
7 changed files with 96 additions and 44 deletions
|
@ -1,9 +1,8 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
#
|
||||
# Shared library
|
||||
#
|
||||
# Shared library for target
|
||||
# ========================================================
|
||||
|
||||
LOCAL_MODULE:= libacc
|
||||
LOCAL_SRC_FILES := acc.cpp
|
||||
|
@ -16,4 +15,23 @@ LOCAL_SHARED_LIBRARIES := libdl libcutils
|
|||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
||||
# Shared library for host
|
||||
# ========================================================
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE:= libacc
|
||||
LOCAL_SRC_FILES := acc.cpp
|
||||
|
||||
ifeq ($(TARGET_ARCH),arm)
|
||||
LOCAL_SRC_FILES += disassem.cpp
|
||||
endif
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := libcutils
|
||||
LOCAL_LDLIBS := -ldl
|
||||
|
||||
include $(BUILD_HOST_SHARED_LIBRARY)
|
||||
|
||||
# Build children
|
||||
# ========================================================
|
||||
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
||||
|
|
|
@ -1087,26 +1087,6 @@ class Compiler : public ErrorSink {
|
|||
size_t mPosition;
|
||||
};
|
||||
|
||||
int ch; // Current input character, or EOF
|
||||
intptr_t tok; // token
|
||||
intptr_t tokc; // token extra info
|
||||
int tokl; // token operator level
|
||||
intptr_t rsym; // return symbol
|
||||
intptr_t loc; // local variable index
|
||||
char* glo; // global variable index
|
||||
char* sym_stk;
|
||||
char* dstk; // Define stack
|
||||
char* dptr; // Macro state: Points to macro text during macro playback.
|
||||
int dch; // Macro state: Saves old value of ch during a macro playback.
|
||||
char* last_id;
|
||||
char* pGlobalBase;
|
||||
char* pVarsBase; // Value of variables
|
||||
|
||||
InputStream* file;
|
||||
|
||||
CodeBuf codeBuf;
|
||||
CodeGenerator* pGen;
|
||||
|
||||
class String {
|
||||
public:
|
||||
String() {
|
||||
|
@ -1306,6 +1286,8 @@ class Compiler : public ErrorSink {
|
|||
void pop() {
|
||||
if (mUsed > 0) {
|
||||
mUsed -= 1;
|
||||
} else {
|
||||
error("internal error: Popped empty stack.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1338,7 +1320,34 @@ class Compiler : public ErrorSink {
|
|||
size_t mSize;
|
||||
};
|
||||
|
||||
struct InputState {
|
||||
InputStream* pStream;
|
||||
int oldCh;
|
||||
};
|
||||
|
||||
|
||||
int ch; // Current input character, or EOF
|
||||
intptr_t tok; // token
|
||||
intptr_t tokc; // token extra info
|
||||
int tokl; // token operator level
|
||||
intptr_t rsym; // return symbol
|
||||
intptr_t loc; // local variable index
|
||||
char* glo; // global variable index
|
||||
char* sym_stk;
|
||||
char* dstk; // Define stack
|
||||
char* dptr; // Macro state: Points to macro text during macro playback.
|
||||
int dch; // Macro state: Saves old value of ch during a macro playback.
|
||||
char* last_id;
|
||||
char* pGlobalBase;
|
||||
char* pVarsBase; // Value of variables
|
||||
|
||||
InputStream* file;
|
||||
|
||||
CodeBuf codeBuf;
|
||||
CodeGenerator* pGen;
|
||||
|
||||
MacroTable mMacros;
|
||||
Array<InputState> mInputStateStack;
|
||||
|
||||
String mErrorBuf;
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
# Executable for host
|
||||
# ========================================================
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE:= acc
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
main.cpp
|
||||
|
@ -7,9 +11,22 @@ LOCAL_SRC_FILES:= \
|
|||
LOCAL_SHARED_LIBRARIES := \
|
||||
libacc
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
include $(BUILD_HOST_EXECUTABLE)
|
||||
|
||||
# Executable for target
|
||||
# ========================================================
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE:= acc
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
main.cpp
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libacc
|
||||
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
|
@ -1,7 +1,10 @@
|
|||
#define VALUE (2*FOO)
|
||||
#define FOO 12
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
return f();
|
||||
}
|
||||
|
||||
int f() {
|
||||
return 10;
|
||||
return VALUE;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ int run(MainPtr mainFunc, int argc, char** argv) {
|
|||
int main(int argc, char** argv) {
|
||||
const char* inFile = NULL;
|
||||
bool printListing;
|
||||
bool runResults = false;
|
||||
FILE* in = stdin;
|
||||
int i;
|
||||
for (i = 1; i < argc; i++) {
|
||||
|
@ -41,6 +42,9 @@ int main(int argc, char** argv) {
|
|||
case 'S':
|
||||
printListing = true;
|
||||
break;
|
||||
case 'R':
|
||||
runResults = true;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unrecognized flag %s\n", arg);
|
||||
return 3;
|
||||
|
@ -108,7 +112,7 @@ int main(int argc, char** argv) {
|
|||
accGetScriptLabel(script, "main", (ACCvoid**) & mainPointer);
|
||||
|
||||
result = accGetError(script);
|
||||
if (result == ACC_NO_ERROR) {
|
||||
if (result == ACC_NO_ERROR && runResults) {
|
||||
fprintf(stderr, "Executing compiled code:\n");
|
||||
int codeArgc = argc - i + 1;
|
||||
char** codeArgv = argv + i - 1;
|
||||
|
|
|
@ -6,4 +6,4 @@ cd ..
|
|||
mm -j8
|
||||
cd tests
|
||||
adb sync
|
||||
adb shell /system/bin/acc -S /system/bin/returnval-ansi.c
|
||||
adb shell /system/bin/acc -R -S /system/bin/returnval-ansi.c
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
#!/bin/sh
|
||||
rm -f test-acc
|
||||
cd ..
|
||||
g++ -I../include acc.cpp disassem.cpp tests/main.cpp -g -ldl -o tests/test-acc
|
||||
cd tests
|
||||
if [ -x "test-acc" ]; then
|
||||
./test-acc -S data/returnval-ansi.c
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$(uname)" = "Linux" ]; then
|
||||
if [ "$(uname -m)" = "i686" ]; then
|
||||
echo "Linux i686. Testing otcc-ansi.c"
|
||||
./test-acc data/otcc-ansi.c data/returnval.c
|
||||
echo "Linux i686. Testing otcc-ansi.c data/otcc.c"
|
||||
./test-acc data/otcc-ansi.c data/otcc.c data/returnval.c
|
||||
fi
|
||||
fi
|
||||
SCRIPT_DIR=`dirname $BASH_SOURCE`
|
||||
DATA=$SCRIPT_DIR/data
|
||||
|
||||
echo "Compiling returnval-ansi.c"
|
||||
acc -S $DATA/returnval-ansi.c
|
||||
|
||||
echo "Compiling whole compiler."
|
||||
acc -S "$DATA/otcc-ansi.c"
|
||||
|
||||
if (( "$(uname)" = "Linux" )) && (( "$(uname -m)" = "i686" )); then
|
||||
echo "Linux i686. Testing otcc-ansi.c"
|
||||
acc -R "$DATA/otcc-ansi.c" "$DATA/returnval.c"
|
||||
acc -R $DATA/otcc-ansi.c $DATA/otcc.c $DATA/returnval.c
|
||||
fi
|
||||
|
||||
echo "Done with tests."
|
||||
|
|
Loading…
Reference in a new issue