Skip to content

C to Capua ASM compiler#34

Open
Chris LeBlanc (kommisar5150) wants to merge 10 commits into
cse-cst:masterfrom
kommisar5150:master
Open

C to Capua ASM compiler#34
Chris LeBlanc (kommisar5150) wants to merge 10 commits into
cse-cst:masterfrom
kommisar5150:master

Conversation

@kommisar5150
Copy link
Copy Markdown
Contributor

First draft of a compiler that converts C code to .casm. Functionality is documented in the CompilerInfo.md file. Makes use of infix/postfix parsing for math expressions, and a pseudo FSM model to determine expected input.

@cannotparse
Copy link
Copy Markdown
Contributor

Mind adding an example C file to examples to show off all the features?

@pg-cse
Copy link
Copy Markdown
Contributor

pg-cse commented Jul 18, 2018

Currently looking at this. A C implementation of LoneBall could be a cool thing for testing and validation.

Comment thread ToolChain/Compiler/Compiler.py Outdated
currentMethod = "" # String containing the current method being evaluated
expectFlag = 0 # Used to control what input we expect next
mathFormula = "" # Will contain our fully assembled math expressions for variable assignments
memoryLocation = 0x40000000 # Memory location for local variables.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this address should be in a constant somewhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The memory location isn't a constant in this context. It increases every new variable assignment. Perhaps I could have it as a constant, and have another global variable take its initial value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do feel it would be better.

:return:
"""

if self.state == 0:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The various states should be defined in constants with appropriate naming. This would make code easier to read.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

Comment thread ToolChain/Compiler/Compiler.py Outdated
mathFormula = "" # Will contain our fully assembled math expressions for variable assignments
memoryLocation = 0x40000000 # Memory location for local variables.
varList = [] # Contains a list of variable names
varLocation = {} # Contains the memory location for all variables
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I am not done looking/testing this code, I do feel like a relatively large number of these variables don't have to be global to a given object.

"""
Here we expect to read the method's name. Once we reach a space or an opening parentheses, we add the method
to the methodlist along with its data type.
TODO: figure out a way to have the main method printed first in the .casm file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tree structure starting from main would work ;)
It would also deal with the issue of dead code (in the case a full function is not called)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously something would also need to be worked out for libraries in that case.

@cannotparse
Copy link
Copy Markdown
Contributor

Cannotparse (cannotparse) commented Jul 23, 2018

Just read the example C file. Looks like this is really shaping up! Great work Chris LeBlanc (@kommisar5150)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants