Skip to content

Commit a8b0112

Browse files
committed
run OK
1 parent 5721243 commit a8b0112

File tree

19 files changed

+1143
-870
lines changed

19 files changed

+1143
-870
lines changed

app.exe

72.9 KB
Binary file not shown.

app/c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ASMS2=$(CS:%.c=%.s)
77
all: $(TARGET)
88

99
$(TARGET): $(ASMS) $(ASMS2)
10-
clang -v -o $(TARGET) $(ASMS) $(ASMS2)
10+
clang -v -lm -o3 -o $(TARGET) $(ASMS) $(ASMS2)
1111
# strip $(TARGET)
1212

1313
%.ll: %.c

app/c/jni_func.c

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,185 @@
55
#include <time.h>
66
#include <unistd.h>
77

8+
#include "runner.h"
9+
810
int ptr_size() {
911
return sizeof(int *);
1012
}
1113

14+
// ====================== stack =====================
15+
union StackEntry *get_sp(struct StackFrame *stack) {
16+
return stack->sp;
17+
}
18+
19+
void set_sp(struct StackFrame *stack, union StackEntry *sp) {
20+
stack->sp = sp;
21+
}
22+
23+
void chg_sp(struct StackFrame *stack, int i) {
24+
stack->sp += i;
25+
}
26+
27+
union StackEntry *get_store(struct StackFrame *stack) {
28+
return stack->store;
29+
}
30+
31+
int get_stack_size(struct StackFrame *stack) {
32+
return stack->sp - stack->store;
33+
}
34+
35+
void push_i64(struct StackFrame *stack, long long i) {
36+
stack->sp->s64 = i;
37+
stack->sp++;
38+
stack->sp++;
39+
}
40+
41+
long long pop_i64(struct StackFrame *stack) {
42+
--stack->sp;
43+
return (--stack->sp)->s64;
44+
}
45+
46+
void push_i32(struct StackFrame *stack, int i) {
47+
stack->sp->s32 = i;
48+
stack->sp++;
49+
}
50+
51+
int pop_i32(struct StackFrame *stack) {
52+
return (--stack->sp)->s32;
53+
}
54+
55+
void push_i16(struct StackFrame *stack, short i) {
56+
stack->sp->s32 = i;
57+
stack->sp++;
58+
}
59+
60+
short pop_i16(struct StackFrame *stack) {
61+
return (short)(--stack->sp)->s32;
62+
}
63+
64+
void push_u16(struct StackFrame *stack, unsigned short i) {
65+
stack->sp->s32 = i;
66+
stack->sp++;
67+
}
68+
69+
unsigned short pop_u16(struct StackFrame *stack) {
70+
return (unsigned short)(--stack->sp)->s32;
71+
}
72+
73+
void push_i8(struct StackFrame *stack, char i) {
74+
stack->sp->s32 = i;
75+
stack->sp++;
76+
}
77+
78+
char pop_i8(struct StackFrame *stack) {
79+
return (char)(--stack->sp)->s32;
80+
}
81+
82+
void push_double(struct StackFrame *stack, double i) {
83+
stack->sp->f64 = i;
84+
stack->sp++;
85+
stack->sp++;
86+
}
87+
88+
double pop_double(struct StackFrame *stack) {
89+
--stack->sp;
90+
return (--stack->sp)->f64;
91+
}
92+
93+
void push_float(struct StackFrame *stack, float i) {
94+
stack->sp->f32 = i;
95+
stack->sp++;
96+
}
97+
98+
float pop_float(struct StackFrame *stack) {
99+
return (--stack->sp)->f32;
100+
}
101+
102+
void push_ptr(struct StackFrame *stack, void *i) {
103+
stack->sp->_ptr = i;
104+
stack->sp++;
105+
}
106+
107+
void *pop_ptr(struct StackFrame *stack) {
108+
return (--stack->sp)->_ptr;
109+
}
110+
111+
void push_entry(struct StackFrame *stack, long long i) {
112+
stack->sp->s64 = i;
113+
stack->sp++;
114+
}
115+
116+
long long pop_entry(struct StackFrame *stack) {
117+
return (--stack->sp)->s64;
118+
}
119+
120+
//====================== local var =====================
121+
122+
void localvar_set_i64(union StackEntry *base, int slot, long long i) {
123+
(base + slot)->s64 = i;
124+
}
125+
126+
long long localvar_get_i64(union StackEntry *base, int slot) {
127+
return (base + slot)->s64;
128+
}
129+
130+
void localvar_set_i32(union StackEntry *base, int slot, int i) {
131+
(base + slot)->s32 = i;
132+
}
133+
134+
int localvar_get_i32(union StackEntry *base, int slot) {
135+
return (base + slot)->s32;
136+
}
137+
138+
void localvar_set_i16(union StackEntry *base, int slot, short i) {
139+
(base + slot)->s32 = i;
140+
}
141+
142+
short localvar_get_i16(union StackEntry *base, int slot) {
143+
return (short)(base + slot)->s32;
144+
}
145+
146+
void localvar_set_u16(union StackEntry *base, int slot, unsigned short i) {
147+
(base + slot)->s32 = i;
148+
}
149+
150+
unsigned short localvar_get_u16(union StackEntry *base, int slot) {
151+
return (unsigned short)(base + slot)->s32;
152+
}
153+
154+
void localvar_set_i8(union StackEntry *base, int slot, char i) {
155+
(base + slot)->s32 = i;
156+
}
157+
158+
char localvar_get_i8(union StackEntry *base, int slot) {
159+
return (char)(base + slot)->s32;
160+
}
161+
162+
void localvar_set_double(union StackEntry *base, int slot, double i) {
163+
(base + slot)->f64 = i;
164+
}
165+
166+
double localvar_get_double(union StackEntry *base, int slot) {
167+
return (base + slot)->f64;
168+
}
169+
170+
void localvar_set_float(union StackEntry *base, int slot, float i) {
171+
(base + slot)->f32 = i;
172+
}
173+
174+
float localvar_get_float(union StackEntry *base, int slot) {
175+
return (base + slot)->f32;
176+
}
177+
178+
void localvar_set_ptr(union StackEntry *base, int slot, void *i) {
179+
(base + slot)->_ptr = i;
180+
}
181+
182+
void *localvar_get_ptr(union StackEntry *base, int slot) {
183+
return (base + slot)->_ptr;
184+
}
185+
186+
12187
long long java_lang_System_currentTimeMillis() {
13188
struct timeval tv;
14189
gettimeofday(&tv, NULL);
@@ -33,6 +208,10 @@ void java_io_PrintStream_println_J(void *ps, long long value) {
33208
printf("%lld\n", value);
34209
}
35210

211+
void java_io_PrintStream_println_D(void *ps, double value) {
212+
printf("%lf\n", value);
213+
}
214+
36215
void java_io_PrintStream_print_C(void *ps, unsigned short value) {
37216
printf("%c", (char) value);
38217
}

app/c/runner.c

Lines changed: 10 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
#include "runner.h"
77

8+
int max_stack_size = 20480;
9+
struct StackFrame *pthd_stack; //can be extends to multithread
10+
811
void classes_clinit();
912

1013
void test_Test_main();
@@ -13,135 +16,18 @@ void print_debug(int v) {
1316
printf("lldebug: %d \n", v);
1417
}
1518

16-
void print_ptr(long long v) {
17-
printf("ll_ptr: %llx (%lld)\n", v, v);
19+
void print_ptr(char *v) {
20+
printf("ll_ptr: %llx (%lld)\n", (long long)(intptr_t)v, (long long)(intptr_t)v);
1821
}
1922

20-
typedef union _SlotEntry{
21-
char ch;
22-
short s16;
23-
unsigned short u16;
24-
int s32;
25-
unsigned int u32;
26-
long long s64;
27-
unsigned long long u64;
28-
float f32;
29-
double f64;
30-
void *_ptr;
31-
}SlotEntry;
32-
3323
int main() {
34-
SlotEntry slot;
35-
slot.s32=40;
36-
print_ptr(slot.s64);
24+
pthd_stack = malloc(sizeof(struct StackFrame));
25+
pthd_stack->store = malloc(sizeof(union StackEntry) * max_stack_size);
26+
pthd_stack->sp = pthd_stack->store;
27+
3728
classes_clinit();
3829
test_Test_main();
39-
}
40-
41-
/*
42-
inline s32 stack_size(RuntimeStack *stack) {
43-
return (stack->sp - stack->store);
44-
}
45-
46-
47-
inline void push_int(RuntimeStack *stack, s32 value) {
48-
stack->sp->ivalue = value;//clear 64bit
49-
stack->sp->type = STACK_ENTRY_INT;
50-
stack->sp++;
51-
}
52-
53-
inline s32 pop_int(RuntimeStack *stack) {
54-
stack->sp--;
55-
return stack->sp->ivalue;
56-
}
57-
58-
59-
inline void push_double(RuntimeStack *stack, f64 value) {
60-
stack->sp->dvalue = value;
61-
stack->sp->type = STACK_ENTRY_DOUBLE;
62-
stack->sp++;
63-
stack->sp->type = STACK_ENTRY_DOUBLE;
64-
// ptr->dvalue = value;
65-
stack->sp++;
66-
}
67-
68-
inline f64 pop_double(RuntimeStack *stack) {
69-
stack->sp -= 2;
70-
return stack->sp->dvalue;
71-
}
72-
73-
inline void push_float(RuntimeStack *stack, f32 value) {
74-
//ptr->lvalue = 0;//clear 64bit
75-
stack->sp->fvalue = value;
76-
stack->sp->type = STACK_ENTRY_FLOAT;
77-
stack->sp++;
78-
}
79-
80-
inline f32 pop_float(RuntimeStack *stack) {
81-
stack->sp--;
82-
return stack->sp->fvalue;
83-
}
84-
85-
86-
inline void push_long(RuntimeStack *stack, s64 value) {
87-
stack->sp->lvalue = value;
88-
stack->sp->type = STACK_ENTRY_LONG;
89-
stack->sp++;
90-
stack->sp->type = STACK_ENTRY_LONG;
91-
// ptr->lvalue = value;
92-
stack->sp++;
93-
}
94-
95-
inline s64 pop_long(RuntimeStack *stack) {
96-
stack->sp -= 2;
97-
return stack->sp->lvalue;
98-
}
99-
100-
inline void push_ref(RuntimeStack *stack, __refer value) {
101-
stack->sp->type = STACK_ENTRY_REF;
102-
stack->sp->rvalue = value;
103-
stack->sp++;
104-
}
105-
106-
inline __refer pop_ref(RuntimeStack *stack) {
107-
stack->sp--;
108-
return stack->sp->rvalue;
109-
}
110-
111-
112-
inline void push_entry(RuntimeStack *stack, StackEntry *entry) {
113-
stack->sp->lvalue = entry->lvalue;
114-
stack->sp->type = entry->type;
115-
stack->sp++;
116-
}
117-
118-
inline void pop_entry(RuntimeStack *stack, StackEntry *entry) {
119-
stack->sp--;
120-
entry->lvalue = stack->sp->lvalue;
121-
entry->type = stack->sp->type;
12230

31+
free(pthd_stack);
12332
}
12433

125-
inline void pop_empty(RuntimeStack *stack) {
126-
stack->sp--;
127-
}
128-
129-
130-
inline void peek_entry(StackEntry *src, StackEntry *dst) {
131-
dst->lvalue = src->lvalue;
132-
dst->type = src->type;
133-
}
134-
135-
136-
inline s32 entry_2_int(StackEntry *entry) {
137-
return entry->ivalue;
138-
}
139-
140-
inline s64 entry_2_long(StackEntry *entry) {
141-
return entry->lvalue;
142-
}
143-
144-
inline __refer entry_2_refer(StackEntry *entry) {
145-
return entry->rvalue;
146-
}
147-
*/

0 commit comments

Comments
 (0)