This commit is contained in:
w-mj
2021-03-01 13:52:41 +08:00
parent 0458775daa
commit 2b8d508f2c
5 changed files with 32 additions and 37 deletions
-3
View File
@@ -1,3 +0,0 @@
Manifest-Version: 1.0
Main-Class: com.compiler.Main
Class-Path: lib/commons-lang3-3.0.jar lib/asm-9.1.jar
+3 -3
View File
@@ -1,10 +1,10 @@
# CJCompiler
把类C语法编译成Java字节码。
把类C语法编译成JVM字节码。
## 构建方式
1. python build.py
2. java -jar ./CJCompiler.jar
1. ant
2. java -jar out/CJCompiler.jar
3. java lexer
-31
View File
@@ -1,31 +0,0 @@
import os
import shutil
proj_dir = os.getcwd()
src_dir = os.path.join(proj_dir, "src")
lib_dir = os.path.join(proj_dir, "lib")
out_dir = os.path.join(proj_dir, "out")
res_dir = os.path.join(proj_dir, "res")
jar = os.path.join(proj_dir, "CJCompiler.jar")
MANIFEST = os.path.join(proj_dir, "MANIFEST.MF")
src_files = []
for path, dir_names, file_names in os.walk(src_dir):
file_paths = [os.path.join(path, x) for x in file_names]
src_files += file_paths
lib_files = [os.path.join(lib_dir, x) for x in os.listdir(lib_dir)]
shutil.rmtree(out_dir, True)
cmd = f"javac -d {out_dir} -encoding utf-8 -cp .;{';'.join(lib_files)} -sourcepath {src_dir} {' '.join(src_files)}"
print(cmd)
os.system(cmd)
shutil.copytree(res_dir, os.path.join(out_dir, "res"))
shutil.copytree(lib_dir, os.path.join(out_dir, "lib"))
cmd = f"cd {out_dir} && jar -cvfm {jar} {MANIFEST} *"
print(cmd)
os.system(cmd)
+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<project name="CJCompiler" default="jar" basedir="">
<property name="lib.dir" value="lib"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<target name="clean">
<delete dir="out" />
<delete file="lexer.class" />
</target>
<target name="build">
<mkdir dir="out/classes"/>
<javac srcdir="src" destdir="out/classes" encoding="utf-8" classpathref="classpath" includeantruntime="false" fork="true">
<compilerarg value="-J-Duser.language=en"/>
</javac>
</target>
<target name="jar" depends="build">
<jar destfile="out/CJCompiler.jar" basedir="out/classes">
<manifest>
<attribute name="Main-Class" value="com.compiler.Main"/>
</manifest>
<zipgroupfileset dir="lib" includes="*.jar"/>
</jar>
</target>
</project>
+1
View File
@@ -13,6 +13,7 @@ while(a<=9){
print mul;
print a;
c = a * b;
print eq;
print c;
print blank;