Nenhuma descrição

asm.cpp 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "asm.h"
  2. Asm::Asm()
  3. {
  4. }
  5. void Asm::strip_comment(QString *line) {
  6. bool in_string = false;
  7. for (int i = 0; i < line->length(); i++) {
  8. if (line->at(i) == '"') {
  9. in_string = !in_string;
  10. } else if (line->at(i) == '@') {
  11. if (!in_string) {
  12. line->truncate(i);
  13. break;
  14. }
  15. }
  16. }
  17. }
  18. QList<QStringList>* Asm::parse(QString text) {
  19. QList<QStringList> *parsed = new QList<QStringList>;
  20. QStringList lines = text.split('\n');
  21. for (QString line : lines) {
  22. QString label;
  23. //QString macro;
  24. //QStringList *params;
  25. strip_comment(&line);
  26. if (line.isEmpty()) {
  27. } else if (line.contains(':')) {
  28. label = line.left(line.indexOf(':'));
  29. QStringList *list = new QStringList;
  30. list->append(".label"); // This is not a real keyword. It's used only to make the output more regular.
  31. list->append(label);
  32. parsed->append(*list);
  33. // There should not be anything else on the line.
  34. // gas will raise a syntax error if there is.
  35. } else {
  36. line = line.trimmed();
  37. //parsed->append(line.split(QRegExp("\\s*,\\s*")));
  38. QString macro;
  39. QStringList params;
  40. int index = line.indexOf(QRegExp("\\s+"));
  41. macro = line.left(index);
  42. params = line.right(line.length() - index).trimmed().split(QRegExp("\\s*,\\s*"));
  43. params.prepend(macro);
  44. parsed->append(params);
  45. }
  46. //if (macro != NULL) {
  47. // if (macros->contains(macro)) {
  48. // void* function = macros->value(macro);
  49. // if (function != NULL) {
  50. // std::function function(params);
  51. // }
  52. // }
  53. //}
  54. }
  55. return parsed;
  56. }