• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


コミットメタ情報

リビジョンdc61060547e3dc15ca51d74167d75b1513da16ac (tree)
日時2009-07-14 10:49:02
作者Android (Google) Code Review <android-gerrit@goog...>
コミッターAndroid (Google) Code Review

ログメッセージ

Merge change 7049

* changes:

Implement support for "char" local and global variables.

変更サマリ

差分

--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -1019,6 +1019,25 @@ class Compiler : public ErrorSink {
10191019 LOG_API("storeR0(%d);\n", ea);
10201020 TypeTag tag = pType->tag;
10211021 switch (tag) {
1022+ case TY_CHAR:
1023+ if (ea > -LOCAL && ea < LOCAL) {
1024+ // Local, fp relative
1025+ if (ea < -4095 || ea > 4095) {
1026+ error("Offset out of range: %08x", ea);
1027+ }
1028+ if (ea < 0) {
1029+ o4(0xE54B0000 | (0xfff & (-ea))); // strb r0, [fp,#-ea]
1030+ } else {
1031+ o4(0xE5CB0000 | (0xfff & ea)); // strb r0, [fp,#ea]
1032+ }
1033+ } else{
1034+ // Global, absolute
1035+ o4(0xE59F1000); // ldr r1, .L1
1036+ o4(0xEA000000); // b .L99
1037+ o4(ea); // .L1: .word 0
1038+ o4(0xE5C10000); // .L99: strb r0, [r1]
1039+ }
1040+ break;
10221041 case TY_POINTER:
10231042 case TY_INT:
10241043 case TY_FLOAT:
@@ -1079,8 +1098,32 @@ class Compiler : public ErrorSink {
10791098
10801099 virtual void loadR0(int ea, bool isIncDec, int op, Type* pType) {
10811100 LOG_API("loadR0(%d, %d, %d, %d);\n", ea, isIncDec, op, pType);
1082- TypeTag tag = collapseType(pType->tag);
1101+ TypeTag tag = pType->tag;
10831102 switch (tag) {
1103+ case TY_CHAR:
1104+ if (ea < LOCAL) {
1105+ // Local, fp relative
1106+ if (ea < -4095 || ea > 4095) {
1107+ error("Offset out of range: %08x", ea);
1108+ }
1109+ if (ea < 0) {
1110+ o4(0xE55B0000 | (0xfff & (-ea))); // ldrb r0, [fp,#-ea]
1111+ } else {
1112+ o4(0xE5DB0000 | (0xfff & ea)); // ldrb r0, [fp,#ea]
1113+ }
1114+ } else {
1115+ // Global, absolute
1116+ o4(0xE59F2000); // ldr r2, .L1
1117+ o4(0xEA000000); // b .L99
1118+ o4(ea); // .L1: .word ea
1119+ o4(0xE5D20000); // .L99: ldrb r0, [r2]
1120+ }
1121+
1122+ if (isIncDec) {
1123+ error("inc/dec not implemented for char.");
1124+ }
1125+ break;
1126+ case TY_POINTER:
10841127 case TY_INT:
10851128 case TY_FLOAT:
10861129 if (ea < LOCAL) {
@@ -2027,6 +2070,13 @@ class Compiler : public ErrorSink {
20272070 virtual void storeR0(int ea, Type* pType) {
20282071 TypeTag tag = pType->tag;
20292072 switch (tag) {
2073+ case TY_CHAR:
2074+ if (ea < -LOCAL || ea > LOCAL) {
2075+ oad(0xa2, ea); // movb %al,ea
2076+ } else {
2077+ oad(0x8588, ea); // movb %al,ea(%ebp)
2078+ }
2079+ break;
20302080 case TY_INT:
20312081 case TY_POINTER:
20322082 gmov(6, ea); /* mov %eax, EA */
@@ -2052,10 +2102,24 @@ class Compiler : public ErrorSink {
20522102 }
20532103
20542104 virtual void loadR0(int ea, bool isIncDec, int op, Type* pType) {
2055- TypeTag tag = collapseType(pType->tag);
2105+ TypeTag tag = pType->tag;
20562106 switch (tag) {
2107+ case TY_CHAR:
2108+ if (ea < -LOCAL || ea > LOCAL) {
2109+ oad(0x05BE0F, ea); // movsbl ea,%eax
2110+ } else {
2111+ oad(0x85BE0F, ea); // movsbl ea(%ebp),%eax
2112+ }
2113+ if (isIncDec) {
2114+ error("inc/dec not implemented for char.");
2115+ }
2116+ break;
20572117 case TY_INT:
2058- gmov(8, ea); /* mov EA, %eax */
2118+ case TY_POINTER:
2119+ if (tag == TY_CHAR) {
2120+ } else {
2121+ gmov(8, ea); /* mov EA, %eax */
2122+ }
20592123 if (isIncDec) {
20602124 /* Implement post-increment or post decrement.
20612125 */
--- /dev/null
+++ b/libacc/tests/data/char.c
@@ -0,0 +1,13 @@
1+char ga;
2+char gb;
3+
4+int main() {
5+ char a = 'c';
6+ char b = a * 3;
7+ printf("a = %d, b = %d\n", a, b);
8+ ga = 'd';
9+ gb = ga * 3;
10+ printf("ga = %d, gb = %d\n", ga, gb);
11+ return 0;
12+}
13+
--- a/libacc/tests/test.py
+++ b/libacc/tests/test.py
@@ -250,6 +250,12 @@ Testing read/write (float*): 8.8 9.9
250250 Testing read/write (double*): 8.8 9.9
251251 """)
252252
253+ def testChar(self):
254+ self.compileCheck(["-R", "data/char.c"], """Executing compiled code:
255+result: 0""", """a = 99, b = 41
256+ga = 100, gb = 44""")
257+
258+
253259 if __name__ == '__main__':
254260 if not outputCanRun():
255261 print "Many tests are expected to fail, because acc is not a 32-bit x86 Linux executable."