summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Asm.py17
-rw-r--r--AsmLine.py17
-rw-r--r--AsmParser.py17
-rw-r--r--Function.py15
-rw-r--r--LICENSE19
-rw-r--r--LinkedNode.py23
-rw-r--r--NamedId.py15
-rw-r--r--Registers.py19
-rw-r--r--Variables.py19
-rwxr-xr-xpp2cc.py43
10 files changed, 89 insertions, 115 deletions
diff --git a/Asm.py b/Asm.py
index 018b4de..55baab1 100644
--- a/Asm.py
+++ b/Asm.py
@@ -1,22 +1,17 @@
#!/usr/bin/env python
"""Compiles C into assembly for the practicum processor (PP2)
-All rights reserved, you may not redistribute or use this program without prior
-permission from Peter Wu or Xander Houtman. Use of this program is entirely
-your own risk. In no circumstances can the authors of this program be held
-responsible for any damage including, but not limited to, financial damage or
-data loss. Modification of this program is not allowed without prior
-permission. The generated output (assembly and messages) are not subject to
-this license.
+Copyright (C) 2011-2014 Peter Wu <lekensteyn@gmail.com>
+Licensed under the MIT license <http://opensource.org/licenses/MIT>.
"""
__author__ = "Peter Wu"
-__copyright__ = "Copyright 2011, Peter Wu"
+__copyright__ = "Copyright (C) 2011-2014 Peter Wu"
__credits__ = ["Peter Wu"]
-__license__ = "Proprietary"
+__license__ = "MIT"
__version__ = "1.0"
__maintainer__ = "Peter Wu"
-__email__ = "uwretep@gmail.com"
+__email__ = "lekensteyn@gmail.com"
import re
@@ -87,7 +82,7 @@ class Asm(object):
return label[0].strip(": ")
def noop(self, label, register="R0"):
"""Returns a labelled no operation operator
-
+
Note that the Zero, Negative and oVerflow flags are modified
"""
return self.binary_op("LOAD", register, register, label) + " ; NOOP"
diff --git a/AsmLine.py b/AsmLine.py
index fc54cbe..9016321 100644
--- a/AsmLine.py
+++ b/AsmLine.py
@@ -1,22 +1,17 @@
#!/usr/bin/env python
"""Compiles C into assembly for the practicum processor (PP2)
-All rights reserved, you may not redistribute or use this program without prior
-permission from Peter Wu or Xander Houtman. Use of this program is entirely
-your own risk. In no circumstances can the authors of this program be held
-responsible for any damage including, but not limited to, financial damage or
-data loss. Modification of this program is not allowed without prior
-permission. The generated output (assembly and messages) are not subject to
-this license.
+Copyright (C) 2011-2014 Peter Wu <lekensteyn@gmail.com>
+Licensed under the MIT license <http://opensource.org/licenses/MIT>.
"""
__author__ = "Peter Wu"
-__copyright__ = "Copyright 2011, Peter Wu"
+__copyright__ = "Copyright (C) 2011-2014 Peter Wu"
__credits__ = ["Peter Wu"]
-__license__ = "Proprietary"
+__license__ = "MIT"
__version__ = "1.0"
__maintainer__ = "Peter Wu"
-__email__ = "uwretep@gmail.com"
+__email__ = "lekensteyn@gmail.com"
import re
from Asm import Asm
@@ -48,7 +43,7 @@ class AsmLine(object):
parts = self.re_whitespace.split(line, 1)
self.instruction = parts[0]
-
+
if self.instruction in Asm.operators_binary:
# a label for sure
reg, operand = self.re_whitespace.split(parts[1], 1)
diff --git a/AsmParser.py b/AsmParser.py
index 13b41b8..c2d0921 100644
--- a/AsmParser.py
+++ b/AsmParser.py
@@ -1,22 +1,17 @@
#!/usr/bin/env python
"""Compiles C into assembly for the practicum processor (PP2)
-All rights reserved, you may not redistribute or use this program without prior
-permission from Peter Wu or Xander Houtman. Use of this program is entirely
-your own risk. In no circumstances can the authors of this program be held
-responsible for any damage including, but not limited to, financial damage or
-data loss. Modification of this program is not allowed without prior
-permission. The generated output (assembly and messages) are not subject to
-this license.
+Copyright (C) 2011-2014 Peter Wu <lekensteyn@gmail.com>
+Licensed under the MIT license <http://opensource.org/licenses/MIT>.
"""
__author__ = "Peter Wu"
-__copyright__ = "Copyright 2011, Peter Wu"
+__copyright__ = "Copyright (C) 2011-2014 Peter Wu"
__credits__ = ["Peter Wu"]
-__license__ = "Proprietary"
+__license__ = "MIT"
__version__ = "1.0"
__maintainer__ = "Peter Wu"
-__email__ = "uwretep@gmail.com"
+__email__ = "lekensteyn@gmail.com"
from AsmLine import AsmLine
from NamedId import NamedId
@@ -75,7 +70,7 @@ class AsmParser(object):
cmd, opts = re.split("\s+", line + " ", 1)
cmd = cmd[1:]
opts = opts.strip()
-
+
if cmd == "CODE":
self.in_section = "CODE"
elif cmd == "DATA":
diff --git a/Function.py b/Function.py
index 6be2bfe..3d8d59c 100644
--- a/Function.py
+++ b/Function.py
@@ -1,22 +1,17 @@
#!/usr/bin/env python
"""Compiles C into assembly for the practicum processor (PP2)
-All rights reserved, you may not redistribute or use this program without prior
-permission from Peter Wu or Xander Houtman. Use of this program is entirely
-your own risk. In no circumstances can the authors of this program be held
-responsible for any damage including, but not limited to, financial damage or
-data loss. Modification of this program is not allowed without prior
-permission. The generated output (assembly and messages) are not subject to
-this license.
+Copyright (C) 2011-2014 Peter Wu <lekensteyn@gmail.com>
+Licensed under the MIT license <http://opensource.org/licenses/MIT>.
"""
__author__ = "Peter Wu"
-__copyright__ = "Copyright 2011, Peter Wu"
+__copyright__ = "Copyright (C) 2011-2014 Peter Wu"
__credits__ = ["Peter Wu"]
-__license__ = "Proprietary"
+__license__ = "MIT"
__version__ = "1.0"
__maintainer__ = "Peter Wu"
-__email__ = "uwretep@gmail.com"
+__email__ = "lekensteyn@gmail.com"
class Function(object):
def __init__(self, decl_node, is_static=False, uniq_provider=None):
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d5033b6
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2011-2014 Peter Wu <lekensteyn@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
+OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/LinkedNode.py b/LinkedNode.py
index b24812a..61ffa74 100644
--- a/LinkedNode.py
+++ b/LinkedNode.py
@@ -1,28 +1,23 @@
#!/usr/bin/env python
"""Compiles C into assembly for the practicum processor (PP2)
-All rights reserved, you may not redistribute or use this program without prior
-permission from Peter Wu or Xander Houtman. Use of this program is entirely
-your own risk. In no circumstances can the authors of this program be held
-responsible for any damage including, but not limited to, financial damage or
-data loss. Modification of this program is not allowed without prior
-permission. The generated output (assembly and messages) are not subject to
-this license.
+Copyright (C) 2011-2014 Peter Wu <lekensteyn@gmail.com>
+Licensed under the MIT license <http://opensource.org/licenses/MIT>.
"""
__author__ = "Peter Wu"
-__copyright__ = "Copyright 2011, Peter Wu"
+__copyright__ = "Copyright (C) 2011-2014 Peter Wu"
__credits__ = ["Peter Wu"]
-__license__ = "Proprietary"
+__license__ = "MIT"
__version__ = "1.0"
__maintainer__ = "Peter Wu"
-__email__ = "uwretep@gmail.com"
+__email__ = "lekensteyn@gmail.com"
class LinkedNode(object):
"""Stores nodes with a reference to the parent"""
def __init__(self, node, parent=None, level_increment=False):
"""Holds properties for a node
-
+
Keyword arguments:
node -- a Node object which is an object from the c_ast class
parent -- a parent LinkedNode object
@@ -109,14 +104,14 @@ class LinkedNode(object):
return "Unknown"
def setBreak(self, break_label):
"""Marks this node as a loop or switch by setting the label for break
-
+
Keywords arguments:
break_label -- The label to continue when using the break keyword
"""
self.break_label = break_label
def setContinue(self, continue_label):
"""Marks this node as a loop by setting the label for continue
-
+
Keywords arguments:
continue_label -- The label to continue when using the continue keyword
"""
@@ -138,7 +133,7 @@ class LinkedNode(object):
return None
def setLabel(self, label_name, label_asm):
"""Sets the label for this node
-
+
Keyword arguments:
label_name -- The label name as can be used in C
label_asm -- The label as it appears in assembly
diff --git a/NamedId.py b/NamedId.py
index cb3091b..68b0d60 100644
--- a/NamedId.py
+++ b/NamedId.py
@@ -1,22 +1,17 @@
#!/usr/bin/env python
"""Compiles C into assembly for the practicum processor (PP2)
-All rights reserved, you may not redistribute or use this program without prior
-permission from Peter Wu or Xander Houtman. Use of this program is entirely
-your own risk. In no circumstances can the authors of this program be held
-responsible for any damage including, but not limited to, financial damage or
-data loss. Modification of this program is not allowed without prior
-permission. The generated output (assembly and messages) are not subject to
-this license.
+Copyright (C) 2011-2014 Peter Wu <lekensteyn@gmail.com>
+Licensed under the MIT license <http://opensource.org/licenses/MIT>.
"""
__author__ = "Peter Wu"
-__copyright__ = "Copyright 2011, Peter Wu"
+__copyright__ = "Copyright (C) 2011-2014 Peter Wu"
__credits__ = ["Peter Wu"]
-__license__ = "Proprietary"
+__license__ = "MIT"
__version__ = "1.0"
__maintainer__ = "Peter Wu"
-__email__ = "uwretep@gmail.com"
+__email__ = "lekensteyn@gmail.com"
class NamedId(object):
def __init__(self, name):
diff --git a/Registers.py b/Registers.py
index 13149fb..3784f96 100644
--- a/Registers.py
+++ b/Registers.py
@@ -1,28 +1,23 @@
#!/usr/bin/env python
"""Compiles C into assembly for the practicum processor (PP2)
-All rights reserved, you may not redistribute or use this program without prior
-permission from Peter Wu or Xander Houtman. Use of this program is entirely
-your own risk. In no circumstances can the authors of this program be held
-responsible for any damage including, but not limited to, financial damage or
-data loss. Modification of this program is not allowed without prior
-permission. The generated output (assembly and messages) are not subject to
-this license.
+Copyright (C) 2011-2014 Peter Wu <lekensteyn@gmail.com>
+Licensed under the MIT license <http://opensource.org/licenses/MIT>.
"""
import re
__author__ = "Peter Wu"
-__copyright__ = "Copyright 2011, Peter Wu"
+__copyright__ = "Copyright (C) 2011-2014 Peter Wu"
__credits__ = ["Peter Wu"]
-__license__ = "Proprietary"
+__license__ = "MIT"
__version__ = "1.0"
__maintainer__ = "Peter Wu"
-__email__ = "uwretep@gmail.com"
+__email__ = "lekensteyn@gmail.com"
class Registers(object):
"""Register related functions
-
+
Some functions were supposed to optimize things (alloc and free), but it's
not implemented
"""
@@ -131,7 +126,7 @@ class Registers(object):
return None
def is_register_changed(self, line, register):
"""Returns True if the register is possibly modified in the line
-
+
Keyword arguments:
line -- The instruction line to be analyzed
register -- The register to be looked for in the line
diff --git a/Variables.py b/Variables.py
index 26de704..6656e82 100644
--- a/Variables.py
+++ b/Variables.py
@@ -1,27 +1,22 @@
#!/usr/bin/env python
"""Compiles C into assembly for the practicum processor (PP2)
-All rights reserved, you may not redistribute or use this program without prior
-permission from Peter Wu or Xander Houtman. Use of this program is entirely
-your own risk. In no circumstances can the authors of this program be held
-responsible for any damage including, but not limited to, financial damage or
-data loss. Modification of this program is not allowed without prior
-permission. The generated output (assembly and messages) are not subject to
-this license.
+Copyright (C) 2011-2014 Peter Wu <lekensteyn@gmail.com>
+Licensed under the MIT license <http://opensource.org/licenses/MIT>.
"""
__author__ = "Peter Wu"
-__copyright__ = "Copyright 2011, Peter Wu"
+__copyright__ = "Copyright (C) 2011-2014 Peter Wu"
__credits__ = ["Peter Wu"]
-__license__ = "Proprietary"
+__license__ = "MIT"
__version__ = "1.0"
__maintainer__ = "Peter Wu"
-__email__ = "uwretep@gmail.com"
+__email__ = "lekensteyn@gmail.com"
class Variables(object):
def __init__(self, parent_variables):
"""A scope for holding variable names
-
+
Keywords arguments:
parent_variables -- the parent Variables object. If None, it's a global
variable scope
@@ -79,7 +74,7 @@ class Variables(object):
class GlobalVariables(Variables):
def __init__(self, defined_names):
"""A scope for holding variable names
-
+
Keywords arguments:
defined_names -- A dictionary holding identifiers which are already
defined in assembly
diff --git a/pp2cc.py b/pp2cc.py
index c2f5029..b154367 100755
--- a/pp2cc.py
+++ b/pp2cc.py
@@ -1,13 +1,8 @@
#!/usr/bin/env python
"""Compiles C into assembly for the practicum processor (PP2)
-All rights reserved, you may not redistribute or use this program without prior
-permission from Peter Wu or Xander Houtman. Use of this program is entirely
-your own risk. In no circumstances can the authors of this program be held
-responsible for any damage including, but not limited to, financial damage or
-data loss. Modification of this program is not allowed without prior
-permission. The generated output (assembly and messages) are not subject to
-this license.
+Copyright (C) 2011-2014 Peter Wu <lekensteyn@gmail.com>
+Licensed under the MIT license <http://opensource.org/licenses/MIT>.
"""
import sys, re, os, operator
@@ -20,12 +15,12 @@ from Variables import Variables, GlobalVariables
from AsmParser import AsmParser
__author__ = "Peter Wu"
-__copyright__ = "Copyright 2011, Peter Wu"
-__credits__ = ["Peter Wu", "Xander Houtman"]
-__license__ = "Proprietary"
+__copyright__ = "Copyright (C) 2011-2014 Peter Wu"
+__credits__ = ["Xander Houtman"]
+__license__ = "MIT"
__version__ = "1.0"
__maintainer__ = "Peter Wu"
-__email__ = "uwretep@gmail.com"
+__email__ = "lekensteyn@gmail.com"
class Logger(object):
def __init__(self):
@@ -270,7 +265,7 @@ class Parse(object):
def parseBinaryLogicalOp(self, linked_node):
"""Returns lines of assembly for a logical OR or AND operation
-
+
ASM for logical OR:
operand1
BEQ fal ; if operand1 is false
@@ -280,7 +275,7 @@ class Parse(object):
BRA end
fal:LOAD R0 0
end:NOOP
-
+
ASM for logical AND:
operand1
BNE tru ; if operand1 is true
@@ -403,7 +398,7 @@ class Parse(object):
return lines
def processShift(self, operator, reg_number, operand_shift, linked_node=None):
"""Returns lines for a shift expression
-
+
Keyword arguments:
operator -- Either >> for right shift or << for left shift
reg_number -- A register Rn containing the number to be shifted
@@ -435,7 +430,7 @@ class Parse(object):
lines.append(self.asm.binary_op("DIV", reg_number, 2))
mask = "%0" + (self.WORDSIZE - 1) * "1"
lines.append(self.asm.binary_op("AND", reg_number, mask))
-
+
# decrease shift count and finish if shift count <= 0
lines.append(self.asm.binary_op("SUB", reg_shift, 1))
lines.append(self.asm.branch_op("BLE", lbl_shift_end))
@@ -528,10 +523,10 @@ class Parse(object):
return lines
def parseUnaryOp(self, linked_node):
"""Returns lines of assembly for unary operators
-
+
Supported operators are logical negation, one's complement (bitwise
NOT), plus and minus
-
+
ASM for logical NOT:
operand
BEQ fal ; if operand is false
@@ -581,14 +576,14 @@ class Parse(object):
return lines
def parseTernaryOp(self, linked_node):
"""Returns lines of ASM for ternary operation cond?expr_true:expr_false
-
+
It looks very similar to an If expect that the return value is important
"""
linked_node.incrementLevel()
node = linked_node.node
lbl_el = self.uniqLbl("el") # else
lbl_end = self.uniqLbl("fi") # endif
-
+
lines = self.parseExpression(node.cond, linked_node)
lines.append(self.asm.branch_op("BEQ", lbl_el))
@@ -618,7 +613,7 @@ class Parse(object):
return lines
def convertInteger(self, value=None, node=None):
"""Returns a string of the value
-
+
For integers, the string returned is a base-10 number modulo WORDSIZE
"""
if value is None:
@@ -828,7 +823,7 @@ class Parse(object):
return lines
def parseFor(self, linked_node):
"""Returns ASM for a for loop
-
+
for (init; cond; next) { body; } is equivalent to:
init; while (cond) { body; next; }
Note that for (;;){} is allowed too which is equivalent to:
@@ -954,7 +949,7 @@ class Parse(object):
return lines
def parseLValue(self, linked_node, register="R0"):
"""Returns lines of ASM for a lvalue type.
-
+
It's assumed that register does not change to another one. If this is
changed in the future, please revisit all uses of it.
"""
@@ -1154,7 +1149,7 @@ class Parse(object):
print("case label does not reduce to an integer constant")
print(e)
raise
-
+
lines_cases.append(self.asm.binary_op("CMP", switch_reg, case_val))
lines_cases.append(self.asm.branch_op("BEQ", lbl_case))
lines_stmts.append(self.asm.noop(lbl_case))
@@ -1486,7 +1481,7 @@ Options:
try:
parse = Parse()
-
+
for filename in settings["input_files"]:
parse.loadFile(filename, use_cpp=settings["use_cpp"],
cpp_args=settings["cpp_args"])