addConstantString static method

String addConstantString(
  1. String value
)

Adds a string constant to the LLVM IR and returns its global name.

This method manages string constant deduplication by checking if the string has already been defined. If not, it generates the LLVM constant declaration and adds it to the header section of the IR.

Parameters:

  • value: The string content to be added as a constant

Returns: The LLVM global variable name for this string constant (e.g., "@str.0")

Example:

final strName = Node.addConstantString("Hello World");
// Results in LLVM IR: @str.0 = private constant [12 x i8] c"Hello World\00"

Implementation

static String addConstantString(String value) {
  if (SymbolTable.strings.containsKey(value)) {
    return SymbolTable.strings[value]!;
  }
  final strName = "@str.${strCount++}";
  SymbolTable.strings[value] = strName;
  String content  = generateLLVMConstant(strName, value);
  Node.addHeaderIrLine(content);
  return strName;

}