diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-12 11:08:03 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-12 11:08:03 +0000 |
commit | fd25256a37696de23d8f6c99827a97b63733845d (patch) | |
tree | dbfc5f680dcdf78ac62f0d7f1d6bb09271e8a6b2 /c_compiler/src/expression.cpp | |
parent | de1f50c2bfa7dfc3b758a0cb89c856534c4ab3a1 (diff) | |
download | Compiler-fd25256a37696de23d8f6c99827a97b63733845d.tar.gz Compiler-fd25256a37696de23d8f6c99827a97b63733845d.zip |
Have to improve reg allocation
Diffstat (limited to 'c_compiler/src/expression.cpp')
-rw-r--r-- | c_compiler/src/expression.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/c_compiler/src/expression.cpp b/c_compiler/src/expression.cpp index 6c1ba97..dea282f 100644 --- a/c_compiler/src/expression.cpp +++ b/c_compiler/src/expression.cpp @@ -69,7 +69,7 @@ VariableStackBindings AdditiveExpression::printasm(VariableStackBindings binding // currently using signed and sub because I only have signed numbers implemented // must update this as I add more types if(operation == "+") - std::cout << "\tadd\t$2,$2,$3" << std::endl; + std::cout << "\tadd\t$2,$3,$2" << std::endl; else if(operation == "-") std::cout << "\tsub\t$2,$3,$2" << std::endl; else @@ -79,6 +79,37 @@ VariableStackBindings AdditiveExpression::printasm(VariableStackBindings binding } +// Multiplicative Expression definition + + +MultiplicativeExpression::MultiplicativeExpression(Expression* _lhs, const std::string& _operation, Expression* _rhs) + : OperationExpression(_lhs, _rhs), operation(_operation) +{} + +VariableStackBindings MultiplicativeExpression::printasm(VariableStackBindings bindings) const +{ + lhs->printasm(bindings); + + std::cout << "\tmove\t$3,$2" << std::endl; + + rhs->printasm(bindings); + + // then perform the right operation + if(operation == "*") + std::cout << "\tmul\t$2,$3,$2" << std::endl; + else if(operation == "/" || operation == "%") { + std::cout << "\tdiv\t$3,$2" << std::endl; + if(operation == "/") + std::cout << "\tmflo\t$2" << std::endl; + else + std::cout << "\tmfhi\t$2" << std::endl; + } else + std::cerr << "Don't recognize symbol '" << operation << "'" << std::endl; + + return bindings; +} + + // Identifier definition Identifier::Identifier(const std::string& id) |