1 Star 0 Fork 0

chisuhua/Compilers---C-to-LLVM

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="UTF-8">
	<title>README</title>
	<style>
		body {
			margin-bottom: 50px;
		}
		.list_indent {
			padding-left: 2em;
		}
		code {
			padding-left: 2px;
			padding-right: 2px;
			background: hsl(220, 80%, 90%);
		}
		.implemented {
			font-size: 70%;
			padding-left: 2px;
			padding-right: 2px;
			background: hsl(120, 80%, 90%);
		}
		.planned {
			font-size: 70%;
			padding-left: 2px;
			padding-right: 2px;
			background: hsl(60, 80%, 90%);
		}
	</style>
</head>
<body>
	<h1>Compilers</h1>
	<h4><i>Luuk van Sloun &amp; Atisha Ribeiro</i></h4>
	<br>
	<h3>Project Structure</h3>
	<ul>
		<li><b>Grammar</b></li>
		<span class="list_indent">
			The grammar is specified in <code>C_Grammar.g4</code>.
		</span>
		<li><b>AST</b></li>
		<div class="list_indent">
			There are 2 classes located in <code>AST.py</code>: The <code>AST</code> class and the <code>GrammarListener</code> class.<br/>
			<code>AST</code> is just a node class that has children nodes. Each node stores 3 values:<br/>
			<ul>
				<li><code>name</code>: specifies the node type (e.g. function)</li>
				<li><code>value</code>: specifies the node value (e.g. main)</li>
				<li><code>type</code>: specifies the node type (e.g. int)</li>
			</ul>
			The class also contains a <code>to_dot()</code> function to visualise the AST.<br/>
			<code>GrammarListener</code> contains an AST object and fills it as it traverses the derivation tree generated by ANTLR.<br/>
		</div>
		<li><b>Symbol Table</b></li>
		<div class="list_indent">
			The <code>SymbolTable</code> class is located in <code>SymbolTable.py</code>.<br/>
			It uses DFS to traverse the AST and fill in the symbol table. While traversing, it checks if variables are declared only once and if variables used have been declared previously.
			If these checks fail, an exception is thrown.<br/>
			The class also contains a <code>to_dot()</code> function to visualise the symbol table.<br/>
		</div>
		<li><b>Code Generation</b></li>
		<div class="list_indent">
			The <code>CodeGenerator</code> class is located in <code>CodeGenerator.py</code>.<br/>
			Traverses the AST recursively with DFS and writes the LLVM IR code to a file.
		</div>
	</ul>

	<h3>Features</h3>
	<ul>
		<li><b>Types</b> <span class="implemented">implemented</span></li>
		<li><b>Import</b> <span class="implemented">implemented</span></li>
		<div class="list_indent">
			<code>printf</code> and <code>scanf</code> are declared when <code>#include &ltstdio.h&gt</code> is specified.
		</div>
		<li><b>Reserverd Words</b> <span class="implemented">implemented</span></li>
		<li><b>Local and global variables</b> <span class="implemented">implemented</span></li>
		<li><b>Comments</b> <span class="implemented">implemented</span></li>
		<li><b>Operations</b> <span class="implemented">implemented</span></li>
		<ul>
			<li><b>Unary Operations <code>+</code> and <code>-</code></b> <span class="implemented">implemented</span></li>
			<li><b>Comparison Operators</b> <span class="implemented">implemented</span></li>
		</ul>
		<li><b>Functions</b> <span class="implemented">implemented</span></li>
		<div class="list_indent">
			exception thrown when there is no return in a non-void function, or when there is no main() present in the code.
		</div>
		<li><b>Arrays</b> <span class="implemented">implemented</span></li>
		<li><b>Conversions</b> <span class="implemented">implemented</span></li>
		<div class="list_indent">
			casts implicitly when there is a type mismatch
		</div>
	</ul>

	<h3>Optimisations</h3>
	<ul>
		<li><b>Unreachable/Dead code</b> <span class="implemented">implemented</span></li>
		<div class="list_indent">
			statements that do not change variables (like <code>a + 2;</code>) are also not generated.
		</div>
	</ul>

	<h3>Usage</h3>
	<ul>
		<li><b>Builing</b></li>
		<div class="list_indent">
			To build the C compiler classes type <code>bash build</code>.<br/>
			This will also compile and execute (with <code>lli</code>) an example file <code>c_prog</code>.
		</div>
		<li><b>Testing</b></li>
		<ul>
		<li>Working test files</li>
		<div class="list_indent">
			To run the files that showcase the implemented features, type <code>bash test</code>.
		</div>
		<li>Error test files</li>
		<div class="list_indent">
			These files showcase exceptions we have implemented. Since they throw an exception, they have to be executed one by one.
		</div>
		</ul>
	</ul>


</body></html>

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chisuhua/Compilers---C-to-LLVM.git
[email protected]:chisuhua/Compilers---C-to-LLVM.git
chisuhua
Compilers---C-to-LLVM
Compilers---C-to-LLVM
master

搜索帮助