<commit_before>var LLVM           = require('../../../../llvm2'),
    types          = require('../../types'),
    errors         = require('../../errors'),
    NativeFunction = require('./native-function'),
    ICE            = errors.InternalCompilerError

var Int8Type    = LLVM.Types.Int8Type,
    Int8PtrType = LLVM.Types.pointerType(LLVM.Types.Int8Type)

var stdCoreTypesStringConcat = null

function initialize (ctx) {
  stdCoreTypesStringConcat = NativeFunction.addExternalFunction(ctx, 'Mstd_Mcore_Mtypes_Mstring_Fconcat', Int8PtrType, [Int8PtrType, Int8PtrType])
}

function assertRexprType (rexprType, type) {
  if (rexprType instanceof type) { return }
  var e = type.name,
      g = rexprType.constructor.name
  throw new ICE('Invalid type of right side of binary op (expected: '+e+', got: '+g+')')
}

function getAdditionBuilder (lexprType, rexprType) {
  switch (lexprType.constructor) {
  case types.String:
    assertRexprType(rexprType, types.String)
    return function (ctx, lvalue, rvalue) {
      return ctx.builder.buildCall(stdCoreTypesStringConcat, [lvalue, rvalue], 'concat')
    }
  // TODO: Only compile Integers!
  case types.Integer:
    assertRexprType(rexprType, types.Integer)
    return function (ctx, lvalue, rvalue) {
      return ctx.builder.buildAdd(lvalue, rvalue, 'add')
    }
  default:
    var l = lexprType.inspect(),
        o = op,
        r = rexprType.inspect()
    throw new ICE('Binary op not found: '+l+' '+o+' '+r)
  }
}

function getBuilder (op, lexprType, rexprType) {
  switch (op) {
    case '+':
      return getAdditionBuilder(lexprType, rexprType)
    default:
      throw new ICE('Binary op builder not found: '+op)
  }
}

module.exports = {
  initialize: initialize,
  getBuilder: getBuilder
}
<commit_msg>Add builder shortcuts for binary ops in LLVM target<commit_after>var LLVM           = require('../../../../llvm2'),
    types          = require('../../types'),
    errors         = require('../../errors'),
    NativeFunction = require('./native-function'),
    ICE            = errors.InternalCompilerError

var Int8Type    = LLVM.Types.Int8Type,
    Int8PtrType = LLVM.Types.pointerType(LLVM.Types.Int8Type)

var stdCoreTypesStringConcat = null

function initialize (ctx) {
  stdCoreTypesStringConcat = NativeFunction.addExternalFunction(ctx, 'Mstd_Mcore_Mtypes_Mstring_Fconcat', Int8PtrType, [Int8PtrType, Int8PtrType])
}

function assertRexprType (rexprType, type) {
  if (rexprType instanceof type) { return }
  var e = type.name,
      g = rexprType.constructor.name
  throw new ICE('Invalid type of right side of binary op (expected: '+e+', got: '+g+')')
}

function buildCallBuilder (fn, name) {
  return function (ctx, lvalue, rvalue) {
    return ctx.builder.buildCall(fn, [lvalue, rvalue], name)
  }
}
function buildOpBuilder (opName, name) {
  return function (ctx, lvalue, rvalue) {
    return ctx.builder[opName](lvalue, rvalue, name)
  }
}

function getAdditionBuilder (lexprType, rexprType) {
  switch (lexprType.constructor) {
  case types.String:
    assertRexprType(rexprType, types.String)
    return buildCallBuilder(stdCoreTypesStringConcat, 'concat')
  // TODO: Only compile Integers!
  case types.Integer:
    assertRexprType(rexprType, types.Integer)
    return buildOpBuilder('buildAdd', 'add')
  default:
    var l = lexprType.inspect(),
        o = op,
        r = rexprType.inspect()
    throw new ICE('Binary op not found: '+l+' '+o+' '+r)
  }
}

function getBuilder (op, lexprType, rexprType) {
  switch (op) {
    case '+':
      return getAdditionBuilder(lexprType, rexprType)
    default:
      throw new ICE('Binary op builder not found: '+op)
  }
}

module.exports = {
  initialize: initialize,
  getBuilder: getBuilder
}

{'fraction_non_alphanumeric': 0.128625134264232, 'fraction_numerical': 0.004296455424274973, 'mean_word_length': 3.461077844311377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3843231', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1197, 'n_words': 292}