Mercurial > hg > CbC > old > device
comparison mc-code-powerpc.c @ 327:da2e3f2d127d
macro/codegen reorganization
author | kono |
---|---|
date | Mon, 21 Jun 2004 23:50:34 +0900 (2004-06-21) |
parents | e5d40f8c4cce |
children | 7ecb023d29b8 |
comparison
equal
deleted
inserted
replaced
326:e5d40f8c4cce | 327:da2e3f2d127d |
---|---|
1 /* Micro-C Code Generation Part for Power PC (Mac OS X) */ | 1 /* Micro-C Code Generation Part for Power PC (Mac OS X) */ |
2 /* $Id$ */ | 2 /* $Id$ */ |
3 | 3 |
4 #define EXTERN extern | 4 #include <stdio.h> |
5 #include "mc.h" | 5 #include "mc.h" |
6 #include "mc-parse.h" | |
6 #include "mc-code.h" | 7 #include "mc-code.h" |
7 #include "mc-codegen.h" | 8 #include "mc-codegen.h" |
8 | 9 |
9 char *l_include_path[] = { | 10 char *l_include_path[] = { |
10 "/usr/include/", | 11 "/usr/include/", |
11 0 | 12 0 |
12 }; | 13 }; |
13 | 14 |
14 // __builtin_expect(a,t) branch prediction | 15 // __builtin_expect(a,t) branch prediction |
15 | 16 |
16 char *init_src = "\ | 17 static |
18 char *init_src0 = "\ | |
17 #define __ppc__ 1\n\ | 19 #define __ppc__ 1\n\ |
18 #define __BIG_ENDIAN__ 1\n\ | 20 #define __BIG_ENDIAN__ 1\n\ |
19 #define __STDC__ 1\n\ | 21 #define __STDC__ 1\n\ |
20 #define __builtin_va_list int\n\ | 22 #define __builtin_va_list int\n\ |
21 #define __builtin_va_start(ap,arg) ap=(((int)(&arg))+sizeof(arg))\n\ | 23 #define __builtin_va_start(ap,arg) ap=(((int)(&arg))+sizeof(arg))\n\ |
58 #define SIZE_OF_SHORT 2 | 60 #define SIZE_OF_SHORT 2 |
59 #define SIZE_OF_FLOAT 4 | 61 #define SIZE_OF_FLOAT 4 |
60 #define SIZE_OF_DOUBLE 8 | 62 #define SIZE_OF_DOUBLE 8 |
61 #define SIZE_OF_LONGLONG 8 | 63 #define SIZE_OF_LONGLONG 8 |
62 #define ENDIAN 1 | 64 #define ENDIAN 1 |
63 | |
64 int size_of_int = SIZE_OF_INT; | |
65 int size_of_short = SIZE_OF_SHORT; | |
66 int size_of_float = SIZE_OF_FLOAT; | |
67 int size_of_double = SIZE_OF_DOUBLE; | |
68 int size_of_longlong = SIZE_OF_LONGLONG; | |
69 int endian = ENDIAN; | |
70 | 65 |
71 static int reg_sp; /* REGister Stack-Pointer */ | 66 static int reg_sp; /* REGister Stack-Pointer */ |
72 static int reg_stack[MAX_MAX]; /* �ºݤΥ쥸�������ΰ� */ | 67 static int reg_stack[MAX_MAX]; /* �ºݤΥ쥸�������ΰ� */ |
73 | 68 |
74 /* floating point registers */ | 69 /* floating point registers */ |
411 } | 406 } |
412 | 407 |
413 void | 408 void |
414 code_init(void) | 409 code_init(void) |
415 { | 410 { |
416 #if 0 | 411 /* called only once */ |
417 macro_define("__ppc__ 1\n"); | 412 |
418 macro_define("__BIG_ENDIAN__ 1\n"); | 413 init_src = init_src0; |
419 // macro_define("_BSD_CT_RUNE_T_ int\n"); | 414 size_of_int = SIZE_OF_INT; |
420 // macro_define("__STDC__ 1\n"); | 415 size_of_short = SIZE_OF_SHORT; |
421 macro_define("__builtin_va_list int\n"); | 416 size_of_float = SIZE_OF_FLOAT; |
422 #endif | 417 size_of_double = SIZE_OF_DOUBLE; |
418 size_of_longlong = SIZE_OF_LONGLONG; | |
419 endian = ENDIAN; | |
420 | |
423 init_ptr_cache(); | 421 init_ptr_cache(); |
424 regv_l(RET_LREGISTER) = RET_LREGISTER_L; | 422 regv_l(RET_LREGISTER) = RET_LREGISTER_L; |
425 regv_h(RET_LREGISTER) = RET_LREGISTER_H; | 423 regv_h(RET_LREGISTER) = RET_LREGISTER_H; |
426 } | 424 } |
427 | 425 |
426 extern void | |
427 emit_reinit() | |
428 { | |
429 /* called for each file */ | |
430 } | |
431 | |
428 void | 432 void |
429 gexpr_code_init(void){ | 433 gexpr_code_init(void){ |
430 #if 0 | |
431 int new_reg,old_reg,dm; | |
432 /* register shuffling */ | |
433 if (is_int_reg(creg)) { | |
434 dm = get_register(); | |
435 new_reg = get_register(); | |
436 old_reg = creg; | |
437 ireg = creg = new_reg; | |
438 free_register(old_reg); | |
439 free_register(dm); | |
440 } else if (is_float_reg(creg)) { | |
441 dm = get_dregister(1); | |
442 new_reg = get_dregister(1); | |
443 old_reg = creg; | |
444 freg = creg = new_reg; | |
445 free_register(old_reg); | |
446 free_register(dm); | |
447 } | |
448 #endif | |
449 } | 434 } |
450 | 435 |
451 void | 436 void |
452 code_gexpr(int e){ | 437 code_gexpr(int e){ |
453 // if (is_int_reg(creg) && creg!=ireg) error(-1); | 438 // if (is_int_reg(creg) && creg!=ireg) error(-1); |
959 | 944 |
960 void | 945 void |
961 | 946 |
962 emit_init(void) | 947 emit_init(void) |
963 { | 948 { |
949 /* called before each declaration */ | |
950 | |
964 free_all_register(); | 951 free_all_register(); |
965 max_reg_var=-1; max_freg_var=-1; | 952 max_reg_var=-1; max_freg_var=-1; |
966 reg_sp = 0; | 953 reg_sp = 0; |
967 freg_sp = 0; | 954 freg_sp = 0; |
968 text_mode(); | 955 text_mode(); |
2717 control=0; | 2704 control=0; |
2718 if (chk) return; | 2705 if (chk) return; |
2719 printf("\tb\tL_%d\n",l); | 2706 printf("\tb\tL_%d\n",l); |
2720 } | 2707 } |
2721 | 2708 |
2722 void | 2709 extern void |
2723 gen_comment(char *s) | 2710 gen_comment(char *s) |
2724 { | 2711 { |
2725 if (chk) return; | 2712 if (chk) return; |
2726 printf("## %s",s); | 2713 printf("## %s",s); |
2727 } | 2714 } |
4977 list3( operands, next, clobber ) | 4964 list3( operands, next, clobber ) |
4978 0 can be shared in input/output | 4965 0 can be shared in input/output |
4979 1 can't be used in input | 4966 1 can't be used in input |
4980 */ | 4967 */ |
4981 | 4968 |
4982 int | 4969 extern int |
4983 asm_operand(char *p,int e1,int mode,int repl,int n,int repl0) | 4970 code_asm_operand(char *p,int e1,int mode,int repl,int n,int repl0) |
4984 { | 4971 { |
4985 int r; | 4972 int r; |
4986 int c; | 4973 int c; |
4987 int val; | 4974 int val; |
4988 int clobber = 0; | 4975 int clobber = 0; |
5033 } else error(-1); | 5020 } else error(-1); |
5034 return repl; | 5021 return repl; |
5035 } | 5022 } |
5036 | 5023 |
5037 void | 5024 void |
5038 free_asm_operand(int repl) | 5025 code_free_asm_operand(int repl) |
5039 { | 5026 { |
5040 for(;repl;repl=cadr(repl)) { | 5027 for(;repl;repl=cadr(repl)) { |
5041 if (car(car(repl))==REGISTER) | 5028 if (car(car(repl))==REGISTER) |
5042 free_register(cadr(car(repl))); | 5029 free_register(cadr(car(repl))); |
5043 } | 5030 } |
5044 } | 5031 } |
5045 | 5032 |
5046 | 5033 |
5047 extern void | 5034 extern void |
5048 replace_asm_string(char *asm_str,int repl) | 5035 code_asm(char *asm_str,int repl) |
5049 { | 5036 { |
5050 int c,i,rstr,val; | 5037 int c,i,rstr,val; |
5051 char *p; | 5038 char *p; |
5052 int reg[MAX_ASM_REG]; | 5039 int reg[MAX_ASM_REG]; |
5053 | 5040 |