Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix encoding problems #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified src/bit/minisys/minicc/MiniCCCfg.java
Binary file not shown.
4 changes: 2 additions & 2 deletions src/bit/minisys/minicc/MiniCCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public void run(String cFile) throws Exception{
}

private void run(String iFile, String oFile, String path) throws IOException{
//Runtime rt = Runtime.getRuntime();//鏍煎紡锛歟xe鍚� 杈撳叆鏂囦欢 杈撳嚭鏂囦欢
//Runtime rt = Runtime.getRuntime();//格式:exe名 输入文件 输出文件
ProcessBuilder pb = new ProcessBuilder(path, iFile, oFile);

pb.redirectErrorStream(true);
Expand All @@ -295,7 +295,7 @@ private void run(String iFile, String oFile, String path) throws IOException{
return;
}
private void runPy(String iFile, String oFile, String path) throws IOException{
PythonInterpreter pyi = new PythonInterpreter();//鏍煎紡锛歅ython鑴氭湰鍚� 杈撳叆鏂囦欢 杈撳嚭鏂囦欢
PythonInterpreter pyi = new PythonInterpreter();//格式:Python脚本名 输入文件 输出文件
// DIRTY HACK! Apparently the retard who wrote this before don't know how to google.
pyi.exec("import sys\nsys.argv = ['<string>', \"" + MiniCCUtil.escape(iFile) + "\", \"" + MiniCCUtil.escape(oFile) + "\"]");
pyi.setOut(System.out);
Expand Down
16 changes: 8 additions & 8 deletions src/bit/minisys/minicc/icgen/ExampleICBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import java.util.Map;

import bit.minisys.minicc.parser.ast.*;
// һ����������ֻʵ���˼ӷ�
// 一个简单样例,只实现了加法
public class ExampleICBuilder implements ASTVisitor{

private Map<ASTNode, ASTNode> map; // ʹ��map�洢�ӽڵ�ķ���ֵ��key��Ӧ�ӽڵ㣬value��Ӧ����ֵ��valueĿǰ������ASTIdentifier,ASTIntegerConstant,TemportaryValue...
private List<Quat> quats; // ���ɵ���Ԫʽ�б�
private Integer tmpId; // ��ʱ�������
private Map<ASTNode, ASTNode> map; // 使用map存储子节点的返回值,key对应子节点,value对应返回值,value目前类别包括ASTIdentifier,ASTIntegerConstant,TemportaryValue...
private List<Quat> quats; // 生成的四元式列表
private Integer tmpId; // 临时变量编号
public ExampleICBuilder() {
map = new HashMap<ASTNode, ASTNode>();
quats = new LinkedList<Quat>();
Expand Down Expand Up @@ -73,11 +73,11 @@ public void visit(ASTBinaryExpression binaryExpression) throws Exception {
ASTNode opnd2 = null;

if (op.equals("=")) {
// ��ֵ����
// ��ȡ����ֵ�Ķ���res
// 赋值操作
// 获取被赋值的对象res
visit(binaryExpression.expr1);
res = map.get(binaryExpression.expr1);
// �ж�Դ����������, Ϊ�˱������a = b + c; ����������Ԫʽ��tmp1 = b + c; a = tmp1;�������Ҳ�����ñ�ķ������
// 判断源操作数类型, 为了避免出现a = b + c; 生成两个四元式:tmp1 = b + c; a = tmp1;的情况。也可以用别的方法解决
if (binaryExpression.expr2 instanceof ASTIdentifier) {
opnd1 = binaryExpression.expr2;
}else if(binaryExpression.expr2 instanceof ASTIntegerConstant) {
Expand All @@ -94,7 +94,7 @@ public void visit(ASTBinaryExpression binaryExpression) throws Exception {
}

}else if (op.equals("+")) {
// �ӷ�����������洢���м����
// 加法操作,结果存储到中间变量
res = new TemporaryValue(++tmpId);
visit(binaryExpression.expr1);
opnd1 = map.get(binaryExpression.expr1);
Expand Down
2 changes: 1 addition & 1 deletion src/bit/minisys/minicc/icgen/Quat.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import bit.minisys.minicc.parser.ast.ASTNode;

// ��Ԫʽ��ʽ���м����, �������ͷ���ֵ�Ľṹֱ��ʹ��AST�ڵ㣬Ҳ�����Զ���IR�ڵ�
// 四元式形式的中间代码, 操作数和返回值的结构直接使用AST节点,也可以自定义IR节点
public class Quat {
private String op;
private ASTNode res;
Expand Down
2 changes: 1 addition & 1 deletion src/bit/minisys/minicc/icgen/TemporaryValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import bit.minisys.minicc.parser.ast.ASTNode;
import bit.minisys.minicc.parser.ast.ASTVisitor;

// ��ʱ����
// 临时变量
public class TemporaryValue extends ASTNode{

private Integer id;
Expand Down
2 changes: 1 addition & 1 deletion src/bit/minisys/minicc/parser/ast/ASTCompilationUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@JsonTypeName("Program")
public class ASTCompilationUnit extends ASTNode{

public List<ASTNode> items; // item ֻ����declaration �� functionDefine
public List<ASTNode> items; // item declaration functionDefine


public ASTCompilationUnit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@JsonTypeName("CompoundStatement")
public class ASTCompoundStatement extends ASTStatement{
public List<ASTNode> blockItems; // ����ֻ���� ���� ���� �������
public List<ASTNode> blockItems;

public ASTCompoundStatement() {
super("CompoundStatement");
Expand Down
1 change: 0 additions & 1 deletion src/bit/minisys/minicc/parser/ast/ASTIdentifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

//import bit.minisys.minicc.symbol.Symbol;

// ��ʶ��
@JsonTypeName("Identifier")
public class ASTIdentifier extends ASTExpression{
public String value;
Expand Down
1 change: 0 additions & 1 deletion src/bit/minisys/minicc/parser/ast/ASTIntegerConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.annotation.JsonTypeName;

// ���ͳ���
@JsonTypeName("IntegerConstant")
public class ASTIntegerConstant extends ASTExpression{
public Integer value;
Expand Down
1 change: 0 additions & 1 deletion src/bit/minisys/minicc/parser/ast/ASTUnaryExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.annotation.JsonTypeName;

// һԪ���ʽ�ڵ�
@JsonTypeName("UnaryExpression")
public class ASTUnaryExpression extends ASTExpression{
public ASTToken op;
Expand Down
10 changes: 5 additions & 5 deletions test/nc_tests/3_PerfectNumber.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
void perfectNumber(int n){
int p[80]; //淇濆瓨鍒嗚В鐨勫洜瀛�
int p[80]; //保存分解的因子
int i,num,count,s,c = 0;
for(num = 2; num < n; num++)
{
count = 0;
s = num;
for(i = 1; i < num/2+1; i++) //寰幆澶勭悊姣忎釜鏁�
for(i = 1; i < num/2+1; i++) //循环处理每个数
{
if(num % i == 0) //鑳借i鏁撮櫎
if(num % i == 0) //能被i整除
{
p[count++] = i; //淇濆瓨鍥犲瓙锛岃璁℃暟鍣╟ount澧炲姞1
s -= i; //鍑忓幓涓�涓洜瀛�
p[count++] = i; //保存因子,让计数器count增加1
s -= i; //减去一个因子
}
}
if( 0 == s)
Expand Down
6 changes: 3 additions & 3 deletions test/nc_tests/4_CounterClockwiseRotationArray4_4.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ void array4_4(){
for(j = 0; j < 4; j++)
{
A[i][j] = Mars_GetInt();
B[3-j][i] = A[i][j]; //鏃嬭浆90搴﹁祴鍊�
B[3-j][i] = A[i][j]; //旋转90度赋值
}
Mars_PrintStr("Array A:\n"); //杈撳嚭鐭╅樀A
Mars_PrintStr("Array A:\n"); //输出矩阵A
for( i = 0; i < 4; i++)
{
for(j = 0 ; j < 4; j++)
Expand All @@ -17,7 +17,7 @@ void array4_4(){
}
Mars_PrintStr("\n");
}
Mars_PrintStr("Array B:\n"); //杈撳嚭鐭╅樀B
Mars_PrintStr("Array B:\n"); //输出矩阵B
for( i = 0; i < 4; i++)
{
for(j = 0 ; j < 4; j++)
Expand Down
2 changes: 1 addition & 1 deletion test/nc_tests/6_QuickSort.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
int a[10] = {1,4,7,2,3,0,8,5,9,6}; // BitMINICC灏氭湭瀹炵幇鎸囬拡锛岄噰鐢ㄥ叏灞�鏁扮粍
int a[10] = {1,4,7,2,3,0,8,5,9,6}; // BitMINICC尚未实现指针,采用全局数组
void quick(int start,int end);
int partion(int low,int high);
void quickSort(int len){
Expand Down