offset = vd->offset;
}
-
- if (2 == size) {
-
- if (offset & 0x1) {
- scf_loge("memory align error\n");
- return -EINVAL;
- }
-
- offset >>= 1;
- SIZE = 1;
- D = rs->id & 0x1;
- V = rs->id >> 1;
-
- } else if (4 == size) {
+ if (4 == size) {
if (offset & 0x3) {
scf_loge("memory align error\n");
if (ret < 0)
return ret;
- opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (r12->id << 12) | (SIZE << 7) | r12->id;
+ opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (r12->id << 12) | (0x2 << 7) | r12->id;
inst = risc_make_inst(c, opcode);
RISC_INST_ADD_CHECK(c->instructions, inst);
return 0;
}
+int arm32_inst_G2PF(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, scf_register_t* rb, int32_t offset, int size)
+{
+ scf_register_t* r12 = f->rops->find_register("x12");
+ scf_instruction_t* inst = NULL;
+
+ uint32_t opcode;
+ uint32_t SIZE = 0;
+ uint32_t D = 0;
+ uint32_t Vd = 0;
+
+ if (offset & 0x3) {
+ scf_loge("memory align error\n");
+ return -EINVAL;
+ }
+
+ if (4 == size) {
+
+ D = rs->id & 0x1;
+ Vd = rs->id >> 1;
+
+ offset >>= 2;
+ SIZE = 2;
+
+ } else if (8 == size) {
+ D = rs->id >> 4;
+ Vd = rs->id & 0xf;
+
+ offset >>= 2;
+ SIZE = 3;
+ } else
+ return -EINVAL;
+
+ if (offset >= 0 && offset < 0xff)
+ opcode = (0xed << 24) | (0x8 << 20) | (D << 22) | (rb->id << 16) | (Vd << 12) | (0x2 << 10) | (SIZE << 8) | offset;
+
+ else if (offset < 0 && offset >= -0xff) {
+ offset = -offset;
+ opcode = (0xed << 24) | (0x0 << 20) | (D << 22) | (rb->id << 16) | (Vd << 12) | (0x2 << 10) | (SIZE << 8) | offset;
+
+ } else {
+ int ret = arm32_inst_I2G(c, r12, offset, 4);
+ if (ret < 0)
+ return ret;
+
+ opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (r12->id << 12) | (0x2 << 7) | r12->id;
+ inst = risc_make_inst(c, opcode);
+ RISC_INST_ADD_CHECK(c->instructions, inst);
+
+ opcode = (0xed << 24) | (0x8 << 20) | (D << 22) | (r12->id << 16) | (Vd << 12) | (0x2 << 10) | (SIZE << 8) | 0;
+ }
+
+ inst = risc_make_inst(c, opcode);
+ RISC_INST_ADD_CHECK(c->instructions, inst);
+
+ return 0;
+}
+
int arm32_inst_G2P(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, scf_register_t* rb, int32_t offset, int size)
{
scf_register_t* r12 = f->rops->find_register("x12");
- scf_register_t* ri = NULL;
scf_instruction_t* inst = NULL;
uint32_t opcode;
if (!rb)
return -EINVAL;
+ if (RISC_COLOR_TYPE(rs->color))
+ return arm32_inst_G2PF(c, f, rs, rb, offset, size);
+
if (1 == size) {
if (offset >= 0 && offset < 0xfff)
}
- if (2 == size) {
-
- if (offset & 0x1) {
- scf_loge("memory align error\n");
- return -EINVAL;
- }
-
- offset >>= 1;
- SIZE = 1;
- D = rd->id & 0x1;
- V = rd->id >> 1;
-
- } else if (4 == size) {
+ if (4 == size) {
if (offset & 0x3) {
scf_loge("memory align error\n");
if (ret < 0)
return ret;
- opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (r12->id << 12) | (SIZE << 7) | r12->id;
+ opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (r12->id << 12) | (0x2 << 7) | r12->id;
inst = risc_make_inst(c, opcode);
RISC_INST_ADD_CHECK(c->instructions, inst);
scf_instruction_t* inst;
uint32_t opcode;
- opcode = (0xee << 24) | (0xe << 20) | (rd->id << 12) | rs->id;
- inst = risc_make_inst(c, opcode);
+ uint32_t D;
+ uint32_t M;
+ uint32_t Vd;
+ uint32_t Vm;
+ uint32_t SIZE;
+
+ if (8 == rd->bytes) {
+ D = rd->id >> 4;
+ Vd = rd->id & 0xf;
+
+ M = rs->id >> 4;
+ Vm = rs->id & 0xf;
+
+ SIZE = 3;
+
+ } else {
+ D = rd->id & 0x1;
+ Vd = rd->id >> 1;
+
+ M = rs->id & 0x1;
+ Vm = rs->id >> 1;
+
+ SIZE = 2;
+ }
+
+ if (RISC_COLOR_TYPE(rd->color)) { // float to float register
+
+ opcode = (0xee << 24) | (0xb << 20) | (D << 22) | (Vd << 12) | (0x2 << 10) | (SIZE << 8) | (0x1 << 6) | (M << 5) | Vm;
+ inst = risc_make_inst(c, opcode);
+
+ } else { // float to general register
+
+ if (8 != rd->bytes) {
+ scf_loge("\n");
+ return NULL;
+ }
+
+ opcode = (0xec << 24) | (0x5 << 20) | ((rd->id + 1) << 16) | (rd->id << 12) | (0xb << 8) | (M << 5) | (0x1 << 4) | Vm;
+ inst = risc_make_inst(c, opcode);
+ }
return inst;
}
RISC_INST_ADD_CHECK(f->init_code->instructions, inst);
f->init_code_bytes += inst->len;
- uint32_t local = f->local_vars_size;
+ uint32_t local = f->local_vars_size + fp->bytes;
if (!(local & 0xf))
- local += 8;
+ local = (local + 0xf) & ~0xf;
if (local > 0xfff) {
local += 1 << 12;
int size = f->rops->variable_size (v);
int is_float = scf_variable_float(v);
- if (!rabi) {
+ if (!rabi || is_float != RISC_COLOR_TYPE(rabi->color)) {
+
rabi = f->rops->find_register_type_id_bytes(is_float, SCF_RISC_REG_X0, size);
ret = f->rops->overflow_reg(rabi, c, f);
}
}
- scf_loge("i: %d, size: %d, v: %s\n", i, size, v->w->text->data);
+ scf_loge("i: %d, size: %d, v: %s, rabi: %s\n", i, size, v->w->text->data, rabi->name);
movx = NULL;
}
RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
- rs = f->rops->find_register_color_bytes(rs->color, f->rops->MAX_BYTES);
+
+ rs = f->rops->find_register_color_bytes(rs->color, is_float ? 8 : f->rops->MAX_BYTES);
}
if (movx) {
if (!f->rops->color_conflict(rd->color, rs->color)) {
rd = f->rops->find_register_color_bytes(rd->color, rs->bytes);
+ scf_loge("i: %d, rd: %s, rs: %s\n", i, rd->name, rs->name);
+
if (!is_float)
inst = ctx->iops->MOV_G(c, rd, rs);
else
return ret;
}
- f->rops->call_rabi(c, f, NULL, NULL, NULL);
+ if (f->rops->call_rabi_varg && pf->vargs_flag)
+ f->rops->call_rabi_varg(c, f);
+ else
+ f->rops->call_rabi(c, f, NULL, NULL, NULL);
int32_t stack_size = _risc_inst_call_stack_size(c, f);
if (stack_size > 0) {
intptr_t id0 = c0 >> 16;
intptr_t id1 = c1 >> 16;
+ intptr_t t0 = c0 >> 24;
+ intptr_t t1 = c1 >> 24;
+
if (c0 & c1 & 0xffff) {
if (id0 == id1)
return 1;
- if (id0 == id1 + 1 && 0xff == (c1 & 0xffff))
- return 1;
+ if (0 == t0 && 0 == t1) {
+ if (id0 == id1 + 1 && 0xff == (c1 & 0xffff))
+ return 1;
- if (id0 == id1 - 1 && 0xff == (c0 & 0xffff))
- return 1;
+ if (id0 == id1 - 1 && 0xff == (c0 & 0xffff))
+ return 1;
+ }
}
return 0;
bp_int -= 8;
f->args_int += 2;
- scf_loge("i: %d, is_float: %d, size: %d, rid: %d, %s\n", i, is_float, size, rid, v->rabi->name);
+ scf_logd("i: %d, is_float: %d, size: %d, rid: %d, %s\n", i, is_float, size, rid, v->rabi->name);
continue;
}
}
if (nints < f->rops->ABI_NB) {
dn->rabi2 = f->rops->find_register_type_id_bytes(is_float, rid, size);
nints += 2;
- }
+ } else
+ dn->rabi2 = NULL;
}
src->rabi = dn->rabi2;
*p_ndoubles = ndoubles;
}
+void arm32_call_rabi_varg(scf_3ac_code_t* c, scf_function_t* f)
+{
+ scf_3ac_operand_t* src = NULL;
+ scf_dag_node_t* dn = NULL;
+
+ int nints = 0;
+ int i;
+
+ for (i = 1; i < c->srcs->size; i++) {
+ src = c->srcs->data[i];
+ dn = src->dag_node;
+ dn->rabi2 = NULL;
+
+ int size = f->rops->variable_size (dn->var);
+ int rid;
+
+ if (scf_variable_float(dn->var))
+ size = 8;
+
+ if (size <= 4) {
+
+ if (nints < f->rops->ABI_NB)
+ dn->rabi2 = f->rops->find_register_type_id_bytes(0, f->rops->abi_regs[nints++], size);
+
+ } else {
+ while (nints < f->rops->ABI_NB) {
+ rid = f->rops->abi_regs[nints];
+
+ if (!(rid & 0x1))
+ break;
+
+ nints++;
+ }
+
+ if (nints < f->rops->ABI_NB) {
+ dn->rabi2 = f->rops->find_register_type_id_bytes(0, rid, size);
+ nints += 2;
+ }
+ }
+
+ src->rabi = dn->rabi2;
+ }
+}
+
int arm32_push_callee_regs(scf_3ac_code_t* c, scf_function_t* f)
{
scf_instruction_t* inst;
.argv_rabi = arm32_argv_rabi,
.call_rabi = arm32_call_rabi,
+ .call_rabi_varg = arm32_call_rabi_varg,
.reg_used = arm32_reg_used,
.reg_cached_vars = arm32_reg_cached_vars,
void (*argv_rabi )(scf_function_t* f);
void (*call_rabi )(scf_3ac_code_t* c, scf_function_t* f, int* p_nints, int* p_nfloats, int* p_ndoubles);
+ void (*call_rabi_varg )(scf_3ac_code_t* c, scf_function_t* f);
int (*reg_used )(scf_register_t* r, scf_dag_node_t* dn);
int (*reg_cached_vars )(scf_register_t* r);
+++ /dev/null
-
-uint8* scf_malloc(int size);
-int scf_freep(uint8** pp);
-int scf_free_array(uint8** pp, int size);
-
-class Point
-{
- uint8* data;
-
- int __init__(Point* this, int size)
- {
- this->data = scf_malloc(size);
-
- return 0;
- }
-
-};
-
-int main(int i)
-{
- Point* pp[2] = {NULL, NULL};
- int err;
-
- i = 1;
-
- pp[i], err = create Point(8);
-
- pp[i] = NULL;
-
- return 0;
-}
+++ /dev/null
-
-uint8* scf_malloc(int size);
-
-class Point
-{
- int x;
- int y;
-
- int __init__(Point* this, int a, int b)
- {
- this->x = a;
- this->y = b;
- return 0;
- }
-
-};
-
-int main()
-{
- Point* p;
- int err;
-
- p, err = create Point(1, 2);
-
- if (-1 == err)
- return -1;
- return 0;
-}
-
+++ /dev/null
-
-int scf__brk (uint8_t* addr);
-uint8_t* scf__sbrk(uintptr_t inc);
-
-int scf_printf(const char* fmt, ...);
-
-struct scf_mblock_t
-{
- uintptr_t prev;
- uintptr_t next;
- uintptr_t size;
-};
-
-scf_mblock_t* scf__mblocks[30];
-scf_mblock_t* scf__free_blocks = NULL;
-uint8_t* scf__last_brk = NULL;
-
-uint8_t* scf__malloc(uintptr_t size)
-{
- scf_mblock_t* b;
- scf_mblock_t* b2;
-
- uintptr_t bytes = (sizeof(scf_mblock_t) + size + 63) >> 6 << 6;
- intptr_t nblocks = sizeof(scf__mblocks) / sizeof(scf__mblocks[0]);
-
- uintptr_t rest;
- uint8_t* addr = NULL;
- uint8_t* p = NULL;
- intptr_t i;
-
- for (i = 0; i < nblocks; i++) {
-
- if ((64 << i) < bytes)
- continue;
-
- if (scf__mblocks[i])
- break;
- }
-
- if (i == nblocks) {
-
- uintptr_t pages = (bytes + 4095) >> 12;
-
- p = scf__sbrk(pages << 12);
- if (!p)
- return NULL;
- scf__last_brk = p + (pages << 12);
-
- rest = (pages << 12) - bytes;
-
- b = (scf_mblock_t*)p;
-
- b->prev = 0x3;
- b->next = bytes;
-
- } else {
- b = scf__mblocks[i];
- scf__mblocks[i] = (scf_mblock_t*)b->size;
-
- uintptr_t bytes2;
- if (b->prev & 0x2)
- bytes2 = b->next;
- else
- bytes2 = b->next - (uintptr_t)b;
-
- p = (uint8_t*)b;
-
- rest = bytes2 - bytes;
- }
-
- addr = p + sizeof(scf_mblock_t);
-
- if (0 == rest) {
- scf_printf("74, b: %p, scf__last_brk: %#lx\n", b, scf__last_brk);
- return addr;
- }
-
- p += bytes;
- b2 = (scf_mblock_t*)p;
-
- for (; i >= 0; i--) {
-
- if (rest >= (64 << i)) {
- b2->size = (uintptr_t)scf__mblocks[i];
- scf__mblocks[i] = b2;
- break;
- }
- }
-
- b ->next = (uintptr_t)b2;
- b2->prev = (uintptr_t)b;
-
- if (b->prev & 0x2) {
- b2->prev |= 0x2;
- b2->prev &= ~0x4;
- b ->prev &= ~0x2;
- b2->next = rest;
- }
-
- scf_printf("100, b: %p, scf__last_brk: %#lx\n", b, scf__last_brk);
- return addr;
-}
-
-int scf__free(uint8_t* p)
-{
- p -= sizeof(scf_mblock_t);
-
- scf_mblock_t* b = (scf_mblock_t*)p;
- scf_mblock_t* b2;
- scf_mblock_t* b3;
- scf_mblock_t** pb;
-
- uintptr_t bytes;
- if (b->prev & 0x2)
- bytes = b->next;
- else
- bytes = b->next - (uintptr_t)b;
-
- intptr_t nblocks = sizeof(scf__mblocks) / sizeof(scf__mblocks[0]);
- intptr_t i;
-
- for (i = nblocks - 1; i >= 0; i--) {
-
- if (bytes >= (64 << i))
- break;
- }
-
- while (!(b->prev & 0x2)) {
-
- b2 = (scf_mblock_t*)b->next;
-
- uintptr_t bytes2;
- if (b2->prev & 0x2)
- bytes2 = b2->next;
- else
- bytes2 = b2->next - (uintptr_t)b2;
-
- for (i = nblocks - 1; i >= 0; i--) {
-
- if (bytes2 >= (64 << i))
- break;
- }
-
- for (pb = &scf__mblocks[i]; *pb; pb = (scf_mblock_t**)&(*pb)->size) {
-
- if (*pb == b2)
- break;
- }
- if (!*pb)
- break;
-
- *pb = (scf_mblock_t*)b2->size;
-
- bytes += bytes2;
-
- if (b2->prev & 0x2) {
- b->prev |= 0x2;
- b->next = bytes;
- } else {
- b3 = (scf_mblock_t*)b2->next;
- b->next = b2->next;
- b3->prev = (uintptr_t)b | (b3->prev & 0x3);
- }
- }
-
- while (!(b->prev & 0x1)) {
-
- b2 = (scf_mblock_t*)(b->prev & ~0x7);
-
- uintptr_t bytes2 = (uintptr_t)b - (uintptr_t)b2;
-
- for (i = nblocks - 1; i >= 0; i--) {
-
- if (bytes2 >= (64 << i))
- break;
- }
-
- for (pb = &scf__mblocks[i]; *pb; pb = (scf_mblock_t**)&(*pb)->size) {
- if (*pb == b2)
- break;
- }
- if (!*pb)
- break;
-
- *pb = (scf_mblock_t*)b2->size;
-
- bytes += bytes2;
-
- if (b->prev & 0x2) {
- b2->prev |= 0x2;
- b2->next = bytes;
-
- } else {
- b3 = (scf_mblock_t*)b->next;
- b2->next = b->next;
- b3->prev = (uintptr_t)b2 | (b3->prev & 0x3);
- }
-
- b = b2;
- }
-
- if (b->prev & 0x2)
- bytes = b->next;
- else
- bytes = b->next - (uintptr_t)b;
-
- if (0x3 == (b->prev) & 0x3) {
-
- if (scf__last_brk == (uint8_t*)b + bytes) {
-
- scf_printf("211, b: %p, scf__last_brk: %#lx\n", b, scf__last_brk);
-
- scf__last_brk = (uint8_t*)b;
- scf__brk((uint8_t*)b);
-
- int flag = 1;
- while (flag) {
- flag = 0;
-
- pb = &scf__free_blocks;
- while (*pb) {
-
- b = *pb;
- bytes = b->next;
-
- if (scf__last_brk != (uint8_t*)b + bytes) {
-
- pb = (scf_mblock_t**)&b->size;
- continue;
- }
- *pb = (scf_mblock_t*)b->size;
-
- scf_printf("232, b: %p, scf__last_brk: %#lx\n", b, scf__last_brk);
-
- scf__last_brk = (uint8_t*)b;
- scf__brk((uint8_t*)b);
- flag = 1;
- }
- }
- } else {
- b->size = (uintptr_t)scf__free_blocks;
- scf__free_blocks = b;
- scf_printf("242, b: %p, scf__last_brk: %#lx\n", b, scf__last_brk);
- }
- return 0;
- }
-
- for (i = nblocks - 1; i >= 0; i--) {
- if (bytes >= (64 << i))
- break;
- }
-
- b->size = (uintptr_t)scf__mblocks[i];
- scf__mblocks[i] = b;
-
- scf_printf("255, b: %p\n", b);
- return 0;
-}
-
-int main()
-{
- uint8_t* p0 = scf__malloc(1000);
- uint8_t* p1 = scf__malloc(1320);
- uint8_t* p2 = scf__malloc(2510);
- uint8_t* p3 = scf__malloc(4510);
- uint8_t* p4 = scf__malloc(510);
- uint8_t* p5 = scf__malloc(6510);
- uint8_t* p6 = scf__malloc(510);
- uint8_t* p7 = scf__malloc(11510);
-
- scf__free(p0);
-
- *p1 = 1;
- scf__free(p1);
-
- *p2 = 2;
- *p4 = 4;
-
- scf__free(p4);
- scf__free(p5);
- scf__free(p2);
- scf__free(p6);
- scf__free(p3);
-
- scf__free(p7);
- return 0;
-}
-
+++ /dev/null
-int printf(char* fmt, int a);
-
-class Point;
-
-Point* malloc(int size);
-
-class Point
-{
- int x;
- int y;
-
- Point* operator+(Point* p0, Point* p1)
- {
- Point* p = malloc(sizeof(Point));
- if (p) {
- p->x = p0->x + p1->x;
- p->y = p0->y + p1->y;
- }
- return p;
- }
-};
-
-int main()
-{
- Point p0 = {1, 2};
- Point p1 = {3, 4};
-
- Point* pp0 = &p0;
- Point* pp1 = &p1;
-
- Point* pp2 = pp0 + pp1;
-
- printf("pp2->x: %d\n", pp2->x);
- printf("pp2->y: %d\n", pp2->y);
- return 0;
-}
+++ /dev/null
-int printf(char* fmt, int a);
-
-class Point
-{
- int x;
- int y;
-};
-
-int cmp_pt(Point* v0, Point* v1);
-
-int cmp_point(Point* p0, Point* p1)
-{
- if (p0->x < p1->x)
- return -1;
- else if (p0->x > p1->x)
- return 1;
- return 0;
-}
-
-int sort(Point** a, cmp_pt* cmp, int m, int n)
-{
- if (m >= n)
- return 0;
-
- int i = m;
- int j = n;
-
- Point* t = a[i];
-
- while (i < j) {
-
- while (i < j && cmp(t, a[j]) < 0)
- j--;
-
- a[i] = a[j];
- a[j] = t;
-
- while (i < j && cmp(a[i], t) < 0)
- i++;
- a[j] = a[i];
- a[i] = t;
- }
-
- sort(a, cmp, m, i - 1);
- sort(a, cmp, i + 1, n);
- return 0;
-}
-
-int main()
-{
- Point p0 = {0, 1};
- Point p1 = {4, 1};
- Point p2 = {2, 1};
- Point p3 = {3, 1};
- Point p4 = {1, 1};
-
- Point* pp[5] = {&p0, &p1, &p2, &p3, &p4};
-
- Point** a = (Point**)pp;
-
- sort(a, cmp_point, 0, 4);
-
- int i;
- for (i = 0; i < 5; i++) {
- printf("%d\n", pp[i]->x);
- }
-
- return 0;
-}
+++ /dev/null
-
-include "../lib/scf_rbtree.c";
-
-struct rbtree_test_t
-{
- scf_rbtree_node_t node;
- int d;
-};
-
-static int test_cmp(scf_rbtree_node_t* node0, void* data)
-{
- rbtree_test_t* v0 = (rbtree_test_t*)node0;
- rbtree_test_t* v1 = (rbtree_test_t*)data;
-
- if (v0->d < v1->d)
- return -1;
- else if (v0->d > v1->d)
- return 1;
- return 0;
-}
-
-static int test_find(scf_rbtree_node_t* node0, void* data)
-{
- rbtree_test_t* v0 = (rbtree_test_t*)node0;
- int d1 = (intptr_t)data;
-
- if (v0->d < d1)
- return -1;
- else if (v0->d > d1)
- return 1;
- return 0;
-}
-
-static int test_print(scf_rbtree_node_t* node0, void* data)
-{
- rbtree_test_t* v0 = (rbtree_test_t*)node0;
-
- scf_printf("v0->d: %d\n", v0->d);
- return 0;
-}
-
-const int N = 37;
-
-int main()
-{
- scf_rbtree_t tree;
- scf_rbtree_init(&tree);
-
- rbtree_test_t* d;
-
- int i;
- for (i = 0; i < N; i++) {
- d = scf__calloc(1, sizeof(rbtree_test_t));
-
- d->d = i;
-
- int ret = scf_rbtree_insert(&tree, &d->node, test_cmp);
- if (ret < 0)
- return -1;
- }
-
- scf_rbtree_foreach(&tree, tree->root, NULL, test_print);
-
- scf_rbtree_depth(&tree, tree->root);
-
- for (i = 0; i < N / 2; i++) {
- d = (rbtree_test_t*) scf_rbtree_find(&tree, (void*)(intptr_t)i, test_find);
-
- int ret = scf_rbtree_delete(&tree, &d->node);
-
- scf__free(d);
- d = NULL;
- }
-
- scf_rbtree_foreach(&tree, tree->root, NULL, test_print);
-
- scf_rbtree_depth(&tree, tree->root);
-
- for (i = 0; i < N / 2; i++) {
- d = scf__calloc(1, sizeof(rbtree_test_t));
-
- d->d = i;
-
- int ret = scf_rbtree_insert(&tree, &d->node, test_cmp);
- if (ret < 0)
- return -1;
- }
- scf_rbtree_foreach_reverse(&tree, tree->root, NULL, test_print);
-
- scf_rbtree_depth(&tree, tree->root);
-
- for (i = 0; i < N; i++) {
- d = (rbtree_test_t*) scf_rbtree_find(&tree, (void*)(intptr_t)i, test_find);
-
- int ret = scf_rbtree_delete(&tree, &d->node);
-
- scf__free(d);
- d = NULL;
- }
-
- scf_rbtree_foreach_reverse(&tree, tree->root, NULL, test_print);
- scf_rbtree_depth(&tree, tree->root);
-
- scf_printf("tree->root: %p, sentinel: %p\n", tree->root, tree->sentinel);
- return 0;
-}
-
+++ /dev/null
-struct va_list
-{
- uint8_t* iptr;
- uint8_t* fptr;
- uint8_t* optr;
-
- intptr_t ireg;
- intptr_t freg;
- intptr_t others;
-};
-
-int scf__write(int fd, uint8_t* buf, uint64_t size);
-
-int scf_ulong2a(char* buf, int* pn, int size, uint64_t num)
-{
- int n = *pn;
- int i = n;
-
- while (n < size - 1) {
-
- buf[n++] = num % 10 + '0';
-
- num /= 10;
- if (0 == num)
- break;
- }
-
- *pn = n--;
-
- while (i < n) {
- char c = buf[i];
- buf[i++] = buf[n];
- buf[n--] = c;
- }
- return *pn;
-}
-
-int scf_long2a(char* buf, int* pn, int size, int64_t num)
-{
- int n = *pn;
-
- if (n < size - 1 && num < 0) {
- buf[n++] = '-';
- num = -num;
- }
-
- *pn = n;
- return scf_ulong2a(buf, pn, size, num);
-}
-
-int scf_hex2a(char* buf, int* pn, int size, uint64_t num)
-{
- int n = *pn;
- int i = n;
-
- while (n < size - 1) {
-
- uint8_t x = num % 16;
-
- if (x > 9)
- buf[n++] = x - 10 + 'a';
- else
- buf[n++] = x + '0';
-
- num /= 16;
- if (0 == num)
- break;
- }
-
- *pn = n--;
-
- while (i < n) {
- char c = buf[i];
- buf[i++] = buf[n];
- buf[n--] = c;
- }
- return *pn;
-}
-
-int scf_hex2a_prefix(char* buf, int* pn, int size, uint64_t num)
-{
- int n = *pn;
-
- if (n < size - 1 - 2) {
- buf[n++] = '0';
- buf[n++] = 'x';
- }
-
- *pn = n;
- return scf_hex2a(buf, pn, size, num);
-}
-
-int scf_p2a(char* buf, int* pn, int size, uint64_t num)
-{
- if (0 == num) {
- int n = *pn;
- char* p = "null";
-
- while (n < size - 1 && *p)
- buf[n++] = *p++;
-
- *pn = n;
- return n;
- }
-
- return scf_hex2a_prefix(buf, pn, size, num);
-}
-
-int scf_str2a(char* buf, int* pn, int size, const char* str)
-{
- int n = *pn;
-
- while (n < size - 1 && *str)
- buf[n++] = *str++;
-
- *pn = n;
- return n;
-}
-
-int scf_vsnprintf(char* buf, int size, const char* fmt, va_list* ap)
-{
- int n = 0;
-
- while (*fmt) {
-
- if ('%' != *fmt) {
- buf[n++] = *fmt++;
- continue;
- }
-
- fmt++;
- if ('%' == *fmt) {
- buf[n++] = *fmt++;
- continue;
- }
-
- int prefix = 0;
- if ('#' == *fmt) {
- prefix++;
- fmt++;
- }
-
- int l = 0;
- if ('l' == *fmt) {
- l++;
- fmt++;
- }
-
- if ('c' == *fmt)
- buf[n++] = va_arg(ap, int32_t);
-
- else if ('u' == *fmt) {
- if (l)
- scf_ulong2a(buf, &n, size, va_arg(ap, uint64_t));
- else
- scf_ulong2a(buf, &n, size, va_arg(ap, uint32_t));
-
- } else if ('d' == *fmt) {
- if (l)
- scf_long2a(buf, &n, size, va_arg(ap, int64_t));
- else
- scf_long2a(buf, &n, size, va_arg(ap, int32_t));
-
- } else if ('x' == *fmt) {
- if (prefix) {
- if (l)
- scf_hex2a_prefix(buf, &n, size, va_arg(ap, uint64_t));
- else
- scf_hex2a_prefix(buf, &n, size, va_arg(ap, uint32_t));
- } else {
- if (l)
- scf_hex2a(buf, &n, size, va_arg(ap, uint64_t));
- else
- scf_hex2a(buf, &n, size, va_arg(ap, uint32_t));
- }
- } else if ('p' == *fmt)
- scf_p2a(buf, &n, size, va_arg(ap, uint64_t));
-
- else if ('s' == *fmt)
- scf_str2a(buf, &n, size, va_arg(ap, char*));
- else
- return -1;
-
- fmt++;
- }
-
- buf[n] = '\0';
- return n;
-}
-
-int scf_printf(const char* fmt, ...)
-{
- va_list ap;
-
- char buf[100];
-
- va_start(ap, fmt);
- int ret = scf_vsnprintf(buf, sizeof(buf) - 1, fmt, &ap);
- va_end(ap);
-
- if (ret > 0) {
- ret = scf__write(1, buf, ret);
- }
-
- return ret;
-}
-
-int main()
-{
- int64_t i64 = -1245;
-
- int ret = scf_printf("hello: %u, %x, %d, %ld, %p, %s\n", 1234, 0x7f1c, -5, i64, &i64, "world");
- return ret;
-}
-
+++ /dev/null
-struct va_list
-{
- uint8_t* iptr;
- uint8_t* fptr;
- uint8_t* optr;
-
- intptr_t ireg;
- intptr_t freg;
- intptr_t others;
-};
-
-int scf__write(int fd, uint8_t* buf, uint64_t size);
-
-int scf_ulong2a(char* buf, int* pn, int size, uint64_t num)
-{
- int n = *pn;
- int i = n;
-
- while (n < size - 1) {
-
- buf[n++] = num % 10 + '0';
-
- num /= 10;
- if (0 == num)
- break;
- }
-
- *pn = n--;
-
- while (i < n) {
- char c = buf[i];
- buf[i++] = buf[n];
- buf[n--] = c;
- }
- return *pn;
-}
-
-int scf_long2a(char* buf, int* pn, int size, int64_t num)
-{
- int n = *pn;
-
- if (n < size - 1 && num < 0) {
- buf[n++] = '-';
- num = -num;
- }
-
- *pn = n;
- return scf_ulong2a(buf, pn, size, num);
-}
-
-int scf_hex2a(char* buf, int* pn, int size, uint64_t num)
-{
- int n = *pn;
- int i = n;
-
- while (n < size - 1) {
-
- uint8_t x = num % 16;
-
- if (x > 9)
- buf[n++] = x - 10 + 'a';
- else
- buf[n++] = x + '0';
-
- num /= 16;
- if (0 == num)
- break;
- }
-
- *pn = n--;
-
- while (i < n) {
- char c = buf[i];
- buf[i++] = buf[n];
- buf[n--] = c;
- }
- return *pn;
-}
-
-int scf_hex2a_prefix(char* buf, int* pn, int size, uint64_t num)
-{
- int n = *pn;
-
- if (n < size - 1 - 2) {
- buf[n++] = '0';
- buf[n++] = 'x';
- }
-
- *pn = n;
- return scf_hex2a(buf, pn, size, num);
-}
-
-int scf_p2a(char* buf, int* pn, int size, uint64_t num)
-{
- if (0 == num) {
- int n = *pn;
- char* p = "null";
-
- while (n < size - 1 && *p)
- buf[n++] = *p++;
-
- *pn = n;
- return n;
- }
-
- return scf_hex2a_prefix(buf, pn, size, num);
-}
-
-int scf_str2a(char* buf, int* pn, int size, const char* str)
-{
- int n = *pn;
-
- while (n < size - 1 && *str)
- buf[n++] = *str++;
-
- *pn = n;
- return n;
-}
-
-int scf_double2a(char* buf, int* pn, int size, double num)
-{
- if (*pn < size - 1 && num < 0.0) {
- buf[(*pn)++] = '-';
- num = -num;
- }
-
- int64_t l = (int64_t)num;
- int64_t diff = (int64_t)((num - l) * 1000000);
-
- scf_ulong2a(buf, pn, size, l);
-
- if (*pn < size - 1)
- buf[(*pn)++] = '.';
-
- return scf_ulong2a(buf, pn, size, diff);
-}
-
-int scf_vsnprintf(char* buf, int size, const char* fmt, va_list* ap)
-{
- int n = 0;
-
- while (*fmt) {
-
- if ('%' != *fmt) {
- buf[n++] = *fmt++;
- continue;
- }
-
- fmt++;
- if ('%' == *fmt) {
- buf[n++] = *fmt++;
- continue;
- }
-
- int prefix = 0;
- if ('#' == *fmt) {
- prefix++;
- fmt++;
- }
-
- int l = 0;
- if ('l' == *fmt) {
- l++;
- fmt++;
- }
-
- if ('c' == *fmt)
- buf[n++] = va_arg(ap, int32_t);
-
- else if ('u' == *fmt) {
- if (l)
- scf_ulong2a(buf, &n, size, va_arg(ap, uint64_t));
- else
- scf_ulong2a(buf, &n, size, va_arg(ap, uint32_t));
-
- } else if ('d' == *fmt) {
- if (l)
- scf_long2a(buf, &n, size, va_arg(ap, int64_t));
- else
- scf_long2a(buf, &n, size, va_arg(ap, int32_t));
-
- } else if ('x' == *fmt) {
- if (prefix) {
- if (l)
- scf_hex2a_prefix(buf, &n, size, va_arg(ap, uint64_t));
- else
- scf_hex2a_prefix(buf, &n, size, va_arg(ap, uint32_t));
- } else {
- if (l)
- scf_hex2a(buf, &n, size, va_arg(ap, uint64_t));
- else
- scf_hex2a(buf, &n, size, va_arg(ap, uint32_t));
- }
- } else if ('p' == *fmt)
- scf_p2a(buf, &n, size, va_arg(ap, uint64_t));
-
- else if ('s' == *fmt)
- scf_str2a(buf, &n, size, va_arg(ap, char*));
-
- else if ('f' == *fmt)
- scf_double2a(buf, &n, size, va_arg(ap, double));
- else
- return -1;
-
- fmt++;
- }
-
- buf[n] = '\0';
- return n;
-}
-
-int scf_printf(const char* fmt, ...)
-{
- va_list ap;
-
- char buf[100];
-
- va_start(ap, fmt);
- int ret = scf_vsnprintf(buf, sizeof(buf) - 1, fmt, &ap);
- va_end(ap);
-
- if (ret > 0) {
- ret = scf__write(1, buf, ret);
- }
-
- return ret;
-}
-
-int main()
-{
- int ret = scf_printf("hello: %f, %f\n", 11.5, -1.5);
- return ret;
-}
-
+++ /dev/null
-int printf(char* fmt, ...);
-
-int main()
-{
- int a = 1;
-
- printf("a: %d\n", a);
- printf("hello\n");
- printf("a: %d, b: %d\n", a, 1);
- return 0;
-}