Skip to content

Commit

Permalink
Add ImmtableString more property
Browse files Browse the repository at this point in the history
Add name, addr space and not null added to the end of string
The name is required for the crossliner to include as global variable
  • Loading branch information
jiaolu committed Jun 21, 2024
1 parent ec61062 commit 81202fc
Show file tree
Hide file tree
Showing 3 changed files with 263 additions and 263 deletions.
8 changes: 4 additions & 4 deletions include/llvm-dialects/Dialect/Dialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* 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.
* limitations under the License.
*/

def args;
Expand Down Expand Up @@ -69,7 +69,7 @@ class Attr<string cppType_> : MetaType {
// A check statement that is issued before using the C++ value in builders.
// $0 is the C++ value.
string check = "";

// Overriding prevents generating a setter method. Attributes are mutable by default.
bit isImmutable = false;
}
Expand Down Expand Up @@ -280,11 +280,11 @@ def : AttrLlvmType<AttrI32, I32>;
def : AttrLlvmType<AttrI64, I64>;

def ImmutableStringAttr : Attr<"::llvm::StringRef"> {
let toLlvmValue = [{ $_builder.CreateGlobalString($0) }];
let toLlvmValue = [{ $_builder.CreateGlobalString($0, "str", 4) }];
let fromLlvmValue = [{ ::llvm::cast<::llvm::ConstantDataArray>(::llvm::cast<::llvm::GlobalVariable>($0)->getInitializer())->getAsString() }];
let isImmutable = true;
}

// Global string variables are essentially pointers in addrspace(0).
def : AttrLlvmType<ImmutableStringAttr, Ptr>;

Expand Down
Loading

0 comments on commit 81202fc

Please sign in to comment.