├── project ├── bin │ ├── 说明.txt │ ├── res.class │ ├── reCon.class │ ├── IsaCou.class │ ├── conrecon.class │ ├── regAllo.class │ ├── assembler.class │ ├── isaConvert.class │ ├── isaconvert2.class │ ├── labalConvert.class │ ├── reconvCount.class │ └── textConvert.class ├── src │ ├── 说明.txt │ ├── IsaCou.java │ ├── assembler.java │ ├── labalConvert.java │ ├── textConvert.java │ ├── reconvCount.java │ ├── conrecon.java │ ├── regAllo.java │ ├── reCon.java │ ├── isaconvert2.java │ └── isaConvert.java ├── isa00.out ├── isa0.out ├── isafinal.out ├── isa.out ├── isa000.out ├── isare.out └── isa.in ├── README.md ├── IsaCou.java ├── assembler.java ├── labalConvert.java ├── textConvert.java ├── reconvCount.java ├── conrecon.java ├── regAllo.java ├── reCon.java ├── isaconvert2.java └── isaConvert.java /project/bin/说明.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/bin/说明.txt -------------------------------------------------------------------------------- /project/src/说明.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/src/说明.txt -------------------------------------------------------------------------------- /project/bin/res.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/bin/res.class -------------------------------------------------------------------------------- /project/bin/reCon.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/bin/reCon.class -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ABC-Tool-Chain 2 | Tool chain for sampling-based programing model including compiler and assembler 3 | -------------------------------------------------------------------------------- /project/bin/IsaCou.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/bin/IsaCou.class -------------------------------------------------------------------------------- /project/bin/conrecon.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/bin/conrecon.class -------------------------------------------------------------------------------- /project/bin/regAllo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/bin/regAllo.class -------------------------------------------------------------------------------- /project/bin/assembler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/bin/assembler.class -------------------------------------------------------------------------------- /project/bin/isaConvert.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/bin/isaConvert.class -------------------------------------------------------------------------------- /project/bin/isaconvert2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/bin/isaconvert2.class -------------------------------------------------------------------------------- /project/bin/labalConvert.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/bin/labalConvert.class -------------------------------------------------------------------------------- /project/bin/reconvCount.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/bin/reconvCount.class -------------------------------------------------------------------------------- /project/bin/textConvert.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixAINetwork/ABC-Tool-Chain/HEAD/project/bin/textConvert.class -------------------------------------------------------------------------------- /project/isa00.out: -------------------------------------------------------------------------------- 1 | mov.u32 %SPL, __local_depot6; 2 | ld.param.u32 %r1, [_Z7scatterPjS_PiS0_S0_ii_param_0]; 0000000000000000 3 | ld.param.u32 %r2, [_Z7scatterPjS_PiS0_S0_ii_param_1]; 0000000000000001 4 | ld.param.u32 %r3, [_Z7scatterPjS_PiS0_S0_ii_param_2]; 0000000000000010 5 | ld.param.u32 %r4, [_Z7scatterPjS_PiS0_S0_ii_param_3]; 0000000000000011 6 | ld.param.u32 %r5, [_Z7scatterPjS_PiS0_S0_ii_param_4]; 0000000000000100 7 | ld.param.u32 %r6, [_Z7scatterPjS_PiS0_S0_ii_param_5]; 0000000000000101 8 | ld.param.u32 %r7, [_Z7scatterPjS_PiS0_S0_ii_param_6]; 0000000000000110 9 | mov.u32 %r8, %tid.x; 10 | mov.u32 %r9, %ctaid.x; 11 | mov.u32 %r10, %ntid.x; 12 | mul.lo.s32 %r11, %r9, %r10; 13 | add.s32 %r10, %r11, %r8; 14 | add.s32 %r10, %r1, %r11; 15 | ld.u32 %r1, [%r22]; 16 | st.u32 [%SP+0], %r1; 17 | add.u32 %r1, %SP, 0; 18 | st.param.b32 [param0+0], %r1; 19 | st.param.b32 [param1+0], %r6; 20 | call.uni (retval0), 21 | ld.param.b32 %r1, [retval0+0]; 22 | mov.u32 %r6, 0; 23 | mov.u32 %r10, %ctaid.x; 24 | mul.lo.s32 %r11, %r10, 16; 25 | add.s32 %r10, %r11, %r1; 26 | add.s32 %r10, %r4, %r11; 27 | ld.u32 %r4, [%r30]; 28 | sub.s32 %r10, %r8, %r4; 29 | add.s32 %r4, %r5, %r8; 30 | ld.u32 %r4, [%r34]; 31 | add.s32 %r5, %r10, %r4; 32 | mov.b32 %r4, %r6; 33 | mov.b32 %r8, %r6; 34 | setp.lt.s32 %p1, %r8, %r9; 35 | @%p2 bra BB6_4; 36 | bra.uni BB6_2; 37 | mul.lo.s32 %r6, %r1, %r7; 38 | add.s32 %r1, %r6, %r8; 39 | add.s32 %r1, %r3, %r6; 40 | ld.u32 %r1, [%r43]; 41 | add.s32 %r4, %r4, %r1; 42 | add.s32 %r1, %r1, 1; 43 | bra.uni BB6_1; 44 | add.s32 %r1, %r5, %r4; 45 | ld.u32 %r1, [%SP+0]; 46 | add.s32 %r3, %r2, %r4; 47 | st.u32 [%r39], %r1; 48 | 1111111111111111: exit 49 | -------------------------------------------------------------------------------- /project/isa0.out: -------------------------------------------------------------------------------- 1 | mov.u32 %SPL, __local_depot6; 2 | ld.param.u32 %r10, [_Z7scatterPjS_PiS0_S0_ii_param_0]; 0000000000000000 3 | ld.param.u32 %r11, [_Z7scatterPjS_PiS0_S0_ii_param_1]; 0000000000000001 4 | ld.param.u32 %r12, [_Z7scatterPjS_PiS0_S0_ii_param_2]; 0000000000000010 5 | ld.param.u32 %r13, [_Z7scatterPjS_PiS0_S0_ii_param_3]; 0000000000000011 6 | ld.param.u32 %r14, [_Z7scatterPjS_PiS0_S0_ii_param_4]; 0000000000000100 7 | ld.param.u32 %r15, [_Z7scatterPjS_PiS0_S0_ii_param_5]; 0000000000000101 8 | ld.param.u32 %r16, [_Z7scatterPjS_PiS0_S0_ii_param_6]; 0000000000000110 9 | mov.u32 %r17, %tid.x; 10 | mov.u32 %r1, %ctaid.x; 11 | mov.u32 %r18, %ntid.x; 12 | mul.lo.s32 %r19, %r1, %r18; 13 | add.s32 %r20, %r19, %r17; 14 | add.s32 %r22, %r10, %r21; 15 | ld.u32 %r23, [%r22]; 16 | st.u32 [%SP+0], %r23; 17 | add.u32 %r24, %SP, 0; 18 | st.param.b32 [param0+0], %r24; 19 | st.param.b32 [param1+0], %r15; 20 | call.uni (retval0), 21 | ld.param.b32 %r2, [retval0+0]; 22 | mov.u32 %r25, 0; 23 | mov.u32 %r26, %ctaid.x; 24 | mul.lo.s32 %r27, %r26, 16; 25 | add.s32 %r28, %r27, %r2; 26 | add.s32 %r30, %r13, %r29; 27 | ld.u32 %r31, [%r30]; 28 | sub.s32 %r32, %r17, %r31; 29 | add.s32 %r34, %r14, %r33; 30 | ld.u32 %r35, [%r34]; 31 | add.s32 %r3, %r32, %r35; 32 | mov.b32 %r45, %r25; 33 | mov.b32 %r46, %r25; 34 | setp.lt.s32 %p1, %r46, %r1; 35 | @%p2 bra BB6_4; 36 | bra.uni BB6_2; 37 | mul.lo.s32 %r40, %r2, %r16; 38 | add.s32 %r41, %r40, %r46; 39 | add.s32 %r43, %r12, %r42; 40 | ld.u32 %r44, [%r43]; 41 | add.s32 %r45, %r45, %r44; 42 | add.s32 %r46, %r46, 1; 43 | bra.uni BB6_1; 44 | add.s32 %r36, %r3, %r45; 45 | ld.u32 %r37, [%SP+0]; 46 | add.s32 %r39, %r11, %r38; 47 | st.u32 [%r39], %r37; 48 | 1111111111111111: exit 49 | -------------------------------------------------------------------------------- /IsaCou.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.util.regex.*; 9 | 10 | public class IsaCou { 11 | private Pattern ISA; 12 | private int isaNum; 13 | static private FileReader fin; 14 | static private FileWriter fout; 15 | static private BufferedReader sin; 16 | static private BufferedWriter sout; 17 | 18 | public IsaCou(){ 19 | isaNum=0; 20 | ISA=Pattern.compile("(((add|sub|mul|mad|div|rem|abs|neg|min|max|setp|set|and|bar|numeric|mov|selp|cvt|ld|st|tex|atom|bra|call|ret)\\.)|\\@\\%p[1234567890]+ bra)"); 21 | } 22 | public void count(){ 23 | try{ 24 | fin=new FileReader(new File("isa00.out")); 25 | fout=new FileWriter(new File("isa000.out")); 26 | sin=new BufferedReader(fin); 27 | sout=new BufferedWriter(fout); 28 | } catch (FileNotFoundException e){ 29 | e.printStackTrace(); 30 | } catch (IOException e){ 31 | e.printStackTrace(); 32 | } 33 | String InString; 34 | StringBuilder OutString; 35 | Matcher match; 36 | 37 | try{ 38 | while((InString=sin.readLine())!=null){ 39 | OutString=new StringBuilder(); 40 | match=ISA.matcher(InString); 41 | if(match.find()){ 42 | isaNum=isaNum+1; 43 | String IN=Integer.toBinaryString(isaNum); 44 | int L=IN.length(); 45 | for (int i=0;i<16-L;i++) 46 | OutString.append("0"); 47 | OutString.append(IN); 48 | OutString.append(": "); 49 | OutString.append(InString); 50 | sout.write(OutString.toString()); 51 | sout.newLine(); 52 | } 53 | else{ 54 | OutString.append(InString); 55 | sout.write(OutString.toString()); 56 | sout.newLine(); 57 | } 58 | } 59 | sin.close(); 60 | sout.close(); 61 | } catch(IOException e){ 62 | e.printStackTrace(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /project/src/IsaCou.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.util.regex.*; 9 | 10 | public class IsaCou { 11 | private Pattern ISA; 12 | private int isaNum; 13 | static private FileReader fin; 14 | static private FileWriter fout; 15 | static private BufferedReader sin; 16 | static private BufferedWriter sout; 17 | 18 | public IsaCou(){ 19 | isaNum=0; 20 | ISA=Pattern.compile("(((add|sub|mul|mad|div|rem|abs|neg|min|max|setp|set|and|bar|numeric|mov|selp|cvt|ld|st|tex|atom|bra|call|ret)\\.)|\\@\\%p[1234567890]+ bra)"); 21 | } 22 | public void count(){ 23 | try{ 24 | fin=new FileReader(new File("isa00.out")); 25 | fout=new FileWriter(new File("isa000.out")); 26 | sin=new BufferedReader(fin); 27 | sout=new BufferedWriter(fout); 28 | } catch (FileNotFoundException e){ 29 | e.printStackTrace(); 30 | } catch (IOException e){ 31 | e.printStackTrace(); 32 | } 33 | String InString; 34 | StringBuilder OutString; 35 | Matcher match; 36 | 37 | try{ 38 | while((InString=sin.readLine())!=null){ 39 | OutString=new StringBuilder(); 40 | match=ISA.matcher(InString); 41 | if(match.find()){ 42 | isaNum=isaNum+1; 43 | String IN=Integer.toBinaryString(isaNum); 44 | int L=IN.length(); 45 | for (int i=0;i<16-L;i++) 46 | OutString.append("0"); 47 | OutString.append(IN); 48 | OutString.append(": "); 49 | OutString.append(InString); 50 | sout.write(OutString.toString()); 51 | sout.newLine(); 52 | } 53 | else{ 54 | OutString.append(InString); 55 | sout.write(OutString.toString()); 56 | sout.newLine(); 57 | } 58 | } 59 | sin.close(); 60 | sout.close(); 61 | } catch(IOException e){ 62 | e.printStackTrace(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /project/isafinal.out: -------------------------------------------------------------------------------- 1 | 0000000000000000 2 | 0000000000000000000000111011000100000000000000010000000000000000 3 | 0000000000000000000000111011000100000000000000100000000000000001 4 | 0000000000000000000000111011000100000000000000110000000000000010 5 | 0000000000000000000000111011000100000000000001000000000000000011 6 | 0000000000000000000000111011000100000000000001010000000000000100 7 | 0000000000000000000000111011000100000000000001100000000000000101 8 | 0000000000000000000000111011000100000000000001110000000000000110 9 | 0000000000000000 10 | 0000000000000000 11 | 0000000000000000 12 | 0000000000000000000000001000001100001001000010100000101100000000 13 | 0000000000000000000000001000000100001011000010000000101000000000 14 | 0000000000000000000000001000000100000001000010110000101000000000 15 | 0000000000000000XD 16 | 0000000000000000XD 17 | 000000000000000000000 18 | 00000000000000000000001110110011 19 | 00000000000000000000001110110011 20 | 0000000000000000XD 21 | 00000000000000000000001110110001 22 | 0000000000000000000000010110000000000000000001100000000000000000 23 | 0000000000000000 24 | 0000000000000000000000010000001100001010000010110000000000010000 25 | 0000000000000000000000001000000100001011000000010000101000000000 26 | 0000000000000000000000001000000100000100000010110000101000000000 27 | 0000000000000000XD 28 | 0000000000000000000000001000001000001000000001000000101000000000 29 | 0000000000000000000000001000000100000101000010000000010000000000 30 | 0000000000000000XD 31 | 0000000000000000000000001000000100001010000001000000010100000000 32 | 0000000000000000000000010010000000000110000001000000000000000000 33 | 0000000000000000000000010010000000000110000010000000000000000000 34 | 0000000000000000000000001001001000001000000010010000000100000000 35 | 00000000000000100000010000110101 36 | 00000000000000000000010000110101 37 | 0000000000000000000000001000001100000001000001110000011000000000 38 | 0000000000000000000000001000000100000110000010000000000100000000 39 | 0000000000000000000000001000000100000011000001100000000100000000 40 | 0000000000000000XD 41 | 0000000000000000000000001000000100000100000000010000010000000000 42 | 0000000000000000000000010000000100000001000000010000000000000001 43 | 00000000000000000000010000110101 44 | 0000000000000000000000001000000100000101000001000000000100000000 45 | 0000000000000000XD 46 | 0000000000000000000000001000000100000010000001000000001100000000 47 | 0000000000000000XD 48 | 0000000000000000000001000111111100000000000000000000000000000000 49 | -------------------------------------------------------------------------------- /project/isa.out: -------------------------------------------------------------------------------- 1 | 0000000000000001: mov.u32 %SPL, __local_depot6; 2 | 0000000000000010: ld.param.u32 %r1, [_Z7scatterPjS_PiS0_S0_ii_param_0]; 0000000000000000 3 | 0000000000000011: ld.param.u32 %r2, [_Z7scatterPjS_PiS0_S0_ii_param_1]; 0000000000000001 4 | 0000000000000100: ld.param.u32 %r3, [_Z7scatterPjS_PiS0_S0_ii_param_2]; 0000000000000010 5 | 0000000000000101: ld.param.u32 %r4, [_Z7scatterPjS_PiS0_S0_ii_param_3]; 0000000000000011 6 | 0000000000000110: ld.param.u32 %r5, [_Z7scatterPjS_PiS0_S0_ii_param_4]; 0000000000000100 7 | 0000000000000111: ld.param.u32 %r6, [_Z7scatterPjS_PiS0_S0_ii_param_5]; 0000000000000101 8 | 0000000000001000: ld.param.u32 %r7, [_Z7scatterPjS_PiS0_S0_ii_param_6]; 0000000000000110 9 | 0000000000001001: mov.u32 %r8, %tid.x; 10 | 0000000000001010: mov.u32 %r9, %ctaid.x; 11 | 0000000000001011: mov.u32 %r10, %ntid.x; 12 | 0000000000001100: mul.lo.s32 %r11, %r9, %r10; 13 | 0000000000001101: add.s32 %r10, %r11, %r8; 14 | 0000000000001110: add.s32 %r10, %r1, %r11; 15 | 0000000000001111: ld.u32 %r1, [%r22]; 16 | 0000000000010000: st.u32 [%SP+0], %r1; 17 | 0000000000010001: add.u32 %r1, %SP, 0; 18 | 0000000000010010: st.param.b32 [param0+0], %r1; 19 | 0000000000010011: st.param.b32 [param1+0], %r6; 20 | 0000000000010100: call.uni (retval0), 21 | 0000000000010101: ld.param.b32 %r1, [retval0+0]; 22 | 0000000000010110: mov.u32 %r6, 0; 23 | 0000000000010111: mov.u32 %r10, %ctaid.x; 24 | 0000000000011000: mul.lo.s32 %r11, %r10, 16; 25 | 0000000000011001: add.s32 %r10, %r11, %r1; 26 | 0000000000011010: add.s32 %r10, %r4, %r11; 27 | 0000000000011011: ld.u32 %r4, [%r30]; 28 | 0000000000011100: sub.s32 %r10, %r8, %r4; 29 | 0000000000011101: add.s32 %r4, %r5, %r8; 30 | 0000000000011110: ld.u32 %r4, [%r34]; 31 | 0000000000011111: add.s32 %r5, %r10, %r4; 32 | 0000000000100000: mov.b32 %r4, %r6; 33 | 0000000000100001: mov.b32 %r8, %r6; 34 | 0000000000100010: setp.lt.s32 %p1, %r8, %r9; 35 | 0000000000100011: @%p2 bra BB6_4; 36 | 0000000000100100: bra.uni BB6_2; 37 | 0000000000100101: mul.lo.s32 %r6, %r1, %r7; 38 | 0000000000100110: add.s32 %r1, %r6, %r8; 39 | 0000000000100111: add.s32 %r1, %r3, %r6; 40 | 0000000000101000: ld.u32 %r1, [%r43]; 41 | 0000000000101001: add.s32 %r4, %r4, %r1; 42 | 0000000000101010: add.s32 %r1, %r1, 1; 43 | 0000000000101011: bra.uni BB6_1; 44 | 0000000000101100: add.s32 %r1, %r5, %r4; 45 | 0000000000101101: ld.u32 %r1, [%SP+0]; 46 | 0000000000101110: add.s32 %r3, %r2, %r4; 47 | 0000000000101111: st.u32 [%r39], %r1; 48 | 1111111111111111: exit 49 | -------------------------------------------------------------------------------- /project/isa000.out: -------------------------------------------------------------------------------- 1 | 0000000000000001: mov.u32 %SPL, __local_depot6; 2 | 0000000000000010: ld.param.u32 %r1, [_Z7scatterPjS_PiS0_S0_ii_param_0]; 0000000000000000 3 | 0000000000000011: ld.param.u32 %r2, [_Z7scatterPjS_PiS0_S0_ii_param_1]; 0000000000000001 4 | 0000000000000100: ld.param.u32 %r3, [_Z7scatterPjS_PiS0_S0_ii_param_2]; 0000000000000010 5 | 0000000000000101: ld.param.u32 %r4, [_Z7scatterPjS_PiS0_S0_ii_param_3]; 0000000000000011 6 | 0000000000000110: ld.param.u32 %r5, [_Z7scatterPjS_PiS0_S0_ii_param_4]; 0000000000000100 7 | 0000000000000111: ld.param.u32 %r6, [_Z7scatterPjS_PiS0_S0_ii_param_5]; 0000000000000101 8 | 0000000000001000: ld.param.u32 %r7, [_Z7scatterPjS_PiS0_S0_ii_param_6]; 0000000000000110 9 | 0000000000001001: mov.u32 %r8, %tid.x; 10 | 0000000000001010: mov.u32 %r9, %ctaid.x; 11 | 0000000000001011: mov.u32 %r10, %ntid.x; 12 | 0000000000001100: mul.lo.s32 %r11, %r9, %r10; 13 | 0000000000001101: add.s32 %r10, %r11, %r8; 14 | 0000000000001110: add.s32 %r10, %r1, %r11; 15 | 0000000000001111: ld.u32 %r1, [%r22]; 16 | 0000000000010000: st.u32 [%SP+0], %r1; 17 | 0000000000010001: add.u32 %r1, %SP, 0; 18 | 0000000000010010: st.param.b32 [param0+0], %r1; 19 | 0000000000010011: st.param.b32 [param1+0], %r6; 20 | 0000000000010100: call.uni (retval0), 21 | 0000000000010101: ld.param.b32 %r1, [retval0+0]; 22 | 0000000000010110: mov.u32 %r6, 0; 23 | 0000000000010111: mov.u32 %r10, %ctaid.x; 24 | 0000000000011000: mul.lo.s32 %r11, %r10, 16; 25 | 0000000000011001: add.s32 %r10, %r11, %r1; 26 | 0000000000011010: add.s32 %r10, %r4, %r11; 27 | 0000000000011011: ld.u32 %r4, [%r30]; 28 | 0000000000011100: sub.s32 %r10, %r8, %r4; 29 | 0000000000011101: add.s32 %r4, %r5, %r8; 30 | 0000000000011110: ld.u32 %r4, [%r34]; 31 | 0000000000011111: add.s32 %r5, %r10, %r4; 32 | 0000000000100000: mov.b32 %r4, %r6; 33 | 0000000000100001: mov.b32 %r8, %r6; 34 | 0000000000100010: setp.lt.s32 %p1, %r8, %r9; 35 | 0000000000100011: @%p2 bra BB6_4; 36 | 0000000000100100: bra.uni BB6_2; 37 | 0000000000100101: mul.lo.s32 %r6, %r1, %r7; 38 | 0000000000100110: add.s32 %r1, %r6, %r8; 39 | 0000000000100111: add.s32 %r1, %r3, %r6; 40 | 0000000000101000: ld.u32 %r1, [%r43]; 41 | 0000000000101001: add.s32 %r4, %r4, %r1; 42 | 0000000000101010: add.s32 %r1, %r1, 1; 43 | 0000000000101011: bra.uni BB6_1; 44 | 0000000000101100: add.s32 %r1, %r5, %r4; 45 | 0000000000101101: ld.u32 %r1, [%SP+0]; 46 | 0000000000101110: add.s32 %r3, %r2, %r4; 47 | 0000000000101111: st.u32 [%r39], %r1; 48 | 1111111111111111: exit 49 | -------------------------------------------------------------------------------- /project/isare.out: -------------------------------------------------------------------------------- 1 | 0000000000000001: mov.u32 %SPL, __local_depot6; 2 | 0000000000000010: ld.param.u32 %r1, [_Z7scatterPjS_PiS0_S0_ii_param_0]; 0000000000000000 3 | 0000000000000011: ld.param.u32 %r2, [_Z7scatterPjS_PiS0_S0_ii_param_1]; 0000000000000001 4 | 0000000000000100: ld.param.u32 %r3, [_Z7scatterPjS_PiS0_S0_ii_param_2]; 0000000000000010 5 | 0000000000000101: ld.param.u32 %r4, [_Z7scatterPjS_PiS0_S0_ii_param_3]; 0000000000000011 6 | 0000000000000110: ld.param.u32 %r5, [_Z7scatterPjS_PiS0_S0_ii_param_4]; 0000000000000100 7 | 0000000000000111: ld.param.u32 %r6, [_Z7scatterPjS_PiS0_S0_ii_param_5]; 0000000000000101 8 | 0000000000001000: ld.param.u32 %r7, [_Z7scatterPjS_PiS0_S0_ii_param_6]; 0000000000000110 9 | 0000000000001001: mov.u32 %r8, %tid.x; 10 | 0000000000001010: mov.u32 %r9, %ctaid.x; 11 | 0000000000001011: mov.u32 %r10, %ntid.x; 12 | 0000000000001100: mul.lo.s32 %r11, %r9, %r10; 13 | 0000000000001101: add.s32 %r10, %r11, %r8; 14 | 0000000000001110: add.s32 %r10, %r1, %r11; 15 | 0000000000001111: ld.u32 %r1, [%r22]; 16 | 0000000000010000: st.u32 [%SP+0], %r1; 17 | 0000000000010001: add.u32 %r1, %SP, 0; 18 | 0000000000010010: st.param.b32 [param0+0], %r1; 19 | 0000000000010011: st.param.b32 [param1+0], %r6; 20 | 0000000000010100: call.uni (retval0), 21 | 0000000000010101: ld.param.b32 %r1, [retval0+0]; 22 | 0000000000010110: mov.u32 %r6, 0; 23 | 0000000000010111: mov.u32 %r10, %ctaid.x; 24 | 0000000000011000: mul.lo.s32 %r11, %r10, 16; 25 | 0000000000011001: add.s32 %r10, %r11, %r1; 26 | 0000000000011010: add.s32 %r10, %r4, %r11; 27 | 0000000000011011: ld.u32 %r4, [%r30]; 28 | 0000000000011100: sub.s32 %r10, %r8, %r4; 29 | 0000000000011101: add.s32 %r4, %r5, %r8; 30 | 0000000000011110: ld.u32 %r4, [%r34]; 31 | 0000000000011111: add.s32 %r5, %r10, %r4; 32 | 0000000000100000: mov.b32 %r4, %r6; 33 | 0000000000100001: mov.b32 %r8, %r6; 34 | 0000000000100010: setp.lt.s32 %p1, %r8, %r9; 35 | 0000000000100011: @%p2 bra BB6_4; 0000000000100101 36 | 0000000000100100: bra.uni BB6_2; 37 | 0000000000100101: mul.lo.s32 %r6, %r1, %r7; 38 | 0000000000100110: add.s32 %r1, %r6, %r8; 39 | 0000000000100111: add.s32 %r1, %r3, %r6; 40 | 0000000000101000: ld.u32 %r1, [%r43]; 41 | 0000000000101001: add.s32 %r4, %r4, %r1; 42 | 0000000000101010: add.s32 %r1, %r1, 1; 43 | 0000000000101011: bra.uni BB6_1; 44 | 0000000000101100: add.s32 %r1, %r5, %r4; 45 | 0000000000101101: ld.u32 %r1, [%SP+0]; 46 | 0000000000101110: add.s32 %r3, %r2, %r4; 47 | 0000000000101111: st.u32 [%r39], %r1; 48 | 1111111111111111: exit 49 | -------------------------------------------------------------------------------- /assembler.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | 9 | 10 | public class assembler { 11 | static private FileReader fin; 12 | static private FileWriter fout; 13 | static private BufferedReader sin; 14 | static private BufferedWriter sout; 15 | 16 | public static void main(String[] args){ 17 | //res Res=new res(); 18 | //Res.Convert(); 19 | 20 | textConvert textconvert=new textConvert(); 21 | int memNum=textconvert.Convert(); 22 | 23 | regAllo regallo=new regAllo(); 24 | regallo.allocation(); 25 | 26 | IsaCou isacou=new IsaCou(); 27 | isacou.count(); 28 | 29 | labalConvert labalconvert=new labalConvert(memNum); 30 | labalconvert.Convert(); 31 | 32 | conrecon recon=new conrecon(); 33 | recon.count(); 34 | 35 | //reconvCount reconvcount=new reconvCount(); 36 | //reconvcount.Count(); 37 | //reCon reconvcount=new reCon(); 38 | //reconvcount.Count(); 39 | 40 | String InString,OutString; 41 | isaconvert2 isaconvert2=new isaconvert2(); 42 | try{ 43 | fin=new FileReader(new File("isare.out")); 44 | fout=new FileWriter(new File("isafinal.out")); 45 | sin=new BufferedReader(fin); 46 | sout=new BufferedWriter(fout); 47 | } catch (FileNotFoundException e){ 48 | e.printStackTrace(); 49 | } catch (IOException e){ 50 | e.printStackTrace(); 51 | } 52 | try{ 53 | while((InString=sin.readLine())!=null){ 54 | System.out.println(InString); 55 | OutString=isaconvert2.Convert(InString); 56 | 57 | sout.write(OutString); 58 | sout.newLine(); 59 | 60 | } 61 | sin.close(); 62 | sout.close(); 63 | } catch (IOException e){ 64 | e.printStackTrace(); 65 | } 66 | 67 | 68 | try{ 69 | fin=new FileReader(new File("isafinal.out")); 70 | fout=new FileWriter(new File("isadebug.out")); 71 | sin=new BufferedReader(fin); 72 | sout=new BufferedWriter(fout); 73 | } catch (FileNotFoundException e){ 74 | e.printStackTrace(); 75 | } catch (IOException e){ 76 | e.printStackTrace(); 77 | } 78 | try{ 79 | while((InString=sin.readLine())!=null){ 80 | System.out.println(InString); 81 | StringBuilder A=new StringBuilder(); 82 | for(int i=0;i<64;i++){ 83 | char AA=InString.charAt(i); 84 | A.append(AA); 85 | if((i+1)%8==0&&i!=63) 86 | A.append("_"); 87 | } 88 | sout.write(A.toString()); 89 | sout.newLine(); 90 | 91 | } 92 | for(int i=0; i<20;i++){ 93 | sout.write("00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000"); 94 | sout.newLine(); 95 | } 96 | sin.close(); 97 | sout.close(); 98 | } catch (IOException e){ 99 | e.printStackTrace(); 100 | } 101 | 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /project/src/assembler.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | 9 | 10 | public class assembler { 11 | static private FileReader fin; 12 | static private FileWriter fout; 13 | static private BufferedReader sin; 14 | static private BufferedWriter sout; 15 | 16 | public static void main(String[] args){ 17 | //res Res=new res(); 18 | //Res.Convert(); 19 | 20 | textConvert textconvert=new textConvert(); 21 | int memNum=textconvert.Convert(); 22 | 23 | regAllo regallo=new regAllo(); 24 | regallo.allocation(); 25 | 26 | IsaCou isacou=new IsaCou(); 27 | isacou.count(); 28 | 29 | labalConvert labalconvert=new labalConvert(memNum); 30 | labalconvert.Convert(); 31 | 32 | conrecon recon=new conrecon(); 33 | recon.count(); 34 | 35 | //reconvCount reconvcount=new reconvCount(); 36 | //reconvcount.Count(); 37 | //reCon reconvcount=new reCon(); 38 | //reconvcount.Count(); 39 | 40 | String InString,OutString; 41 | isaconvert2 isaconvert2=new isaconvert2(); 42 | try{ 43 | fin=new FileReader(new File("isare.out")); 44 | fout=new FileWriter(new File("isafinal.out")); 45 | sin=new BufferedReader(fin); 46 | sout=new BufferedWriter(fout); 47 | } catch (FileNotFoundException e){ 48 | e.printStackTrace(); 49 | } catch (IOException e){ 50 | e.printStackTrace(); 51 | } 52 | try{ 53 | while((InString=sin.readLine())!=null){ 54 | System.out.println(InString); 55 | OutString=isaconvert2.Convert(InString); 56 | 57 | sout.write(OutString); 58 | sout.newLine(); 59 | 60 | } 61 | sin.close(); 62 | sout.close(); 63 | } catch (IOException e){ 64 | e.printStackTrace(); 65 | } 66 | 67 | 68 | try{ 69 | fin=new FileReader(new File("isafinal.out")); 70 | fout=new FileWriter(new File("isadebug.out")); 71 | sin=new BufferedReader(fin); 72 | sout=new BufferedWriter(fout); 73 | } catch (FileNotFoundException e){ 74 | e.printStackTrace(); 75 | } catch (IOException e){ 76 | e.printStackTrace(); 77 | } 78 | try{ 79 | while((InString=sin.readLine())!=null){ 80 | System.out.println(InString); 81 | StringBuilder A=new StringBuilder(); 82 | for(int i=0;i<64;i++){ 83 | char AA=InString.charAt(i); 84 | A.append(AA); 85 | if((i+1)%8==0&&i!=63) 86 | A.append("_"); 87 | } 88 | sout.write(A.toString()); 89 | sout.newLine(); 90 | 91 | } 92 | for(int i=0; i<20;i++){ 93 | sout.write("00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000"); 94 | sout.newLine(); 95 | } 96 | sin.close(); 97 | sout.close(); 98 | } catch (IOException e){ 99 | e.printStackTrace(); 100 | } 101 | 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /project/isa.in: -------------------------------------------------------------------------------- 1 | 2 | .visible .entry _Z7scatterPjS_PiS0_S0_ii( 3 | .param .u32 _Z7scatterPjS_PiS0_S0_ii_param_0, 4 | .param .u32 _Z7scatterPjS_PiS0_S0_ii_param_1, 5 | .param .u32 _Z7scatterPjS_PiS0_S0_ii_param_2, 6 | .param .u32 _Z7scatterPjS_PiS0_S0_ii_param_3, 7 | .param .u32 _Z7scatterPjS_PiS0_S0_ii_param_4, 8 | .param .u32 _Z7scatterPjS_PiS0_S0_ii_param_5, 9 | .param .u32 _Z7scatterPjS_PiS0_S0_ii_param_6 10 | ) 11 | { 12 | .local .align 4 .b8 __local_depot6[4]; 13 | .reg .b32 %SP; 14 | .reg .b32 %SPL; 15 | .reg .pred %p<3>; 16 | .reg .s32 %r<47>; 17 | 18 | 19 | .loc 1 220 1 20 | func_begin6: 21 | .loc 1 220 0 22 | 23 | .loc 1 220 1 24 | 25 | mov.u32 %SPL, __local_depot6; 26 | cvta.local.u32 %SP, %SPL; 27 | ld.param.u32 %r10, [_Z7scatterPjS_PiS0_S0_ii_param_0]; 28 | ld.param.u32 %r11, [_Z7scatterPjS_PiS0_S0_ii_param_1]; 29 | ld.param.u32 %r12, [_Z7scatterPjS_PiS0_S0_ii_param_2]; 30 | ld.param.u32 %r13, [_Z7scatterPjS_PiS0_S0_ii_param_3]; 31 | ld.param.u32 %r14, [_Z7scatterPjS_PiS0_S0_ii_param_4]; 32 | ld.param.u32 %r15, [_Z7scatterPjS_PiS0_S0_ii_param_5]; 33 | ld.param.u32 %r16, [_Z7scatterPjS_PiS0_S0_ii_param_6]; 34 | tmp108: 35 | func_exec_begin6: 36 | .loc 1 223 1 37 | mov.u32 %r17, %tid.x; 38 | tmp109: 39 | .loc 1 224 1 40 | mov.u32 %r1, %ctaid.x; 41 | tmp110: 42 | .loc 1 225 1 43 | mov.u32 %r18, %ntid.x; 44 | mul.lo.s32 %r19, %r1, %r18; 45 | add.s32 %r20, %r19, %r17; 46 | tmp111: 47 | .loc 1 227 1 48 | shl.b32 %r21, %r20, 2; 49 | add.s32 %r22, %r10, %r21; 50 | ld.u32 %r23, [%r22]; 51 | st.u32 [%SP+0], %r23; 52 | add.u32 %r24, %SP, 0; 53 | // Callseq Start 2 54 | { 55 | .reg .b32 temp_param_reg; 56 | .loc 1 228 44 57 | .param .b32 param0; 58 | st.param.b32 [param0+0], %r24; 59 | .param .b32 param1; 60 | st.param.b32 [param1+0], %r15; 61 | .param .b32 retval0; 62 | call.uni (retval0), 63 | _Z11getBinIndexRji, 64 | ( 65 | param0, 66 | param1 67 | ); 68 | ld.param.b32 %r2, [retval0+0]; 69 | } 70 | // Callseq End 2 71 | mov.u32 %r25, 0; 72 | tmp112: 73 | .loc 1 230 1 74 | mov.u32 %r26, %ctaid.x; 75 | mul.lo.s32 %r27, %r26, 16; 76 | add.s32 %r28, %r27, %r2; 77 | shl.b32 %r29, %r28, 2; 78 | add.s32 %r30, %r13, %r29; 79 | ld.u32 %r31, [%r30]; 80 | sub.s32 %r32, %r17, %r31; 81 | shl.b32 %r33, %r2, 2; 82 | add.s32 %r34, %r14, %r33; 83 | ld.u32 %r35, [%r34]; 84 | add.s32 %r3, %r32, %r35; 85 | tmp113: 86 | .loc 1 232 1 87 | mov.b32 %r45, %r25; 88 | tmp114: 89 | .loc 1 233 1 90 | mov.b32 %r46, %r25; 91 | tmp115: 92 | 93 | BB6_1: 94 | .loc 1 233 1 95 | setp.lt.s32 %p1, %r46, %r1; 96 | not.pred %p2, %p1; 97 | @%p2 bra BB6_4; 98 | bra.uni BB6_2; 99 | 100 | BB6_2: 101 | .loc 1 234 1 102 | tmp116: 103 | mul.lo.s32 %r40, %r2, %r16; 104 | add.s32 %r41, %r40, %r46; 105 | shl.b32 %r42, %r41, 2; 106 | add.s32 %r43, %r12, %r42; 107 | ld.u32 %r44, [%r43]; 108 | add.s32 %r45, %r45, %r44; 109 | tmp117: 110 | 111 | .loc 1 233 54 112 | add.s32 %r46, %r46, 1; 113 | tmp118: 114 | bra.uni BB6_1; 115 | tmp119: 116 | 117 | BB6_4: 118 | .loc 1 235 1 119 | add.s32 %r36, %r3, %r45; 120 | tmp120: 121 | .loc 1 237 1 122 | ld.u32 %r37, [%SP+0]; 123 | shl.b32 %r38, %r36, 2; 124 | add.s32 %r39, %r11, %r38; 125 | st.u32 [%r39], %r37; 126 | tmp121: 127 | .loc 1 239 2 128 | ret; 129 | tmp122: 130 | func_end6: 131 | } 132 | 133 | -------------------------------------------------------------------------------- /labalConvert.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.util.regex.*; 9 | import java.util.HashMap; 10 | 11 | public class labalConvert { 12 | private int LineNum;//,memNum; 13 | //private int [] memDiv; 14 | private Pattern Labal1,Labal2,Labal3,Mem,addr; 15 | private HashMap labal,mem; 16 | static private FileReader fin,ffin; 17 | static private FileWriter fout; 18 | static private BufferedReader sin,ssin; 19 | static private BufferedWriter sout; 20 | 21 | public labalConvert(int i){ 22 | LineNum=0; 23 | //memNum=i; 24 | /*memDiv=new int [memNum+1]; 25 | for(int ii=0;ii<=memNum;ii++){ 26 | memDiv[ii]=0; 27 | }*/ 28 | labal=new HashMap(); 29 | mem=new HashMap(); 30 | Mem=Pattern.compile(" \\.(shared|local|global|const)"); 31 | addr=Pattern.compile("(\\_\\_cuda\\_\\_[a-zA-Z0123456789\\_]+)\\[([0123456789]+)\\];"); 32 | Labal1=Pattern.compile("((\\$L[a-zA-Z0123456789\\_]+)\\;)"); 33 | Labal2=Pattern.compile("((\\$L[a-zA-Z0123456789\\_]+)\\:)"); 34 | Labal3=Pattern.compile("([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01]):"); 35 | } 36 | 37 | public void Convert(){ 38 | try{ 39 | fin=new FileReader(new File("isa000.out")); 40 | fout=new FileWriter(new File("isa.out")); 41 | sin=new BufferedReader(fin); 42 | sout=new BufferedWriter(fout); 43 | } catch (FileNotFoundException e){ 44 | e.printStackTrace(); 45 | } catch (IOException e){ 46 | e.printStackTrace(); 47 | } 48 | String InString; 49 | Matcher match1,match2; 50 | int mn=0; 51 | try{ 52 | while((InString=sin.readLine())!=null){ 53 | System.out.println(InString); 54 | LineNum=LineNum+1; 55 | match1=Mem.matcher(InString); 56 | match2=addr.matcher(InString); 57 | if(match1.find()){ 58 | mn=mn+1; 59 | if(match2.find()){ 60 | String G0=match2.group(1); 61 | mem.put(G0, Integer.toString(mn)); 62 | } 63 | } 64 | 65 | 66 | match1=Labal1.matcher(InString); 67 | match2=Labal2.matcher(InString); 68 | if(match1.find()){ 69 | System.out.println(InString); 70 | String LL=match1.group(2); 71 | String IInString; 72 | 73 | try{ 74 | ffin=new FileReader(new File("isa000.out")); 75 | ssin=new BufferedReader(ffin); 76 | } catch (FileNotFoundException e){ 77 | e.printStackTrace(); 78 | } 79 | try{ 80 | while((IInString=ssin.readLine())!=null){ 81 | Matcher mm=Labal2.matcher(IInString); 82 | if (mm.find()){ 83 | System.out.println(IInString); 84 | String GetL=mm.group(2); 85 | if (GetL.equals(LL)){ 86 | while((IInString=ssin.readLine())!=null){ 87 | Matcher mm2=Labal3.matcher(IInString); 88 | if (mm2.find()){ 89 | String LL2=mm2.group(1); 90 | labal.put(LL, LL2); 91 | break; 92 | } 93 | } 94 | } 95 | } 96 | 97 | } 98 | } catch (IOException e){ 99 | e.printStackTrace(); 100 | } 101 | ssin.close(); 102 | 103 | sout.write(InString); 104 | sout.write(labal.get(LL)); 105 | sout.newLine(); 106 | 107 | } 108 | else if (!match2.find()){ 109 | sout.write(InString); 110 | sout.newLine(); 111 | } 112 | } 113 | sin.close(); 114 | sout.close(); 115 | } catch (IOException e){ 116 | e.printStackTrace(); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /project/src/labalConvert.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.util.regex.*; 9 | import java.util.HashMap; 10 | 11 | public class labalConvert { 12 | private int LineNum;//,memNum; 13 | //private int [] memDiv; 14 | private Pattern Labal1,Labal2,Labal3,Mem,addr; 15 | private HashMap labal,mem; 16 | static private FileReader fin,ffin; 17 | static private FileWriter fout; 18 | static private BufferedReader sin,ssin; 19 | static private BufferedWriter sout; 20 | 21 | public labalConvert(int i){ 22 | LineNum=0; 23 | //memNum=i; 24 | /*memDiv=new int [memNum+1]; 25 | for(int ii=0;ii<=memNum;ii++){ 26 | memDiv[ii]=0; 27 | }*/ 28 | labal=new HashMap(); 29 | mem=new HashMap(); 30 | Mem=Pattern.compile(" \\.(shared|local|global|const)"); 31 | addr=Pattern.compile("(\\_\\_cuda\\_\\_[a-zA-Z0123456789\\_]+)\\[([0123456789]+)\\];"); 32 | Labal1=Pattern.compile("((\\$L[a-zA-Z0123456789\\_]+)\\;)"); 33 | Labal2=Pattern.compile("((\\$L[a-zA-Z0123456789\\_]+)\\:)"); 34 | Labal3=Pattern.compile("([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01]):"); 35 | } 36 | 37 | public void Convert(){ 38 | try{ 39 | fin=new FileReader(new File("isa000.out")); 40 | fout=new FileWriter(new File("isa.out")); 41 | sin=new BufferedReader(fin); 42 | sout=new BufferedWriter(fout); 43 | } catch (FileNotFoundException e){ 44 | e.printStackTrace(); 45 | } catch (IOException e){ 46 | e.printStackTrace(); 47 | } 48 | String InString; 49 | Matcher match1,match2; 50 | int mn=0; 51 | try{ 52 | while((InString=sin.readLine())!=null){ 53 | System.out.println(InString); 54 | LineNum=LineNum+1; 55 | match1=Mem.matcher(InString); 56 | match2=addr.matcher(InString); 57 | if(match1.find()){ 58 | mn=mn+1; 59 | if(match2.find()){ 60 | String G0=match2.group(1); 61 | mem.put(G0, Integer.toString(mn)); 62 | } 63 | } 64 | 65 | 66 | match1=Labal1.matcher(InString); 67 | match2=Labal2.matcher(InString); 68 | if(match1.find()){ 69 | System.out.println(InString); 70 | String LL=match1.group(2); 71 | String IInString; 72 | 73 | try{ 74 | ffin=new FileReader(new File("isa000.out")); 75 | ssin=new BufferedReader(ffin); 76 | } catch (FileNotFoundException e){ 77 | e.printStackTrace(); 78 | } 79 | try{ 80 | while((IInString=ssin.readLine())!=null){ 81 | Matcher mm=Labal2.matcher(IInString); 82 | if (mm.find()){ 83 | System.out.println(IInString); 84 | String GetL=mm.group(2); 85 | if (GetL.equals(LL)){ 86 | while((IInString=ssin.readLine())!=null){ 87 | Matcher mm2=Labal3.matcher(IInString); 88 | if (mm2.find()){ 89 | String LL2=mm2.group(1); 90 | labal.put(LL, LL2); 91 | break; 92 | } 93 | } 94 | } 95 | } 96 | 97 | } 98 | } catch (IOException e){ 99 | e.printStackTrace(); 100 | } 101 | ssin.close(); 102 | 103 | sout.write(InString); 104 | sout.write(labal.get(LL)); 105 | sout.newLine(); 106 | 107 | } 108 | else if (!match2.find()){ 109 | sout.write(InString); 110 | sout.newLine(); 111 | } 112 | } 113 | sin.close(); 114 | sout.close(); 115 | } catch (IOException e){ 116 | e.printStackTrace(); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /textConvert.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.util.regex.*; 9 | import java.util.HashMap; 10 | 11 | public class textConvert { 12 | private int isaNum,memNum,entryNum; 13 | private Pattern ISA,Labal,Mem,entry,share,local,cvt; 14 | private HashMap Entry,Share,Inreg; 15 | static private FileReader fin; 16 | static private FileWriter fout; 17 | static private BufferedReader sin; 18 | static private BufferedWriter sout; 19 | 20 | public textConvert(){ 21 | isaNum=0; 22 | memNum=0; 23 | entryNum=0; 24 | Entry=new HashMap(); 25 | Share=new HashMap(); 26 | Inreg=new HashMap(); 27 | ISA=Pattern.compile("(((add|sub|mul|mad|div|rem|abs|neg|min|max|setp|set|and|bar|numeric|mov|selp|cvt|ld|st|tex|atom|bra|call|ret)\\.)|\\@\\%p[1234567890]+ bra)"); 28 | Labal=Pattern.compile("(\\$L[a-zA-Z0123456789\\_]+\\:)"); 29 | Mem=Pattern.compile(" \\.(shared)"); 30 | entry=Pattern.compile(".param .[usf]32 ([a-zA-Z0123456789\\_]*)"); 31 | share=Pattern.compile("\\[?(\\_\\_cuda\\_[a-zA-Z0123456789\\_]*)(\\+\\d+\\])?[\\[\\;]"); 32 | local=Pattern.compile("\\[([a-zA-Z0123456789\\_]*)\\];"); 33 | cvt=Pattern.compile("(cvt.[a-zA-Z0123456789.]*) (\\%r[0123456789]+, )\\%(tid.x|tid.y|tid.z|ntid.x|ntid.y|ntid.z|ctaid.x|ctaid.y|ctaid.z|nctaid.x|nctaid.y|nctaid.z);"); 34 | 35 | 36 | Inreg.put("tid.x", "00001"); 37 | Inreg.put("tid.y", "00010"); 38 | Inreg.put("tid.z", "00011"); 39 | Inreg.put("ntid.x", "00100"); 40 | Inreg.put("ntid.y", "00101"); 41 | Inreg.put("ntid.z", "00110"); 42 | Inreg.put("ctaid.x", "00111"); 43 | Inreg.put("ctaid.y", "01000"); 44 | Inreg.put("ctaid.z", "01001"); 45 | Inreg.put("nctaid.x", "01010"); 46 | Inreg.put("nctaid.y", "01011"); 47 | Inreg.put("nctaid.z", "01100"); 48 | } 49 | 50 | public int Convert(){ 51 | try{ 52 | fin=new FileReader(new File("isa.in")); 53 | fout=new FileWriter(new File("isa0.out")); 54 | sin=new BufferedReader(fin); 55 | sout=new BufferedWriter(fout); 56 | } catch (FileNotFoundException e){ 57 | e.printStackTrace(); 58 | } catch (IOException e){ 59 | e.printStackTrace(); 60 | } 61 | String InString; 62 | StringBuilder OutString; 63 | Matcher match; 64 | 65 | 66 | try{ 67 | while((InString=sin.readLine())!=null){ 68 | OutString=new StringBuilder(); 69 | System.out.println(InString); 70 | match=entry.matcher(InString); 71 | if(match.find()){ 72 | String G=match.group(1); 73 | StringBuilder en=new StringBuilder("000000"); 74 | String n=Integer.toBinaryString(entryNum); 75 | int L=n.length(); 76 | for(int i=0;i<10-L;i++){ 77 | en.append("0"); 78 | } 79 | en.append(n); 80 | Entry.put(G, en.toString()); 81 | entryNum=entryNum+1; 82 | } 83 | match=ISA.matcher(InString); 84 | if(match.find()){ 85 | isaNum=isaNum+1; 86 | /*String IN=Integer.toBinaryString(isaNum); 87 | int L=IN.length(); 88 | for (int i=0;i<16-L;i++) 89 | OutString.append("0"); 90 | OutString.append(IN); 91 | OutString.append(": ");*/ 92 | OutString.append(InString); 93 | Matcher match2; 94 | match2=share.matcher(InString); 95 | if(match2.find()){ 96 | String G2=match2.group(1); 97 | String tp=Share.get(G2); 98 | OutString.append(" "); 99 | OutString.append(tp); 100 | } 101 | match2=local.matcher(InString); 102 | if(match2.find()){ 103 | String G2=match2.group(1); 104 | String tp=Entry.get(G2); 105 | OutString.append(" "); 106 | OutString.append(tp); 107 | } 108 | match2=cvt.matcher(InString); 109 | if(match2.find()){ 110 | String G2=match2.group(3); 111 | 112 | OutString.append(Inreg.get(G2)); 113 | 114 | } 115 | sout.write(OutString.toString()); 116 | sout.newLine(); 117 | } 118 | match=Mem.matcher(InString); 119 | if(match.find()){ 120 | Matcher match2=share.matcher(InString); 121 | if(match2.find()){ 122 | String G=match2.group(1); 123 | StringBuilder en=new StringBuilder(); 124 | String n=Integer.toBinaryString(memNum); 125 | int L=n.length(); 126 | for(int i=0;i<6-L;i++){ 127 | en.append("0"); 128 | } 129 | en.append(n); 130 | en.append("0000000000"); 131 | Share.put(G, en.toString()); 132 | memNum=memNum+1; 133 | } 134 | 135 | 136 | } 137 | 138 | match=Labal.matcher(InString); 139 | if(match.find()){ 140 | sout.write(InString); 141 | sout.newLine(); 142 | 143 | } 144 | 145 | } 146 | sout.write("1111111111111111: exit"); 147 | sout.newLine(); 148 | sout.close(); 149 | sin.close(); 150 | }catch (IOException e){ 151 | e.printStackTrace(); 152 | } 153 | 154 | return memNum; 155 | 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /project/src/textConvert.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.util.regex.*; 9 | import java.util.HashMap; 10 | 11 | public class textConvert { 12 | private int isaNum,memNum,entryNum; 13 | private Pattern ISA,Labal,Mem,entry,share,local,cvt; 14 | private HashMap Entry,Share,Inreg; 15 | static private FileReader fin; 16 | static private FileWriter fout; 17 | static private BufferedReader sin; 18 | static private BufferedWriter sout; 19 | 20 | public textConvert(){ 21 | isaNum=0; 22 | memNum=0; 23 | entryNum=0; 24 | Entry=new HashMap(); 25 | Share=new HashMap(); 26 | Inreg=new HashMap(); 27 | ISA=Pattern.compile("(((add|sub|mul|mad|div|rem|abs|neg|min|max|setp|set|and|bar|numeric|mov|selp|cvt|ld|st|tex|atom|bra|call|ret)\\.)|\\@\\%p[1234567890]+ bra)"); 28 | Labal=Pattern.compile("(\\$L[a-zA-Z0123456789\\_]+\\:)"); 29 | Mem=Pattern.compile(" \\.(shared)"); 30 | entry=Pattern.compile(".param .[usf]32 ([a-zA-Z0123456789\\_]*)"); 31 | share=Pattern.compile("\\[?(\\_\\_cuda\\_[a-zA-Z0123456789\\_]*)(\\+\\d+\\])?[\\[\\;]"); 32 | local=Pattern.compile("\\[([a-zA-Z0123456789\\_]*)\\];"); 33 | cvt=Pattern.compile("(cvt.[a-zA-Z0123456789.]*) (\\%r[0123456789]+, )\\%(tid.x|tid.y|tid.z|ntid.x|ntid.y|ntid.z|ctaid.x|ctaid.y|ctaid.z|nctaid.x|nctaid.y|nctaid.z);"); 34 | 35 | 36 | Inreg.put("tid.x", "00001"); 37 | Inreg.put("tid.y", "00010"); 38 | Inreg.put("tid.z", "00011"); 39 | Inreg.put("ntid.x", "00100"); 40 | Inreg.put("ntid.y", "00101"); 41 | Inreg.put("ntid.z", "00110"); 42 | Inreg.put("ctaid.x", "00111"); 43 | Inreg.put("ctaid.y", "01000"); 44 | Inreg.put("ctaid.z", "01001"); 45 | Inreg.put("nctaid.x", "01010"); 46 | Inreg.put("nctaid.y", "01011"); 47 | Inreg.put("nctaid.z", "01100"); 48 | } 49 | 50 | public int Convert(){ 51 | try{ 52 | fin=new FileReader(new File("isa.in")); 53 | fout=new FileWriter(new File("isa0.out")); 54 | sin=new BufferedReader(fin); 55 | sout=new BufferedWriter(fout); 56 | } catch (FileNotFoundException e){ 57 | e.printStackTrace(); 58 | } catch (IOException e){ 59 | e.printStackTrace(); 60 | } 61 | String InString; 62 | StringBuilder OutString; 63 | Matcher match; 64 | 65 | 66 | try{ 67 | while((InString=sin.readLine())!=null){ 68 | OutString=new StringBuilder(); 69 | System.out.println(InString); 70 | match=entry.matcher(InString); 71 | if(match.find()){ 72 | String G=match.group(1); 73 | StringBuilder en=new StringBuilder("000000"); 74 | String n=Integer.toBinaryString(entryNum); 75 | int L=n.length(); 76 | for(int i=0;i<10-L;i++){ 77 | en.append("0"); 78 | } 79 | en.append(n); 80 | Entry.put(G, en.toString()); 81 | entryNum=entryNum+1; 82 | } 83 | match=ISA.matcher(InString); 84 | if(match.find()){ 85 | isaNum=isaNum+1; 86 | /*String IN=Integer.toBinaryString(isaNum); 87 | int L=IN.length(); 88 | for (int i=0;i<16-L;i++) 89 | OutString.append("0"); 90 | OutString.append(IN); 91 | OutString.append(": ");*/ 92 | OutString.append(InString); 93 | Matcher match2; 94 | match2=share.matcher(InString); 95 | if(match2.find()){ 96 | String G2=match2.group(1); 97 | String tp=Share.get(G2); 98 | OutString.append(" "); 99 | OutString.append(tp); 100 | } 101 | match2=local.matcher(InString); 102 | if(match2.find()){ 103 | String G2=match2.group(1); 104 | String tp=Entry.get(G2); 105 | OutString.append(" "); 106 | OutString.append(tp); 107 | } 108 | match2=cvt.matcher(InString); 109 | if(match2.find()){ 110 | String G2=match2.group(3); 111 | 112 | OutString.append(Inreg.get(G2)); 113 | 114 | } 115 | sout.write(OutString.toString()); 116 | sout.newLine(); 117 | } 118 | match=Mem.matcher(InString); 119 | if(match.find()){ 120 | Matcher match2=share.matcher(InString); 121 | if(match2.find()){ 122 | String G=match2.group(1); 123 | StringBuilder en=new StringBuilder(); 124 | String n=Integer.toBinaryString(memNum); 125 | int L=n.length(); 126 | for(int i=0;i<6-L;i++){ 127 | en.append("0"); 128 | } 129 | en.append(n); 130 | en.append("0000000000"); 131 | Share.put(G, en.toString()); 132 | memNum=memNum+1; 133 | } 134 | 135 | 136 | } 137 | 138 | match=Labal.matcher(InString); 139 | if(match.find()){ 140 | sout.write(InString); 141 | sout.newLine(); 142 | 143 | } 144 | 145 | } 146 | sout.write("1111111111111111: exit"); 147 | sout.newLine(); 148 | sout.close(); 149 | sin.close(); 150 | }catch (IOException e){ 151 | e.printStackTrace(); 152 | } 153 | 154 | return memNum; 155 | 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /reconvCount.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.util.regex.*; 9 | import java.util.HashMap; 10 | import java.util.Stack; 11 | 12 | 13 | 14 | public class reconvCount { 15 | static private FileReader fin; 16 | static private FileWriter fout; 17 | static private BufferedReader sin; 18 | static private BufferedWriter sout; 19 | private int [][] branch,path; 20 | private Stack Pstack; 21 | private Pattern bra,pre,num1,num2,ex; 22 | private int braNum; 23 | private HashMap Bno1; 24 | private HashMap Bno2; 25 | public reconvCount(){ 26 | bra=Pattern.compile("(bra)"); 27 | pre=Pattern.compile("@%p"); 28 | num1=Pattern.compile("^([01][01][01][01][01][01][01][01])"); 29 | num2=Pattern.compile(";([01][01][01][01][01][01][01][01])"); 30 | ex=Pattern.compile("^(11111111)"); 31 | String InString; 32 | Matcher match,match1; 33 | braNum=0; 34 | Pstack=new Stack(); 35 | Bno1=new HashMap(); 36 | Bno2=new HashMap(); 37 | 38 | try{ 39 | fin=new FileReader(new File("isa.out")); 40 | //fout=new FileWriter(new File("isare.out")); 41 | sin=new BufferedReader(fin); 42 | //sout=new BufferedWriter(fout); 43 | } catch (FileNotFoundException e){ 44 | e.printStackTrace(); 45 | } 46 | try{ 47 | while((InString=sin.readLine())!=null){ 48 | System.out.println(InString); 49 | match=bra.matcher(InString); 50 | if(match.find()){ 51 | braNum=braNum+1; 52 | 53 | } 54 | match=ex.matcher(InString); 55 | if (match.find()){ 56 | braNum=braNum+1; 57 | } 58 | 59 | 60 | 61 | } 62 | sin.close(); 63 | }catch (IOException e){ 64 | e.printStackTrace(); 65 | } 66 | branch=new int[braNum+1][12]; 67 | path=new int[braNum+1][12]; 68 | for(int i=1;i<=braNum;i++){ 69 | branch[i][0]=i; 70 | path[i][0]=0; 71 | for(int j=1;j<=11;j++){ 72 | branch[i][j]=0; 73 | path[i][j]=0; 74 | } 75 | } 76 | int bNum=0; 77 | try{ 78 | fin=new FileReader(new File("isa.out")); 79 | //fout=new FileWriter(new File("isare.out")); 80 | sin=new BufferedReader(fin); 81 | //sout=new BufferedWriter(fout); 82 | } catch (FileNotFoundException e){ 83 | e.printStackTrace(); 84 | } 85 | try{ 86 | while((InString=sin.readLine())!=null){ 87 | System.out.println(InString); 88 | match=bra.matcher(InString); 89 | if(match.find()){ 90 | match1=num1.matcher(InString); 91 | if (match1.find()){ 92 | bNum=bNum+1; 93 | String L=match1.group(1); 94 | Bno1.put(L,bNum); 95 | Bno2.put(bNum,L); 96 | int a=0; 97 | for(int i=0;i<8;i++){ 98 | char bit=L.charAt(i); 99 | a = (a << 1) | (bit - '0'); 100 | } 101 | branch[bNum][1]=a; 102 | } 103 | 104 | } 105 | match=ex.matcher(InString); 106 | if (match.find()){ 107 | match1=num1.matcher(InString); 108 | if (match1.find()){ 109 | bNum=bNum+1; 110 | String L=match1.group(1); 111 | Bno1.put(L,bNum); 112 | Bno2.put(bNum,L); 113 | int a=0; 114 | for(int i=0;i<8;i++){ 115 | char bit=L.charAt(i); 116 | a = (a << 1) | (bit - '0'); 117 | } 118 | branch[bNum][1]=a; 119 | } 120 | } 121 | 122 | 123 | 124 | } 125 | sin.close(); 126 | }catch (IOException e){ 127 | e.printStackTrace(); 128 | } 129 | 130 | 131 | } 132 | 133 | public void Count(){ 134 | String InString; 135 | 136 | 137 | Matcher match1,match2,match3,match4; 138 | 139 | try{ 140 | fin=new FileReader(new File("isa.out")); 141 | fout=new FileWriter(new File("isare.out")); 142 | sin=new BufferedReader(fin); 143 | sout=new BufferedWriter(fout); 144 | } catch (FileNotFoundException e){ 145 | e.printStackTrace(); 146 | }catch (IOException e){ 147 | e.printStackTrace(); 148 | } 149 | try{ 150 | while((InString=sin.readLine())!=null){ 151 | match1=bra.matcher(InString); 152 | match2=pre.matcher(InString); 153 | match3=num1.matcher(InString); 154 | match4=num2.matcher(InString); 155 | int preNum=0; 156 | if (match1.find()){ 157 | System.out.println(InString); 158 | if (match3.find()){ 159 | String L=match3.group(1); 160 | preNum=Bno1.get(L); 161 | } 162 | if (match2.find()){ 163 | 164 | 165 | if (match4.find()){ 166 | String L=match4.group(1); 167 | int a=0; 168 | for(int i=0;i<8;i++){ 169 | char bit=L.charAt(i); 170 | a = (a << 1) | (bit - '0'); 171 | } 172 | 173 | int leNum=braNum,riNum=braNum; 174 | int jj=65534; 175 | for (int i=1;i<=braNum;i++){ 176 | int de=branch[i][1]-a; 177 | if (de>0&&de0&&de0&&de Pstack; 21 | private Pattern bra,pre,num1,num2,ex; 22 | private int braNum; 23 | private HashMap Bno1; 24 | private HashMap Bno2; 25 | public reconvCount(){ 26 | bra=Pattern.compile("(bra)"); 27 | pre=Pattern.compile("@%p"); 28 | num1=Pattern.compile("^([01][01][01][01][01][01][01][01])"); 29 | num2=Pattern.compile(";([01][01][01][01][01][01][01][01])"); 30 | ex=Pattern.compile("^(11111111)"); 31 | String InString; 32 | Matcher match,match1; 33 | braNum=0; 34 | Pstack=new Stack(); 35 | Bno1=new HashMap(); 36 | Bno2=new HashMap(); 37 | 38 | try{ 39 | fin=new FileReader(new File("isa.out")); 40 | //fout=new FileWriter(new File("isare.out")); 41 | sin=new BufferedReader(fin); 42 | //sout=new BufferedWriter(fout); 43 | } catch (FileNotFoundException e){ 44 | e.printStackTrace(); 45 | } 46 | try{ 47 | while((InString=sin.readLine())!=null){ 48 | System.out.println(InString); 49 | match=bra.matcher(InString); 50 | if(match.find()){ 51 | braNum=braNum+1; 52 | 53 | } 54 | match=ex.matcher(InString); 55 | if (match.find()){ 56 | braNum=braNum+1; 57 | } 58 | 59 | 60 | 61 | } 62 | sin.close(); 63 | }catch (IOException e){ 64 | e.printStackTrace(); 65 | } 66 | branch=new int[braNum+1][12]; 67 | path=new int[braNum+1][12]; 68 | for(int i=1;i<=braNum;i++){ 69 | branch[i][0]=i; 70 | path[i][0]=0; 71 | for(int j=1;j<=11;j++){ 72 | branch[i][j]=0; 73 | path[i][j]=0; 74 | } 75 | } 76 | int bNum=0; 77 | try{ 78 | fin=new FileReader(new File("isa.out")); 79 | //fout=new FileWriter(new File("isare.out")); 80 | sin=new BufferedReader(fin); 81 | //sout=new BufferedWriter(fout); 82 | } catch (FileNotFoundException e){ 83 | e.printStackTrace(); 84 | } 85 | try{ 86 | while((InString=sin.readLine())!=null){ 87 | System.out.println(InString); 88 | match=bra.matcher(InString); 89 | if(match.find()){ 90 | match1=num1.matcher(InString); 91 | if (match1.find()){ 92 | bNum=bNum+1; 93 | String L=match1.group(1); 94 | Bno1.put(L,bNum); 95 | Bno2.put(bNum,L); 96 | int a=0; 97 | for(int i=0;i<8;i++){ 98 | char bit=L.charAt(i); 99 | a = (a << 1) | (bit - '0'); 100 | } 101 | branch[bNum][1]=a; 102 | } 103 | 104 | } 105 | match=ex.matcher(InString); 106 | if (match.find()){ 107 | match1=num1.matcher(InString); 108 | if (match1.find()){ 109 | bNum=bNum+1; 110 | String L=match1.group(1); 111 | Bno1.put(L,bNum); 112 | Bno2.put(bNum,L); 113 | int a=0; 114 | for(int i=0;i<8;i++){ 115 | char bit=L.charAt(i); 116 | a = (a << 1) | (bit - '0'); 117 | } 118 | branch[bNum][1]=a; 119 | } 120 | } 121 | 122 | 123 | 124 | } 125 | sin.close(); 126 | }catch (IOException e){ 127 | e.printStackTrace(); 128 | } 129 | 130 | 131 | } 132 | 133 | public void Count(){ 134 | String InString; 135 | 136 | 137 | Matcher match1,match2,match3,match4; 138 | 139 | try{ 140 | fin=new FileReader(new File("isa.out")); 141 | fout=new FileWriter(new File("isare.out")); 142 | sin=new BufferedReader(fin); 143 | sout=new BufferedWriter(fout); 144 | } catch (FileNotFoundException e){ 145 | e.printStackTrace(); 146 | }catch (IOException e){ 147 | e.printStackTrace(); 148 | } 149 | try{ 150 | while((InString=sin.readLine())!=null){ 151 | match1=bra.matcher(InString); 152 | match2=pre.matcher(InString); 153 | match3=num1.matcher(InString); 154 | match4=num2.matcher(InString); 155 | int preNum=0; 156 | if (match1.find()){ 157 | System.out.println(InString); 158 | if (match3.find()){ 159 | String L=match3.group(1); 160 | preNum=Bno1.get(L); 161 | } 162 | if (match2.find()){ 163 | 164 | 165 | if (match4.find()){ 166 | String L=match4.group(1); 167 | int a=0; 168 | for(int i=0;i<8;i++){ 169 | char bit=L.charAt(i); 170 | a = (a << 1) | (bit - '0'); 171 | } 172 | 173 | int leNum=braNum,riNum=braNum; 174 | int jj=65534; 175 | for (int i=1;i<=braNum;i++){ 176 | int de=branch[i][1]-a; 177 | if (de>0&&de0&&de0&&de Pstack; 19 | private Pattern bra, pre, num1, num2; 20 | private int braNum; 21 | private HashMap waL; 22 | private HashMap Bno1; 23 | private HashMap Bno2; 24 | 25 | public conrecon() { 26 | bra = Pattern.compile("(bra)"); 27 | pre = Pattern.compile("@%p"); 28 | num1 = Pattern 29 | .compile("^([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01])"); 30 | num2 = Pattern 31 | .compile(";([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01])"); 32 | 33 | String InString; 34 | Matcher match1, match2, match3; 35 | braNum = 0; 36 | Pstack = new Stack(); 37 | Bno1 = new HashMap(); 38 | Bno2 = new HashMap(); 39 | waL = new HashMap(); 40 | 41 | 42 | try { 43 | fin = new FileReader(new File("isa.out")); 44 | // fout=new FileWriter(new File("isare.out")); 45 | sin = new BufferedReader(fin); 46 | // sout=new BufferedWriter(fout); 47 | } catch (FileNotFoundException e) { 48 | e.printStackTrace(); 49 | } 50 | int OKL = 0; 51 | try { 52 | while ((InString = sin.readLine()) != null) { 53 | System.out.println(InString); 54 | if(OKL==1){ 55 | OKL=0; 56 | match1=num1.matcher(InString); 57 | if(match1.find()){ 58 | String G=match1.group(1); 59 | if(!"1".equals(waL.get(G))){ 60 | braNum=braNum+1; 61 | waL.put(G, "1"); 62 | } 63 | } 64 | } 65 | match1 = bra.matcher(InString); 66 | if (match1.find()) { 67 | match2=num1.matcher(InString); 68 | if(match2.find()){ 69 | String G = match2.group(1); 70 | if(!"1".equals(waL.get(G))){ 71 | waL.put(G, "1"); 72 | braNum=braNum+1; 73 | } 74 | } 75 | 76 | match2=num2.matcher(InString); 77 | if(match2.find()){ 78 | String GG = match2.group(1); 79 | if(!"1".equals(waL.get(GG))){ 80 | braNum=braNum+1; 81 | waL.put(GG, "1"); 82 | } 83 | } 84 | match3=pre.matcher(InString); 85 | if(match3.find()){ 86 | OKL=1; 87 | } 88 | } 89 | 90 | 91 | 92 | 93 | } 94 | sin.close(); 95 | 96 | } catch (IOException e) { 97 | e.printStackTrace(); 98 | } 99 | branch = new int[braNum + 1][8]; 100 | path = new int[braNum + 1][8]; 101 | for (int i = 1; i <= braNum; i++) { 102 | branch[i][0] = i; 103 | path[i][0] = i; 104 | for (int j = 1; j <= 7; j++) { 105 | branch[i][j] = 0; 106 | path[i][j] = 0; 107 | } 108 | } 109 | 110 | OKL = 0; 111 | int bnum=0; 112 | 113 | try { 114 | fin = new FileReader(new File("isa.out")); 115 | // fout=new FileWriter(new File("isare.out")); 116 | sin = new BufferedReader(fin); 117 | // sout=new BufferedWriter(fout); 118 | } catch (FileNotFoundException e) { 119 | e.printStackTrace(); 120 | } 121 | try { 122 | while ((InString = sin.readLine()) != null) { 123 | System.out.println(InString); 124 | match1 = num1.matcher(InString); 125 | String G; 126 | if (match1.find()) { 127 | G=match1.group(1); 128 | if("1".equals(waL.get(G))){ 129 | bnum=bnum+1; 130 | Bno1.put(G, bnum); 131 | Bno2.put(bnum, G); 132 | } 133 | 134 | 135 | } 136 | } 137 | if(!"1".equals(waL.get("1111111111111111"))){ 138 | bnum=bnum+1; 139 | Bno1.put("1111111111111111",braNum); 140 | Bno2.put(braNum,"1111111111111111"); 141 | } 142 | 143 | sin.close(); 144 | }catch (IOException e) { 145 | e.printStackTrace(); 146 | } 147 | 148 | try { 149 | fin = new FileReader(new File("isa.out")); 150 | // fout=new FileWriter(new File("isare.out")); 151 | sin = new BufferedReader(fin); 152 | // sout=new BufferedWriter(fout); 153 | } catch (FileNotFoundException e) { 154 | e.printStackTrace(); 155 | } 156 | try { 157 | while ((InString = sin.readLine()) != null) { 158 | String G; 159 | match1=bra.matcher(InString); 160 | if(match1.find()){ 161 | int sn=0,dn1=0,dn2=0; 162 | 163 | match2=num1.matcher(InString); 164 | if(match2.find()){ 165 | G=match2.group(1); 166 | sn=Bno1.get(G); 167 | } 168 | 169 | match2=num2.matcher(InString); 170 | if(match2.find()){ 171 | G=match2.group(1); 172 | dn1=Bno1.get(G); 173 | branch[sn][1]=dn1; 174 | path[sn][1]=1; 175 | for(int i=3;i<=6;i++){ 176 | if (branch[dn1][i]==0){ 177 | branch[dn1][i]=sn; 178 | path[dn1][i]=1; 179 | break; 180 | } 181 | } 182 | } 183 | match2=pre.matcher(InString); 184 | if(match2.find()){ 185 | int a=0; 186 | 187 | match3=num1.matcher(InString); 188 | if(match3.find()) 189 | G=match3.group(1); 190 | else G="0"; 191 | for(int i=0;i<16;i++){ 192 | char bit=G.charAt(i); 193 | a = (a << 1) | (bit - '0'); 194 | } 195 | a=a+1; 196 | StringBuilder t=new StringBuilder(); 197 | String LL=Integer.toBinaryString(a); 198 | int L=LL.length(); 199 | for(int i=0;i<16-L;i++){ 200 | t.append("0"); 201 | } 202 | t.append(LL); 203 | String Q=t.toString(); 204 | if("1".equals(waL.get(Q))){ 205 | dn2=Bno1.get(Q); 206 | } 207 | else dn2=Bno1.get("1111111111111111"); 208 | branch[sn][2]=dn2; 209 | path[sn][2]=1; 210 | for(int i=3;i<=6;i++){ 211 | if (branch[dn2][i]==0){ 212 | branch[dn2][i]=sn; 213 | path[dn2][i]=1; 214 | break; 215 | } 216 | } 217 | } 218 | } 219 | 220 | } 221 | sin.close(); 222 | 223 | } catch (IOException e) { 224 | e.printStackTrace(); 225 | } 226 | for(int i=1;i1){ 324 | Pstack.push(Num); 325 | c=1; 326 | } 327 | 328 | } 329 | for(int i=3;i<=6;i++){ 330 | if(branch[Num][i]!=0&&path[Num][i]!=0&&branch[Num][i] Pstack; 19 | private Pattern bra, pre, num1, num2; 20 | private int braNum; 21 | private HashMap waL; 22 | private HashMap Bno1; 23 | private HashMap Bno2; 24 | 25 | public conrecon() { 26 | bra = Pattern.compile("(bra)"); 27 | pre = Pattern.compile("@%p"); 28 | num1 = Pattern 29 | .compile("^([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01])"); 30 | num2 = Pattern 31 | .compile(";([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01])"); 32 | 33 | String InString; 34 | Matcher match1, match2, match3; 35 | braNum = 0; 36 | Pstack = new Stack(); 37 | Bno1 = new HashMap(); 38 | Bno2 = new HashMap(); 39 | waL = new HashMap(); 40 | 41 | 42 | try { 43 | fin = new FileReader(new File("isa.out")); 44 | // fout=new FileWriter(new File("isare.out")); 45 | sin = new BufferedReader(fin); 46 | // sout=new BufferedWriter(fout); 47 | } catch (FileNotFoundException e) { 48 | e.printStackTrace(); 49 | } 50 | int OKL = 0; 51 | try { 52 | while ((InString = sin.readLine()) != null) { 53 | System.out.println(InString); 54 | if(OKL==1){ 55 | OKL=0; 56 | match1=num1.matcher(InString); 57 | if(match1.find()){ 58 | String G=match1.group(1); 59 | if(!"1".equals(waL.get(G))){ 60 | braNum=braNum+1; 61 | waL.put(G, "1"); 62 | } 63 | } 64 | } 65 | match1 = bra.matcher(InString); 66 | if (match1.find()) { 67 | match2=num1.matcher(InString); 68 | if(match2.find()){ 69 | String G = match2.group(1); 70 | if(!"1".equals(waL.get(G))){ 71 | waL.put(G, "1"); 72 | braNum=braNum+1; 73 | } 74 | } 75 | 76 | match2=num2.matcher(InString); 77 | if(match2.find()){ 78 | String GG = match2.group(1); 79 | if(!"1".equals(waL.get(GG))){ 80 | braNum=braNum+1; 81 | waL.put(GG, "1"); 82 | } 83 | } 84 | match3=pre.matcher(InString); 85 | if(match3.find()){ 86 | OKL=1; 87 | } 88 | } 89 | 90 | 91 | 92 | 93 | } 94 | sin.close(); 95 | 96 | } catch (IOException e) { 97 | e.printStackTrace(); 98 | } 99 | branch = new int[braNum + 1][8]; 100 | path = new int[braNum + 1][8]; 101 | for (int i = 1; i <= braNum; i++) { 102 | branch[i][0] = i; 103 | path[i][0] = i; 104 | for (int j = 1; j <= 7; j++) { 105 | branch[i][j] = 0; 106 | path[i][j] = 0; 107 | } 108 | } 109 | 110 | OKL = 0; 111 | int bnum=0; 112 | 113 | try { 114 | fin = new FileReader(new File("isa.out")); 115 | // fout=new FileWriter(new File("isare.out")); 116 | sin = new BufferedReader(fin); 117 | // sout=new BufferedWriter(fout); 118 | } catch (FileNotFoundException e) { 119 | e.printStackTrace(); 120 | } 121 | try { 122 | while ((InString = sin.readLine()) != null) { 123 | System.out.println(InString); 124 | match1 = num1.matcher(InString); 125 | String G; 126 | if (match1.find()) { 127 | G=match1.group(1); 128 | if("1".equals(waL.get(G))){ 129 | bnum=bnum+1; 130 | Bno1.put(G, bnum); 131 | Bno2.put(bnum, G); 132 | } 133 | 134 | 135 | } 136 | } 137 | if(!"1".equals(waL.get("1111111111111111"))){ 138 | bnum=bnum+1; 139 | Bno1.put("1111111111111111",braNum); 140 | Bno2.put(braNum,"1111111111111111"); 141 | } 142 | 143 | sin.close(); 144 | }catch (IOException e) { 145 | e.printStackTrace(); 146 | } 147 | 148 | try { 149 | fin = new FileReader(new File("isa.out")); 150 | // fout=new FileWriter(new File("isare.out")); 151 | sin = new BufferedReader(fin); 152 | // sout=new BufferedWriter(fout); 153 | } catch (FileNotFoundException e) { 154 | e.printStackTrace(); 155 | } 156 | try { 157 | while ((InString = sin.readLine()) != null) { 158 | String G; 159 | match1=bra.matcher(InString); 160 | if(match1.find()){ 161 | int sn=0,dn1=0,dn2=0; 162 | 163 | match2=num1.matcher(InString); 164 | if(match2.find()){ 165 | G=match2.group(1); 166 | sn=Bno1.get(G); 167 | } 168 | 169 | match2=num2.matcher(InString); 170 | if(match2.find()){ 171 | G=match2.group(1); 172 | dn1=Bno1.get(G); 173 | branch[sn][1]=dn1; 174 | path[sn][1]=1; 175 | for(int i=3;i<=6;i++){ 176 | if (branch[dn1][i]==0){ 177 | branch[dn1][i]=sn; 178 | path[dn1][i]=1; 179 | break; 180 | } 181 | } 182 | } 183 | match2=pre.matcher(InString); 184 | if(match2.find()){ 185 | int a=0; 186 | 187 | match3=num1.matcher(InString); 188 | if(match3.find()) 189 | G=match3.group(1); 190 | else G="0"; 191 | for(int i=0;i<16;i++){ 192 | char bit=G.charAt(i); 193 | a = (a << 1) | (bit - '0'); 194 | } 195 | a=a+1; 196 | StringBuilder t=new StringBuilder(); 197 | String LL=Integer.toBinaryString(a); 198 | int L=LL.length(); 199 | for(int i=0;i<16-L;i++){ 200 | t.append("0"); 201 | } 202 | t.append(LL); 203 | String Q=t.toString(); 204 | if("1".equals(waL.get(Q))){ 205 | dn2=Bno1.get(Q); 206 | } 207 | else dn2=Bno1.get("1111111111111111"); 208 | branch[sn][2]=dn2; 209 | path[sn][2]=1; 210 | for(int i=3;i<=6;i++){ 211 | if (branch[dn2][i]==0){ 212 | branch[dn2][i]=sn; 213 | path[dn2][i]=1; 214 | break; 215 | } 216 | } 217 | } 218 | } 219 | 220 | } 221 | sin.close(); 222 | 223 | } catch (IOException e) { 224 | e.printStackTrace(); 225 | } 226 | for(int i=1;i1){ 324 | Pstack.push(Num); 325 | c=1; 326 | } 327 | 328 | } 329 | for(int i=3;i<=6;i++){ 330 | if(branch[Num][i]!=0&&path[Num][i]!=0&&branch[Num][i] alloreg1,allomem; 15 | private HashMap alloreg2; 16 | private HashMap regstate; 17 | private int regocu[]; 18 | static private FileReader fin,ffin; 19 | static private FileWriter fout; 20 | static private BufferedReader sin,ssin; 21 | static private BufferedWriter sout; 22 | 23 | public regAllo(){ 24 | alloreg1=new HashMap (); 25 | allomem=new HashMap (); 26 | alloreg2=new HashMap (); 27 | regstate=new HashMap (); 28 | regocu=new int[17]; 29 | reg=Pattern.compile("(%[rf][0123456789]+)([,;+])"); 30 | for(int i=1;i<=16;i++) 31 | regocu[i]=0; 32 | } 33 | public void allocation(){ 34 | int lineNum=0; 35 | int MemNum=0; 36 | 37 | try{ 38 | fin=new FileReader(new File("isa0.out")); 39 | fout=new FileWriter(new File("isa00.out")); 40 | sin=new BufferedReader(fin); 41 | sout=new BufferedWriter(fout); 42 | } catch (FileNotFoundException e){ 43 | e.printStackTrace(); 44 | } catch (IOException e){ 45 | e.printStackTrace(); 46 | } 47 | String InString; 48 | StringBuffer OutString; 49 | Matcher match; 50 | try{ 51 | while((InString=sin.readLine())!=null){ 52 | for(int i=1;i<=16;i++){ 53 | if (regocu[i]==2) 54 | regocu[i]=0; 55 | } 56 | lineNum=lineNum+1; 57 | //OutString=new StringBuffer(); 58 | System.out.println(InString); 59 | match=reg.matcher(InString); 60 | while(match.find()){ 61 | String reNm=match.group(1); 62 | System.out.println(reNm); 63 | boolean allsec=false; 64 | if(!"1".equals(regstate.get(reNm)) && !"2".equals(regstate.get(reNm))){ 65 | 66 | for(int i=1;i<=16;i++){ 67 | if(regocu[i]==0){ 68 | allsec=true; 69 | regocu[i]=1; 70 | alloreg1.put(reNm, i); 71 | alloreg2.put(i, reNm); 72 | regstate.put(reNm, "1"); 73 | break; 74 | } 75 | } 76 | } 77 | 78 | if("2".equals(regstate.get(reNm))){ 79 | Integer sl=0; 80 | for(int i=1;i<=16;i++){ 81 | if(regocu[i]==0){ 82 | allsec=true; 83 | regocu[i]=1; 84 | alloreg1.put(reNm, i); 85 | alloreg2.put(i, reNm); 86 | regstate.put(reNm, "1"); 87 | sl=i; 88 | break; 89 | } 90 | } 91 | if(allsec){ 92 | OutString=new StringBuffer(); 93 | OutString.append(" ld.global.s32 %r"); 94 | String ew=sl.toString(); 95 | OutString.append(ew); 96 | OutString.append(", [__cuda__]; "); 97 | sl=allomem.get(reNm); 98 | ew=Integer.toBinaryString(sl); 99 | int lenl=ew.length(); 100 | for(int i=1;i<=16-lenl;i++) 101 | OutString.append("0"); 102 | OutString.append(ew); 103 | System.out.println(OutString.toString()); 104 | sout.write(OutString.toString()); 105 | sout.newLine(); 106 | } 107 | 108 | } 109 | if(!allsec && !"1".equals(regstate.get(reNm))){ 110 | try{ 111 | ffin=new FileReader(new File("isa0.out")); 112 | ssin=new BufferedReader(ffin); 113 | } catch(FileNotFoundException e){ 114 | e.printStackTrace(); 115 | } 116 | String IInString; 117 | boolean regu[]=new boolean[17]; 118 | for(int i=1;i<=16;i++){ 119 | regu[i]=true; 120 | } 121 | int llineNum=0; 122 | try{ 123 | while((IInString=ssin.readLine())!=null){ 124 | llineNum=llineNum+1; 125 | if(llineNum>=lineNum){ 126 | Matcher mmatch=reg.matcher(IInString); 127 | boolean same=false; 128 | while(mmatch.find()){ 129 | String cp=mmatch.group(1); 130 | if (cp.equals(reNm)){ 131 | same=true; 132 | break; 133 | } 134 | } 135 | if(same){ 136 | mmatch=reg.matcher(IInString); 137 | while(mmatch.find()){ 138 | String s=mmatch.group(1); 139 | if (!s.equals(reNm) && ("0".equals(regstate.get(s)) || "1".equals(regstate.get(s)) || "2".equals(regstate.get(s)))){ 140 | int nn=alloreg1.get(s); 141 | regu[nn]=false; 142 | } 143 | 144 | } 145 | } 146 | } 147 | } 148 | } catch(IOException e){ 149 | e.printStackTrace(); 150 | } 151 | ssin.close(); 152 | llineNum=0; 153 | try{ 154 | ffin=new FileReader(new File("isa0.out")); 155 | ssin=new BufferedReader(ffin); 156 | } catch(FileNotFoundException e){ 157 | e.printStackTrace(); 158 | } 159 | try{ 160 | while((IInString=ssin.readLine())!=null){ 161 | llineNum=llineNum+1; 162 | if(llineNum>lineNum){ 163 | int fdmm=0; 164 | for(int i=1;i<=16;i++){ 165 | if(regu[i]) 166 | fdmm=fdmm+1; 167 | } 168 | if(fdmm==1) 169 | break; 170 | Matcher mmatch=reg.matcher(IInString); 171 | while(mmatch.find()){ 172 | for(int i=1;i<=16;i++){ 173 | if(regu[i]){ 174 | String rrenm=alloreg2.get(i); 175 | if(rrenm.equals(mmatch.group(1))) 176 | regu[i]=false; 177 | } 178 | 179 | } 180 | int ffdm=0; 181 | for(int i=1;i<=16;i++){ 182 | if(regu[i]) 183 | ffdm=ffdm+1; 184 | } 185 | if(ffdm==1) 186 | break; 187 | } 188 | if(fdmm==1) 189 | break; 190 | } 191 | } 192 | ssin.close(); 193 | } catch (IOException e){ 194 | e.printStackTrace(); 195 | } 196 | int rn=0; 197 | for(int i=1;i<=16;i++){ 198 | if(regu[i]) 199 | rn=i; 200 | } 201 | String tomem=alloreg2.get(rn); 202 | MemNum=MemNum+1; 203 | allomem.put(tomem, MemNum); 204 | regstate.put(tomem, "2"); 205 | alloreg1.put(reNm, rn); 206 | alloreg2.put(rn, reNm); 207 | regstate.put(reNm, "1"); 208 | OutString=new StringBuffer(); 209 | if("2".equals(regstate.get(reNm))){ 210 | OutString.append(" ld.global.s32 %r"); 211 | Integer sl=rn; 212 | String ew=sl.toString(); 213 | OutString.append(ew); 214 | OutString.append(", [__cuda__]; "); 215 | sl=allomem.get(reNm); 216 | ew=Integer.toBinaryString(sl); 217 | int lenl=ew.length(); 218 | for(int i=1;i<=16-lenl;i++) 219 | OutString.append("0"); 220 | OutString.append(ew); 221 | System.out.println(OutString.toString()); 222 | sout.write(OutString.toString()); 223 | sout.newLine(); 224 | } 225 | 226 | OutString.append(" st.global.s32 [%r0+"); 227 | Integer MN=MemNum; 228 | String t=MN.toString(); 229 | OutString.append(t); 230 | OutString.append("], %r"); 231 | MN=rn; 232 | t=MN.toString(); 233 | OutString.append(t); 234 | OutString.append(";"); 235 | System.out.println(OutString.toString()); 236 | sout.write(OutString.toString()); 237 | sout.newLine(); 238 | 239 | } 240 | if ("1".equals(regstate.get(reNm))){ 241 | try{ 242 | ffin=new FileReader(new File("isa0.out")); 243 | ssin=new BufferedReader(ffin); 244 | } catch(FileNotFoundException e){ 245 | e.printStackTrace(); 246 | } 247 | String IInString; 248 | int llineNum=0; 249 | boolean regend=true; 250 | try{ 251 | while((IInString=ssin.readLine())!=null){ 252 | llineNum=llineNum+1; 253 | 254 | if(llineNum>lineNum){ 255 | Matcher mmatch=reg.matcher(IInString); 256 | while(mmatch.find()){ 257 | String rreNm=mmatch.group(1); 258 | if (rreNm.equals(reNm)){ 259 | regend=false; 260 | break; 261 | 262 | } 263 | } 264 | } 265 | if (regend==false){ 266 | ssin.close(); 267 | break; 268 | } 269 | } 270 | } catch (IOException e){ 271 | e.printStackTrace(); 272 | } 273 | if (regend==true){ 274 | regstate.put(reNm, "0"); 275 | regocu[alloreg1.get(reNm)]=2; 276 | } 277 | } 278 | 279 | } 280 | 281 | match=reg.matcher(InString); 282 | boolean mat=false; 283 | OutString=new StringBuffer(); 284 | while(match.find()){ 285 | mat=true; 286 | String con1=match.group(1); 287 | String con2=match.group(2); 288 | Integer N=alloreg1.get(con1); 289 | String NN=N.toString(); 290 | StringBuffer Ot=new StringBuffer(); 291 | Ot.append("%r"); 292 | Ot.append(NN); 293 | Ot.append(con2); 294 | String con3=Ot.toString(); 295 | 296 | match.appendReplacement(OutString, con3); 297 | } 298 | match.appendTail(OutString); 299 | System.out.println(OutString.toString()); 300 | sout.write(OutString.toString()); 301 | sout.newLine(); 302 | } 303 | sin.close(); 304 | sout.close(); 305 | } 306 | catch (IOException e){ 307 | e.printStackTrace(); 308 | } 309 | } 310 | } 311 | -------------------------------------------------------------------------------- /project/src/regAllo.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.util.regex.*; 9 | import java.util.HashMap; 10 | 11 | public class regAllo { 12 | 13 | private Pattern reg; 14 | private HashMap alloreg1,allomem; 15 | private HashMap alloreg2; 16 | private HashMap regstate; 17 | private int regocu[]; 18 | static private FileReader fin,ffin; 19 | static private FileWriter fout; 20 | static private BufferedReader sin,ssin; 21 | static private BufferedWriter sout; 22 | 23 | public regAllo(){ 24 | alloreg1=new HashMap (); 25 | allomem=new HashMap (); 26 | alloreg2=new HashMap (); 27 | regstate=new HashMap (); 28 | regocu=new int[17]; 29 | reg=Pattern.compile("(%[rf][0123456789]+)([,;+])"); 30 | for(int i=1;i<=16;i++) 31 | regocu[i]=0; 32 | } 33 | public void allocation(){ 34 | int lineNum=0; 35 | int MemNum=0; 36 | 37 | try{ 38 | fin=new FileReader(new File("isa0.out")); 39 | fout=new FileWriter(new File("isa00.out")); 40 | sin=new BufferedReader(fin); 41 | sout=new BufferedWriter(fout); 42 | } catch (FileNotFoundException e){ 43 | e.printStackTrace(); 44 | } catch (IOException e){ 45 | e.printStackTrace(); 46 | } 47 | String InString; 48 | StringBuffer OutString; 49 | Matcher match; 50 | try{ 51 | while((InString=sin.readLine())!=null){ 52 | for(int i=1;i<=16;i++){ 53 | if (regocu[i]==2) 54 | regocu[i]=0; 55 | } 56 | lineNum=lineNum+1; 57 | //OutString=new StringBuffer(); 58 | System.out.println(InString); 59 | match=reg.matcher(InString); 60 | while(match.find()){ 61 | String reNm=match.group(1); 62 | System.out.println(reNm); 63 | boolean allsec=false; 64 | if(!"1".equals(regstate.get(reNm)) && !"2".equals(regstate.get(reNm))){ 65 | 66 | for(int i=1;i<=16;i++){ 67 | if(regocu[i]==0){ 68 | allsec=true; 69 | regocu[i]=1; 70 | alloreg1.put(reNm, i); 71 | alloreg2.put(i, reNm); 72 | regstate.put(reNm, "1"); 73 | break; 74 | } 75 | } 76 | } 77 | 78 | if("2".equals(regstate.get(reNm))){ 79 | Integer sl=0; 80 | for(int i=1;i<=16;i++){ 81 | if(regocu[i]==0){ 82 | allsec=true; 83 | regocu[i]=1; 84 | alloreg1.put(reNm, i); 85 | alloreg2.put(i, reNm); 86 | regstate.put(reNm, "1"); 87 | sl=i; 88 | break; 89 | } 90 | } 91 | if(allsec){ 92 | OutString=new StringBuffer(); 93 | OutString.append(" ld.global.s32 %r"); 94 | String ew=sl.toString(); 95 | OutString.append(ew); 96 | OutString.append(", [__cuda__]; "); 97 | sl=allomem.get(reNm); 98 | ew=Integer.toBinaryString(sl); 99 | int lenl=ew.length(); 100 | for(int i=1;i<=16-lenl;i++) 101 | OutString.append("0"); 102 | OutString.append(ew); 103 | System.out.println(OutString.toString()); 104 | sout.write(OutString.toString()); 105 | sout.newLine(); 106 | } 107 | 108 | } 109 | if(!allsec && !"1".equals(regstate.get(reNm))){ 110 | try{ 111 | ffin=new FileReader(new File("isa0.out")); 112 | ssin=new BufferedReader(ffin); 113 | } catch(FileNotFoundException e){ 114 | e.printStackTrace(); 115 | } 116 | String IInString; 117 | boolean regu[]=new boolean[17]; 118 | for(int i=1;i<=16;i++){ 119 | regu[i]=true; 120 | } 121 | int llineNum=0; 122 | try{ 123 | while((IInString=ssin.readLine())!=null){ 124 | llineNum=llineNum+1; 125 | if(llineNum>=lineNum){ 126 | Matcher mmatch=reg.matcher(IInString); 127 | boolean same=false; 128 | while(mmatch.find()){ 129 | String cp=mmatch.group(1); 130 | if (cp.equals(reNm)){ 131 | same=true; 132 | break; 133 | } 134 | } 135 | if(same){ 136 | mmatch=reg.matcher(IInString); 137 | while(mmatch.find()){ 138 | String s=mmatch.group(1); 139 | if (!s.equals(reNm) && ("0".equals(regstate.get(s)) || "1".equals(regstate.get(s)) || "2".equals(regstate.get(s)))){ 140 | int nn=alloreg1.get(s); 141 | regu[nn]=false; 142 | } 143 | 144 | } 145 | } 146 | } 147 | } 148 | } catch(IOException e){ 149 | e.printStackTrace(); 150 | } 151 | ssin.close(); 152 | llineNum=0; 153 | try{ 154 | ffin=new FileReader(new File("isa0.out")); 155 | ssin=new BufferedReader(ffin); 156 | } catch(FileNotFoundException e){ 157 | e.printStackTrace(); 158 | } 159 | try{ 160 | while((IInString=ssin.readLine())!=null){ 161 | llineNum=llineNum+1; 162 | if(llineNum>lineNum){ 163 | int fdmm=0; 164 | for(int i=1;i<=16;i++){ 165 | if(regu[i]) 166 | fdmm=fdmm+1; 167 | } 168 | if(fdmm==1) 169 | break; 170 | Matcher mmatch=reg.matcher(IInString); 171 | while(mmatch.find()){ 172 | for(int i=1;i<=16;i++){ 173 | if(regu[i]){ 174 | String rrenm=alloreg2.get(i); 175 | if(rrenm.equals(mmatch.group(1))) 176 | regu[i]=false; 177 | } 178 | 179 | } 180 | int ffdm=0; 181 | for(int i=1;i<=16;i++){ 182 | if(regu[i]) 183 | ffdm=ffdm+1; 184 | } 185 | if(ffdm==1) 186 | break; 187 | } 188 | if(fdmm==1) 189 | break; 190 | } 191 | } 192 | ssin.close(); 193 | } catch (IOException e){ 194 | e.printStackTrace(); 195 | } 196 | int rn=0; 197 | for(int i=1;i<=16;i++){ 198 | if(regu[i]) 199 | rn=i; 200 | } 201 | String tomem=alloreg2.get(rn); 202 | MemNum=MemNum+1; 203 | allomem.put(tomem, MemNum); 204 | regstate.put(tomem, "2"); 205 | alloreg1.put(reNm, rn); 206 | alloreg2.put(rn, reNm); 207 | regstate.put(reNm, "1"); 208 | OutString=new StringBuffer(); 209 | if("2".equals(regstate.get(reNm))){ 210 | OutString.append(" ld.global.s32 %r"); 211 | Integer sl=rn; 212 | String ew=sl.toString(); 213 | OutString.append(ew); 214 | OutString.append(", [__cuda__]; "); 215 | sl=allomem.get(reNm); 216 | ew=Integer.toBinaryString(sl); 217 | int lenl=ew.length(); 218 | for(int i=1;i<=16-lenl;i++) 219 | OutString.append("0"); 220 | OutString.append(ew); 221 | System.out.println(OutString.toString()); 222 | sout.write(OutString.toString()); 223 | sout.newLine(); 224 | } 225 | 226 | OutString.append(" st.global.s32 [%r0+"); 227 | Integer MN=MemNum; 228 | String t=MN.toString(); 229 | OutString.append(t); 230 | OutString.append("], %r"); 231 | MN=rn; 232 | t=MN.toString(); 233 | OutString.append(t); 234 | OutString.append(";"); 235 | System.out.println(OutString.toString()); 236 | sout.write(OutString.toString()); 237 | sout.newLine(); 238 | 239 | } 240 | if ("1".equals(regstate.get(reNm))){ 241 | try{ 242 | ffin=new FileReader(new File("isa0.out")); 243 | ssin=new BufferedReader(ffin); 244 | } catch(FileNotFoundException e){ 245 | e.printStackTrace(); 246 | } 247 | String IInString; 248 | int llineNum=0; 249 | boolean regend=true; 250 | try{ 251 | while((IInString=ssin.readLine())!=null){ 252 | llineNum=llineNum+1; 253 | 254 | if(llineNum>lineNum){ 255 | Matcher mmatch=reg.matcher(IInString); 256 | while(mmatch.find()){ 257 | String rreNm=mmatch.group(1); 258 | if (rreNm.equals(reNm)){ 259 | regend=false; 260 | break; 261 | 262 | } 263 | } 264 | } 265 | if (regend==false){ 266 | ssin.close(); 267 | break; 268 | } 269 | } 270 | } catch (IOException e){ 271 | e.printStackTrace(); 272 | } 273 | if (regend==true){ 274 | regstate.put(reNm, "0"); 275 | regocu[alloreg1.get(reNm)]=2; 276 | } 277 | } 278 | 279 | } 280 | 281 | match=reg.matcher(InString); 282 | boolean mat=false; 283 | OutString=new StringBuffer(); 284 | while(match.find()){ 285 | mat=true; 286 | String con1=match.group(1); 287 | String con2=match.group(2); 288 | Integer N=alloreg1.get(con1); 289 | String NN=N.toString(); 290 | StringBuffer Ot=new StringBuffer(); 291 | Ot.append("%r"); 292 | Ot.append(NN); 293 | Ot.append(con2); 294 | String con3=Ot.toString(); 295 | 296 | match.appendReplacement(OutString, con3); 297 | } 298 | match.appendTail(OutString); 299 | System.out.println(OutString.toString()); 300 | sout.write(OutString.toString()); 301 | sout.newLine(); 302 | } 303 | sin.close(); 304 | sout.close(); 305 | } 306 | catch (IOException e){ 307 | e.printStackTrace(); 308 | } 309 | } 310 | } 311 | -------------------------------------------------------------------------------- /reCon.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.util.regex.*; 9 | import java.util.HashMap; 10 | import java.util.Stack; 11 | 12 | 13 | 14 | public class reCon{ 15 | static private FileReader fin; 16 | static private FileWriter fout; 17 | static private BufferedReader sin; 18 | static private BufferedWriter sout; 19 | private int [][] branch,path; 20 | private Stack Pstack; 21 | private Pattern bra,pre,num1,num2,ex; 22 | private int braNum; 23 | private HashMap Bno1; 24 | private HashMap Bno2; 25 | private HashMap PP,PP2; 26 | public reCon(){ 27 | bra=Pattern.compile("(bra)"); 28 | pre=Pattern.compile("@%p"); 29 | num1=Pattern.compile("^([01][01][01][01][01][01][01][01])"); 30 | num2=Pattern.compile(";([01][01][01][01][01][01][01][01])"); 31 | ex=Pattern.compile("^(11111111)"); 32 | String InString; 33 | Matcher match,match1,match2,match3; 34 | braNum=0; 35 | Pstack=new Stack(); 36 | Bno1=new HashMap(); 37 | Bno2=new HashMap(); 38 | PP=new HashMap(); 39 | PP2=new HashMap(); 40 | int www=0; 41 | try{ 42 | fin=new FileReader(new File("isa.out")); 43 | //fout=new FileWriter(new File("isare.out")); 44 | sin=new BufferedReader(fin); 45 | //sout=new BufferedWriter(fout); 46 | } catch (FileNotFoundException e){ 47 | e.printStackTrace(); 48 | } 49 | try{ 50 | while((InString=sin.readLine())!=null){ 51 | 52 | System.out.println(InString); 53 | match=bra.matcher(InString); 54 | match3=pre.matcher(InString); 55 | String Get,To; 56 | if(www==1){ 57 | match1=num1.matcher(InString); 58 | if (match1.find()){ 59 | Get=match1.group(1); 60 | To=PP.get(Get); 61 | if (!"1".equals(To)){ 62 | braNum=braNum+1; 63 | PP.put(Get, "1"); 64 | } 65 | } 66 | } 67 | www=0; 68 | if(match.find()){ 69 | match1=num1.matcher(InString); 70 | match2=num2.matcher(InString); 71 | if (match1.find()){ 72 | Get=match1.group(1); 73 | To=PP.get(Get); 74 | if (!"1".equals(To)){ 75 | braNum=braNum+1; 76 | PP.put(Get, "1"); 77 | } 78 | } 79 | if (match2.find()){ 80 | Get=match2.group(1); 81 | To=PP.get(Get); 82 | if (!"1".equals(To)){ 83 | braNum=braNum+1; 84 | PP.put(Get, "1"); 85 | } 86 | } 87 | if(match3.find()) www=1; 88 | 89 | } 90 | match=ex.matcher(InString); 91 | if (match.find()){ 92 | Get="11111111"; 93 | To=PP.get(Get); 94 | if (!"1".equals(To)){ 95 | braNum=braNum+1; 96 | PP.put(Get, "1"); 97 | } 98 | } 99 | 100 | 101 | 102 | } 103 | sin.close(); 104 | }catch (IOException e){ 105 | e.printStackTrace(); 106 | } 107 | branch=new int[braNum+1][12]; 108 | path=new int[braNum+1][12]; 109 | for(int i=1;i<=braNum;i++){ 110 | branch[i][0]=i; 111 | path[i][0]=0; 112 | for(int j=1;j<=11;j++){ 113 | branch[i][j]=0; 114 | path[i][j]=0; 115 | } 116 | } 117 | int bNum=0; 118 | try{ 119 | fin=new FileReader(new File("isa.out")); 120 | //fout=new FileWriter(new File("isare.out")); 121 | sin=new BufferedReader(fin); 122 | //sout=new BufferedWriter(fout); 123 | } catch (FileNotFoundException e){ 124 | e.printStackTrace(); 125 | } 126 | try{ 127 | while((InString=sin.readLine())!=null){ 128 | System.out.println(InString); 129 | match=bra.matcher(InString); 130 | String Get,To; 131 | if(www==1){ 132 | match1=num1.matcher(InString); 133 | if(match1.find()){ 134 | Get=match1.group(1); 135 | To=PP2.get(Get); 136 | if (!"1".equals(To)){ 137 | bNum=bNum+1; 138 | PP2.put(Get, "1"); 139 | Bno1.put(Get, bNum); 140 | Bno2.put(bNum, Get); 141 | int a=0; 142 | for(int i=0;i<8;i++){ 143 | char bit=Get.charAt(i); 144 | a = (a << 1) | (bit - '0'); 145 | } 146 | branch[bNum][1]=a; 147 | 148 | } 149 | } 150 | } 151 | www=0; 152 | if(match.find()){ 153 | match1=num1.matcher(InString); 154 | match2=num2.matcher(InString); 155 | match3=pre.matcher(InString); 156 | if (match3.find()){ 157 | www=1; 158 | } 159 | if (match1.find()){ 160 | Get=match1.group(1); 161 | To=PP2.get(Get); 162 | if (!"1".equals(To)){ 163 | bNum=bNum+1; 164 | PP2.put(Get, "1"); 165 | Bno1.put(Get, bNum); 166 | Bno2.put(bNum, Get); 167 | int a=0; 168 | for(int i=0;i<8;i++){ 169 | char bit=Get.charAt(i); 170 | a = (a << 1) | (bit - '0'); 171 | } 172 | branch[bNum][1]=a; 173 | 174 | } 175 | 176 | 177 | } 178 | if (match2.find()){ 179 | Get=match2.group(1); 180 | To=PP2.get(Get); 181 | if (!"1".equals(To)){ 182 | bNum=bNum+1; 183 | PP2.put(Get, "1"); 184 | Bno1.put(Get, bNum); 185 | Bno2.put(bNum, Get); 186 | int a=0; 187 | for(int i=0;i<8;i++){ 188 | char bit=Get.charAt(i); 189 | a = (a << 1) | (bit - '0'); 190 | } 191 | branch[bNum][1]=a; 192 | 193 | } 194 | 195 | 196 | } 197 | 198 | } 199 | 200 | match=ex.matcher(InString); 201 | if (match.find()){ 202 | match1=num1.matcher(InString); 203 | if (match1.find()){ 204 | bNum=bNum+1; 205 | String L=match1.group(1); 206 | To=PP2.get(L); 207 | if (!"1".equals(To)){ 208 | Bno1.put(L,bNum); 209 | Bno2.put(bNum,L); 210 | int a=0; 211 | for(int i=0;i<8;i++){ 212 | char bit=L.charAt(i); 213 | a = (a << 1) | (bit - '0'); 214 | } 215 | branch[bNum][1]=a; 216 | } 217 | 218 | } 219 | } 220 | 221 | 222 | 223 | } 224 | sin.close(); 225 | }catch (IOException e){ 226 | e.printStackTrace(); 227 | } 228 | 229 | 230 | } 231 | 232 | public void Count(){ 233 | String InString; 234 | 235 | 236 | Matcher match1,match2,match3,match4; 237 | 238 | try{ 239 | fin=new FileReader(new File("isa.out")); 240 | fout=new FileWriter(new File("isare.out")); 241 | sin=new BufferedReader(fin); 242 | sout=new BufferedWriter(fout); 243 | } catch (FileNotFoundException e){ 244 | e.printStackTrace(); 245 | }catch (IOException e){ 246 | e.printStackTrace(); 247 | } 248 | try{ 249 | while((InString=sin.readLine())!=null){ 250 | match1=bra.matcher(InString); 251 | match2=pre.matcher(InString); 252 | match3=num1.matcher(InString); 253 | match4=num2.matcher(InString); 254 | int preNum=0,jumNum=0; 255 | if (match1.find()){ 256 | System.out.println(InString); 257 | if (match3.find()){ 258 | String L=match3.group(1); 259 | preNum=Bno1.get(L); 260 | } 261 | if (match4.find()){ 262 | String LLL=match4.group(1); 263 | jumNum=Bno1.get(LLL); 264 | } 265 | if (match2.find()){ 266 | match4=num2.matcher(InString); 267 | 268 | if (match4.find()){ 269 | 270 | int leNum=braNum,riNum=braNum; 271 | int jj=65534; 272 | for (int i=1;i<=braNum;i++){ 273 | int de=branch[i][1]-jumNum; 274 | if (de>0&&de0&&de0&&de Pstack; 21 | private Pattern bra,pre,num1,num2,ex; 22 | private int braNum; 23 | private HashMap Bno1; 24 | private HashMap Bno2; 25 | private HashMap PP,PP2; 26 | public reCon(){ 27 | bra=Pattern.compile("(bra)"); 28 | pre=Pattern.compile("@%p"); 29 | num1=Pattern.compile("^([01][01][01][01][01][01][01][01])"); 30 | num2=Pattern.compile(";([01][01][01][01][01][01][01][01])"); 31 | ex=Pattern.compile("^(11111111)"); 32 | String InString; 33 | Matcher match,match1,match2,match3; 34 | braNum=0; 35 | Pstack=new Stack(); 36 | Bno1=new HashMap(); 37 | Bno2=new HashMap(); 38 | PP=new HashMap(); 39 | PP2=new HashMap(); 40 | int www=0; 41 | try{ 42 | fin=new FileReader(new File("isa.out")); 43 | //fout=new FileWriter(new File("isare.out")); 44 | sin=new BufferedReader(fin); 45 | //sout=new BufferedWriter(fout); 46 | } catch (FileNotFoundException e){ 47 | e.printStackTrace(); 48 | } 49 | try{ 50 | while((InString=sin.readLine())!=null){ 51 | 52 | System.out.println(InString); 53 | match=bra.matcher(InString); 54 | match3=pre.matcher(InString); 55 | String Get,To; 56 | if(www==1){ 57 | match1=num1.matcher(InString); 58 | if (match1.find()){ 59 | Get=match1.group(1); 60 | To=PP.get(Get); 61 | if (!"1".equals(To)){ 62 | braNum=braNum+1; 63 | PP.put(Get, "1"); 64 | } 65 | } 66 | } 67 | www=0; 68 | if(match.find()){ 69 | match1=num1.matcher(InString); 70 | match2=num2.matcher(InString); 71 | if (match1.find()){ 72 | Get=match1.group(1); 73 | To=PP.get(Get); 74 | if (!"1".equals(To)){ 75 | braNum=braNum+1; 76 | PP.put(Get, "1"); 77 | } 78 | } 79 | if (match2.find()){ 80 | Get=match2.group(1); 81 | To=PP.get(Get); 82 | if (!"1".equals(To)){ 83 | braNum=braNum+1; 84 | PP.put(Get, "1"); 85 | } 86 | } 87 | if(match3.find()) www=1; 88 | 89 | } 90 | match=ex.matcher(InString); 91 | if (match.find()){ 92 | Get="11111111"; 93 | To=PP.get(Get); 94 | if (!"1".equals(To)){ 95 | braNum=braNum+1; 96 | PP.put(Get, "1"); 97 | } 98 | } 99 | 100 | 101 | 102 | } 103 | sin.close(); 104 | }catch (IOException e){ 105 | e.printStackTrace(); 106 | } 107 | branch=new int[braNum+1][12]; 108 | path=new int[braNum+1][12]; 109 | for(int i=1;i<=braNum;i++){ 110 | branch[i][0]=i; 111 | path[i][0]=0; 112 | for(int j=1;j<=11;j++){ 113 | branch[i][j]=0; 114 | path[i][j]=0; 115 | } 116 | } 117 | int bNum=0; 118 | try{ 119 | fin=new FileReader(new File("isa.out")); 120 | //fout=new FileWriter(new File("isare.out")); 121 | sin=new BufferedReader(fin); 122 | //sout=new BufferedWriter(fout); 123 | } catch (FileNotFoundException e){ 124 | e.printStackTrace(); 125 | } 126 | try{ 127 | while((InString=sin.readLine())!=null){ 128 | System.out.println(InString); 129 | match=bra.matcher(InString); 130 | String Get,To; 131 | if(www==1){ 132 | match1=num1.matcher(InString); 133 | if(match1.find()){ 134 | Get=match1.group(1); 135 | To=PP2.get(Get); 136 | if (!"1".equals(To)){ 137 | bNum=bNum+1; 138 | PP2.put(Get, "1"); 139 | Bno1.put(Get, bNum); 140 | Bno2.put(bNum, Get); 141 | int a=0; 142 | for(int i=0;i<8;i++){ 143 | char bit=Get.charAt(i); 144 | a = (a << 1) | (bit - '0'); 145 | } 146 | branch[bNum][1]=a; 147 | 148 | } 149 | } 150 | } 151 | www=0; 152 | if(match.find()){ 153 | match1=num1.matcher(InString); 154 | match2=num2.matcher(InString); 155 | match3=pre.matcher(InString); 156 | if (match3.find()){ 157 | www=1; 158 | } 159 | if (match1.find()){ 160 | Get=match1.group(1); 161 | To=PP2.get(Get); 162 | if (!"1".equals(To)){ 163 | bNum=bNum+1; 164 | PP2.put(Get, "1"); 165 | Bno1.put(Get, bNum); 166 | Bno2.put(bNum, Get); 167 | int a=0; 168 | for(int i=0;i<8;i++){ 169 | char bit=Get.charAt(i); 170 | a = (a << 1) | (bit - '0'); 171 | } 172 | branch[bNum][1]=a; 173 | 174 | } 175 | 176 | 177 | } 178 | if (match2.find()){ 179 | Get=match2.group(1); 180 | To=PP2.get(Get); 181 | if (!"1".equals(To)){ 182 | bNum=bNum+1; 183 | PP2.put(Get, "1"); 184 | Bno1.put(Get, bNum); 185 | Bno2.put(bNum, Get); 186 | int a=0; 187 | for(int i=0;i<8;i++){ 188 | char bit=Get.charAt(i); 189 | a = (a << 1) | (bit - '0'); 190 | } 191 | branch[bNum][1]=a; 192 | 193 | } 194 | 195 | 196 | } 197 | 198 | } 199 | 200 | match=ex.matcher(InString); 201 | if (match.find()){ 202 | match1=num1.matcher(InString); 203 | if (match1.find()){ 204 | bNum=bNum+1; 205 | String L=match1.group(1); 206 | To=PP2.get(L); 207 | if (!"1".equals(To)){ 208 | Bno1.put(L,bNum); 209 | Bno2.put(bNum,L); 210 | int a=0; 211 | for(int i=0;i<8;i++){ 212 | char bit=L.charAt(i); 213 | a = (a << 1) | (bit - '0'); 214 | } 215 | branch[bNum][1]=a; 216 | } 217 | 218 | } 219 | } 220 | 221 | 222 | 223 | } 224 | sin.close(); 225 | }catch (IOException e){ 226 | e.printStackTrace(); 227 | } 228 | 229 | 230 | } 231 | 232 | public void Count(){ 233 | String InString; 234 | 235 | 236 | Matcher match1,match2,match3,match4; 237 | 238 | try{ 239 | fin=new FileReader(new File("isa.out")); 240 | fout=new FileWriter(new File("isare.out")); 241 | sin=new BufferedReader(fin); 242 | sout=new BufferedWriter(fout); 243 | } catch (FileNotFoundException e){ 244 | e.printStackTrace(); 245 | }catch (IOException e){ 246 | e.printStackTrace(); 247 | } 248 | try{ 249 | while((InString=sin.readLine())!=null){ 250 | match1=bra.matcher(InString); 251 | match2=pre.matcher(InString); 252 | match3=num1.matcher(InString); 253 | match4=num2.matcher(InString); 254 | int preNum=0,jumNum=0; 255 | if (match1.find()){ 256 | System.out.println(InString); 257 | if (match3.find()){ 258 | String L=match3.group(1); 259 | preNum=Bno1.get(L); 260 | } 261 | if (match4.find()){ 262 | String LLL=match4.group(1); 263 | jumNum=Bno1.get(LLL); 264 | } 265 | if (match2.find()){ 266 | match4=num2.matcher(InString); 267 | 268 | if (match4.find()){ 269 | 270 | int leNum=braNum,riNum=braNum; 271 | int jj=65534; 272 | for (int i=1;i<=braNum;i++){ 273 | int de=branch[i][1]-jumNum; 274 | if (de>0&&de0&&de0&&de Op2,Op3,Op3i,Op4,Setp,Setpi; 8 | 9 | public isaconvert2(){ 10 | iff=Pattern.compile("(add|sub|mul|div|min|max|rem|and|or|xor|shl|hi|lo|shr).[ful]*[.]*(s|u|b|f)([0123456789]+)"); 11 | syn=Pattern.compile("bar.sync"); 12 | hilo=Pattern.compile("mul.(hi|lo|[bsfu]\\d+)"); 13 | op3=Pattern.compile("(add|sub|mul|div|min|max|rem|and|or|xor|shl|shr).[ful]*[.]?([subf]\\d+|hi|lo)"); 14 | op4=Pattern.compile("(mad|slep)."); 15 | op2=Pattern.compile("(abs|not|neg|cnot)."); 16 | pred=Pattern.compile("(@(!)?%p(\\d+))"); 17 | bra=Pattern.compile("(bra)"); 18 | //ldst=Pattern.compile("((ld|st).(global|shared|local|const))"); 19 | reg3=Pattern.compile("(\\%r(\\d+), \\%r(\\d+), \\%r(\\d+))"); 20 | reg3i=Pattern.compile("(\\%r(\\d+), \\%r(\\d+), (\\d+))"); 21 | regp3=Pattern.compile("(\\%[rp](\\d+), \\%r(\\d+), \\%r(\\d+))"); 22 | regp3i=Pattern.compile("(\\%[rp](\\d+), \\%r(\\d+), (\\d+))"); 23 | setp=Pattern.compile("set[p]?.(eq|ne|lt|le|gt|ge)"); 24 | bp=Pattern.compile(";([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01]) ([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01])"); 25 | b=Pattern.compile(";([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01])"); 26 | codNum=Pattern.compile("^([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01])"); 27 | reg2=Pattern.compile("(\\%r(\\d+), \\%r(\\d+))"); 28 | reg2i=Pattern.compile("(\\%r(\\d+), (\\d+))"); 29 | mvc=Pattern.compile("(mov|cvt)."); 30 | exit=Pattern.compile("exit"); 31 | reg4=Pattern.compile("(\\%r(\\d+), \\%r(\\d+), \\%r(\\d+), \\%r(\\d+));"); 32 | movs=Pattern.compile("\\%r(\\d+), \\_\\_cuda[a-zA-Z0123456789\\_]+; ([01]+)"); 33 | cvtin=Pattern.compile("\\%r(\\d+), \\%[a-zA-Z.]+;([01]+)"); 34 | ld=Pattern.compile("ld.(global|local|shared|param)"); 35 | st=Pattern.compile("st.(global|local|shared|param)"); 36 | ldr=Pattern.compile("\\%r(\\d+), \\[\\%r(\\d+)\\+(\\d+)\\];"); 37 | ldp=Pattern.compile("\\%r(\\d+), \\[[a-zA-Z0123456789\\_]+(\\+\\d+)?\\]; ([01]+)"); 38 | str=Pattern.compile("\\[\\%r(\\d+)\\+(\\d+)\\], \\%r(\\d+);"); 39 | fs32=Pattern.compile(".f32.[su]32"); 40 | sf32=Pattern.compile(".[su]32.f32"); 41 | //stp=Pattern.compile(""); 42 | 43 | Op3=new HashMap(); 44 | Op3.put("add", "0000001"); 45 | Op3.put("sub", "0000010"); 46 | Op3.put("mul", "0000"); 47 | Op3.put("div", "0000110"); 48 | Op3.put("rem", "0000111"); 49 | //Op3.put("abs", "00001000"); 50 | //Op3.put("neg", "00001001"); 51 | Op3.put("min", "0001010"); 52 | Op3.put("max", "0001011"); 53 | Op3.put("and", "0100101"); 54 | Op3.put("or", "0100110"); 55 | Op3.put("xor", "0100111"); 56 | 57 | Op3.put("shl", "0101010"); 58 | Op3.put("shr", "0101011"); 59 | 60 | 61 | Op3i=new HashMap(); 62 | Op3i.put("and", "1100101"); 63 | Op3i.put("or", "1100110"); 64 | Op3i.put("xor", "1100111"); 65 | Op3i.put("shl", "1101010"); 66 | Op3i.put("shr", "1101011"); 67 | Op3i.put("add", "1000001"); 68 | Op3i.put("sub", "1000010"); 69 | Op3i.put("mul", "1000"); 70 | Op3i.put("div", "1000110"); 71 | Op3i.put("rem", "1000111"); 72 | Op3i.put("min", "1001010"); 73 | Op3i.put("max", "1001011"); 74 | 75 | 76 | 77 | 78 | 79 | Op2=new HashMap(); 80 | Op2.put("abs", "0000000010001000"); 81 | Op2.put("neg", "0000000010001001"); 82 | Op2.put("not", "0000000010101000"); 83 | Op2.put("cnot", "0000000010101001"); 84 | 85 | 86 | 87 | 88 | 89 | Op4=new HashMap(); 90 | Op4.put("mad", "0000000010000101"); 91 | Op4.put("selp", "0000000010100010"); 92 | 93 | Setp=new HashMap(); 94 | Setp.put("eq","0000000010010000"); 95 | Setp.put("ne","0000000010010001"); 96 | Setp.put("lt","0000000010010010"); 97 | Setp.put("le","0000000010010011"); 98 | Setp.put("gt","0000000010010100"); 99 | Setp.put("ge","0000000010010101"); 100 | 101 | 102 | Setpi=new HashMap(); 103 | Setpi.put("eq","0000000101010000"); 104 | Setpi.put("ne","0000000101010001"); 105 | Setpi.put("lt","0000000101010010"); 106 | Setpi.put("le","0000000101010011"); 107 | Setpi.put("gt","0000000101010100"); 108 | Setpi.put("ge","0000000101010100"); 109 | 110 | 111 | } 112 | public String Convert(String Instring){ 113 | StringBuilder OutString; 114 | Matcher match; 115 | 116 | OutString=new StringBuilder(); 117 | System.out.println(Instring); 118 | /*match=codNum.matcher(Instring); 119 | if(match.find()){ 120 | String G=match.group(1); 121 | OutString.append(G); 122 | OutString.append(" "); 123 | }*/ 124 | 125 | match=pred.matcher(Instring); 126 | if(match.find()){ 127 | System.out.println("pred Yes!"); 128 | String G1=match.group(2); 129 | String G2=match.group(3); 130 | if ("!".equals(G1)) 131 | OutString.append("00000000001"); 132 | else 133 | OutString.append("00000000000"); 134 | int pN=Integer.parseInt(G2); 135 | String G3=Integer.toBinaryString(pN); 136 | int LL=G3.length(); 137 | for (int i=0;i<5-LL;i++) 138 | OutString.append("0"); 139 | OutString.append(G3); 140 | } 141 | else 142 | OutString.append("0000000000000000"); 143 | 144 | 145 | match=op3.matcher(Instring); 146 | 147 | if(match.find()){ 148 | OutString.append("00000"); 149 | String G1=match.group(1); 150 | //String G2=match.group(2); 151 | String G2; 152 | Matcher mo=iff.matcher(Instring); 153 | if(mo.find()) 154 | G2=mo.group(2); 155 | else G2=(":P"); 156 | Matcher match1=reg3.matcher(Instring); 157 | Matcher match2=reg3i.matcher(Instring); 158 | Matcher match3=regp3.matcher(Instring); 159 | if(match1.find()||match3.find()){ 160 | if(!"f".equals(G2)){ 161 | OutString.append("0001"); 162 | } 163 | else OutString.append("0011"); 164 | } 165 | if(match2.find()){ 166 | if(!"f".equals(G2)){ 167 | OutString.append("0010"); 168 | } 169 | else OutString.append("0100"); 170 | } 171 | 172 | 173 | match1=reg3.matcher(Instring); 174 | match2=reg3i.matcher(Instring); 175 | match3=regp3.matcher(Instring); 176 | 177 | if(match1.find()){ 178 | OutString.append(Op3.get(G1)); 179 | if("mul".equals(G1)){ 180 | Matcher mm=hilo.matcher(Instring); 181 | if(mm.find()){ 182 | String tg=mm.group(1); 183 | if("lo".equals(tg)) 184 | OutString.append("011"); 185 | else if("hi".equals(tg)) 186 | OutString.append("100"); 187 | else 188 | OutString.append("011"); 189 | 190 | } 191 | } 192 | String r1=match1.group(2); 193 | String r2=match1.group(3); 194 | String r3=match1.group(4); 195 | int L; 196 | int rr2=Integer.parseInt(r2); 197 | String R2=Integer.toBinaryString(rr2); 198 | L=R2.length(); 199 | for (int i=0;i<8-L;i++) 200 | OutString.append("0"); 201 | OutString.append(R2); 202 | int rr3=Integer.parseInt(r3); 203 | String R3=Integer.toBinaryString(rr3); 204 | L=R3.length(); 205 | for (int i=0;i<8-L;i++) 206 | OutString.append("0"); 207 | OutString.append(R3); 208 | int rr1=Integer.parseInt(r1); 209 | String R1=Integer.toBinaryString(rr1); 210 | L=R1.length(); 211 | for (int i=0;i<8-L;i++) 212 | OutString.append("0"); 213 | OutString.append(R1); 214 | OutString.append("00000000"); 215 | } 216 | else if(match2.find()){ 217 | OutString.append(Op3.get(G1)); 218 | 219 | if("mul".equals(G1)){ 220 | Matcher mm=hilo.matcher(Instring); 221 | if(mm.find()){ 222 | String tg=mm.group(1); 223 | if("lo".equals(tg)) 224 | OutString.append("011"); 225 | else if("hi".equals(tg)) 226 | OutString.append("100"); 227 | } 228 | } 229 | String r1=match2.group(2); 230 | String r2=match2.group(3); 231 | String r3=match2.group(4); 232 | int L; 233 | int rr2=Integer.parseInt(r2); 234 | String R2=Integer.toBinaryString(rr2); 235 | L=R2.length(); 236 | for (int i=0;i<8-L;i++) 237 | OutString.append("0"); 238 | OutString.append(R2); 239 | int rr1=Integer.parseInt(r1); 240 | String R1=Integer.toBinaryString(rr1); 241 | L=R1.length(); 242 | for (int i=0;i<8-L;i++) 243 | OutString.append("0"); 244 | OutString.append(R1); 245 | int rr3=Integer.parseInt(r3); 246 | String R3=Integer.toBinaryString(rr3); 247 | L=R3.length(); 248 | for (int i=0;i<16-L;i++) 249 | OutString.append("0"); 250 | OutString.append(R3); 251 | } 252 | else if(match3.find()){ 253 | OutString.append(Op3.get(G1)); 254 | 255 | if("mul".equals(G1)){ 256 | Matcher mm=hilo.matcher(Instring); 257 | if(mm.find()){ 258 | String tg=mm.group(1); 259 | if("lo".equals(tg)) 260 | OutString.append("011"); 261 | else if("hi".equals(tg)) 262 | OutString.append("100"); 263 | } 264 | } 265 | String r1=match3.group(2); 266 | String r2=match3.group(3); 267 | String r3=match3.group(4); 268 | int L; 269 | int rr2=Integer.parseInt(r2); 270 | String R2=Integer.toBinaryString(rr2); 271 | L=R2.length(); 272 | for (int i=0;i<8-L;i++) 273 | OutString.append("0"); 274 | OutString.append(R2); 275 | int rr3=Integer.parseInt(r3); 276 | String R3=Integer.toBinaryString(rr3); 277 | L=R3.length(); 278 | for (int i=0;i<8-L;i++) 279 | OutString.append("0"); 280 | OutString.append(R3); 281 | int rr1=Integer.parseInt(r1); 282 | String R1=Integer.toBinaryString(rr1); 283 | L=R1.length(); 284 | OutString.append("001"); 285 | for (int i=0;i<5-L;i++) 286 | OutString.append("0"); 287 | OutString.append(R1); 288 | OutString.append("00000000"); 289 | } 290 | 291 | return OutString.toString(); 292 | } 293 | 294 | match=op2.matcher(Instring); 295 | if(match.find()){ 296 | String G1=match.group(1); 297 | 298 | Matcher match1=reg2.matcher(Instring); 299 | //Matcher match2=reg2i.matcher(Instring); 300 | if(match1.find()){ 301 | OutString.append(Op2.get(G1)); 302 | String G2=match1.group(2); 303 | String G3=match1.group(3); 304 | int r2=Integer.parseInt(G2); 305 | int r3=Integer.parseInt(G3); 306 | String R2=Integer.toBinaryString(r2); 307 | String R3=Integer.toBinaryString(r3); 308 | int L; 309 | L=R3.length(); 310 | for(int i=0;i<8-L;i++) 311 | OutString.append("0"); 312 | OutString.append(R3); 313 | OutString.append("00000000"); 314 | L=R2.length(); 315 | for (int i=0;i<8-L;i++) 316 | OutString.append("0"); 317 | OutString.append(R2); 318 | OutString.append("00000000"); 319 | } 320 | return OutString.toString(); 321 | 322 | } 323 | 324 | 325 | match=mvc.matcher(Instring); 326 | if(match.find()){ 327 | String G1=match.group(1); 328 | Matcher match1=reg2.matcher(Instring); 329 | Matcher match2=reg2i.matcher(Instring); 330 | Matcher match3=movs.matcher(Instring); 331 | Matcher match4=cvtin.matcher(Instring); 332 | Matcher match5=fs32.matcher(Instring); 333 | Matcher match6=sf32.matcher(Instring); 334 | if("mov".equals(G1)&&match1.find()){ 335 | OutString.append("0000000100100000"); 336 | String G2=match1.group(2); 337 | String G3=match1.group(3); 338 | int r2=Integer.parseInt(G2); 339 | int r3=Integer.parseInt(G3); 340 | String R2=Integer.toBinaryString(r2); 341 | String R3=Integer.toBinaryString(r3); 342 | int L; 343 | L=R3.length(); 344 | for(int i=0;i<8-L;i++) 345 | OutString.append("0"); 346 | OutString.append(R3); 347 | 348 | L=R2.length(); 349 | for (int i=0;i<8-L;i++) 350 | OutString.append("0"); 351 | OutString.append(R2); 352 | OutString.append("00000000"); 353 | OutString.append("00000000"); 354 | } 355 | else if("mov".equals(G1)&&match2.find()){ 356 | OutString.append("000000010110000000000000"); 357 | String G2=match2.group(2); 358 | String G3=match2.group(3); 359 | int r2=Integer.parseInt(G2); 360 | int r3=Integer.parseInt(G3); 361 | String R2=Integer.toBinaryString(r2); 362 | String R3=Integer.toBinaryString(r3); 363 | int L=R2.length(); 364 | for (int i=0;i<8-L;i++) 365 | OutString.append("0"); 366 | OutString.append(R2); 367 | L=R3.length(); 368 | //OutString.append("1"); 369 | for(int i=0;i<16-L;i++) 370 | OutString.append("0"); 371 | OutString.append(R3); 372 | 373 | } 374 | else if("mov".equals(G1)&&match3.find()){ 375 | OutString.append("000000010110000000000000"); 376 | String G2=match3.group(1); 377 | String G3=match3.group(2); 378 | int r2=Integer.parseInt(G2); 379 | String R2=Integer.toBinaryString(r2); 380 | int L=R2.length(); 381 | for (int i=0;i<8-L;i++) 382 | OutString.append("0"); 383 | OutString.append(R2); 384 | OutString.append(G3); 385 | } 386 | else if("cvt".equals(G1)&&match1.find()){ 387 | if(match5.find()){ 388 | OutString.append("0000000100100011"); 389 | } 390 | else if(match6.find()){ 391 | OutString.append("0000000100100100"); 392 | } 393 | else OutString.append("0000000010100000"); 394 | String G2=match1.group(2); 395 | String G3=match1.group(3); 396 | int r2=Integer.parseInt(G2); 397 | int r3=Integer.parseInt(G3); 398 | String R2=Integer.toBinaryString(r2); 399 | String R3=Integer.toBinaryString(r3); 400 | int L; 401 | L=R3.length(); 402 | for(int i=0;i<8-L;i++) 403 | OutString.append("0"); 404 | OutString.append(R3); 405 | 406 | L=R2.length(); 407 | for (int i=0;i<8-L;i++) 408 | OutString.append("0"); 409 | OutString.append(R2); 410 | OutString.append("00000000"); 411 | OutString.append("00000000"); 412 | } 413 | else if("cvt".equals(G1)&&match4.find()){ 414 | OutString.append("0000000100111000"); 415 | String G2=match4.group(1); 416 | String G3=match4.group(2); 417 | OutString.append("000"); 418 | OutString.append(G3); 419 | int r2=Integer.parseInt(G2); 420 | String R2=Integer.toBinaryString(r2); 421 | int L; 422 | L=R2.length(); 423 | for(int i=0;i<8-L;i++) 424 | OutString.append("0"); 425 | OutString.append(R2); 426 | OutString.append("00000000"); 427 | OutString.append("00000000"); 428 | } 429 | return OutString.toString(); 430 | } 431 | 432 | 433 | match=bra.matcher(Instring); 434 | if (match.find()){ 435 | OutString.append("0000010000110101"); 436 | Matcher mmm; 437 | 438 | 439 | mmm=bp.matcher(Instring); 440 | if(mmm.find()){ 441 | String G2=mmm.group(1); 442 | String G3=mmm.group(2); 443 | 444 | OutString.append(G3); 445 | 446 | OutString.append(G2); 447 | } 448 | else{ 449 | mmm=b.matcher(Instring); 450 | if(mmm.find()){ 451 | String G2=mmm.group(1); 452 | int a=0; 453 | for(int i=0;i<16;i++){ 454 | char bit=G2.charAt(i); 455 | a = (a << 1) | (bit - '0'); 456 | } 457 | a=a+1; 458 | String ax=Integer.toBinaryString(a); 459 | int ll=ax.length(); 460 | StringBuilder mp=new StringBuilder(); 461 | for(int i=0;i<16-ll;i++){ 462 | mp.append("0"); 463 | } 464 | mp.append(ax); 465 | OutString.append(mp.toString()); 466 | OutString.append(G2); 467 | 468 | } 469 | 470 | 471 | } 472 | return OutString.toString(); 473 | } 474 | match=syn.matcher(Instring); 475 | if(match.find()){ 476 | OutString.append("000001000111111000000000000000000000000000000000"); 477 | return OutString.toString(); 478 | } 479 | match=exit.matcher(Instring); 480 | if(match.find()){ 481 | OutString.append("000001000111111100000000000000000000000000000000"); 482 | return OutString.toString(); 483 | } 484 | 485 | match=op4.matcher(Instring); 486 | if(match.find()){ 487 | String G1=match.group(1); 488 | OutString.append(Op4.get(G1)); 489 | Matcher mm=reg4.matcher(Instring); 490 | String r1,r2,r3,r4; 491 | if(mm.find()){ 492 | r1=mm.group(2); 493 | r2=mm.group(3); 494 | r3=mm.group(4); 495 | r4=mm.group(5); 496 | } 497 | else{ 498 | r1="d";r2="d";r3="d";r4="d"; 499 | } 500 | 501 | int L; 502 | int rr2=Integer.parseInt(r2); 503 | String R2=Integer.toBinaryString(rr2); 504 | L=R2.length(); 505 | for (int i=0;i<8-L;i++) 506 | OutString.append("0"); 507 | OutString.append(R2); 508 | int rr3=Integer.parseInt(r3); 509 | String R3=Integer.toBinaryString(rr3); 510 | L=R3.length(); 511 | for (int i=0;i<8-L;i++) 512 | OutString.append("0"); 513 | OutString.append(R3); 514 | int rr1=Integer.parseInt(r1); 515 | String R1=Integer.toBinaryString(rr1); 516 | L=R1.length(); 517 | for (int i=0;i<8-L;i++) 518 | OutString.append("0"); 519 | OutString.append(R1); 520 | int rr4=Integer.parseInt(r4); 521 | String R4=Integer.toBinaryString(rr4); 522 | L=R4.length(); 523 | for (int i=0;i<8-L;i++) 524 | OutString.append("0"); 525 | OutString.append(R4); 526 | return OutString.toString(); 527 | } 528 | 529 | match=setp.matcher(Instring); 530 | if(match.find()){ 531 | String G=match.group(1); 532 | Matcher match1=regp3.matcher(Instring); 533 | Matcher match2=regp3i.matcher(Instring); 534 | 535 | if(match1.find()){ 536 | OutString.append(Setp.get(G)); 537 | String r1=match1.group(2); 538 | String r2=match1.group(3); 539 | String r3=match1.group(4); 540 | int L; 541 | int rr2=Integer.parseInt(r2); 542 | String R2=Integer.toBinaryString(rr2); 543 | L=R2.length(); 544 | for (int i=0;i<8-L;i++) 545 | OutString.append("0"); 546 | OutString.append(R2); 547 | int rr3=Integer.parseInt(r3); 548 | String R3=Integer.toBinaryString(rr3); 549 | L=R3.length(); 550 | for (int i=0;i<8-L;i++) 551 | OutString.append("0"); 552 | OutString.append(R3); 553 | int rr1=Integer.parseInt(r1); 554 | String R1=Integer.toBinaryString(rr1); 555 | L=R1.length(); 556 | for (int i=0;i<8-L;i++) 557 | OutString.append("0"); 558 | OutString.append(R1); 559 | OutString.append("00000000"); 560 | } 561 | else if(match2.find()){ 562 | OutString.append(Setpi.get(G)); 563 | String r1=match2.group(2); 564 | String r2=match2.group(3); 565 | String r3=match2.group(4); 566 | int L; 567 | int rr2=Integer.parseInt(r2); 568 | String R2=Integer.toBinaryString(rr2); 569 | L=R2.length(); 570 | for (int i=0;i<8-L;i++) 571 | OutString.append("0"); 572 | OutString.append(R2); 573 | int rr1=Integer.parseInt(r1); 574 | String R1=Integer.toBinaryString(rr1); 575 | L=R1.length(); 576 | for (int i=0;i<8-L;i++) 577 | OutString.append("0"); 578 | OutString.append(R1); 579 | int rr3=Integer.parseInt(r3); 580 | String R3=Integer.toBinaryString(rr3); 581 | L=R3.length(); 582 | for (int i=0;i<16-L;i++) 583 | OutString.append("0"); 584 | OutString.append(R3); 585 | } 586 | return OutString.toString(); 587 | } 588 | match=ld.matcher(Instring); 589 | if(match.find()){ 590 | String G=match.group(1); 591 | if("shared".equals(G)){ 592 | OutString.append("0000001110110001"); 593 | } 594 | else 595 | OutString.append("0000001110110001"); 596 | Matcher match1=ldr.matcher(Instring); 597 | Matcher match2=ldp.matcher(Instring); 598 | if(match1.find()){ 599 | String G1=match1.group(1); 600 | String G2=match1.group(2); 601 | String G3=match1.group(3); 602 | int r1=Integer.parseInt(G1); 603 | int r2=Integer.parseInt(G2); 604 | int r3=Integer.parseInt(G3); 605 | String rr1=Integer.toBinaryString(r1); 606 | String rr2=Integer.toBinaryString(r2); 607 | String rr3=Integer.toBinaryString(r3); 608 | int L; 609 | L=rr2.length(); 610 | for(int i=0;i<8-L;i++) 611 | OutString.append("0"); 612 | OutString.append(rr2); 613 | L=rr1.length(); 614 | for(int i=0;i<8-L;i++) 615 | OutString.append("0"); 616 | OutString.append(rr1); 617 | L=rr3.length(); 618 | for(int i=0;i<16-L;i++) 619 | OutString.append("0"); 620 | OutString.append(rr3); 621 | 622 | } 623 | else if(match2.find()){ 624 | String G1=match2.group(1); 625 | String G2=match2.group(3); 626 | OutString.append("00000000"); 627 | int r1=Integer.parseInt(G1); 628 | String rr1=Integer.toBinaryString(r1); 629 | int L; 630 | L=rr1.length(); 631 | for(int i=0;i<8-L;i++) 632 | OutString.append("0"); 633 | OutString.append(rr1); 634 | OutString.append(G2); 635 | } 636 | return OutString.toString(); 637 | } 638 | match=st.matcher(Instring); 639 | if(match.find()){ 640 | String G=match.group(1); 641 | if("shared".equals(G)){ 642 | OutString.append("0000001110110011"); 643 | } 644 | else 645 | OutString.append("0000001110110011"); 646 | 647 | Matcher match1=str.matcher(Instring); 648 | if(match1.find()){ 649 | String G1=match1.group(1); 650 | String G2=match1.group(2); 651 | String G3=match1.group(3); 652 | int r1=Integer.parseInt(G1); 653 | int r2=Integer.parseInt(G2); 654 | int r3=Integer.parseInt(G3); 655 | String rr1=Integer.toBinaryString(r1); 656 | String rr2=Integer.toBinaryString(r2); 657 | String rr3=Integer.toBinaryString(r3); 658 | int L; 659 | L=rr1.length(); 660 | for(int i=0;i<8-L;i++) 661 | OutString.append("0"); 662 | OutString.append(rr1); 663 | L=rr3.length(); 664 | for(int i=0;i<8-L;i++) 665 | OutString.append("0"); 666 | OutString.append(rr3); 667 | L=rr2.length(); 668 | for(int i=0;i<16-L;i++) 669 | OutString.append("0"); 670 | OutString.append(rr2); 671 | } 672 | return OutString.toString(); 673 | } 674 | 675 | OutString.append("XD"); 676 | return OutString.toString(); 677 | 678 | } 679 | 680 | } 681 | -------------------------------------------------------------------------------- /project/src/isaconvert2.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.regex.*; 3 | import java.util.HashMap; 4 | 5 | public class isaconvert2 { 6 | private Pattern op2,op3,op4,fs32,sf32,pred,bra,cvtin,movs,iff,reg3,reg3i,regp3,regp3i,reg4,setp,b,bp,codNum,reg2,reg2i,hilo,mvc,syn,exit,ld,st,ldr,ldp,str; 7 | private HashMap Op2,Op3,Op3i,Op4,Setp,Setpi; 8 | 9 | public isaconvert2(){ 10 | iff=Pattern.compile("(add|sub|mul|div|min|max|rem|and|or|xor|shl|hi|lo|shr).[ful]*[.]*(s|u|b|f)([0123456789]+)"); 11 | syn=Pattern.compile("bar.sync"); 12 | hilo=Pattern.compile("mul.(hi|lo|[bsfu]\\d+)"); 13 | op3=Pattern.compile("(add|sub|mul|div|min|max|rem|and|or|xor|shl|shr).[ful]*[.]?([subf]\\d+|hi|lo)"); 14 | op4=Pattern.compile("(mad|slep)."); 15 | op2=Pattern.compile("(abs|not|neg|cnot)."); 16 | pred=Pattern.compile("(@(!)?%p(\\d+))"); 17 | bra=Pattern.compile("(bra)"); 18 | //ldst=Pattern.compile("((ld|st).(global|shared|local|const))"); 19 | reg3=Pattern.compile("(\\%r(\\d+), \\%r(\\d+), \\%r(\\d+))"); 20 | reg3i=Pattern.compile("(\\%r(\\d+), \\%r(\\d+), (\\d+))"); 21 | regp3=Pattern.compile("(\\%[rp](\\d+), \\%r(\\d+), \\%r(\\d+))"); 22 | regp3i=Pattern.compile("(\\%[rp](\\d+), \\%r(\\d+), (\\d+))"); 23 | setp=Pattern.compile("set[p]?.(eq|ne|lt|le|gt|ge)"); 24 | bp=Pattern.compile(";([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01]) ([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01])"); 25 | b=Pattern.compile(";([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01])"); 26 | codNum=Pattern.compile("^([01][01][01][01][01][01][01][01][01][01][01][01][01][01][01][01])"); 27 | reg2=Pattern.compile("(\\%r(\\d+), \\%r(\\d+))"); 28 | reg2i=Pattern.compile("(\\%r(\\d+), (\\d+))"); 29 | mvc=Pattern.compile("(mov|cvt)."); 30 | exit=Pattern.compile("exit"); 31 | reg4=Pattern.compile("(\\%r(\\d+), \\%r(\\d+), \\%r(\\d+), \\%r(\\d+));"); 32 | movs=Pattern.compile("\\%r(\\d+), \\_\\_cuda[a-zA-Z0123456789\\_]+; ([01]+)"); 33 | cvtin=Pattern.compile("\\%r(\\d+), \\%[a-zA-Z.]+;([01]+)"); 34 | ld=Pattern.compile("ld.(global|local|shared|param)"); 35 | st=Pattern.compile("st.(global|local|shared|param)"); 36 | ldr=Pattern.compile("\\%r(\\d+), \\[\\%r(\\d+)\\+(\\d+)\\];"); 37 | ldp=Pattern.compile("\\%r(\\d+), \\[[a-zA-Z0123456789\\_]+(\\+\\d+)?\\]; ([01]+)"); 38 | str=Pattern.compile("\\[\\%r(\\d+)\\+(\\d+)\\], \\%r(\\d+);"); 39 | fs32=Pattern.compile(".f32.[su]32"); 40 | sf32=Pattern.compile(".[su]32.f32"); 41 | //stp=Pattern.compile(""); 42 | 43 | Op3=new HashMap(); 44 | Op3.put("add", "0000001"); 45 | Op3.put("sub", "0000010"); 46 | Op3.put("mul", "0000"); 47 | Op3.put("div", "0000110"); 48 | Op3.put("rem", "0000111"); 49 | //Op3.put("abs", "00001000"); 50 | //Op3.put("neg", "00001001"); 51 | Op3.put("min", "0001010"); 52 | Op3.put("max", "0001011"); 53 | Op3.put("and", "0100101"); 54 | Op3.put("or", "0100110"); 55 | Op3.put("xor", "0100111"); 56 | 57 | Op3.put("shl", "0101010"); 58 | Op3.put("shr", "0101011"); 59 | 60 | 61 | Op3i=new HashMap(); 62 | Op3i.put("and", "1100101"); 63 | Op3i.put("or", "1100110"); 64 | Op3i.put("xor", "1100111"); 65 | Op3i.put("shl", "1101010"); 66 | Op3i.put("shr", "1101011"); 67 | Op3i.put("add", "1000001"); 68 | Op3i.put("sub", "1000010"); 69 | Op3i.put("mul", "1000"); 70 | Op3i.put("div", "1000110"); 71 | Op3i.put("rem", "1000111"); 72 | Op3i.put("min", "1001010"); 73 | Op3i.put("max", "1001011"); 74 | 75 | 76 | 77 | 78 | 79 | Op2=new HashMap(); 80 | Op2.put("abs", "0000000010001000"); 81 | Op2.put("neg", "0000000010001001"); 82 | Op2.put("not", "0000000010101000"); 83 | Op2.put("cnot", "0000000010101001"); 84 | 85 | 86 | 87 | 88 | 89 | Op4=new HashMap(); 90 | Op4.put("mad", "0000000010000101"); 91 | Op4.put("selp", "0000000010100010"); 92 | 93 | Setp=new HashMap(); 94 | Setp.put("eq","0000000010010000"); 95 | Setp.put("ne","0000000010010001"); 96 | Setp.put("lt","0000000010010010"); 97 | Setp.put("le","0000000010010011"); 98 | Setp.put("gt","0000000010010100"); 99 | Setp.put("ge","0000000010010101"); 100 | 101 | 102 | Setpi=new HashMap(); 103 | Setpi.put("eq","0000000101010000"); 104 | Setpi.put("ne","0000000101010001"); 105 | Setpi.put("lt","0000000101010010"); 106 | Setpi.put("le","0000000101010011"); 107 | Setpi.put("gt","0000000101010100"); 108 | Setpi.put("ge","0000000101010100"); 109 | 110 | 111 | } 112 | public String Convert(String Instring){ 113 | StringBuilder OutString; 114 | Matcher match; 115 | 116 | OutString=new StringBuilder(); 117 | System.out.println(Instring); 118 | /*match=codNum.matcher(Instring); 119 | if(match.find()){ 120 | String G=match.group(1); 121 | OutString.append(G); 122 | OutString.append(" "); 123 | }*/ 124 | 125 | match=pred.matcher(Instring); 126 | if(match.find()){ 127 | System.out.println("pred Yes!"); 128 | String G1=match.group(2); 129 | String G2=match.group(3); 130 | if ("!".equals(G1)) 131 | OutString.append("00000000001"); 132 | else 133 | OutString.append("00000000000"); 134 | int pN=Integer.parseInt(G2); 135 | String G3=Integer.toBinaryString(pN); 136 | int LL=G3.length(); 137 | for (int i=0;i<5-LL;i++) 138 | OutString.append("0"); 139 | OutString.append(G3); 140 | } 141 | else 142 | OutString.append("0000000000000000"); 143 | 144 | 145 | match=op3.matcher(Instring); 146 | 147 | if(match.find()){ 148 | OutString.append("00000"); 149 | String G1=match.group(1); 150 | //String G2=match.group(2); 151 | String G2; 152 | Matcher mo=iff.matcher(Instring); 153 | if(mo.find()) 154 | G2=mo.group(2); 155 | else G2=(":P"); 156 | Matcher match1=reg3.matcher(Instring); 157 | Matcher match2=reg3i.matcher(Instring); 158 | Matcher match3=regp3.matcher(Instring); 159 | if(match1.find()||match3.find()){ 160 | if(!"f".equals(G2)){ 161 | OutString.append("0001"); 162 | } 163 | else OutString.append("0011"); 164 | } 165 | if(match2.find()){ 166 | if(!"f".equals(G2)){ 167 | OutString.append("0010"); 168 | } 169 | else OutString.append("0100"); 170 | } 171 | 172 | 173 | match1=reg3.matcher(Instring); 174 | match2=reg3i.matcher(Instring); 175 | match3=regp3.matcher(Instring); 176 | 177 | if(match1.find()){ 178 | OutString.append(Op3.get(G1)); 179 | if("mul".equals(G1)){ 180 | Matcher mm=hilo.matcher(Instring); 181 | if(mm.find()){ 182 | String tg=mm.group(1); 183 | if("lo".equals(tg)) 184 | OutString.append("011"); 185 | else if("hi".equals(tg)) 186 | OutString.append("100"); 187 | else 188 | OutString.append("011"); 189 | 190 | } 191 | } 192 | String r1=match1.group(2); 193 | String r2=match1.group(3); 194 | String r3=match1.group(4); 195 | int L; 196 | int rr2=Integer.parseInt(r2); 197 | String R2=Integer.toBinaryString(rr2); 198 | L=R2.length(); 199 | for (int i=0;i<8-L;i++) 200 | OutString.append("0"); 201 | OutString.append(R2); 202 | int rr3=Integer.parseInt(r3); 203 | String R3=Integer.toBinaryString(rr3); 204 | L=R3.length(); 205 | for (int i=0;i<8-L;i++) 206 | OutString.append("0"); 207 | OutString.append(R3); 208 | int rr1=Integer.parseInt(r1); 209 | String R1=Integer.toBinaryString(rr1); 210 | L=R1.length(); 211 | for (int i=0;i<8-L;i++) 212 | OutString.append("0"); 213 | OutString.append(R1); 214 | OutString.append("00000000"); 215 | } 216 | else if(match2.find()){ 217 | OutString.append(Op3.get(G1)); 218 | 219 | if("mul".equals(G1)){ 220 | Matcher mm=hilo.matcher(Instring); 221 | if(mm.find()){ 222 | String tg=mm.group(1); 223 | if("lo".equals(tg)) 224 | OutString.append("011"); 225 | else if("hi".equals(tg)) 226 | OutString.append("100"); 227 | } 228 | } 229 | String r1=match2.group(2); 230 | String r2=match2.group(3); 231 | String r3=match2.group(4); 232 | int L; 233 | int rr2=Integer.parseInt(r2); 234 | String R2=Integer.toBinaryString(rr2); 235 | L=R2.length(); 236 | for (int i=0;i<8-L;i++) 237 | OutString.append("0"); 238 | OutString.append(R2); 239 | int rr1=Integer.parseInt(r1); 240 | String R1=Integer.toBinaryString(rr1); 241 | L=R1.length(); 242 | for (int i=0;i<8-L;i++) 243 | OutString.append("0"); 244 | OutString.append(R1); 245 | int rr3=Integer.parseInt(r3); 246 | String R3=Integer.toBinaryString(rr3); 247 | L=R3.length(); 248 | for (int i=0;i<16-L;i++) 249 | OutString.append("0"); 250 | OutString.append(R3); 251 | } 252 | else if(match3.find()){ 253 | OutString.append(Op3.get(G1)); 254 | 255 | if("mul".equals(G1)){ 256 | Matcher mm=hilo.matcher(Instring); 257 | if(mm.find()){ 258 | String tg=mm.group(1); 259 | if("lo".equals(tg)) 260 | OutString.append("011"); 261 | else if("hi".equals(tg)) 262 | OutString.append("100"); 263 | } 264 | } 265 | String r1=match3.group(2); 266 | String r2=match3.group(3); 267 | String r3=match3.group(4); 268 | int L; 269 | int rr2=Integer.parseInt(r2); 270 | String R2=Integer.toBinaryString(rr2); 271 | L=R2.length(); 272 | for (int i=0;i<8-L;i++) 273 | OutString.append("0"); 274 | OutString.append(R2); 275 | int rr3=Integer.parseInt(r3); 276 | String R3=Integer.toBinaryString(rr3); 277 | L=R3.length(); 278 | for (int i=0;i<8-L;i++) 279 | OutString.append("0"); 280 | OutString.append(R3); 281 | int rr1=Integer.parseInt(r1); 282 | String R1=Integer.toBinaryString(rr1); 283 | L=R1.length(); 284 | OutString.append("001"); 285 | for (int i=0;i<5-L;i++) 286 | OutString.append("0"); 287 | OutString.append(R1); 288 | OutString.append("00000000"); 289 | } 290 | 291 | return OutString.toString(); 292 | } 293 | 294 | match=op2.matcher(Instring); 295 | if(match.find()){ 296 | String G1=match.group(1); 297 | 298 | Matcher match1=reg2.matcher(Instring); 299 | //Matcher match2=reg2i.matcher(Instring); 300 | if(match1.find()){ 301 | OutString.append(Op2.get(G1)); 302 | String G2=match1.group(2); 303 | String G3=match1.group(3); 304 | int r2=Integer.parseInt(G2); 305 | int r3=Integer.parseInt(G3); 306 | String R2=Integer.toBinaryString(r2); 307 | String R3=Integer.toBinaryString(r3); 308 | int L; 309 | L=R3.length(); 310 | for(int i=0;i<8-L;i++) 311 | OutString.append("0"); 312 | OutString.append(R3); 313 | OutString.append("00000000"); 314 | L=R2.length(); 315 | for (int i=0;i<8-L;i++) 316 | OutString.append("0"); 317 | OutString.append(R2); 318 | OutString.append("00000000"); 319 | } 320 | return OutString.toString(); 321 | 322 | } 323 | 324 | 325 | match=mvc.matcher(Instring); 326 | if(match.find()){ 327 | String G1=match.group(1); 328 | Matcher match1=reg2.matcher(Instring); 329 | Matcher match2=reg2i.matcher(Instring); 330 | Matcher match3=movs.matcher(Instring); 331 | Matcher match4=cvtin.matcher(Instring); 332 | Matcher match5=fs32.matcher(Instring); 333 | Matcher match6=sf32.matcher(Instring); 334 | if("mov".equals(G1)&&match1.find()){ 335 | OutString.append("0000000100100000"); 336 | String G2=match1.group(2); 337 | String G3=match1.group(3); 338 | int r2=Integer.parseInt(G2); 339 | int r3=Integer.parseInt(G3); 340 | String R2=Integer.toBinaryString(r2); 341 | String R3=Integer.toBinaryString(r3); 342 | int L; 343 | L=R3.length(); 344 | for(int i=0;i<8-L;i++) 345 | OutString.append("0"); 346 | OutString.append(R3); 347 | 348 | L=R2.length(); 349 | for (int i=0;i<8-L;i++) 350 | OutString.append("0"); 351 | OutString.append(R2); 352 | OutString.append("00000000"); 353 | OutString.append("00000000"); 354 | } 355 | else if("mov".equals(G1)&&match2.find()){ 356 | OutString.append("000000010110000000000000"); 357 | String G2=match2.group(2); 358 | String G3=match2.group(3); 359 | int r2=Integer.parseInt(G2); 360 | int r3=Integer.parseInt(G3); 361 | String R2=Integer.toBinaryString(r2); 362 | String R3=Integer.toBinaryString(r3); 363 | int L=R2.length(); 364 | for (int i=0;i<8-L;i++) 365 | OutString.append("0"); 366 | OutString.append(R2); 367 | L=R3.length(); 368 | //OutString.append("1"); 369 | for(int i=0;i<16-L;i++) 370 | OutString.append("0"); 371 | OutString.append(R3); 372 | 373 | } 374 | else if("mov".equals(G1)&&match3.find()){ 375 | OutString.append("000000010110000000000000"); 376 | String G2=match3.group(1); 377 | String G3=match3.group(2); 378 | int r2=Integer.parseInt(G2); 379 | String R2=Integer.toBinaryString(r2); 380 | int L=R2.length(); 381 | for (int i=0;i<8-L;i++) 382 | OutString.append("0"); 383 | OutString.append(R2); 384 | OutString.append(G3); 385 | } 386 | else if("cvt".equals(G1)&&match1.find()){ 387 | if(match5.find()){ 388 | OutString.append("0000000100100011"); 389 | } 390 | else if(match6.find()){ 391 | OutString.append("0000000100100100"); 392 | } 393 | else OutString.append("0000000010100000"); 394 | String G2=match1.group(2); 395 | String G3=match1.group(3); 396 | int r2=Integer.parseInt(G2); 397 | int r3=Integer.parseInt(G3); 398 | String R2=Integer.toBinaryString(r2); 399 | String R3=Integer.toBinaryString(r3); 400 | int L; 401 | L=R3.length(); 402 | for(int i=0;i<8-L;i++) 403 | OutString.append("0"); 404 | OutString.append(R3); 405 | 406 | L=R2.length(); 407 | for (int i=0;i<8-L;i++) 408 | OutString.append("0"); 409 | OutString.append(R2); 410 | OutString.append("00000000"); 411 | OutString.append("00000000"); 412 | } 413 | else if("cvt".equals(G1)&&match4.find()){ 414 | OutString.append("0000000100111000"); 415 | String G2=match4.group(1); 416 | String G3=match4.group(2); 417 | OutString.append("000"); 418 | OutString.append(G3); 419 | int r2=Integer.parseInt(G2); 420 | String R2=Integer.toBinaryString(r2); 421 | int L; 422 | L=R2.length(); 423 | for(int i=0;i<8-L;i++) 424 | OutString.append("0"); 425 | OutString.append(R2); 426 | OutString.append("00000000"); 427 | OutString.append("00000000"); 428 | } 429 | return OutString.toString(); 430 | } 431 | 432 | 433 | match=bra.matcher(Instring); 434 | if (match.find()){ 435 | OutString.append("0000010000110101"); 436 | Matcher mmm; 437 | 438 | 439 | mmm=bp.matcher(Instring); 440 | if(mmm.find()){ 441 | String G2=mmm.group(1); 442 | String G3=mmm.group(2); 443 | 444 | OutString.append(G3); 445 | 446 | OutString.append(G2); 447 | } 448 | else{ 449 | mmm=b.matcher(Instring); 450 | if(mmm.find()){ 451 | String G2=mmm.group(1); 452 | int a=0; 453 | for(int i=0;i<16;i++){ 454 | char bit=G2.charAt(i); 455 | a = (a << 1) | (bit - '0'); 456 | } 457 | a=a+1; 458 | String ax=Integer.toBinaryString(a); 459 | int ll=ax.length(); 460 | StringBuilder mp=new StringBuilder(); 461 | for(int i=0;i<16-ll;i++){ 462 | mp.append("0"); 463 | } 464 | mp.append(ax); 465 | OutString.append(mp.toString()); 466 | OutString.append(G2); 467 | 468 | } 469 | 470 | 471 | } 472 | return OutString.toString(); 473 | } 474 | match=syn.matcher(Instring); 475 | if(match.find()){ 476 | OutString.append("000001000111111000000000000000000000000000000000"); 477 | return OutString.toString(); 478 | } 479 | match=exit.matcher(Instring); 480 | if(match.find()){ 481 | OutString.append("000001000111111100000000000000000000000000000000"); 482 | return OutString.toString(); 483 | } 484 | 485 | match=op4.matcher(Instring); 486 | if(match.find()){ 487 | String G1=match.group(1); 488 | OutString.append(Op4.get(G1)); 489 | Matcher mm=reg4.matcher(Instring); 490 | String r1,r2,r3,r4; 491 | if(mm.find()){ 492 | r1=mm.group(2); 493 | r2=mm.group(3); 494 | r3=mm.group(4); 495 | r4=mm.group(5); 496 | } 497 | else{ 498 | r1="d";r2="d";r3="d";r4="d"; 499 | } 500 | 501 | int L; 502 | int rr2=Integer.parseInt(r2); 503 | String R2=Integer.toBinaryString(rr2); 504 | L=R2.length(); 505 | for (int i=0;i<8-L;i++) 506 | OutString.append("0"); 507 | OutString.append(R2); 508 | int rr3=Integer.parseInt(r3); 509 | String R3=Integer.toBinaryString(rr3); 510 | L=R3.length(); 511 | for (int i=0;i<8-L;i++) 512 | OutString.append("0"); 513 | OutString.append(R3); 514 | int rr1=Integer.parseInt(r1); 515 | String R1=Integer.toBinaryString(rr1); 516 | L=R1.length(); 517 | for (int i=0;i<8-L;i++) 518 | OutString.append("0"); 519 | OutString.append(R1); 520 | int rr4=Integer.parseInt(r4); 521 | String R4=Integer.toBinaryString(rr4); 522 | L=R4.length(); 523 | for (int i=0;i<8-L;i++) 524 | OutString.append("0"); 525 | OutString.append(R4); 526 | return OutString.toString(); 527 | } 528 | 529 | match=setp.matcher(Instring); 530 | if(match.find()){ 531 | String G=match.group(1); 532 | Matcher match1=regp3.matcher(Instring); 533 | Matcher match2=regp3i.matcher(Instring); 534 | 535 | if(match1.find()){ 536 | OutString.append(Setp.get(G)); 537 | String r1=match1.group(2); 538 | String r2=match1.group(3); 539 | String r3=match1.group(4); 540 | int L; 541 | int rr2=Integer.parseInt(r2); 542 | String R2=Integer.toBinaryString(rr2); 543 | L=R2.length(); 544 | for (int i=0;i<8-L;i++) 545 | OutString.append("0"); 546 | OutString.append(R2); 547 | int rr3=Integer.parseInt(r3); 548 | String R3=Integer.toBinaryString(rr3); 549 | L=R3.length(); 550 | for (int i=0;i<8-L;i++) 551 | OutString.append("0"); 552 | OutString.append(R3); 553 | int rr1=Integer.parseInt(r1); 554 | String R1=Integer.toBinaryString(rr1); 555 | L=R1.length(); 556 | for (int i=0;i<8-L;i++) 557 | OutString.append("0"); 558 | OutString.append(R1); 559 | OutString.append("00000000"); 560 | } 561 | else if(match2.find()){ 562 | OutString.append(Setpi.get(G)); 563 | String r1=match2.group(2); 564 | String r2=match2.group(3); 565 | String r3=match2.group(4); 566 | int L; 567 | int rr2=Integer.parseInt(r2); 568 | String R2=Integer.toBinaryString(rr2); 569 | L=R2.length(); 570 | for (int i=0;i<8-L;i++) 571 | OutString.append("0"); 572 | OutString.append(R2); 573 | int rr1=Integer.parseInt(r1); 574 | String R1=Integer.toBinaryString(rr1); 575 | L=R1.length(); 576 | for (int i=0;i<8-L;i++) 577 | OutString.append("0"); 578 | OutString.append(R1); 579 | int rr3=Integer.parseInt(r3); 580 | String R3=Integer.toBinaryString(rr3); 581 | L=R3.length(); 582 | for (int i=0;i<16-L;i++) 583 | OutString.append("0"); 584 | OutString.append(R3); 585 | } 586 | return OutString.toString(); 587 | } 588 | match=ld.matcher(Instring); 589 | if(match.find()){ 590 | String G=match.group(1); 591 | if("shared".equals(G)){ 592 | OutString.append("0000001110110001"); 593 | } 594 | else 595 | OutString.append("0000001110110001"); 596 | Matcher match1=ldr.matcher(Instring); 597 | Matcher match2=ldp.matcher(Instring); 598 | if(match1.find()){ 599 | String G1=match1.group(1); 600 | String G2=match1.group(2); 601 | String G3=match1.group(3); 602 | int r1=Integer.parseInt(G1); 603 | int r2=Integer.parseInt(G2); 604 | int r3=Integer.parseInt(G3); 605 | String rr1=Integer.toBinaryString(r1); 606 | String rr2=Integer.toBinaryString(r2); 607 | String rr3=Integer.toBinaryString(r3); 608 | int L; 609 | L=rr2.length(); 610 | for(int i=0;i<8-L;i++) 611 | OutString.append("0"); 612 | OutString.append(rr2); 613 | L=rr1.length(); 614 | for(int i=0;i<8-L;i++) 615 | OutString.append("0"); 616 | OutString.append(rr1); 617 | L=rr3.length(); 618 | for(int i=0;i<16-L;i++) 619 | OutString.append("0"); 620 | OutString.append(rr3); 621 | 622 | } 623 | else if(match2.find()){ 624 | String G1=match2.group(1); 625 | String G2=match2.group(3); 626 | OutString.append("00000000"); 627 | int r1=Integer.parseInt(G1); 628 | String rr1=Integer.toBinaryString(r1); 629 | int L; 630 | L=rr1.length(); 631 | for(int i=0;i<8-L;i++) 632 | OutString.append("0"); 633 | OutString.append(rr1); 634 | OutString.append(G2); 635 | } 636 | return OutString.toString(); 637 | } 638 | match=st.matcher(Instring); 639 | if(match.find()){ 640 | String G=match.group(1); 641 | if("shared".equals(G)){ 642 | OutString.append("0000001110110011"); 643 | } 644 | else 645 | OutString.append("0000001110110011"); 646 | 647 | Matcher match1=str.matcher(Instring); 648 | if(match1.find()){ 649 | String G1=match1.group(1); 650 | String G2=match1.group(2); 651 | String G3=match1.group(3); 652 | int r1=Integer.parseInt(G1); 653 | int r2=Integer.parseInt(G2); 654 | int r3=Integer.parseInt(G3); 655 | String rr1=Integer.toBinaryString(r1); 656 | String rr2=Integer.toBinaryString(r2); 657 | String rr3=Integer.toBinaryString(r3); 658 | int L; 659 | L=rr1.length(); 660 | for(int i=0;i<8-L;i++) 661 | OutString.append("0"); 662 | OutString.append(rr1); 663 | L=rr3.length(); 664 | for(int i=0;i<8-L;i++) 665 | OutString.append("0"); 666 | OutString.append(rr3); 667 | L=rr2.length(); 668 | for(int i=0;i<16-L;i++) 669 | OutString.append("0"); 670 | OutString.append(rr2); 671 | } 672 | return OutString.toString(); 673 | } 674 | 675 | OutString.append("XD"); 676 | return OutString.toString(); 677 | 678 | } 679 | 680 | } 681 | -------------------------------------------------------------------------------- /isaConvert.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.regex.*; 3 | import java.util.HashMap; 4 | 5 | public class isaConvert { 6 | private Pattern reg,pred,addi,addc,addf,subi,subc,subf,muli,mulf,madi,madf,divi,divf; 7 | private Pattern setp,mov,ld,st,bra,reg2,reg3,reg4,preg3; 8 | private HashMap typeUS6Hash,typeUS2Hash,addcHash,rndHash; 9 | private HashMap ftzHash,satHash,typeF2Hash,subcHash,hiloHash; 10 | private HashMap rnd2Hash,rnd3Hash,cmpopHash,boolopHash,typeBUSF11Hash; 11 | private int regNum; 12 | public isaConvert(){ 13 | regNum=0; 14 | reg=Pattern.compile("(.reg .[usf]\\d{1,2} \\%[a-zA-Z]+<(\\d+)>;)"); 15 | pred=Pattern.compile("(@(!)?%p(\\d+))"); 16 | addi=Pattern.compile("(add(.sat)?.([us]\\d{2}))"); 17 | addc=Pattern.compile("((add.cc|addc|addc.cc).([us])32)"); 18 | addf=Pattern.compile("(add(.r[mnpz])?(.ftz)?(.sat)?.f(32|64))"); 19 | subi=Pattern.compile("(sub(.sat)?.([us]\\d{2}))"); 20 | subc=Pattern.compile("((sub.cc|subc|subc.cc).([us])32)"); 21 | subf=Pattern.compile("(sub(.r[mnpz])?(.ftz)?(.sat)?.f(32|64))"); 22 | muli=Pattern.compile("(mul(.hi|.lo|.wide)?.([us]\\d{2}))"); 23 | mulf=Pattern.compile("(mul(.r[mnpz])?(.ftz)?(.sat)?.f(32|64))"); 24 | madi=Pattern.compile("(mad(.hi|.lo|.wide)?(.sat)?.([us]\\d{2}))"); 25 | madf=Pattern.compile("(mad(.r[nzmp])?(.ftz)?(.sat)?.f(32|64))"); 26 | divi=Pattern.compile("(div.([us]\\d{2}))"); 27 | divf=Pattern.compile("(div(.approx|.full|.r[nzmp])(.ftz)?.f(32|64))"); 28 | setp=Pattern.compile("(setp(.eq|.ne|.lt|.gt|.ge|.lo|.ls|.hi|.hs|.equ|.neu|.ltu|.leu|.gtu|.geu|.num|.nan)(.and|.or|.xor)?(.ftz)?(.[busf]\\d{2}))"); 29 | mov=Pattern.compile("(mov.([busf]\\d{2}||pred))"); 30 | ld=Pattern.compile("(ld.(global|shared|local|const))"); 31 | st=Pattern.compile("(st.(global|shared|local|const))"); 32 | bra=Pattern.compile("(bra)"); 33 | reg3=Pattern.compile("(\\%r(\\d+), \\%r(\\d+), \\%r(\\d+))"); 34 | reg4=Pattern.compile("(\\%r(\\d+), \\%r(\\d+), \\%r(\\d+), \\%r(\\d+))"); 35 | preg3=Pattern.compile("(\\%p(\\d+), \\%r(\\d+), \\%r(\\d+))"); 36 | 37 | //used in addi subi muli madi divi 38 | typeUS6Hash=new HashMap(); 39 | typeUS6Hash.put("u16","000"); 40 | typeUS6Hash.put("u32","001"); 41 | typeUS6Hash.put("u64","010"); 42 | typeUS6Hash.put("s16","100"); 43 | typeUS6Hash.put("s32","101"); 44 | typeUS6Hash.put("s64","110"); 45 | 46 | //used in addc subc 47 | typeUS2Hash=new HashMap(); 48 | typeUS2Hash.put("u","0"); 49 | typeUS2Hash.put("s", "1"); 50 | 51 | //used in addc subc 52 | addcHash=new HashMap(); 53 | addcHash.put("add.cc", "00"); 54 | addcHash.put("addc", "10"); 55 | addcHash.put("addc.cc", "11"); 56 | 57 | //used in addf subf 58 | rndHash=new HashMap(); 59 | rndHash.put(".rn", "100"); 60 | rndHash.put(".rz", "101"); 61 | rndHash.put(".rm", "110"); 62 | rndHash.put(".rp", "111"); 63 | rndHash.put(null, "010"); 64 | 65 | //used in addf subf mulf madf divf 66 | ftzHash=new HashMap(); 67 | ftzHash.put(null,"0"); 68 | ftzHash.put(".ftz","1"); 69 | 70 | //used in addf subf mulf madf divf 71 | satHash=new HashMap(); 72 | satHash.put(null, "0"); 73 | satHash.put(".sat", "1"); 74 | 75 | //used in addf subf 76 | typeF2Hash=new HashMap(); 77 | typeF2Hash.put("32", "0"); 78 | typeF2Hash.put("64", "1"); 79 | 80 | //used in subc 81 | subcHash=new HashMap(); 82 | subcHash.put("sub.cc", "00"); 83 | subcHash.put("subc", "10"); 84 | subcHash.put("subc.cc", "11"); 85 | 86 | //used in muli madi 87 | hiloHash=new HashMap(); 88 | hiloHash.put(null, "00"); 89 | hiloHash.put(".hi", "01"); 90 | hiloHash.put(".lo", "10"); 91 | hiloHash.put(".wide", "11"); 92 | 93 | //used in mulf madf 94 | rnd2Hash=new HashMap(); 95 | rnd2Hash.put(null, "100"); 96 | rnd2Hash.put(".rn", "000"); 97 | rnd2Hash.put(".rz", "001"); 98 | rnd2Hash.put(".rm", "010"); 99 | rnd2Hash.put(".rp", "011"); 100 | 101 | //used in divf 102 | rnd3Hash=new HashMap(); 103 | rnd3Hash.put(".rn", "00"); 104 | rnd3Hash.put(".rz", "01"); 105 | rnd3Hash.put(".rm", "10"); 106 | rnd3Hash.put(".rp", "11"); 107 | 108 | //used in setp 109 | cmpopHash=new HashMap(); 110 | cmpopHash.put(".eq", "01010"); 111 | cmpopHash.put(".ne", "01011"); 112 | cmpopHash.put(".lt", "01100"); 113 | cmpopHash.put(".gt", "01101"); 114 | cmpopHash.put(".ge", "01110"); 115 | cmpopHash.put(".lo", "01111"); 116 | cmpopHash.put(".ls", "10000"); 117 | cmpopHash.put(".hi", "10001"); 118 | cmpopHash.put(".hs", "10010"); 119 | cmpopHash.put(".equ", "10011"); 120 | cmpopHash.put(".neu", "10100"); 121 | cmpopHash.put(".ltu", "10101"); 122 | cmpopHash.put(".leu", "10110"); 123 | cmpopHash.put(".gtu", "10111"); 124 | cmpopHash.put(".geu", "11000"); 125 | cmpopHash.put(".num", "11001"); 126 | cmpopHash.put(".nan", "11010"); 127 | 128 | //used in setp 129 | boolopHash=new HashMap(); 130 | boolopHash.put(null, "00"); 131 | boolopHash.put(".and", "01"); 132 | boolopHash.put("or", "10"); 133 | boolopHash.put("xor", "11"); 134 | 135 | //used in setp 136 | typeBUSF11Hash=new HashMap(); 137 | typeBUSF11Hash.put(".b16","0000"); 138 | typeBUSF11Hash.put(".b32","0001"); 139 | typeBUSF11Hash.put(".b64","0010"); 140 | typeBUSF11Hash.put(".u16","0100"); 141 | typeBUSF11Hash.put(".u32","0101"); 142 | typeBUSF11Hash.put(".u64","0110"); 143 | typeBUSF11Hash.put(".s16","1000"); 144 | typeBUSF11Hash.put(".s32","1001"); 145 | typeBUSF11Hash.put(".s64","1010"); 146 | typeBUSF11Hash.put(".f32","1100"); 147 | typeBUSF11Hash.put(".f64","1101"); 148 | 149 | 150 | 151 | } 152 | public String Convert(String InString){ 153 | StringBuilder OutString; 154 | Matcher Match; 155 | 156 | //reg 157 | Match=reg.matcher(InString); 158 | if(Match.find()){ 159 | System.out.println("reg Yes!"); 160 | String G1=Match.group(2); 161 | regNum=regNum+Integer.parseInt(G1); 162 | } 163 | 164 | //pred 165 | Match=pred.matcher(InString); 166 | if(Match.find()){ 167 | System.out.println("pred Yes!"); 168 | String G1=Match.group(2); 169 | String G2=Match.group(3); 170 | if ("!".equals(G1)) 171 | OutString=new StringBuilder("00000000000"); 172 | else 173 | OutString=new StringBuilder("00000000001"); 174 | int pN=regNum+Integer.parseInt(G2); 175 | String G3=Integer.toBinaryString(pN); 176 | int LL=G3.length(); 177 | for (int i=0;i<5-LL;i++) 178 | OutString.append("0"); 179 | OutString.append(G3); 180 | } 181 | else 182 | OutString=new StringBuilder("0000000000000000"); 183 | 184 | //add 185 | Match=addi.matcher(InString); 186 | if (Match.find()){ 187 | System.out.println("add Yes!"); 188 | /*for (int i=1;i<=2;i++){ 189 | System.out.println(addM.group(i)); 190 | }*/ 191 | OutString.append("0000000000000"); 192 | String G1=Match.group(2); 193 | if ((".sat").equals(G1)) 194 | OutString.append("111"); 195 | else { 196 | String G2=Match.group(3); 197 | OutString.append(typeUS6Hash.get(G2)); 198 | } 199 | Match=reg3.matcher(InString); 200 | if (Match.find()){ 201 | System.out.println("Found!"); 202 | String R1=Match.group(2); 203 | String R2=Match.group(3); 204 | String R3=Match.group(4); 205 | int r1=Integer.parseInt(R1); 206 | int r2=Integer.parseInt(R2); 207 | int r3=Integer.parseInt(R3); 208 | String B1=Integer.toBinaryString(r1); 209 | String B2=Integer.toBinaryString(r2); 210 | String B3=Integer.toBinaryString(r3); 211 | int l1=B1.length(); 212 | int l2=B2.length(); 213 | int l3=B3.length(); 214 | for (int i=0;i<8-l1;i++) 215 | OutString.append("0"); 216 | OutString.append(B1); 217 | for (int i=0;i<8-l2;i++) 218 | OutString.append("0"); 219 | OutString.append(B2); 220 | for (int i=0;i<8-l3;i++) 221 | OutString.append("0"); 222 | OutString.append(B3); 223 | int L=OutString.length(); 224 | for (int i=0;i<8;i++) 225 | OutString.append("0"); 226 | } 227 | else System.out.println("Not Found"); 228 | return OutString.toString(); 229 | } 230 | 231 | //addc 232 | Match=addc.matcher(InString); 233 | if (Match.find()){ 234 | System.out.println("adc Yes!"); 235 | OutString.append("0000000000001"); 236 | String G1=Match.group(2); 237 | OutString.append(addcHash.get(G1)); 238 | String G2=Match.group(3); 239 | OutString.append(typeUS2Hash.get(G2)); 240 | Match=reg3.matcher(InString); 241 | if (Match.find()){ 242 | System.out.println("Found!"); 243 | String R1=Match.group(2); 244 | String R2=Match.group(3); 245 | String R3=Match.group(4); 246 | int r1=Integer.parseInt(R1); 247 | int r2=Integer.parseInt(R2); 248 | int r3=Integer.parseInt(R3); 249 | String B1=Integer.toBinaryString(r1); 250 | String B2=Integer.toBinaryString(r2); 251 | String B3=Integer.toBinaryString(r3); 252 | int l1=B1.length(); 253 | int l2=B2.length(); 254 | int l3=B3.length(); 255 | for (int i=0;i<8-l1;i++) 256 | OutString.append("0"); 257 | OutString.append(B1); 258 | for (int i=0;i<8-l2;i++) 259 | OutString.append("0"); 260 | OutString.append(B2); 261 | for (int i=0;i<8-l3;i++) 262 | OutString.append("0"); 263 | OutString.append(B3); 264 | int L=OutString.length(); 265 | for (int i=0;i<8;i++) 266 | OutString.append("0"); 267 | } 268 | else System.out.println("Not Found"); 269 | return OutString.toString(); 270 | } 271 | 272 | //addf 273 | Match=addf.matcher(InString); 274 | if(Match.find()){ 275 | System.out.println("adf Yes!"); 276 | OutString.append("0000000000"); 277 | String G1=Match.group(2); 278 | String G2=Match.group(3); 279 | String G3=Match.group(4); 280 | String G4=Match.group(5); 281 | OutString.append(rndHash.get(G1)); 282 | OutString.append(ftzHash.get(G2)); 283 | OutString.append(satHash.get(G3)); 284 | OutString.append(typeF2Hash.get(G4)); 285 | Match=reg3.matcher(InString); 286 | if (Match.find()){ 287 | System.out.println("Found!"); 288 | String R1=Match.group(2); 289 | String R2=Match.group(3); 290 | String R3=Match.group(4); 291 | int r1=Integer.parseInt(R1); 292 | int r2=Integer.parseInt(R2); 293 | int r3=Integer.parseInt(R3); 294 | String B1=Integer.toBinaryString(r1); 295 | String B2=Integer.toBinaryString(r2); 296 | String B3=Integer.toBinaryString(r3); 297 | int l1=B1.length(); 298 | int l2=B2.length(); 299 | int l3=B3.length(); 300 | for (int i=0;i<8-l1;i++) 301 | OutString.append("0"); 302 | OutString.append(B1); 303 | for (int i=0;i<8-l2;i++) 304 | OutString.append("0"); 305 | OutString.append(B2); 306 | for (int i=0;i<8-l3;i++) 307 | OutString.append("0"); 308 | OutString.append(B3); 309 | int L=OutString.length(); 310 | for (int i=0;i<8;i++) 311 | OutString.append("0"); 312 | } 313 | else System.out.println("Not Found"); 314 | return OutString.toString(); 315 | } 316 | 317 | //subi 318 | Match=subi.matcher(InString); 319 | if (Match.find()){ 320 | System.out.println("sub Yes!"); 321 | /*for (int i=1;i<=2;i++){ 322 | System.out.println(addM.group(i)); 323 | }*/ 324 | OutString.append("0000000001000"); 325 | String G1=Match.group(2); 326 | if ((".sat").equals(G1)) 327 | OutString.append("111"); 328 | else { 329 | String G2=Match.group(3); 330 | OutString.append(typeUS6Hash.get(G2)); 331 | } 332 | Match=reg3.matcher(InString); 333 | if (Match.find()){ 334 | System.out.println("Found!"); 335 | String R1=Match.group(2); 336 | String R2=Match.group(3); 337 | String R3=Match.group(4); 338 | int r1=Integer.parseInt(R1); 339 | int r2=Integer.parseInt(R2); 340 | int r3=Integer.parseInt(R3); 341 | String B1=Integer.toBinaryString(r1); 342 | String B2=Integer.toBinaryString(r2); 343 | String B3=Integer.toBinaryString(r3); 344 | int l1=B1.length(); 345 | int l2=B2.length(); 346 | int l3=B3.length(); 347 | for (int i=0;i<8-l1;i++) 348 | OutString.append("0"); 349 | OutString.append(B1); 350 | for (int i=0;i<8-l2;i++) 351 | OutString.append("0"); 352 | OutString.append(B2); 353 | for (int i=0;i<8-l3;i++) 354 | OutString.append("0"); 355 | OutString.append(B3); 356 | int L=OutString.length(); 357 | for (int i=0;i<8;i++) 358 | OutString.append("0"); 359 | } 360 | else System.out.println("Not Found"); 361 | return OutString.toString(); 362 | } 363 | 364 | //subc 365 | Match=subc.matcher(InString); 366 | if (Match.find()){ 367 | System.out.println("sbc Yes!"); 368 | OutString.append("0000000001001"); 369 | String G1=Match.group(2); 370 | OutString.append(subcHash.get(G1)); 371 | String G2=Match.group(3); 372 | OutString.append(typeUS2Hash.get(G2)); 373 | Match=reg3.matcher(InString); 374 | if (Match.find()){ 375 | System.out.println("Found!"); 376 | String R1=Match.group(2); 377 | String R2=Match.group(3); 378 | String R3=Match.group(4); 379 | int r1=Integer.parseInt(R1); 380 | int r2=Integer.parseInt(R2); 381 | int r3=Integer.parseInt(R3); 382 | String B1=Integer.toBinaryString(r1); 383 | String B2=Integer.toBinaryString(r2); 384 | String B3=Integer.toBinaryString(r3); 385 | int l1=B1.length(); 386 | int l2=B2.length(); 387 | int l3=B3.length(); 388 | for (int i=0;i<8-l1;i++) 389 | OutString.append("0"); 390 | OutString.append(B1); 391 | for (int i=0;i<8-l2;i++) 392 | OutString.append("0"); 393 | OutString.append(B2); 394 | for (int i=0;i<8-l3;i++) 395 | OutString.append("0"); 396 | OutString.append(B3); 397 | int L=OutString.length(); 398 | for (int i=0;i<8;i++) 399 | OutString.append("0"); 400 | } 401 | else System.out.println("Not Found"); 402 | return OutString.toString(); 403 | } 404 | 405 | //subf 406 | Match=subf.matcher(InString); 407 | if(Match.find()){ 408 | System.out.println("sbf Yes!"); 409 | OutString.append("0000000001"); 410 | String G1=Match.group(2); 411 | String G2=Match.group(3); 412 | String G3=Match.group(4); 413 | String G4=Match.group(5); 414 | OutString.append(rndHash.get(G1)); 415 | OutString.append(ftzHash.get(G2)); 416 | OutString.append(satHash.get(G3)); 417 | OutString.append(typeF2Hash.get(G4)); 418 | Match=reg3.matcher(InString); 419 | if (Match.find()){ 420 | System.out.println("Found!"); 421 | String R1=Match.group(2); 422 | String R2=Match.group(3); 423 | String R3=Match.group(4); 424 | int r1=Integer.parseInt(R1); 425 | int r2=Integer.parseInt(R2); 426 | int r3=Integer.parseInt(R3); 427 | String B1=Integer.toBinaryString(r1); 428 | String B2=Integer.toBinaryString(r2); 429 | String B3=Integer.toBinaryString(r3); 430 | int l1=B1.length(); 431 | int l2=B2.length(); 432 | int l3=B3.length(); 433 | for (int i=0;i<8-l1;i++) 434 | OutString.append("0"); 435 | OutString.append(B1); 436 | for (int i=0;i<8-l2;i++) 437 | OutString.append("0"); 438 | OutString.append(B2); 439 | for (int i=0;i<8-l3;i++) 440 | OutString.append("0"); 441 | OutString.append(B3); 442 | int L=OutString.length(); 443 | for (int i=0;i<8;i++) 444 | OutString.append("0"); 445 | } 446 | else System.out.println("Not Found"); 447 | return OutString.toString(); 448 | } 449 | 450 | 451 | //muli 452 | Match=muli.matcher(InString); 453 | if(Match.find()){ 454 | System.out.println("muli Yes!"); 455 | OutString.append("0000000010"); 456 | String G1=Match.group(2); 457 | String G2=Match.group(3); 458 | OutString.append("0"); 459 | OutString.append(hiloHash.get(G1)); 460 | OutString.append(typeUS6Hash.get(G2)); 461 | Match=reg3.matcher(InString); 462 | if (Match.find()){ 463 | System.out.println("Found!"); 464 | String R1=Match.group(2); 465 | String R2=Match.group(3); 466 | String R3=Match.group(4); 467 | int r1=Integer.parseInt(R1); 468 | int r2=Integer.parseInt(R2); 469 | int r3=Integer.parseInt(R3); 470 | String B1=Integer.toBinaryString(r1); 471 | String B2=Integer.toBinaryString(r2); 472 | String B3=Integer.toBinaryString(r3); 473 | int l1=B1.length(); 474 | int l2=B2.length(); 475 | int l3=B3.length(); 476 | for (int i=0;i<8-l1;i++) 477 | OutString.append("0"); 478 | OutString.append(B1); 479 | for (int i=0;i<8-l2;i++) 480 | OutString.append("0"); 481 | OutString.append(B2); 482 | for (int i=0;i<8-l3;i++) 483 | OutString.append("0"); 484 | OutString.append(B3); 485 | int L=OutString.length(); 486 | for (int i=0;i<8;i++) 487 | OutString.append("0"); 488 | } 489 | else System.out.println("Not Found"); 490 | return OutString.toString(); 491 | } 492 | 493 | //mulf 494 | Match=mulf.matcher(InString); 495 | if(Match.find()){ 496 | System.out.println("mulf Yes!"); 497 | OutString.append("0000000010"); 498 | String G1=Match.group(2); 499 | String G2=Match.group(3); 500 | String G3=Match.group(4); 501 | String G4=Match.group(5); 502 | if (G4.equals("32")){ 503 | OutString.append("1"); 504 | OutString.append(rnd2Hash.get(G1)); 505 | OutString.append(ftzHash.get(G2)); 506 | OutString.append(satHash.get(G3)); 507 | } 508 | else{ 509 | OutString.append("111"); 510 | OutString.append(rnd2Hash.get(G1)); 511 | } 512 | Match=reg3.matcher(InString); 513 | if (Match.find()){ 514 | System.out.println("Found!"); 515 | String R1=Match.group(2); 516 | String R2=Match.group(3); 517 | String R3=Match.group(4); 518 | int r1=Integer.parseInt(R1); 519 | int r2=Integer.parseInt(R2); 520 | int r3=Integer.parseInt(R3); 521 | String B1=Integer.toBinaryString(r1); 522 | String B2=Integer.toBinaryString(r2); 523 | String B3=Integer.toBinaryString(r3); 524 | int l1=B1.length(); 525 | int l2=B2.length(); 526 | int l3=B3.length(); 527 | for (int i=0;i<8-l1;i++) 528 | OutString.append("0"); 529 | OutString.append(B1); 530 | for (int i=0;i<8-l2;i++) 531 | OutString.append("0"); 532 | OutString.append(B2); 533 | for (int i=0;i<8-l3;i++) 534 | OutString.append("0"); 535 | OutString.append(B3); 536 | int L=OutString.length(); 537 | for (int i=0;i<8;i++) 538 | OutString.append("0"); 539 | } 540 | else System.out.println("Not Found"); 541 | return OutString.toString(); 542 | } 543 | 544 | //madi 545 | Match=madi.matcher(InString); 546 | if(Match.find()){ 547 | System.out.println("madi Yes!"); 548 | OutString.append("0000000011"); 549 | String G1=Match.group(2); 550 | String G2=Match.group(3); 551 | String G3=Match.group(4); 552 | if (".sat".equals(G2)){ 553 | OutString.append("001111"); 554 | } 555 | else { 556 | OutString.append("0"); 557 | OutString.append(hiloHash.get(G1)); 558 | OutString.append(typeUS6Hash.get(G3)); 559 | } 560 | Match=reg4.matcher(InString); 561 | if (Match.find()){ 562 | System.out.println("Found!"); 563 | String R1=Match.group(2); 564 | String R2=Match.group(3); 565 | String R3=Match.group(4); 566 | String R4=Match.group(5); 567 | int r1=Integer.parseInt(R1); 568 | int r2=Integer.parseInt(R2); 569 | int r3=Integer.parseInt(R3); 570 | int r4=Integer.parseInt(R4); 571 | String B1=Integer.toBinaryString(r1); 572 | String B2=Integer.toBinaryString(r2); 573 | String B3=Integer.toBinaryString(r3); 574 | String B4=Integer.toBinaryString(r4); 575 | int l1=B1.length(); 576 | int l2=B2.length(); 577 | int l3=B3.length(); 578 | int l4=B4.length(); 579 | for (int i=0;i<8-l1;i++) 580 | OutString.append("0"); 581 | OutString.append(B1); 582 | for (int i=0;i<8-l2;i++) 583 | OutString.append("0"); 584 | OutString.append(B2); 585 | for (int i=0;i<8-l3;i++) 586 | OutString.append("0"); 587 | OutString.append(B3); 588 | for (int i=0;i<8-l4;i++) 589 | OutString.append("0"); 590 | OutString.append(B4); 591 | 592 | } 593 | else System.out.println("Not Found"); 594 | return OutString.toString(); 595 | } 596 | 597 | //madf 598 | Match=madf.matcher(InString); 599 | if(Match.find()){ 600 | System.out.println("madf Yes!"); 601 | OutString.append("0000000011"); 602 | String G1=Match.group(2); 603 | String G2=Match.group(3); 604 | String G3=Match.group(4); 605 | String G4=Match.group(5); 606 | if("32".equals(G4)){ 607 | OutString.append("1"); 608 | OutString.append(rnd2Hash.get(G1)); 609 | OutString.append(ftzHash.get(G2)); 610 | OutString.append(satHash.get(G3)); 611 | } 612 | else { 613 | OutString.append("111"); 614 | OutString.append(rnd2Hash.get(G1)); 615 | } 616 | Match=reg4.matcher(InString); 617 | if (Match.find()){ 618 | System.out.println("Found!"); 619 | String R1=Match.group(2); 620 | String R2=Match.group(3); 621 | String R3=Match.group(4); 622 | String R4=Match.group(5); 623 | int r1=Integer.parseInt(R1); 624 | int r2=Integer.parseInt(R2); 625 | int r3=Integer.parseInt(R3); 626 | int r4=Integer.parseInt(R4); 627 | String B1=Integer.toBinaryString(r1); 628 | String B2=Integer.toBinaryString(r2); 629 | String B3=Integer.toBinaryString(r3); 630 | String B4=Integer.toBinaryString(r4); 631 | int l1=B1.length(); 632 | int l2=B2.length(); 633 | int l3=B3.length(); 634 | int l4=B4.length(); 635 | for (int i=0;i<8-l1;i++) 636 | OutString.append("0"); 637 | OutString.append(B1); 638 | for (int i=0;i<8-l2;i++) 639 | OutString.append("0"); 640 | OutString.append(B2); 641 | for (int i=0;i<8-l3;i++) 642 | OutString.append("0"); 643 | OutString.append(B3); 644 | for (int i=0;i<8-l4;i++) 645 | OutString.append("0"); 646 | OutString.append(B4); 647 | 648 | } 649 | else System.out.println("Not Found"); 650 | return OutString.toString(); 651 | } 652 | 653 | //divi 654 | Match=divi.matcher(InString); 655 | if(Match.find()){ 656 | System.out.println("divi Yes!"); 657 | OutString.append("0000000101000"); 658 | String G1=Match.group(2); 659 | OutString.append(typeUS6Hash.get(G1)); 660 | Match=reg3.matcher(InString); 661 | if (Match.find()){ 662 | System.out.println("Found!"); 663 | String R1=Match.group(2); 664 | String R2=Match.group(3); 665 | String R3=Match.group(4); 666 | int r1=Integer.parseInt(R1); 667 | int r2=Integer.parseInt(R2); 668 | int r3=Integer.parseInt(R3); 669 | String B1=Integer.toBinaryString(r1); 670 | String B2=Integer.toBinaryString(r2); 671 | String B3=Integer.toBinaryString(r3); 672 | int l1=B1.length(); 673 | int l2=B2.length(); 674 | int l3=B3.length(); 675 | for (int i=0;i<8-l1;i++) 676 | OutString.append("0"); 677 | OutString.append(B1); 678 | for (int i=0;i<8-l2;i++) 679 | OutString.append("0"); 680 | OutString.append(B2); 681 | for (int i=0;i<8-l3;i++) 682 | OutString.append("0"); 683 | OutString.append(B3); 684 | int L=OutString.length(); 685 | for (int i=0;i<8;i++) 686 | OutString.append("0"); 687 | } 688 | else System.out.println("Not Found"); 689 | return OutString.toString(); 690 | } 691 | 692 | //divf 693 | Match=divf.matcher(InString); 694 | if(Match.find()){ 695 | System.out.println("divf Yes!"); 696 | OutString.append("0000000101"); 697 | String G1=Match.group(2); 698 | String G2=Match.group(3); 699 | String G3=Match.group(4); 700 | if (".approx".equals(G1)){ 701 | OutString.append("00100"); 702 | OutString.append(ftzHash.get(G2)); 703 | } 704 | else if (".full".equals(G1)){ 705 | OutString.append("00101"); 706 | OutString.append(ftzHash.get(G2)); 707 | } 708 | else { 709 | if("64".equals(G3)){ 710 | OutString.append("0011"); 711 | OutString.append(rnd3Hash.get(G1)); 712 | } 713 | else { 714 | OutString.append("010"); 715 | OutString.append(rnd3Hash.get(G1)); 716 | OutString.append(ftzHash.get(G2)); 717 | } 718 | } 719 | Match=reg3.matcher(InString); 720 | if (Match.find()){ 721 | System.out.println("Found!"); 722 | String R1=Match.group(2); 723 | String R2=Match.group(3); 724 | String R3=Match.group(4); 725 | int r1=Integer.parseInt(R1); 726 | int r2=Integer.parseInt(R2); 727 | int r3=Integer.parseInt(R3); 728 | String B1=Integer.toBinaryString(r1); 729 | String B2=Integer.toBinaryString(r2); 730 | String B3=Integer.toBinaryString(r3); 731 | int l1=B1.length(); 732 | int l2=B2.length(); 733 | int l3=B3.length(); 734 | for (int i=0;i<8-l1;i++) 735 | OutString.append("0"); 736 | OutString.append(B1); 737 | for (int i=0;i<8-l2;i++) 738 | OutString.append("0"); 739 | OutString.append(B2); 740 | for (int i=0;i<8-l3;i++) 741 | OutString.append("0"); 742 | OutString.append(B3); 743 | int L=OutString.length(); 744 | for (int i=0;i<8;i++) 745 | OutString.append("0"); 746 | } 747 | else System.out.println("Not Found"); 748 | return OutString.toString(); 749 | } 750 | 751 | //setp 752 | Match=setp.matcher(InString); 753 | if(Match.find()){ 754 | System.out.println("setp Yes!"); 755 | OutString.append("00011"); 756 | String G1=Match.group(2); 757 | String G2=Match.group(3); 758 | //String G3=Match.group(4); 759 | String G4=Match.group(5); 760 | OutString.append(cmpopHash.get(G1)); 761 | OutString.append(boolopHash.get(G2)); 762 | OutString.append(typeBUSF11Hash.get(G4)); 763 | Match=preg3.matcher(InString); 764 | if (Match.find()){ 765 | System.out.println("Found!"); 766 | String R1=Match.group(2); 767 | String R2=Match.group(3); 768 | String R3=Match.group(4); 769 | int r1=Integer.parseInt(R1)+regNum; 770 | int r2=Integer.parseInt(R2); 771 | int r3=Integer.parseInt(R3); 772 | String B1=Integer.toBinaryString(r1); 773 | String B2=Integer.toBinaryString(r2); 774 | String B3=Integer.toBinaryString(r3); 775 | int l1=B1.length(); 776 | int l2=B2.length(); 777 | int l3=B3.length(); 778 | for (int i=0;i<8-l1;i++) 779 | OutString.append("0"); 780 | OutString.append(B1); 781 | for (int i=0;i<8-l2;i++) 782 | OutString.append("0"); 783 | OutString.append(B2); 784 | for (int i=0;i<8-l3;i++) 785 | OutString.append("0"); 786 | OutString.append(B3); 787 | int L=OutString.length(); 788 | for (int i=0;i<8;i++) 789 | OutString.append("0"); 790 | } 791 | else System.out.println("Not Found"); 792 | return OutString.toString(); 793 | } 794 | 795 | //mov ******************* 796 | Match=mov.matcher(InString); 797 | if(Match.find()){ 798 | System.out.println("mov Yes!"); 799 | OutString.append("0000000000011001"); 800 | OutString.append("00000000000000000000000000000000"); 801 | return OutString.toString(); 802 | } 803 | 804 | //ld *********************** 805 | Match=ld.matcher(InString); 806 | if(Match.find()){ 807 | System.out.println("ld Yes!"); 808 | OutString.append("000000000010"); 809 | String G1=Match.group(2); 810 | if (G1.equals("global")) 811 | OutString.append("1010"); 812 | if (G1.equals("shared")) 813 | OutString.append("1011"); 814 | if (G1.equals("local")) 815 | OutString.append("1100"); 816 | if (G1.equals("const")) 817 | OutString.append("1101"); 818 | return OutString.toString(); 819 | } 820 | 821 | //st ******************* 822 | Match=st.matcher(InString); 823 | if(Match.find()){ 824 | System.out.println("st Yes!"); 825 | OutString.append("00000000001"); 826 | String G1=Match.group(2); 827 | if (G1.equals("global")) 828 | OutString.append("01110"); 829 | if (G1.equals("shared")) 830 | OutString.append("01111"); 831 | if (G1.equals("local")) 832 | OutString.append("10000"); 833 | if (G1.equals("const")) 834 | OutString.append("10001"); 835 | return OutString.toString(); 836 | } 837 | 838 | //bra ********************* 839 | Match=bra.matcher(InString); 840 | if(Match.find()){ 841 | System.out.println("bra Yes!"); 842 | OutString.append("0000000000110010"); 843 | return OutString.toString(); 844 | } 845 | 846 | return "XD"; 847 | 848 | 849 | 850 | 851 | } 852 | } 853 | -------------------------------------------------------------------------------- /project/src/isaConvert.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.regex.*; 3 | import java.util.HashMap; 4 | 5 | public class isaConvert { 6 | private Pattern reg,pred,addi,addc,addf,subi,subc,subf,muli,mulf,madi,madf,divi,divf; 7 | private Pattern setp,mov,ld,st,bra,reg2,reg3,reg4,preg3; 8 | private HashMap typeUS6Hash,typeUS2Hash,addcHash,rndHash; 9 | private HashMap ftzHash,satHash,typeF2Hash,subcHash,hiloHash; 10 | private HashMap rnd2Hash,rnd3Hash,cmpopHash,boolopHash,typeBUSF11Hash; 11 | private int regNum; 12 | public isaConvert(){ 13 | regNum=0; 14 | reg=Pattern.compile("(.reg .[usf]\\d{1,2} \\%[a-zA-Z]+<(\\d+)>;)"); 15 | pred=Pattern.compile("(@(!)?%p(\\d+))"); 16 | addi=Pattern.compile("(add(.sat)?.([us]\\d{2}))"); 17 | addc=Pattern.compile("((add.cc|addc|addc.cc).([us])32)"); 18 | addf=Pattern.compile("(add(.r[mnpz])?(.ftz)?(.sat)?.f(32|64))"); 19 | subi=Pattern.compile("(sub(.sat)?.([us]\\d{2}))"); 20 | subc=Pattern.compile("((sub.cc|subc|subc.cc).([us])32)"); 21 | subf=Pattern.compile("(sub(.r[mnpz])?(.ftz)?(.sat)?.f(32|64))"); 22 | muli=Pattern.compile("(mul(.hi|.lo|.wide)?.([us]\\d{2}))"); 23 | mulf=Pattern.compile("(mul(.r[mnpz])?(.ftz)?(.sat)?.f(32|64))"); 24 | madi=Pattern.compile("(mad(.hi|.lo|.wide)?(.sat)?.([us]\\d{2}))"); 25 | madf=Pattern.compile("(mad(.r[nzmp])?(.ftz)?(.sat)?.f(32|64))"); 26 | divi=Pattern.compile("(div.([us]\\d{2}))"); 27 | divf=Pattern.compile("(div(.approx|.full|.r[nzmp])(.ftz)?.f(32|64))"); 28 | setp=Pattern.compile("(setp(.eq|.ne|.lt|.gt|.ge|.lo|.ls|.hi|.hs|.equ|.neu|.ltu|.leu|.gtu|.geu|.num|.nan)(.and|.or|.xor)?(.ftz)?(.[busf]\\d{2}))"); 29 | mov=Pattern.compile("(mov.([busf]\\d{2}||pred))"); 30 | ld=Pattern.compile("(ld.(global|shared|local|const))"); 31 | st=Pattern.compile("(st.(global|shared|local|const))"); 32 | bra=Pattern.compile("(bra)"); 33 | reg3=Pattern.compile("(\\%r(\\d+), \\%r(\\d+), \\%r(\\d+))"); 34 | reg4=Pattern.compile("(\\%r(\\d+), \\%r(\\d+), \\%r(\\d+), \\%r(\\d+))"); 35 | preg3=Pattern.compile("(\\%p(\\d+), \\%r(\\d+), \\%r(\\d+))"); 36 | 37 | //used in addi subi muli madi divi 38 | typeUS6Hash=new HashMap(); 39 | typeUS6Hash.put("u16","000"); 40 | typeUS6Hash.put("u32","001"); 41 | typeUS6Hash.put("u64","010"); 42 | typeUS6Hash.put("s16","100"); 43 | typeUS6Hash.put("s32","101"); 44 | typeUS6Hash.put("s64","110"); 45 | 46 | //used in addc subc 47 | typeUS2Hash=new HashMap(); 48 | typeUS2Hash.put("u","0"); 49 | typeUS2Hash.put("s", "1"); 50 | 51 | //used in addc subc 52 | addcHash=new HashMap(); 53 | addcHash.put("add.cc", "00"); 54 | addcHash.put("addc", "10"); 55 | addcHash.put("addc.cc", "11"); 56 | 57 | //used in addf subf 58 | rndHash=new HashMap(); 59 | rndHash.put(".rn", "100"); 60 | rndHash.put(".rz", "101"); 61 | rndHash.put(".rm", "110"); 62 | rndHash.put(".rp", "111"); 63 | rndHash.put(null, "010"); 64 | 65 | //used in addf subf mulf madf divf 66 | ftzHash=new HashMap(); 67 | ftzHash.put(null,"0"); 68 | ftzHash.put(".ftz","1"); 69 | 70 | //used in addf subf mulf madf divf 71 | satHash=new HashMap(); 72 | satHash.put(null, "0"); 73 | satHash.put(".sat", "1"); 74 | 75 | //used in addf subf 76 | typeF2Hash=new HashMap(); 77 | typeF2Hash.put("32", "0"); 78 | typeF2Hash.put("64", "1"); 79 | 80 | //used in subc 81 | subcHash=new HashMap(); 82 | subcHash.put("sub.cc", "00"); 83 | subcHash.put("subc", "10"); 84 | subcHash.put("subc.cc", "11"); 85 | 86 | //used in muli madi 87 | hiloHash=new HashMap(); 88 | hiloHash.put(null, "00"); 89 | hiloHash.put(".hi", "01"); 90 | hiloHash.put(".lo", "10"); 91 | hiloHash.put(".wide", "11"); 92 | 93 | //used in mulf madf 94 | rnd2Hash=new HashMap(); 95 | rnd2Hash.put(null, "100"); 96 | rnd2Hash.put(".rn", "000"); 97 | rnd2Hash.put(".rz", "001"); 98 | rnd2Hash.put(".rm", "010"); 99 | rnd2Hash.put(".rp", "011"); 100 | 101 | //used in divf 102 | rnd3Hash=new HashMap(); 103 | rnd3Hash.put(".rn", "00"); 104 | rnd3Hash.put(".rz", "01"); 105 | rnd3Hash.put(".rm", "10"); 106 | rnd3Hash.put(".rp", "11"); 107 | 108 | //used in setp 109 | cmpopHash=new HashMap(); 110 | cmpopHash.put(".eq", "01010"); 111 | cmpopHash.put(".ne", "01011"); 112 | cmpopHash.put(".lt", "01100"); 113 | cmpopHash.put(".gt", "01101"); 114 | cmpopHash.put(".ge", "01110"); 115 | cmpopHash.put(".lo", "01111"); 116 | cmpopHash.put(".ls", "10000"); 117 | cmpopHash.put(".hi", "10001"); 118 | cmpopHash.put(".hs", "10010"); 119 | cmpopHash.put(".equ", "10011"); 120 | cmpopHash.put(".neu", "10100"); 121 | cmpopHash.put(".ltu", "10101"); 122 | cmpopHash.put(".leu", "10110"); 123 | cmpopHash.put(".gtu", "10111"); 124 | cmpopHash.put(".geu", "11000"); 125 | cmpopHash.put(".num", "11001"); 126 | cmpopHash.put(".nan", "11010"); 127 | 128 | //used in setp 129 | boolopHash=new HashMap(); 130 | boolopHash.put(null, "00"); 131 | boolopHash.put(".and", "01"); 132 | boolopHash.put("or", "10"); 133 | boolopHash.put("xor", "11"); 134 | 135 | //used in setp 136 | typeBUSF11Hash=new HashMap(); 137 | typeBUSF11Hash.put(".b16","0000"); 138 | typeBUSF11Hash.put(".b32","0001"); 139 | typeBUSF11Hash.put(".b64","0010"); 140 | typeBUSF11Hash.put(".u16","0100"); 141 | typeBUSF11Hash.put(".u32","0101"); 142 | typeBUSF11Hash.put(".u64","0110"); 143 | typeBUSF11Hash.put(".s16","1000"); 144 | typeBUSF11Hash.put(".s32","1001"); 145 | typeBUSF11Hash.put(".s64","1010"); 146 | typeBUSF11Hash.put(".f32","1100"); 147 | typeBUSF11Hash.put(".f64","1101"); 148 | 149 | 150 | 151 | } 152 | public String Convert(String InString){ 153 | StringBuilder OutString; 154 | Matcher Match; 155 | 156 | //reg 157 | Match=reg.matcher(InString); 158 | if(Match.find()){ 159 | System.out.println("reg Yes!"); 160 | String G1=Match.group(2); 161 | regNum=regNum+Integer.parseInt(G1); 162 | } 163 | 164 | //pred 165 | Match=pred.matcher(InString); 166 | if(Match.find()){ 167 | System.out.println("pred Yes!"); 168 | String G1=Match.group(2); 169 | String G2=Match.group(3); 170 | if ("!".equals(G1)) 171 | OutString=new StringBuilder("00000000000"); 172 | else 173 | OutString=new StringBuilder("00000000001"); 174 | int pN=regNum+Integer.parseInt(G2); 175 | String G3=Integer.toBinaryString(pN); 176 | int LL=G3.length(); 177 | for (int i=0;i<5-LL;i++) 178 | OutString.append("0"); 179 | OutString.append(G3); 180 | } 181 | else 182 | OutString=new StringBuilder("0000000000000000"); 183 | 184 | //add 185 | Match=addi.matcher(InString); 186 | if (Match.find()){ 187 | System.out.println("add Yes!"); 188 | /*for (int i=1;i<=2;i++){ 189 | System.out.println(addM.group(i)); 190 | }*/ 191 | OutString.append("0000000000000"); 192 | String G1=Match.group(2); 193 | if ((".sat").equals(G1)) 194 | OutString.append("111"); 195 | else { 196 | String G2=Match.group(3); 197 | OutString.append(typeUS6Hash.get(G2)); 198 | } 199 | Match=reg3.matcher(InString); 200 | if (Match.find()){ 201 | System.out.println("Found!"); 202 | String R1=Match.group(2); 203 | String R2=Match.group(3); 204 | String R3=Match.group(4); 205 | int r1=Integer.parseInt(R1); 206 | int r2=Integer.parseInt(R2); 207 | int r3=Integer.parseInt(R3); 208 | String B1=Integer.toBinaryString(r1); 209 | String B2=Integer.toBinaryString(r2); 210 | String B3=Integer.toBinaryString(r3); 211 | int l1=B1.length(); 212 | int l2=B2.length(); 213 | int l3=B3.length(); 214 | for (int i=0;i<8-l1;i++) 215 | OutString.append("0"); 216 | OutString.append(B1); 217 | for (int i=0;i<8-l2;i++) 218 | OutString.append("0"); 219 | OutString.append(B2); 220 | for (int i=0;i<8-l3;i++) 221 | OutString.append("0"); 222 | OutString.append(B3); 223 | int L=OutString.length(); 224 | for (int i=0;i<8;i++) 225 | OutString.append("0"); 226 | } 227 | else System.out.println("Not Found"); 228 | return OutString.toString(); 229 | } 230 | 231 | //addc 232 | Match=addc.matcher(InString); 233 | if (Match.find()){ 234 | System.out.println("adc Yes!"); 235 | OutString.append("0000000000001"); 236 | String G1=Match.group(2); 237 | OutString.append(addcHash.get(G1)); 238 | String G2=Match.group(3); 239 | OutString.append(typeUS2Hash.get(G2)); 240 | Match=reg3.matcher(InString); 241 | if (Match.find()){ 242 | System.out.println("Found!"); 243 | String R1=Match.group(2); 244 | String R2=Match.group(3); 245 | String R3=Match.group(4); 246 | int r1=Integer.parseInt(R1); 247 | int r2=Integer.parseInt(R2); 248 | int r3=Integer.parseInt(R3); 249 | String B1=Integer.toBinaryString(r1); 250 | String B2=Integer.toBinaryString(r2); 251 | String B3=Integer.toBinaryString(r3); 252 | int l1=B1.length(); 253 | int l2=B2.length(); 254 | int l3=B3.length(); 255 | for (int i=0;i<8-l1;i++) 256 | OutString.append("0"); 257 | OutString.append(B1); 258 | for (int i=0;i<8-l2;i++) 259 | OutString.append("0"); 260 | OutString.append(B2); 261 | for (int i=0;i<8-l3;i++) 262 | OutString.append("0"); 263 | OutString.append(B3); 264 | int L=OutString.length(); 265 | for (int i=0;i<8;i++) 266 | OutString.append("0"); 267 | } 268 | else System.out.println("Not Found"); 269 | return OutString.toString(); 270 | } 271 | 272 | //addf 273 | Match=addf.matcher(InString); 274 | if(Match.find()){ 275 | System.out.println("adf Yes!"); 276 | OutString.append("0000000000"); 277 | String G1=Match.group(2); 278 | String G2=Match.group(3); 279 | String G3=Match.group(4); 280 | String G4=Match.group(5); 281 | OutString.append(rndHash.get(G1)); 282 | OutString.append(ftzHash.get(G2)); 283 | OutString.append(satHash.get(G3)); 284 | OutString.append(typeF2Hash.get(G4)); 285 | Match=reg3.matcher(InString); 286 | if (Match.find()){ 287 | System.out.println("Found!"); 288 | String R1=Match.group(2); 289 | String R2=Match.group(3); 290 | String R3=Match.group(4); 291 | int r1=Integer.parseInt(R1); 292 | int r2=Integer.parseInt(R2); 293 | int r3=Integer.parseInt(R3); 294 | String B1=Integer.toBinaryString(r1); 295 | String B2=Integer.toBinaryString(r2); 296 | String B3=Integer.toBinaryString(r3); 297 | int l1=B1.length(); 298 | int l2=B2.length(); 299 | int l3=B3.length(); 300 | for (int i=0;i<8-l1;i++) 301 | OutString.append("0"); 302 | OutString.append(B1); 303 | for (int i=0;i<8-l2;i++) 304 | OutString.append("0"); 305 | OutString.append(B2); 306 | for (int i=0;i<8-l3;i++) 307 | OutString.append("0"); 308 | OutString.append(B3); 309 | int L=OutString.length(); 310 | for (int i=0;i<8;i++) 311 | OutString.append("0"); 312 | } 313 | else System.out.println("Not Found"); 314 | return OutString.toString(); 315 | } 316 | 317 | //subi 318 | Match=subi.matcher(InString); 319 | if (Match.find()){ 320 | System.out.println("sub Yes!"); 321 | /*for (int i=1;i<=2;i++){ 322 | System.out.println(addM.group(i)); 323 | }*/ 324 | OutString.append("0000000001000"); 325 | String G1=Match.group(2); 326 | if ((".sat").equals(G1)) 327 | OutString.append("111"); 328 | else { 329 | String G2=Match.group(3); 330 | OutString.append(typeUS6Hash.get(G2)); 331 | } 332 | Match=reg3.matcher(InString); 333 | if (Match.find()){ 334 | System.out.println("Found!"); 335 | String R1=Match.group(2); 336 | String R2=Match.group(3); 337 | String R3=Match.group(4); 338 | int r1=Integer.parseInt(R1); 339 | int r2=Integer.parseInt(R2); 340 | int r3=Integer.parseInt(R3); 341 | String B1=Integer.toBinaryString(r1); 342 | String B2=Integer.toBinaryString(r2); 343 | String B3=Integer.toBinaryString(r3); 344 | int l1=B1.length(); 345 | int l2=B2.length(); 346 | int l3=B3.length(); 347 | for (int i=0;i<8-l1;i++) 348 | OutString.append("0"); 349 | OutString.append(B1); 350 | for (int i=0;i<8-l2;i++) 351 | OutString.append("0"); 352 | OutString.append(B2); 353 | for (int i=0;i<8-l3;i++) 354 | OutString.append("0"); 355 | OutString.append(B3); 356 | int L=OutString.length(); 357 | for (int i=0;i<8;i++) 358 | OutString.append("0"); 359 | } 360 | else System.out.println("Not Found"); 361 | return OutString.toString(); 362 | } 363 | 364 | //subc 365 | Match=subc.matcher(InString); 366 | if (Match.find()){ 367 | System.out.println("sbc Yes!"); 368 | OutString.append("0000000001001"); 369 | String G1=Match.group(2); 370 | OutString.append(subcHash.get(G1)); 371 | String G2=Match.group(3); 372 | OutString.append(typeUS2Hash.get(G2)); 373 | Match=reg3.matcher(InString); 374 | if (Match.find()){ 375 | System.out.println("Found!"); 376 | String R1=Match.group(2); 377 | String R2=Match.group(3); 378 | String R3=Match.group(4); 379 | int r1=Integer.parseInt(R1); 380 | int r2=Integer.parseInt(R2); 381 | int r3=Integer.parseInt(R3); 382 | String B1=Integer.toBinaryString(r1); 383 | String B2=Integer.toBinaryString(r2); 384 | String B3=Integer.toBinaryString(r3); 385 | int l1=B1.length(); 386 | int l2=B2.length(); 387 | int l3=B3.length(); 388 | for (int i=0;i<8-l1;i++) 389 | OutString.append("0"); 390 | OutString.append(B1); 391 | for (int i=0;i<8-l2;i++) 392 | OutString.append("0"); 393 | OutString.append(B2); 394 | for (int i=0;i<8-l3;i++) 395 | OutString.append("0"); 396 | OutString.append(B3); 397 | int L=OutString.length(); 398 | for (int i=0;i<8;i++) 399 | OutString.append("0"); 400 | } 401 | else System.out.println("Not Found"); 402 | return OutString.toString(); 403 | } 404 | 405 | //subf 406 | Match=subf.matcher(InString); 407 | if(Match.find()){ 408 | System.out.println("sbf Yes!"); 409 | OutString.append("0000000001"); 410 | String G1=Match.group(2); 411 | String G2=Match.group(3); 412 | String G3=Match.group(4); 413 | String G4=Match.group(5); 414 | OutString.append(rndHash.get(G1)); 415 | OutString.append(ftzHash.get(G2)); 416 | OutString.append(satHash.get(G3)); 417 | OutString.append(typeF2Hash.get(G4)); 418 | Match=reg3.matcher(InString); 419 | if (Match.find()){ 420 | System.out.println("Found!"); 421 | String R1=Match.group(2); 422 | String R2=Match.group(3); 423 | String R3=Match.group(4); 424 | int r1=Integer.parseInt(R1); 425 | int r2=Integer.parseInt(R2); 426 | int r3=Integer.parseInt(R3); 427 | String B1=Integer.toBinaryString(r1); 428 | String B2=Integer.toBinaryString(r2); 429 | String B3=Integer.toBinaryString(r3); 430 | int l1=B1.length(); 431 | int l2=B2.length(); 432 | int l3=B3.length(); 433 | for (int i=0;i<8-l1;i++) 434 | OutString.append("0"); 435 | OutString.append(B1); 436 | for (int i=0;i<8-l2;i++) 437 | OutString.append("0"); 438 | OutString.append(B2); 439 | for (int i=0;i<8-l3;i++) 440 | OutString.append("0"); 441 | OutString.append(B3); 442 | int L=OutString.length(); 443 | for (int i=0;i<8;i++) 444 | OutString.append("0"); 445 | } 446 | else System.out.println("Not Found"); 447 | return OutString.toString(); 448 | } 449 | 450 | 451 | //muli 452 | Match=muli.matcher(InString); 453 | if(Match.find()){ 454 | System.out.println("muli Yes!"); 455 | OutString.append("0000000010"); 456 | String G1=Match.group(2); 457 | String G2=Match.group(3); 458 | OutString.append("0"); 459 | OutString.append(hiloHash.get(G1)); 460 | OutString.append(typeUS6Hash.get(G2)); 461 | Match=reg3.matcher(InString); 462 | if (Match.find()){ 463 | System.out.println("Found!"); 464 | String R1=Match.group(2); 465 | String R2=Match.group(3); 466 | String R3=Match.group(4); 467 | int r1=Integer.parseInt(R1); 468 | int r2=Integer.parseInt(R2); 469 | int r3=Integer.parseInt(R3); 470 | String B1=Integer.toBinaryString(r1); 471 | String B2=Integer.toBinaryString(r2); 472 | String B3=Integer.toBinaryString(r3); 473 | int l1=B1.length(); 474 | int l2=B2.length(); 475 | int l3=B3.length(); 476 | for (int i=0;i<8-l1;i++) 477 | OutString.append("0"); 478 | OutString.append(B1); 479 | for (int i=0;i<8-l2;i++) 480 | OutString.append("0"); 481 | OutString.append(B2); 482 | for (int i=0;i<8-l3;i++) 483 | OutString.append("0"); 484 | OutString.append(B3); 485 | int L=OutString.length(); 486 | for (int i=0;i<8;i++) 487 | OutString.append("0"); 488 | } 489 | else System.out.println("Not Found"); 490 | return OutString.toString(); 491 | } 492 | 493 | //mulf 494 | Match=mulf.matcher(InString); 495 | if(Match.find()){ 496 | System.out.println("mulf Yes!"); 497 | OutString.append("0000000010"); 498 | String G1=Match.group(2); 499 | String G2=Match.group(3); 500 | String G3=Match.group(4); 501 | String G4=Match.group(5); 502 | if (G4.equals("32")){ 503 | OutString.append("1"); 504 | OutString.append(rnd2Hash.get(G1)); 505 | OutString.append(ftzHash.get(G2)); 506 | OutString.append(satHash.get(G3)); 507 | } 508 | else{ 509 | OutString.append("111"); 510 | OutString.append(rnd2Hash.get(G1)); 511 | } 512 | Match=reg3.matcher(InString); 513 | if (Match.find()){ 514 | System.out.println("Found!"); 515 | String R1=Match.group(2); 516 | String R2=Match.group(3); 517 | String R3=Match.group(4); 518 | int r1=Integer.parseInt(R1); 519 | int r2=Integer.parseInt(R2); 520 | int r3=Integer.parseInt(R3); 521 | String B1=Integer.toBinaryString(r1); 522 | String B2=Integer.toBinaryString(r2); 523 | String B3=Integer.toBinaryString(r3); 524 | int l1=B1.length(); 525 | int l2=B2.length(); 526 | int l3=B3.length(); 527 | for (int i=0;i<8-l1;i++) 528 | OutString.append("0"); 529 | OutString.append(B1); 530 | for (int i=0;i<8-l2;i++) 531 | OutString.append("0"); 532 | OutString.append(B2); 533 | for (int i=0;i<8-l3;i++) 534 | OutString.append("0"); 535 | OutString.append(B3); 536 | int L=OutString.length(); 537 | for (int i=0;i<8;i++) 538 | OutString.append("0"); 539 | } 540 | else System.out.println("Not Found"); 541 | return OutString.toString(); 542 | } 543 | 544 | //madi 545 | Match=madi.matcher(InString); 546 | if(Match.find()){ 547 | System.out.println("madi Yes!"); 548 | OutString.append("0000000011"); 549 | String G1=Match.group(2); 550 | String G2=Match.group(3); 551 | String G3=Match.group(4); 552 | if (".sat".equals(G2)){ 553 | OutString.append("001111"); 554 | } 555 | else { 556 | OutString.append("0"); 557 | OutString.append(hiloHash.get(G1)); 558 | OutString.append(typeUS6Hash.get(G3)); 559 | } 560 | Match=reg4.matcher(InString); 561 | if (Match.find()){ 562 | System.out.println("Found!"); 563 | String R1=Match.group(2); 564 | String R2=Match.group(3); 565 | String R3=Match.group(4); 566 | String R4=Match.group(5); 567 | int r1=Integer.parseInt(R1); 568 | int r2=Integer.parseInt(R2); 569 | int r3=Integer.parseInt(R3); 570 | int r4=Integer.parseInt(R4); 571 | String B1=Integer.toBinaryString(r1); 572 | String B2=Integer.toBinaryString(r2); 573 | String B3=Integer.toBinaryString(r3); 574 | String B4=Integer.toBinaryString(r4); 575 | int l1=B1.length(); 576 | int l2=B2.length(); 577 | int l3=B3.length(); 578 | int l4=B4.length(); 579 | for (int i=0;i<8-l1;i++) 580 | OutString.append("0"); 581 | OutString.append(B1); 582 | for (int i=0;i<8-l2;i++) 583 | OutString.append("0"); 584 | OutString.append(B2); 585 | for (int i=0;i<8-l3;i++) 586 | OutString.append("0"); 587 | OutString.append(B3); 588 | for (int i=0;i<8-l4;i++) 589 | OutString.append("0"); 590 | OutString.append(B4); 591 | 592 | } 593 | else System.out.println("Not Found"); 594 | return OutString.toString(); 595 | } 596 | 597 | //madf 598 | Match=madf.matcher(InString); 599 | if(Match.find()){ 600 | System.out.println("madf Yes!"); 601 | OutString.append("0000000011"); 602 | String G1=Match.group(2); 603 | String G2=Match.group(3); 604 | String G3=Match.group(4); 605 | String G4=Match.group(5); 606 | if("32".equals(G4)){ 607 | OutString.append("1"); 608 | OutString.append(rnd2Hash.get(G1)); 609 | OutString.append(ftzHash.get(G2)); 610 | OutString.append(satHash.get(G3)); 611 | } 612 | else { 613 | OutString.append("111"); 614 | OutString.append(rnd2Hash.get(G1)); 615 | } 616 | Match=reg4.matcher(InString); 617 | if (Match.find()){ 618 | System.out.println("Found!"); 619 | String R1=Match.group(2); 620 | String R2=Match.group(3); 621 | String R3=Match.group(4); 622 | String R4=Match.group(5); 623 | int r1=Integer.parseInt(R1); 624 | int r2=Integer.parseInt(R2); 625 | int r3=Integer.parseInt(R3); 626 | int r4=Integer.parseInt(R4); 627 | String B1=Integer.toBinaryString(r1); 628 | String B2=Integer.toBinaryString(r2); 629 | String B3=Integer.toBinaryString(r3); 630 | String B4=Integer.toBinaryString(r4); 631 | int l1=B1.length(); 632 | int l2=B2.length(); 633 | int l3=B3.length(); 634 | int l4=B4.length(); 635 | for (int i=0;i<8-l1;i++) 636 | OutString.append("0"); 637 | OutString.append(B1); 638 | for (int i=0;i<8-l2;i++) 639 | OutString.append("0"); 640 | OutString.append(B2); 641 | for (int i=0;i<8-l3;i++) 642 | OutString.append("0"); 643 | OutString.append(B3); 644 | for (int i=0;i<8-l4;i++) 645 | OutString.append("0"); 646 | OutString.append(B4); 647 | 648 | } 649 | else System.out.println("Not Found"); 650 | return OutString.toString(); 651 | } 652 | 653 | //divi 654 | Match=divi.matcher(InString); 655 | if(Match.find()){ 656 | System.out.println("divi Yes!"); 657 | OutString.append("0000000101000"); 658 | String G1=Match.group(2); 659 | OutString.append(typeUS6Hash.get(G1)); 660 | Match=reg3.matcher(InString); 661 | if (Match.find()){ 662 | System.out.println("Found!"); 663 | String R1=Match.group(2); 664 | String R2=Match.group(3); 665 | String R3=Match.group(4); 666 | int r1=Integer.parseInt(R1); 667 | int r2=Integer.parseInt(R2); 668 | int r3=Integer.parseInt(R3); 669 | String B1=Integer.toBinaryString(r1); 670 | String B2=Integer.toBinaryString(r2); 671 | String B3=Integer.toBinaryString(r3); 672 | int l1=B1.length(); 673 | int l2=B2.length(); 674 | int l3=B3.length(); 675 | for (int i=0;i<8-l1;i++) 676 | OutString.append("0"); 677 | OutString.append(B1); 678 | for (int i=0;i<8-l2;i++) 679 | OutString.append("0"); 680 | OutString.append(B2); 681 | for (int i=0;i<8-l3;i++) 682 | OutString.append("0"); 683 | OutString.append(B3); 684 | int L=OutString.length(); 685 | for (int i=0;i<8;i++) 686 | OutString.append("0"); 687 | } 688 | else System.out.println("Not Found"); 689 | return OutString.toString(); 690 | } 691 | 692 | //divf 693 | Match=divf.matcher(InString); 694 | if(Match.find()){ 695 | System.out.println("divf Yes!"); 696 | OutString.append("0000000101"); 697 | String G1=Match.group(2); 698 | String G2=Match.group(3); 699 | String G3=Match.group(4); 700 | if (".approx".equals(G1)){ 701 | OutString.append("00100"); 702 | OutString.append(ftzHash.get(G2)); 703 | } 704 | else if (".full".equals(G1)){ 705 | OutString.append("00101"); 706 | OutString.append(ftzHash.get(G2)); 707 | } 708 | else { 709 | if("64".equals(G3)){ 710 | OutString.append("0011"); 711 | OutString.append(rnd3Hash.get(G1)); 712 | } 713 | else { 714 | OutString.append("010"); 715 | OutString.append(rnd3Hash.get(G1)); 716 | OutString.append(ftzHash.get(G2)); 717 | } 718 | } 719 | Match=reg3.matcher(InString); 720 | if (Match.find()){ 721 | System.out.println("Found!"); 722 | String R1=Match.group(2); 723 | String R2=Match.group(3); 724 | String R3=Match.group(4); 725 | int r1=Integer.parseInt(R1); 726 | int r2=Integer.parseInt(R2); 727 | int r3=Integer.parseInt(R3); 728 | String B1=Integer.toBinaryString(r1); 729 | String B2=Integer.toBinaryString(r2); 730 | String B3=Integer.toBinaryString(r3); 731 | int l1=B1.length(); 732 | int l2=B2.length(); 733 | int l3=B3.length(); 734 | for (int i=0;i<8-l1;i++) 735 | OutString.append("0"); 736 | OutString.append(B1); 737 | for (int i=0;i<8-l2;i++) 738 | OutString.append("0"); 739 | OutString.append(B2); 740 | for (int i=0;i<8-l3;i++) 741 | OutString.append("0"); 742 | OutString.append(B3); 743 | int L=OutString.length(); 744 | for (int i=0;i<8;i++) 745 | OutString.append("0"); 746 | } 747 | else System.out.println("Not Found"); 748 | return OutString.toString(); 749 | } 750 | 751 | //setp 752 | Match=setp.matcher(InString); 753 | if(Match.find()){ 754 | System.out.println("setp Yes!"); 755 | OutString.append("00011"); 756 | String G1=Match.group(2); 757 | String G2=Match.group(3); 758 | //String G3=Match.group(4); 759 | String G4=Match.group(5); 760 | OutString.append(cmpopHash.get(G1)); 761 | OutString.append(boolopHash.get(G2)); 762 | OutString.append(typeBUSF11Hash.get(G4)); 763 | Match=preg3.matcher(InString); 764 | if (Match.find()){ 765 | System.out.println("Found!"); 766 | String R1=Match.group(2); 767 | String R2=Match.group(3); 768 | String R3=Match.group(4); 769 | int r1=Integer.parseInt(R1)+regNum; 770 | int r2=Integer.parseInt(R2); 771 | int r3=Integer.parseInt(R3); 772 | String B1=Integer.toBinaryString(r1); 773 | String B2=Integer.toBinaryString(r2); 774 | String B3=Integer.toBinaryString(r3); 775 | int l1=B1.length(); 776 | int l2=B2.length(); 777 | int l3=B3.length(); 778 | for (int i=0;i<8-l1;i++) 779 | OutString.append("0"); 780 | OutString.append(B1); 781 | for (int i=0;i<8-l2;i++) 782 | OutString.append("0"); 783 | OutString.append(B2); 784 | for (int i=0;i<8-l3;i++) 785 | OutString.append("0"); 786 | OutString.append(B3); 787 | int L=OutString.length(); 788 | for (int i=0;i<8;i++) 789 | OutString.append("0"); 790 | } 791 | else System.out.println("Not Found"); 792 | return OutString.toString(); 793 | } 794 | 795 | //mov ******************* 796 | Match=mov.matcher(InString); 797 | if(Match.find()){ 798 | System.out.println("mov Yes!"); 799 | OutString.append("0000000000011001"); 800 | OutString.append("00000000000000000000000000000000"); 801 | return OutString.toString(); 802 | } 803 | 804 | //ld *********************** 805 | Match=ld.matcher(InString); 806 | if(Match.find()){ 807 | System.out.println("ld Yes!"); 808 | OutString.append("000000000010"); 809 | String G1=Match.group(2); 810 | if (G1.equals("global")) 811 | OutString.append("1010"); 812 | if (G1.equals("shared")) 813 | OutString.append("1011"); 814 | if (G1.equals("local")) 815 | OutString.append("1100"); 816 | if (G1.equals("const")) 817 | OutString.append("1101"); 818 | return OutString.toString(); 819 | } 820 | 821 | //st ******************* 822 | Match=st.matcher(InString); 823 | if(Match.find()){ 824 | System.out.println("st Yes!"); 825 | OutString.append("00000000001"); 826 | String G1=Match.group(2); 827 | if (G1.equals("global")) 828 | OutString.append("01110"); 829 | if (G1.equals("shared")) 830 | OutString.append("01111"); 831 | if (G1.equals("local")) 832 | OutString.append("10000"); 833 | if (G1.equals("const")) 834 | OutString.append("10001"); 835 | return OutString.toString(); 836 | } 837 | 838 | //bra ********************* 839 | Match=bra.matcher(InString); 840 | if(Match.find()){ 841 | System.out.println("bra Yes!"); 842 | OutString.append("0000000000110010"); 843 | return OutString.toString(); 844 | } 845 | 846 | return "XD"; 847 | 848 | 849 | 850 | 851 | } 852 | } 853 | --------------------------------------------------------------------------------