Commit 31745239 authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Updated to not generate names for unnamed globals

parent 6e28ed40
// Copyright 2017 The Australian National University // Copyright 2017 The Australian National University
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#pragma once #pragma once
#include "Visitor.hpp" #include "Visitor.hpp"
...@@ -89,7 +89,7 @@ namespace C ...@@ -89,7 +89,7 @@ namespace C
std::string id = std::to_string(last_global_id++); std::string id = std::to_string(last_global_id++);
std::string id_name = "G("s + id + (name.empty() ? ""s : ", "s + name) + ")"s; std::string id_name = "G("s + id + (name.empty() ? ""s : ", "s + name) + ")"s;
stream << "\t" << "MuID "s + id_name + ";" << std::endl; stream << "\t" << "MuID "s + id_name + ";" << std::endl;
write_line(id_name + " = " + irbuilder + "->gen_sym(" + irbuilder + ", \"@" + (name.empty() ? "__"s + id : name) + "\");"); write_line(id_name + " = " + irbuilder + "->gen_sym(" + irbuilder + ", " + (name.empty() ? "NULL" : "\"@" + name + "\"")+ ");");
return id_name; return id_name;
} }
...@@ -240,7 +240,7 @@ namespace C ...@@ -240,7 +240,7 @@ namespace C
auto fixedtys = accept_list("MuTypeNode", context->fieldTys); auto fixedtys = accept_list("MuTypeNode", context->fieldTys);
auto varty = accept<MuTypeNode>(context->varTy); auto varty = accept<MuTypeNode>(context->varTy);
std::string id; std::string id;
if (declare_inline("struct<"s + list_to_string(fixedtys.content) + " " + varty + ">"s, id)) if (declare_inline("hybrid<"s + list_to_string(fixedtys.content) + " " + varty + ">"s, id))
generate_call(irbuilder + "->new_type_hybrid"s, irbuilder, id, fixedtys.value, fixedtys.size, varty); generate_call(irbuilder + "->new_type_hybrid"s, irbuilder, id, fixedtys.value, fixedtys.size, varty);
current_ids.pop(); current_ids.pop();
return id; return id;
...@@ -495,9 +495,9 @@ namespace C ...@@ -495,9 +495,9 @@ namespace C
if (context->ver) if (context->ver)
current_ids.push(accept<MuID>(context->ver)); // the id of the function version we are constructing current_ids.push(accept<MuID>(context->ver)); // the id of the function version we are constructing
else else
current_ids.push(get_id(::last_name = ::parent_names.top() + ".__"s + std::to_string(last_global_id++), false)); current_ids.push(gen_local());
::parent_names.push(::last_name); // the global name of the function version ::parent_names.push(::parent_names.top() + ".__"s + std::to_string(last_global_id++)); // the global name of the function version
auto bbs = accept_list("MuBBNode", context->body); auto bbs = accept_list("MuBBNode", context->body);
......
...@@ -26,11 +26,11 @@ Translates MuIR in text form and creates a correspondinng boot image, or generat ...@@ -26,11 +26,11 @@ Translates MuIR in text form and creates a correspondinng boot image, or generat
cp -r $antlr4/runtime/Cpp/run/usr/local/lib/* ./lib/ cp -r $antlr4/runtime/Cpp/run/usr/local/lib/* ./lib/
``` ```
* If you want to compile directly (as opposed to output C files) you'll need Mu, place your `libmu*` files in `./lib`, * If you want to compile directly (as opposed to output C files) you'll need Mu, place your `libmu*` files in `./lib`,
also set the environement variable MU_ZEBU to the locatation of the mu-impl-fast source code. also set the environement variable `MU_ZEBU` to the locatation of the mu-impl-fast source code.
## C Code prerequisites ## C Code prerequisites
To run the generated C code you will need: To run the generated C code you will need:
* To link with Mu (make sure that the environment variable MU_ZEBU is set to the locatation of the mu-impl-fast source code) * To link with Mu (make sure that the environment variable `MU_ZEBU` is set to the locatation of the mu-impl-fast source code)
* A C compiler (tested with GCC version 5.4.0, whith the default `-std=gnu11`) * A C compiler (tested with GCC version 5.4.0, whith the default `-std=gnu11`)
## Building ## Building
...@@ -64,7 +64,7 @@ the name can be changed again with another `.bundle` directive. Muc will automat ...@@ -64,7 +64,7 @@ the name can be changed again with another `.bundle` directive. Muc will automat
* A top level declaration may be given a local name, in which case it is prefixed with the name of the bundle followed by a `.`. * A top level declaration may be given a local name, in which case it is prefixed with the name of the bundle followed by a `.`.
(e.g. `.typedef %void = void`, instead of `.typedef @__bundle_1.foo`). (Note: you can give a `.const` a name starting with `%`, however (e.g. `.typedef %void = void`, instead of `.typedef @__bundle_1.foo`). (Note: you can give a `.const` a name starting with `%`, however
when refering it with `%`, if there is a local name more recently defined with a `%` (such as a block paramter) that will have priority. when refering it with `%`, if there is a local name more recently defined with a `%` (such as a block paramter) that will have priority.
* Top level declarations with a global name starting with an '_' are not passed to the whitelist of make bootimage (such as names local to unamed bundles) * Top level declarations with a global name starting with an `_` are not passed to the whitelist of make bootimage (such as names local to unamed bundles)
* You may ommit the `@` or `%` in front of names, where the name `foo` is interpreted according to the following rules: * You may ommit the `@` or `%` in front of names, where the name `foo` is interpreted according to the following rules:
* if the name could be interpreted as a keyword/part of the syntax, it is (e.g. `.global v <void>` creates a new anonymous type with value `void`, it does not refer to `@void`) * if the name could be interpreted as a keyword/part of the syntax, it is (e.g. `.global v <void>` creates a new anonymous type with value `void`, it does not refer to `@void`)
* if the name is used for a 'value' (an operand of an instruction, but not a constant) and `%foo` was declared, then it is interpreted as `%foo` * if the name is used for a 'value' (an operand of an instruction, but not a constant) and `%foo` was declared, then it is interpreted as `%foo`
...@@ -93,7 +93,7 @@ Muc will only check for correct syntax, it is up to you to ensure your input is ...@@ -93,7 +93,7 @@ Muc will only check for correct syntax, it is up to you to ensure your input is
There is a bug in Zebu in that it will not allow you to reference entities declared in another bundle, to overcome this There is a bug in Zebu in that it will not allow you to reference entities declared in another bundle, to overcome this
combine your bundles into 1, e.g. `./muc -r <(cat bundle1.uir bundle2.uir) out`, unfortunently this will change the behaviour combine your bundles into 1, e.g. `./muc -r <(cat bundle1.uir bundle2.uir) out`, unfortunently this will change the behaviour
of how local top level names are interpret, unless you put `.bundle` directives at the start of each bundle file. of how local top level names are interpreted, unless you put `.bundle` directives at the start of each bundle file.
The file mu-fastimpl.h was taken from 'mu/mu-impl-fast' (master branch) and muapi.h from 'mu/mu-spec' they are kept up to date on each commit of mu-tool-compiler. The file mu-fastimpl.h was taken from 'mu/mu-impl-fast' (master branch) and muapi.h from 'mu/mu-spec' they are kept up to date on each commit of mu-tool-compiler.
If they are changed (or Zebu's behaviour or the spec changes with respect to hem), muc may not work correctly. If they are changed (or Zebu's behaviour or the spec changes with respect to hem), muc may not work correctly.
...@@ -105,5 +105,5 @@ In all other cases (except for referencing the result of an instruction or a blo ...@@ -105,5 +105,5 @@ In all other cases (except for referencing the result of an instruction or a blo
When using `-c`, float and double inline constants will be be considered unique (for the purposes of generating inline declarations) if there text is unique, e.g: When using `-c`, float and double inline constants will be be considered unique (for the purposes of generating inline declarations) if there text is unique, e.g:
`%a = FADD <float> <float>1.1f <float>1.10f` will generate two constants, whereas when using `-r` it will only generate one (since 1.1 = 1.10). `%a = FADD <float> <float>1.1f <float>1.10f` will generate two constants, whereas when using `-r` it will only generate one (since 1.1 = 1.10).
Inline declarations will call `gen_sym` with names of the form `@__#` where '#' is a number, this is due to a bug in Zebu were all top-level declarations Bundle names will be generated in the form `@__bundle_#`. (so to be safe never write global names starting with a `__` in your input files).
must have names. In addition bundle names will be generated in the form `@__bundle_#`. (so to be safe never write global names starting with a `__` in your input files).
\ No newline at end of file
// Copyright 2017 The Australian National University // Copyright 2017 The Australian National University
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#pragma once #pragma once
#include "Visitor.hpp" #include "Visitor.hpp"
...@@ -101,8 +101,7 @@ namespace Runtime ...@@ -101,8 +101,7 @@ namespace Runtime
current_ids.push(id = inline_decls[str]); current_ids.push(id = inline_decls[str]);
return false; return false;
} else { } else {
std::string name = "@__"s + std::to_string(anon_id++); current_ids.push(id = inline_decls[str] = irbuilder->gen_sym(irbuilder, nullptr));
current_ids.push(id = inline_decls[str] = irbuilder->gen_sym(irbuilder, name.c_str()));
return true; return true;
} }
} else { } else {
...@@ -433,9 +432,9 @@ namespace Runtime ...@@ -433,9 +432,9 @@ namespace Runtime
if (context->ver) if (context->ver)
current_ids.push(accept<MuID>(context->ver)); // the id of the function version we are constructing current_ids.push(accept<MuID>(context->ver)); // the id of the function version we are constructing
else else
current_ids.push(get_id(::last_name = ::parent_names.top() + ".__"s + std::to_string(anon_id++), false)); current_ids.push(irbuilder->gen_sym(irbuilder, nullptr));
::parent_names.push(::last_name); // the global name of the function version ::parent_names.push(::parent_names.top() + ".__"s + std::to_string(anon_id++)); // the global name of the function version
auto bbs = accept_list<MuBBNode>(context->body); auto bbs = accept_list<MuBBNode>(context->body);
......
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
// limitations under the License. // limitations under the License.
// Run the following after modifying this file: // Run the following after modifying this file:
// wget http://www.antlr.org/download/antlr-4.7-complete.jar -O antlr.jar
// java -jar antlr.jar -Dlanguage=Cpp -no-listener -visitor -o parser/ -lib ./ UIR.g4 // java -jar antlr.jar -Dlanguage=Cpp -no-listener -visitor -o parser/ -lib ./ UIR.g4
grammar UIR; grammar UIR;
ir ir
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <sstream> #include <sstream>
#include <gmpxx.h> #include <gmpxx.h>
#include "muapi.h" //#include "muapi.h"
#include "parser/UIRBaseVisitor.h" #include "parser/UIRBaseVisitor.h"
#include "parser/UIRParser.h" #include "parser/UIRParser.h"
#include "parser/UIRLexer.h" #include "parser/UIRLexer.h"
...@@ -65,6 +65,25 @@ std::string list_to_string<std::vector<std::string>>(std::vector<std::string> v) ...@@ -65,6 +65,25 @@ std::string list_to_string<std::vector<std::string>>(std::vector<std::string> v)
return value; return value;
} }
template<typename T>
std::string concat_strings(T v) {
std::string result {};
for (auto val : v)
result += std::to_string(val);
return result;
}
// Returns 'v' seperated by ' '
template<>
std::string concat_strings<std::vector<std::string>>(std::vector<std::string> v) {
std::string result {};
for (auto val : v)
result += val;
return result;
}
// This is converted to a string incase UINT64_MAX dosn't fit in an unsigned long // This is converted to a string incase UINT64_MAX dosn't fit in an unsigned long
// (an mpz_class can't be constructed from a long long) // (an mpz_class can't be constructed from a long long)
mpz_class mask_64(std::to_string(UINT64_MAX)); mpz_class mask_64(std::to_string(UINT64_MAX));
...@@ -81,4 +100,10 @@ void generate_bundle_name() { ...@@ -81,4 +100,10 @@ void generate_bundle_name() {
} }
// This is used to annotate the return types of visitor functions // This is used to annotate the return types of visitor functions
template<typename T = void> using Any = antlrcpp::Any; template<typename T = void> using Any = antlrcpp::Any;
\ No newline at end of file
std::size_t stosz(const std::string& str, std::size_t* pos = 0, int base = 10 )
{
static_assert(sizeof(std::size_t) <= sizeof(unsigned long long), "size_t should not be bigger than unsigned long long");
return (std::size_t)std::stoull(str, pos, base);
}
\ No newline at end of file
File deleted
// Copyright 2017 The Australian National University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Generated from UIR.g4 by ANTLR 4.7 // Generated from UIR.g4 by ANTLR 4.7
......
// Copyright 2017 The Australian National University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Generated from UIR.g4 by ANTLR 4.7 // Generated from UIR.g4 by ANTLR 4.7
......
// Copyright 2017 The Australian National University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Generated from UIR.g4 by ANTLR 4.7 // Generated from UIR.g4 by ANTLR 4.7
......
// Copyright 2017 The Australian National University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Generated from UIR.g4 by ANTLR 4.7 // Generated from UIR.g4 by ANTLR 4.7
......
This source diff could not be displayed because it is too large. You can view the blob instead.
// Copyright 2017 The Australian National University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Generated from UIR.g4 by ANTLR 4.7 // Generated from UIR.g4 by ANTLR 4.7
...@@ -136,6 +122,7 @@ public: ...@@ -136,6 +122,7 @@ public:
public: public:
IrContext(antlr4::ParserRuleContext *parent, size_t invokingState); IrContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override; virtual size_t getRuleIndex() const override;
antlr4::tree::TerminalNode *EOF();
std::vector<TopLevelDefContext *> topLevelDef(); std::vector<TopLevelDefContext *> topLevelDef();
TopLevelDefContext* topLevelDef(size_t i); TopLevelDefContext* topLevelDef(size_t i);
......
// Copyright 2017 The Australian National University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Generated from UIR.g4 by ANTLR 4.7 // Generated from UIR.g4 by ANTLR 4.7
......
// Copyright 2017 The Australian National University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Generated from UIR.g4 by ANTLR 4.7 // Generated from UIR.g4 by ANTLR 4.7
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment