Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history


merge
  • Loading branch information
jiweixing committed Apr 9, 2019
2 parents 61f9344 + 37310d4 commit c459462
Show file tree
Hide file tree
Showing 45 changed files with 974 additions and 41 deletions.
25 changes: 25 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/jdom.jar"/>
<classpathentry kind="lib" path="lib/codegen.jar"/>
<classpathentry kind="lib" path="lib/icgen.jar"/>
<classpathentry kind="lib" path="lib/opt.jar"/>
<classpathentry kind="lib" path="lib/parser.jar"/>
<classpathentry kind="lib" path="lib/pp.jar"/>
<classpathentry kind="lib" path="lib/scanner.jar"/>
<classpathentry kind="lib" path="lib/semantic.jar"/>
<classpathentry kind="lib" path="lib/simulator.jar"/>
<classpathentry kind="lib" path="lib/util.jar"/>
<classpathentry kind="lib" path="lib/jython.jar"/>
<classpathentry kind="lib" path="lib/antlr-4.6-complete.jar"/>
<classpathentry kind="lib" path="lib/Mars4_5.jar"/>

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>

<classpathentry kind="output" path="bin"/>
</classpath>
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>BIT-MiniCC-Clean</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
4 changes: 4 additions & 0 deletions .settings/org.eclipse.wst.common.project.facet.core.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.7"/>
</faceted-project>
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# bit-minic-compiler
A C compiler framework in Java

Weixing Ji ([email protected]) <br>

Contributor:<br>
Yu Hao, 2017<br>
Shuofu Ning, 2016-2017<br>
YiFan Wu, 2015-2016
6 changes: 5 additions & 1 deletion bit-minic-clean/src/bit/minisys/minicc/BITMiniCC.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ public class BITMiniCC {
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {

public static void main(String[] args) throws Exception {
//System.out.println(System.getProperty("user.dir"));

if(args.length < 1){
usage();
return;
Expand All @@ -20,6 +23,7 @@ public static void main(String[] args) throws Exception {

MiniCCompiler cc = new MiniCCompiler();
System.out.println("Start to compile ...");
// System.out.println(System.getProperty("user.dir"));
cc.run(file);
System.out.println("Compiling completed!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,5 @@
import org.xml.sax.SAXException;

public interface IMiniCCCodeGen {
/*
* @return String the path of the output file
* @param iFile input file path
* @param type architecture
*/
public String run(String iFile, String type) throws Exception;
public void run(String iFile, String oFile) throws IOException, ParserConfigurationException, SAXException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
import java.io.IOException;

public interface IMiniCCICGen {
/*
* @return String the path of the output file
* @param iFile input file path
*/
public String run(String iFile) throws Exception;
public void run(String iFile, String oFile) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
import java.io.IOException;

public interface IMiniCCOptimizer {
/*
* @return String the path of the output file
* @param iFile input file path
*/
public String run(String iFile) throws Exception;
public void run(String iFile, String oFile) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,5 @@
import org.xml.sax.SAXException;

public interface IMiniCCParser {
/*
* @return String the path of the output file
* @param iFile input file path
*/
public String run(String iFile) throws Exception;
public void run(String iFile, String oFile) throws ParserConfigurationException, SAXException, IOException;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package bit.minisys.minicc.pp;

public interface IMiniCCPreProcessor {
/*
* @return String the path of the output file
* @param iFile input file path
*/
public String run(String iFile) throws Exception;
public void run(String iFile, String oFile);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
import java.io.IOException;

public interface IMiniCCScanner {
/*
* @return String the path of the output file
* @param iFile input file path
*/
public String run(String iFile) throws Exception;
public void run(String iFile, String oFile) throws IOException, Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
import java.io.IOException;

public interface IMiniCCSemantic {
/*
* @return String the path of the output file
* @param iFile input file path
*/
public String run(String iFile) throws Exception;
public void run(String iFile, String oFile) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package bit.minisys.minicc.simulator;

public interface IMIPSSimulator {
/*
* @param input input file path
*/
public void run(String input) throws Exception;
public void run(String iFile);
}
16 changes: 16 additions & 0 deletions config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<config name="config.xml">
<phases>
<phase>
<phase skip="false" type="java" path="" name="pp" />
<phase skip="false" type="java" path="" name="scanning" />
<phase skip="false" type="java" path="" name="parsing" />
<phase skip="false" type="java" path="" name="semantic" />
<phase skip="true" type="java" path="" name="icgen" />
<phase skip="true" type="java" path="" name="optimizing" />
<phase skip="false" type="java" path="bit.minisys.minicc.codegen.MiniCCMIPSCodeGen" name="codegen" />
<phase skip="false" type="java" path="" name="simulating" />
</phase>
</phases>
</config>

Binary file added doc/BITMiniCC.pdf
Binary file not shown.
17 changes: 17 additions & 0 deletions input/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#define NUM 4

/* this is a demo program */

int main(){
int a;
int b;

a = MARS_SCANF_I();
b = MARS_SCANF_I();

a = a + b;

MARS_PRINTF_I(a);

return 0;
}
99 changes: 99 additions & 0 deletions input/test.code.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

# Code generated from MiniCCompiler at
# input file:D:\projects\bit-minicc\bit-minic-clean\input\test.ic2.xml
# Please do not change this file!

.data
.text
__init:
# setup the stack
lui $sp, 0x8000
addi $sp, $sp, 0x0000
addiu $sp, $sp, -1024

# redirect to main function
jal __main

# make system call to terminate the program
li $v0, 10
syscall


__MARS_SCANF_I:
li $v0, 5
syscall
move $t0, $v0
jr $ra


__MARS_PRINTF_I:
li $v0, 1
syscall
jr $ra

__main:

# allocate stack frame for the callee
addiu $fp, $sp, 0
addiu $sp, $sp, -136
sw $ra, 0($fp)

sw $a0, 8($fp)
sw $a1, 12($fp)
sw $a2, 16($fp)
sw $a3, 20($fp)


jal __MARS_SCANF_I

lw $ra, 0($fp)

lw $a0, 8($sp)
lw $a1, 12($sp)
lw $a2, 16($sp)
lw $a3, 20($sp)

move $t9, $v0
sw $ra, 0($fp)

sw $a0, 8($fp)
sw $a1, 12($fp)
sw $a2, 16($fp)
sw $a3, 20($fp)


jal __MARS_SCANF_I

lw $ra, 0($fp)

lw $a0, 8($sp)
lw $a1, 12($sp)
lw $a2, 16($sp)
lw $a3, 20($sp)

move $t8, $v0
add $t9, $t9, $t8
sw $ra, 0($fp)

sw $a0, 8($fp)
sw $a1, 12($fp)
sw $a2, 16($fp)
sw $a3, 20($fp)

move $a0, $25

jal __MARS_PRINTF_I

lw $ra, 0($fp)

lw $a0, 8($sp)
lw $a1, 12($sp)
lw $a2, 16($sp)
lw $a3, 20($sp)

addi $v0, $v0, 0
addiu $sp, $fp, 0
addiu $fp, $fp, -136
jr $ra


7 changes: 7 additions & 0 deletions input/test.ic.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<IC name="test.ic.xml">
<functions>
<function />
</functions>
</IC>

7 changes: 7 additions & 0 deletions input/test.ic2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<IC name="test.ic.xml">
<functions>
<function />
</functions>
</IC>

14 changes: 14 additions & 0 deletions input/test.pp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

int main ( ) {
int a ;
int b ;

a = MARS_SCANF_I ( ) ;
b = MARS_SCANF_I ( ) ;

a = a + b ;

MARS_PRINTF_I ( a ) ;

return 0 ;
}
Loading

0 comments on commit c459462

Please sign in to comment.